geode/loader/src/hooks/DynamicCastFix.cpp
alk 9869ddcdea
Macos support for Geode v2 (#437)
updates loader refactor stuff and other things

---------

Co-authored-by: matcool <26722564+matcool@users.noreply.github.com>
Co-authored-by: dankmeme01 <42031238+dankmeme01@users.noreply.github.com>
2024-01-21 14:08:06 -03:00

22 lines
860 B
C++

#include <Geode/DefaultInclude.hpp>
#include <Geode/loader/Mod.hpp>
using namespace geode::prelude;
$execute {
// this replaces the call to __dynamic_cast with a call to our own
// this is needed because the transitions in cocos uses dynamic cast to check
// layers, which fail on user layers due to typeinfo not matching
#if defined(GEODE_IS_MACOS)
void* dynamicCastAddr = reinterpret_cast<void*>(base::get() + 0x7a7c9f);
(void) Mod::get()->hook(dynamicCastAddr, &cast::typeinfoCastInternal, "__dynamic_cast");
#elif defined(GEODE_IS_ANDROID)
void* handle = dlopen("libcocos2dcpp.so", RTLD_LAZY | RTLD_NOLOAD);
void* dynamicCastAddr = dlsym(handle, "__dynamic_cast");
(void)Mod::get()->hook(dynamicCastAddr, &cast::typeinfoCastInternal, "__dynamic_cast");
dlclose(handle);
#endif
}