r5sdk/r5dev/filesystem/filesystem.h
Kawe Mazidjatari 9bf7660138 FileSystem improvements
* Added method 'FPrintf'.
* Shifted indexes back by 2 if <GAMEDLL_S3 (Anything <S3 doesn't have the 2 FeatureFlags initialization methods which shifts everything past index 10 back by 2).
2022-08-12 15:51:04 +02:00

61 lines
2.4 KiB
C++

#ifndef FILESYSTEM_H
#define FILESYSTEM_H
#include "vpklib/packedstore.h"
#include "filesystem/basefilesystem.h"
#define GAMEINFOPATH_TOKEN "|gameinfo_path|"
#define BASESOURCEPATHS_TOKEN "|all_source_engine_paths|"
#if defined (GAMEDLL_S0) || defined (GAMEDLL_S1) || defined (GAMEDLL_S2)
constexpr int FS_VFTABLE_SHIFT = 2;
#else
constexpr int FS_VFTABLE_SHIFT = 0;
#endif
class IFileSystem
{
public:
void AddSearchPath(const char* pPath, const char* pPathID, SearchPathAdd_t addType);
bool RemoveSearchPath(const char* pPath, const char* pPathID);
int FPrintf(FileHandle_t file, const char* pFormat, ...) FMTFUNCTION(3, 4);
bool ReadFromCache(const char* pPath, void* pResult);
VPKData_t* MountVPK(const char* pVpkPath);
};
class CFileSystem_Stdio : public IFileSystem, public CBaseFileSystem
{
};
extern CFileSystem_Stdio** g_pFullFileSystem; // Ptr to g_pFileSystem_Stdio.
extern CFileSystem_Stdio* g_pFileSystem_Stdio;
CFileSystem_Stdio* FileSystem();
///////////////////////////////////////////////////////////////////////////////
class VFileSystem_Stdio : public IDetour
{
virtual void GetAdr(void) const
{
spdlog::debug("| VAR: g_pFullFileSystem : {:#18x} |\n", reinterpret_cast<uintptr_t>(g_pFullFileSystem));
spdlog::debug("| VAR: g_pFileSystem_Stdio : {:#18x} |\n", reinterpret_cast<uintptr_t>(g_pFileSystem_Stdio));
spdlog::debug("+----------------------------------------------------------------+\n");
}
virtual void GetFun(void) const { }
virtual void GetVar(void) const
{
g_pFullFileSystem = g_GameDll.FindPatternSIMD(reinterpret_cast<rsig_t>("\x48\x8B\x0D\x00\x00\x00\x00\x45\x33\xC0\x48\x83\xC1\x08\x48\x8B\x01"),
"xxx????xxxxxxxxxx").ResolveRelativeAddressSelf(0x3, 0x7).RCast<CFileSystem_Stdio**>();
g_pFileSystem_Stdio = g_GameDll.FindPatternSIMD(reinterpret_cast<rsig_t>("\x48\x8D\x05\x00\x00\x00\x00\x48\x89\x05\x00\x00\x00\x00\x48\x8D\x0D\x00\x00\x00\x00\x48\x8D\x05\x00\x00\x00\x00\x48\x89\x05\x00\x00\x00\x00\xE9\x00\x00\x00\x00"),
"xxx????xxx????xxx????xxx????xxx????x????").FindPattern("48 89", CMemory::Direction::DOWN, 512, 1).ResolveRelativeAddressSelf(0x3, 0x7).RCast<CFileSystem_Stdio*>();
}
virtual void GetCon(void) const { }
virtual void Attach(void) const { }
virtual void Detach(void) const { }
};
///////////////////////////////////////////////////////////////////////////////
REGISTER(VFileSystem_Stdio);
#endif // !FILESYSTEM_H