From c95bc9658502160cfd0a4ace2b9560b7ee347393 Mon Sep 17 00:00:00 2001 From: Riley Date: Tue, 28 May 2024 00:45:55 -0500 Subject: [PATCH] Add safety checks in core for renderer. --- Amalgam/src/Core/Core.cpp | 78 +++++++++++++++++++++++++++------------ 1 file changed, 55 insertions(+), 23 deletions(-) diff --git a/Amalgam/src/Core/Core.cpp b/Amalgam/src/Core/Core.cpp index a9075fd..d9aceec 100644 --- a/Amalgam/src/Core/Core.cpp +++ b/Amalgam/src/Core/Core.cpp @@ -8,6 +8,31 @@ #include "../Features/Visuals/Visuals.h" #include "../Hooks/Direct3DDevice9_Present.h" +__forceinline bool CheckRenderIsCompatible() +{ + // Check for if we are running in DXVK mode. + if(GetModuleHandleA("dxvk_d3d9.dll")) + { + MessageBoxA(nullptr, "You are running with graphics options that Amalgam does not support.\n" + "Please remove -vulkan from your launch options and reinject.", "Error", MB_ICONERROR); + U::Core.bUnload = true; + return false; + } + + // Check for if we are running in DirectX 8. + auto cvDXLevel = I::CVar->FindVar("mat_dxlevel"); + auto iLevel = cvDXLevel->GetInt(); + if(iLevel < 90) + { + std::string fmt = std::format("You are running with graphics options that Amalgam does not support.\nPlease remove -dxlevel {} from your launch options and reinject.\0", iLevel); + MessageBox(nullptr, fmt.c_str(), "Error", MB_ICONERROR); + U::Core.bUnload = true; + return false; + } + + return true; +} + void CCore::Load() { // Check the DirectX version @@ -15,11 +40,16 @@ void CCore::Load() U::Signatures.Initialize(); U::Interfaces.Initialize(); + U::ConVars.Initialize(); + + if(!CheckRenderIsCompatible()) + return; + MH_Initialize(); DirectX::Startup(); U::Hooks.Initialize(); DirectX::bIsReady.store(true); - U::ConVars.Initialize(); + F::Materials.LoadMaterials(); F::Commands.Initialize(); @@ -31,32 +61,34 @@ void CCore::Load() void CCore::Unload() { - G::Unload = true; - DirectX::bIsReady.store(false); - - U::Hooks.Unload(); - U::ConVars.Unload(); - F::Materials.UnloadMaterials(); - - F::Visuals.RestoreWorldModulation(); - Vars::Visuals::World::SkyboxChanger.Value = "Off"; // hooks won't run, remove here - if (I::Input->CAM_IsThirdPerson()) + if(!bUnload) { - auto pLocal = H::Entities.GetLocal(); - if (pLocal) + G::Unload = true; + DirectX::bIsReady.store(false); + + U::Hooks.Unload(); + U::ConVars.Unload(); + F::Materials.UnloadMaterials(); + + F::Visuals.RestoreWorldModulation(); + Vars::Visuals::World::SkyboxChanger.Value = "Off"; // hooks won't run, remove here + if(I::Input->CAM_IsThirdPerson()) { - I::Input->CAM_ToFirstPerson(); - pLocal->ThirdPersonSwitch(); + auto pLocal = H::Entities.GetLocal(); + if(pLocal) + { + I::Input->CAM_ToFirstPerson(); + pLocal->ThirdPersonSwitch(); + } } + if(auto cl_wpn_sway_interp = U::ConVars.FindVar("cl_wpn_sway_interp")) + cl_wpn_sway_interp->SetValue(0.f); + if(auto cl_wpn_sway_scale = U::ConVars.FindVar("cl_wpn_sway_scale")) + cl_wpn_sway_scale->SetValue(0.f); + + Sleep(250); } - if (auto cl_wpn_sway_interp = U::ConVars.FindVar("cl_wpn_sway_interp")) - cl_wpn_sway_interp->SetValue(0.f); - if (auto cl_wpn_sway_scale = U::ConVars.FindVar("cl_wpn_sway_scale")) - cl_wpn_sway_scale->SetValue(0.f); - - Sleep(250); - - SDK::Output("Amalgam", "Unloaded", { 175, 150, 255, 255 }); + SDK::Output("Amalgam", "Unloaded", {175, 150, 255, 255}); } bool CCore::ShouldUnload()