port WinVidGameWindowProc

This commit is contained in:
Marcin Kurczewski 2024-06-09 15:54:39 +02:00
parent 1b4c2e737a
commit 14605cc479
No known key found for this signature in database
GPG Key ID: CC65E6FD28CAE42A
7 changed files with 195 additions and 10 deletions

View File

@ -69,10 +69,10 @@
</g>
<g transform="translate(0 116)">
<text x="0" y="7.50">Tomb2.exe progress according to the physical function order:</text>
<text class="todo" style="font-size: 12px; " x="747" y="9"><tspan text-anchor="end"><tspan class="decompiled">41.63% (507)</tspan> · <tspan class="known">55.91% (681)</tspan> · <tspan class="todo">0% (0)</tspan> · <tspan class="unused">2.46% (30)</tspan></tspan></text>
<text class="todo" style="font-size: 12px; " x="747" y="9"><tspan text-anchor="end"><tspan class="decompiled">41.71% (508)</tspan> · <tspan class="known">55.83% (680)</tspan> · <tspan class="todo">0% (0)</tspan> · <tspan class="unused">2.46% (30)</tspan></tspan></text>
<g transform="translate(0 20)">
<rect width="310.94" height="6" x="0" y="0" class="decompiled"/>
<rect width="417.66" height="6" x="310.94" y="0" class="known"/>
<rect width="311.56" height="6" x="0" y="0" class="decompiled"/>
<rect width="417.04" height="6" x="311.56" y="0" class="known"/>
<rect width="18.40" height="6" x="728.60" y="0" class="unused"/>
</g>
<g transform="translate(0 31)">
@ -938,7 +938,7 @@
<rect width="12" height="12" x="135" y="255" class="known"><title>BOOL __stdcall EnumDisplayAdaptersCallback(GUID *lpGUID, LPTSTR lpDriverDescription, LPTSTR lpDriverName, LPVOID lpContext);</title></rect>
<rect width="12" height="12" x="150" y="255" class="decompiled"><title>void __thiscall S_FlaggedString_InitAdapter(DISPLAY_ADAPTER *adapter);</title></rect>
<rect width="12" height="12" x="165" y="255" class="decompiled"><title>bool __cdecl WinVidRegisterGameWindowClass(void);</title></rect>
<rect width="12" height="12" x="180" y="255" class="known"><title>LRESULT __stdcall WinVidGameWindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);</title></rect>
<rect width="12" height="12" x="180" y="255" class="decompiled"><title>LRESULT __stdcall WinVidGameWindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);</title></rect>
<rect width="12" height="12" x="195" y="255" class="known"><title>void __cdecl WinVidResizeGameWindow(HWND hWnd, int32_t edge, LPRECT rect);</title></rect>
<rect width="12" height="12" x="210" y="255" class="known"><title>bool __cdecl WinVidCheckGameWindowPalette(HWND hWnd);</title></rect>
<rect width="12" height="12" x="225" y="255" class="known"><title>bool __cdecl WinVidCreateGameWindow(void);</title></rect>
@ -1298,10 +1298,10 @@
</g>
<g transform="translate(0 546)">
<text x="0" y="7.50">Tomb2.exe progress according to the function sizes:</text>
<text class="todo" style="font-size: 12px; " x="747" y="9"><tspan text-anchor="end"><tspan class="decompiled">38.48%</tspan> · <tspan class="known">61.19%</tspan> · <tspan class="todo">0%</tspan> · <tspan class="unused">0.33%</tspan></tspan></text>
<text class="todo" style="font-size: 12px; " x="747" y="9"><tspan text-anchor="end"><tspan class="decompiled">38.83%</tspan> · <tspan class="known">60.84%</tspan> · <tspan class="todo">0%</tspan> · <tspan class="unused">0.33%</tspan></tspan></text>
<g transform="translate(0 20)">
<rect width="287.46" height="6" x="0" y="0" class="decompiled"/>
<rect width="457.10" height="6" x="287.46" y="0" class="known"/>
<rect width="290.05" height="6" x="0" y="0" class="decompiled"/>
<rect width="454.51" height="6" x="290.05" y="0" class="known"/>
<rect width="2.44" height="6" x="744.56" y="0" class="unused"/>
</g>
<g transform="translate(0 31)">
@ -1348,7 +1348,7 @@
<rect width="28.60" height="28.33" x="177.07" y="130.59" class="decompiled"><title>void __cdecl Camera_Update(void);</title></rect>
<rect width="28.60" height="28.20" x="177.07" y="161.92" class="decompiled"><title>void __cdecl Output_InsertTrans8(const PHD_VBUF *vbuf, int16_t shade);</title></rect>
<rect width="28.60" height="28.12" x="177.07" y="193.12" class="known"><title>void __cdecl MonkControl(int16_t item_num);</title></rect>
<rect width="28.60" height="28.07" x="177.07" y="224.25" class="known"><title>LRESULT __stdcall WinVidGameWindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);</title></rect>
<rect width="28.60" height="28.07" x="177.07" y="224.25" class="decompiled"><title>LRESULT __stdcall WinVidGameWindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);</title></rect>
<rect width="28.60" height="28.04" x="177.07" y="255.32" class="known"><title>int32_t __cdecl SkidooDynamics(ITEM_INFO *skidoo);</title></rect>
<rect width="28.60" height="28.02" x="177.07" y="286.36" class="known"><title>void __cdecl do_sound_option(INVENTORY_ITEM *item);</title></rect>
<rect width="28.60" height="27.36" x="177.07" y="317.38" class="decompiled"><title>void __cdecl Sound_Effect(int32_t sample_id, const XYZ_32 *pos, uint32_t flags);</title></rect>

