From 151d678453f3e321fcccf2512e6e2f53436f1469 Mon Sep 17 00:00:00 2001 From: Jack <66967891+ASpoonPlaysGames@users.noreply.github.com> Date: Fri, 8 Jul 2022 23:21:13 +0100 Subject: Add Postload support for rpaks (#217) * fixed custom rpaks being loaded more than once * formatting * better things, although LoadPakSyncHook is annoying * formatting * removing unnecessary comments and stuff (whoops) * Moving to use PakLoadManager * formatting * postload things * formatting * trailing space smh --- NorthstarDedicatedTest/modmanager.cpp | 7 +++++++ NorthstarDedicatedTest/modmanager.h | 1 + NorthstarDedicatedTest/rpakfilesystem.cpp | 19 +++++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/NorthstarDedicatedTest/modmanager.cpp b/NorthstarDedicatedTest/modmanager.cpp index 50c7b371..9de1c7b1 100644 --- a/NorthstarDedicatedTest/modmanager.cpp +++ b/NorthstarDedicatedTest/modmanager.cpp @@ -383,6 +383,13 @@ void ModManager::LoadMods() modPak.m_bAutoLoad = !bUseRpakJson || (dRpakJson.HasMember("Preload") && dRpakJson["Preload"].IsObject() && dRpakJson["Preload"].HasMember(pakName) && dRpakJson["Preload"][pakName].IsTrue()); + // postload things + if (!bUseRpakJson || + (dRpakJson.HasMember("Postload") && dRpakJson["Postload"].IsObject() && dRpakJson["Postload"].HasMember(pakName))) + { + modPak.m_sLoadAfterPak = dRpakJson["Postload"][pakName].GetString(); + } + modPak.m_sPakName = pakName; // not using atm because we need to resolve path to rpak diff --git a/NorthstarDedicatedTest/modmanager.h b/NorthstarDedicatedTest/modmanager.h index 798c2306..00c0384a 100644 --- a/NorthstarDedicatedTest/modmanager.h +++ b/NorthstarDedicatedTest/modmanager.h @@ -57,6 +57,7 @@ struct ModRpakEntry public: bool m_bAutoLoad; std::string m_sPakName; + std::string m_sLoadAfterPak; }; class Mod diff --git a/NorthstarDedicatedTest/rpakfilesystem.cpp b/NorthstarDedicatedTest/rpakfilesystem.cpp index b3105996..1a4736a9 100644 --- a/NorthstarDedicatedTest/rpakfilesystem.cpp +++ b/NorthstarDedicatedTest/rpakfilesystem.cpp @@ -108,6 +108,23 @@ void LoadPreloadPaks() } } +void LoadPostloadPaks(char** map) +{ + // note, loading from ./ is necessary otherwise paks will load from gamedir/r2/paks + for (Mod& mod : g_ModManager->m_loadedMods) + { + if (!mod.Enabled) + continue; + + // need to get a relative path of mod to mod folder + fs::path modPakPath("./" / mod.ModDirectory / "paks"); + + for (ModRpakEntry& pak : mod.Rpaks) + if (pak.m_sLoadAfterPak == *map) + g_PakLoadManager->LoadPakAsync((modPakPath / pak.m_sPakName).string().c_str(), false); + } +} + void LoadCustomMapPaks(char** pakName, bool* bNeedToFreePakName) { // whether the vanilla game has this rpak @@ -212,6 +229,8 @@ int LoadPakAsyncHook(char* path, void* unknownSingleton, int flags, void* callba // add the hash to the map g_PakLoadManager->AddLoadedPak(ret, hash); + LoadPostloadPaks(&path); + if (bNeedToFreePakName) delete[] path; -- cgit v1.2.3