From 0f88271668b68778c317c0b5da02ee40a209e271 Mon Sep 17 00:00:00 2001 From: narzoul Date: Fri, 7 Jun 2019 21:18:50 +0200 Subject: [PATCH] Fixed compatibility issue with Windows 10 v1903 See issue #43 --- DDrawCompat/Common/Hook.cpp | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/DDrawCompat/Common/Hook.cpp b/DDrawCompat/Common/Hook.cpp index 4e3e78a..fdfd9e5 100644 --- a/DDrawCompat/Common/Hook.cpp +++ b/DDrawCompat/Common/Hook.cpp @@ -52,25 +52,9 @@ namespace } auto modules = getProcessModules(GetCurrentProcess()); - const HMODULE targetModule = GetModuleHandle(moduleName); - for (auto module : modules) { FARPROC func = Compat::getProcAddressFromIat(module, moduleName, funcName); - if (!func) - { - typedef decltype(GetProcAddress)* GetProcAddressFunc; - static const auto origGetProcAddressFunc = reinterpret_cast( - Compat::getProcAddress(GetModuleHandle("kernel32"), "GetProcAddress")); - - auto getProcAddressFunc = reinterpret_cast( - Compat::getProcAddressFromIat(module, "kernel32", "GetProcAddress")); - if (getProcAddressFunc && *getProcAddressFunc != origGetProcAddressFunc) - { - func = getProcAddressFunc(targetModule, funcName); - } - } - if (func) { hookFunctions.insert(func); @@ -141,6 +125,13 @@ namespace std::make_pair(hookedFuncPtr, HookedFunctionInfo{ module, origFuncPtr, newFuncPtr })); } + FARPROC origGetProcAddress(HMODULE module, const char* procName) + { + static const auto origGetProcAddressFunc = reinterpret_cast( + Compat::getProcAddress(GetModuleHandle("kernel32"), "GetProcAddress")); + return origGetProcAddressFunc(module, procName); + } + void unhookFunction(const std::map::iterator& hookedFunc) { DetourTransactionBegin(); @@ -275,7 +266,7 @@ namespace Compat void hookFunction(HMODULE module, const char* funcName, void*& origFuncPtr, void* newFuncPtr) { - FARPROC procAddr = getProcAddress(module, funcName); + FARPROC procAddr = origGetProcAddress(module, funcName); if (!procAddr) { Compat::LogDebug() << "Failed to load the address of a function: " << funcName;