diff --git a/src/Components/Modules/Theatre.cpp b/src/Components/Modules/Theatre.cpp index 4cbdb746..e8b491f1 100644 --- a/src/Components/Modules/Theatre.cpp +++ b/src/Components/Modules/Theatre.cpp @@ -11,10 +11,25 @@ namespace Components unsigned int Theatre::CurrentSelection; std::vector Theatre::Demos; + Dvar::Var Theatre::CLAutoRecord; + Dvar::Var Theatre::CLDemosKeep; + char Theatre::BaselineSnapshot[131072] = {0}; int Theatre::BaselineSnapshotMsgLen; int Theatre::BaselineSnapshotMsgOff; + nlohmann::json Theatre::DemoInfo::to_json() const + { + return nlohmann::json + { + { "mapname", mapname }, + { "gametype", gametype }, + { "author", author }, + { "length", length }, + { "timestamp", std::to_string(timeStamp) }, + }; + } + void Theatre::GamestateWriteStub(Game::msg_t* msg, char byte) { Game::MSG_WriteLong(msg, 0); @@ -295,14 +310,14 @@ namespace Components } } - uint32_t Theatre::InitCGameStub() + int Theatre::CL_FirstSnapshot_Stub() { - if (Dvar::Var("cl_autoRecord").get() && !*Game::demoPlaying) + if (CLAutoRecord.get() && !*Game::demoPlaying) { std::vector files; auto demos = FileSystem::GetFileList("demos/", "dm_13"); - for (auto demo : demos) + for (auto& demo : demos) { if (Utils::String::StartsWith(demo, "auto_")) { @@ -310,7 +325,7 @@ namespace Components } } - auto numDel = static_cast(files.size()) - Dvar::Var("cl_demosKeep").get(); + auto numDel = static_cast(files.size()) - CLDemosKeep.get(); for (auto i = 0; i < numDel; ++i) { @@ -322,13 +337,13 @@ namespace Components Command::Execute(Utils::String::VA("record auto_%lld", std::time(nullptr)), true); } - return Utils::Hook::Call(0x42BBB0)(); + return Utils::Hook::Call(0x42BBB0)(); // DB_GetLoadedFlags } - void Theatre::MapChangeStub() + void Theatre::SV_SpawnServer_Stub() { StopRecording(); - Utils::Hook::Call(0x464A60)(); + Utils::Hook::Call(0x464A60)(); // Com_SyncThreads } void Theatre::StopRecording() @@ -341,8 +356,8 @@ namespace Components Theatre::Theatre() { - Dvar::Register("cl_autoRecord", true, Game::DVAR_ARCHIVE, "Automatically record games."); - Dvar::Register("cl_demosKeep", 30, 1, 999, Game::DVAR_ARCHIVE, "How many demos to keep with autorecord."); + CLAutoRecord = Dvar::Register("cl_autoRecord", true, Game::DVAR_ARCHIVE, "Automatically record games"); + CLDemosKeep = Dvar::Register("cl_demosKeep", 30, 1, 999, Game::DVAR_ARCHIVE, "How many demos to keep with autorecord"); Utils::Hook(0x5A8370, GamestateWriteStub, HOOK_CALL).install()->quick(); Utils::Hook(0x5A85D2, RecordGamestateStub, HOOK_CALL).install()->quick(); @@ -357,8 +372,8 @@ namespace Components Utils::Hook(0x5A8156, StopRecordStub, HOOK_CALL).install()->quick(); // Autorecording - Utils::Hook(0x5A1D6A, InitCGameStub, HOOK_CALL).install()->quick(); - Utils::Hook(0x4A712A, MapChangeStub, HOOK_CALL).install()->quick(); + Utils::Hook(0x5A1D6A, CL_FirstSnapshot_Stub, HOOK_CALL).install()->quick(); + Utils::Hook(0x4A712A, SV_SpawnServer_Stub, HOOK_CALL).install()->quick(); // UIScripts UIScript::Add("loadDemos", LoadDemos); @@ -372,7 +387,7 @@ namespace Components if (!Dedicated::IsEnabled()) Utils::Hook::Set(0x47440B, "mp/defaultStringTable.csv"); // Change font size - Utils::Hook::Set(0x5AC854, 2); - Utils::Hook::Set(0x5AC85A, 2); + Utils::Hook::Set(0x5AC854, 2); + Utils::Hook::Set(0x5AC85A, 2); } } diff --git a/src/Components/Modules/Theatre.hpp b/src/Components/Modules/Theatre.hpp index 6c61c06d..c5d0481e 100644 --- a/src/Components/Modules/Theatre.hpp +++ b/src/Components/Modules/Theatre.hpp @@ -20,23 +20,16 @@ namespace Components int length; std::time_t timeStamp; - [[nodiscard]] nlohmann::json to_json() const - { - return nlohmann::json - { - { "mapname", mapname }, - { "gametype", gametype }, - { "author", author }, - { "length", length }, - { "timestamp", Utils::String::VA("%lld", timeStamp) } // Ugly, but prevents information loss - }; - } + [[nodiscard]] nlohmann::json to_json() const; }; static DemoInfo CurrentInfo; static unsigned int CurrentSelection; static std::vector Demos; + static Dvar::Var CLAutoRecord; + static Dvar::Var CLDemosKeep; + static char BaselineSnapshot[131072]; static int BaselineSnapshotMsgLen; static int BaselineSnapshotMsgOff; @@ -60,8 +53,8 @@ namespace Components static void ServerTimedOutStub(); static void UISetActiveMenuStub(); - static uint32_t InitCGameStub(); - static void MapChangeStub(); + static int CL_FirstSnapshot_Stub(); + static void SV_SpawnServer_Stub(); static void RecordStub(int channel, char* message, char* file); static void StopRecordStub(int channel, char* message);