aboutsummaryrefslogtreecommitdiff
path: root/NorthstarDedicatedTest/filesystem.cpp
diff options
context:
space:
mode:
authorBobTheBob <32057864+BobTheBob9@users.noreply.github.com>2021-07-23 02:32:18 +0100
committerBobTheBob <32057864+BobTheBob9@users.noreply.github.com>2021-07-23 02:32:18 +0100
commit23a1dafcde70822a9899e9aab190f36521c1aedd (patch)
tree58292b4d3abfa22742c9d8e8fcff208c9c6b2475 /NorthstarDedicatedTest/filesystem.cpp
parent8564c36b49f5f0451be5036371e421a44425b02e (diff)
downloadNorthstarLauncher-23a1dafcde70822a9899e9aab190f36521c1aedd.tar.gz
NorthstarLauncher-23a1dafcde70822a9899e9aab190f36521c1aedd.zip
add basic vpk file replacement
Diffstat (limited to 'NorthstarDedicatedTest/filesystem.cpp')
-rw-r--r--NorthstarDedicatedTest/filesystem.cpp26
1 files changed, 24 insertions, 2 deletions
diff --git a/NorthstarDedicatedTest/filesystem.cpp b/NorthstarDedicatedTest/filesystem.cpp
index 135201b6..877898ee 100644
--- a/NorthstarDedicatedTest/filesystem.cpp
+++ b/NorthstarDedicatedTest/filesystem.cpp
@@ -3,6 +3,9 @@
#include "hooks.h"
#include "hookutils.h"
#include "sourceinterface.h"
+#include "modmanager.h"
+
+#include <iostream>
// hook forward declares
typedef FileHandle_t(*ReadFileFromVPKType)(VPKData* vpkInfo, __int64* b, const char* filename);
@@ -25,8 +28,25 @@ void InitialiseFilesystem(HMODULE baseAddress)
ENABLER_CREATEHOOK(hook, (*g_Filesystem)->m_vtable->ReadFromCache, &ReadFromCacheHook, reinterpret_cast<LPVOID*>(&readFromCache));
}
-bool ShouldReplaceFile(const char* path)
+void SetNewModSearchPaths(Mod* mod)
+{
+ // put our new path to the head
+ // in future we should look into manipulating paths at head manually, might be effort tho
+ (*g_Filesystem)->m_vtable->AddSearchPath(&*(*g_Filesystem), (fs::absolute(mod->ModDirectory) / "mod").string().c_str(), "GAME", PATH_ADD_TO_HEAD);
+}
+
+bool TryReplaceFile(const char* path)
{
+ // is this efficient? no clue
+ for (ModOverrideFile* modFile : g_ModManager->m_modFiles)
+ {
+ if (!modFile->path.compare(fs::path(path).lexically_normal()))
+ {
+ SetNewModSearchPaths(modFile->owningMod);
+ return true;
+ }
+ }
+
return false;
}
@@ -34,7 +54,7 @@ FileHandle_t ReadFileFromVPKHook(VPKData* vpkInfo, __int64* b, const char* filen
{
// move this to a convar at some point when we can read them in native
//spdlog::info("ReadFileFromVPKHook {} {}", filename, vpkInfo->path);
- if (ShouldReplaceFile(filename))
+ if (TryReplaceFile(filename))
{
*b = -1;
return b;
@@ -48,6 +68,8 @@ bool ReadFromCacheHook(IFileSystem* filesystem, const char* path, void* result)
// move this to a convar at some point when we can read them in native
//spdlog::info("ReadFromCacheHook {}", path);
+ if (TryReplaceFile(path))
+ return false;
return readFromCache(filesystem, path, result);
} \ No newline at end of file