2021-12-25 22:36:38 +01:00
|
|
|
#pragma once
|
2022-08-13 11:24:55 +02:00
|
|
|
#include "public/ifilesystem.h"
|
2022-06-12 12:14:31 +02:00
|
|
|
|
2022-08-13 11:24:55 +02:00
|
|
|
class CBaseFileSystem : public IFileSystem
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2022-04-09 00:59:42 +02:00
|
|
|
public:
|
2022-08-13 11:24:55 +02:00
|
|
|
//--------------------------------------------------------
|
|
|
|
// Purpose: Static methods used for hooking.
|
|
|
|
//--------------------------------------------------------
|
2022-04-09 00:59:42 +02:00
|
|
|
static void Warning(CBaseFileSystem* pFileSystem, FileWarningLevel_t level, const char* fmt, ...);
|
2022-11-08 01:11:14 +01:00
|
|
|
static bool VCheckDisk(const char* pszFilePath);
|
2023-11-26 13:21:20 +01:00
|
|
|
static FileHandle_t VReadFromVPK(CBaseFileSystem* pFileSystem, FileHandle_t pResults, const char* pszFilePath);
|
|
|
|
static bool VReadFromCache(CBaseFileSystem* pFileSystem, const char* pszFilePath, FileSystemCache* pCache);
|
2023-05-22 12:32:49 +02:00
|
|
|
static void VAddMapPackFile(CBaseFileSystem* pFileSystem, const char* pPath, const char* pPathID, SearchPathAdd_t addType);
|
2022-11-06 12:21:21 +01:00
|
|
|
static VPKData_t* VMountVPKFile(CBaseFileSystem* pFileSystem, const char* pszVpkPath);
|
|
|
|
static const char* VUnmountVPKFile(CBaseFileSystem* pFileSystem, const char* pszVpkPath);
|
2022-08-13 11:24:55 +02:00
|
|
|
|
2023-05-29 21:41:17 +02:00
|
|
|
CUtlString ReadString(FileHandle_t pFile);
|
2022-11-23 12:18:33 +01:00
|
|
|
|
2022-08-13 11:24:55 +02:00
|
|
|
protected:
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// Purpose: Functions implementing basic file system behavior.
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
virtual FILE* FS_fopen(const char* filename, const char* options, unsigned flags, int64* size) = 0;
|
|
|
|
virtual void FS_setbufsize(FILE* fp, unsigned nBytes) = 0;
|
|
|
|
virtual void FS_fclose(FILE* fp) = 0;
|
|
|
|
virtual void FS_fseek(FILE* fp, int64 pos, int seekType) = 0;
|
|
|
|
virtual long FS_ftell(FILE* fp) = 0;
|
|
|
|
virtual int FS_feof(FILE* fp) = 0;
|
|
|
|
virtual size_t FS_fread(void* dest, size_t destSize, size_t size, FILE* fp) = 0;
|
|
|
|
virtual size_t FS_fwrite(const void* src, size_t size, FILE* fp) = 0;
|
|
|
|
virtual bool FS_setmode(FILE* fp, FileMode_t mode) = 0;
|
|
|
|
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 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;
|
|
|
|
virtual bool FS_FindNextFile(HANDLE handle, WIN32_FIND_DATA* dat) = 0;
|
|
|
|
virtual bool FS_FindClose(HANDLE handle) = 0;
|
|
|
|
virtual int FS_GetSectorSize(FILE*) = 0;
|
2021-12-25 22:36:38 +01:00
|
|
|
};
|
|
|
|
|
2022-04-09 01:14:22 +02:00
|
|
|
/* ==== CBASEFILESYSTEM ================================================================================================================================================= */
|
2024-01-02 15:21:36 +01:00
|
|
|
inline void(*CBaseFileSystem__Warning)(CBaseFileSystem* pFileSystem, FileWarningLevel_t level, const char* fmt, ...);
|
|
|
|
inline FileHandle_t(*CBaseFileSystem__LoadFromVPK)(CBaseFileSystem* pFileSystem, FileHandle_t pResults, const char* pszAssetName);
|
|
|
|
inline bool(*CBaseFileSystem__LoadFromCache)(CBaseFileSystem* pFileSystem, const char* pszAssetName, FileSystemCache* pCache);
|
|
|
|
inline void(*CBaseFileSystem__AddMapPackFile)(CBaseFileSystem* pFileSystem, const char* pPath, const char* pPathID, SearchPathAdd_t addType);
|
|
|
|
inline VPKData_t*(*CBaseFileSystem__MountVPKFile)(CBaseFileSystem* pFileSystem, const char* pszVpkPath);
|
|
|
|
inline const char* (*CBaseFileSystem__UnmountVPKFile)(CBaseFileSystem* pFileSystem, const char* pszVpkPath);
|
|
|
|
inline int(*CBaseFileSystem__GetMountedVPKHandle)(CBaseFileSystem* pFileSystem, const char* pszVpkPath);
|
2022-04-09 00:59:42 +02:00
|
|
|
|
2022-05-27 22:38:49 +02:00
|
|
|
extern CBaseFileSystem* g_pFileSystem;
|
2021-12-25 22:36:38 +01:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2022-05-13 14:53:25 +02:00
|
|
|
class VBaseFileSystem : public IDetour
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2022-04-11 01:44:30 +02:00
|
|
|
virtual void GetAdr(void) const
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2024-01-02 15:21:36 +01:00
|
|
|
LogFunAdr("CBaseFileSystem::Warning", CBaseFileSystem__Warning);
|
|
|
|
LogFunAdr("CBaseFileSystem::LoadFromVPK", CBaseFileSystem__LoadFromVPK);
|
|
|
|
LogFunAdr("CBaseFileSystem::LoadFromCache", CBaseFileSystem__LoadFromCache);
|
|
|
|
LogFunAdr("CBaseFileSystem::AddMapPackFile", CBaseFileSystem__AddMapPackFile);
|
|
|
|
LogFunAdr("CBaseFileSystem::MountVPKFile", CBaseFileSystem__MountVPKFile);
|
|
|
|
LogFunAdr("CBaseFileSystem::UnmountVPKFile", CBaseFileSystem__UnmountVPKFile);
|
|
|
|
LogFunAdr("CBaseFileSystem::GetMountedVPKHandle", CBaseFileSystem__GetMountedVPKHandle);
|
|
|
|
LogVarAdr("g_pFileSystem", g_pFileSystem);
|
2021-12-25 22:36:38 +01:00
|
|
|
}
|
2022-04-18 03:35:08 +02:00
|
|
|
virtual void GetFun(void) const
|
|
|
|
{
|
2024-01-02 15:21:36 +01:00
|
|
|
g_GameDll.FindPatternSIMD("4C 89 4C 24 20 C3 CC CC CC CC CC CC CC CC CC CC 48").GetPtr(CBaseFileSystem__Warning);
|
|
|
|
g_GameDll.FindPatternSIMD("48 89 5C 24 ?? 57 48 81 EC ?? ?? ?? ?? 49 8B C0 4C 8D 8C 24 ?? ?? ?? ??").GetPtr(CBaseFileSystem__LoadFromVPK);
|
|
|
|
g_GameDll.FindPatternSIMD("40 53 48 81 EC ?? ?? ?? ?? 80 3D ?? ?? ?? ?? ?? 49 8B D8").GetPtr(CBaseFileSystem__LoadFromCache);
|
|
|
|
g_GameDll.FindPatternSIMD("4C 89 44 24 ?? 48 89 54 24 ?? 55 ?? 41 54 41 55 48 8D AC 24 ?? ?? ?? ??").GetPtr(CBaseFileSystem__AddMapPackFile);
|
|
|
|
g_GameDll.FindPatternSIMD("48 89 5C 24 ?? 48 89 6C 24 ?? 57 48 81 EC ?? ?? ?? ?? 48 8B F9 4C 8D 05 ?? ?? ?? ??").GetPtr(CBaseFileSystem__MountVPKFile);
|
|
|
|
g_GameDll.FindPatternSIMD("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").GetPtr(CBaseFileSystem__UnmountVPKFile);
|
|
|
|
g_GameDll.FindPatternSIMD("48 89 74 24 ?? 57 48 81 EC ?? ?? ?? ?? 48 8B F9 4C 8D 05 ?? ?? ?? ??").GetPtr(CBaseFileSystem__GetMountedVPKHandle);
|
2022-04-18 03:35:08 +02:00
|
|
|
}
|
|
|
|
virtual void GetVar(void) const
|
|
|
|
{
|
2022-12-01 22:44:55 +01:00
|
|
|
g_pFileSystem = g_GameDll.FindPatternSIMD("48 8D 05 ?? ?? ?? ?? 48 89 05 ?? ?? ?? ?? 48 8D 0D ?? ?? ?? ?? 48 8D 05 ?? ?? ?? ?? 48 89 05 ?? ?? ?? ?? E9 ?? ?? ?? ??")
|
|
|
|
.FindPattern("48 89", CMemory::Direction::DOWN, 512, 2).ResolveRelativeAddressSelf(0x3, 0x7).RCast<CBaseFileSystem*>();
|
2022-04-18 03:35:08 +02:00
|
|
|
}
|
2022-04-11 01:44:30 +02:00
|
|
|
virtual void GetCon(void) const { }
|
2023-11-26 13:21:20 +01:00
|
|
|
virtual void Detour(const bool bAttach) const;
|
2021-12-25 22:36:38 +01:00
|
|
|
};
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|