aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBobTheBob <32057864+BobTheBob9@users.noreply.github.com>2021-08-29 04:51:22 +0100
committerBobTheBob <32057864+BobTheBob9@users.noreply.github.com>2021-08-29 04:51:22 +0100
commit9f0288d744cd8dbd9b4213bd7a1a73a0c822b5a6 (patch)
tree423081767816e5c203a1b164492e6497382798c9
parent83ea828342e59af290857b0854ba768d9412e92c (diff)
downloadNorthstarLauncher-9f0288d744cd8dbd9b4213bd7a1a73a0c822b5a6.tar.gz
NorthstarLauncher-9f0288d744cd8dbd9b4213bd7a1a73a0c822b5a6.zip
add mod vpk support
-rw-r--r--NorthstarDedicatedTest/filesystem.cpp25
-rw-r--r--NorthstarDedicatedTest/modmanager.cpp17
2 files changed, 40 insertions, 2 deletions
diff --git a/NorthstarDedicatedTest/filesystem.cpp b/NorthstarDedicatedTest/filesystem.cpp
index 458cfd5c..1e17017e 100644
--- a/NorthstarDedicatedTest/filesystem.cpp
+++ b/NorthstarDedicatedTest/filesystem.cpp
@@ -25,6 +25,10 @@ typedef FileHandle_t(*ReadFileFromFilesystemType)(IFileSystem* filesystem, const
ReadFileFromFilesystemType readFileFromFilesystem;
FileHandle_t ReadFileFromFilesystemHook(IFileSystem* filesystem, const char* pPath, const char* pOptions, int64_t a4, uint32_t a5);
+typedef VPKData* (*MountVPKType)(IFileSystem* fileSystem, const char* vpkPath);
+MountVPKType mountVPK;
+VPKData* MountVPKHook(IFileSystem* fileSystem, const char* vpkPath);
+
bool readingOriginalFile;
std::string currentModPath;
SourceInterface<IFileSystem>* g_Filesystem;
@@ -40,6 +44,7 @@ void InitialiseFilesystem(HMODULE baseAddress)
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));
ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x15F20, &ReadFileFromFilesystemHook, reinterpret_cast<LPVOID*>(&readFileFromFilesystem));
+ ENABLER_CREATEHOOK(hook, (*g_Filesystem)->m_vtable->MountVPK, &MountVPKHook, reinterpret_cast<LPVOID*>(&mountVPK));
}
std::string ReadVPKFile(const char* path)
@@ -155,4 +160,24 @@ FileHandle_t ReadFileFromFilesystemHook(IFileSystem* filesystem, const char* pPa
TryReplaceFile((char*)pPath, true);
return readFileFromFilesystem(filesystem, pPath, pOptions, a4, a5);
+}
+
+VPKData* MountVPKHook(IFileSystem* fileSystem, const char* vpkPath)
+{
+ spdlog::info("MountVPK {}", vpkPath);
+ VPKData* ret = mountVPK(fileSystem, vpkPath);
+
+ for (Mod* mod : g_ModManager->m_loadedMods)
+ {
+ if (!mod->Enabled)
+ continue;
+
+ for (std::string& vpkPath : mod->Vpks)
+ {
+ spdlog::info(vpkPath);
+ spdlog::info((void*)mountVPK(fileSystem, vpkPath.c_str()));
+ }
+ }
+
+ return ret;
} \ No newline at end of file
diff --git a/NorthstarDedicatedTest/modmanager.cpp b/NorthstarDedicatedTest/modmanager.cpp
index 63115ea4..f5deed1a 100644
--- a/NorthstarDedicatedTest/modmanager.cpp
+++ b/NorthstarDedicatedTest/modmanager.cpp
@@ -247,9 +247,22 @@ void ModManager::LoadMods()
// read vpk paths
if (fs::exists(mod->ModDirectory / "vpk"))
+ {
for (fs::directory_entry file : fs::directory_iterator(mod->ModDirectory / "vpk"))
- if (fs::is_regular_file(file) && file.path().extension() == "vpk")
- mod->Vpks.push_back(file.path().string());
+ {
+ // a bunch of checks to make sure we're only adding dir vpks and their paths are good
+ // note: the game will literally only load vpks with the english prefix
+ if (fs::is_regular_file(file) && file.path().extension() == ".vpk" &&
+ file.path().string().find("english") != std::string::npos && file.path().string().find(".bsp.pak000_dir") != std::string::npos)
+ {
+ std::string formattedPath = file.path().filename().string();
+
+ // this really fucking sucks but it'll work
+ mod->Vpks.push_back((file.path().parent_path() / formattedPath.substr(strlen("english"), formattedPath.find(".bsp") - 3)).string());
+ }
+ }
+ }
+
// read keyvalues paths
if (fs::exists(mod->ModDirectory / "keyvalues"))