aboutsummaryrefslogtreecommitdiff
path: root/NorthstarDedicatedTest
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
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')
-rw-r--r--NorthstarDedicatedTest/modmanager.cpp34
-rw-r--r--NorthstarDedicatedTest/modmanager.h4
-rw-r--r--NorthstarDedicatedTest/scriptsrson.cpp8
-rw-r--r--NorthstarDedicatedTest/squirrel.cpp14
-rw-r--r--NorthstarDedicatedTest/squirrel.h13
5 files changed, 52 insertions, 21 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)
diff --git a/NorthstarDedicatedTest/modmanager.h b/NorthstarDedicatedTest/modmanager.h
index 662c34c4..78b3153c 100644
--- a/NorthstarDedicatedTest/modmanager.h
+++ b/NorthstarDedicatedTest/modmanager.h
@@ -59,7 +59,9 @@ public:
std::string DownloadLink;
// whether clients need the mod to join servers running this mod
- bool RequiredOnClient = true;
+ bool RequiredOnClient;
+ // the priority for this mod's files, mods with prio 0 are loaded first, then 1, then 2, etc
+ int LoadPriority;
// custom scripts used by the mod
std::vector<ModScript*> Scripts;
diff --git a/NorthstarDedicatedTest/scriptsrson.cpp b/NorthstarDedicatedTest/scriptsrson.cpp
index 05386910..1f08e7f1 100644
--- a/NorthstarDedicatedTest/scriptsrson.cpp
+++ b/NorthstarDedicatedTest/scriptsrson.cpp
@@ -2,6 +2,7 @@
#include "modmanager.h"
#include "scriptsrson.h"
#include "filesystem.h"
+#include "squirrel.h"
#include <sstream>
#include <fstream>
@@ -21,11 +22,11 @@ void ModManager::BuildScriptsRson()
{
for (ModScript* script : mod->Scripts)
{
- /* should create something with the format
+ /* should create something with this format for each script
When: "CONTEXT"
Scripts:
[
- "_coolscript.gnut"
+ _coolscript.gnut
]*/
scriptsRson += "When: \"";
@@ -48,4 +49,7 @@ void ModManager::BuildScriptsRson()
overrideFile->owningMod = nullptr;
overrideFile->path = "scripts/vscripts/scripts.rson";
m_modFiles.push_back(overrideFile);
+
+ // todo: for preventing dupe scripts in scripts.rson, we could actually parse when conditions with the squirrel vm, just need a way to get a result out of squirrelmanager.ExecuteCode
+ // this would probably be the best way to do this, imo
} \ No newline at end of file
diff --git a/NorthstarDedicatedTest/squirrel.cpp b/NorthstarDedicatedTest/squirrel.cpp
index 4462eb7f..d999ef0d 100644
--- a/NorthstarDedicatedTest/squirrel.cpp
+++ b/NorthstarDedicatedTest/squirrel.cpp
@@ -123,14 +123,14 @@ template<Context context> void* CreateNewVMHook(void* a1, Context realContext)
sqvm = ClientCreateNewVM(a1, realContext);
if (realContext == UI)
- g_UISquirrelManager->sqvm = sqvm;
+ g_UISquirrelManager->VMCreated(sqvm);
else
- g_ClientSquirrelManager->sqvm = sqvm;
+ g_ClientSquirrelManager->VMCreated(sqvm)
}
else if (context == SERVER)
{
sqvm = ServerCreateNewVM(a1, context);
- g_ServerSquirrelManager->sqvm = sqvm;
+ g_ServerSquirrelManager->VMCreated(sqvm);
}
spdlog::info("CreateNewVM {} {}", GetContextName(realContext), sqvm);
@@ -144,18 +144,18 @@ template<Context context> void DestroyVMHook(void* a1, void* sqvm)
if (context == CLIENT)
{
if (g_ClientSquirrelManager->sqvm == sqvm)
- g_ClientSquirrelManager->sqvm = nullptr;
+ g_ClientSquirrelManager->VMDestroyed();
else if (g_UISquirrelManager->sqvm == sqvm)
{
- g_UISquirrelManager->sqvm = nullptr;
- realContext == UI;
+ g_UISquirrelManager->VMDestroyed();
+ realContext = UI;
}
ClientDestroyVM(a1, sqvm);
}
else if (context == SERVER)
{
- g_ServerSquirrelManager->sqvm = nullptr;
+ g_ServerSquirrelManager->VMDestroyed();
ServerDestroyVM(a1, sqvm);
}
diff --git a/NorthstarDedicatedTest/squirrel.h b/NorthstarDedicatedTest/squirrel.h
index bb377604..43f6cef8 100644
--- a/NorthstarDedicatedTest/squirrel.h
+++ b/NorthstarDedicatedTest/squirrel.h
@@ -44,9 +44,6 @@ typedef SQInteger(*SQFunction)(void* sqvm);
template<Context context> class SquirrelManager
{
-private:
- //std::vector<
-
public:
void* sqvm;
@@ -54,6 +51,16 @@ public:
SquirrelManager() : sqvm(nullptr)
{}
+ void VMCreated(void* sqvm)
+ {
+ sqvm = sqvm;
+ }
+
+ void VMDestroyed()
+ {
+ sqvm = nullptr;
+ }
+
void ExecuteCode(const char* code)
{
// ttf2sdk checks ThreadIsInMainThread here, might be good to do that? doesn't seem like an issue rn tho