1
0
mirror of https://github.com/narzoul/DDrawCompat synced 2024-12-30 08:55:36 +01:00

Make GetCursorPos constant in WM_MOUSEMOVE handler

Fixes most of the cursor trails in Lego Loco (#179).
This commit is contained in:
narzoul 2023-07-16 16:34:58 +02:00
parent ca485fc15c
commit df0b071ddf
3 changed files with 32 additions and 2 deletions

View File

@ -191,7 +191,7 @@ namespace Gdi
g_prevCursorInfo = {};
POINT pos = {};
GetCursorPos(&pos);
CALL_ORIG_FUNC(GetCursorPos)(&pos);
SetCursorPos(pos.x, pos.y);
}

View File

@ -2,6 +2,7 @@
#include <set>
#include <Windows.h>
#include <Windowsx.h>
#include <Common/Hook.h>
#include <Common/Log.h>
@ -54,6 +55,7 @@ namespace
Compat::SrwLock g_windowProcSrwLock;
std::map<HWND, WindowProc> g_windowProc;
thread_local POINT* g_cursorPos = nullptr;
thread_local unsigned g_inCreateDialog = 0;
thread_local unsigned g_inMessageBox = 0;
thread_local unsigned g_inWindowProc = 0;
@ -88,6 +90,7 @@ namespace
{
LOG_FUNC("ddcWindowProc", Compat::WindowMessageStruct(hwnd, uMsg, wParam, lParam));
ScopedIncrement inc(g_inWindowProc);
POINT cursorPos = {};
switch (uMsg)
{
@ -111,6 +114,15 @@ namespace
onInitDialog(hwnd);
break;
case WM_MOUSEMOVE:
if (1 == g_inWindowProc)
{
cursorPos = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
ClientToScreen(hwnd, &cursorPos);
g_cursorPos = &cursorPos;
}
break;
case WM_SYNCPAINT:
if (Gdi::Window::isTopLevelWindow(hwnd))
{
@ -190,6 +202,13 @@ namespace
onInitMenuPopup(reinterpret_cast<HMENU>(wParam));
break;
case WM_MOUSEMOVE:
if (1 == g_inWindowProc)
{
g_cursorPos = nullptr;
}
break;
case WM_NCDESTROY:
onDestroyWindow(hwnd);
break;
@ -247,6 +266,16 @@ namespace
return LOG_RESULT(CALL_ORIG_FUNC(SetWindowLongA)(hWnd, nIndex, dwNewLong));
}
BOOL WINAPI getCursorPos(LPPOINT lpPoint)
{
if (lpPoint && g_cursorPos)
{
*lpPoint = *g_cursorPos;
return TRUE;
}
return CALL_ORIG_FUNC(GetCursorPos)(lpPoint);
}
BOOL WINAPI getMessage(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax,
decltype(&GetMessageA) origGetMessage)
{
@ -719,6 +748,7 @@ namespace Gdi
HOOK_FUNCTION(user32, DialogBoxParamW, createDialog<DialogBoxParamW>);
HOOK_FUNCTION(user32, DialogBoxIndirectParamA, createDialog<DialogBoxIndirectParamA>);
HOOK_FUNCTION(user32, DialogBoxIndirectParamW, createDialog<DialogBoxIndirectParamW>);
HOOK_FUNCTION(user32, GetCursorPos, getCursorPos);
HOOK_FUNCTION(user32, GetMessageA, getMessageA);
HOOK_FUNCTION(user32, GetMessageW, getMessageW);
HOOK_FUNCTION(user32, GetWindowLongA, getWindowLongA);

View File

@ -103,7 +103,7 @@ namespace
{
POINT cp = g_cursorPos;
POINT origCp = {};
GetCursorPos(&origCp);
CALL_ORIG_FUNC(GetCursorPos)(&origCp);
cp.x += (llHook.pt.x - origCp.x);
cp.y += (llHook.pt.y - origCp.y);