Skip to content

Commit

Permalink
hook BeginPaint
Browse files Browse the repository at this point in the history
  • Loading branch information
FunkyFr3sh committed Dec 30, 2024
1 parent d1af7fa commit 743df36
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
4 changes: 3 additions & 1 deletion inc/hook.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ typedef struct HOOKLISTDATA {
HMODULE mod;
} HOOKLISTDATA;

typedef struct HOOKLIST { char module_name[32]; HOOKLISTDATA data[38]; } HOOKLIST;
typedef struct HOOKLIST { char module_name[32]; HOOKLISTDATA data[39]; } HOOKLIST;

typedef BOOL(WINAPI* GETCURSORPOSPROC)(LPPOINT);
typedef BOOL(WINAPI* CLIPCURSORPROC)(const RECT*);
Expand Down Expand Up @@ -64,6 +64,7 @@ typedef BOOL(WINAPI* SETWINDOWPLACEMENTPROC)(HWND, const WINDOWPLACEMENT*);
typedef BOOL(WINAPI* ENUMDISPLAYSETTINGSAPROC)(LPCSTR, DWORD, DEVMODEA*);
typedef LRESULT(WINAPI* DEFWINDOWPROCAPROC)(HWND, UINT, WPARAM, LPARAM);
typedef HWND(WINAPI* SETPARENTPROC)(HWND, HWND);
typedef HDC (WINAPI* BEGINPAINTPROC)(HWND, LPPAINTSTRUCT);
typedef SHORT(WINAPI* GETKEYSTATEPROC)(int);
typedef SHORT(WINAPI* GETASYNCKEYSTATEPROC)(int);

Expand Down Expand Up @@ -127,6 +128,7 @@ extern SETWINDOWPLACEMENTPROC real_SetWindowPlacement;
extern ENUMDISPLAYSETTINGSAPROC real_EnumDisplaySettingsA;
extern DEFWINDOWPROCAPROC real_DefWindowProcA;
extern SETPARENTPROC real_SetParent;
extern BEGINPAINTPROC real_BeginPaint;
extern GETKEYSTATEPROC real_GetKeyState;
extern GETASYNCKEYSTATEPROC real_GetAsyncKeyState;
extern GETDEVICECAPSPROC real_GetDeviceCaps;
Expand Down
1 change: 1 addition & 0 deletions inc/winapi_hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ BOOL WINAPI fake_SetWindowPlacement(HWND hWnd, const WINDOWPLACEMENT* lpwndpl);
BOOL WINAPI fake_EnumDisplaySettingsA(LPCSTR lpszDeviceName, DWORD iModeNum, DEVMODEA* lpDevMode);
LRESULT WINAPI fake_DefWindowProcA(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
HWND WINAPI fake_SetParent(HWND hWndChild, HWND hWndNewParent);
HDC WINAPI fake_BeginPaint(HWND hWnd, LPPAINTSTRUCT lpPaint);
SHORT WINAPI fake_GetKeyState(int nVirtKey);
SHORT WINAPI fake_GetAsyncKeyState(int vKey);
int WINAPI fake_GetDeviceCaps(HDC hdc, int index);
Expand Down
2 changes: 2 additions & 0 deletions src/hook.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ SETWINDOWPLACEMENTPROC real_SetWindowPlacement = SetWindowPlacement;
ENUMDISPLAYSETTINGSAPROC real_EnumDisplaySettingsA = EnumDisplaySettingsA;
DEFWINDOWPROCAPROC real_DefWindowProcA = DefWindowProcA;
SETPARENTPROC real_SetParent = SetParent;
BEGINPAINTPROC real_BeginPaint = BeginPaint;
GETKEYSTATEPROC real_GetKeyState = GetKeyState;
GETASYNCKEYSTATEPROC real_GetAsyncKeyState = GetAsyncKeyState;
GETDEVICECAPSPROC real_GetDeviceCaps = GetDeviceCaps;
Expand Down Expand Up @@ -119,6 +120,7 @@ HOOKLIST g_hook_hooklist[] =
{ "EnumDisplaySettingsA", (PROC)fake_EnumDisplaySettingsA, (PROC*)&real_EnumDisplaySettingsA, 0 },
{ "DefWindowProcA", (PROC)fake_DefWindowProcA, (PROC*)&real_DefWindowProcA, 0 },
{ "SetParent", (PROC)fake_SetParent, (PROC*)&real_SetParent, 0 },
{ "BeginPaint", (PROC)fake_BeginPaint, (PROC*)&real_BeginPaint, 0 },
{ "GetKeyState", (PROC)fake_GetKeyState, (PROC*)&real_GetKeyState, 0 },
{ "GetAsyncKeyState", (PROC)fake_GetAsyncKeyState, (PROC*)&real_GetAsyncKeyState, 0 },
{ "SetForegroundWindow", (PROC)fake_SetForegroundWindow, (PROC*)&real_SetForegroundWindow, 0 },
Expand Down
20 changes: 20 additions & 0 deletions src/winapi_hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,26 @@ HWND WINAPI fake_SetParent(HWND hWndChild, HWND hWndNewParent)
return real_SetParent(hWndChild, hWndNewParent);
}

HDC WINAPI fake_BeginPaint(HWND hWnd, LPPAINTSTRUCT lpPaint)
{
if (g_ddraw.ref && g_ddraw.width && g_ddraw.hwnd && g_ddraw.hwnd == hWnd && lpPaint)
{
HDC result = real_BeginPaint(hWnd, lpPaint);

if (result)
{
lpPaint->rcPaint.left = 0;
lpPaint->rcPaint.top = 0;
lpPaint->rcPaint.right = g_ddraw.width;
lpPaint->rcPaint.bottom = g_ddraw.height;
}

return result;
}

return real_BeginPaint(hWnd, lpPaint);
}

SHORT WINAPI fake_GetKeyState(int nVirtKey)
{
if (g_config.windowed && g_ddraw.ref && g_ddraw.hwnd && !util_in_foreground())
Expand Down

0 comments on commit 743df36

Please sign in to comment.