Before

Width:  |  Height:  |  Size: 360 KiB

After

Width:  |  Height:  |  Size: 360 KiB

View File

@ -3050,7 +3050,7 @@ typedef struct {
0x00445F40 0x01BE -R BOOL __stdcall EnumDisplayAdaptersCallback(GUID *lpGUID, LPTSTR lpDriverDescription, LPTSTR lpDriverName, LPVOID lpContext);
0x00446100 0x0035 + void __thiscall S_FlaggedString_InitAdapter(DISPLAY_ADAPTER *adapter);
0x00446140 0x006A +R bool __cdecl WinVidRegisterGameWindowClass(void);
0x004461B0 0x049F -R LRESULT __stdcall WinVidGameWindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
0x004461B0 0x049F +R LRESULT __stdcall WinVidGameWindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
0x004467C0 0x01C0 -R void __cdecl WinVidResizeGameWindow(HWND hWnd, int32_t edge, LPRECT rect);
0x004469A0 0x00BC -R bool __cdecl WinVidCheckGameWindowPalette(HWND hWnd);
0x00446A60 0x00C6 -R bool __cdecl WinVidCreateGameWindow(void);
@ -3757,3 +3757,4 @@ typedef struct {
0x004D7EC8 - LPDIRECT3DMATERIAL2 g_D3DMaterial;
0x004D7ED4 - LPDIRECTDRAW g_DDrawInterface;
0x00466448 - const char g_GameClassName[];
0x004D7ED8 - bool g_IsGameWindowChanging;

View File

@ -2473,3 +2473,184 @@ bool __cdecl WinVidRegisterGameWindowClass(void)
};
return RegisterClassExA(&wnd_class) != 0;
}
LRESULT CALLBACK
WinVidGameWindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
if (g_IsFMVPlaying) {
switch (Msg) {
case WM_DESTROY:
g_IsGameWindowCreated = false;
g_GameWindowHandle = NULL;
PostQuitMessage(0);
break;
case WM_MOVE:
g_GameWindowPositionX = (int)(short)LOWORD(lParam);
g_GameWindowPositionY = (int)(short)HIWORD(lParam);
break;
case WM_ACTIVATEAPP:
g_IsGameWindowActive = (wParam != 0);
break;
case WM_SYSCOMMAND:
if (wParam == SC_KEYMENU) {
return 0;
}
break;
}
return DefWindowProc(hWnd, Msg, wParam, lParam);
}
switch (Msg) {
case WM_CREATE:
g_IsGameWindowCreated = true;
break;
case WM_DESTROY:
g_IsGameWindowCreated = false;
g_GameWindowHandle = NULL;
PostQuitMessage(0);
break;
case WM_MOVE:
g_GameWindowPositionX = (int)(short)LOWORD(lParam);
g_GameWindowPositionY = (int)(short)HIWORD(lParam);
break;
case WM_SIZE:
switch (wParam) {
case SIZE_RESTORED:
g_IsGameWindowMinimized = false;
g_IsGameWindowMaximized = false;
break;
case SIZE_MAXIMIZED:
g_IsGameWindowMinimized = false;
g_IsGameWindowMaximized = true;
break;
case SIZE_MINIMIZED:
g_IsGameWindowMinimized = true;
g_IsGameWindowMaximized = false;
return DefWindowProc(hWnd, Msg, wParam, lParam);
default:
return DefWindowProc(hWnd, Msg, wParam, lParam);
}
if (g_IsGameFullScreen
|| ((int)(short)LOWORD(lParam) == g_GameWindowWidth
&& (int)(short)HIWORD(lParam) == g_GameWindowHeight)) {
break;
}
g_GameWindowWidth = (int)(short)LOWORD(lParam);
g_GameWindowHeight = (int)(short)HIWORD(lParam);
if (g_IsGameWindowUpdating) {
break;
}
UpdateGameResolution();
break;
case WM_PAINT: {
PAINTSTRUCT paint;
HDC hdc = BeginPaint(hWnd, &paint);
LPDDS surface = (g_SavedAppSettings.render_mode == RM_SOFTWARE)
? g_RenderBufferSurface
: g_BackBufferSurface;
if (g_IsGameFullScreen || !g_PrimaryBufferSurface || !surface) {
HBRUSH brush = (HBRUSH)GetStockObject(BLACK_BRUSH);
FillRect(hdc, &paint.rcPaint, brush);
} else {
if (g_SavedAppSettings.render_mode == RM_SOFTWARE
&& !WinVidCheckGameWindowPalette(hWnd)
&& g_RenderBufferSurface) {
WinVidClearBuffer(g_RenderBufferSurface, NULL, 0);
}
UpdateFrame(false, NULL);
}
EndPaint(hWnd, &paint);
return 0;
}
case WM_ACTIVATE:
if (LOWORD(wParam) && g_DDrawPalette != NULL
&& g_PrimaryBufferSurface != NULL) {
g_PrimaryBufferSurface->lpVtbl->SetPalette(
g_PrimaryBufferSurface, g_DDrawPalette);
}
break;
case WM_ERASEBKGND:
return 1;
case WM_ACTIVATEAPP:
if (wParam && !g_IsGameWindowActive && g_IsGameFullScreen
&& g_SavedAppSettings.render_mode == RM_HARDWARE) {
g_WinVidNeedToResetBuffers = true;
}
g_IsGameWindowActive = (wParam != 0);
break;
case WM_SETCURSOR:
if (g_IsGameFullScreen) {
SetCursor(NULL);
return 1;
}
break;
case WM_GETMINMAXINFO:
if (WinVidGetMinMaxInfo((LPMINMAXINFO)lParam)) {
return 0;
}
break;
case WM_NCPAINT:
case WM_NCLBUTTONDOWN:
case WM_NCLBUTTONDBLCLK:
case WM_NCRBUTTONDOWN:
case WM_NCRBUTTONDBLCLK:
case WM_NCMBUTTONDOWN:
case WM_NCMBUTTONDBLCLK:
if (g_IsGameFullScreen) {
return 0;
}
break;
case WM_SYSCOMMAND:
if (wParam == SC_KEYMENU) {
return 0;
}
break;
case WM_SIZING:
WinVidResizeGameWindow(hWnd, wParam, (LPRECT)lParam);
break;
case WM_MOVING:
if (g_IsGameFullScreen || g_IsGameWindowMaximized) {
GetWindowRect(hWnd, (LPRECT)lParam);
return 1;
}
break;
case WM_ENTERSIZEMOVE:
g_IsGameWindowChanging = true;
break;
case WM_EXITSIZEMOVE:
g_IsGameWindowChanging = false;
break;
case WM_PALETTECHANGED:
if (hWnd != (HWND)wParam && !g_IsGameFullScreen && g_DDrawPalette) {
InvalidateRect(hWnd, NULL, FALSE);
}
break;
}
return DefWindowProc(hWnd, Msg, wParam, lParam);
}

