Add filesystem cache types

Types for file system cache.
This commit is contained in:
Kawe Mazidjatari 2023-05-20 14:04:33 +02:00
parent 44edef1724
commit e338f0331a
3 changed files with 49 additions and 8 deletions

View File

@ -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;
}
//---------------------------------------------------------------------------------

View File

@ -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<FileHandle_t(*)(CBaseFileSystem* pFileSystem, FileHandle_t pResults, const char* pszAssetName)>();
inline CMemory p_CBaseFileSystem_LoadFromCache;
inline auto v_CBaseFileSystem_LoadFromCache = p_CBaseFileSystem_LoadFromCache.RCast<bool(*)(CBaseFileSystem* pFileSystem, const char* pszAssetName, void* pResults)>();
inline auto v_CBaseFileSystem_LoadFromCache = p_CBaseFileSystem_LoadFromCache.RCast<bool(*)(CBaseFileSystem* pFileSystem, const char* pszAssetName, FileSystemCache* pCache)>();
inline CMemory p_CBaseFileSystem_MountVPKFile;
inline auto v_CBaseFileSystem_MountVPKFile = p_CBaseFileSystem_MountVPKFile.RCast<VPKData_t* (*)(CBaseFileSystem* pFileSystem, const char* pszVpkPath)>();
@ -86,7 +86,7 @@ class VBaseFileSystem : public IDetour
v_CBaseFileSystem_Warning = p_CBaseFileSystem_Warning.RCast<void(*)(CBaseFileSystem*, FileWarningLevel_t, const char*, ...)>(); /*4C 89 4C 24 20 C3 ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? 48*/
v_CBaseFileSystem_LoadFromVPK = p_CBaseFileSystem_LoadFromVPK.RCast<FileHandle_t(*)(CBaseFileSystem*, FileHandle_t, const char*)>(); /*48 89 5C 24 ?? 57 48 81 EC ?? ?? ?? ?? 49 8B C0 4C 8D 8C 24 ?? ?? ?? ??*/
v_CBaseFileSystem_LoadFromCache = p_CBaseFileSystem_LoadFromCache.RCast<bool(*)(CBaseFileSystem*, const char*, void*)>(); /*40 53 48 81 EC ?? ?? ?? ?? 80 3D ?? ?? ?? ?? ?? 49 8B D8*/
v_CBaseFileSystem_LoadFromCache = p_CBaseFileSystem_LoadFromCache.RCast<bool(*)(CBaseFileSystem*, const char*, FileSystemCache*)>(); /*40 53 48 81 EC ?? ?? ?? ?? 80 3D ?? ?? ?? ?? ?? 49 8B D8*/
v_CBaseFileSystem_MountVPKFile = p_CBaseFileSystem_MountVPKFile.RCast<VPKData_t*(*)(CBaseFileSystem*, const char*)>(); /*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<const char*(*)(CBaseFileSystem*, const char*)>(); /*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<int (*)(CBaseFileSystem*, const char*)>(); /*48 89 74 24 ?? 57 48 81 EC ?? ?? ?? ?? 48 8B F9 4C 8D 05 ?? ?? ?? ??*/

View File

@ -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;