aboutsummaryrefslogtreecommitdiff
path: root/primedev/core/filesystem
diff options
context:
space:
mode:
authorF1F7Y <64418963+F1F7Y@users.noreply.github.com>2024-09-05 15:22:52 +0200
committerGitHub <noreply@github.com>2024-09-05 15:22:52 +0200
commit27f478e7a296bca381a3bd78b82798863cac749c (patch)
tree4241222bdf1c15151e041055196c02f2d9ac9104 /primedev/core/filesystem
parent68d374dbac1e0fa6fefa67db1e54d7d1eb9dc433 (diff)
downloadNorthstarLauncher-27f478e7a296bca381a3bd78b82798863cac749c.tar.gz
NorthstarLauncher-27f478e7a296bca381a3bd78b82798863cac749c.zip
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.
Diffstat (limited to 'primedev/core/filesystem')
-rw-r--r--primedev/core/filesystem/filesystem.cpp22
-rw-r--r--primedev/core/filesystem/filesystem.h3
2 files changed, 12 insertions, 13 deletions
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 <iostream>
@@ -10,23 +10,23 @@ std::string sCurrentModPath;
ConVar* Cvar_ns_fs_log_reads;
-SourceInterface<IFileSystem>* 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<decltype(o_pCBaseFileSystem__OpenEx)>();
HookAttach(&(PVOID&)o_pCBaseFileSystem__OpenEx, (PVOID)h_CBaseFileSystem__OpenEx);
- g_pFilesystem = new SourceInterface<IFileSystem>("filesystem_stdio.dll", "VFileSystem017");
+ g_pFilesystem = Sys_GetFactoryPtr("filesystem_stdio.dll", "VFileSystem017").RCast<IFileSystem*>();
- o_pAddSearchPath = reinterpret_cast<decltype(o_pAddSearchPath)>((*g_pFilesystem)->m_vtable->AddSearchPath);
+ o_pAddSearchPath = reinterpret_cast<decltype(o_pAddSearchPath)>(g_pFilesystem->m_vtable->AddSearchPath);
HookAttach(&(PVOID&)o_pAddSearchPath, (PVOID)h_AddSearchPath);
- o_pReadFromCache = reinterpret_cast<decltype(o_pReadFromCache)>((*g_pFilesystem)->m_vtable->ReadFromCache);
+ o_pReadFromCache = reinterpret_cast<decltype(o_pReadFromCache)>(g_pFilesystem->m_vtable->ReadFromCache);
HookAttach(&(PVOID&)o_pReadFromCache, (PVOID)h_ReadFromCache);
- o_pMountVPK = reinterpret_cast<decltype(o_pMountVPK)>((*g_pFilesystem)->m_vtable->MountVPK);
+ o_pMountVPK = reinterpret_cast<decltype(o_pMountVPK)>(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<IFileSystem>* g_pFilesystem;
+extern IFileSystem* g_pFilesystem;
std::string ReadVPKFile(const char* path);
std::string ReadVPKOriginalFile(const char* path);