Skip to content

Commit 482f200

Browse files
committed
Use ObjcHook instead
1 parent 2f7874b commit 482f200

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

loader/src/hooks/ShutdownFix.cpp

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <Geode/platform/cplatform.h>
22
#ifdef GEODE_IS_MACOS
3-
#include <Geode/loader/Mod.hpp>
3+
#include <Geode/utils/ObjcHook.hpp>
44
#include <objc/runtime.h>
55

66
using namespace geode::prelude;
@@ -17,17 +17,8 @@ void shutdownGameHook(void* self, SEL sel) {
1717
}
1818

1919
$execute {
20-
auto appController = objc_getClass("AppController");
21-
if (!appController) return;
22-
23-
auto shutdownGame = class_getInstanceMethod(appController, sel_registerName("shutdownGame"));
24-
if (!shutdownGame) return;
25-
26-
s_originalShutdownGame = reinterpret_cast<decltype(s_originalShutdownGame)>(method_getImplementation(shutdownGame));
27-
if (s_originalShutdownGame) (void)Mod::get()->hook(
28-
reinterpret_cast<void*>(s_originalShutdownGame),
29-
&shutdownGameHook,
30-
"AppController::shutdownGame"
31-
);
20+
if (auto original = hook::replaceObjcMethod("AppController", "shutdownGame", reinterpret_cast<void*>(&shutdownGameHook))) {
21+
s_originalShutdownGame = reinterpret_cast<decltype(s_originalShutdownGame)>(original.unwrap());
22+
}
3223
};
3324
#endif

0 commit comments

Comments
 (0)