From 27f478e7a296bca381a3bd78b82798863cac749c Mon Sep 17 00:00:00 2001 From: F1F7Y <64418963+F1F7Y@users.noreply.github.com> Date: Thu, 5 Sep 2024 15:22:52 +0200 Subject: core: Remove use of `SourceInterface` for `IFileSystem` (#805) `SourceInteface` class goes back to icepick and is not good. We have a replacement, let's use it. --- primedev/core/filesystem/filesystem.cpp | 22 +++++++++++----------- primedev/core/filesystem/filesystem.h | 3 +-- 2 files changed, 12 insertions(+), 13 deletions(-) (limited to 'primedev/core/filesystem') diff --git a/primedev/core/filesystem/filesystem.cpp b/primedev/core/filesystem/filesystem.cpp index 2c3a50a1..3c711e8e 100644 --- a/primedev/core/filesystem/filesystem.cpp +++ b/primedev/core/filesystem/filesystem.cpp @@ -1,5 +1,5 @@ #include "filesystem.h" -#include "core/sourceinterface.h" +#include "core/tier1.h" #include "mods/modmanager.h" #include @@ -10,23 +10,23 @@ std::string sCurrentModPath; ConVar* Cvar_ns_fs_log_reads; -SourceInterface* g_pFilesystem; +IFileSystem* g_pFilesystem; std::string ReadVPKFile(const char* path) { // read scripts.rson file, todo: check if this can be overwritten - FileHandle_t fileHandle = (*g_pFilesystem)->m_vtable2->Open(&(*g_pFilesystem)->m_vtable2, path, "rb", "GAME", 0); + FileHandle_t fileHandle = g_pFilesystem->m_vtable2->Open(&g_pFilesystem->m_vtable2, path, "rb", "GAME", 0); std::stringstream fileStream; int bytesRead = 0; char data[4096]; do { - bytesRead = (*g_pFilesystem)->m_vtable2->Read(&(*g_pFilesystem)->m_vtable2, data, (int)std::size(data), fileHandle); + bytesRead = g_pFilesystem->m_vtable2->Read(&g_pFilesystem->m_vtable2, data, (int)std::size(data), fileHandle); fileStream.write(data, bytesRead); } while (bytesRead == std::size(data)); - (*g_pFilesystem)->m_vtable2->Close(*g_pFilesystem, fileHandle); + g_pFilesystem->m_vtable2->Close(g_pFilesystem, fileHandle); return fileStream.str(); } @@ -65,12 +65,12 @@ void SetNewModSearchPaths(Mod* mod) if ((fs::absolute(mod->m_ModDirectory) / MOD_OVERRIDE_DIR).string().compare(sCurrentModPath)) { o_pAddSearchPath( - &*(*g_pFilesystem), (fs::absolute(mod->m_ModDirectory) / MOD_OVERRIDE_DIR).string().c_str(), "GAME", PATH_ADD_TO_HEAD); + g_pFilesystem, (fs::absolute(mod->m_ModDirectory) / MOD_OVERRIDE_DIR).string().c_str(), "GAME", PATH_ADD_TO_HEAD); sCurrentModPath = (fs::absolute(mod->m_ModDirectory) / MOD_OVERRIDE_DIR).string(); } } else // push compiled to head - o_pAddSearchPath(&*(*g_pFilesystem), fs::absolute(GetCompiledAssetsPath()).string().c_str(), "GAME", PATH_ADD_TO_HEAD); + o_pAddSearchPath(g_pFilesystem, fs::absolute(GetCompiledAssetsPath()).string().c_str(), "GAME", PATH_ADD_TO_HEAD); } bool TryReplaceFile(const char* pPath, bool shouldCompile) @@ -167,12 +167,12 @@ ON_DLL_LOAD("filesystem_stdio.dll", Filesystem, (CModule module)) o_pCBaseFileSystem__OpenEx = module.Offset(0x15F50).RCast(); HookAttach(&(PVOID&)o_pCBaseFileSystem__OpenEx, (PVOID)h_CBaseFileSystem__OpenEx); - g_pFilesystem = new SourceInterface("filesystem_stdio.dll", "VFileSystem017"); + g_pFilesystem = Sys_GetFactoryPtr("filesystem_stdio.dll", "VFileSystem017").RCast(); - o_pAddSearchPath = reinterpret_cast((*g_pFilesystem)->m_vtable->AddSearchPath); + o_pAddSearchPath = reinterpret_cast(g_pFilesystem->m_vtable->AddSearchPath); HookAttach(&(PVOID&)o_pAddSearchPath, (PVOID)h_AddSearchPath); - o_pReadFromCache = reinterpret_cast((*g_pFilesystem)->m_vtable->ReadFromCache); + o_pReadFromCache = reinterpret_cast(g_pFilesystem->m_vtable->ReadFromCache); HookAttach(&(PVOID&)o_pReadFromCache, (PVOID)h_ReadFromCache); - o_pMountVPK = reinterpret_cast((*g_pFilesystem)->m_vtable->MountVPK); + o_pMountVPK = reinterpret_cast(g_pFilesystem->m_vtable->MountVPK); HookAttach(&(PVOID&)o_pMountVPK, (PVOID)h_MountVPK); } diff --git a/primedev/core/filesystem/filesystem.h b/primedev/core/filesystem/filesystem.h index 4e2c18d9..2c592b3f 100644 --- a/primedev/core/filesystem/filesystem.h +++ b/primedev/core/filesystem/filesystem.h @@ -1,5 +1,4 @@ #pragma once -#include "core/sourceinterface.h" // taken from ttf2sdk typedef void* FileHandle_t; @@ -48,7 +47,7 @@ public: VTable2* m_vtable2; }; -extern SourceInterface* g_pFilesystem; +extern IFileSystem* g_pFilesystem; std::string ReadVPKFile(const char* path); std::string ReadVPKOriginalFile(const char* path); -- cgit v1.2.3