mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
Fix FileSystem size integer truncation
The implementation in the engine always took/returned signed 64bit size types, but I made a mistake when reversing the virtual function table. All types have been changed to what they should be (mostly signed 64bit, very few unsigned), and usage in-SDK has been adjusted accordingly.
This commit is contained in:
parent
d59a320d69
commit
5f64cd83d8
@ -500,10 +500,10 @@ void RTech_Decompress_f(const CCommand& args)
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t nPakLen = FileSystem()->Size(hPakFile);
|
||||
const ssize_t nPakLen = FileSystem()->Size(hPakFile);
|
||||
|
||||
std::unique_ptr<uint8_t[]> pPakBufContainer(new uint8_t[nPakLen]);
|
||||
uint8_t* pPakBuf = pPakBufContainer.get();
|
||||
uint8_t* const pPakBuf = pPakBufContainer.get();
|
||||
|
||||
FileSystem()->Read(pPakBuf, nPakLen, hPakFile);
|
||||
FileSystem()->Close(hPakFile);
|
||||
@ -524,8 +524,8 @@ void RTech_Decompress_f(const CCommand& args)
|
||||
DevMsg(eDLL_T::RTECH, " | |-- Hash : '0x%08llX'\n", pHeader->m_nHash);
|
||||
DevMsg(eDLL_T::RTECH, " | |-- Entries : '%u'\n", pHeader->m_nAssetEntryCount);
|
||||
DevMsg(eDLL_T::RTECH, " | |-+ Compression -----------------------------------------\n");
|
||||
DevMsg(eDLL_T::RTECH, " | |-- Size comp: '%llu'\n", pHeader->m_nSizeDisk);
|
||||
DevMsg(eDLL_T::RTECH, " | |-- Size decp: '%llu'\n", pHeader->m_nSizeMemory);
|
||||
DevMsg(eDLL_T::RTECH, " | |-- Size comp: '%zu'\n", pHeader->m_nSizeDisk);
|
||||
DevMsg(eDLL_T::RTECH, " | |-- Size decp: '%zu'\n", pHeader->m_nSizeMemory);
|
||||
|
||||
if (pHeader->m_nMagic != PAK_HEADER_MAGIC)
|
||||
{
|
||||
@ -541,16 +541,19 @@ void RTech_Decompress_f(const CCommand& args)
|
||||
|
||||
return;
|
||||
}
|
||||
if (pHeader->m_nSizeDisk != nPakLen)
|
||||
|
||||
const size_t unsignedPakLen = static_cast<size_t>(nPakLen);
|
||||
|
||||
if (pHeader->m_nSizeDisk != unsignedPakLen)
|
||||
{
|
||||
Error(eDLL_T::RTECH, NO_ERROR, "%s - pak file '%s' decompressed size '%llu' doesn't match expected size '%llu'!\n",
|
||||
__FUNCTION__, inPakFile.String(), nPakLen, pHeader->m_nSizeMemory);
|
||||
Error(eDLL_T::RTECH, NO_ERROR, "%s - pak file '%s' decompressed size '%zu' doesn't match expected size '%zu'!\n",
|
||||
__FUNCTION__, inPakFile.String(), unsignedPakLen, pHeader->m_nSizeMemory);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
RPakDecompState_t decompState;
|
||||
uint64_t nDecompSize = g_pRTech->DecompressPakFileInit(&decompState, pPakBuf, nPakLen, NULL, sizeof(RPakHeader_t));
|
||||
const uint64_t nDecompSize = g_pRTech->DecompressPakFileInit(&decompState, pPakBuf, unsignedPakLen, NULL, sizeof(RPakHeader_t));
|
||||
|
||||
if (nDecompSize == pHeader->m_nSizeDisk)
|
||||
{
|
||||
@ -568,12 +571,12 @@ void RTech_Decompress_f(const CCommand& args)
|
||||
|
||||
|
||||
std::unique_ptr<uint8_t[]> pDecompBufContainer(new uint8_t[nPakLen]);
|
||||
uint8_t* pDecompBuf = pDecompBufContainer.get();
|
||||
uint8_t* const pDecompBuf = pDecompBufContainer.get();
|
||||
|
||||
decompState.m_nOutMask = UINT64_MAX;
|
||||
decompState.m_nOut = uint64_t(pDecompBuf);
|
||||
|
||||
uint8_t nDecompResult = g_pRTech->DecompressPakFile(&decompState, nPakLen, pHeader->m_nSizeMemory);
|
||||
uint8_t nDecompResult = g_pRTech->DecompressPakFile(&decompState, unsignedPakLen, pHeader->m_nSizeMemory);
|
||||
if (nDecompResult != 1)
|
||||
{
|
||||
Error(eDLL_T::RTECH, NO_ERROR, "%s - decompression failed for '%s' return value: '%hu'!\n",
|
||||
@ -610,7 +613,7 @@ void RTech_Decompress_f(const CCommand& args)
|
||||
}
|
||||
|
||||
memcpy_s(pDecompBuf, sizeof(RPakHeader_t), pPakBuf, sizeof(RPakHeader_t));// Overwrite first 0x80 bytes which are NULL with the header data.
|
||||
FileSystem()->Write(pDecompBuf, int(decompState.m_nDecompSize), hDecompFile);
|
||||
FileSystem()->Write(pDecompBuf, decompState.m_nDecompSize, hDecompFile);
|
||||
|
||||
DevMsg(eDLL_T::RTECH, " |-- Checksum : '0x%08X'\n", crc32::update(NULL, pDecompBuf, decompState.m_nDecompSize));
|
||||
DevMsg(eDLL_T::RTECH, "-+ Decompressed pak file to: '%s'\n", outPakFile.String());
|
||||
|
@ -21,7 +21,7 @@ protected:
|
||||
virtual size_t FS_vfprintf(FILE* fp, const char* fmt, va_list list) = 0;
|
||||
virtual int FS_ferror(FILE* fp) = 0;
|
||||
virtual int FS_fflush(FILE* fp) = 0;
|
||||
virtual char* FS_fgets(char* dest, int destSize, FILE* fp) = 0;
|
||||
virtual char* FS_fgets(char* dest, unsigned int destSize) = 0;
|
||||
virtual int FS_stat(const char* path, struct _stat* buf, bool* pbLoadedFromSteamCache = NULL) = 0;
|
||||
virtual int FS_chmod(const char* path, int pmode) = 0;
|
||||
virtual HANDLE FS_FindFirstFile(const char* findname, WIN32_FIND_DATA* dat) = 0;
|
||||
|
@ -72,7 +72,7 @@ void CAI_NetworkBuilder::SaveNetworkGraph(CAI_Network* pNetwork)
|
||||
}
|
||||
else
|
||||
{
|
||||
uint32_t nLen = FileSystem()->Size(pNavMesh);
|
||||
const ssize_t nLen = FileSystem()->Size(pNavMesh);
|
||||
std::unique_ptr<uint8_t[]> pBuf(new uint8_t[nLen]);
|
||||
|
||||
FileSystem()->Read(pBuf.get(), nLen, pNavMesh);
|
||||
@ -325,7 +325,7 @@ void CAI_NetworkManager::LoadNetworkGraph(CAI_NetworkManager* pAINetworkManager,
|
||||
}
|
||||
else
|
||||
{
|
||||
uint32_t nLen = FileSystem()->Size(pNavMesh);
|
||||
const ssize_t nLen = FileSystem()->Size(pNavMesh);
|
||||
std::unique_ptr<uint8_t[]> pBuf(new uint8_t[nLen]);
|
||||
|
||||
FileSystem()->Read(pBuf.get(), nLen, pNavMesh);
|
||||
|
@ -24,10 +24,10 @@ void CBanSystem::Load(void)
|
||||
if (!pFile)
|
||||
return;
|
||||
|
||||
uint32_t nLen = FileSystem()->Size(pFile);
|
||||
const ssize_t nLen = FileSystem()->Size(pFile);
|
||||
std::unique_ptr<char[]> pBuf(new char[nLen + 1]);
|
||||
|
||||
int nRead = FileSystem()->Read(pBuf.get(), nLen, pFile);
|
||||
const ssize_t nRead = FileSystem()->Read(pBuf.get(), nLen, pFile);
|
||||
FileSystem()->Close(pFile);
|
||||
|
||||
pBuf.get()[nRead] = '\0'; // Null terminate the string buffer containing our banned list.
|
||||
@ -48,8 +48,8 @@ void CBanSystem::Load(void)
|
||||
nlohmann::json jsEntry = jsIn[std::to_string(i)];
|
||||
if (!jsEntry.is_null())
|
||||
{
|
||||
string svIpAddress = jsEntry["ipAddress"].get<string>();
|
||||
uint64_t nNucleusID = jsEntry["nucleusId"].get<uint64_t>();
|
||||
const string svIpAddress = jsEntry["ipAddress"].get<string>();
|
||||
const uint64_t nNucleusID = jsEntry["nucleusId"].get<uint64_t>();
|
||||
|
||||
m_vBanList.push_back(std::make_pair(svIpAddress, nNucleusID));
|
||||
}
|
||||
@ -85,7 +85,7 @@ void CBanSystem::Save(void) const
|
||||
jsOut["totalBans"] = m_vBanList.size();
|
||||
string svJsOut = jsOut.dump(4);
|
||||
|
||||
FileSystem()->Write(svJsOut.data(), int(svJsOut.size()), pFile);
|
||||
FileSystem()->Write(svJsOut.data(), svJsOut.size(), pFile);
|
||||
}
|
||||
catch (const std::exception& ex)
|
||||
{
|
||||
|
@ -185,17 +185,17 @@ enum
|
||||
abstract_class IBaseFileSystem
|
||||
{
|
||||
public:
|
||||
virtual int Read(void* pOutput, int size, FileHandle_t file) = 0;
|
||||
virtual int Write(void const* pInput, int size, FileHandle_t file) = 0;
|
||||
virtual ssize_t Read(void* pOutput, ssize_t size, FileHandle_t file) = 0;
|
||||
virtual ssize_t Write(void const* pInput, ssize_t size, FileHandle_t file) = 0;
|
||||
|
||||
// if pathID is NULL, all paths will be searched for the file
|
||||
virtual FileHandle_t Open(const char* pFileName, const char* pOptions, const char* pPathID = 0, int64_t unknown = 0) = 0;
|
||||
virtual void Close(FileHandle_t file) = 0;
|
||||
|
||||
virtual void Seek(FileHandle_t file, int pos, FileSystemSeek_t seekType) = 0;
|
||||
virtual unsigned int Tell(FileHandle_t file) = 0;
|
||||
virtual unsigned int FSize(const char* pFileName, const char* pPathID = 0) = 0; // Gets optimized away if it isn't named differently or used.
|
||||
virtual unsigned int Size(FileHandle_t file) = 0;
|
||||
virtual void Seek(FileHandle_t file, ptrdiff_t pos, FileSystemSeek_t seekType) = 0;
|
||||
virtual ptrdiff_t Tell(FileHandle_t file) = 0;
|
||||
virtual ssize_t FSize(const char* pFileName, const char* pPathID = 0) = 0; // Gets optimized away if it isn't named differently or used.
|
||||
virtual ssize_t Size(FileHandle_t file) = 0;
|
||||
|
||||
virtual void Flush(FileHandle_t file) = 0;
|
||||
virtual bool Precache(const char* pFileName, const char* pPathID = 0) = 0;
|
||||
@ -204,12 +204,12 @@ public:
|
||||
virtual bool IsFileWritable(char const* pFileName, const char* pPathID = 0) = 0;
|
||||
virtual bool SetFileWritable(char const* pFileName, bool writable, const char* pPathID = 0) = 0;
|
||||
|
||||
virtual long GetFileTime(const char* pFileName, const char* pPathID = 0) = 0;
|
||||
virtual long long GetFileTime(const char* pFileName, const char* pPathID = 0) = 0;
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Reads/writes files to utlbuffers. Use this for optimal read performance when doing open/read/close.
|
||||
//--------------------------------------------------------
|
||||
virtual bool ReadFile(const char* pFileName, const char* pPath, CUtlBuffer& buf, int nMaxBytes = 0, int nStartingByte = 0, FSAllocFunc_t pfnAlloc = NULL) = 0;
|
||||
virtual bool ReadFile(const char* pFileName, const char* pPath, CUtlBuffer& buf, ssize_t nMaxBytes = 0, ptrdiff_t nStartingByte = 0, FSAllocFunc_t pfnAlloc = NULL) = 0;
|
||||
virtual bool WriteFile(const char* pFileName, const char* pPath, CUtlBuffer& buf) = 0;
|
||||
virtual bool UnzipFile(const char* pFileName, const char* pPath, const char* pDestination) = 0;
|
||||
};
|
||||
@ -246,13 +246,13 @@ public:
|
||||
// remember it in case you add search paths with this path ID.
|
||||
virtual void MarkPathIDByRequestOnly(const char* pPathID, bool bRequestOnly) = 0;
|
||||
// converts a partial path into a full path
|
||||
virtual const char* RelativePathToFullPath(const char* pFileName, const char* pPathID, char* pLocalPath, size_t localPathBufferSize, PathTypeFilter_t pathFilter = FILTER_NONE, PathTypeQuery_t* pPathType = NULL) = 0;
|
||||
virtual const char* RelativePathToFullPath(const char* pFileName, const char* pPathID, char* pLocalPath, ssize_t localPathBufferSize, PathTypeFilter_t pathFilter = FILTER_NONE, PathTypeQuery_t* pPathType = NULL) = 0;
|
||||
#if IsGameConsole()
|
||||
// Given a relative path, gets the PACK file that contained this file and its offset and size. Can be used to prefetch a file to a HDD for caching reason.
|
||||
virtual bool GetPackFileInfoFromRelativePath(const char* pFileName, const char* pPathID, char* pPackPath, int nPackPathBufferSize, int64& nPosition, int64& nLength) = 0;
|
||||
virtual bool GetPackFileInfoFromRelativePath(const char* pFileName, const char* pPathID, char* pPackPath, ssize_t nPackPathBufferSize, ptrdiff_t& nPosition, ssize_t& nLength) = 0;
|
||||
#endif
|
||||
// Returns the search path, each path is separated by ;s. Returns the length of the string returned
|
||||
virtual int GetSearchPath(const char* pathID, bool bGetPackFiles, char* pPath, int nMaxLen) = 0;
|
||||
virtual ssize_t GetSearchPath(const char* pathID, bool bGetPackFiles, char* pPath, ssize_t nMaxLen) = 0;
|
||||
virtual bool AddPackFile(const char* fullpath, const char* pathID) = 0; // interface for custom pack files > 4Gb
|
||||
|
||||
//--------------------------------------------------------
|
||||
@ -262,21 +262,21 @@ public:
|
||||
virtual bool RenameFile(char const* pOldPath, char const* pNewPath, const char* pathID = 0) = 0; // Renames a file (on the WritePath)
|
||||
virtual int CreateDirHierarchy(const char* path, const char* pathID = 0) = 0; // create a local directory structure
|
||||
virtual bool IsDirectory(const char* pFileName, const char* pathID = 0) = 0; // File I/O and info
|
||||
virtual void FileTimeToString(char* pStrip, int maxCharsIncludingTerminator, long fileTime) = 0;
|
||||
virtual ssize_t FileTimeToString(char* pStrip, ssize_t maxCharsIncludingTerminator, long fileTime) = 0; // Returns the string size
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Open file operations
|
||||
//--------------------------------------------------------
|
||||
|
||||
virtual void SetBufferSize(FileHandle_t file, unsigned nBytes) = 0;
|
||||
virtual void SetBufferSize(FileHandle_t file/*, ssize_t nBytes*/) = 0; // Amos: unsure if this is accurate, no longer takes the second argument?
|
||||
virtual bool IsOk(FileHandle_t file) = 0;
|
||||
virtual bool EndOfFile(FileHandle_t file) = 0;
|
||||
virtual char* ReadLine(char* pOutput, int maxChars, FileHandle_t file) = 0;
|
||||
virtual char* ReadLine(char* pOutput, size_t maxChars, FileHandle_t file) = 0;
|
||||
#if ! defined(SWIG)
|
||||
// Don't let SWIG see the PRINTF_FORMAT_STRING attribute or it will complain.
|
||||
virtual int FPrintf(FileHandle_t file, PRINTF_FORMAT_STRING const char* pFormat, ...) FMTFUNCTION(3, 4) = 0;
|
||||
virtual ssize_t FPrintf(FileHandle_t file, PRINTF_FORMAT_STRING const char* pFormat, ...) FMTFUNCTION(3, 4) = 0;
|
||||
#else
|
||||
virtual int FPrintf(FileHandle_t file, const char* pFormat, ...) FMTFUNCTION(3, 4) = 0;
|
||||
virtual ssize_t FPrintf(FileHandle_t file, const char* pFormat, ...) FMTFUNCTION(3, 4) = 0;
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------
|
||||
@ -312,21 +312,21 @@ public:
|
||||
|
||||
// FIXME: This method is obsolete! Use RelativePathToFullPath instead!
|
||||
// converts a partial path into a full path
|
||||
virtual const char* GetLocalPath(const char* pFileName, char* pLocalPath, int localPathBufferSize) = 0;
|
||||
virtual const char* GetLocalPath(const char* pFileName, char* pLocalPath, ssize_t localPathBufferSize) = 0;
|
||||
|
||||
// Returns true on success ( based on current list of search paths, otherwise false if
|
||||
// it can't be resolved )
|
||||
virtual bool FullPathToRelativePath(const char* pFullpath, char* pRelative, int maxlen) = 0;
|
||||
virtual bool FullPathToRelativePath(const char* pFullpath, char* pRelative, ssize_t maxlen) = 0;
|
||||
|
||||
// Gets the current working directory
|
||||
virtual bool GetCurrentDirectory(char* pDirectory, int maxlen) = 0;
|
||||
virtual bool GetCurrentDirectory(char* pDirectory, unsigned int maxlen) = 0; // Last parameter is a DWORD passed to 'GetCurrentDirectoryA()' internally.
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Filename dictionary operations
|
||||
//--------------------------------------------------------
|
||||
|
||||
virtual FileNameHandle_t FindOrAddFileName(char const* pFileName) = 0;
|
||||
virtual bool String(const FileNameHandle_t& handle, char* buf, int buflen) = 0;
|
||||
virtual bool String(const FileNameHandle_t& handle, char* buf, ssize_t buflen) = 0;
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Asynchronous file operations
|
||||
@ -368,11 +368,11 @@ public:
|
||||
// Start of new functions after Lost Coast release (7/05)
|
||||
//--------------------------------------------------------
|
||||
|
||||
virtual FileHandle_t OpenEx(const char* pFileName, const char* pOptions, unsigned flags = 0, const char* pathID = 0, char** ppszResolvedFilename = NULL) = 0;
|
||||
virtual FileHandle_t OpenEx(const char* pFileName, const char* pOptions, unsigned flags = 0, const char* pathID = 0/*, char** ppszResolvedFilename = NULL*/) = 0;
|
||||
|
||||
// Extended version of read provides more context to allow for more optimal reading
|
||||
virtual int ReadEx(void* pOutput, int sizeDest, int size, FileHandle_t file) = 0;
|
||||
virtual int ReadFileEx(const char* pFileName, const char* pPath, void** ppBuf, bool bNullTerminate = false, bool bOptimalAlloc = false, int nMaxBytes = 0, int nStartingByte = 0, FSAllocFunc_t pfnAlloc = NULL) = 0;
|
||||
virtual ssize_t ReadEx(void* pOutput, ssize_t sizeDest, ssize_t size, FileHandle_t file) = 0;
|
||||
virtual ssize_t ReadFileEx(const char* pFileName, const char* pPath, void** ppBuf, bool bNullTerminate = false, bool bOptimalAlloc = false, ssize_t nMaxBytes = 0, ptrdiff_t nStartingByte = 0, FSAllocFunc_t pfnAlloc = NULL) = 0;
|
||||
|
||||
virtual FileNameHandle_t FindFileName(char const* pFileName) = 0;
|
||||
|
||||
@ -403,17 +403,17 @@ public:
|
||||
virtual KeyValues* LoadKeyValues(KeyValuesPreloadType_t type, char const* filename, char const* pPathID = 0) = 0;
|
||||
virtual bool LoadKeyValues(KeyValues& head, KeyValuesPreloadType_t type, char const* filename, char const* pPathID = 0) = 0;
|
||||
|
||||
virtual bool GetFileTypeForFullPath(char const* pFullPath, wchar_t* buf, size_t bufSizeInBytes) = 0;
|
||||
virtual bool GetFileTypeForFullPath(char const* pFullPath, wchar_t* buf, size_t bufSizeInBytes) = 0;
|
||||
|
||||
//--------------------------------------------------------
|
||||
//--------------------------------------------------------
|
||||
virtual bool ReadToBuffer(FileHandle_t hFile, CUtlBuffer& buf, int nMaxBytes = 0, FSAllocFunc_t pfnAlloc = NULL) = 0;
|
||||
virtual bool ReadToBuffer(FileHandle_t hFile, CUtlBuffer& buf, ssize_t nMaxBytes = 0, FSAllocFunc_t pfnAlloc = NULL) = 0;
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Optimal IO operations
|
||||
//--------------------------------------------------------
|
||||
virtual bool GetOptimalIOConstraints(FileHandle_t hFile, unsigned* pOffsetAlign, unsigned* pSizeAlign, unsigned* pBufferAlign) = 0;
|
||||
virtual void* AllocOptimalReadBuffer(FileHandle_t hFile, unsigned nSize = 0, unsigned nOffset = 0) = 0;
|
||||
virtual bool GetOptimalIOConstraints(FileHandle_t hFile, uint64_t* pOffsetAlign, uint64_t* pSizeAlign, uint64_t* pBufferAlign) = 0;
|
||||
virtual void* AllocOptimalReadBuffer(ptrdiff_t nOffset = 0/*!!! UNUSED !!!*/, ssize_t nSize = 0) = 0;
|
||||
virtual void FreeOptimalReadBuffer(void*) = 0;
|
||||
|
||||
|
||||
|
@ -12,16 +12,16 @@
|
||||
#include "filesystem/filesystem.h"
|
||||
|
||||
// Builds a directory which is a subdirectory of the current mod.
|
||||
void GetModSubdirectory( const char *pSubDir, char *pBuf, size_t nBufLen );
|
||||
void GetModSubdirectory( const char *pSubDir, char *pBuf, ssize_t nBufLen );
|
||||
|
||||
// Builds a directory which is a subdirectory of the current mod's *content*.
|
||||
void GetModContentSubdirectory( const char *pSubDir, char *pBuf, size_t nBufLen );
|
||||
void GetModContentSubdirectory( const char *pSubDir, char *pBuf, ssize_t nBufLen );
|
||||
|
||||
// Generates a filename under the 'game' subdirectory given a subdirectory of 'content'.
|
||||
void ComputeModFilename( const char *pContentFileName, char *pBuf, size_t nBufLen );
|
||||
void ComputeModFilename( const char *pContentFileName, char *pBuf, ssize_t nBufLen );
|
||||
|
||||
// Generates a filename under the 'content' subdirectory given a subdirectory of 'game'.
|
||||
void ComputeModContentFilename( const char *pGameFileName, char *pBuf, size_t nBufLen );
|
||||
void ComputeModContentFilename( const char *pGameFileName, char *pBuf, ssize_t nBufLen );
|
||||
|
||||
// Finds all files matching the a name within a directory and its sub directories. Output entries are paths to found files (relative to and including szStartDirectory).
|
||||
void RecursiveFindFilesMatchingName( CUtlVector< CUtlString > &fileList, const char* szStartDirectory, const char* szTargetFileName, const char *pPathID, char separator = CORRECT_PATH_SEPARATOR);
|
||||
@ -36,6 +36,6 @@ void GetSearchPath( CUtlVector< CUtlString > &pathList, const char *pPathID );
|
||||
// 1. if its full path already return.
|
||||
// 2. if its a relative path try to find it under the path id.
|
||||
// 3. if find fails treat relative path as relative to the current dir.
|
||||
bool GenerateFullPath( const char *pFileName, char const *pPathID, char *pBuf, size_t nBufLen );
|
||||
bool GenerateFullPath( const char *pFileName, char const *pPathID, char *pBuf, ssize_t nBufLen );
|
||||
|
||||
#endif // FILEUTILS_H
|
||||
|
@ -17,11 +17,11 @@
|
||||
// *pBuf -
|
||||
// nBufLen -
|
||||
//-----------------------------------------------------------------------------
|
||||
void GetModSubdirectory(const char* pSubDir, char* pBuf, size_t nBufLen)
|
||||
void GetModSubdirectory(const char* pSubDir, char* pBuf, ssize_t nBufLen)
|
||||
{
|
||||
// Compute starting directory.
|
||||
Assert(FileSystem()->GetSearchPath( "MOD", false, NULL, 0) < nBufLen );
|
||||
FileSystem()->GetSearchPath( "MOD", false, pBuf, int( nBufLen ) );
|
||||
FileSystem()->GetSearchPath( "MOD", false, pBuf, nBufLen );
|
||||
char* pSemi = strchr( pBuf, ';' );
|
||||
if ( pSemi )
|
||||
{
|
||||
@ -47,7 +47,7 @@ void GetModSubdirectory(const char* pSubDir, char* pBuf, size_t nBufLen)
|
||||
// *pBuf -
|
||||
// nBufLen -
|
||||
//-----------------------------------------------------------------------------
|
||||
void GetModContentSubdirectory( const char *pSubDir, char *pBuf, size_t nBufLen )
|
||||
void GetModContentSubdirectory( const char *pSubDir, char *pBuf, ssize_t nBufLen )
|
||||
{
|
||||
char pTemp[ MAX_PATH ];
|
||||
GetModSubdirectory( pSubDir, pTemp, sizeof(pTemp) );
|
||||
@ -60,7 +60,7 @@ void GetModContentSubdirectory( const char *pSubDir, char *pBuf, size_t nBufLen
|
||||
// *pBuf -
|
||||
// nBufLen -
|
||||
//-----------------------------------------------------------------------------
|
||||
void ComputeModFilename( const char *pContentFileName, char *pBuf, size_t nBufLen )
|
||||
void ComputeModFilename( const char *pContentFileName, char *pBuf, ssize_t nBufLen )
|
||||
{
|
||||
char pRelativePath[ MAX_PATH ];
|
||||
if ( !FileSystem()->FullPathToRelativePath(pContentFileName, pRelativePath, sizeof(pRelativePath)))
|
||||
@ -86,7 +86,7 @@ void ComputeModFilename( const char *pContentFileName, char *pBuf, size_t nBufLe
|
||||
// *pBuf -
|
||||
// nBufLen -
|
||||
//-----------------------------------------------------------------------------
|
||||
void ComputeModContentFilename( const char *pGameFileName, char *pBuf, size_t nBufLen )
|
||||
void ComputeModContentFilename( const char *pGameFileName, char *pBuf, ssize_t nBufLen )
|
||||
{
|
||||
char pRelativePath[ MAX_PATH ];
|
||||
if ( !FileSystem()->FullPathToRelativePath( pGameFileName, pRelativePath, sizeof(pRelativePath) ) )
|
||||
@ -214,7 +214,7 @@ void AddFilesToList( CUtlVector< CUtlString > &fileList, const char *pDirectory,
|
||||
//-----------------------------------------------------------------------------
|
||||
void GetSearchPath(CUtlVector< CUtlString >& pathList, const char* pPathID)
|
||||
{
|
||||
int nMaxLen = FileSystem()->GetSearchPath(pPathID, false, NULL, 0);
|
||||
const ssize_t nMaxLen = FileSystem()->GetSearchPath(pPathID, false, NULL, 0);
|
||||
char* pBuf = (char*)stackalloc(nMaxLen);
|
||||
FileSystem()->GetSearchPath(pPathID, false, pBuf, nMaxLen);
|
||||
|
||||
@ -236,7 +236,7 @@ void GetSearchPath(CUtlVector< CUtlString >& pathList, const char* pPathID)
|
||||
// nBufLen -
|
||||
// Output: True on success, false otherwise.
|
||||
//-----------------------------------------------------------------------------
|
||||
bool GenerateFullPath(const char* pFileName, char const* pPathID, char* pBuf, size_t nBufLen)
|
||||
bool GenerateFullPath(const char* pFileName, char const* pPathID, char* pBuf, ssize_t nBufLen)
|
||||
{
|
||||
if (V_IsAbsolutePath(pFileName))
|
||||
{
|
||||
@ -244,7 +244,7 @@ bool GenerateFullPath(const char* pFileName, char const* pPathID, char* pBuf, si
|
||||
return true;
|
||||
}
|
||||
|
||||
const char* pFullPath = FileSystem()->RelativePathToFullPath(pFileName, pPathID, pBuf, int(nBufLen));
|
||||
const char* pFullPath = FileSystem()->RelativePathToFullPath(pFileName, pPathID, pBuf, nBufLen);
|
||||
if (pFullPath && V_IsAbsolutePath(pFullPath))
|
||||
return true;
|
||||
|
||||
|
@ -29,10 +29,10 @@ RSON::Node_t* RSON::LoadFromFile(const char* pszFilePath, const char* pPathID)
|
||||
if (!file)
|
||||
return NULL;
|
||||
|
||||
unsigned int nFileSize = FileSystem()->Size(file);
|
||||
const ssize_t nFileSize = FileSystem()->Size(file);
|
||||
std::unique_ptr<char[]> fileBuf(new char[nFileSize + 1]);
|
||||
|
||||
int nRead = FileSystem()->Read(fileBuf.get(), nFileSize, file);
|
||||
const ssize_t nRead = FileSystem()->Read(fileBuf.get(), nFileSize, file);
|
||||
FileSystem()->Close(file);
|
||||
|
||||
fileBuf[nRead] = '\0';
|
||||
|
@ -335,7 +335,7 @@ void CPackedStore::ValidateCRC32PostDecomp(const CUtlString& assetPath, const ui
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t nLen = FileSystem()->Size(hAsset);
|
||||
const ssize_t nLen = FileSystem()->Size(hAsset);
|
||||
std::unique_ptr<uint8_t[]> pBuf(new uint8_t[nLen]);
|
||||
|
||||
FileSystem()->Read(pBuf.get(), nLen, hAsset);
|
||||
@ -402,7 +402,7 @@ bool CPackedStore::ShouldPrune(const CUtlString& filePath, CUtlVector<CUtlString
|
||||
|
||||
if (fileHandle)
|
||||
{
|
||||
const int nSize = FileSystem()->Size(fileHandle);
|
||||
const ssize_t nSize = FileSystem()->Size(fileHandle);
|
||||
|
||||
if (!nSize)
|
||||
{
|
||||
@ -467,8 +467,8 @@ void CPackedStore::PackWorkspace(const VPKPair_t& vpkPair, const char* workspace
|
||||
return;
|
||||
}
|
||||
|
||||
uint64_t nSharedTotal = NULL;
|
||||
uint64_t nSharedCount = NULL;
|
||||
size_t nSharedTotal = NULL;
|
||||
size_t nSharedCount = NULL;
|
||||
|
||||
FOR_EACH_VEC(entryValues, i)
|
||||
{
|
||||
@ -489,7 +489,7 @@ void CPackedStore::PackWorkspace(const VPKPair_t& vpkPair, const char* workspace
|
||||
szDestPath++;
|
||||
}
|
||||
|
||||
uint32_t nLen = FileSystem()->Size(hAsset);
|
||||
const ssize_t nLen = FileSystem()->Size(hAsset);
|
||||
std::unique_ptr<uint8_t[]> pBuf(new uint8_t[nLen]);
|
||||
|
||||
FileSystem()->Read(pBuf.get(), nLen, hAsset);
|
||||
@ -512,7 +512,7 @@ void CPackedStore::PackWorkspace(const VPKPair_t& vpkPair, const char* workspace
|
||||
{
|
||||
VPKChunkDescriptor_t& descriptor = entryBlock.m_Fragments[j];
|
||||
|
||||
FileSystem()->Read(pEntryBuffer.get(), int(descriptor.m_nCompressedSize), hAsset);
|
||||
FileSystem()->Read(pEntryBuffer.get(), descriptor.m_nCompressedSize, hAsset);
|
||||
descriptor.m_nPackFileOffset = FileSystem()->Tell(hPackFile);
|
||||
|
||||
if (entryValue.m_bDeduplicate && Deduplicate(pEntryBuffer.get(), descriptor, j))
|
||||
@ -542,13 +542,13 @@ void CPackedStore::PackWorkspace(const VPKPair_t& vpkPair, const char* workspace
|
||||
descriptor.m_nCompressedSize = descriptor.m_nUncompressedSize;
|
||||
}
|
||||
|
||||
FileSystem()->Write(pEntryBuffer.get(), int(descriptor.m_nCompressedSize), hPackFile);
|
||||
FileSystem()->Write(pEntryBuffer.get(), descriptor.m_nCompressedSize, hPackFile);
|
||||
}
|
||||
|
||||
FileSystem()->Close(hAsset);
|
||||
}
|
||||
|
||||
DevMsg(eDLL_T::FS, "*** Build block totaling '%lu' bytes with '%llu' shared bytes among '%llu' chunks\n", FileSystem()->Tell(hPackFile), nSharedTotal, nSharedCount);
|
||||
DevMsg(eDLL_T::FS, "*** Build block totaling '%zd' bytes with '%zu' shared bytes among '%zu' chunks\n", FileSystem()->Tell(hPackFile), nSharedTotal, nSharedCount);
|
||||
FileSystem()->Close(hPackFile);
|
||||
|
||||
m_ChunkHashMap.clear();
|
||||
@ -633,12 +633,12 @@ void CPackedStore::UnpackWorkspace(const VPKDir_t& vpkDir, const char* workspace
|
||||
{
|
||||
const VPKChunkDescriptor_t& fragment = entryBlock.m_Fragments[k];
|
||||
|
||||
FileSystem()->Seek(hPackFile, int(fragment.m_nPackFileOffset), FileSystemSeek_t::FILESYSTEM_SEEK_HEAD);
|
||||
FileSystem()->Read(pSourceBuffer.get(), int(fragment.m_nCompressedSize), hPackFile);
|
||||
FileSystem()->Seek(hPackFile, fragment.m_nPackFileOffset, FileSystemSeek_t::FILESYSTEM_SEEK_HEAD);
|
||||
FileSystem()->Read(pSourceBuffer.get(), fragment.m_nCompressedSize, hPackFile);
|
||||
|
||||
if (fragment.m_nCompressedSize == fragment.m_nUncompressedSize) // Data is not compressed.
|
||||
{
|
||||
FileSystem()->Write(pSourceBuffer.get(), int(fragment.m_nUncompressedSize), hAsset);
|
||||
FileSystem()->Write(pSourceBuffer.get(), fragment.m_nUncompressedSize, hAsset);
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -658,7 +658,7 @@ void CPackedStore::UnpackWorkspace(const VPKDir_t& vpkDir, const char* workspace
|
||||
}
|
||||
else // If successfully decompressed, write to file.
|
||||
{
|
||||
FileSystem()->Write(pDestBuffer.get(), int(nDstLen), hAsset);
|
||||
FileSystem()->Write(pDestBuffer.get(), nDstLen, hAsset);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1063,14 +1063,14 @@ int VPKDir_t::CTreeBuilder::WriteTree(FileHandle_t hDirectoryFile) const
|
||||
|
||||
for (auto& iKeyValue : m_FileTree)
|
||||
{
|
||||
FileSystem()->Write(iKeyValue.first.c_str(), int(iKeyValue.first.length() + 1), hDirectoryFile);
|
||||
FileSystem()->Write(iKeyValue.first.c_str(), iKeyValue.first.length() + 1, hDirectoryFile);
|
||||
for (auto& jKeyValue : iKeyValue.second)
|
||||
{
|
||||
FileSystem()->Write(jKeyValue.first.c_str(), int(jKeyValue.first.length() + 1), hDirectoryFile);
|
||||
FileSystem()->Write(jKeyValue.first.c_str(), jKeyValue.first.length() + 1, hDirectoryFile);
|
||||
for (auto& vEntry : jKeyValue.second)
|
||||
{
|
||||
CUtlString entryPath = vEntry.m_EntryPath.UnqualifiedFilename().StripExtension();
|
||||
FileSystem()->Write(entryPath.Get(), int(entryPath.Length() + 1), hDirectoryFile);
|
||||
const CUtlString entryPath = vEntry.m_EntryPath.UnqualifiedFilename().StripExtension();
|
||||
FileSystem()->Write(entryPath.Get(), entryPath.Length() + 1, hDirectoryFile);
|
||||
|
||||
FileSystem()->Write(&vEntry.m_nFileCRC, sizeof(uint32_t), hDirectoryFile);
|
||||
FileSystem()->Write(&vEntry.m_iPreloadSize, sizeof(uint16_t), hDirectoryFile);
|
||||
@ -1133,7 +1133,7 @@ void VPKDir_t::BuildDirectoryFile(const CUtlString& directoryPath, const CUtlVec
|
||||
WriteTreeSize(hDirectoryFile);
|
||||
|
||||
FileSystem()->Close(hDirectoryFile);
|
||||
DevMsg(eDLL_T::FS, "*** Build directory totaling '%llu' bytes with '%i' entries and '%i' descriptors\n",
|
||||
DevMsg(eDLL_T::FS, "*** Build directory totaling '%zu' bytes with '%i' entries and '%i' descriptors\n",
|
||||
size_t(sizeof(VPKDirHeader_t) + m_Header.m_nDirectorySize), entryBlocks.Count(), nDescriptors);
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
|
Loading…
x
Reference in New Issue
Block a user