diff --git a/inc/config.h b/inc/config.h index 593130a..8660c49 100644 --- a/inc/config.h +++ b/inc/config.h @@ -58,7 +58,6 @@ typedef struct CNCDDRAWCONFIG int resolutions; int fixchilds; BOOL hook_peekmessage; - BOOL hook_getmessage; /* Undocumented settings */ diff --git a/src/config.c b/src/config.c index f20e8cb..950d18f 100644 --- a/src/config.c +++ b/src/config.c @@ -68,7 +68,6 @@ 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); GET_STRING("win_version", "", g_config.win_version, sizeof(g_config.win_version)); /* Undocumented settings */ @@ -300,9 +299,8 @@ 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 one of the following settings if your cursor doesn't work properly when upscaling is enabled\n" + "; Enable the following setting 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" @@ -844,7 +842,7 @@ static void cfg_create_ini() "\n" "; Enemy Infestation\n" "[EI]\n" - "hook_getmessage=true\n" + "hook_peekmessage=true\n" "\n" "; Fairy Tale About Father Frost, Ivan and Nastya\n" "[mrazik]\n" diff --git a/src/winapi_hooks.c b/src/winapi_hooks.c index c6efbf5..ed4648c 100644 --- a/src/winapi_hooks.c +++ b/src/winapi_hooks.c @@ -614,15 +614,38 @@ HHOOK WINAPI fake_SetWindowsHookExA(int idHook, HOOKPROC lpfn, HINSTANCE hmod, D void HandleMessage(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax, UINT wRemoveMsg) { - if (g_ddraw.ref && g_ddraw.width) + if (lpMsg && g_ddraw.ref && g_ddraw.hwnd && g_ddraw.width) { - switch (lpMsg->message) + if (!g_config.windowed || real_ScreenToClient(g_ddraw.hwnd, &lpMsg->pt)) + { + int x = max(lpMsg->pt.x - g_ddraw.mouse.x_adjust, 0); + int y = max(lpMsg->pt.y - g_ddraw.mouse.y_adjust, 0); + + if (g_config.adjmouse) + { + x = (DWORD)(roundf(x * g_ddraw.mouse.unscale_x)); + y = (DWORD)(roundf(y * g_ddraw.mouse.unscale_y)); + } + + lpMsg->pt.x = min(x, g_ddraw.width - 1); + lpMsg->pt.y = min(y, g_ddraw.height - 1); + } + else + { + lpMsg->pt.x = InterlockedExchangeAdd((LONG*)&g_ddraw.cursor.x, 0); + lpMsg->pt.y = InterlockedExchangeAdd((LONG*)&g_ddraw.cursor.y, 0); + } + + if (lpMsg->hwnd != g_ddraw.hwnd || !g_config.hook_peekmessage) + return; + + switch (LOWORD(lpMsg->message)) { case WM_LBUTTONUP: case WM_RBUTTONUP: case WM_MBUTTONUP: { - if (!g_config.devmode && !g_mouse_locked) + if (!g_config.devmode && !g_mouse_locked && (wRemoveMsg & PM_REMOVE)) { int x = GET_X_LPARAM(lpMsg->lParam); int y = GET_Y_LPARAM(lpMsg->lParam); @@ -672,7 +695,6 @@ void HandleMessage(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMa { if (!g_config.devmode && !g_mouse_locked) { - // Does not work with 'New Robinson' if (!wMsgFilterMin && !wMsgFilterMax && !(wRemoveMsg & (PM_QS_INPUT | PM_QS_PAINT | PM_QS_POSTMESSAGE | PM_QS_SENDMESSAGE))) @@ -682,7 +704,7 @@ void HandleMessage(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMa } } - if (lpMsg->message == WM_MOUSEWHEEL) + if (LOWORD(lpMsg->message) == WM_MOUSEWHEEL) { POINT pt = { GET_X_LPARAM(lpMsg->lParam), GET_Y_LPARAM(lpMsg->lParam) }; real_ScreenToClient(g_ddraw.hwnd, &pt); @@ -732,33 +754,9 @@ BOOL WINAPI fake_GetMessageA(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wM g_ddraw.last_msg_pull_tick = timeGetTime(); BOOL result = real_GetMessageA(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax); - - if (result && lpMsg && g_ddraw.ref && g_ddraw.hwnd && g_ddraw.width && !g_config.fixmousehook) + if (result) { - if (!g_config.windowed || real_ScreenToClient(g_ddraw.hwnd, &lpMsg->pt)) - { - int x = max(lpMsg->pt.x - g_ddraw.mouse.x_adjust, 0); - int y = max(lpMsg->pt.y - g_ddraw.mouse.y_adjust, 0); - - if (g_config.adjmouse) - { - x = (DWORD)(roundf(x * g_ddraw.mouse.unscale_x)); - y = (DWORD)(roundf(y * g_ddraw.mouse.unscale_y)); - } - - lpMsg->pt.x = min(x, g_ddraw.width - 1); - lpMsg->pt.y = min(y, g_ddraw.height - 1); - } - else - { - lpMsg->pt.x = InterlockedExchangeAdd((LONG*)&g_ddraw.cursor.x, 0); - lpMsg->pt.y = InterlockedExchangeAdd((LONG*)&g_ddraw.cursor.y, 0); - } - - if (g_config.hook_getmessage) - { - HandleMessage(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax, PM_REMOVE); - } + HandleMessage(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax, PM_REMOVE); } return result; @@ -770,33 +768,9 @@ BOOL WINAPI fake_PeekMessageA(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT w g_ddraw.last_msg_pull_tick = timeGetTime(); BOOL result = real_PeekMessageA(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax, wRemoveMsg); - - if (result && lpMsg && g_ddraw.ref && g_ddraw.hwnd && g_ddraw.width && !g_config.fixmousehook) + if (result) { - if (!g_config.windowed || real_ScreenToClient(g_ddraw.hwnd, &lpMsg->pt)) - { - int x = max(lpMsg->pt.x - g_ddraw.mouse.x_adjust, 0); - int y = max(lpMsg->pt.y - g_ddraw.mouse.y_adjust, 0); - - if (g_config.adjmouse) - { - x = (DWORD)(roundf(x * g_ddraw.mouse.unscale_x)); - y = (DWORD)(roundf(y * g_ddraw.mouse.unscale_y)); - } - - lpMsg->pt.x = min(x, g_ddraw.width - 1); - lpMsg->pt.y = min(y, g_ddraw.height - 1); - } - else - { - lpMsg->pt.x = InterlockedExchangeAdd((LONG*)&g_ddraw.cursor.x, 0); - lpMsg->pt.y = InterlockedExchangeAdd((LONG*)&g_ddraw.cursor.y, 0); - } - - if (g_config.hook_peekmessage) - { - HandleMessage(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax, wRemoveMsg); - } + HandleMessage(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax, wRemoveMsg); } return result;