aboutsummaryrefslogtreecommitdiff
path: root/NorthstarDedicatedTest/filesystem.cpp
diff options
context:
space:
mode:
authorBobTheBob <32057864+BobTheBob9@users.noreply.github.com>2021-07-21 16:40:01 +0100
committerBobTheBob <32057864+BobTheBob9@users.noreply.github.com>2021-07-21 16:40:01 +0100
commit8564c36b49f5f0451be5036371e421a44425b02e (patch)
treefcd1fbe100e7c8fb9ba7eee8e5923abd5ad0ba27 /NorthstarDedicatedTest/filesystem.cpp
parent8650a7520baec35765bc837d9313325e0c7631d3 (diff)
downloadNorthstarLauncher-8564c36b49f5f0451be5036371e421a44425b02e.tar.gz
NorthstarLauncher-8564c36b49f5f0451be5036371e421a44425b02e.zip
add some basic filesystem stuff and client/ui script callbacks
Diffstat (limited to 'NorthstarDedicatedTest/filesystem.cpp')
-rw-r--r--NorthstarDedicatedTest/filesystem.cpp53
1 files changed, 53 insertions, 0 deletions
diff --git a/NorthstarDedicatedTest/filesystem.cpp b/NorthstarDedicatedTest/filesystem.cpp
new file mode 100644
index 00000000..135201b6
--- /dev/null
+++ b/NorthstarDedicatedTest/filesystem.cpp
@@ -0,0 +1,53 @@
+#include "pch.h"
+#include "filesystem.h"
+#include "hooks.h"
+#include "hookutils.h"
+#include "sourceinterface.h"
+
+// hook forward declares
+typedef FileHandle_t(*ReadFileFromVPKType)(VPKData* vpkInfo, __int64* b, const char* filename);
+ReadFileFromVPKType readFileFromVPK;
+FileHandle_t ReadFileFromVPKHook(VPKData* vpkInfo, __int64* b, const char* filename);
+
+typedef bool(*ReadFromCacheType)(IFileSystem* filesystem, const char* path, void* result);
+ReadFromCacheType readFromCache;
+bool ReadFromCacheHook(IFileSystem* filesystem, const char* path, void* result);
+
+SourceInterface<IFileSystem>* g_Filesystem;
+
+void InitialiseFilesystem(HMODULE baseAddress)
+{
+ g_Filesystem = new SourceInterface<IFileSystem>("filesystem_stdio.dll", "VFileSystem017");
+
+ // create hooks
+ HookEnabler hook;
+ ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x5CBA0, &ReadFileFromVPKHook, reinterpret_cast<LPVOID*>(&readFileFromVPK));
+ ENABLER_CREATEHOOK(hook, (*g_Filesystem)->m_vtable->ReadFromCache, &ReadFromCacheHook, reinterpret_cast<LPVOID*>(&readFromCache));
+}
+
+bool ShouldReplaceFile(const char* path)
+{
+ return false;
+}
+
+FileHandle_t ReadFileFromVPKHook(VPKData* vpkInfo, __int64* b, const char* filename)
+{
+ // move this to a convar at some point when we can read them in native
+ //spdlog::info("ReadFileFromVPKHook {} {}", filename, vpkInfo->path);
+ if (ShouldReplaceFile(filename))
+ {
+ *b = -1;
+ return b;
+ }
+
+ return readFileFromVPK(vpkInfo, b, filename);
+}
+
+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);
+
+
+ return readFromCache(filesystem, path, result);
+} \ No newline at end of file