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.
This commit is contained in:
Kawe Mazidjatari 2023-07-15 21:36:14 +02:00
parent e515c2d93f
commit 5fc38d5c96

View File

@ -49,14 +49,23 @@ void Mod_GetAllInstalledMaps()
CUtlVector<CUtlString> fileList;
AddFilesToList(fileList, "vpk", "vpk", nullptr, '/');
std::cmatch regexMatches;
std::lock_guard<std::mutex> 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())
{