From a9f0b8f8f53530136e62dc9c868138129752eeb7 Mon Sep 17 00:00:00 2001 From: FunkyFr3sh Date: Wed, 11 Sep 2024 15:47:31 +0200 Subject: [PATCH] don't let messages pass through with peek/getmessage hooks --- src/winapi_hooks.c | 26 ++++++++++++++++++-------- src/wndproc.c | 3 ++- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/winapi_hooks.c b/src/winapi_hooks.c index 68dc9dd6bb..c6efbf53f4 100644 --- a/src/winapi_hooks.c +++ b/src/winapi_hooks.c @@ -612,7 +612,7 @@ HHOOK WINAPI fake_SetWindowsHookExA(int idHook, HOOKPROC lpfn, HINSTANCE hmod, D return result; } -BOOL HandleMessage(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax) +void HandleMessage(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax, UINT wRemoveMsg) { if (g_ddraw.ref && g_ddraw.width) { @@ -645,7 +645,14 @@ BOOL HandleMessage(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMa InterlockedExchange((LONG*)&g_ddraw.cursor.y, y); mouse_lock(); - //return FALSE; + + if (!wMsgFilterMin && + !wMsgFilterMax && + !(wRemoveMsg & (PM_QS_INPUT | PM_QS_PAINT | PM_QS_POSTMESSAGE | PM_QS_SENDMESSAGE))) + { + lpMsg->message = WM_NULL; + break; + } } /* fall through for lParam */ } @@ -666,7 +673,13 @@ BOOL HandleMessage(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMa if (!g_config.devmode && !g_mouse_locked) { // Does not work with 'New Robinson' - //return FALSE; + if (!wMsgFilterMin && + !wMsgFilterMax && + !(wRemoveMsg & (PM_QS_INPUT | PM_QS_PAINT | PM_QS_POSTMESSAGE | PM_QS_SENDMESSAGE))) + { + lpMsg->message = WM_NULL; + break; + } } if (lpMsg->message == WM_MOUSEWHEEL) @@ -709,11 +722,8 @@ BOOL HandleMessage(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMa break; } - } } - - return TRUE; } BOOL WINAPI fake_GetMessageA(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax) @@ -747,7 +757,7 @@ BOOL WINAPI fake_GetMessageA(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wM if (g_config.hook_getmessage) { - HandleMessage(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax); + HandleMessage(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax, PM_REMOVE); } } @@ -785,7 +795,7 @@ BOOL WINAPI fake_PeekMessageA(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT w if (g_config.hook_peekmessage) { - HandleMessage(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax); + HandleMessage(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax, wRemoveMsg); } } diff --git a/src/wndproc.c b/src/wndproc.c index 0d65fce2ea..811bef3119 100644 --- a/src/wndproc.c +++ b/src/wndproc.c @@ -22,7 +22,7 @@ LRESULT CALLBACK fake_WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam if (uMsg != WM_MOUSEMOVE && uMsg != WM_NCMOUSEMOVE && uMsg != WM_NCHITTEST && uMsg != WM_SETCURSOR && uMsg != WM_KEYUP && uMsg != WM_KEYDOWN && uMsg != WM_CHAR && uMsg != WM_DEADCHAR && uMsg != WM_INPUT && uMsg != WM_UNICHAR && uMsg != WM_IME_CHAR && uMsg != WM_IME_KEYDOWN && uMsg != WM_IME_KEYUP && uMsg != WM_TIMER && - uMsg != WM_D3D9DEVICELOST) + uMsg != WM_D3D9DEVICELOST && uMsg != WM_NULL) { TRACE( " uMsg = %s (%d), wParam = %08X (%d), lParam = %08X (%d, LO=%d HI=%d)\n", @@ -42,6 +42,7 @@ LRESULT CALLBACK fake_WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam switch (uMsg) { + case WM_NULL: case WM_MOVING: case WM_NCLBUTTONDOWN: case WM_NCLBUTTONUP: