Skip to content

Commit

Permalink
Change geode loading order, auto updating not implemented yet
Browse files Browse the repository at this point in the history
  • Loading branch information
altalk23 committed Jul 8, 2023
1 parent 07d9fcb commit 26e38ec
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 130 deletions.
1 change: 1 addition & 0 deletions bindings/Cocos2d.bro
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,7 @@ class cocos2d::CCRenderTexture {
static cocos2d::CCRenderTexture* create(int, int, cocos2d::CCTexture2DPixelFormat) = mac 0x35c720;
auto newCCImage(bool) = mac 0x35d7d0;
auto saveToFile(char const*) = mac 0x35dab0;
auto beginWithClear(float r, float g, float b, float a) = mac 0x35d010;
}

class cocos2d::CCRepeat {
Expand Down
77 changes: 2 additions & 75 deletions loader/launcher/mac/Bootstrapper.cpp
Original file line number Diff line number Diff line change
@@ -1,77 +1,4 @@
#include <ghc/filesystem.hpp>
#include <mach-o/dyld.h>
#include <unistd.h>
#include <dlfcn.h>
#include <array>
#include <iostream>
#include <CoreFoundation/CoreFoundation.h>

void displayError(std::string alertMessage) {
CFStringRef cfTitle = CFStringCreateWithCString(NULL, "Geode Bootstrapper", kCFStringEncodingUTF8);
CFStringRef cfMessage = CFStringCreateWithCString(NULL, alertMessage.c_str(), kCFStringEncodingUTF8);

CFUserNotificationDisplayNotice(0, kCFUserNotificationCautionAlertLevel, NULL, NULL, NULL, cfTitle, cfMessage, NULL);
}

void loadGeode() {
auto dylib = dlopen("Geode.dylib", RTLD_NOW);
if (!dylib) {
displayError(std::string("Couldn't load Geode: ") + dlerror());
return;
}
auto trigger = dlsym(dylib, "dynamicTrigger");
if (!trigger) {
displayError(std::string("Couldn't start Geode: ") + dlerror());
return;
}
reinterpret_cast<void(*)()>(trigger)();
return;
}

extern "C" void fake();
__attribute__((constructor)) void _entry() {
std::array<char, PATH_MAX> 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 libDir = workingDir / "Frameworks";
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",
libDir / "Geode.dylib", error
);
if (error) {
displayError(std::string("Couldn't update Geode: ") + error.message());
return loadGeode();
}
}

if (ghc::filesystem::exists(updatesDir / "resources", error) && !error) {
ghc::filesystem::remove_all(resourcesDir / "geode.loader", error);

if (error) {
displayError(std::string("Couldn't update Geode resources: ") + error.message());
return loadGeode();
}

ghc::filesystem::rename(
updatesDir / "resources",
resourcesDir / "geode.loader", error
);

if (error) {
displayError(std::string("Couldn't update Geode resources: ") + error.message());
return loadGeode();
}
}

return loadGeode();
fake();
}
11 changes: 10 additions & 1 deletion loader/launcher/mac/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,13 @@ set_target_properties(Bootstrapper PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${GEODE_BIN_PATH}/nightly"
)

target_link_libraries(Bootstrapper PRIVATE "-framework CoreFoundation" ghc_filesystem)
target_link_libraries(Bootstrapper PRIVATE)

add_library(FakeGeode SHARED FakeGeode.cpp)
target_compile_features(FakeGeode PUBLIC cxx_std_17)
set_target_properties(FakeGeode PROPERTIES
PREFIX ""
OUTPUT_NAME "Geode"
)

target_link_libraries(Bootstrapper PRIVATE geode-loader)
1 change: 1 addition & 0 deletions loader/launcher/mac/FakeGeode.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
extern "C" void fake() {}
Empty file added loader/launcher/mac/Updater.cpp
Empty file.
9 changes: 2 additions & 7 deletions loader/src/hooks/MenuLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,7 @@ struct CustomMenuLayer : Modify<CustomMenuLayer, MenuLayer> {
}

void onMissingTextures(CCObject*) {
static bool shownInfoPopup = false;
if (shownInfoPopup) {
return this->onGeode(nullptr);
}
shownInfoPopup = true;


#ifdef GEODE_IS_DESKTOP

try {
Expand All @@ -218,7 +213,7 @@ struct CustomMenuLayer : Modify<CustomMenuLayer, MenuLayer> {
"and <cy>unzip its contents</c> into <cb>geode/update/resources</c>.\n"
"Afterwards, <cg>restart the game</c>.\n"
"You may also continue without installing resources, but be aware that "
"the game <cr>will crash</c>.",
"you won't be able to open <cr>the Geode menu</c>.",
"Dismiss", "Open Github",
[](auto, bool btn2) {
if (btn2) {
Expand Down
1 change: 1 addition & 0 deletions loader/src/platform/Objcpp.mm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#if defined(GEODE_IS_MACOS)

#include "mac/main.mm"
#include "mac/crashlog.mm"
#include "mac/FileWatcher.mm"
#include "mac/util.mm"
Expand Down
47 changes: 0 additions & 47 deletions loader/src/platform/mac/main.cpp

This file was deleted.

66 changes: 66 additions & 0 deletions loader/src/platform/mac/main.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#include <Geode/DefaultInclude.hpp>

#if defined(GEODE_IS_MACOS)

#import <Cocoa/Cocoa.h>
#include "../load.hpp"
#include <dlfcn.h>
#include <mach-o/dyld.h>
#include <unistd.h>
#include <tulip/TulipHook.hpp>
#include <iostream>

#include <thread>

using namespace geode::prelude;

std::length_error::~length_error() _NOEXCEPT {} // do not ask...

// 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

extern "C" void fake() {}

void applicationDidFinishLaunchingHook(void* self, SEL sel, NSNotification* notification) {
// updateGeode();

std::array<uint8_t, 6> patchBytes = {
0x55,
0x48, 0x89, 0xe5,
0x41, 0x57
};

auto res = tulip::hook::writeMemory((void*)(base::get() + 0x69a0), patchBytes.data(), 6);
if (!res)
return;

int exitCode = geodeEntry(nullptr);
if (exitCode != 0)
return;

return reinterpret_cast<void(*)(void*, SEL, NSNotification*)>(geode::base::get() + 0x69a0)(self, sel, notification);
}


bool loadGeode() {
auto detourAddr = reinterpret_cast<uintptr_t>(&applicationDidFinishLaunchingHook) - geode::base::get() - 0x69a5;
auto detourAddrPtr = reinterpret_cast<uint8_t*>(&detourAddr);

std::array<uint8_t, 5> patchBytes = {
0xe9, detourAddrPtr[0], detourAddrPtr[1], detourAddrPtr[2], detourAddrPtr[3]
};

auto res = tulip::hook::writeMemory((void*)(base::get() + 0x69a0), patchBytes.data(), 5);
if (!res)
return false;

return true;
}

__attribute__((constructor)) void _entry() {
if (!loadGeode())
return;
}

#endif

0 comments on commit 26e38ec

Please sign in to comment.