From cb35ee4beb15602f8e94e6ce6e9c52c809f6326c Mon Sep 17 00:00:00 2001 From: narzoul Date: Tue, 6 Apr 2021 13:34:06 +0200 Subject: [PATCH] Fixed crash at startup in Anno 1503 AD --- DDrawCompat/Common/Hook.cpp | 2 -- DDrawCompat/Dll/DllMain.cpp | 15 ++++----------- DDrawCompat/Gdi/WinProc.cpp | 1 - 3 files changed, 4 insertions(+), 14 deletions(-) diff --git a/DDrawCompat/Common/Hook.cpp b/DDrawCompat/Common/Hook.cpp index 5c614a0..0e213ea 100644 --- a/DDrawCompat/Common/Hook.cpp +++ b/DDrawCompat/Common/Hook.cpp @@ -215,8 +215,6 @@ namespace } g_isDbgEngInitialized = true; - CoInitialize(nullptr); - HRESULT result = S_OK; if (FAILED(result = DebugCreate(IID_IDebugClient, reinterpret_cast(&g_debugClient))) || FAILED(result = g_debugClient->QueryInterface(IID_IDebugControl, reinterpret_cast(&g_debugControl))) || diff --git a/DDrawCompat/Dll/DllMain.cpp b/DDrawCompat/Dll/DllMain.cpp index 4f5b07d..e27e907 100644 --- a/DDrawCompat/Dll/DllMain.cpp +++ b/DDrawCompat/Dll/DllMain.cpp @@ -38,20 +38,13 @@ namespace void installHooks(); - template - Result WINAPI directDrawFunc(FirstParam firstParam, Params... params) + template + HRESULT WINAPI directDrawFunc(FirstParam firstParam, Params... params) { LOG_FUNC(getFuncName(), firstParam, params...); installHooks(); suppressEmulatedDirectDraw(firstParam); - return LOG_RESULT(reinterpret_cast>(Dll::g_origProcs.*origFunc)( - firstParam, params...)); - } - - template - FuncPtr getDirectDrawFuncPtr(FuncPtr) - { - return &directDrawFunc; + return LOG_RESULT(reinterpret_cast(Dll::g_origProcs.*origFunc)(firstParam, params...)); } std::string getDirName(const std::string& path) @@ -190,7 +183,7 @@ namespace #define HOOK_DDRAW_PROC(proc) \ Compat::hookFunction( \ reinterpret_cast(Dll::g_origProcs.proc), \ - getDirectDrawFuncPtr<&Dll::Procs::proc>(static_cast(nullptr)), \ + static_cast(&directDrawFunc<&Dll::Procs::proc, decltype(&proc)>), \ #proc); BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) diff --git a/DDrawCompat/Gdi/WinProc.cpp b/DDrawCompat/Gdi/WinProc.cpp index 00eb6cc..869ed06 100644 --- a/DDrawCompat/Gdi/WinProc.cpp +++ b/DDrawCompat/Gdi/WinProc.cpp @@ -459,7 +459,6 @@ namespace Gdi HOOK_FUNCTION(user32, UpdateLayeredWindow, updateLayeredWindow); HOOK_FUNCTION(user32, UpdateLayeredWindowIndirect, updateLayeredWindowIndirect); - CoInitialize(nullptr); SetWinEventHook(EVENT_OBJECT_CREATE, EVENT_OBJECT_CREATE, Dll::g_currentModule, &objectCreateEvent, GetCurrentProcessId(), 0, WINEVENT_INCONTEXT); SetWinEventHook(EVENT_OBJECT_STATECHANGE, EVENT_OBJECT_STATECHANGE,