#include "mods/modmanager.h" #include "squirrel/squirrel.h" ADD_SQFUNC("array", NSGetModNames, "", "", ScriptContext::SERVER | ScriptContext::CLIENT | ScriptContext::UI) { g_pSquirrel->newarray(sqvm, 0); for (Mod& mod : g_pModManager->GetMods()) { g_pSquirrel->pushstring(sqvm, mod.Name.c_str()); g_pSquirrel->arrayappend(sqvm, -2); } return SQRESULT_NOTNULL; } ADD_SQFUNC("bool", NSIsModEnabled, "string modName", "", ScriptContext::SERVER | ScriptContext::CLIENT | ScriptContext::UI) { const SQChar* modName = g_pSquirrel->getstring(sqvm, 1); // manual lookup, not super performant but eh not a big deal for (Mod& mod : g_pModManager->GetMods()) { if (!mod.Name.compare(modName)) { g_pSquirrel->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->getstring(sqvm, 1); const SQBool enabled = g_pSquirrel->getbool(sqvm, 2); // manual lookup, not super performant but eh not a big deal for (Mod& mod : g_pModManager->GetMods()) { 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->getstring(sqvm, 1); // manual lookup, not super performant but eh not a big deal for (Mod& mod : g_pModManager->GetMods()) { if (!mod.Name.compare(modName)) { g_pSquirrel->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->getstring(sqvm, 1); // manual lookup, not super performant but eh not a big deal for (Mod& mod : g_pModManager->GetMods()) { if (!mod.Name.compare(modName)) { g_pSquirrel->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->getstring(sqvm, 1); // manual lookup, not super performant but eh not a big deal for (Mod& mod : g_pModManager->GetMods()) { if (!mod.Name.compare(modName)) { g_pSquirrel->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->getstring(sqvm, 1); // manual lookup, not super performant but eh not a big deal for (Mod& mod : g_pModManager->GetMods()) { if (!mod.Name.compare(modName)) { g_pSquirrel->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->getstring(sqvm, 1); // manual lookup, not super performant but eh not a big deal for (Mod& mod : g_pModManager->GetMods()) { if (!mod.Name.compare(modName)) { g_pSquirrel->pushbool(sqvm, mod.RequiredOnClient); return SQRESULT_NOTNULL; } } return SQRESULT_NULL; } ADD_SQFUNC( "array", NSGetModConvarsByModName, "string modName", "", ScriptContext::SERVER | ScriptContext::CLIENT | ScriptContext::UI) { const SQChar* modName = g_pSquirrel->getstring(sqvm, 1); g_pSquirrel->newarray(sqvm, 0); // manual lookup, not super performant but eh not a big deal for (Mod& mod : g_pModManager->GetMods()) { if (!mod.Name.compare(modName)) { for (ModConVar& cvar : mod.ConVars) { g_pSquirrel->pushstring(sqvm, cvar.Name.c_str()); g_pSquirrel->arrayappend(sqvm, -2); } return SQRESULT_NOTNULL; } } return SQRESULT_NOTNULL; // return empty array } ADD_SQFUNC("void", NSReloadMods, "", "", ScriptContext::UI) { g_pModManager->LoadMods(); return SQRESULT_NULL; }