aboutsummaryrefslogtreecommitdiff
path: root/NorthstarDedicatedTest/filesystem.cpp
diff options
context:
space:
mode:
authorBobTheBob <32057864+BobTheBob9@users.noreply.github.com>2021-07-27 04:27:26 +0100
committerBobTheBob <32057864+BobTheBob9@users.noreply.github.com>2021-07-27 04:27:26 +0100
commit64b8db08ed9bd9de5aae85aedbf07caf51cb819c (patch)
treeab9de693f02d318d942b595aebe206a550f1db2c /NorthstarDedicatedTest/filesystem.cpp
parent80428e6f62899162c036f2752edfbfd7d1adb80b (diff)
downloadNorthstarLauncher-64b8db08ed9bd9de5aae85aedbf07caf51cb819c.tar.gz
NorthstarLauncher-64b8db08ed9bd9de5aae85aedbf07caf51cb819c.zip
add pdata support, improve filesystem hooks
Diffstat (limited to 'NorthstarDedicatedTest/filesystem.cpp')
-rw-r--r--NorthstarDedicatedTest/filesystem.cpp40
1 files changed, 33 insertions, 7 deletions
diff --git a/NorthstarDedicatedTest/filesystem.cpp b/NorthstarDedicatedTest/filesystem.cpp
index aa6975fe..04b8c98e 100644
--- a/NorthstarDedicatedTest/filesystem.cpp
+++ b/NorthstarDedicatedTest/filesystem.cpp
@@ -17,7 +17,12 @@ typedef bool(*ReadFromCacheType)(IFileSystem* filesystem, const char* path, void
ReadFromCacheType readFromCache;
bool ReadFromCacheHook(IFileSystem* filesystem, const char* path, void* result);
+typedef void(*AddSearchPathType)(IFileSystem* fileSystem, const char* pPath, const char* pathID, SearchPathAdd_t addType);
+AddSearchPathType addSearchPathOriginal;
+void AddSearchPathHook(IFileSystem* fileSystem, const char* pPath, const char* pathID, SearchPathAdd_t addType);
+
bool readingOriginalFile;
+std::string currentModPath;
SourceInterface<IFileSystem>* g_Filesystem;
void InitialiseFilesystem(HMODULE baseAddress)
@@ -28,6 +33,7 @@ void InitialiseFilesystem(HMODULE baseAddress)
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));
+ ENABLER_CREATEHOOK(hook, (*g_Filesystem)->m_vtable->AddSearchPath, &AddSearchPathHook, reinterpret_cast<LPVOID*>(&addSearchPathOriginal));
}
std::string ReadVPKFile(const char* path)
@@ -60,13 +66,21 @@ std::string ReadVPKOriginalFile(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
- // potentially we could also determine whether the file we're setting paths for needs a mod dir, or compiled assets
+ // put our new path to the head if we need to read from a different mod path
+ // in the future we could also determine whether the file we're setting paths for needs a mod dir, or compiled assets
if (mod != nullptr)
- (*g_Filesystem)->m_vtable->AddSearchPath(&*(*g_Filesystem), (fs::absolute(mod->ModDirectory) / MOD_OVERRIDE_DIR).string().c_str(), "GAME", PATH_ADD_TO_HEAD);
-
- (*g_Filesystem)->m_vtable->AddSearchPath(&*(*g_Filesystem), fs::absolute(COMPILED_ASSETS_PATH).string().c_str(), "GAME", PATH_ADD_TO_HEAD);
+ {
+ if ((fs::absolute(mod->ModDirectory) / MOD_OVERRIDE_DIR).string().compare(currentModPath))
+ {
+ spdlog::info("changing mod search path from {} to {}", currentModPath, mod->ModDirectory.string());
+
+ addSearchPathOriginal(&*(*g_Filesystem), (fs::absolute(mod->ModDirectory) / MOD_OVERRIDE_DIR).string().c_str(), "GAME", PATH_ADD_TO_HEAD);
+ currentModPath = (fs::absolute(mod->ModDirectory) / MOD_OVERRIDE_DIR).string();
+ }
+ }
+ else if (!currentModPath.size()) // if currentModPath isn't set yet, then push compiled to head
+ addSearchPathOriginal(&*(*g_Filesystem), fs::absolute(COMPILED_ASSETS_PATH).string().c_str(), "GAME", PATH_ADD_TO_HEAD);
+
}
bool TryReplaceFile(const char* path)
@@ -76,7 +90,7 @@ bool TryReplaceFile(const char* path)
(*g_ModManager).CompileAssetsForFile(path);
- // is this efficient? no clue
+ // is this efficient? could probably be improved
for (ModOverrideFile* modFile : g_ModManager->m_modFiles)
{
if (!modFile->path.compare(fs::path(path).lexically_normal()))
@@ -111,4 +125,16 @@ bool ReadFromCacheHook(IFileSystem* filesystem, const char* path, void* result)
return false;
return readFromCache(filesystem, path, result);
+}
+
+void AddSearchPathHook(IFileSystem* fileSystem, const char* pPath, const char* pathID, SearchPathAdd_t addType)
+{
+ addSearchPathOriginal(fileSystem, pPath, pathID, addType);
+
+ // make sure current mod paths are at head
+ if (!strcmp(pathID, "GAME") && currentModPath.compare(pPath) && addType == PATH_ADD_TO_HEAD)
+ {
+ addSearchPathOriginal(fileSystem, currentModPath.c_str(), "GAME", PATH_ADD_TO_HEAD);
+ addSearchPathOriginal(fileSystem, COMPILED_ASSETS_PATH.string().c_str(), "GAME", PATH_ADD_TO_HEAD);
+ }
} \ No newline at end of file