From 24a73ccc6d3b94be99503d79cc0ac9c5daef0a04 Mon Sep 17 00:00:00 2001 From: FunkyFr3sh Date: Sat, 7 Oct 2023 09:03:11 +0200 Subject: [PATCH] #251 hook GetMessage for Enemy Infestation --- inc/config.h | 1 + inc/hook.h | 3 ++- inc/winapi_hooks.h | 1 + src/config.c | 4 +++- src/hook.c | 2 ++ src/winapi_hooks.c | 28 +++++++++++++++++++++++----- 6 files changed, 32 insertions(+), 7 deletions(-) diff --git a/inc/config.h b/inc/config.h index 97d9755..dc35419 100644 --- a/inc/config.h +++ b/inc/config.h @@ -45,6 +45,7 @@ typedef struct CNCDDRAWCONFIG int resolutions; int fixchilds; BOOL hook_peekmessage; + BOOL hook_getmessage; /* Undocumented settings */ diff --git a/inc/hook.h b/inc/hook.h index 1663f99..ed453fc 100644 --- a/inc/hook.h +++ b/inc/hook.h @@ -47,7 +47,7 @@ typedef int (WINAPI* STRETCHDIBITSPROC)( typedef BOOL (WINAPI* SETFOREGROUNDWINDOWPROC)(HWND hWnd); typedef HHOOK(WINAPI* SETWINDOWSHOOKEXAPROC)(int, HOOKPROC, HINSTANCE, DWORD); typedef BOOL(WINAPI* PEEKMESSAGEAPROC)(LPMSG, HWND, UINT, UINT, UINT); - +typedef BOOL(WINAPI* GETMESSAGEAPROC)(LPMSG, HWND, UINT, UINT); typedef int (WINAPI* GETDEVICECAPSPROC)(HDC, int); typedef HFONT(WINAPI* CREATEFONTINDIRECTAPROC)(CONST LOGFONT*); @@ -92,6 +92,7 @@ extern STRETCHDIBITSPROC real_StretchDIBits; extern SETFOREGROUNDWINDOWPROC real_SetForegroundWindow; extern SETWINDOWSHOOKEXAPROC real_SetWindowsHookExA; extern PEEKMESSAGEAPROC real_PeekMessageA; +extern GETMESSAGEAPROC real_GetMessageA; extern GETDEVICECAPSPROC real_GetDeviceCaps; extern CREATEFONTINDIRECTAPROC real_CreateFontIndirectA; extern CREATEFONTAPROC real_CreateFontA; diff --git a/inc/winapi_hooks.h b/inc/winapi_hooks.h index b2962da..a66f475 100644 --- a/inc/winapi_hooks.h +++ b/inc/winapi_hooks.h @@ -32,6 +32,7 @@ HWND WINAPI fake_GetForegroundWindow(void); BOOL WINAPI fake_SetForegroundWindow(HWND hWnd); HHOOK WINAPI fake_SetWindowsHookExA(int idHook, HOOKPROC lpfn, HINSTANCE hmod, DWORD dwThreadId); BOOL WINAPI fake_PeekMessageA(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax, UINT wRemoveMsg); +BOOL WINAPI fake_GetMessageA(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax); int WINAPI fake_GetDeviceCaps(HDC hdc, int index); BOOL WINAPI fake_StretchBlt( diff --git a/src/config.c b/src/config.c index cb8b656..cad0772 100644 --- a/src/config.c +++ b/src/config.c @@ -62,6 +62,7 @@ void cfg_load() GET_INT(g_config.resolutions, "resolutions", RESLIST_NORMAL); GET_INT(g_config.fixchilds, "fixchilds", FIX_CHILDS_DETECT_PAINT); GET_BOOL(g_config.hook_peekmessage, "hook_peekmessage", FALSE); + GET_BOOL(g_config.hook_getmessage, "hook_getmessage", FALSE); /* Undocumented settings */ @@ -264,8 +265,9 @@ static void cfg_create_ini() "; Note: Disables upscaling if a child window was detected (to ensure the game is fully playable, may look weird though)\n" "fixchilds=2\n" "\n" - "; Enable the following setting if your cursor doesn't work properly when upscaling is enabled\n" + "; Enable one of the following settings if your cursor doesn't work properly when upscaling is enabled\n" "hook_peekmessage=false\n" + "hook_getmessage=false\n" "\n" "\n" "; Undocumented settings - You may or may not change these (You should rather focus on the settings above)\n" diff --git a/src/hook.c b/src/hook.c index 6ae412a..1b654d0 100644 --- a/src/hook.c +++ b/src/hook.c @@ -47,6 +47,7 @@ STRETCHDIBITSPROC real_StretchDIBits = StretchDIBits; SETFOREGROUNDWINDOWPROC real_SetForegroundWindow = SetForegroundWindow; SETWINDOWSHOOKEXAPROC real_SetWindowsHookExA = SetWindowsHookExA; PEEKMESSAGEAPROC real_PeekMessageA = PeekMessageA; +GETMESSAGEAPROC real_GetMessageA = GetMessageA; GETDEVICECAPSPROC real_GetDeviceCaps = GetDeviceCaps; CREATEFONTINDIRECTAPROC real_CreateFontIndirectA = CreateFontIndirectA; CREATEFONTAPROC real_CreateFontA = CreateFontA; @@ -90,6 +91,7 @@ HOOKLIST g_hook_hooklist[] = { "GetTopWindow", (PROC)fake_GetTopWindow, (PROC*)&real_GetTopWindow, 0 }, { "GetForegroundWindow", (PROC)fake_GetForegroundWindow, (PROC*)&real_GetForegroundWindow, 0 }, { "PeekMessageA", (PROC)fake_PeekMessageA, (PROC*)&real_PeekMessageA, 0 }, + { "GetMessageA", (PROC)fake_GetMessageA, (PROC*)&real_GetMessageA, 0 }, { "SetForegroundWindow", (PROC)fake_SetForegroundWindow, (PROC*)&real_SetForegroundWindow, 0 }, { "SetWindowsHookExA", (PROC)fake_SetWindowsHookExA, (PROC*)&real_SetWindowsHookExA, 0 }, { "", NULL, NULL, 0 } diff --git a/src/winapi_hooks.c b/src/winapi_hooks.c index a31e14b..7efbb76 100644 --- a/src/winapi_hooks.c +++ b/src/winapi_hooks.c @@ -593,11 +593,9 @@ HHOOK WINAPI fake_SetWindowsHookExA(int idHook, HOOKPROC lpfn, HINSTANCE hmod, D return real_SetWindowsHookExA(idHook, lpfn, hmod, dwThreadId); } -BOOL WINAPI fake_PeekMessageA(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax, UINT wRemoveMsg) +BOOL HandleMessage(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax) { - BOOL result = real_PeekMessageA(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax, wRemoveMsg); - - if (result && g_ddraw && g_ddraw->width && g_config.hook_peekmessage) + if (g_ddraw && g_ddraw->width) { switch (lpMsg->message) { @@ -690,10 +688,30 @@ BOOL WINAPI fake_PeekMessageA(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT w break; } - + } } + return TRUE; +} + +BOOL WINAPI fake_GetMessageA(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax) +{ + BOOL result = real_GetMessageA(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax); + + if (result && g_config.hook_getmessage) + HandleMessage(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax); + + return result; +} + +BOOL WINAPI fake_PeekMessageA(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax, UINT wRemoveMsg) +{ + BOOL result = real_PeekMessageA(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax, wRemoveMsg); + + if (result && g_config.hook_peekmessage) + HandleMessage(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax); + return result; }