Skip to content

Commit

Permalink
hook SelectPalette
Browse files Browse the repository at this point in the history
  • Loading branch information
FunkyFr3sh committed Dec 15, 2024
1 parent 6c67db5 commit a5a4204
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions inc/hook.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ 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 HPALETTE(WINAPI* SELECTPALETTEPROC)(HDC, HPALETTE, BOOL);

typedef HMODULE(WINAPI* LOADLIBRARYAPROC)(LPCSTR);
typedef HMODULE(WINAPI* LOADLIBRARYWPROC)(LPCWSTR);
Expand Down Expand Up @@ -119,6 +120,7 @@ extern GETDEVICECAPSPROC real_GetDeviceCaps;
extern CREATEFONTINDIRECTAPROC real_CreateFontIndirectA;
extern CREATEFONTAPROC real_CreateFontA;
extern GETSYSTEMPALETTEENTRIESPROC real_GetSystemPaletteEntries;
extern SELECTPALETTEPROC real_SelectPalette;
extern LOADLIBRARYAPROC real_LoadLibraryA;
extern LOADLIBRARYWPROC real_LoadLibraryW;
extern LOADLIBRARYEXAPROC real_LoadLibraryExA;
Expand Down
1 change: 1 addition & 0 deletions inc/winapi_hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,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);
HPALETTE WINAPI fake_SelectPalette(HDC, HPALETTE, BOOL);

HMODULE WINAPI fake_LoadLibraryA(LPCSTR lpLibFileName);
HMODULE WINAPI fake_LoadLibraryW(LPCWSTR lpLibFileName);
Expand Down
2 changes: 2 additions & 0 deletions src/hook.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ GETDEVICECAPSPROC real_GetDeviceCaps = GetDeviceCaps;
CREATEFONTINDIRECTAPROC real_CreateFontIndirectA = CreateFontIndirectA;
CREATEFONTAPROC real_CreateFontA = CreateFontA;
GETSYSTEMPALETTEENTRIESPROC real_GetSystemPaletteEntries = GetSystemPaletteEntries;
SELECTPALETTEPROC real_SelectPalette = SelectPalette;
LOADLIBRARYAPROC real_LoadLibraryA = LoadLibraryA;
LOADLIBRARYWPROC real_LoadLibraryW = LoadLibraryW;
LOADLIBRARYEXAPROC real_LoadLibraryExA = LoadLibraryExA;
Expand Down Expand Up @@ -151,6 +152,7 @@ HOOKLIST g_hook_hooklist[] =
{ "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 },
{ "SelectPalette", (PROC)fake_SelectPalette, (PROC*)&real_SelectPalette, 0 },
{ "CreateFontIndirectA", (PROC)fake_CreateFontIndirectA, (PROC*)&real_CreateFontIndirectA, 0 },
{ "", NULL, NULL, 0 }
}
Expand Down
18 changes: 18 additions & 0 deletions src/winapi_hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -1385,6 +1385,24 @@ UINT WINAPI fake_GetSystemPaletteEntries(HDC hdc, UINT iStart, UINT cEntries, LP
return real_GetSystemPaletteEntries(hdc, iStart, cEntries, pPalEntries);
}

HPALETTE WINAPI fake_SelectPalette(HDC hdc, HPALETTE hPal, BOOL bForceBkgd)
{
if (g_ddraw.ref && g_ddraw.bpp == 8 && WindowFromDC(hdc) == g_ddraw.hwnd)
{
if (g_ddraw.primary && g_ddraw.primary->palette)
{
TRACE("%s [%p]\n", __FUNCTION__, _ReturnAddress());

PALETTEENTRY pal[256];
GetPaletteEntries(hPal, 0, 256, pal);

ddp_SetEntries(g_ddraw.primary->palette, 0, 0, 256, pal);
}
}

return real_SelectPalette(hdc, hPal, bForceBkgd);
}

HMODULE WINAPI fake_LoadLibraryA(LPCSTR lpLibFileName)
{
HMODULE hmod_old = GetModuleHandleA(lpLibFileName);
Expand Down

0 comments on commit a5a4204

Please sign in to comment.