From 9bf76601386ba0887a13f34c5700fcb0efee5506 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Fri, 12 Aug 2022 15:51:04 +0200 Subject: [PATCH] FileSystem improvements * Added method 'FPrintf'. * Shifted indexes back by 2 if (index, this, pPath, pPathID, addType); } @@ -31,10 +31,34 @@ void IFileSystem::AddSearchPath(const char* pPath, const char* pPathID, SearchPa //----------------------------------------------------------------------------- bool IFileSystem::RemoveSearchPath(const char* pPath, const char* pPathID) { - const int index = 13; + const int index = (13 - FS_VFTABLE_SHIFT); return CallVFunc(index, this, pPath, pPathID); } +//----------------------------------------------------------------------------- +// Purpose: print to file. +// Input : file - +// *pFormat - +// ... - +// Output : number of bytes written. +//----------------------------------------------------------------------------- +int IFileSystem::FPrintf(FileHandle_t file, const char* pFormat, ...) FMTFUNCTION(3, 4) +{ + const int index = (29 - FS_VFTABLE_SHIFT); + char buf[65560]; + {///////////////////////////// + va_list args{}; + va_start(args, pFormat); + + vsnprintf(buf, sizeof(buf), pFormat, args); + + buf[sizeof(buf) - 1] = '\0'; + va_end(args); + }///////////////////////////// + + return CallVFunc(index, this, file, buf); +} + //----------------------------------------------------------------------------- // Purpose: read file from cache. // Input : *pPath - @@ -43,7 +67,7 @@ bool IFileSystem::RemoveSearchPath(const char* pPath, const char* pPathID) //----------------------------------------------------------------------------- bool IFileSystem::ReadFromCache(const char* pPath, void* pResult) { - const int index = 76; + const int index = (76 - FS_VFTABLE_SHIFT); return CallVFunc(index, this, pPath, pResult); } @@ -54,7 +78,7 @@ bool IFileSystem::ReadFromCache(const char* pPath, void* pResult) //----------------------------------------------------------------------------- VPKData_t* IFileSystem::MountVPK(const char* pPath) { - const int index = 92; + const int index = (92 - FS_VFTABLE_SHIFT); return CallVFunc(index, this, pPath); } diff --git a/r5dev/filesystem/filesystem.h b/r5dev/filesystem/filesystem.h index 77d1529b..0069f82f 100644 --- a/r5dev/filesystem/filesystem.h +++ b/r5dev/filesystem/filesystem.h @@ -6,11 +6,20 @@ #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); };