From d767824932dc2bdc86da9532831d7457b1591a2f Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Tue, 30 Jan 2024 13:49:09 +0100 Subject: [PATCH] VpkLib: actually search for corresponding data block file Instead of just using English as default, actually scan for all supported directory tree files, error if not found. This completes the sanitization logic which allows the user to only pass in the data block file to load the directory tree file --- src/vpklib/packedstore.cpp | 43 ++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/src/vpklib/packedstore.cpp b/src/vpklib/packedstore.cpp index e195af99..29a402cf 100644 --- a/src/vpklib/packedstore.cpp +++ b/src/vpklib/packedstore.cpp @@ -887,30 +887,55 @@ VPKDir_t::VPKDir_t(const CUtlString& dirFilePath, bool bSanitizeName) } } + // NOTE: if we already have a locale, we call Init() anyways as that is the + // directory tree file the user wants, despite requesting for sanitization + bool found = false; + // If we don't have a locale prefix, replace the target name with // locale+target, so you get something like "englishserver", and // then we replace the target name in the passed in string with // the new prefix to finalize name sanitization. if (!bHasLocale) { - CUtlString packDirPrefix; - packDirPrefix.Append(g_LanguageNames[0]); - - for (size_t i = 0; i < SDK_ARRAYSIZE(DIR_TARGET); i++) + for (size_t i = 0; i < SDK_ARRAYSIZE(g_LanguageNames); i++) { - const char* targetName = DIR_TARGET[i]; + CUtlString packDirToSearch; + packDirToSearch.Append(g_LanguageNames[i]); - if (sanitizedName.Find(targetName) != -1) + for (size_t j = 0; j < SDK_ARRAYSIZE(DIR_TARGET); j++) { - packDirPrefix.Append(targetName); - sanitizedName = sanitizedName.Replace(targetName, packDirPrefix); + const char* targetName = DIR_TARGET[j]; + if (sanitizedName.Find(targetName) != -1) + { + packDirToSearch.Append(targetName); + packDirToSearch = sanitizedName.Replace(targetName, packDirToSearch); + + break; + } + } + + // R1 has multiple language VPK files, by default we check for english first + // but if it doesn't exist we continue looking until we've found a directory + // file + if (FileSystem()->FileExists(packDirToSearch.String(), "GAME")) + { + sanitizedName = packDirToSearch; + found = true; break; } } } - Init(sanitizedName); + if (bHasLocale || found) + { + Init(sanitizedName); + } + else + { + Error(eDLL_T::FS, NO_ERROR, "Corresponding VPK directory file for '%s' not found\n", dirFilePath.Get()); + m_bInitFailed = true; + } } //-----------------------------------------------------------------------------