From 52b8755219212cf7d2a71f662a8f05df003d69b8 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Fri, 27 May 2022 22:38:49 +0200 Subject: [PATCH] FileSystem improvements * Added proper pointer to g_pFileSystem_Stdio. * Renamed existing one to g_pFullFileSystem (correct name). * Obtain g_pFileSystem from the same constructor as g_pFileSystem_Stdio. --- r5dev/engine/cmodel_bsp.cpp | 6 +++--- r5dev/filesystem/basefilesystem.cpp | 1 + r5dev/filesystem/basefilesystem.h | 6 +++--- r5dev/filesystem/filesystem.cpp | 7 ++++--- r5dev/filesystem/filesystem.h | 14 +++++++++++--- r5dev/vstdlib/callback.cpp | 4 ++-- 6 files changed, 24 insertions(+), 14 deletions(-) diff --git a/r5dev/engine/cmodel_bsp.cpp b/r5dev/engine/cmodel_bsp.cpp index 3d780dad..ab593317 100644 --- a/r5dev/engine/cmodel_bsp.cpp +++ b/r5dev/engine/cmodel_bsp.cpp @@ -161,7 +161,7 @@ void MOD_ProcessPakQueue() { return; } - if ((*(unsigned __int8(__fastcall**)(__int64))(*(_QWORD*)*(_QWORD*)g_pFileSystem_Stdio + 696i64 - FSTDIO_OFS))(*(_QWORD*)g_pFileSystem_Stdio) && !*dword_1634F445C) + if ((*(unsigned __int8(__fastcall**)(__int64))(*(_QWORD*)*(_QWORD*)g_pFullFileSystem + 696i64 - FSTDIO_OFS))(*(_QWORD*)g_pFullFileSystem) && !*dword_1634F445C) { v1 = &*off_141874660; for (i = 0; i < 5; ++i) @@ -274,8 +274,8 @@ void MOD_ProcessPakQueue() JT_ReleaseFifoLock((JobFifoLock_s*)&*qword_167ED7BE0); v23 = *qword_1671061C8; } - (*(void(__fastcall**)(__int64, __int64))(*(_QWORD*)*(_QWORD*)g_pFileSystem_Stdio + 656i64 - FSTDIO_OFS))(*(_QWORD*)g_pFileSystem_Stdio, 256i64); - (*(void(__fastcall**)(__int64, __int64))(*(_QWORD*)*(_QWORD*)g_pFileSystem_Stdio + 648i64 - FSTDIO_OFS))(*(_QWORD*)g_pFileSystem_Stdio, v23); + (*(void(__fastcall**)(__int64, __int64))(*(_QWORD*)*(_QWORD*)g_pFullFileSystem + 656i64 - FSTDIO_OFS))(*(_QWORD*)g_pFullFileSystem, 256i64); + (*(void(__fastcall**)(__int64, __int64))(*(_QWORD*)*(_QWORD*)g_pFullFileSystem + 648i64 - FSTDIO_OFS))(*(_QWORD*)g_pFullFileSystem, v23); } } } diff --git a/r5dev/filesystem/basefilesystem.cpp b/r5dev/filesystem/basefilesystem.cpp index c5103040..01ce0217 100644 --- a/r5dev/filesystem/basefilesystem.cpp +++ b/r5dev/filesystem/basefilesystem.cpp @@ -167,3 +167,4 @@ void CBaseFileSystem_Detach() DetourDetach((LPVOID*)&CBaseFileSystem_LoadFromVPK, &CBaseFileSystem::ReadFromVPK); DetourDetach((LPVOID*)&CBaseFileSystem_LoadFromCache, &CBaseFileSystem::ReadFromCache); } +CBaseFileSystem* g_pFileSystem = nullptr; \ No newline at end of file diff --git a/r5dev/filesystem/basefilesystem.h b/r5dev/filesystem/basefilesystem.h index 0e8e7f8c..e3b43448 100644 --- a/r5dev/filesystem/basefilesystem.h +++ b/r5dev/filesystem/basefilesystem.h @@ -23,7 +23,7 @@ inline auto CBaseFileSystem_LoadFromVPK = p_CBaseFileSystem_LoadFromVPK.RCast(); -inline CBaseFileSystem* g_pFileSystem = nullptr; +extern CBaseFileSystem* g_pFileSystem; /////////////////////////////////////////////////////////////////////////////// void CBaseFileSystem_Attach(); @@ -52,8 +52,8 @@ class VBaseFileSystem : public IDetour } virtual void GetVar(void) const { - g_pFileSystem = g_mGameDll.FindPatternSIMD(reinterpret_cast("\x48\x83\xEC\x28\xE8\x00\x00\x00\x00\x48\x8D\x05\x00\x00\x00\x00"), "xxxxx????xxx????") - .Offset(0x20).FindPatternSelf("48 89 05", CMemory::Direction::DOWN).ResolveRelativeAddressSelf(0x3, 0x7).RCast(); + g_pFileSystem = g_mGameDll.FindPatternSIMD(reinterpret_cast("\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, 2).ResolveRelativeAddressSelf(0x3, 0x7).RCast(); } virtual void GetCon(void) const { } virtual void Attach(void) const { } diff --git a/r5dev/filesystem/filesystem.cpp b/r5dev/filesystem/filesystem.cpp index d08a1ca4..32f68e16 100644 --- a/r5dev/filesystem/filesystem.cpp +++ b/r5dev/filesystem/filesystem.cpp @@ -8,7 +8,7 @@ // *pPathID - // addType - //----------------------------------------------------------------------------- -void CFileSystem_Stdio::AddSearchPath(const char* pPath, const char* pPathID, SearchPathAdd_t addType) +void IFileSystem::AddSearchPath(const char* pPath, const char* pPathID, SearchPathAdd_t addType) { static int index = 12; CallVFunc(index, this, pPath, pPathID, addType); @@ -20,7 +20,7 @@ void CFileSystem_Stdio::AddSearchPath(const char* pPath, const char* pPathID, Se // *pResult - // Output : true if exists, false otherwise. //----------------------------------------------------------------------------- -bool CFileSystem_Stdio::ReadFromCache(const char* pPath, void* pResult) +bool IFileSystem::ReadFromCache(const char* pPath, void* pResult) { static int index = 76; return CallVFunc(index, this, pPath, pResult); @@ -31,11 +31,12 @@ bool CFileSystem_Stdio::ReadFromCache(const char* pPath, void* pResult) // Input : *pPath - // Output : *VPKData_t (information about mounted VPK file) //----------------------------------------------------------------------------- -VPKData_t* CFileSystem_Stdio::MountVPK(const char* pPath) +VPKData_t* IFileSystem::MountVPK(const char* pPath) { static int index = 92; return CallVFunc(index, this, pPath); } /////////////////////////////////////////////////////////////////////////////// +IFileSystem* g_pFullFileSystem = nullptr; CFileSystem_Stdio* g_pFileSystem_Stdio = nullptr; \ No newline at end of file diff --git a/r5dev/filesystem/filesystem.h b/r5dev/filesystem/filesystem.h index 299e4c4b..9fbde28b 100644 --- a/r5dev/filesystem/filesystem.h +++ b/r5dev/filesystem/filesystem.h @@ -23,13 +23,17 @@ enum class FileWarningLevel_t : int FILESYSTEM_WARNING_REPORTALLACCESSES_ASYNC // Report all open/close/read/write events and all async I/O file events to the console ( !slower(est)! ) }; -class CFileSystem_Stdio +class IFileSystem { public: void AddSearchPath(const char* pPath, const char* pathID, SearchPathAdd_t addType); bool ReadFromCache(const char* pPath, void* pResult); VPKData_t* MountVPK(const char* vpkPath); }; +class CFileSystem_Stdio : public IFileSystem +{ +}; +extern IFileSystem* g_pFullFileSystem; extern CFileSystem_Stdio* g_pFileSystem_Stdio; /////////////////////////////////////////////////////////////////////////////// @@ -37,14 +41,18 @@ class VFileSystem_Stdio : public IDetour { virtual void GetAdr(void) const { + spdlog::debug("| VAR: g_pFullFileSystem : {:#18x} |\n", reinterpret_cast(g_pFullFileSystem)); spdlog::debug("| VAR: g_pFileSystem_Stdio : {:#18x} |\n", reinterpret_cast(g_pFileSystem_Stdio)); spdlog::debug("+----------------------------------------------------------------+\n"); } virtual void GetFun(void) const { } virtual void GetVar(void) const { - g_pFileSystem_Stdio = g_mGameDll.FindPatternSIMD(reinterpret_cast("\x48\x8B\x0D\x00\x00\x00\x00\x45\x33\xC0\x48\x83\xC1\x08\x48\x8B\x01"), - "xxx????xxxxxxxxxx").ResolveRelativeAddressSelf(0x3, 0x7).RCast(); + g_pFullFileSystem = g_mGameDll.FindPatternSIMD(reinterpret_cast("\x48\x8B\x0D\x00\x00\x00\x00\x45\x33\xC0\x48\x83\xC1\x08\x48\x8B\x01"), + "xxx????xxxxxxxxxx").ResolveRelativeAddressSelf(0x3, 0x7).RCast(); + + g_pFileSystem_Stdio = g_mGameDll.FindPatternSIMD(reinterpret_cast("\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(); } virtual void GetCon(void) const { } virtual void Attach(void) const { } diff --git a/r5dev/vstdlib/callback.cpp b/r5dev/vstdlib/callback.cpp index b6149039..e9cb461f 100644 --- a/r5dev/vstdlib/callback.cpp +++ b/r5dev/vstdlib/callback.cpp @@ -661,9 +661,9 @@ void VPK_Mount_f(const CCommand& args) return; } - if (g_pFileSystem_Stdio) + if (g_pFullFileSystem) { - VPKData_t* pPakData = g_pFileSystem_Stdio->MountVPK(args.Arg(1)); + VPKData_t* pPakData = g_pFullFileSystem->MountVPK(args.Arg(1)); if (pPakData) { DevMsg(eDLL_T::FS, "Mounted VPK file '%s' with handle '%d'\n", args.Arg(1), pPakData->m_nHandle);