aboutsummaryrefslogtreecommitdiff
path: root/NorthstarDLL/scripts/client/scriptmodmenu.cpp
diff options
context:
space:
mode:
authorEmma Miler <emma.pi@protonmail.com>2022-12-19 19:32:16 +0100
committerGitHub <noreply@github.com>2022-12-19 19:32:16 +0100
commite04f3b36accccb590a2d51b4829256b9964ac3fd (patch)
tree20ee30c82e6f53e6e772be2e1b9613eebca12bf3 /NorthstarDLL/scripts/client/scriptmodmenu.cpp
parent33f18a735986dcd136bf8ba70ad8331306c28227 (diff)
downloadNorthstarLauncher-e04f3b36accccb590a2d51b4829256b9964ac3fd.tar.gz
NorthstarLauncher-e04f3b36accccb590a2d51b4829256b9964ac3fd.zip
Restructuring (#365)
* Remove launcher proxy * Restructuring * More restructuring * Fix include dirs * Fix merge * Remove clang thing * Filters * Oops
Diffstat (limited to 'NorthstarDLL/scripts/client/scriptmodmenu.cpp')
-rw-r--r--NorthstarDLL/scripts/client/scriptmodmenu.cpp166
1 files changed, 166 insertions, 0 deletions
diff --git a/NorthstarDLL/scripts/client/scriptmodmenu.cpp b/NorthstarDLL/scripts/client/scriptmodmenu.cpp
new file mode 100644
index 00000000..75d05acc
--- /dev/null
+++ b/NorthstarDLL/scripts/client/scriptmodmenu.cpp
@@ -0,0 +1,166 @@
+#include "pch.h"
+#include "mods/modmanager.h"
+#include "squirrel/squirrel.h"
+
+ADD_SQFUNC("array<string>", NSGetModNames, "", "", ScriptContext::SERVER | ScriptContext::CLIENT | ScriptContext::UI)
+{
+ g_pSquirrel<context>->newarray(sqvm, 0);
+
+ for (Mod& mod : g_pModManager->m_LoadedMods)
+ {
+ g_pSquirrel<context>->pushstring(sqvm, mod.Name.c_str());
+ g_pSquirrel<context>->arrayappend(sqvm, -2);
+ }
+
+ return SQRESULT_NOTNULL;
+}
+
+ADD_SQFUNC("bool", NSIsModEnabled, "string modName", "", ScriptContext::SERVER | ScriptContext::CLIENT | ScriptContext::UI)
+{
+ const SQChar* modName = g_pSquirrel<context>->getstring(sqvm, 1);
+
+ // manual lookup, not super performant but eh not a big deal
+ for (Mod& mod : g_pModManager->m_LoadedMods)
+ {
+ if (!mod.Name.compare(modName))
+ {
+ g_pSquirrel<context>->pushbool(sqvm, mod.m_bEnabled);
+ return SQRESULT_NOTNULL;
+ }
+ }
+
+ return SQRESULT_NULL;
+}
+
+ADD_SQFUNC("void", NSSetModEnabled, "string modName, bool enabled", "", ScriptContext::SERVER | ScriptContext::CLIENT | ScriptContext::UI)
+{
+ const SQChar* modName = g_pSquirrel<context>->getstring(sqvm, 1);
+ const SQBool enabled = g_pSquirrel<context>->getbool(sqvm, 2);
+
+ // manual lookup, not super performant but eh not a big deal
+ for (Mod& mod : g_pModManager->m_LoadedMods)
+ {
+ if (!mod.Name.compare(modName))
+ {
+ mod.m_bEnabled = enabled;
+ return SQRESULT_NULL;
+ }
+ }
+
+ return SQRESULT_NULL;
+}
+
+ADD_SQFUNC("string", NSGetModDescriptionByModName, "string modName", "", ScriptContext::SERVER | ScriptContext::CLIENT | ScriptContext::UI)
+{
+ const SQChar* modName = g_pSquirrel<context>->getstring(sqvm, 1);
+
+ // manual lookup, not super performant but eh not a big deal
+ for (Mod& mod : g_pModManager->m_LoadedMods)
+ {
+ if (!mod.Name.compare(modName))
+ {
+ g_pSquirrel<context>->pushstring(sqvm, mod.Description.c_str());
+ return SQRESULT_NOTNULL;
+ }
+ }
+
+ return SQRESULT_NULL;
+}
+
+ADD_SQFUNC("string", NSGetModVersionByModName, "string modName", "", ScriptContext::SERVER | ScriptContext::CLIENT | ScriptContext::UI)
+{
+ const SQChar* modName = g_pSquirrel<context>->getstring(sqvm, 1);
+
+ // manual lookup, not super performant but eh not a big deal
+ for (Mod& mod : g_pModManager->m_LoadedMods)
+ {
+ if (!mod.Name.compare(modName))
+ {
+ g_pSquirrel<context>->pushstring(sqvm, mod.Version.c_str());
+ return SQRESULT_NOTNULL;
+ }
+ }
+
+ return SQRESULT_NULL;
+}
+
+ADD_SQFUNC("string", NSGetModDownloadLinkByModName, "string modName", "", ScriptContext::SERVER | ScriptContext::CLIENT | ScriptContext::UI)
+{
+ const SQChar* modName = g_pSquirrel<context>->getstring(sqvm, 1);
+
+ // manual lookup, not super performant but eh not a big deal
+ for (Mod& mod : g_pModManager->m_LoadedMods)
+ {
+ if (!mod.Name.compare(modName))
+ {
+ g_pSquirrel<context>->pushstring(sqvm, mod.DownloadLink.c_str());
+ return SQRESULT_NOTNULL;
+ }
+ }
+
+ return SQRESULT_NULL;
+}
+
+ADD_SQFUNC("int", NSGetModLoadPriority, "string modName", "", ScriptContext::SERVER | ScriptContext::CLIENT | ScriptContext::UI)
+{
+ const SQChar* modName = g_pSquirrel<context>->getstring(sqvm, 1);
+
+ // manual lookup, not super performant but eh not a big deal
+ for (Mod& mod : g_pModManager->m_LoadedMods)
+ {
+ if (!mod.Name.compare(modName))
+ {
+ g_pSquirrel<context>->pushinteger(sqvm, mod.LoadPriority);
+ return SQRESULT_NOTNULL;
+ }
+ }
+
+ return SQRESULT_NULL;
+}
+
+ADD_SQFUNC("bool", NSIsModRequiredOnClient, "string modName", "", ScriptContext::SERVER | ScriptContext::CLIENT | ScriptContext::UI)
+{
+ const SQChar* modName = g_pSquirrel<context>->getstring(sqvm, 1);
+
+ // manual lookup, not super performant but eh not a big deal
+ for (Mod& mod : g_pModManager->m_LoadedMods)
+ {
+ if (!mod.Name.compare(modName))
+ {
+ g_pSquirrel<context>->pushbool(sqvm, mod.RequiredOnClient);
+ return SQRESULT_NOTNULL;
+ }
+ }
+
+ return SQRESULT_NULL;
+}
+
+ADD_SQFUNC(
+ "array<string>", NSGetModConvarsByModName, "string modName", "", ScriptContext::SERVER | ScriptContext::CLIENT | ScriptContext::UI)
+{
+ const SQChar* modName = g_pSquirrel<context>->getstring(sqvm, 1);
+ g_pSquirrel<context>->newarray(sqvm, 0);
+
+ // manual lookup, not super performant but eh not a big deal
+ for (Mod& mod : g_pModManager->m_LoadedMods)
+ {
+ if (!mod.Name.compare(modName))
+ {
+ for (ModConVar* cvar : mod.ConVars)
+ {
+ g_pSquirrel<context>->pushstring(sqvm, cvar->Name.c_str());
+ g_pSquirrel<context>->arrayappend(sqvm, -2);
+ }
+
+ return SQRESULT_NOTNULL;
+ }
+ }
+
+ return SQRESULT_NOTNULL; // return empty array
+}
+
+ADD_SQFUNC("void", NSReloadMods, "", "", ScriptContext::UI)
+{
+ g_pModManager->LoadMods();
+ return SQRESULT_NULL;
+}