Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ add_library(${PROJECT_NAME} SHARED ${SOURCES} src/platform/Mac.mm)

set_source_files_properties(src/platform/Mac.mm PROPERTIES SKIP_PRECOMPILE_HEADERS ON)

if ("${CMAKE_SYSTEM_NAME}" STREQUAL "iOS" OR IOS)
target_link_libraries(${PROJECT_NAME} "-framework CoreGraphics")
endif()

if (NOT DEFINED ENV{GEODE_SDK})
message(FATAL_ERROR "Unable to find Geode SDK! Please define GEODE_SDK environment variable to point to Geode")
else()
Expand Down
4 changes: 2 additions & 2 deletions src/pages/Attributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void DevTools::drawBasicAttributes(CCNode* node) {
int width, height;
auto bytes = renderToBytes(node, width, height);

saveRenderToFile(bytes, width, height, file->c_str());
saveRenderToFile(bytes, width, height, string::pathToString(*file).c_str());
}
});
}
Expand All @@ -85,7 +85,7 @@ void DevTools::drawBasicAttributes(CCNode* node) {
ImGui::SameLine();
if (ImGui::Button(U8STR(FEATHER_COPY " Copy"))) {
clipboard::write(
utils::intToHex(reinterpret_cast<uintptr_t>(node))
fmt::format("{:#x}", reinterpret_cast<uintptr_t>(node))
);
}
if (node->getUserData()) {
Expand Down
7 changes: 4 additions & 3 deletions src/platform/Android.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ using namespace geode::prelude;
#include "utils.hpp"

std::string formatAddressIntoOffsetImpl(uintptr_t addr, bool module) {
if (addr > base::get() && addr - 0x1000000 < base::get())
if (addr > base::get() && addr - 0x1000000 < base::get()) {
if(module) return fmt::format("libcocos2d.so + {:#x}", addr - base::get());
else return fmt::format("{:#x}", addr - base::get());
}
return fmt::format("{:#x}", addr);
}

void saveRenderToFile(std::vector<uint8_t> const& data, float width, float height, char const* filename) {
void saveRenderToFile(std::vector<uint8_t> const& data, int width, int height, char const* filename) {
auto img = new CCImage;
img->initWithImageData((void*)data.data(), data.size(), kCCImageFormatRGBA8888, width, height, 8);
img->initWithImageData((void*)data.data(), data.size(), CCImage::kFmtRawData, width, height, 8);
img->saveToFile(filename);
}

Expand Down
30 changes: 29 additions & 1 deletion src/platform/Mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@
#import <Foundation/Foundation.h>

#import <CoreGraphics/CoreGraphics.h>
#ifdef GEODE_IS_MACOS
#include <ImageIO/CGImageDestination.h>
#else
#import <UIKit/UIKit.h>
#endif

static std::vector<struct dyld_image_info const*> getAllImages() {
std::vector<struct dyld_image_info const*> images;
Expand Down Expand Up @@ -114,7 +118,7 @@ void saveRenderToFile(std::vector<uint8_t> const& data, int width, int height, c
32,
width * 4,
colorSpace,
kCGBitmapByteOrderDefault | kCGImageAlphaPremultipliedLast,
kCGImageAlphaPremultipliedLast,
provider,
NULL,
false,
Expand All @@ -128,6 +132,29 @@ void saveRenderToFile(std::vector<uint8_t> const& data, int width, int height, c
return;
}

#ifdef GEODE_IS_IOS
UIImage* image = [UIImage imageWithCGImage:cgImg];
if (!image) {
geode::log::error("Failed to create UIImage");
CGImageRelease(cgImg);
CGDataProviderRelease(provider);
CGColorSpaceRelease(colorSpace);
return;
}

NSData* pngData = UIImagePNGRepresentation(image);
if (!pngData) {
geode::log::error("Failed to create PNG data from UIImage");
CGImageRelease(cgImg);
CGDataProviderRelease(provider);
CGColorSpaceRelease(colorSpace);
return;
}

if (auto err = geode::utils::file::writeBinary(filename, { (uint8_t*)pngData.bytes, (uint8_t*)pngData.bytes + pngData.length }).err()) {
geode::log::error("Failed to write image to {}: {}", filename, err);
}
#else
CFMutableDataRef pngData = CFDataCreateMutable(NULL, 0);
CGImageDestinationRef destination = CGImageDestinationCreateWithData(pngData, kUTTypePNG, 1, NULL);
if (!destination) {
Expand Down Expand Up @@ -160,6 +187,7 @@ void saveRenderToFile(std::vector<uint8_t> const& data, int width, int height, c

CFRelease(destination);
CFRelease(pngData);
#endif
CGImageRelease(cgImg);
CGColorSpaceRelease(colorSpace);
CGDataProviderRelease(provider);
Expand Down
4 changes: 2 additions & 2 deletions src/platform/Win32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ class $modify(CCEGLView) {

#include "utils.hpp"

void saveRenderToFile(std::vector<uint8_t> const& data, float width, float height, char const* filename) {
void saveRenderToFile(std::vector<uint8_t> const& data, int width, int height, char const* filename) {
auto img = new CCImage;
img->initWithImageData((void*)data.data(), data.size(), kCCImageFormatRGBA8888, width, height, 8);
img->initWithImageData((void*)data.data(), data.size(), CCImage::kFmtRawData, width, height, 8);
img->saveToFile(filename);
}

Expand Down
4 changes: 4 additions & 0 deletions src/platform/utils.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#include "utils.hpp"

#if defined(GEODE_IS_MACOS)
#include <OpenGL/gl.h>
#elif defined(GEODE_IS_IOS)
#include <OpenGLES/ES2/gl.h>
#endif
#include <unordered_map>
#include <cocos2d.h>

Expand Down
Loading