From e338f0331ac3bc511b8158fc155f464e9bc34f07 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Sat, 20 May 2023 14:04:33 +0200 Subject: [PATCH] Add filesystem cache types Types for file system cache. --- r5dev/filesystem/basefilesystem.cpp | 7 +++-- r5dev/filesystem/basefilesystem.h | 6 ++-- r5dev/public/ifilesystem.h | 44 +++++++++++++++++++++++++++-- 3 files changed, 49 insertions(+), 8 deletions(-) diff --git a/r5dev/filesystem/basefilesystem.cpp b/r5dev/filesystem/basefilesystem.cpp index 96b70747..b8c4cdf5 100644 --- a/r5dev/filesystem/basefilesystem.cpp +++ b/r5dev/filesystem/basefilesystem.cpp @@ -87,17 +87,18 @@ FileHandle_t CBaseFileSystem::VReadFromVPK(CBaseFileSystem* pFileSystem, FileHan // Purpose: loads files from cache // Input : *this - // *pszFilePath - -// *pResults - +// *pCache - // Output : true if file exists, false otherwise //--------------------------------------------------------------------------------- -bool CBaseFileSystem::VReadFromCache(CBaseFileSystem* pFileSystem, char* pszFilePath, void* pResults) +bool CBaseFileSystem::VReadFromCache(CBaseFileSystem* pFileSystem, char* pszFilePath, FileSystemCache* pCache) { if (VCheckDisk(pszFilePath)) { return false; } - return v_CBaseFileSystem_LoadFromCache(pFileSystem, pszFilePath, pResults); + bool result = v_CBaseFileSystem_LoadFromCache(pFileSystem, pszFilePath, pCache); + return result; } //--------------------------------------------------------------------------------- diff --git a/r5dev/filesystem/basefilesystem.h b/r5dev/filesystem/basefilesystem.h index d5ef07f9..3f8228c2 100644 --- a/r5dev/filesystem/basefilesystem.h +++ b/r5dev/filesystem/basefilesystem.h @@ -10,7 +10,7 @@ public: 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 bool VReadFromCache(CBaseFileSystem* pFileSystem, char* pszFilePath, FileSystemCache* pCache); static VPKData_t* VMountVPKFile(CBaseFileSystem* pFileSystem, const char* pszVpkPath); static const char* VUnmountVPKFile(CBaseFileSystem* pFileSystem, const char* pszVpkPath); @@ -49,7 +49,7 @@ inline CMemory p_CBaseFileSystem_LoadFromVPK; inline auto v_CBaseFileSystem_LoadFromVPK = p_CBaseFileSystem_LoadFromVPK.RCast(); inline CMemory p_CBaseFileSystem_LoadFromCache; -inline auto v_CBaseFileSystem_LoadFromCache = p_CBaseFileSystem_LoadFromCache.RCast(); +inline auto v_CBaseFileSystem_LoadFromCache = p_CBaseFileSystem_LoadFromCache.RCast(); inline CMemory p_CBaseFileSystem_MountVPKFile; inline auto v_CBaseFileSystem_MountVPKFile = p_CBaseFileSystem_MountVPKFile.RCast(); @@ -86,7 +86,7 @@ class VBaseFileSystem : public IDetour v_CBaseFileSystem_Warning = p_CBaseFileSystem_Warning.RCast(); /*4C 89 4C 24 20 C3 ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? 48*/ v_CBaseFileSystem_LoadFromVPK = p_CBaseFileSystem_LoadFromVPK.RCast(); /*48 89 5C 24 ?? 57 48 81 EC ?? ?? ?? ?? 49 8B C0 4C 8D 8C 24 ?? ?? ?? ??*/ - v_CBaseFileSystem_LoadFromCache = p_CBaseFileSystem_LoadFromCache.RCast(); /*40 53 48 81 EC ?? ?? ?? ?? 80 3D ?? ?? ?? ?? ?? 49 8B D8*/ + v_CBaseFileSystem_LoadFromCache = p_CBaseFileSystem_LoadFromCache.RCast(); /*40 53 48 81 EC ?? ?? ?? ?? 80 3D ?? ?? ?? ?? ?? 49 8B D8*/ v_CBaseFileSystem_MountVPKFile = p_CBaseFileSystem_MountVPKFile.RCast(); /*48 89 5C 24 ?? 48 89 6C 24 ?? 57 48 81 EC ?? ?? ?? ?? 48 8B F9 4C 8D 05 ?? ?? ?? ??*/ v_CBaseFileSystem_UnmountVPKFile = p_CBaseFileSystem_UnmountVPKFile.RCast(); /*48 89 5C 24 ?? 57 48 83 EC 20 48 8B DA 48 8B F9 48 8B CB 48 8D 15 ?? ?? ?? ?? E8 ?? ?? ?? ?? 48 85 C0*/ v_CBaseFileSystem_GetMountedVPKHandle = p_CBaseFileSystem_GetMountedVPKHandle.RCast(); /*48 89 74 24 ?? 57 48 81 EC ?? ?? ?? ?? 48 8B F9 4C 8D 05 ?? ?? ?? ??*/ diff --git a/r5dev/public/ifilesystem.h b/r5dev/public/ifilesystem.h index a38c6d04..a025c6c0 100644 --- a/r5dev/public/ifilesystem.h +++ b/r5dev/public/ifilesystem.h @@ -37,10 +37,50 @@ struct FileSystemStatistics nSeeks; }; +struct FileSystemCacheDescriptor +{ + const char* pszFilePath; + const char* pszFileName; + const char* pszFileExt; + + void* pUnk0; // Ptr to ptr of some dynamically allocated buffer. + + int nFileSize; + int nFileFlags; // Might be wrong. + + void* pUnk1; // Ptr to some data; compressed perhaps? + + int nUnk0; + int nUnk1; + + int nUnk2; + int nUnk3; + int nUnk4; + + int nPadding; +}; + +struct FileSystemCacheBuffer +{ + byte* pData; // Actual file buffer. + void* pUnk; + int nUnk0; + volatile LONG nLock; + int nUnk1; + int nUnk2; // Used to index into arrays. +}; + +struct FileSystemCache +{ + int nUnk0; // Most of the time, this is set to '1'. + FileSystemCacheDescriptor* pDescriptor; + FileSystemCacheBuffer* pBuffer; +}; + //----------------------------------------------------------------------------- // File system allocation functions. Client must free on failure //----------------------------------------------------------------------------- -typedef void* (*FSAllocFunc_t)(const char* pszFilename, unsigned nBytes); +typedef void* (*FSAllocFunc_t)(const char* pszFileName, unsigned nBytes); //----------------------------------------------------------------------------- @@ -386,7 +426,7 @@ public: //-------------------------------------------------------- // Cache/VPK operations //-------------------------------------------------------- - virtual bool ReadFromCache(const char* pPath, void* pResult) = 0; + virtual bool ReadFromCache(const char* pPath, FileSystemCache* pCache) = 0; virtual bool __fastcall sub_14037FFA0(__int64 a1, unsigned int a2, __int64 a3) = 0;