diff --git a/r5dev/engine/net.cpp b/r5dev/engine/net.cpp index 6e22862f..7965b168 100644 --- a/r5dev/engine/net.cpp +++ b/r5dev/engine/net.cpp @@ -65,14 +65,13 @@ int NET_SendDatagram(SOCKET s, void* pPayload, int iLenght, netadr_t* pAdr, bool // Purpose: sets the user specified encryption key // Input : svNetKey - //----------------------------------------------------------------------------- -void NET_SetKey(string svNetKey) +void NET_SetKey(const string& svNetKey) { std::lock_guard l(g_NetKeyMutex); if (svNetKey.size() == AES_128_B64_ENCODED_SIZE && - IsValidBase64(svNetKey)) + IsValidBase64(svNetKey, &g_svNetKey)) // Results are tokenized by 'IsValidBase64()'. { - g_svNetKey = svNetKey; // Results are tokenized by 'IsValidBase64()'. v_NET_SetKey(g_pNetKey, g_svNetKey.c_str()); DevMsg(eDLL_T::ENGINE, "Installed NetKey: '%s%s%s'\n", diff --git a/r5dev/engine/net.h b/r5dev/engine/net.h index 032f3199..2dce686e 100644 --- a/r5dev/engine/net.h +++ b/r5dev/engine/net.h @@ -39,7 +39,7 @@ inline auto v_NET_PrintFunc = p_NET_PrintFunc.RCast(); /////////////////////////////////////////////////////////////////////////////// bool NET_ReceiveDatagram(int iSocket, netpacket_s* pInpacket, bool bRaw); int NET_SendDatagram(SOCKET s, void* pPayload, int iLenght, netadr_t* pAdr, bool bEncrypted); -void NET_SetKey(string svNetKey); +void NET_SetKey(const string& svNetKey); void NET_GenerateKey(); void NET_PrintFunc(const char* fmt, ...); void NET_Shutdown(void* thisptr, const char* szReason, uint8_t bBadRep, bool bRemoveNow); diff --git a/r5dev/public/utility/utility.cpp b/r5dev/public/utility/utility.cpp index c8b3d703..1d97b609 100644 --- a/r5dev/public/utility/utility.cpp +++ b/r5dev/public/utility/utility.cpp @@ -374,7 +374,7 @@ string CreateTimedFileName() /////////////////////////////////////////////////////////////////////////////// // For creating directories for output streams. -string CreateDirectories(string svInput, bool bWindows) +void CreateDirectories(string svInput, string* pszOutput, bool bWindows) { if (bWindows) { @@ -388,12 +388,14 @@ string CreateDirectories(string svInput, bool bWindows) } fs::path fspPathOut(svInput); - string result = fspPathOut.u8string(); + + if (pszOutput) + { + *pszOutput = fspPathOut.u8string(); + } fspPathOut = fspPathOut.parent_path(); fs::create_directories(fspPathOut); - - return result; } /////////////////////////////////////////////////////////////////////////////// @@ -432,14 +434,17 @@ string ConvertToUnixPath(const string& svInput) /////////////////////////////////////////////////////////////////////////////// // For checking if input is a valid Base64. -bool IsValidBase64(string& svInput) +bool IsValidBase64(const string& svInput, string* psvOutput) { static const std::regex rx(R"((?:[A-Za-z0-9+\/]{4}?)*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=))"); std::smatch mh; if (std::regex_search(svInput, mh, rx)) { - svInput = mh[0].str(); + if (psvOutput) + { + *psvOutput = mh[0].str(); + } return true; } return false; diff --git a/r5dev/public/utility/utility.h b/r5dev/public/utility/utility.h index 46abdb6d..0a263166 100644 --- a/r5dev/public/utility/utility.h +++ b/r5dev/public/utility/utility.h @@ -30,12 +30,12 @@ string GetFileName(const string& svInput, bool bRemoveExtension = false, bool bW string RemoveFileName(const string& svInput, bool bWindows = false); string CreateTimedFileName(); -string CreateDirectories(string svInput, bool bWindows = false); +void CreateDirectories(string svInput, string* pszOutput = nullptr, bool bWindows = false); string ConvertToWinPath(const string& svInput); string ConvertToUnixPath(const string& svInput); -bool IsValidBase64(string& svInput); +bool IsValidBase64(const string& svInput, string* psvOutput = nullptr); string Base64Encode(const string& svInput); string Base64Decode(const string& svInput); diff --git a/r5dev/vpklib/packedstore.cpp b/r5dev/vpklib/packedstore.cpp index 7aec09b7..32ae5a6b 100644 --- a/r5dev/vpklib/packedstore.cpp +++ b/r5dev/vpklib/packedstore.cpp @@ -140,7 +140,7 @@ vector CPackedStore::GetEntryValues(const string& svWorkspace, K if (!pManifestKV) { - Warning(eDLL_T::FS, "Invalid VPK manifest KV; unable to build entry list\n"); + Warning(eDLL_T::FS, "Invalid VPK build manifest KV; unable to parse entry list\n"); return vEntryValues; } @@ -317,7 +317,7 @@ void CPackedStore::BuildManifest(const vector& vBlock, const st kv.RecursiveSaveToFile(uBuf, 0); - FileSystem()->CreateDirHierarchy(string(svWorkspace + "manifest/").c_str(), "GAME"); + FileSystem()->CreateDirHierarchy(fmt::format("{:s}{:s}", svWorkspace, "manifest/").c_str(), "GAME"); FileSystem()->WriteFile(svPathOut.c_str(), "GAME", uBuf); } @@ -510,7 +510,8 @@ void CPackedStore::UnpackWorkspace(const VPKDir_t& vDirectory, const string& svW } else // Chunk belongs to this block. { - const string svFilePath = CreateDirectories(svWorkspace + vEntryBlock.m_svEntryPath); + string svFilePath; + CreateDirectories(svWorkspace + vEntryBlock.m_svEntryPath, &svFilePath); FileHandle_t hAsset = FileSystem()->Open(svFilePath.c_str(), "wb", "GAME"); if (!hAsset) @@ -597,13 +598,12 @@ VPKEntryBlock_t::VPKEntryBlock_t(FileHandle_t hDirectoryFile, const string& svEn { m_svEntryPath = svEntryPath; // Set the entry path. StringReplace(m_svEntryPath, "\\", "/"); // Flip windows-style backslash to forward slash. - StringReplace(m_svEntryPath, " /", ""); // Remove space character representing VPK root. + StringReplace(m_svEntryPath, " /", ""); // Remove space character representing VPK root. FileSystem()->Read(&m_nFileCRC, sizeof(uint32_t), hDirectoryFile); // FileSystem()->Read(&m_iPreloadSize, sizeof(uint16_t), hDirectoryFile); // FileSystem()->Read(&m_iPackFileIndex, sizeof(uint16_t), hDirectoryFile); // - uint16_t nMarker = 0; do // Loop through all chunks in the entry and add to list. {