From 1c263ca573bdaae7c3c81cb1237a8f3868e1ddb2 Mon Sep 17 00:00:00 2001 From: FunkyFr3sh Date: Sun, 15 Dec 2024 00:46:44 +0100 Subject: [PATCH] hook GetSystemPaletteEntries --- inc/hook.h | 3 +++ inc/winapi_hooks.h | 1 + src/ddpalette.c | 11 +++++++++-- src/hook.c | 2 ++ src/winapi_hooks.c | 15 +++++++++++++++ 5 files changed, 30 insertions(+), 2 deletions(-) diff --git a/inc/hook.h b/inc/hook.h index 92301d42c9..299ac75721 100644 --- a/inc/hook.h +++ b/inc/hook.h @@ -64,6 +64,8 @@ typedef SHORT(WINAPI* GETASYNCKEYSTATEPROC)(int); typedef int (WINAPI* GETDEVICECAPSPROC)(HDC, int); typedef HFONT(WINAPI* CREATEFONTINDIRECTAPROC)(CONST LOGFONT*); typedef HFONT(WINAPI* CREATEFONTAPROC)(int, int, int, int, int, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, LPCTSTR); +typedef UINT(WINAPI* GETSYSTEMPALETTEENTRIESPROC)(HDC, UINT, UINT, LPPALETTEENTRY); + typedef HMODULE(WINAPI* LOADLIBRARYAPROC)(LPCSTR); typedef HMODULE(WINAPI* LOADLIBRARYWPROC)(LPCWSTR); typedef HMODULE(WINAPI* LOADLIBRARYEXAPROC)(LPCSTR, HANDLE, DWORD); @@ -116,6 +118,7 @@ extern GETASYNCKEYSTATEPROC real_GetAsyncKeyState; extern GETDEVICECAPSPROC real_GetDeviceCaps; extern CREATEFONTINDIRECTAPROC real_CreateFontIndirectA; extern CREATEFONTAPROC real_CreateFontA; +extern GETSYSTEMPALETTEENTRIESPROC real_GetSystemPaletteEntries; extern LOADLIBRARYAPROC real_LoadLibraryA; extern LOADLIBRARYWPROC real_LoadLibraryW; extern LOADLIBRARYEXAPROC real_LoadLibraryExA; diff --git a/inc/winapi_hooks.h b/inc/winapi_hooks.h index fa5c6350f6..3569abb038 100644 --- a/inc/winapi_hooks.h +++ b/inc/winapi_hooks.h @@ -58,6 +58,7 @@ int WINAPI fake_StretchDIBits( HFONT WINAPI fake_CreateFontIndirectA(CONST LOGFONTA*); HFONT WINAPI fake_CreateFontA(int, int, int, int, int, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, LPCTSTR); +UINT WINAPI fake_GetSystemPaletteEntries(HDC, UINT, UINT, LPPALETTEENTRY); HMODULE WINAPI fake_LoadLibraryA(LPCSTR lpLibFileName); HMODULE WINAPI fake_LoadLibraryW(LPCWSTR lpLibFileName); diff --git a/src/ddpalette.c b/src/ddpalette.c index e7bde4b74d..af18231b9d 100644 --- a/src/ddpalette.c +++ b/src/ddpalette.c @@ -14,11 +14,15 @@ HRESULT ddp_GetEntries( DWORD dwNumEntries, LPPALETTEENTRY lpEntries) { - for (int i = dwBase, x = 0; i < dwBase + dwNumEntries; i++, x++) + if (!lpEntries) + return DDERR_INVALIDPARAMS; + + for (int i = dwBase, x = 0; i < dwBase + dwNumEntries && i < 256; i++, x++) { lpEntries[x].peRed = This->data_rgb[i].rgbRed; lpEntries[x].peGreen = This->data_rgb[i].rgbGreen; lpEntries[x].peBlue = This->data_rgb[i].rgbBlue; + lpEntries[x].peFlags = 0; } return DD_OK; @@ -31,7 +35,10 @@ HRESULT ddp_SetEntries( DWORD dwCount, LPPALETTEENTRY lpEntries) { - for (int i = dwStartingEntry, x = 0; i < dwStartingEntry + dwCount; i++, x++) + if (!lpEntries) + return DDERR_INVALIDPARAMS; + + for (int i = dwStartingEntry, x = 0; i < dwStartingEntry + dwCount && i < 256; i++, x++) { This->data_bgr[i] = (lpEntries[x].peBlue << 16) | (lpEntries[x].peGreen << 8) | lpEntries[x].peRed; diff --git a/src/hook.c b/src/hook.c index 6533a4da23..3229a3a336 100644 --- a/src/hook.c +++ b/src/hook.c @@ -57,6 +57,7 @@ GETASYNCKEYSTATEPROC real_GetAsyncKeyState = GetAsyncKeyState; GETDEVICECAPSPROC real_GetDeviceCaps = GetDeviceCaps; CREATEFONTINDIRECTAPROC real_CreateFontIndirectA = CreateFontIndirectA; CREATEFONTAPROC real_CreateFontA = CreateFontA; +GETSYSTEMPALETTEENTRIESPROC real_GetSystemPaletteEntries = GetSystemPaletteEntries; LOADLIBRARYAPROC real_LoadLibraryA = LoadLibraryA; LOADLIBRARYWPROC real_LoadLibraryW = LoadLibraryW; LOADLIBRARYEXAPROC real_LoadLibraryExA = LoadLibraryExA; @@ -149,6 +150,7 @@ HOOKLIST g_hook_hooklist[] = { "StretchDIBits", (PROC)fake_StretchDIBits, (PROC*)&real_StretchDIBits, HOOK_SKIP_2 }, { "GetDeviceCaps", (PROC)fake_GetDeviceCaps, (PROC*)&real_GetDeviceCaps, HOOK_LOCAL_ONLY }, { "CreateFontA", (PROC)fake_CreateFontA, (PROC*)&real_CreateFontA, 0 }, + { "GetSystemPaletteEntries", (PROC)fake_GetSystemPaletteEntries, (PROC*)&real_GetSystemPaletteEntries, 0 }, { "CreateFontIndirectA", (PROC)fake_CreateFontIndirectA, (PROC*)&real_CreateFontIndirectA, 0 }, { "", NULL, NULL, 0 } } diff --git a/src/winapi_hooks.c b/src/winapi_hooks.c index eebc18136f..b909e10bdb 100644 --- a/src/winapi_hooks.c +++ b/src/winapi_hooks.c @@ -20,6 +20,7 @@ #include "dllmain.h" #include "hook.h" #include "directinput.h" +#include "ddpalette.h" BOOL WINAPI fake_GetCursorPos(LPPOINT lpPoint) @@ -1348,6 +1349,20 @@ HFONT WINAPI fake_CreateFontA( lpszFace); } +UINT WINAPI fake_GetSystemPaletteEntries(HDC hdc, UINT iStart, UINT cEntries, LPPALETTEENTRY pPalEntries) +{ + if (g_ddraw.ref && g_ddraw.bpp == 8 && WindowFromDC(hdc) == g_ddraw.hwnd) + { + if (g_ddraw.primary && g_ddraw.primary->palette) + { + ddp_GetEntries(g_ddraw.primary->palette, 0, iStart, cEntries, pPalEntries); + return cEntries - iStart; + } + } + + return real_GetSystemPaletteEntries(hdc, iStart, cEntries, pPalEntries); +} + HMODULE WINAPI fake_LoadLibraryA(LPCSTR lpLibFileName) { HMODULE hmod_old = GetModuleHandleA(lpLibFileName);