2121
2222#include < cstdio>
2323#include < filesystem>
24+ #include < Hook.hpp>
2425
2526REDECL (EngineDemoRecorder::SetSignonState);
2627REDECL (EngineDemoRecorder::StartRecording);
@@ -346,6 +347,10 @@ DETOUR_COMMAND(EngineDemoRecorder::record) {
346347 }
347348}
348349
350+ Memory::Patch *g_StartupDemoFile_headerNamePatch;
351+ Memory::Patch *g_StartupDemoHeader_headerNamePatch;
352+ std::string g_uniqueDemoHeaderName;
353+
349354bool EngineDemoRecorder::Init () {
350355 auto disconnect = engine->cl ->Original (Offsets::Disconnect);
351356 auto demorecorder = Memory::DerefDeref<void *>(disconnect + Offsets::demorecorder);
@@ -355,6 +360,19 @@ bool EngineDemoRecorder::Init() {
355360 this ->s_ClientDemoRecorder ->Hook (EngineDemoRecorder::StopRecording_Hook, EngineDemoRecorder::StopRecording, Offsets::StopRecording);
356361 if (!sar.game ->Is (SourceGame_INFRA | SourceGame_Portal2_2011)) {
357362 this ->s_ClientDemoRecorder ->Hook (EngineDemoRecorder::RecordCustomData_Hook, EngineDemoRecorder::RecordCustomData, Offsets::RecordCustomData);
363+
364+ uint32_t uniqueId = static_cast <uint32_t >(time (NULL ));
365+ g_uniqueDemoHeaderName = Utils::ssprintf (" demoheader_%08x.tmp" , uniqueId);
366+
367+ auto uniqueDemoHeaderName = g_uniqueDemoHeaderName.c_str ();
368+ auto uniqueDemoHeaderNamePtr = (unsigned char *)&uniqueDemoHeaderName;
369+
370+ g_StartupDemoFile_headerNamePatch = new Memory::Patch ();
371+ auto StartupDemoFile = Memory::Scan (this ->Name (), Offsets::StartupDemoFile);
372+ g_StartupDemoFile_headerNamePatch->Execute (StartupDemoFile + Offsets::StartupDemoFile_HeaderName, uniqueDemoHeaderNamePtr, 4 );
373+ g_StartupDemoHeader_headerNamePatch = new Memory::Patch ();
374+ auto StartupDemoHeader = Memory::Scan (this ->Name (), Offsets::StartupDemoHeader);
375+ g_StartupDemoHeader_headerNamePatch->Execute (StartupDemoHeader + Offsets::StartupDemoHeader_HeaderName, uniqueDemoHeaderNamePtr, 4 );
358376 }
359377
360378 this ->GetRecordingTick = s_ClientDemoRecorder->Original <_GetRecordingTick>(Offsets::GetRecordingTick);
@@ -371,6 +389,11 @@ bool EngineDemoRecorder::Init() {
371389 return this ->hasLoaded = this ->s_ClientDemoRecorder ;
372390}
373391void EngineDemoRecorder::Shutdown () {
392+ g_StartupDemoFile_headerNamePatch->Restore ();
393+ SAFE_DELETE (g_StartupDemoFile_headerNamePatch);
394+ g_StartupDemoHeader_headerNamePatch->Restore ();
395+ SAFE_DELETE (g_StartupDemoHeader_headerNamePatch);
396+
374397 Interface::Delete (this ->s_ClientDemoRecorder );
375398 Command::Unhook (" stop" , EngineDemoRecorder::stop_callback);
376399 Command::Unhook (" record" , EngineDemoRecorder::record_callback);
0 commit comments