aboutsummaryrefslogtreecommitdiff
path: root/NorthstarDedicatedTest/modmanager.cpp
diff options
context:
space:
mode:
authorBobTheBob <32057864+BobTheBob9@users.noreply.github.com>2021-07-21 00:51:32 +0100
committerBobTheBob <32057864+BobTheBob9@users.noreply.github.com>2021-07-21 00:51:32 +0100
commit93fe64e04ed766727634e5b5f6906f6461a70711 (patch)
tree467f58533ddf4c139f896166894bde8213fd34c8 /NorthstarDedicatedTest/modmanager.cpp
parent958d03d2817e312c8eb70234f1c65e4bcbded716 (diff)
downloadNorthstarLauncher-93fe64e04ed766727634e5b5f6906f6461a70711.tar.gz
NorthstarLauncher-93fe64e04ed766727634e5b5f6906f6461a70711.zip
add eval commands and script compile error hook
Diffstat (limited to 'NorthstarDedicatedTest/modmanager.cpp')
-rw-r--r--NorthstarDedicatedTest/modmanager.cpp54
1 files changed, 44 insertions, 10 deletions
diff --git a/NorthstarDedicatedTest/modmanager.cpp b/NorthstarDedicatedTest/modmanager.cpp
index 72998347..a45d2b2a 100644
--- a/NorthstarDedicatedTest/modmanager.cpp
+++ b/NorthstarDedicatedTest/modmanager.cpp
@@ -106,20 +106,44 @@ Mod::Mod(fs::path modDir, char* jsonBuf)
script->Path = scriptObj["Path"].GetString();
script->RsonRunOn = scriptObj["RunOn"].GetString();
- // callbacks
- for (auto iterator = scriptObj.MemberBegin(); iterator != scriptObj.MemberEnd(); iterator++)
+ if (scriptObj.HasMember("ServerCallback") && scriptObj["ServerCallback"].IsObject())
{
- if (!iterator->name.IsString() || !iterator->value.IsObject())
- continue;
+ ModScriptCallback* callback = new ModScriptCallback;
+ callback->Context = SERVER;
+
+ if (scriptObj["ServerCallback"].HasMember("Before") && scriptObj["ServerCallback"]["Before"].IsString())
+ callback->BeforeCallback = scriptObj["ServerCallback"]["Before"].GetString();
+ if (scriptObj["ServerCallback"].HasMember("After") && scriptObj["ServerCallback"]["After"].IsString())
+ callback->AfterCallback = scriptObj["ServerCallback"]["After"].GetString();
+
+ script->Callbacks.push_back(callback);
+ }
+
+ if (scriptObj.HasMember("ClientCallback") && scriptObj["ClientCallback"].IsObject())
+ {
ModScriptCallback* callback = new ModScriptCallback;
- callback->HookedCodeCallback = iterator->name.GetString();
+ callback->Context = CLIENT;
- if (iterator->value.HasMember("Before") && iterator->value["Before"].IsString())
- callback->BeforeCallback = iterator->value["Before"].GetString();
+ if (scriptObj["ClientCallback"].HasMember("Before") && scriptObj["ClientCallback"]["Before"].IsString())
+ callback->BeforeCallback = scriptObj["ClientCallback"]["Before"].GetString();
- if (iterator->value.HasMember("After") && iterator->value["After"].IsString())
- callback->AfterCallback = iterator->value["After"].GetString();
+ if (scriptObj["ClientCallback"].HasMember("After") && scriptObj["ClientCallback"]["After"].IsString())
+ callback->AfterCallback = scriptObj["ClientCallback"]["After"].GetString();
+
+ script->Callbacks.push_back(callback);
+ }
+
+ if (scriptObj.HasMember("UICallback") && scriptObj["UICallback"].IsObject())
+ {
+ ModScriptCallback* callback = new ModScriptCallback;
+ callback->Context = UI;
+
+ if (scriptObj["UICallback"].HasMember("Before") && scriptObj["UICallback"]["Before"].IsString())
+ callback->BeforeCallback = scriptObj["UICallback"]["Before"].GetString();
+
+ if (scriptObj["UICallback"].HasMember("After") && scriptObj["UICallback"]["After"].IsString())
+ callback->AfterCallback = scriptObj["UICallback"]["After"].GetString();
script->Callbacks.push_back(callback);
}
@@ -128,6 +152,12 @@ Mod::Mod(fs::path modDir, char* jsonBuf)
}
}
+ // vpk stuff
+ if (fs::exists(modDir / "vpk"))
+ for (fs::directory_entry file : fs::directory_iterator(modDir / "vpk"))
+ if (fs::is_regular_file(file) && file.path().extension() == "vpk")
+ Vpks.push_back(file.path().string());
+
wasReadSuccessfully = true;
}
@@ -138,6 +168,8 @@ ModManager::ModManager()
void ModManager::LoadMods()
{
+ // this needs better support for reloads
+
std::vector<fs::path> modDirs;
// get mod directories
@@ -179,8 +211,10 @@ void ModManager::LoadMods()
for (Mod* mod : loadedMods)
{
+ // for reloads, this is sorta barebones, when we have a good findconvar method, we could probably reset flags and stuff on preexisting convars
+ // potentially it might also be good to unregister convars when they get removed on a reload, but unsure if necessary
for (ModConVar* convar : mod->ConVars)
- if (g_CustomConvars.find(convar->Name) == g_CustomConvars.end()) // make sure convar isn't registered yet
+ 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());
}