aboutsummaryrefslogtreecommitdiff
path: root/NorthstarDLL/mods
diff options
context:
space:
mode:
authorcat_or_not <41955154+catornot@users.noreply.github.com>2023-12-14 07:07:02 -0500
committerGitHub <noreply@github.com>2023-12-14 13:07:02 +0100
commit43f0bce0596ec60434e48d8037ffed373bc13852 (patch)
tree717f8728ad41369a9e8c6dfe928460e9163014c0 /NorthstarDLL/mods
parent0976a3500e6774258322ab2bc80ebd515c175e77 (diff)
downloadNorthstarLauncher-43f0bce0596ec60434e48d8037ffed373bc13852.tar.gz
NorthstarLauncher-43f0bce0596ec60434e48d8037ffed373bc13852.zip
Add plugin dependency constants (#458)v1.21.0-rc1
Adds dependency constants for plugins so mods can rely on plugins without always producing script errors when the plugin is missing
Diffstat (limited to 'NorthstarDLL/mods')
-rw-r--r--NorthstarDLL/mods/modmanager.cpp28
-rw-r--r--NorthstarDLL/mods/modmanager.h4
2 files changed, 32 insertions, 0 deletions
diff --git a/NorthstarDLL/mods/modmanager.cpp b/NorthstarDLL/mods/modmanager.cpp
index b7194d04..982f5068 100644
--- a/NorthstarDLL/mods/modmanager.cpp
+++ b/NorthstarDLL/mods/modmanager.cpp
@@ -104,6 +104,7 @@ Mod::Mod(fs::path modDir, char* jsonBuf)
ParseScripts(modJson);
ParseLocalization(modJson);
ParseDependencies(modJson);
+ ParsePluginDependencies(modJson);
ParseInitScript(modJson);
// A mod is remote if it's located in the remote mods folder
@@ -483,6 +484,28 @@ void Mod::ParseDependencies(rapidjson_document& json)
}
}
+void Mod::ParsePluginDependencies(rapidjson_document& json)
+{
+ if (!json.HasMember("PluginDependencies"))
+ return;
+
+ if (!json["PluginDependencies"].IsArray())
+ {
+ spdlog::warn("'PluginDependencies' field is not an object, skipping...");
+ return;
+ }
+
+ for (auto& name : json["PluginDependencies"].GetArray())
+ {
+ if (!name.IsString())
+ continue;
+
+ spdlog::info("Plugin Constant {} defined by {}", name.GetString(), Name);
+
+ PluginDependencyConstants.push_back(name.GetString());
+ }
+}
+
void Mod::ParseInitScript(rapidjson_document& json)
{
if (!json.HasMember("InitScript"))
@@ -688,6 +711,11 @@ void ModManager::LoadMods()
m_DependencyConstants.emplace(pair);
}
+ for (std::string& dependency : mod.PluginDependencyConstants)
+ {
+ m_PluginDependencyConstants.insert(dependency);
+ }
+
if (m_bHasEnabledModsCfg && m_EnabledModsCfg.HasMember(mod.Name.c_str()))
mod.m_bEnabled = m_EnabledModsCfg[mod.Name.c_str()].IsTrue();
else
diff --git a/NorthstarDLL/mods/modmanager.h b/NorthstarDLL/mods/modmanager.h
index 813edec7..c141414f 100644
--- a/NorthstarDLL/mods/modmanager.h
+++ b/NorthstarDLL/mods/modmanager.h
@@ -7,6 +7,7 @@
#include <string>
#include <vector>
#include <filesystem>
+#include <unordered_set>
const std::string MOD_FOLDER_SUFFIX = "\\mods";
const std::string THUNDERSTORE_MOD_FOLDER_SUFFIX = "\\packages";
@@ -124,6 +125,7 @@ class Mod
// hashed with STR_HASH
std::unordered_map<std::string, std::string> DependencyConstants;
+ std::vector<std::string> PluginDependencyConstants;
public:
Mod(fs::path modPath, char* jsonBuf);
@@ -134,6 +136,7 @@ class Mod
void ParseScripts(rapidjson_document& json);
void ParseLocalization(rapidjson_document& json);
void ParseDependencies(rapidjson_document& json);
+ void ParsePluginDependencies(rapidjson_document& json);
void ParseInitScript(rapidjson_document& json);
};
@@ -160,6 +163,7 @@ class ModManager
std::vector<Mod> m_LoadedMods;
std::unordered_map<std::string, ModOverrideFile> m_ModFiles;
std::unordered_map<std::string, std::string> m_DependencyConstants;
+ std::unordered_set<std::string> m_PluginDependencyConstants;
public:
ModManager();