mirror of
https://github.com/narzoul/DDrawCompat
synced 2024-12-30 08:55:36 +01:00
parent
8e8eeb083a
commit
0f88271668
@ -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<GetProcAddressFunc>(
|
||||
Compat::getProcAddress(GetModuleHandle("kernel32"), "GetProcAddress"));
|
||||
|
||||
auto getProcAddressFunc = reinterpret_cast<GetProcAddressFunc>(
|
||||
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<decltype(&GetProcAddress)>(
|
||||
Compat::getProcAddress(GetModuleHandle("kernel32"), "GetProcAddress"));
|
||||
return origGetProcAddressFunc(module, procName);
|
||||
}
|
||||
|
||||
void unhookFunction(const std::map<void*, HookedFunctionInfo>::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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user