1
0
mirror of https://github.com/FunkyFr3sh/cnc-ddraw.git synced 2025-03-15 06:04:49 +01:00

#251 hook GetMessage for Enemy Infestation

This commit is contained in:
FunkyFr3sh 2023-10-07 09:03:11 +02:00
parent 43aa290d1e
commit 24a73ccc6d
6 changed files with 32 additions and 7 deletions

View File

@ -45,6 +45,7 @@ typedef struct CNCDDRAWCONFIG
int resolutions;
int fixchilds;
BOOL hook_peekmessage;
BOOL hook_getmessage;
/* Undocumented settings */

View File

@ -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;

View File

@ -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(

View File

@ -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"

View File

@ -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 }

View File

@ -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;
}