From 871ccbf19609acc1db69f03f04937ebd1ea9c526 Mon Sep 17 00:00:00 2001 From: FunkyFr3sh Date: Wed, 20 Mar 2024 05:35:36 +0100 Subject: [PATCH] hook GetKeyState and GetAsyncKeyState for infantry --- inc/hook.h | 6 +++++- inc/version.h | 2 +- inc/winapi_hooks.h | 2 ++ src/hook.c | 4 ++++ src/winapi_hooks.c | 22 ++++++++++++++++++++++ src/wndproc.c | 2 +- 6 files changed, 35 insertions(+), 3 deletions(-) diff --git a/inc/hook.h b/inc/hook.h index 6ebb33b..ebb7c01 100644 --- a/inc/hook.h +++ b/inc/hook.h @@ -17,7 +17,7 @@ typedef struct HOOKLISTDATA { HMODULE mod; } HOOKLISTDATA; -typedef struct HOOKLIST { char module_name[32]; HOOKLISTDATA data[30]; } HOOKLIST; +typedef struct HOOKLIST { char module_name[32]; HOOKLISTDATA data[32]; } HOOKLIST; typedef BOOL(WINAPI* GETCURSORPOSPROC)(LPPOINT); typedef BOOL(WINAPI* CLIPCURSORPROC)(const RECT*); @@ -56,6 +56,8 @@ 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 SHORT(WINAPI* GETKEYSTATEPROC)(int); +typedef SHORT(WINAPI* GETASYNCKEYSTATEPROC)(int); typedef int (WINAPI* GETDEVICECAPSPROC)(HDC, int); typedef HFONT(WINAPI* CREATEFONTINDIRECTAPROC)(CONST LOGFONT*); @@ -101,6 +103,8 @@ extern SETFOREGROUNDWINDOWPROC real_SetForegroundWindow; extern SETWINDOWSHOOKEXAPROC real_SetWindowsHookExA; extern PEEKMESSAGEAPROC real_PeekMessageA; extern GETMESSAGEAPROC real_GetMessageA; +extern GETKEYSTATEPROC real_GetKeyState; +extern GETASYNCKEYSTATEPROC real_GetAsyncKeyState; extern GETDEVICECAPSPROC real_GetDeviceCaps; extern CREATEFONTINDIRECTAPROC real_CreateFontIndirectA; extern CREATEFONTAPROC real_CreateFontA; diff --git a/inc/version.h b/inc/version.h index a75a5b5..7dd8747 100644 --- a/inc/version.h +++ b/inc/version.h @@ -7,7 +7,7 @@ #define VERSION_MAJOR 6 #define VERSION_MINOR 3 #define VERSION_BUILD 0 -#define VERSION_REVISION 0 +#define VERSION_REVISION 1 #define VERSION VERSION_MAJOR, VERSION_MINOR, VERSION_BUILD, VERSION_REVISION #define VERSION_STRING ver_str(VERSION_MAJOR, VERSION_MINOR, VERSION_BUILD, VERSION_REVISION) diff --git a/inc/winapi_hooks.h b/inc/winapi_hooks.h index a66f475..839eccc 100644 --- a/inc/winapi_hooks.h +++ b/inc/winapi_hooks.h @@ -33,6 +33,8 @@ 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); +SHORT WINAPI fake_GetKeyState(int nVirtKey); +SHORT WINAPI fake_GetAsyncKeyState(int vKey); int WINAPI fake_GetDeviceCaps(HDC hdc, int index); BOOL WINAPI fake_StretchBlt( diff --git a/src/hook.c b/src/hook.c index 5646765..d8f72a7 100644 --- a/src/hook.c +++ b/src/hook.c @@ -49,6 +49,8 @@ SETFOREGROUNDWINDOWPROC real_SetForegroundWindow = SetForegroundWindow; SETWINDOWSHOOKEXAPROC real_SetWindowsHookExA = SetWindowsHookExA; PEEKMESSAGEAPROC real_PeekMessageA = PeekMessageA; GETMESSAGEAPROC real_GetMessageA = GetMessageA; +GETKEYSTATEPROC real_GetKeyState = GetKeyState; +GETASYNCKEYSTATEPROC real_GetAsyncKeyState = GetAsyncKeyState; GETDEVICECAPSPROC real_GetDeviceCaps = GetDeviceCaps; CREATEFONTINDIRECTAPROC real_CreateFontIndirectA = CreateFontIndirectA; CREATEFONTAPROC real_CreateFontA = CreateFontA; @@ -93,6 +95,8 @@ HOOKLIST g_hook_hooklist[] = { "GetForegroundWindow", (PROC)fake_GetForegroundWindow, (PROC*)&real_GetForegroundWindow, 0 }, { "PeekMessageA", (PROC)fake_PeekMessageA, (PROC*)&real_PeekMessageA, 0 }, { "GetMessageA", (PROC)fake_GetMessageA, (PROC*)&real_GetMessageA, 0 }, + { "GetKeyState", (PROC)fake_GetKeyState, (PROC*)&real_GetKeyState, 0 }, + { "GetAsyncKeyState", (PROC)fake_GetAsyncKeyState, (PROC*)&real_GetAsyncKeyState, 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 6492f59..a16d860 100644 --- a/src/winapi_hooks.c +++ b/src/winapi_hooks.c @@ -716,6 +716,28 @@ BOOL WINAPI fake_PeekMessageA(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT w return result; } +SHORT WINAPI fake_GetKeyState(int nVirtKey) +{ + if (g_config.infantryhack && g_ddraw && g_ddraw->hwnd) + { + if (real_GetForegroundWindow() != g_ddraw->hwnd) + return 0; + } + + return GetKeyState(nVirtKey); +} + +SHORT WINAPI fake_GetAsyncKeyState(int vKey) +{ + if (g_config.infantryhack && g_ddraw && g_ddraw->hwnd) + { + if (real_GetForegroundWindow() != g_ddraw->hwnd) + return 0; + } + + return GetAsyncKeyState(vKey); +} + int WINAPI fake_GetDeviceCaps(HDC hdc, int index) { if (g_ddraw && diff --git a/src/wndproc.c b/src/wndproc.c index b4451b8..d545046 100644 --- a/src/wndproc.c +++ b/src/wndproc.c @@ -667,7 +667,7 @@ LRESULT CALLBACK fake_WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam { /* let it pass through once (tiberian sun) */ static BOOL one_time; - + if (wParam && !one_time && g_config.tshack) { one_time = TRUE;