View File

@ -114,3 +114,5 @@ bool __cdecl WinVidGetDisplayAdapters(void);
bool __cdecl EnumerateDisplayAdapters(
DISPLAY_ADAPTER_LIST *display_adapter_list);
bool __cdecl WinVidRegisterGameWindowClass(void);
LRESULT CALLBACK
WinVidGameWindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);

View File

@ -444,7 +444,6 @@
#define GiantYetiControl ((void __cdecl (*)(int16_t item_num))0x00443050)
#define YetiControl ((void __cdecl (*)(int16_t item_num))0x00443350)
#define EnumDisplayAdaptersCallback ((BOOL __stdcall (*)(GUID *lpGUID, LPTSTR lpDriverDescription, LPTSTR lpDriverName, LPVOID lpContext))0x00445F40)
#define WinVidGameWindowProc ((LRESULT __stdcall (*)(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam))0x004461B0)
#define WinVidResizeGameWindow ((void __cdecl (*)(HWND hWnd, int32_t edge, LPRECT rect))0x004467C0)
#define WinVidCheckGameWindowPalette ((bool __cdecl (*)(HWND hWnd))0x004469A0)
#define WinVidCreateGameWindow ((bool __cdecl (*)(void))0x00446A60)

View File

@ -179,6 +179,7 @@ extern const char *g_TR2XVersion;
#define g_D3DMaterial (*(LPDIRECT3DMATERIAL2*)0x004D7EC8)
#define g_MinWindowClientHeight (*(int32_t*)0x004D7ED0)
#define g_DDrawInterface (*(LPDIRECTDRAW*)0x004D7ED4)
#define g_IsGameWindowChanging (*(bool*)0x004D7ED8)
#define g_MaxWindowHeight (*(int32_t*)0x004D7EDC)
#define g_DDraw (*(LPDIRECTDRAW3*)0x004D7EE0)
#define g_IsGameWindowCreated (*(bool*)0x004D7EE4)

View File

@ -156,6 +156,7 @@ static void Inject_Decomp(const bool enable)
INJECT(enable, 0x00445E50, WinVidGetDisplayAdapters);
INJECT(enable, 0x00445F20, EnumerateDisplayAdapters);
INJECT(enable, 0x00446140, WinVidRegisterGameWindowClass);
INJECT(enable, 0x004461B0, WinVidGameWindowProc);
}
static void Inject_Background(const bool enable)