From 48ab98a11539532fc96c6ae610659cb09219ef52 Mon Sep 17 00:00:00 2001 From: altalk23 Date: Sat, 8 Oct 2022 12:41:36 +0300 Subject: [PATCH] macos fixes and implemented the bootstrapper without testing --- README.md | 1 + bindings/Cocos2d.bro | 51 +++++++++++++++++-- loader/CMakeLists.txt | 8 ++- loader/include/Geode/Geode.hpp | 2 +- .../cocos2dx/label_nodes/CCLabelBMFont.h | 1 + .../cocos2dx/sprite_nodes/CCSpriteBatchNode.h | 1 + loader/include/Geode/modify/Field.hpp | 2 +- loader/launcher/mac/Bootstrapper.cpp | 41 +++++++++++++++ loader/launcher/mac/CMakeLists.txt | 10 ++++ loader/launcher/windows/Bootstrapper.cpp | 40 +++++++++++++++ loader/launcher/windows/CMakeLists.txt | 20 ++++---- loader/launcher/windows/proxyLoader.c | 2 +- loader/src/hooks/GeodeNodeMetadata.cpp | 4 +- loader/src/hooks/LoadingLayer.cpp | 2 +- loader/src/hooks/MenuLayer.cpp | 1 + loader/src/hooks/TouchDispatcherFix.cpp | 1 - loader/src/hooks/persist.cpp | 2 +- loader/src/index/Index.cpp | 2 +- loader/src/main.cpp | 46 +++++++++++++++-- loader/test/dependency/main.cpp | 1 + loader/test/main/main.cpp | 14 ++--- 21 files changed, 218 insertions(+), 34 deletions(-) create mode 100644 loader/launcher/mac/Bootstrapper.cpp create mode 100644 loader/launcher/mac/CMakeLists.txt create mode 100644 loader/launcher/windows/Bootstrapper.cpp diff --git a/README.md b/README.md index e911dfa6..1d289769 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ There's nothing worse than having to read thousands of words just to see what so ```cpp #include +#include USE_GEODE_NAMESPACE(); diff --git a/bindings/Cocos2d.bro b/bindings/Cocos2d.bro index 9d9b04c1..b7ecdebd 100644 --- a/bindings/Cocos2d.bro +++ b/bindings/Cocos2d.bro @@ -257,9 +257,37 @@ class cocos2d::CCKeypadHandler { class cocos2d::CCLabelBMFont { static cocos2d::CCLabelBMFont* create(char const*, char const*) = mac 0x347660; auto limitLabelWidth(float, float, float) = mac 0x34a6e0, ios 0x21b740; - auto setScale(float) = mac 0x34a5d0; - auto setString(char const*, bool) = mac 0x3489e0; - auto setAnchorPoint(cocos2d::CCPoint const&) = mac 0x349440; + + virtual ~CCLabelBMFont() = mac 0x347e80, ios 0x219afc; + + virtual auto init() = mac 0x347b10, ios 0x2198e0; + virtual auto setScaleX(float) = mac 0x34a5b0, ios 0x21b6e8; + virtual auto setScaleY(float) = mac 0x34a5d0, ios 0x21b714; + virtual auto setScale(float) = mac 0x34a590, ios 0x21b6bc; + virtual auto setAnchorPoint(cocos2d::CCPoint const&) = mac 0x349440, ios 0x21aa7c; + virtual auto setString(char const*) = mac 0x348990, ios 0x21a408; + virtual auto setString(char const*, bool) = mac 0x3489e0, ios 0x21a42c; + virtual auto getString() = mac 0x348bf0, ios 0x21a60c; + virtual auto setCString(char const*) = mac 0x348c10, ios 0x21a63c; + virtual auto updateLabel() = mac 0x349480, ios 0x21aad0; + virtual auto setAlignment(cocos2d::CCTextAlignment) = mac 0x34a530, ios 0x21b68c; + virtual auto setWidth(float) = mac 0x34a550, ios 0x21b69c; + virtual auto setLineBreakWithoutSpace(bool) = mac 0x34a570, ios 0x21b6ac; + virtual auto isOpacityModifyRGB() = mac 0x3490e0, ios 0x21a8c4; + virtual auto setOpacityModifyRGB(bool) = mac 0x348f70, ios 0x21a80c; + virtual auto getOpacity() = mac 0x348df0, ios 0x21a748; + virtual auto getDisplayedOpacity() = mac 0x348e10, ios 0x21a758; + virtual auto setOpacity(unsigned char) = mac 0x348e30, ios 0x21a768; + virtual auto updateDisplayedOpacity(unsigned char) = mac 0x349100, ios 0x21a8d4; + virtual auto isCascadeOpacityEnabled() = mac 0x349400, ios 0x21aa5c; + virtual auto setCascadeOpacityEnabled(bool) = mac 0x349420, ios 0x21aa6c; + virtual auto getColor() = mac 0x348c30, ios 0x21a648; + virtual auto getDisplayedColor() = mac 0x348c50, ios 0x21a658; + virtual auto setColor(cocos2d::ccColor3B const&) = mac 0x348c70, ios 0x21a668; + virtual auto updateDisplayedColor(cocos2d::ccColor3B const&) = mac 0x349210, ios 0x21a968; + virtual auto isCascadeColorEnabled() = mac 0x3493c0, ios 0x21aa3c; + virtual auto setCascadeColorEnabled(bool) = mac 0x3493e0, ios 0x21aa4c; + virtual auto setString(unsigned short*, bool) = mac 0x348a60, ios 0x21a4b4; } class cocos2d::CCLabelTTF { @@ -747,6 +775,23 @@ class cocos2d::CCSpriteBatchNode { static auto createWithTexture(cocos2d::CCTexture2D*, unsigned int) = mac 0xbb310; auto getUsedAtlasCapacity() = mac 0xbc6b0; auto increaseAtlasCapacity(unsigned int) = mac 0xbc670; + + virtual ~CCSpriteBatchNode() = mac 0xbb790, ios 0x130d18; + + virtual auto init() = mac 0xbb680, ios 0x130c20; + virtual auto addChild(cocos2d::CCNode*) = mac 0xbbb40, ios 0x131034; + virtual auto addChild(cocos2d::CCNode*, int) = mac 0xbbb50, ios 0x131038; + virtual auto addChild(cocos2d::CCNode*, int, int) = mac 0xbb930, ios 0x130e0c; + virtual auto removeChild(cocos2d::CCNode*, bool) = mac 0xbbbb0, ios 0x1310a4; + virtual auto removeAllChildrenWithCleanup(bool) = mac 0xbbe30, ios 0x1312d8; + virtual auto reorderChild(cocos2d::CCNode*, int) = mac 0xbbb60, ios 0x13103c; + virtual auto sortAllChildren() = mac 0xbbee0, ios 0x13137c; + virtual auto draw() = mac 0xbc540, ios 0x13191c; + virtual auto visit() = mac 0xbb880, ios 0x130d54; + virtual auto getTexture() = mac 0xbcd70, ios 0x131a70; + virtual auto setTexture(cocos2d::CCTexture2D*) = mac 0xbcda0, ios 0x131a90; + virtual auto setBlendFunc(cocos2d::ccBlendFunc) = mac 0xbcd30, ios 0x131a50; + virtual auto getBlendFunc() = mac 0xbcd50, ios 0x131a60; } class cocos2d::CCSpriteFrame { diff --git a/loader/CMakeLists.txt b/loader/CMakeLists.txt index cfab048b..013cecfc 100644 --- a/loader/CMakeLists.txt +++ b/loader/CMakeLists.txt @@ -117,12 +117,18 @@ target_link_libraries(${PROJECT_NAME} z lilac_hook geode-sdk) set_source_files_properties(${OBJC_SOURCES} PROPERTIES SKIP_PRECOMPILE_HEADERS ON) target_precompile_headers(${PROJECT_NAME} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/include/Geode/DefaultInclude.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/include/Geode/Modify.hpp" + "${CMAKE_CURRENT_SOURCE_DIR}/include/Geode/Utils.hpp" + "${CMAKE_CURRENT_SOURCE_DIR}/include/Geode/Loader.hpp" + "${CMAKE_CURRENT_SOURCE_DIR}/include/Geode/UI.hpp" + "${CMAKE_CURRENT_SOURCE_DIR}/include/Geode/Bindings.hpp" + # "${CMAKE_CURRENT_SOURCE_DIR}/include/Geode/Modify.hpp" "${CMAKE_CURRENT_SOURCE_DIR}/include/Geode/cocos/cocos2dx/include/cocos2d.h" ) # Create launcher if (APPLE) + add_subdirectory(launcher/mac) + if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm" OR GEODE_TARGET_PLATFORM STREQUAL "iOS") add_custom_command(TARGET geode-loader POST_BUILD COMMAND diff --git a/loader/include/Geode/Geode.hpp b/loader/include/Geode/Geode.hpp index 19315f47..f96b4fa8 100644 --- a/loader/include/Geode/Geode.hpp +++ b/loader/include/Geode/Geode.hpp @@ -3,5 +3,5 @@ #include "Bindings.hpp" #include "Utils.hpp" #include "Loader.hpp" -#include "Modify.hpp" +// #include "Modify.hpp" #include "UI.hpp" diff --git a/loader/include/Geode/cocos/cocos2dx/label_nodes/CCLabelBMFont.h b/loader/include/Geode/cocos/cocos2dx/label_nodes/CCLabelBMFont.h index 9a57b9b3..be494e5a 100644 --- a/loader/include/Geode/cocos/cocos2dx/label_nodes/CCLabelBMFont.h +++ b/loader/include/Geode/cocos/cocos2dx/label_nodes/CCLabelBMFont.h @@ -198,6 +198,7 @@ public: * @js ctor */ CCLabelBMFont(); + GEODE_MONOSTATE_CONSTRUCTOR_COCOS(CCLabelBMFont, CCSpriteBatchNode) /** * @js NA * @lua NA diff --git a/loader/include/Geode/cocos/cocos2dx/sprite_nodes/CCSpriteBatchNode.h b/loader/include/Geode/cocos/cocos2dx/sprite_nodes/CCSpriteBatchNode.h index d6d9bfc5..da208ba7 100644 --- a/loader/include/Geode/cocos/cocos2dx/sprite_nodes/CCSpriteBatchNode.h +++ b/loader/include/Geode/cocos/cocos2dx/sprite_nodes/CCSpriteBatchNode.h @@ -68,6 +68,7 @@ public: * @js ctor */ CCSpriteBatchNode(); + GEODE_MONOSTATE_CONSTRUCTOR_COCOS(CCSpriteBatchNode, CCNode) /** * @js NA * @lua NA diff --git a/loader/include/Geode/modify/Field.hpp b/loader/include/Geode/modify/Field.hpp index 75c3a27f..73bb11bd 100644 --- a/loader/include/Geode/modify/Field.hpp +++ b/loader/include/Geode/modify/Field.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include #include "Traits.hpp" #include diff --git a/loader/launcher/mac/Bootstrapper.cpp b/loader/launcher/mac/Bootstrapper.cpp new file mode 100644 index 00000000..c4cce77e --- /dev/null +++ b/loader/launcher/mac/Bootstrapper.cpp @@ -0,0 +1,41 @@ +#include "../../../filesystem/fs/filesystem.hpp" +#include +#include +#include +#include + +__attribute__((constructor)) void _entry() { + std::array gddir; + + uint32_t out = PATH_MAX; + _NSGetExecutablePath(gddir.data(), &out); + + ghc::filesystem::path gdpath = gddir.data(); + auto workingDir = gdpath.parent_path().parent_path(); + + auto updatesDir = workingDir / "geode" / "update"; + auto resourcesDir = workingDir / "geode" / "resources"; + + auto error = std::error_code(); + + if (ghc::filesystem::exists(updatesDir / "Geode.dylib", error) && !error) { + ghc::filesystem::rename( + updatesDir / "Geode.dylib", + workingDir / "Geode.dylib", error + ); + if (error) return; + } + + if (ghc::filesystem::exists(updatesDir / "resources", error) && !error) { + ghc::filesystem::rename( + updatesDir / "resources", + resourcesDir / "geode.loader", error + ); + if (error) return; + } + + auto dylib = dlopen("Geode.dylib", RTLD_NOW); + if (dylib) return; + + return; +} \ No newline at end of file diff --git a/loader/launcher/mac/CMakeLists.txt b/loader/launcher/mac/CMakeLists.txt new file mode 100644 index 00000000..e69e60ae --- /dev/null +++ b/loader/launcher/mac/CMakeLists.txt @@ -0,0 +1,10 @@ +cmake_minimum_required(VERSION 3.3.0) + + +add_library(Bootstrapper SHARED Bootstrapper.cpp) +set_target_properties(Bootstrapper PROPERTIES + PREFIX "" + OUTPUT_NAME "GeodeBootstrapper" + LIBRARY_OUTPUT_DIRECTORY "${GEODE_BIN_PATH}/nightly" + RUNTIME_OUTPUT_DIRECTORY "${GEODE_BIN_PATH}/nightly" +) diff --git a/loader/launcher/windows/Bootstrapper.cpp b/loader/launcher/windows/Bootstrapper.cpp new file mode 100644 index 00000000..be8e6705 --- /dev/null +++ b/loader/launcher/windows/Bootstrapper.cpp @@ -0,0 +1,40 @@ +#include +#include "../../../filesystem/fs/filesystem.hpp" + +DWORD WINAPI load(PVOID _) { + auto workingDir = ghc::filesystem::current_path(); + auto updatesDir = workingDir / "geode" / "update"; + auto resourcesDir = workingDir / "geode" / "resources"; + + auto error = std::error_code(); + + if (ghc::filesystem::exists(updatesDir / "Geode.dll", error) && !error) { + ghc::filesystem::rename( + updatesDir / "Geode.dll", + workingDir / "Geode.dll", error + ); + if (error) return error.value(); + } + + if (ghc::filesystem::exists(updatesDir / "resources", error) && !error) { + ghc::filesystem::rename( + updatesDir / "resources", + resourcesDir / "geode.loader", error + ); + if (error) return error.value(); + } + + LoadLibraryA("Geode.dll"); + return 0; +} + +BOOL WINAPI DllMain(HINSTANCE module, DWORD reason, LPVOID _) { + if (reason == DLL_PROCESS_ATTACH) { + HANDLE handle = CreateThread(NULL, 0, load, module, 0, NULL); + if (handle) + CloseHandle(handle); + else + return FALSE; + } + return TRUE; +} \ No newline at end of file diff --git a/loader/launcher/windows/CMakeLists.txt b/loader/launcher/windows/CMakeLists.txt index 64b4d38b..141f846b 100644 --- a/loader/launcher/windows/CMakeLists.txt +++ b/loader/launcher/windows/CMakeLists.txt @@ -1,15 +1,17 @@ cmake_minimum_required(VERSION 3.3.0) -add_library(proxy_loader SHARED proxyLoader.c) -set_target_properties(proxy_loader PROPERTIES +add_library(ProxyLoader SHARED proxyLoader.c) +set_target_properties(ProxyLoader PROPERTIES + PREFIX "" OUTPUT_NAME "XInput9_1_0" - RUNTIME_OUTPUT_DIRECTORY "${GEODE_BIN_PATH}" + RUNTIME_OUTPUT_DIRECTORY "${GEODE_BIN_PATH}/nightly" + LIBRARY_OUTPUT_DIRECTORY "${GEODE_BIN_PATH}/nightly" ) -add_custom_command( - COMMAND - ${CMAKE_COMMAND} -E rename "$" "${GEODE_BIN_PATH}/nightly/$" - DEPENDS $ - VERBATIM - TARGET proxy_loader +add_library(Bootstrapper SHARED Bootstrapper.cpp) +set_target_properties(ProxyLoader PROPERTIES + PREFIX "" + OUTPUT_NAME "GeodeBootstrapper" + RUNTIME_OUTPUT_DIRECTORY "${GEODE_BIN_PATH}/nightly" + LIBRARY_OUTPUT_DIRECTORY "${GEODE_BIN_PATH}/nightly" ) diff --git a/loader/launcher/windows/proxyLoader.c b/loader/launcher/windows/proxyLoader.c index a49170d7..31bf1055 100644 --- a/loader/launcher/windows/proxyLoader.c +++ b/loader/launcher/windows/proxyLoader.c @@ -11,7 +11,7 @@ DWORD XInputGetDSoundAudioDeviceGuids(DWORD user, GUID* render, GUID* capture) { #pragma comment(linker, "/export:XInputGetDSoundAudioDeviceGuids=_XInputGetDSoundAudioDeviceGuids") DWORD WINAPI load(PVOID _) { - LoadLibraryA("Geode.dll"); + LoadLibraryA("GeodeBootstrapper.dll"); return 0; } diff --git a/loader/src/hooks/GeodeNodeMetadata.cpp b/loader/src/hooks/GeodeNodeMetadata.cpp index d5356b15..8bb95f69 100644 --- a/loader/src/hooks/GeodeNodeMetadata.cpp +++ b/loader/src/hooks/GeodeNodeMetadata.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include #include USE_GEODE_NAMESPACE(); @@ -95,7 +95,7 @@ CCNode* CCNode::getChildByIDRecursive(std::string const& id) { return child; } CCARRAY_FOREACH_B_TYPE(m_pChildren, child, CCNode) { - if (child = child->getChildByIDRecursive(id)) { + if ((child = child->getChildByIDRecursive(id))) { return child; } } diff --git a/loader/src/hooks/LoadingLayer.cpp b/loader/src/hooks/LoadingLayer.cpp index 5ff4f5d5..65a1a078 100644 --- a/loader/src/hooks/LoadingLayer.cpp +++ b/loader/src/hooks/LoadingLayer.cpp @@ -1,4 +1,4 @@ -#include +#include #include USE_GEODE_NAMESPACE(); diff --git a/loader/src/hooks/MenuLayer.cpp b/loader/src/hooks/MenuLayer.cpp index de0b13be..1776072b 100644 --- a/loader/src/hooks/MenuLayer.cpp +++ b/loader/src/hooks/MenuLayer.cpp @@ -8,6 +8,7 @@ #include #include "../ui/internal/info/ModInfoLayer.hpp" #include +#include USE_GEODE_NAMESPACE(); diff --git a/loader/src/hooks/TouchDispatcherFix.cpp b/loader/src/hooks/TouchDispatcherFix.cpp index ca8f02de..450708b0 100644 --- a/loader/src/hooks/TouchDispatcherFix.cpp +++ b/loader/src/hooks/TouchDispatcherFix.cpp @@ -1,4 +1,3 @@ -#include #include USE_GEODE_NAMESPACE(); diff --git a/loader/src/hooks/persist.cpp b/loader/src/hooks/persist.cpp index 274f3081..68704e56 100644 --- a/loader/src/hooks/persist.cpp +++ b/loader/src/hooks/persist.cpp @@ -1,4 +1,4 @@ -#include +#include #include USE_GEODE_NAMESPACE(); diff --git a/loader/src/index/Index.cpp b/loader/src/index/Index.cpp index da80097d..c9568dae 100644 --- a/loader/src/index/Index.cpp +++ b/loader/src/index/Index.cpp @@ -197,7 +197,7 @@ void Index::indexUpdateProgress( uint8_t percentage ) { Loader::get()->queueInGDThread([this, status, info, percentage]() -> void { - Log::get() << info; + log::debug(info); m_callbacksMutex.lock(); for (auto& d : m_callbacks) { d(status, info, percentage); diff --git a/loader/src/main.cpp b/loader/src/main.cpp index 23f5de4c..2325ed86 100644 --- a/loader/src/main.cpp +++ b/loader/src/main.cpp @@ -6,6 +6,7 @@ #include #include #include "../core/Core.hpp" +#include int geodeEntry(void* platformData); // platform-specific entry points @@ -16,20 +17,55 @@ int geodeEntry(void* platformData); std::length_error::~length_error() _NOEXCEPT {} // do not ask... -__attribute__((constructor)) void _entry() { - char gddir[PATH_MAX]; - uint32_t out = PATH_MAX; - _NSGetExecutablePath(gddir, &out); +// camila has an old ass macos and this function turned +// from dynamic to static thats why she needs to define it +// this is what old versions does to a silly girl - ghc::filesystem::path gdpath = gddir; +__attribute__((constructor)) void _entry() { + std::array gddir; + + uint32_t out = PATH_MAX; + _NSGetExecutablePath(gddir.data(), &out); + + ghc::filesystem::path gdpath = gddir.data(); ghc::filesystem::current_path(gdpath.parent_path().parent_path()); + auto workingDir = ghc::filesystem::current_path(); + auto updatesDir = workingDir / "geode" / "update"; + + auto error = std::error_code(); + + if (ghc::filesystem::exists(updatesDir / "GeodeBootstrapper.dylib", error) && !error) { + ghc::filesystem::rename( + updatesDir / "GeodeBootstrapper.dylib", + workingDir / "GeodeBootstrapper.dylib", error + ); + if (error) return; + } + geodeEntry(nullptr); } + #elif defined(GEODE_IS_WINDOWS) #include DWORD WINAPI loadThread(void* arg) { + auto module = GetModuleHandleA("GeodeBootstrapper.dll"); + FreeLibrary(module); + + auto workingDir = ghc::filesystem::current_path(); + auto updatesDir = workingDir / "geode" / "update"; + + auto error = std::error_code(); + + if (ghc::filesystem::exists(updatesDir / "GeodeBootstrapper.dll", error) && !error) { + ghc::filesystem::rename( + updatesDir / "GeodeBootstrapper.dll", + workingDir / "GeodeBootstrapper.dll", error + ); + if (error) return error.value(); + } + return geodeEntry(arg); } diff --git a/loader/test/dependency/main.cpp b/loader/test/dependency/main.cpp index f0c92484..714ada0d 100644 --- a/loader/test/dependency/main.cpp +++ b/loader/test/dependency/main.cpp @@ -1,4 +1,5 @@ #include +#include USE_GEODE_NAMESPACE(); diff --git a/loader/test/main/main.cpp b/loader/test/main/main.cpp index e1492ec6..6493eaff 100644 --- a/loader/test/main/main.cpp +++ b/loader/test/main/main.cpp @@ -1,36 +1,36 @@ #include +#include USE_GEODE_NAMESPACE(); // Exported functions GEODE_API bool GEODE_CALL geode_enable() { - Log::get() << "Enabled"; + log::info("Enabled"); return true; } GEODE_API bool GEODE_CALL geode_disable() { - Log::get() << "Disabled"; + log::info("Disabled"); return true; } GEODE_API bool GEODE_CALL geode_load(Mod*) { - Log::get() << "Loaded"; + log::info("Loaded"); return true; } GEODE_API bool GEODE_CALL geode_unload() { - Log::get() << "Unoaded"; + log::info("Unloaded"); return true; } // Modify class $modify(GJGarageLayerTest, GJGarageLayer) { GJGarageLayerTest() : - myValue(1907), - myString("yeah have fun finding a better thing for this") {} + myValue(1907) {} int myValue; - std::string myString; + std::string myString = "yeah have fun finding a better thing for this"; bool init() { if (!GJGarageLayer::init()) return false;