From 2f2367e5b5602b023b95394e5ed37ccd988ec274 Mon Sep 17 00:00:00 2001 From: FunkyFr3sh Date: Sat, 25 May 2024 07:29:30 +0200 Subject: [PATCH] hook BitBlt --- inc/hook.h | 2 ++ inc/winapi_hooks.h | 3 +++ src/ddsurface.c | 4 ++-- src/hook.c | 2 ++ src/utils.c | 2 +- src/winapi_hooks.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 52 insertions(+), 3 deletions(-) diff --git a/inc/hook.h b/inc/hook.h index ebb7c0149f..ae3a4044ba 100644 --- a/inc/hook.h +++ b/inc/hook.h @@ -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); @@ -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; diff --git a/inc/winapi_hooks.h b/inc/winapi_hooks.h index 839ecccff1..d7e6efe486 100644 --- a/inc/winapi_hooks.h +++ b/inc/winapi_hooks.h @@ -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); diff --git a/src/ddsurface.c b/src/ddsurface.c index 54714178fe..30377aed5a 100644 --- a/src/ddsurface.c +++ b/src/ddsurface.c @@ -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, diff --git a/src/hook.c b/src/hook.c index f25b020a40..1b2efb34ff 100644 --- a/src/hook.c +++ b/src/hook.c @@ -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; @@ -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 }, diff --git a/src/utils.c b/src/utils.c index 60136503ee..4d29bfb09b 100644 --- a/src/utils.c +++ b/src/utils.c @@ -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); } diff --git a/src/winapi_hooks.c b/src/winapi_hooks.c index b1e6754b17..c530b43221 100644 --- a/src/winapi_hooks.c +++ b/src/winapi_hooks.c @@ -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,