aboutsummaryrefslogtreecommitdiff
path: root/NorthstarDedicatedTest/modmanager.cpp
diff options
context:
space:
mode:
authorBobTheBob <32057864+BobTheBob9@users.noreply.github.com>2021-07-25 04:43:11 +0100
committerBobTheBob <32057864+BobTheBob9@users.noreply.github.com>2021-07-25 04:43:11 +0100
commit153e7f564c4bb1d5da200f2aecdca7c8d1836997 (patch)
tree2d49d5848b57d963e2b1551d55ce336383226fad /NorthstarDedicatedTest/modmanager.cpp
parent844e12403400b455fe5df8c2e19145a2ed1a7d45 (diff)
downloadNorthstarLauncher-153e7f564c4bb1d5da200f2aecdca7c8d1836997.tar.gz
NorthstarLauncher-153e7f564c4bb1d5da200f2aecdca7c8d1836997.zip
wasted a day working on something that didn't end up working, rework some modloader code
Diffstat (limited to 'NorthstarDedicatedTest/modmanager.cpp')
-rw-r--r--NorthstarDedicatedTest/modmanager.cpp34
1 files changed, 26 insertions, 8 deletions
diff --git a/NorthstarDedicatedTest/modmanager.cpp b/NorthstarDedicatedTest/modmanager.cpp
index 05974d4e..66fff17f 100644
--- a/NorthstarDedicatedTest/modmanager.cpp
+++ b/NorthstarDedicatedTest/modmanager.cpp
@@ -68,6 +68,14 @@ Mod::Mod(fs::path modDir, char* jsonBuf)
else
RequiredOnClient = false;
+ if (modJson.HasMember("LoadPriority"))
+ LoadPriority = modJson["LoadPriority"].GetInt();
+ else
+ {
+ spdlog::info("Mod file {} is missing a LoadPriority, consider adding one", (modDir / "mod.json").string());
+ LoadPriority = 0;
+ }
+
// mod convars
if (modJson.HasMember("ConVars") && modJson["ConVars"].IsArray())
{
@@ -171,6 +179,9 @@ ModManager::ModManager()
void ModManager::LoadMods()
{
// this needs better support for reloads
+
+ // do we need to dealloc individual entries in m_loadedMods? idk, rework
+ m_loadedMods.clear();
std::vector<fs::path> modDirs;
@@ -211,8 +222,14 @@ void ModManager::LoadMods()
}
}
+ // sort by load prio, lowest-highest
+ std::sort(m_loadedMods.begin(), m_loadedMods.end(), [](Mod* a, Mod* b) {
+ return a->LoadPriority > b->LoadPriority;
+ });
+
// do we need to dealloc individual entries in m_modFiles? idk, rework
m_modFiles.clear();
+ fs::remove_all(COMPILED_ASSETS_PATH);
for (Mod* mod : m_loadedMods)
{
@@ -222,25 +239,26 @@ void ModManager::LoadMods()
for (ModConVar* convar : mod->ConVars)
if (g_CustomConvars.find(convar->Name) == g_CustomConvars.end()) // make sure convar isn't registered yet, unsure if necessary but idk what behaviour is for defining same convar multiple times
RegisterConVar(convar->Name.c_str(), convar->DefaultValue.c_str(), convar->Flags, convar->HelpString.c_str());
-
-
- // register mod files
- if (fs::exists(mod->ModDirectory / MOD_OVERRIDE_DIR))
+ }
+
+ // in a seperate loop because we register mod files in reverse order, since mods loaded later should have their files prioritised
+ for (int i = m_loadedMods.size() - 1; i > -1; i--)
+ {
+ if (fs::exists(m_loadedMods[i]->ModDirectory / MOD_OVERRIDE_DIR))
{
- for (fs::directory_entry file : fs::recursive_directory_iterator(mod->ModDirectory / MOD_OVERRIDE_DIR))
+ for (fs::directory_entry file : fs::recursive_directory_iterator(m_loadedMods[i]->ModDirectory / MOD_OVERRIDE_DIR))
{
if (file.is_regular_file())
{
// super temp because it relies hard on load order
ModOverrideFile* modFile = new ModOverrideFile;
- modFile->owningMod = mod;
- modFile->path = file.path().lexically_relative(mod->ModDirectory / MOD_OVERRIDE_DIR).lexically_normal();
+ modFile->owningMod = m_loadedMods[i];
+ modFile->path = file.path().lexically_relative(m_loadedMods[i]->ModDirectory / MOD_OVERRIDE_DIR).lexically_normal();
m_modFiles.push_back(modFile);
}
}
}
}
-
}
void ModManager::CompileAssetsForFile(const char* filename)