aboutsummaryrefslogtreecommitdiff
path: root/NorthstarDedicatedTest/modmanager.cpp
diff options
context:
space:
mode:
authorEladNLG <e1lad8955@gmail.com>2022-07-10 18:22:59 +0300
committerGitHub <noreply@github.com>2022-07-10 16:22:59 +0100
commit85635ad99dbdfa909341e4138f6fdb0c9bf73bf1 (patch)
tree03a9198f9be9edc3496b3a72510987373369125e /NorthstarDedicatedTest/modmanager.cpp
parent151d678453f3e321fcccf2512e6e2f53436f1469 (diff)
downloadNorthstarLauncher-85635ad99dbdfa909341e4138f6fdb0c9bf73bf1.tar.gz
NorthstarLauncher-85635ad99dbdfa909341e4138f6fdb0c9bf73bf1.zip
Add dependency constants (#156)v1.9.1-rc4v1.9.1-rc3v1.9.1-rc2v1.9.1
* Fix duplicate script in scripts.rson when 2 mods add a custom script with the same path Allow mods to force a VPK to load through vpk.json * Remove unnecessary print * Fix match predicate using the value instead of the name * - Add a dependency constant system for use in compile flags - Remove the duplicate script engine error fix - Add ClientSq_defconst & ServerSq_defconst * Format fix * - Fix access violation - Separate dependency constants into mod and add checks for conflicts * - Remove unnecessary comment * Remove VPK loading for now and allow 2 mods to use the same constant if the mod names match * Fix bugs * fix mistake * fix keyvalues not working with modded files * simplify code * Fix formatting * Remove keyvalues fix
Diffstat (limited to 'NorthstarDedicatedTest/modmanager.cpp')
-rw-r--r--NorthstarDedicatedTest/modmanager.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/NorthstarDedicatedTest/modmanager.cpp b/NorthstarDedicatedTest/modmanager.cpp
index 9de1c7b1..de45bd23 100644
--- a/NorthstarDedicatedTest/modmanager.cpp
+++ b/NorthstarDedicatedTest/modmanager.cpp
@@ -186,6 +186,26 @@ Mod::Mod(fs::path modDir, char* jsonBuf)
}
}
+ if (modJson.HasMember("Dependencies") && modJson["Dependencies"].IsObject())
+ {
+ for (auto v = modJson["Dependencies"].MemberBegin(); v != modJson["Dependencies"].MemberEnd(); v++)
+ {
+ if (!v->name.IsString() || !v->value.IsString())
+ continue;
+
+ spdlog::info("Constant {} defined by {} for mod {}", v->name.GetString(), Name, v->value.GetString());
+ if (DependencyConstants.find(v->name.GetString()) != DependencyConstants.end() &&
+ v->value.GetString() != DependencyConstants[v->name.GetString()])
+ {
+ spdlog::error("A dependency constant with the same name already exists for another mod. Change the constant name.");
+ return;
+ }
+
+ if (DependencyConstants.find(v->name.GetString()) == DependencyConstants.end())
+ DependencyConstants.emplace(v->name.GetString(), v->value.GetString());
+ }
+ }
+
wasReadSuccessfully = true;
}
@@ -212,6 +232,8 @@ void ModManager::LoadMods()
fs::remove_all(GetCompiledAssetsPath());
fs::create_directories(GetModFolderPath());
+ DependencyConstants.clear();
+
// read enabled mods cfg
std::ifstream enabledModsStream(GetNorthstarPrefix() + "/enabledmods.json");
std::stringstream enabledModsStringStream;
@@ -253,6 +275,18 @@ void ModManager::LoadMods()
Mod mod(modDir, (char*)jsonStringStream.str().c_str());
+ for (auto& pair : mod.DependencyConstants)
+ {
+ if (DependencyConstants.find(pair.first) != DependencyConstants.end() && DependencyConstants[pair.first] != pair.second)
+ {
+ spdlog::error("Constant {} in mod {} already exists in another mod.", pair.first, mod.Name);
+ mod.wasReadSuccessfully = false;
+ break;
+ }
+ if (DependencyConstants.find(pair.first) == DependencyConstants.end())
+ DependencyConstants.emplace(pair);
+ }
+
if (m_hasEnabledModsCfg && m_enabledModsCfg.HasMember(mod.Name.c_str()))
mod.Enabled = m_enabledModsCfg[mod.Name.c_str()].IsTrue();
else