From 474af97e89a47cd1db1cc491a08195e1c33b3df7 Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Wed, 20 Mar 2024 22:55:03 +0100 Subject: [PATCH] port HideDDrawGameWindow --- docs/progress.svg | 16 ++++++++-------- docs/progress.txt | 2 +- src/decomp/decomp.c | 24 ++++++++++++++++++++++++ src/decomp/decomp.h | 1 + src/global/funcs.h | 1 - src/inject_exec.c | 1 + 6 files changed, 35 insertions(+), 10 deletions(-) diff --git a/docs/progress.svg b/docs/progress.svg index 62db1f9f..fe9b23a7 100644 --- a/docs/progress.svg +++ b/docs/progress.svg @@ -69,10 +69,10 @@ Tomb2.exe progress according to the physical function order: -32.43% (395) · 65.11% (793) · 0.41% (5) · 2.05% (25) +32.51% (396) · 65.02% (792) · 0.41% (5) · 2.05% (25) - - + + @@ -914,7 +914,7 @@ void __cdecl WinVidHideGameWindow(void); void __cdecl WinVidSetGameWindowSize(int32_t width, int32_t height); bool __cdecl ShowDDrawGameWindow(bool active); -bool __cdecl HideDDrawGameWindow(void); +bool __cdecl HideDDrawGameWindow(void); HRESULT __cdecl DDrawSurfaceCreate(LPDDSDESC dsp, LPDDS *surface); HRESULT __cdecl DDrawSurfaceRestoreLost(LPDDS surface1, LPDDS surface2, bool blank); bool __cdecl WinVidClearBuffer(LPDDS surface, LPRECT rect, DWORD fillColor); @@ -1299,10 +1299,10 @@ Tomb2.exe progress according to the function sizes: -29.33% · 70.35% · 0% · 0.32% +29.37% · 70.31% · 0% · 0.32% - - + + @@ -1912,7 +1912,7 @@ bool __cdecl WinVidGoFullScreen(DISPLAY_MODE *dispMode); bool __cdecl IntroFMV(const char *file_name1, const char *file_name2); void __cdecl DyingMonk(int16_t item_num); -bool __cdecl HideDDrawGameWindow(void); +bool __cdecl HideDDrawGameWindow(void); int32_t __cdecl CreateTexturePalette(RGB888 *pal); void __cdecl Lara_SwimTurn(struct ITEM_INFO *item); void __cdecl Sound_UpdateContinued(void); diff --git a/docs/progress.txt b/docs/progress.txt index 5aefa675..c76b008a 100644 --- a/docs/progress.txt +++ b/docs/progress.txt @@ -2573,7 +2573,7 @@ typedef enum GAME_OBJECT_ID { 00445110 0000003A +R void __cdecl WinVidHideGameWindow(void); 00445150 00000035 +R void __cdecl WinVidSetGameWindowSize(int32_t width, int32_t height); 00445190 000000A7 +R bool __cdecl ShowDDrawGameWindow(bool active); -00445240 00000087 -R bool __cdecl HideDDrawGameWindow(void); +00445240 00000087 +R bool __cdecl HideDDrawGameWindow(void); 004452D0 00000044 -R HRESULT __cdecl DDrawSurfaceCreate(LPDDSDESC dsp, LPDDS *surface); 00445320 00000046 -R HRESULT __cdecl DDrawSurfaceRestoreLost(LPDDS surface1, LPDDS surface2, bool blank); 00445370 0000004D -R bool __cdecl WinVidClearBuffer(LPDDS surface, LPRECT rect, DWORD fillColor); diff --git a/src/decomp/decomp.c b/src/decomp/decomp.c index b3ede47e..a34c81f3 100644 --- a/src/decomp/decomp.c +++ b/src/decomp/decomp.c @@ -646,3 +646,27 @@ bool __cdecl ShowDDrawGameWindow(bool active) g_IsDDrawGameWindowShow = true; return true; } + +bool __cdecl HideDDrawGameWindow(void) +{ + if (!g_GameWindowHandle || !g_DDraw) { + return false; + } + if (!g_IsDDrawGameWindowShow) { + return true; + } + + WinVidHideGameWindow(); + g_IsGameWindowUpdating = true; + const HRESULT result = IDirectDraw_SetCooperativeLevel( + g_DDraw, g_GameWindowHandle, DDSCL_NORMAL); + if (SUCCEEDED(result)) { + g_IsDDrawGameWindowShow = false; + SetWindowPos( + g_GameWindowHandle, NULL, g_GameWindowX, g_GameWindowY, 0, 0, + SWP_NOCOPYBITS | SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOSIZE); + } + + g_IsGameWindowUpdating = false; + return SUCCEEDED(result); +} diff --git a/src/decomp/decomp.h b/src/decomp/decomp.h index 13165b3c..4150b9db 100644 --- a/src/decomp/decomp.h +++ b/src/decomp/decomp.h @@ -37,3 +37,4 @@ void __cdecl WinVidShowGameWindow(int32_t cmd_show); void __cdecl WinVidHideGameWindow(void); void __cdecl WinVidSetGameWindowSize(int32_t width, int32_t height); bool __cdecl ShowDDrawGameWindow(bool active); +bool __cdecl HideDDrawGameWindow(void); diff --git a/src/global/funcs.h b/src/global/funcs.h index 32e6f1ec..3523618a 100644 --- a/src/global/funcs.h +++ b/src/global/funcs.h @@ -513,7 +513,6 @@ #define DDrawRelease ((void __cdecl (*)(void))0x00444C30) #define GameWindowCalculateSizeFromClient ((void __cdecl (*)(int32_t *width, int32_t *height))0x00444C70) #define GameWindowCalculateSizeFromClientByZero ((void __cdecl (*)(int32_t *width, int32_t *height))0x00444CF0) -#define HideDDrawGameWindow ((bool __cdecl (*)(void))0x00445240) #define DDrawSurfaceCreate ((HRESULT __cdecl (*)(LPDDSDESC dsp, LPDDS *surface))0x004452D0) #define DDrawSurfaceRestoreLost ((HRESULT __cdecl (*)(LPDDS surface1, LPDDS surface2, bool blank))0x00445320) #define WinVidClearBuffer ((bool __cdecl (*)(LPDDS surface, LPRECT rect, DWORD fillColor))0x00445370) diff --git a/src/inject_exec.c b/src/inject_exec.c index ca60d157..f487fbcd 100644 --- a/src/inject_exec.c +++ b/src/inject_exec.c @@ -66,6 +66,7 @@ static void Inject_Decomp(void) INJECT(1, 0x00445110, WinVidHideGameWindow); INJECT(1, 0x00445150, WinVidSetGameWindowSize); INJECT(1, 0x00445190, ShowDDrawGameWindow); + INJECT(1, 0x00445240, HideDDrawGameWindow); INJECT(1, 0x004471F0, DInputCreate); INJECT(1, 0x00447220, DInputRelease); INJECT(1, 0x00447240, WinInReadKeyboard);