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.
This commit is contained in:
Kawe Mazidjatari 2022-05-27 22:38:49 +02:00
parent 2cc47f60e2
commit 52b8755219
6 changed files with 24 additions and 14 deletions

View File

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

View File

@ -167,3 +167,4 @@ void CBaseFileSystem_Detach()
DetourDetach((LPVOID*)&CBaseFileSystem_LoadFromVPK, &CBaseFileSystem::ReadFromVPK);
DetourDetach((LPVOID*)&CBaseFileSystem_LoadFromCache, &CBaseFileSystem::ReadFromCache);
}
CBaseFileSystem* g_pFileSystem = nullptr;

View File

@ -23,7 +23,7 @@ inline auto CBaseFileSystem_LoadFromVPK = p_CBaseFileSystem_LoadFromVPK.RCast<Fi
inline CMemory p_CBaseFileSystem_LoadFromCache;
inline auto CBaseFileSystem_LoadFromCache = p_CBaseFileSystem_LoadFromCache.RCast<bool(*)(CBaseFileSystem* thisptr, char* pszAssetName, void* pResults)>();
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<rsig_t>("\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<CBaseFileSystem*>();
g_pFileSystem = g_mGameDll.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, 2).ResolveRelativeAddressSelf(0x3, 0x7).RCast<CBaseFileSystem*>();
}
virtual void GetCon(void) const { }
virtual void Attach(void) const { }

View File

@ -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<void>(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<bool>(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<VPKData_t*>(index, this, pPath);
}
///////////////////////////////////////////////////////////////////////////////
IFileSystem* g_pFullFileSystem = nullptr;
CFileSystem_Stdio* g_pFileSystem_Stdio = nullptr;

View File

@ -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<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_pFileSystem_Stdio = g_mGameDll.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_pFullFileSystem = g_mGameDll.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<IFileSystem*>();
g_pFileSystem_Stdio = g_mGameDll.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 { }

View File

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