Skip to content

Commit

Permalink
hook BitBlt
Browse files Browse the repository at this point in the history
  • Loading branch information
FunkyFr3sh committed May 25, 2024
1 parent 0bce13b commit 2f2367e
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 3 deletions.
2 changes: 2 additions & 0 deletions inc/hook.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ typedef BOOL (WINAPI* SHOWWINDOWPROC)(HWND, int);
typedef HWND(WINAPI* GETTOPWINDOWPROC)(HWND);
typedef HWND(WINAPI* GETFOREGROUNDWINDOWPROC)();
typedef BOOL(WINAPI* STRETCHBLTPROC)(HDC, int, int, int, int, HDC, int, int, int, int, DWORD);
typedef BOOL(WINAPI* BITBLTPROC)(HDC, int, int, int, int, HDC, int, int, DWORD);

typedef int (WINAPI* SETDIBITSTODEVICEPROC)(
HDC, int, int, DWORD, DWORD, int, int, UINT, UINT, const VOID*, const BITMAPINFO*, UINT);
Expand Down Expand Up @@ -97,6 +98,7 @@ extern SHOWWINDOWPROC real_ShowWindow;
extern GETTOPWINDOWPROC real_GetTopWindow;
extern GETFOREGROUNDWINDOWPROC real_GetForegroundWindow;
extern STRETCHBLTPROC real_StretchBlt;
extern BITBLTPROC real_BitBlt;
extern SETDIBITSTODEVICEPROC real_SetDIBitsToDevice;
extern STRETCHDIBITSPROC real_StretchDIBits;
extern SETFOREGROUNDWINDOWPROC real_SetForegroundWindow;
Expand Down
3 changes: 3 additions & 0 deletions inc/winapi_hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ int WINAPI fake_GetDeviceCaps(HDC hdc, int index);
BOOL WINAPI fake_StretchBlt(
HDC hdcDest, int xDest, int yDest, int wDest, int hDest, HDC hdcSrc, int xSrc, int ySrc, int wSrc, int hSrc, DWORD rop);

BOOL WINAPI fake_BitBlt(
HDC hdc, int x, int y, int cx, int cy, HDC hdcSrc, int x1, int y1, DWORD rop);

int WINAPI fake_SetDIBitsToDevice(
HDC, int, int, DWORD, DWORD, int, int, UINT, UINT, const VOID*, const BITMAPINFO*, UINT);

Expand Down
4 changes: 2 additions & 2 deletions src/ddsurface.c
Original file line number Diff line number Diff line change
Expand Up @@ -573,11 +573,11 @@ HRESULT dds_BltFast(
}
else
{
BitBlt(dst_dc, dst_x, dst_y, dst_w, dst_h, src_dc, src_x, src_y, SRCCOPY);
real_BitBlt(dst_dc, dst_x, dst_y, dst_w, dst_h, src_dc, src_x, src_y, SRCCOPY);
}

/*
BitBlt(
real_BitBlt(
dst_dc,
dwX,
dwY,
Expand Down
2 changes: 2 additions & 0 deletions src/hook.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ SHOWWINDOWPROC real_ShowWindow = ShowWindow;
GETTOPWINDOWPROC real_GetTopWindow = GetTopWindow;
GETFOREGROUNDWINDOWPROC real_GetForegroundWindow = GetForegroundWindow;
STRETCHBLTPROC real_StretchBlt = StretchBlt;
BITBLTPROC real_BitBlt = BitBlt;
SETDIBITSTODEVICEPROC real_SetDIBitsToDevice = SetDIBitsToDevice;
STRETCHDIBITSPROC real_StretchDIBits = StretchDIBits;
SETFOREGROUNDWINDOWPROC real_SetForegroundWindow = SetForegroundWindow;
Expand Down Expand Up @@ -127,6 +128,7 @@ HOOKLIST g_hook_hooklist[] =
{
"gdi32.dll",
{
{ "BitBlt", (PROC)fake_BitBlt, (PROC*)&real_BitBlt, HOOK_SKIP_2 },
{ "StretchBlt", (PROC)fake_StretchBlt, (PROC*)&real_StretchBlt, HOOK_SKIP_2 },
{ "SetDIBitsToDevice", (PROC)fake_SetDIBitsToDevice, (PROC*)&real_SetDIBitsToDevice, HOOK_SKIP_2 },
{ "StretchDIBits", (PROC)fake_StretchDIBits, (PROC*)&real_StretchDIBits, HOOK_SKIP_2 },
Expand Down
2 changes: 1 addition & 1 deletion src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ BOOL CALLBACK util_enum_child_proc(HWND hwnd, LPARAM lparam)

real_MapWindowPoints(HWND_DESKTOP, g_ddraw.hwnd, (LPPOINT)&pos, 2);

BitBlt(dst_dc, 0, 0, size.right, size.bottom, src_dc, pos.left, pos.top, SRCCOPY);
real_BitBlt(dst_dc, 0, 0, size.right, size.bottom, src_dc, pos.left, pos.top, SRCCOPY);

ReleaseDC(hwnd, dst_dc);
}
Expand Down
42 changes: 42 additions & 0 deletions src/winapi_hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,48 @@ BOOL WINAPI fake_StretchBlt(
return real_StretchBlt(hdcDest, xDest, yDest, wDest, hDest, hdcSrc, xSrc, ySrc, wSrc, hSrc, rop);
}

BOOL WINAPI fake_BitBlt(
HDC hdc,
int x,
int y,
int cx,
int cy,
HDC hdcSrc,
int x1,
int y1,
DWORD rop)
{
if (g_ddraw.ref && g_ddraw.hwnd && WindowFromDC(hdc) == g_ddraw.hwnd)
{
if (g_ddraw.primary && (g_ddraw.primary->bpp == 16 || g_ddraw.primary->bpp == 32 || g_ddraw.primary->palette))
{
HDC primary_dc;
dds_GetDC(g_ddraw.primary, &primary_dc);

if (primary_dc)
{
int result =
real_BitBlt(
primary_dc,
x,
y,
cx,
cy,
hdcSrc,
x1,
y1,
rop);

dds_ReleaseDC(g_ddraw.primary, primary_dc);

return result;
}
}
}

return real_BitBlt(hdc, x, y, cx, cy, hdcSrc, x1, y1, rop);
}

int WINAPI fake_SetDIBitsToDevice(
HDC hdc,
int xDest,
Expand Down

0 comments on commit 2f2367e

Please sign in to comment.