From 05d5703b14e0fe8bf5f7403d158a4985047e36ac Mon Sep 17 00:00:00 2001 From: BlueAmulet <43395286+BlueAmulet@users.noreply.github.com> Date: Fri, 30 Aug 2024 11:44:54 -0600 Subject: [PATCH] Fix old code for HookLib --- EDFModLoader/dllmain.cpp | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/EDFModLoader/dllmain.cpp b/EDFModLoader/dllmain.cpp index 7c969a5..5c40d10 100644 --- a/EDFModLoader/dllmain.cpp +++ b/EDFModLoader/dllmain.cpp @@ -100,25 +100,13 @@ BOOLEAN EDFMLAPI RemoveHookWrap(void *Original) { } static void RemoveAllHooks(void) { - for (std::vector::iterator it = hooks.begin(); it != hooks.end();) { - void *hook = *it; - if (MH_DisableHook(hook)) { - it = hooks.erase(it); - } else { - // hook is HOOK_DATA->OriginalBeginning - // hook-16 is HOOK_DATA->OriginalFunction - // TODO: Fork HookLib and expose HOOK_DATA or add function to retrieve original address - PVOID address = *((PVOID*)hook - 16 / sizeof(PVOID)); - - HMODULE hmodDLL; - wchar_t DLLName[MAX_PATH]; - GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, (LPCWSTR)address, &hmodDLL); - GetModuleFileNameW(hmodDLL, DLLName, _countof(DLLName)); - PathStripPathW(DLLName); - - PLOG_ERROR << "Failed to remove " << DLLName << "+" << std::hex << ((ULONG_PTR)address - (ULONG_PTR)hmodDLL) << " hook"; - it++; - } + if (MH_DisableHook(MH_ALL_HOOKS)) + { + hooks.clear(); + } + else + { + PLOG_WARNING << "Failed to remove hooks"; } } @@ -424,7 +412,7 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserv PluginInfo *selfInfo = new PluginInfo; selfInfo->infoVersion = PluginInfo::MaxInfoVer; selfInfo->name = "EDFModLoader"; - selfInfo->version = PLUG_VER(1, 0, 9, 0); + selfInfo->version = PLUG_VER(1, 0, 9, 1); PluginData *selfData = new PluginData; selfData->info = selfInfo; selfData->module = hModule;