Shutdown dedicated dll properly

Systems where not getting shutdown properly. For dedicated 'ExitProcess()' in the GameDLL caused 'abort()' to get called even when systems where shutdown properly. We call TerminateProcess after all systems have shutdown properly in the SDK and GameDLL.
This commit is contained in:
Amos 2022-02-18 14:00:58 +01:00
parent 9e21284172
commit fd924b56e8
7 changed files with 74 additions and 0 deletions

View File

@ -46,6 +46,14 @@ void R5Dev_Init()
void R5Dev_Shutdown()
{
static bool bShutDown = false;
if (bShutDown)
{
spdlog::error("Recursive shutdown!\n");
return;
}
bShutDown = true;
Systems_Shutdown();
WinSys_Detach();

View File

@ -17,6 +17,7 @@
#include "vpc/interfaces.h"
#include "common/opcodes.h"
#include "launcher/IApplication.h"
#include "launcher/prx.h"
#include "ebisusdk/EbisuSDK.h"
#ifndef DEDICATED
#include "milessdk/win64_rrthreads.h"
@ -83,6 +84,9 @@ void Systems_Init()
// Hook functions
IApplication_Attach();
#ifdef DEDICATED
PRX_Attach();
#endif // DEDICATED
CBaseClient_Attach();
CBaseFileSystem_Attach();
@ -159,6 +163,9 @@ void Systems_Shutdown()
// Unhook functions
IApplication_Detach();
#ifdef DEDICATED
PRX_Detach();
#endif // DEDICATED
CBaseClient_Detach();
CBaseFileSystem_Detach();

View File

@ -5,6 +5,9 @@ namespace
/* ==== ------- ========================================================================================================================================================= */
}
void R5Dev_Init();
void R5Dev_Shutdown();
void Systems_Init();
void Systems_Shutdown();
void PrintHAddress();

View File

@ -207,6 +207,7 @@
<ClInclude Include="engine\sys_engine.h" />
<ClInclude Include="engine\sys_utils.h" />
<ClInclude Include="launcher\IApplication.h" />
<ClInclude Include="launcher\prx.h" />
<ClInclude Include="mathlib\adler32.h" />
<ClInclude Include="mathlib\bits.h" />
<ClInclude Include="mathlib\color.h" />
@ -406,6 +407,7 @@
<ClCompile Include="engine\sys_engine.cpp" />
<ClCompile Include="engine\sys_utils.cpp" />
<ClCompile Include="launcher\IApplication.cpp" />
<ClCompile Include="launcher\prx.cpp" />
<ClCompile Include="mathlib\adler32.cpp" />
<ClCompile Include="mathlib\bits.cpp" />
<ClCompile Include="mathlib\crc32.cpp" />

View File

@ -714,6 +714,9 @@
<ClInclude Include="protoc\sv_rcon.pb.h">
<Filter>thirdparty\protobuf</Filter>
</ClInclude>
<ClInclude Include="launcher\prx.h">
<Filter>sdk\launcher</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="client\IVEngineClient.cpp">
@ -956,6 +959,9 @@
<ClCompile Include="protoc\sv_rcon.pb.cc">
<Filter>thirdparty\protobuf</Filter>
</ClCompile>
<ClCompile Include="launcher\prx.cpp">
<Filter>sdk\launcher</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="r5dev.def" />

24
r5dev/launcher/prx.cpp Normal file
View File

@ -0,0 +1,24 @@
#include <core/stdafx.h>
#include <core/init.h>
#include <launcher/prx.h>
//-----------------------------------------------------------------------------
// Purpose: shutdown and unload SDK
//-----------------------------------------------------------------------------
void h_exit_or_terminate_process(UINT uExitCode)
{
R5Dev_Shutdown();
HANDLE h = GetCurrentProcess();
TerminateProcess(h, uExitCode);
}
void PRX_Attach()
{
DetourAttach((LPVOID*)&exit_or_terminate_process, &h_exit_or_terminate_process);
}
void PRX_Detach()
{
DetourAttach((LPVOID*)&exit_or_terminate_process, &h_exit_or_terminate_process);
}

24
r5dev/launcher/prx.h Normal file
View File

@ -0,0 +1,24 @@
#pragma once
namespace
{
/* ==== PRX ============================================================================================================================================================= */
ADDRESS p_exit_or_terminate_process = g_mGameDll.FindPatternSIMD((std::uint8_t*)"\x40\x53\x48\x83\xEC\x20\x8B\xD9\xE8\x00\x00\x00\x00\x84\xC0", "xxxxxxxxx????xx");
void (*exit_or_terminate_process)(UINT uExitCode) = (void (*)(UINT))p_exit_or_terminate_process.GetPtr(); /*40 53 48 83 EC 20 8B D9 E8 ? ? ? ? 84 C0 */
}
void PRX_Attach();
void PRX_Detach();
///////////////////////////////////////////////////////////////////////////////
class HPRX : public IDetour
{
virtual void debugp()
{
std::cout << "| FUN: exit_or_terminate_process : 0x" << std::hex << std::uppercase << p_exit_or_terminate_process.GetPtr() << std::setw(npad) << " |" << std::endl;
std::cout << "+----------------------------------------------------------------+" << std::endl;
}
};
///////////////////////////////////////////////////////////////////////////////
REGISTER(HPRX);