From b9c7cabda90c26df437b4e3911843ca1069fc88a Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Sun, 25 Feb 2024 21:15:37 +0100 Subject: [PATCH] ImGui: move initialization code to DX hook setups Also removed unused global declaration 'g_bImGuiInitialized'. --- r5dev/engine/sys_getmodes.cpp | 4 ---- r5dev/materialsystem/cmaterialsystem.cpp | 3 --- r5dev/windows/id3dx.cpp | 6 ++++++ r5dev/windows/id3dx.h | 1 - 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/r5dev/engine/sys_getmodes.cpp b/r5dev/engine/sys_getmodes.cpp index 6df451ea..f38de0e0 100644 --- a/r5dev/engine/sys_getmodes.cpp +++ b/r5dev/engine/sys_getmodes.cpp @@ -17,10 +17,6 @@ bool HCVideoMode_Common__CreateGameWindow(int* pnRect) g_nWindowRect[1] = pnRect[1]; const bool ret = CVideoMode_Common__CreateGameWindow(pnRect); - - if (!ImguiSystem_Init()) - Error(eDLL_T::MS, 0, "ImGui system initialization failed!\n"); - return ret; } diff --git a/r5dev/materialsystem/cmaterialsystem.cpp b/r5dev/materialsystem/cmaterialsystem.cpp index af4ad1d1..db64393f 100644 --- a/r5dev/materialsystem/cmaterialsystem.cpp +++ b/r5dev/materialsystem/cmaterialsystem.cpp @@ -30,9 +30,6 @@ bool CMaterialSystem::Connect(CMaterialSystem* thisptr, const CreateInterfaceFn void CMaterialSystem::Disconnect(CMaterialSystem* thisptr) { -#ifndef MATERIALSYSTEM_NODX - ImguiSystem_Shutdown(); -#endif CMaterialSystem__Disconnect(thisptr); } diff --git a/r5dev/windows/id3dx.cpp b/r5dev/windows/id3dx.cpp index 19c0d55b..f6727648 100644 --- a/r5dev/windows/id3dx.cpp +++ b/r5dev/windows/id3dx.cpp @@ -349,6 +349,9 @@ void DirectX_Init() Assert(0); Error(eDLL_T::COMMON, 0xBAD0C0DE, "Failed to detour process: error code = %08x\n", hr); } + + if (!ImguiSystem_Init()) + Error(eDLL_T::MS, 0, "ImGui system initialization failed!\n"); } void DirectX_Shutdown() @@ -367,6 +370,9 @@ void DirectX_Shutdown() // Commit the transaction DetourTransactionCommit(); + + if (ImguiSystem_IsInitialized()) + ImguiSystem_Shutdown(); } void VDXGI::GetAdr(void) const diff --git a/r5dev/windows/id3dx.h b/r5dev/windows/id3dx.h index 83db0447..c531c89c 100644 --- a/r5dev/windows/id3dx.h +++ b/r5dev/windows/id3dx.h @@ -22,7 +22,6 @@ typedef HRESULT(__stdcall* IDXGIResizeBuffers) (IDXGISwapChain* pSwapChain, UI ///////////////////////////////////////////////////////////////////////////// // Globals -extern BOOL g_bImGuiInitialized; extern UINT g_nWindowRect[2]; // TODO[ AMOS ]: Remove this in favor of CGame's window rect members??? /////////////////////////////////////////////////////////////////////////////