mirror of
https://github.com/FunkyFr3sh/cnc-ddraw.git
synced 2025-03-24 17:49:52 +01:00
merge PeekMessage and GetMessage hooks
This commit is contained in:
parent
a9f0b8f8f5
commit
cd021dc090
@ -58,7 +58,6 @@ typedef struct CNCDDRAWCONFIG
|
|||||||
int resolutions;
|
int resolutions;
|
||||||
int fixchilds;
|
int fixchilds;
|
||||||
BOOL hook_peekmessage;
|
BOOL hook_peekmessage;
|
||||||
BOOL hook_getmessage;
|
|
||||||
|
|
||||||
/* Undocumented settings */
|
/* Undocumented settings */
|
||||||
|
|
||||||
|
@ -68,7 +68,6 @@ void cfg_load()
|
|||||||
GET_INT(g_config.resolutions, "resolutions", RESLIST_NORMAL);
|
GET_INT(g_config.resolutions, "resolutions", RESLIST_NORMAL);
|
||||||
GET_INT(g_config.fixchilds, "fixchilds", FIX_CHILDS_DETECT_PAINT);
|
GET_INT(g_config.fixchilds, "fixchilds", FIX_CHILDS_DETECT_PAINT);
|
||||||
GET_BOOL(g_config.hook_peekmessage, "hook_peekmessage", FALSE);
|
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));
|
GET_STRING("win_version", "", g_config.win_version, sizeof(g_config.win_version));
|
||||||
|
|
||||||
/* Undocumented settings */
|
/* 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"
|
"; Note: Disables upscaling if a child window was detected (to ensure the game is fully playable, may look weird though)\n"
|
||||||
"fixchilds=2\n"
|
"fixchilds=2\n"
|
||||||
"\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_peekmessage=false\n"
|
||||||
"hook_getmessage=false\n"
|
|
||||||
"\n"
|
"\n"
|
||||||
"\n"
|
"\n"
|
||||||
"; Undocumented settings - You may or may not change these (You should rather focus on the settings above)\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"
|
"\n"
|
||||||
"; Enemy Infestation\n"
|
"; Enemy Infestation\n"
|
||||||
"[EI]\n"
|
"[EI]\n"
|
||||||
"hook_getmessage=true\n"
|
"hook_peekmessage=true\n"
|
||||||
"\n"
|
"\n"
|
||||||
"; Fairy Tale About Father Frost, Ivan and Nastya\n"
|
"; Fairy Tale About Father Frost, Ivan and Nastya\n"
|
||||||
"[mrazik]\n"
|
"[mrazik]\n"
|
||||||
|
@ -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)
|
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_LBUTTONUP:
|
||||||
case WM_RBUTTONUP:
|
case WM_RBUTTONUP:
|
||||||
case WM_MBUTTONUP:
|
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 x = GET_X_LPARAM(lpMsg->lParam);
|
||||||
int y = GET_Y_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)
|
if (!g_config.devmode && !g_mouse_locked)
|
||||||
{
|
{
|
||||||
// Does not work with 'New Robinson'
|
|
||||||
if (!wMsgFilterMin &&
|
if (!wMsgFilterMin &&
|
||||||
!wMsgFilterMax &&
|
!wMsgFilterMax &&
|
||||||
!(wRemoveMsg & (PM_QS_INPUT | PM_QS_PAINT | PM_QS_POSTMESSAGE | PM_QS_SENDMESSAGE)))
|
!(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) };
|
POINT pt = { GET_X_LPARAM(lpMsg->lParam), GET_Y_LPARAM(lpMsg->lParam) };
|
||||||
real_ScreenToClient(g_ddraw.hwnd, &pt);
|
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();
|
g_ddraw.last_msg_pull_tick = timeGetTime();
|
||||||
|
|
||||||
BOOL result = real_GetMessageA(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax);
|
BOOL result = real_GetMessageA(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax);
|
||||||
|
if (result)
|
||||||
if (result && lpMsg && g_ddraw.ref && g_ddraw.hwnd && g_ddraw.width && !g_config.fixmousehook)
|
|
||||||
{
|
{
|
||||||
if (!g_config.windowed || real_ScreenToClient(g_ddraw.hwnd, &lpMsg->pt))
|
HandleMessage(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax, PM_REMOVE);
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
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();
|
g_ddraw.last_msg_pull_tick = timeGetTime();
|
||||||
|
|
||||||
BOOL result = real_PeekMessageA(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax, wRemoveMsg);
|
BOOL result = real_PeekMessageA(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax, wRemoveMsg);
|
||||||
|
if (result)
|
||||||
if (result && lpMsg && g_ddraw.ref && g_ddraw.hwnd && g_ddraw.width && !g_config.fixmousehook)
|
|
||||||
{
|
{
|
||||||
if (!g_config.windowed || real_ScreenToClient(g_ddraw.hwnd, &lpMsg->pt))
|
HandleMessage(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax, wRemoveMsg);
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user