1
0
mirror of https://github.com/FunkyFr3sh/cnc-ddraw.git synced 2025-03-15 06:04:49 +01:00

add better forground window detection and always enable new GetKeyState hooks

This commit is contained in:
FunkyFr3sh 2024-03-20 21:31:05 +01:00
parent c8d4cd997e
commit f57055fd8c
3 changed files with 12 additions and 6 deletions

View File

@ -8,6 +8,7 @@
HMODULE WINAPI util_enumerate_modules(_In_opt_ HMODULE hModuleLast);
BOOL util_is_bad_read_ptr(void* p);
BOOL util_is_minimized(HWND hwnd);
BOOL util_in_foreground();
BOOL util_is_avx_supported();
void util_limit_game_ticks();
void util_update_bnet_pos(int newX, int newY);

View File

@ -100,6 +100,13 @@ BOOL util_is_minimized(HWND hwnd)
return IsIconic(hwnd) || (real_GetClientRect(hwnd, &rc) && (rc.right - rc.left == 0 || rc.bottom - rc.top == 0));
}
BOOL util_in_foreground()
{
DWORD process_id = 0;
return GetWindowThreadProcessId(real_GetForegroundWindow(), &process_id) && process_id == GetCurrentProcessId();
}
BOOL util_is_avx_supported()
{
const DWORD XMM_STATE_BIT = 1 << 1;

View File

@ -718,10 +718,9 @@ BOOL WINAPI fake_PeekMessageA(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT w
SHORT WINAPI fake_GetKeyState(int nVirtKey)
{
if (g_config.infantryhack && g_ddraw && g_ddraw->hwnd)
if (g_config.windowed && g_ddraw && g_ddraw->hwnd && !util_in_foreground())
{
if (real_GetForegroundWindow() != g_ddraw->hwnd)
return 0;
return 0;
}
return real_GetKeyState(nVirtKey);
@ -729,10 +728,9 @@ SHORT WINAPI fake_GetKeyState(int nVirtKey)
SHORT WINAPI fake_GetAsyncKeyState(int vKey)
{
if (g_config.infantryhack && g_ddraw && g_ddraw->hwnd)
if (g_config.windowed && g_ddraw && g_ddraw->hwnd && !util_in_foreground())
{
if (real_GetForegroundWindow() != g_ddraw->hwnd)
return 0;
return 0;
}
return real_GetAsyncKeyState(vKey);