From 5fc38d5c96613a0dd7644754aeaa2db28db0d4a1 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Sat, 15 Jul 2023 21:36:14 +0200 Subject: [PATCH] Fix bug where map names aren't captured correctly In rare occasions (depending on the installation path), the regex might fail to extract the level name from the VPK file name. If the path has a similar pattern, or certain characters, it will capture the wrong string. This fix has been tested, and confirmed to fix the bug. --- r5dev/engine/cmodel_bsp.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/r5dev/engine/cmodel_bsp.cpp b/r5dev/engine/cmodel_bsp.cpp index 8b5549aa..7c7380dc 100644 --- a/r5dev/engine/cmodel_bsp.cpp +++ b/r5dev/engine/cmodel_bsp.cpp @@ -49,14 +49,23 @@ void Mod_GetAllInstalledMaps() CUtlVector fileList; AddFilesToList(fileList, "vpk", "vpk", nullptr, '/'); + std::cmatch regexMatches; std::lock_guard l(g_InstalledMapsMutex); + g_InstalledMaps.clear(); // Clear current list. - std::cmatch regexMatches; FOR_EACH_VEC(fileList, i) { - const CUtlString& fileName = fileList[i]; - std::regex_search(fileName.Get(), regexMatches, s_ArchiveRegex); + const CUtlString& filePath = fileList[i]; + + const char* pFilePath = filePath.Get(); + const char* pFileName = strrchr(pFilePath, '/')+1; + + // Should always point right in front of the last + // slash, as the files are loaded from 'vpk/'. + Assert(pFileName); + + std::regex_search(pFileName, regexMatches, s_ArchiveRegex); if (!regexMatches.empty()) {