diff --git a/source/FunctionAddressProvider.cpp b/source/FunctionAddressProvider.cpp index 8a4212a..4af59c4 100644 --- a/source/FunctionAddressProvider.cpp +++ b/source/FunctionAddressProvider.cpp @@ -57,3 +57,13 @@ void FunctionAddressProvider::resetHandles() { rplHandle.handle = nullptr; } } + +function_replacement_library_type_t FunctionAddressProvider::getTypeForHandle(OSDynLoad_Module handle) { + for (auto &rplHandle : rpl_handles) { + if (rplHandle.handle == handle) { + return rplHandle.library; + } + } + return LIBRARY_OTHER; +} + diff --git a/source/FunctionAddressProvider.h b/source/FunctionAddressProvider.h index d1384b2..8f5fa9b 100644 --- a/source/FunctionAddressProvider.h +++ b/source/FunctionAddressProvider.h @@ -16,6 +16,8 @@ public: uint32_t getEffectiveAddressOfFunction(function_replacement_library_type_t library, const char *functionName); void resetHandles(); + function_replacement_library_type_t getTypeForHandle(OSDynLoad_Module toReset); + std::list rpl_handles = { {LIBRARY_AVM, "avm.rpl", nullptr}, {LIBRARY_CAMERA, "camera.rpl", nullptr}, diff --git a/source/main.cpp b/source/main.cpp index 717db80..2a50374 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -96,6 +96,17 @@ void notify_callback(OSDynLoad_Module module, for (auto &cur : gPatchedFunctions) { PatchFunction(cur); } + } else if (reason == OS_DYNLOAD_NOTIFY_UNLOADED) { + std::lock_guard lock(gPatchedFunctionsMutex); + auto library = gFunctionAddressProvider->getTypeForHandle(module); + if (library != LIBRARY_OTHER) { + for (auto &cur : gPatchedFunctions) { + if (cur->library == library) { + cur->isPatched = false; + } + } + } + CheckIfPatchedFunctionsAreStillInMemory(); } }