From 835f74065cba8faae67c6ab8dc9b91bdbd465e96 Mon Sep 17 00:00:00 2001 From: Louvenarde Date: Sun, 16 Jun 2024 00:58:16 +0200 Subject: [PATCH] Fix a crash with arena reloading on custom maps --- src/Components/Modules/Friends.cpp | 5 +- src/Components/Modules/Logger.cpp | 289 +++++++++++++++-------------- src/Components/Modules/Maps.cpp | 172 +++++++++-------- src/Components/Modules/Maps.hpp | 9 +- 4 files changed, 250 insertions(+), 225 deletions(-) diff --git a/src/Components/Modules/Friends.cpp b/src/Components/Modules/Friends.cpp index 90cf83c7..cc327e1d 100644 --- a/src/Components/Modules/Friends.cpp +++ b/src/Components/Modules/Friends.cpp @@ -315,7 +315,10 @@ namespace Components Friends::LoggedOn = (Steam::Proxy::SteamUser_ && Steam::Proxy::SteamUser_->LoggedOn()); if (!Steam::Proxy::SteamFriends) return; - Game::UI_UpdateArenas(); + if (Game::Sys_IsMainThread()) + { + Game::UI_UpdateArenas(); + } int count = Steam::Proxy::SteamFriends->GetFriendCount(4); diff --git a/src/Components/Modules/Logger.cpp b/src/Components/Modules/Logger.cpp index 4f54ca63..25a50c60 100644 --- a/src/Components/Modules/Logger.cpp +++ b/src/Components/Modules/Logger.cpp @@ -38,32 +38,32 @@ namespace Components void Logger::MessagePrint(const int channel, const std::string& msg) { static const auto shouldPrint = []() -> bool - { - return Flags::HasFlag("stdout") || Loader::IsPerformingUnitTests(); - }(); + { + return Flags::HasFlag("stdout") || Loader::IsPerformingUnitTests(); + }(); - if (shouldPrint) - { - (void)std::fputs(msg.data(), stdout); - (void)std::fflush(stdout); - return; - } + if (shouldPrint) + { + (void)std::fputs(msg.data(), stdout); + (void)std::fflush(stdout); + return; + } #ifdef _DEBUG - if (!IsConsoleReady()) - { - OutputDebugStringA(msg.data()); - } + if (!IsConsoleReady()) + { + OutputDebugStringA(msg.data()); + } #endif - if (!Game::Sys_IsMainThread()) - { - EnqueueMessage(msg); - } - else - { - Game::Com_PrintMessage(channel, msg.data(), 0); - } + if (!Game::Sys_IsMainThread()) + { + EnqueueMessage(msg); + } + else + { + Game::Com_PrintMessage(channel, msg.data(), 0); + } } void Logger::DebugInternal(const std::string_view& fmt, std::format_args&& args, [[maybe_unused]] const std::source_location& loc) @@ -120,33 +120,33 @@ namespace Components void Logger::PrintFail2BanInternal(const std::string_view& fmt, std::format_args&& args) { static const auto shouldPrint = []() -> bool - { - return Flags::HasFlag("fail2ban"); - }(); + { + return Flags::HasFlag("fail2ban"); + }(); - if (!shouldPrint) - { - return; - } + if (!shouldPrint) + { + return; + } - auto msg = std::vformat(fmt, args); + auto msg = std::vformat(fmt, args); - static auto log_next_time_stamp = true; - if (log_next_time_stamp) - { - auto now = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()); - // Convert to local time - std::tm timeInfo = *std::localtime(&now); + static auto log_next_time_stamp = true; + if (log_next_time_stamp) + { + auto now = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()); + // Convert to local time + std::tm timeInfo = *std::localtime(&now); - std::ostringstream ss; - ss << std::put_time(&timeInfo, "%Y-%m-%d %H:%M:%S "); + std::ostringstream ss; + ss << std::put_time(&timeInfo, "%Y-%m-%d %H:%M:%S "); - msg.insert(0, ss.str()); - } + msg.insert(0, ss.str()); + } - log_next_time_stamp = (msg.find('\n') != std::string::npos); + log_next_time_stamp = (msg.find('\n') != std::string::npos); - Utils::IO::WriteFile(IW4x_fail2ban_location.get(), msg, true); + Utils::IO::WriteFile(IW4x_fail2ban_location.get(), msg, true); } void Logger::Frame() @@ -227,28 +227,28 @@ namespace Components pushad - push [esp + 28h] + push[esp + 28h] call PrintMessagePipe add esp, 4h popad ret - returnPrint: + returnPrint : pushad - push 0 // gLog - push [esp + 2Ch] // data - call NetworkLog - add esp, 8h + push 0 // gLog + push[esp + 2Ch] // data + call NetworkLog + add esp, 8h - popad + popad - push esi - mov esi, [esp + 0Ch] + push esi + mov esi, [esp + 0Ch] - push 4AA835h - ret + push 4AA835h + ret } } @@ -262,13 +262,16 @@ namespace Components { const auto* g_log = (*Game::g_log) ? (*Game::g_log)->current.string : ""; - if (std::strcmp(g_log, file) == 0) + if (g_log) // This can be null - has happened before { - if (std::strcmp(folder, "userraw") != 0) + if (std::strcmp(g_log, file) == 0) { - if (IW4x_one_log.get()) + if (std::strcmp(folder, "userraw") != 0) { - strncpy_s(folder, 256, "userraw", _TRUNCATE); + if (IW4x_one_log.get()) + { + strncpy_s(folder, 256, "userraw", _TRUNCATE); + } } } } @@ -280,8 +283,8 @@ namespace Components { pushad - push [esp + 20h + 8h] - push [esp + 20h + 10h] + push[esp + 20h + 8h] + push[esp + 20h + 10h] call RedirectOSPath add esp, 8h @@ -310,116 +313,116 @@ namespace Components void Logger::AddServerCommands() { Command::AddSV("log_add", [](const Command::Params* params) - { - if (params->size() < 2) return; - - std::unique_lock lock(LoggingMutex); - - Network::Address addr(params->get(1)); - if (std::ranges::find(LoggingAddresses[0], addr) == LoggingAddresses[0].end()) { - LoggingAddresses[0].push_back(addr); - } - }); + if (params->size() < 2) return; + + std::unique_lock lock(LoggingMutex); + + Network::Address addr(params->get(1)); + if (std::ranges::find(LoggingAddresses[0], addr) == LoggingAddresses[0].end()) + { + LoggingAddresses[0].push_back(addr); + } + }); Command::AddSV("log_del", [](const Command::Params* params) - { - if (params->size() < 2) return; - - std::unique_lock lock(LoggingMutex); - - const auto num = std::atoi(params->get(1)); - if (!std::strcmp(VA("%i", num), params->get(1)) && static_cast(num) < LoggingAddresses[0].size()) { - auto addr = Logger::LoggingAddresses[0].begin() + num; - Print("Address {} removed\n", addr->getString()); - LoggingAddresses[0].erase(addr); - } - else - { - Network::Address addr(params->get(1)); + if (params->size() < 2) return; - if (const auto i = std::ranges::find(LoggingAddresses[0], addr); i != LoggingAddresses[0].end()) + std::unique_lock lock(LoggingMutex); + + const auto num = std::atoi(params->get(1)); + if (!std::strcmp(VA("%i", num), params->get(1)) && static_cast(num) < LoggingAddresses[0].size()) { - LoggingAddresses[0].erase(i); - Print("Address {} removed\n", addr.getString()); + auto addr = Logger::LoggingAddresses[0].begin() + num; + Print("Address {} removed\n", addr->getString()); + LoggingAddresses[0].erase(addr); } else { - Print("Address {} not found!\n", addr.getString()); + Network::Address addr(params->get(1)); + + if (const auto i = std::ranges::find(LoggingAddresses[0], addr); i != LoggingAddresses[0].end()) + { + LoggingAddresses[0].erase(i); + Print("Address {} removed\n", addr.getString()); + } + else + { + Print("Address {} not found!\n", addr.getString()); + } } - } - }); + }); Command::AddSV("log_list", []([[maybe_unused]] const Command::Params* params) - { - Print("# ID: Address\n"); - Print("-------------\n"); - - std::unique_lock lock(LoggingMutex); - - for (unsigned int i = 0; i < LoggingAddresses[0].size(); ++i) { - Print("#{:03d}: {}\n", i, LoggingAddresses[0][i].getString()); - } - }); + Print("# ID: Address\n"); + Print("-------------\n"); + + std::unique_lock lock(LoggingMutex); + + for (unsigned int i = 0; i < LoggingAddresses[0].size(); ++i) + { + Print("#{:03d}: {}\n", i, LoggingAddresses[0][i].getString()); + } + }); Command::AddSV("g_log_add", [](const Command::Params* params) - { - if (params->size() < 2) return; - - std::unique_lock lock(LoggingMutex); - - const Network::Address addr(params->get(1)); - if (std::ranges::find(LoggingAddresses[1], addr) == LoggingAddresses[1].end()) { - LoggingAddresses[1].push_back(addr); - } - }); + if (params->size() < 2) return; + + std::unique_lock lock(LoggingMutex); + + const Network::Address addr(params->get(1)); + if (std::ranges::find(LoggingAddresses[1], addr) == LoggingAddresses[1].end()) + { + LoggingAddresses[1].push_back(addr); + } + }); Command::AddSV("g_log_del", [](const Command::Params* params) - { - if (params->size() < 2) return; - - std::unique_lock lock(LoggingMutex); - - const auto num = std::atoi(params->get(1)); - if (!std::strcmp(VA("%i", num), params->get(1)) && static_cast(num) < LoggingAddresses[1].size()) { - const auto addr = LoggingAddresses[1].begin() + num; - Print("Address {} removed\n", addr->getString()); - LoggingAddresses[1].erase(addr); - } - else - { - const Network::Address addr(params->get(1)); - const auto i = std::ranges::find(LoggingAddresses[1].begin(), LoggingAddresses[1].end(), addr); - if (i != LoggingAddresses[1].end()) + if (params->size() < 2) return; + + std::unique_lock lock(LoggingMutex); + + const auto num = std::atoi(params->get(1)); + if (!std::strcmp(VA("%i", num), params->get(1)) && static_cast(num) < LoggingAddresses[1].size()) { - LoggingAddresses[1].erase(i); - Print("Address {} removed\n", addr.getString()); + const auto addr = LoggingAddresses[1].begin() + num; + Print("Address {} removed\n", addr->getString()); + LoggingAddresses[1].erase(addr); } else { - Print("Address {} not found!\n", addr.getString()); + const Network::Address addr(params->get(1)); + const auto i = std::ranges::find(LoggingAddresses[1].begin(), LoggingAddresses[1].end(), addr); + if (i != LoggingAddresses[1].end()) + { + LoggingAddresses[1].erase(i); + Print("Address {} removed\n", addr.getString()); + } + else + { + Print("Address {} not found!\n", addr.getString()); + } } - } - }); + }); Command::AddSV("g_log_list", []([[maybe_unused]] const Command::Params* params) - { - Print("# ID: Address\n"); - Print("-------------\n"); - - std::unique_lock lock(LoggingMutex); - for (std::size_t i = 0; i < LoggingAddresses[1].size(); ++i) { - Print("#{:03d}: {}\n", i, LoggingAddresses[1][i].getString()); - } - }); + Print("# ID: Address\n"); + Print("-------------\n"); + + std::unique_lock lock(LoggingMutex); + for (std::size_t i = 0; i < LoggingAddresses[1].size(); ++i) + { + Print("#{:03d}: {}\n", i, LoggingAddresses[1][i].getString()); + } + }); } - void PrintAliasError(Game::conChannel_t channel, const char * originalMsg, const char* soundName, const char* lastErrorStr) + void PrintAliasError(Game::conChannel_t channel, const char* originalMsg, const char* soundName, const char* lastErrorStr) { // We add a bit more info and we clear the sound stream when it happens // to avoid spamming the error @@ -461,10 +464,10 @@ namespace Components Events::OnSVInit(AddServerCommands); Events::OnDvarInit([] - { - IW4x_one_log = Dvar::Register("iw4x_onelog", false, Game::DVAR_LATCH, "Only write the game log to the 'userraw' OS folder"); - IW4x_fail2ban_location = Dvar::Register("iw4x_fail2ban_location", "/var/log/iw4x.log", Game::DVAR_NONE, "Fail2Ban logfile location"); - }); + { + IW4x_one_log = Dvar::Register("iw4x_onelog", false, Game::DVAR_LATCH, "Only write the game log to the 'userraw' OS folder"); + IW4x_fail2ban_location = Dvar::Register("iw4x_fail2ban_location", "/var/log/iw4x.log", Game::DVAR_NONE, "Fail2Ban logfile location"); + }); } Logger::~Logger() diff --git a/src/Components/Modules/Maps.cpp b/src/Components/Modules/Maps.cpp index 5300c66f..bdc3d45e 100644 --- a/src/Components/Modules/Maps.cpp +++ b/src/Components/Modules/Maps.cpp @@ -103,9 +103,9 @@ namespace Components const char* Maps::LoadArenaFileStub(const char* name, char* buffer, int size) { - std::string data = RawFiles::ReadRawFile(name, buffer, size); + std::string data; - if (Maps::UserMap.isValid()) + if (Maps::UserMap.isValid()) { const auto mapname = Maps::UserMap.getName(); const auto arena = GetArenaPath(mapname); @@ -116,6 +116,10 @@ namespace Components data = Utils::IO::ReadFile(arena); } } + else + { + data = RawFiles::ReadRawFile(name, buffer, size); + } strncpy_s(buffer, size, data.data(), _TRUNCATE); return buffer; @@ -141,11 +145,11 @@ namespace Components Maps::CurrentDependencies.clear(); auto dependencies = GetDependenciesForMap(zoneInfo->name); - + std::vector data; Utils::Merge(&data, zoneInfo, zoneCount); Utils::Memory::Allocator allocator; - + if (dependencies.requiresTeamZones) { auto teams = dependencies.requiredTeams; @@ -177,7 +181,7 @@ namespace Components auto patchZone = std::format("patch_{}", zoneInfo->name); if (FastFiles::Exists(patchZone)) { - data.push_back({patchZone.data(), zoneInfo->allocFlags, zoneInfo->freeFlags}); + data.push_back({ patchZone.data(), zoneInfo->allocFlags, zoneInfo->freeFlags }); } return FastFiles::LoadLocalizeZones(data.data(), data.size(), sync); @@ -185,18 +189,18 @@ namespace Components void Maps::OverrideMapEnts(Game::MapEnts* ents) { - auto callback = [] (Game::XAssetHeader header, void* ents) - { - Game::MapEnts* mapEnts = reinterpret_cast(ents); - Game::clipMap_t* clipMap = header.clipMap; - - if (clipMap && mapEnts && !_stricmp(mapEnts->name, clipMap->name)) + auto callback = [](Game::XAssetHeader header, void* ents) { - clipMap->mapEnts = mapEnts; - //*Game::marMapEntsPtr = mapEnts; - //Game::G_SpawnEntitiesFromString(); - } - }; + Game::MapEnts* mapEnts = reinterpret_cast(ents); + Game::clipMap_t* clipMap = header.clipMap; + + if (clipMap && mapEnts && !_stricmp(mapEnts->name, clipMap->name)) + { + clipMap->mapEnts = mapEnts; + //*Game::marMapEntsPtr = mapEnts; + //Game::G_SpawnEntitiesFromString(); + } + }; // Internal doesn't lock the thread, as locking is impossible, due to executing this in the thread that holds the current lock Game::DB_EnumXAssets_Internal(Game::XAssetType::ASSET_TYPE_CLIPMAP_MP, callback, ents, true); @@ -276,7 +280,7 @@ namespace Components Logger::Print("Waiting for database...\n"); while (!Game::Sys_IsDatabaseReady()) std::this_thread::sleep_for(10ms); - if (!Game::DB_XAssetPool[Game::XAssetType::ASSET_TYPE_GAMEWORLD_MP].gameWorldMp || !Game::DB_XAssetPool[Game::XAssetType::ASSET_TYPE_GAMEWORLD_MP].gameWorldMp->name || + if (!Game::DB_XAssetPool[Game::XAssetType::ASSET_TYPE_GAMEWORLD_MP].gameWorldMp || !Game::DB_XAssetPool[Game::XAssetType::ASSET_TYPE_GAMEWORLD_MP].gameWorldMp->name || !Game::DB_XAssetPool[Game::XAssetType::ASSET_TYPE_GAMEWORLD_MP].gameWorldMp->g_glassData || Maps::SPMap) { return Game::DB_XAssetPool[Game::XAssetType::ASSET_TYPE_GAMEWORLD_SP].gameWorldSp->g_glassData; @@ -294,7 +298,7 @@ namespace Components call Maps::GetWorldData - mov [esp + 20h], eax + mov[esp + 20h], eax popad pop eax @@ -314,6 +318,22 @@ namespace Components } } + void Maps::ForceRefreshArenas() + { + if (Game::Sys_IsMainThread()) + { + Game::sharedUiInfo_t* uiInfo = reinterpret_cast(0x62E4B78); + uiInfo->updateArenas = 1; + Game::UI_UpdateArenas(); + } + else + { + // Dangerous!! + assert(false, "Arenas refreshed from wrong thread??"); + Logger::Print("Tried to refresh arenas from a thread that is NOT the main thread!! This could have lead to a crash. Please report this bug and how you got it!"); + } + } + // TODO : Remove hook entirely? void Maps::GetBSPName(char* buffer, size_t size, const char* format, const char* mapname) { @@ -459,7 +479,7 @@ namespace Components char hashBuf[100] = { 0 }; unsigned int hash = atoi(Game::MSG_ReadStringLine(msg, hashBuf, sizeof hashBuf)); - if(!Maps::CheckMapInstalled(mapname, false, true) || hash && hash != Maps::GetUsermapHash(mapname)) + if (!Maps::CheckMapInstalled(mapname, false, true) || hash && hash != Maps::GetUsermapHash(mapname)) { // Reconnecting forces the client to download the new map Command::Execute("disconnect", false); @@ -480,12 +500,12 @@ namespace Components push eax pushad - push [esp + 28h] + push[esp + 28h] push ebp call Maps::TriggerReconnectForMap add esp, 8h - mov [esp + 20h], eax + mov[esp + 20h], eax popad pop eax @@ -495,7 +515,7 @@ namespace Components push 487C50h // Rotate map - skipRotation: + skipRotation : retn } } @@ -506,7 +526,7 @@ namespace Components { pushad - push [esp + 24h] + push[esp + 24h] call Maps::PrepareUsermap pop eax @@ -523,7 +543,7 @@ namespace Components { pushad - push [esp + 24h] + push[esp + 24h] call Maps::PrepareUsermap pop eax @@ -668,7 +688,7 @@ namespace Components Logger::Error(Game::ERR_DISCONNECT, "Missing map file {}.\nYou may have a damaged installation or are attempting to load a non-existent map.", mapname); } - + return false; } @@ -706,7 +726,7 @@ namespace Components void Maps::G_SpawnTurretHook(Game::gentity_s* ent, int unk, int unk2) { - if (Maps::CurrentMainZone == "mp_backlot_sh"s || Maps::CurrentMainZone == "mp_con_spring"s || + if (Maps::CurrentMainZone == "mp_backlot_sh"s || Maps::CurrentMainZone == "mp_con_spring"s || Maps::CurrentMainZone == "mp_mogadishu_sh"s || Maps::CurrentMainZone == "mp_nightshift_sh"s) { return; @@ -736,7 +756,7 @@ namespace Components Logger::Error(Game::errorParm_t::ERR_DROP, "Invalid trigger index ({}) in entities exceeds the maximum trigger count ({}) defined in the clipmap. Check your map ents, or your clipmap!", triggerIndex, ents->trigger.count); return 0; } - else + else { return Utils::Hook::Call(0x4416C0)(triggerIndex, bounds); } @@ -744,29 +764,29 @@ namespace Components return 0; } - + Maps::Maps() { Scheduler::Once([] - { - Dvar::Register("isDlcInstalled_All", false, Game::DVAR_EXTERNAL | Game::DVAR_INIT, ""); - Maps::RListSModels = Dvar::Register("r_listSModels", false, Game::DVAR_NONE, "Display a list of visible SModels"); - - Maps::AddDlc({ 1, "Stimulus Pack", {"mp_complex", "mp_compact", "mp_storm", "mp_overgrown", "mp_crash"} }); - Maps::AddDlc({ 2, "Resurgence Pack", {"mp_abandon", "mp_vacant", "mp_trailerpark", "mp_strike", "mp_fuel2"} }); - Maps::AddDlc({ 3, "IW4x Classics", {"mp_nuked", "mp_cross_fire", "mp_cargoship", "mp_bloc", "mp_killhouse", "mp_bog_sh", "mp_cargoship_sh", "mp_shipment", "mp_shipment_long", "mp_rust_long", "mp_firingrange", "mp_bloc_sh", "mp_crash_tropical", "mp_estate_tropical", "mp_fav_tropical", "mp_storm_spring"} }); - Maps::AddDlc({ 4, "Call Of Duty 4 Pack", {"mp_farm", "mp_backlot", "mp_pipeline", "mp_countdown", "mp_crash_snow", "mp_carentan", "mp_broadcast", "mp_showdown", "mp_convoy", "mp_citystreets"} }); - Maps::AddDlc({ 5, "Modern Warfare 3 Pack", {"mp_dome", "mp_hardhat", "mp_paris", "mp_seatown", "mp_bravo", "mp_underground", "mp_plaza2", "mp_village", "mp_alpha"}}); - - Maps::UpdateDlcStatus(); - - UIScript::Add("downloadDLC", []([[maybe_unused]] const UIScript::Token& token, [[maybe_unused]] const Game::uiInfo_s* info) { - const auto dlc = token.get(); + Dvar::Register("isDlcInstalled_All", false, Game::DVAR_EXTERNAL | Game::DVAR_INIT, ""); + Maps::RListSModels = Dvar::Register("r_listSModels", false, Game::DVAR_NONE, "Display a list of visible SModels"); - Game::ShowMessageBox(Utils::String::VA("DLC %d does not exist!", dlc), "ERROR"); - }); - }, Scheduler::Pipeline::MAIN); + Maps::AddDlc({ 1, "Stimulus Pack", {"mp_complex", "mp_compact", "mp_storm", "mp_overgrown", "mp_crash"} }); + Maps::AddDlc({ 2, "Resurgence Pack", {"mp_abandon", "mp_vacant", "mp_trailerpark", "mp_strike", "mp_fuel2"} }); + Maps::AddDlc({ 3, "IW4x Classics", {"mp_nuked", "mp_cross_fire", "mp_cargoship", "mp_bloc", "mp_killhouse", "mp_bog_sh", "mp_cargoship_sh", "mp_shipment", "mp_shipment_long", "mp_rust_long", "mp_firingrange", "mp_bloc_sh", "mp_crash_tropical", "mp_estate_tropical", "mp_fav_tropical", "mp_storm_spring"} }); + Maps::AddDlc({ 4, "Call Of Duty 4 Pack", {"mp_farm", "mp_backlot", "mp_pipeline", "mp_countdown", "mp_crash_snow", "mp_carentan", "mp_broadcast", "mp_showdown", "mp_convoy", "mp_citystreets"} }); + Maps::AddDlc({ 5, "Modern Warfare 3 Pack", {"mp_dome", "mp_hardhat", "mp_paris", "mp_seatown", "mp_bravo", "mp_underground", "mp_plaza2", "mp_village", "mp_alpha"} }); + + Maps::UpdateDlcStatus(); + + UIScript::Add("downloadDLC", []([[maybe_unused]] const UIScript::Token& token, [[maybe_unused]] const Game::uiInfo_s* info) + { + const auto dlc = token.get(); + + Game::ShowMessageBox(Utils::String::VA("DLC %d does not exist!", dlc), "ERROR"); + }); + }, Scheduler::Pipeline::MAIN); // disable turrets on CoD:OL 448+ maps for now Utils::Hook(0x5EE577, Maps::G_SpawnTurretHook, HOOK_CALL).install()->quick(); @@ -782,7 +802,7 @@ namespace Components #endif // - + //#define SORT_SMODELS #if !defined(DEBUG) || !defined(SORT_SMODELS) // Don't sort static models @@ -825,13 +845,13 @@ namespace Components Utils::Hook(0x5B34DD, Maps::LoadMapLoadscreenStub, HOOK_CALL).install()->quick(); Command::Add("delayReconnect", []() - { - Scheduler::Once([] { - Command::Execute("closemenu popup_reconnectingtoparty", false); - Command::Execute("reconnect", false); - }, Scheduler::Pipeline::CLIENT, 10s); - }); + Scheduler::Once([] + { + Command::Execute("closemenu popup_reconnectingtoparty", false); + Command::Execute("reconnect", false); + }, Scheduler::Pipeline::CLIENT, 10s); + }); if (Dedicated::IsEnabled()) { @@ -845,12 +865,6 @@ namespace Components // Load usermap arena file Utils::Hook(0x630A88, Maps::LoadArenaFileStub, HOOK_CALL).install()->quick(); - // Always refresh arena when loading or unloading a zone - Utils::Hook::Nop(0x485017, 2); - Utils::Hook::Nop(0x4BDFB7, 2); // Unknown - Utils::Hook::Nop(0x45ED6F, 2); // loadGameInfo - Utils::Hook::Nop(0x4A5888, 2); // UI_InitOnceForAllClients - // Allow hiding specific smodels Utils::Hook(0x50E67C, Maps::HideModelStub, HOOK_CALL).install()->quick(); @@ -861,33 +875,33 @@ namespace Components // Client only Scheduler::Loop([] - { - auto*& gameWorld = *reinterpret_cast(0x66DEE94); - if (!Game::CL_IsCgameInitialized() || !gameWorld || !Maps::RListSModels.get()) return; - - std::map models; - for (unsigned int i = 0; i < gameWorld->dpvs.smodelCount; ++i) { - if (gameWorld->dpvs.smodelVisData[0][i]) + auto*& gameWorld = *reinterpret_cast(0x66DEE94); + if (!Game::CL_IsCgameInitialized() || !gameWorld || !Maps::RListSModels.get()) return; + + std::map models; + for (unsigned int i = 0; i < gameWorld->dpvs.smodelCount; ++i) { - std::string name = gameWorld->dpvs.smodelDrawInsts[i].model->name; + if (gameWorld->dpvs.smodelVisData[0][i]) + { + std::string name = gameWorld->dpvs.smodelDrawInsts[i].model->name; - if (!models.contains(name)) models[name] = 1; - else models[name]++; + if (!models.contains(name)) models[name] = 1; + else models[name]++; + } } - } - Game::Font_s* font = Game::R_RegisterFont("fonts/smallFont", 0); - auto height = Game::R_TextHeight(font); - auto scale = 0.75f; - float color[4] = {0.0f, 1.0f, 0.0f, 1.0f}; + Game::Font_s* font = Game::R_RegisterFont("fonts/smallFont", 0); + auto height = Game::R_TextHeight(font); + auto scale = 0.75f; + float color[4] = { 0.0f, 1.0f, 0.0f, 1.0f }; - unsigned int i = 0; - for (auto& model : models) - { - Game::R_AddCmdDrawText(Utils::String::VA("%d %s", model.second, model.first.data()), std::numeric_limits::max(), font, 15.0f, (height * scale + 1) * (i++ + 1) + 15.0f, scale, scale, 0.0f, color, Game::ITEM_TEXTSTYLE_NORMAL); - } - }, Scheduler::Pipeline::RENDERER); + unsigned int i = 0; + for (auto& model : models) + { + Game::R_AddCmdDrawText(Utils::String::VA("%d %s", model.second, model.first.data()), std::numeric_limits::max(), font, 15.0f, (height * scale + 1) * (i++ + 1) + 15.0f, scale, scale, 0.0f, color, Game::ITEM_TEXTSTYLE_NORMAL); + } + }, Scheduler::Pipeline::RENDERER); } Maps::~Maps() diff --git a/src/Components/Modules/Maps.hpp b/src/Components/Modules/Maps.hpp index 356cf6fe..aca7d6bc 100644 --- a/src/Components/Modules/Maps.hpp +++ b/src/Components/Modules/Maps.hpp @@ -13,7 +13,7 @@ namespace Components { ZeroMemory(&this->searchPath, sizeof this->searchPath); this->hash = Maps::GetUsermapHash(this->mapname); - Game::UI_UpdateArenas(); + Maps::ForceRefreshArenas(); } ~UserMapContainer() @@ -29,7 +29,10 @@ namespace Components { bool wasValid = this->isValid(); this->mapname.clear(); - if (wasValid) Game::UI_UpdateArenas(); + if (wasValid) + { + Maps::ForceRefreshArenas(); + } } void loadIwd(); @@ -95,6 +98,8 @@ namespace Components static Dvar::Var RListSModels; + static void ForceRefreshArenas(); + static void GetBSPName(char* buffer, size_t size, const char* format, const char* mapname); static void LoadAssetRestrict(Game::XAssetType type, Game::XAssetHeader asset, const std::string& name, bool* restrict); static void LoadMapZones(Game::XZoneInfo *zoneInfo, unsigned int zoneCount, int sync);