diff --git a/r5dev/common/completion.cpp b/r5dev/common/completion.cpp index a94918b9..702a487c 100644 --- a/r5dev/common/completion.cpp +++ b/r5dev/common/completion.cpp @@ -27,7 +27,7 @@ int _Host_Map_f_CompletionFunc(char const* cmdname, char const* partial, char co substring = (char*)partial + strlen(cmdname); } - const int mapcount = (int)g_InstalledMaps.size(); + const int mapcount = g_InstalledMaps.Count(); const int longest = COMMAND_COMPLETION_ITEM_LENGTH; const int count = MIN(mapcount, COMMAND_COMPLETION_MAXITEMS); @@ -36,9 +36,9 @@ int _Host_Map_f_CompletionFunc(char const* cmdname, char const* partial, char co { for (int i = 0; i < count; i++) { - if (strstr(g_InstalledMaps[i].c_str(), substring)) + if (strstr(g_InstalledMaps[i].String(), substring)) { - strncpy(commands[filtered_count], g_InstalledMaps[i].c_str(), longest); + strncpy(commands[filtered_count], g_InstalledMaps[i].String(), longest); char old[COMMAND_COMPLETION_ITEM_LENGTH]; strncpy(old, commands[filtered_count], sizeof(old)); diff --git a/r5dev/engine/cmodel_bsp.cpp b/r5dev/engine/cmodel_bsp.cpp index 19562068..462c8303 100644 --- a/r5dev/engine/cmodel_bsp.cpp +++ b/r5dev/engine/cmodel_bsp.cpp @@ -21,7 +21,7 @@ #include "client/clientstate.h" #endif // !DEDICATED -vector g_InstalledMaps; +CUtlVector g_InstalledMaps; string s_LevelName; std::regex s_ArchiveRegex{ R"([^_]*_(.*)(.bsp.pak000_dir).*)" }; @@ -52,7 +52,7 @@ void Mod_GetAllInstalledMaps() std::cmatch regexMatches; std::lock_guard l(g_InstalledMapsMutex); - g_InstalledMaps.clear(); // Clear current list. + g_InstalledMaps.Purge(); // Clear current list. FOR_EACH_VEC(fileList, i) { @@ -67,18 +67,20 @@ void Mod_GetAllInstalledMaps() if (!regexMatches.empty()) { - if (regexMatches[1].str().compare("frontend") == 0) + const string match = regexMatches[1].str(); + + if (match.compare("frontend") == 0) continue; // Frontend contains no BSP's. - else if (regexMatches[1].str().compare("mp_common") == 0) + else if (match.compare("mp_common") == 0) { - if (std::find(g_InstalledMaps.begin(), g_InstalledMaps.end(), "mp_lobby") == g_InstalledMaps.end()) - g_InstalledMaps.push_back("mp_lobby"); + if (!g_InstalledMaps.HasElement("mp_lobby")) + g_InstalledMaps.AddToTail("mp_lobby"); + continue; // Common contains mp_lobby. } - - if (std::find(g_InstalledMaps.begin(), g_InstalledMaps.end(), regexMatches[1].str()) == g_InstalledMaps.end()) - g_InstalledMaps.push_back(regexMatches[1].str()); + else if (!g_InstalledMaps.HasElement(match.c_str())) + g_InstalledMaps.AddToTail(match.c_str()); } } } diff --git a/r5dev/engine/cmodel_bsp.h b/r5dev/engine/cmodel_bsp.h index fb94a996..ff66ce91 100644 --- a/r5dev/engine/cmodel_bsp.h +++ b/r5dev/engine/cmodel_bsp.h @@ -27,7 +27,7 @@ inline __int64(*sub_14045A1D0)(unsigned __int8(__fastcall* a1)(_QWORD), JobFifoL inline void(*sub_140441220)(__int64 a1, __int64 a2); extern bool s_bBasePaksInitialized; -extern vector g_InstalledMaps; +extern CUtlVector g_InstalledMaps; bool Mod_LevelHasChanged(const char* pszLevelName); void Mod_GetAllInstalledMaps(); diff --git a/r5dev/game/shared/vscript_shared.cpp b/r5dev/game/shared/vscript_shared.cpp index 8dc435c2..9ad86027 100644 --- a/r5dev/game/shared/vscript_shared.cpp +++ b/r5dev/game/shared/vscript_shared.cpp @@ -38,13 +38,16 @@ namespace VScriptCode { std::lock_guard l(g_InstalledMapsMutex); - if (g_InstalledMaps.empty()) + if (g_InstalledMaps.IsEmpty()) return SQ_OK; sq_newarray(v, 0); - for (const string& it : g_InstalledMaps) + + FOR_EACH_VEC(g_InstalledMaps, i) { - sq_pushstring(v, it.c_str(), -1); + const CUtlString& mapName = g_InstalledMaps[i]; + + sq_pushstring(v, mapName.String(), -1); sq_arrayappend(v, -2); } diff --git a/r5dev/gameui/IBrowser.cpp b/r5dev/gameui/IBrowser.cpp index 5854aaef..566cbc86 100644 --- a/r5dev/gameui/IBrowser.cpp +++ b/r5dev/gameui/IBrowser.cpp @@ -519,11 +519,15 @@ void CBrowser::HostPanel(void) if (ImGui::BeginCombo("Map", g_pServerListManager->m_Server.m_svHostMap.c_str())) { g_InstalledMapsMutex.lock(); - for (const string& svMap : g_InstalledMaps) + + FOR_EACH_VEC(g_InstalledMaps, i) { - if (ImGui::Selectable(svMap.c_str(), svMap == g_pServerListManager->m_Server.m_svHostMap)) + const CUtlString& mapName = g_InstalledMaps[i]; + + if (ImGui::Selectable(mapName.String(), + mapName.IsEqual_CaseInsensitive(g_pServerListManager->m_Server.m_svHostMap.c_str()))) { - g_pServerListManager->m_Server.m_svHostMap = svMap; + g_pServerListManager->m_Server.m_svHostMap = mapName.String(); } }