diff --git a/src/Components/Modules/MapRotation.cpp b/src/Components/Modules/MapRotation.cpp index fbce8123..7a95a4f7 100644 --- a/src/Components/Modules/MapRotation.cpp +++ b/src/Components/Modules/MapRotation.cpp @@ -39,6 +39,11 @@ namespace Components return this->rotationEntries_.at(index); } + MapRotation::RotationData::rotationEntry& MapRotation::RotationData::peekNextEntry() + { + return this->rotationEntries_.at(this->index_); + } + void MapRotation::RotationData::parse(const std::string& data) { const auto tokens = Utils::String::Split(data, ' '); @@ -74,16 +79,6 @@ namespace Components void MapRotation::LoadRotation(const std::string& data) { - static auto loaded = false; - - if (loaded) - { - // Load the rotation once - return; - } - - loaded = true; - try { DedicatedRotation.parse(data); @@ -98,6 +93,15 @@ namespace Components void MapRotation::LoadMapRotation() { + static auto loaded = false; + if (loaded) + { + // Load the rotation once + return; + } + + loaded = true; + const std::string mapRotation = (*Game::sv_mapRotation)->current.string; // People may have sv_mapRotation empty because they only use 'addMap' or 'addGametype' if (!mapRotation.empty()) @@ -252,6 +256,28 @@ namespace Components ApplyRotation(rotationCurrent); } + void MapRotation::SetNextMap(RotationData& rotation) + { + assert(!rotation.empty()); + + const auto& entry = rotation.peekNextEntry(); + if (entry.first == "map"s) + { + Game::Dvar_SetString(*Game::nextmap, entry.second.data()); + } + } + + void MapRotation::SetNextMap(const char* value) + { + assert(value); + Game::Dvar_SetString(*Game::nextmap, value); + } + + void MapRotation::ClearNextMap() + { + Game::Dvar_SetString(*Game::nextmap, ""); + } + void MapRotation::RandomizeMapRotation() { if (SVRandomMapRotation.get()) @@ -280,6 +306,7 @@ namespace Components { Logger::Debug("Applying {}", (*Game::sv_mapRotationCurrent)->name); ApplyMapRotationCurrent(mapRotationCurrent); + ClearNextMap(); return; } @@ -288,12 +315,14 @@ namespace Components { Logger::Print(Game::CON_CHANNEL_SERVER, "{} is empty or contains invalid data. Restarting map\n", (*Game::sv_mapRotation)->name); RestartCurrentMap(); + SetNextMap("map_restart"); return; } RandomizeMapRotation(); ApplyRotation(DedicatedRotation); + SetNextMap(DedicatedRotation); } MapRotation::MapRotation() diff --git a/src/Components/Modules/MapRotation.hpp b/src/Components/Modules/MapRotation.hpp index 198a63de..34927b70 100644 --- a/src/Components/Modules/MapRotation.hpp +++ b/src/Components/Modules/MapRotation.hpp @@ -32,6 +32,7 @@ namespace Components [[nodiscard]] std::size_t getEntriesSize() const noexcept; rotationEntry& getNextEntry(); + rotationEntry& peekNextEntry(); void parse(const std::string& data); @@ -63,6 +64,11 @@ namespace Components static void RestartCurrentMap(); static void ApplyRotation(RotationData& rotation); static void ApplyMapRotationCurrent(const std::string& data); + + // Utils functions + static void SetNextMap(RotationData& rotation); // Only call this after ApplyRotation + static void SetNextMap(const char* value); + static void ClearNextMap(); static void RandomizeMapRotation(); static void SV_MapRotate_f(); diff --git a/src/Game/Dvars.cpp b/src/Game/Dvars.cpp index 3986092d..c6b207e3 100644 --- a/src/Game/Dvars.cpp +++ b/src/Game/Dvars.cpp @@ -55,6 +55,8 @@ namespace Game const dvar_t** sv_cheats = reinterpret_cast(0x2098DE0); const dvar_t** sv_voiceQuality = reinterpret_cast(0x2098DB0); + const dvar_t** nextmap = reinterpret_cast(0x1AD7924); + const dvar_t** cl_showSend = reinterpret_cast(0xA1E870); const dvar_t** cl_voice = reinterpret_cast(0xB2BB44); const dvar_t** cl_ingame = reinterpret_cast(0xB2BB80); diff --git a/src/Game/Dvars.hpp b/src/Game/Dvars.hpp index 38463a3b..6a8140a5 100644 --- a/src/Game/Dvars.hpp +++ b/src/Game/Dvars.hpp @@ -107,6 +107,8 @@ namespace Game extern const dvar_t** sv_cheats; extern const dvar_t** sv_voiceQuality; + extern const dvar_t** nextmap; + extern const dvar_t** cl_showSend; extern const dvar_t** cl_voice; extern const dvar_t** cl_ingame;