From 18f2e27409c817bad7274bb8fdbd51fab3704d02 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Thu, 9 Jan 2025 17:08:47 +0100 Subject: [PATCH] Engine: implement support for loading ui_mainmenu.rpak For future updates, this allows for customizing the main menu to its full extend without modifying larger ui rpak files as we separate all title screen assets and put it into this new pak. --- src/engine/host_cmd.cpp | 36 ++++++++++++++++++++++++++++++++++++ src/engine/host_cmd.h | 11 ++++++++++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/src/engine/host_cmd.cpp b/src/engine/host_cmd.cpp index 560c3c58..a166f652 100644 --- a/src/engine/host_cmd.cpp +++ b/src/engine/host_cmd.cpp @@ -1,5 +1,6 @@ #include "core/stdafx.h" #include "tier0/commandline.h" +#include "rtech/pak/pakstate.h" #include "host_cmd.h" #include "common.h" #include "client/client.h" @@ -7,6 +8,38 @@ #include "windows/id3dx.h" #endif // !DEDICATED +#ifndef DEDICATED +static void DoNothing(){}; + +/* +================== +Host_SetupUIMaterials + + setup and initialize + UI materials +================== +*/ +static void Host_SetupUIMaterials() +{ + // Don't sync during video init as this is where this function is called + // from. We restore the function pointer after we loaded the pak file. + void* const oldSyncFn = g_pakGlobals->threadSyncFunc; + g_pakGlobals->threadSyncFunc = DoNothing; + + static const char* const pakFileName = "ui_mainmenu.rpak"; + const PakHandle_t pak = g_pakLoadApi->LoadAsync(pakFileName, AlignedMemAlloc(), 3, false); + + // NOTE: make sure to wait for the async load, as the pak must be loaded + // before we continue processing UI materials. + if (pak == PAK_INVALID_HANDLE || !g_pakLoadApi->WaitForAsyncLoad(pak, DoNothing)) + Error(eDLL_T::ENGINE, EXIT_FAILURE, "Failed to load pak file '%s'\n", pakFileName); + + g_pakGlobals->threadSyncFunc = oldSyncFn; + + v_Host_SetupUIMaterials(); +} +#endif // !DEDICATED + /* ================== Host_Shutdown @@ -81,6 +114,9 @@ static bool DFS_InitializeFeatureFlagDefinitions(const char* pszFeatureFlags) /////////////////////////////////////////////////////////////////////////////// void VHostCmd::Detour(const bool bAttach) const { +#ifndef DEDICATED + DetourSetup(&v_Host_SetupUIMaterials, &Host_SetupUIMaterials, bAttach); +#endif // !DEDICATED DetourSetup(&v_Host_Shutdown, &Host_Shutdown, bAttach); DetourSetup(&v_Host_Status_PrintClient, &Host_Status_PrintClient, bAttach); DetourSetup(&v_DFS_InitializeFeatureFlagDefinitions, &DFS_InitializeFeatureFlagDefinitions, bAttach); diff --git a/src/engine/host_cmd.h b/src/engine/host_cmd.h index 6cb0786b..011d87c5 100644 --- a/src/engine/host_cmd.h +++ b/src/engine/host_cmd.h @@ -19,8 +19,11 @@ extern EngineParms_t* g_pEngineParms; /* ==== HOST ============================================================================================================================================================ */ inline void(*v_Host_Init)(); +#ifndef DEDICATED inline void(*v_Host_Init_DuringVideo)(bool* bDedicated); inline void(*v_Host_Init_PostVideo)(bool* bDedicated); +inline void(*v_Host_SetupUIMaterials)(); +#endif // !DEDICATED inline void(*v_Host_Shutdown)(); inline bool(*v_Host_NewGame)(char* pszMapName, char* pszMapGroup, bool bLoadGame, char bBackground, LARGE_INTEGER PerformanceCount); inline void(*v_Host_Disconnect)(bool bShowMainMenu); @@ -38,8 +41,11 @@ class VHostCmd : public IDetour virtual void GetAdr(void) const { LogFunAdr("Host_Init", v_Host_Init); +#ifndef DEDICATED LogFunAdr("Host_Init_DuringVideo", v_Host_Init_DuringVideo); LogFunAdr("Host_Init_PostVideo", v_Host_Init_PostVideo); + LogFunAdr("Host_SetupUIMaterials", v_Host_SetupUIMaterials); +#endif // !DEDICATED LogFunAdr("Host_Shutdown", v_Host_Shutdown); LogFunAdr("Host_Disconnect", v_Host_Disconnect); LogFunAdr("Host_NewGame", v_Host_NewGame); @@ -53,11 +59,14 @@ class VHostCmd : public IDetour virtual void GetFun(void) const { g_GameDll.FindPatternSIMD("88 4C 24 08 53 55 56 57 48 83 EC 68").GetPtr(v_Host_Init); +#ifndef DEDICATED g_GameDll.FindPatternSIMD("48 89 5C 24 ?? 48 89 74 24 ?? 48 89 7C 24 ?? 55 41 54 41 55 41 56 41 57 48 8D AC 24 ?? ?? ?? ?? B8 ?? ?? ?? ?? E8 ?? ?? ?? ?? 48 2B E0 48 8B D9").GetPtr(v_Host_Init_DuringVideo); + g_GameDll.FindPatternSIMD("48 8B C4 41 56 48 81 EC ?? ?? ?? ?? 45 33 F6").GetPtr(v_Host_Init_PostVideo); + g_GameDll.FindPatternSIMD("48 89 5C 24 ?? 48 89 6C 24 ?? 48 89 74 24 ?? 57 41 56 41 57 48 83 EC ?? 48 8B 05 ?? ?? ?? ?? 48 8D 3D").GetPtr(v_Host_SetupUIMaterials); +#endif // !DEDICATED g_GameDll.FindPatternSIMD("48 8B C4 ?? 41 54 41 55 48 81 EC 70 04 ?? ?? F2 0F 10 05 ?? ?? ?? 0B").GetPtr(v_Host_NewGame); g_GameDll.FindPatternSIMD("40 53 48 83 EC 30 0F B6 D9").GetPtr(v_Host_Disconnect); g_GameDll.FindPatternSIMD("40 56 57 41 56 48 81 EC ?? ?? ?? ??").GetPtr(v_Host_ChangeLevel); - g_GameDll.FindPatternSIMD("48 8B C4 41 56 48 81 EC ?? ?? ?? ?? 45 33 F6").GetPtr(v_Host_Init_PostVideo); g_GameDll.FindPatternSIMD("48 8B C4 48 83 EC ?? 80 3D ?? ?? ?? ?? ?? 0F 85 ?? ?? ?? ?? 8B 15 ?? ?? ?? ??").GetPtr(v_Host_Shutdown); g_GameDll.FindPatternSIMD("48 89 5C 24 ?? 48 89 6C 24 ?? 56 57 41 56 48 83 EC 60 48 8B A9 ?? ?? ?? ??").GetPtr(v_Host_Status_PrintClient);