Skip to content

Commit

Permalink
don't let messages pass through with peek/getmessage hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
FunkyFr3sh committed Sep 11, 2024
1 parent 2353363 commit a9f0b8f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
26 changes: 18 additions & 8 deletions src/winapi_hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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 */
}
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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);
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/wndproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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:
Expand Down

0 comments on commit a9f0b8f

Please sign in to comment.