From 3292ad7d2a14f202df99fe46d3b9eb83277f1f21 Mon Sep 17 00:00:00 2001 From: BobTheBob Date: Wed, 8 Mar 2023 02:13:32 +0000 Subject: add functions for setting remote mods to actually load --- NorthstarDLL/NorthstarDLL.vcxproj | 2 +- NorthstarDLL/NorthstarDLL.vcxproj.filters | 2 +- NorthstarDLL/mods/modmanager.cpp | 24 ++++++++++-------------- NorthstarDLL/mods/modmanager.h | 23 +++++++++++++++-------- 4 files changed, 27 insertions(+), 24 deletions(-) diff --git a/NorthstarDLL/NorthstarDLL.vcxproj b/NorthstarDLL/NorthstarDLL.vcxproj index e26f5762..0d8aebfc 100644 --- a/NorthstarDLL/NorthstarDLL.vcxproj +++ b/NorthstarDLL/NorthstarDLL.vcxproj @@ -509,7 +509,7 @@ Create - + diff --git a/NorthstarDLL/NorthstarDLL.vcxproj.filters b/NorthstarDLL/NorthstarDLL.vcxproj.filters index 44687ba6..ed634a4c 100644 --- a/NorthstarDLL/NorthstarDLL.vcxproj.filters +++ b/NorthstarDLL/NorthstarDLL.vcxproj.filters @@ -1441,7 +1441,7 @@ Source Files\mods\reload - + Source Files\mods\reload diff --git a/NorthstarDLL/mods/modmanager.cpp b/NorthstarDLL/mods/modmanager.cpp index 38305770..f97624be 100644 --- a/NorthstarDLL/mods/modmanager.cpp +++ b/NorthstarDLL/mods/modmanager.cpp @@ -19,6 +19,12 @@ #include #include +// precaculated string hashes +// note: use backslashes for these, since we use lexically_normal for file paths which uses them +const size_t hScriptsRsonHash = STR_HASH("scripts\\vscripts\\scripts.rson"); +const size_t hPdefHash = STR_HASH("cfg\\server\\persistent_player_data_version_231.pdef"); // this can have multiple versions, but we use 231 so that's what we hash +const size_t hKBActHash = STR_HASH("scripts\\kb_act.lst"); + ModManager* g_pModManager; Mod::Mod(fs::path modDir, std::string sJson, bool bRemote) @@ -283,14 +289,6 @@ Mod::Mod(fs::path modDir, std::string sJson, bool bRemote) ModManager::ModManager() { - // precaculated string hashes - // note: use backslashes for these, since we use lexically_normal for file paths which uses them - m_hScriptsRsonHash = STR_HASH("scripts\\vscripts\\scripts.rson"); - m_hPdefHash = STR_HASH( - "cfg\\server\\persistent_player_data_version_231.pdef" // this can have multiple versions, but we use 231 so that's what we hash - ); - m_hKBActHash = STR_HASH("scripts\\kb_act.lst"); - m_LastModLoadState = nullptr; m_ModLoadState = new ModLoadState; @@ -351,7 +349,6 @@ auto ModConCommandCallback(const CCommand& command) - void ModManager::LoadMods(bool bReloadAssets, bool bDeferredAssetReload) { // reset state of all currently loaded mods, if we've loaded once already @@ -467,9 +464,8 @@ void ModManager::LoadModDefinitions() } else { - // todo: need custom logic for deciding whether to enable remote mods, but should be off by default - // in the future, remote mods should only be enabled explicitly at runtime, never based on any file or persistent state - mod.m_bEnabled = false; + // remote mods should only be enabled explicitly at runtime, never based on any file or persistent state + mod.m_bEnabled = m_setsAllowedRemoteMods.find(mod.Name) != m_setsAllowedRemoteMods.end(); } if (mod.m_bWasReadSuccessfully) @@ -1175,13 +1171,13 @@ void ModManager::CompileAssetsForFile(const char* filename) { size_t fileHash = STR_HASH(NormaliseModFilePath(fs::path(filename))); - if (fileHash == m_hScriptsRsonHash) + if (fileHash == hScriptsRsonHash) BuildScriptsRson(); //else if (fileHash == m_hPdefHash) //{ // // BuildPdef(); todo //} - else if (fileHash == m_hKBActHash) + else if (fileHash == hKBActHash) BuildKBActionsList(); else { diff --git a/NorthstarDLL/mods/modmanager.h b/NorthstarDLL/mods/modmanager.h index 3002a099..2673fb3c 100644 --- a/NorthstarDLL/mods/modmanager.h +++ b/NorthstarDLL/mods/modmanager.h @@ -133,10 +133,7 @@ class ModManager private: bool m_bHasLoadedMods = false; - // precalculated hashes - size_t m_hScriptsRsonHash; - size_t m_hPdefHash; - size_t m_hKBActHash; + std::unordered_set m_setsAllowedRemoteMods {}; void LoadModDefinitions(); void SaveEnabledMods(); @@ -208,21 +205,31 @@ class ModManager std::string NormaliseModFilePath(const fs::path path); void CompileAssetsForFile(const char* filename); - // getters + // getters and setters inline std::vector& GetMods() { return m_ModLoadState->m_LoadedMods; - }; + } inline std::unordered_map& GetModFiles() { return m_ModLoadState->m_ModFiles; - }; + } inline std::unordered_map& GetDependencyConstants() { return m_ModLoadState->m_DependencyConstants; - }; + } + + inline void SetAllowedRemoteMods(const std::unordered_set setsAllowedRemoteMods) + { + m_setsAllowedRemoteMods = setsAllowedRemoteMods; + } + + void ClearAllowedRemoteMods(void) + { + m_setsAllowedRemoteMods.clear(); + } // compile asset type stuff, these are done in files under runtime/compiled/ void BuildScriptsRson(); -- cgit v1.2.3