diff --git a/r5dev/filesystem/basefilesystem.cpp b/r5dev/filesystem/basefilesystem.cpp index a20e8735..c0a19764 100644 --- a/r5dev/filesystem/basefilesystem.cpp +++ b/r5dev/filesystem/basefilesystem.cpp @@ -52,7 +52,40 @@ void CBaseFileSystem::Warning(CBaseFileSystem* pFileSystem, FileWarningLevel_t l } //--------------------------------------------------------------------------------- -// Purpose: attempts to load files from disk if exist before loading from VPK +// Purpose: attempts to load files from disk if exist before loading from VPK/cache +// Input : *pszFilePath - +// Output : handle to file on success, NULL on failure +//--------------------------------------------------------------------------------- +bool CBaseFileSystem::VCheckDisk(const char* pszFilePath) +{ + // Only load material files from the disk if the mode isn't zero, + // use -novpk to load valve materials from the disk. + if (FileSystem()->CheckVPKMode(0) && strstr(pszFilePath, ".vmt")) + { + return false; + } + + std::string svFilePath = ConvertToWinPath(pszFilePath); + + if (svFilePath.find("\\\*\\") != string::npos) + { + // Erase '//*/'. + svFilePath.erase(0, 4); + } + + // TODO: obtain 'mod' SearchPath's instead. + svFilePath.insert(0, "platform\\"); + + if (::FileExists(svFilePath) /*|| ::FileExists(pszFilePath)*/) + { + return true; + } + + return false; +} + +//--------------------------------------------------------------------------------- +// Purpose: loads files from VPK // Input : *this - // *pResults - // *pszFilePath - @@ -60,27 +93,17 @@ void CBaseFileSystem::Warning(CBaseFileSystem* pFileSystem, FileWarningLevel_t l //--------------------------------------------------------------------------------- FileHandle_t CBaseFileSystem::VReadFromVPK(CBaseFileSystem* pFileSystem, FileHandle_t pResults, char* pszFilePath) { - std::string svFilePath = ConvertToWinPath(pszFilePath); - - if (svFilePath.find("\\\*\\") != string::npos) - { - // Erase '//*/'. - svFilePath.erase(0, 4); - } - - // TODO: obtain 'mod' SearchPath's instead. - svFilePath.insert(0, "platform\\"); - - if (::FileExists(svFilePath) /*|| ::FileExists(pszFilePath)*/) + if (VCheckDisk(pszFilePath)) { *reinterpret_cast(pResults) = -1; return pResults; } + return v_CBaseFileSystem_LoadFromVPK(pFileSystem, pResults, pszFilePath); } //--------------------------------------------------------------------------------- -// Purpose: attempts to load files from disk if exist before loading from cache +// Purpose: loads files from cache // Input : *this - // *pszFilePath - // *pResults - @@ -88,21 +111,11 @@ FileHandle_t CBaseFileSystem::VReadFromVPK(CBaseFileSystem* pFileSystem, FileHan //--------------------------------------------------------------------------------- bool CBaseFileSystem::VReadFromCache(CBaseFileSystem* pFileSystem, char* pszFilePath, void* pResults) { - std::string svFilePath = ConvertToWinPath(pszFilePath); - - if (svFilePath.find("\\\*\\") != string::npos) - { - // Erase '//*/'. - svFilePath.erase(0, 4); - } - - // TODO: obtain 'mod' SearchPath's instead. - svFilePath.insert(0, "platform\\"); - - if (::FileExists(svFilePath) /*|| ::FileExists(pszFilePath)*/) + if (VCheckDisk(pszFilePath)) { return false; } + return v_CBaseFileSystem_LoadFromCache(pFileSystem, pszFilePath, pResults); } diff --git a/r5dev/filesystem/basefilesystem.h b/r5dev/filesystem/basefilesystem.h index d666327b..ad581b83 100644 --- a/r5dev/filesystem/basefilesystem.h +++ b/r5dev/filesystem/basefilesystem.h @@ -8,6 +8,7 @@ public: // Purpose: Static methods used for hooking. //-------------------------------------------------------- static void Warning(CBaseFileSystem* pFileSystem, FileWarningLevel_t level, const char* fmt, ...); + static bool VCheckDisk(const char* pszFilePath); static FileHandle_t VReadFromVPK(CBaseFileSystem* pFileSystem, FileHandle_t pResults, char* pszFilePath); static bool VReadFromCache(CBaseFileSystem* pFileSystem, char* pszFilePath, void* pResults); static VPKData_t* VMountVPKFile(CBaseFileSystem* pFileSystem, const char* pszVpkPath); diff --git a/r5dev/public/ifilesystem.h b/r5dev/public/ifilesystem.h index aabadbb7..7fedab36 100644 --- a/r5dev/public/ifilesystem.h +++ b/r5dev/public/ifilesystem.h @@ -385,7 +385,7 @@ public: virtual bool __fastcall sub_140383E00(__int64 a2) = 0; virtual bool sub_1403836A0() = 0; virtual __int64 __fastcall sub_140384310(int a1) = 0; - virtual __int64 __fastcall sub_140383820(int a1) = 0; + virtual __int64 __fastcall CheckVPKMode(int nMode) = 0; // Checks if the VPK mode equals the mode input. //--------------------------------------------------------