#include "mods/modmanager.h" #include "squirrel/squirrel.h" template void ModToSquirrel(HSQUIRRELVM sqvm, Mod& mod) { g_pSquirrel->pushnewstructinstance(sqvm, 9); // name g_pSquirrel->pushstring(sqvm, mod.Name.c_str(), -1); g_pSquirrel->sealstructslot(sqvm, 0); // description g_pSquirrel->pushstring(sqvm, mod.Description.c_str(), -1); g_pSquirrel->sealstructslot(sqvm, 1); // version g_pSquirrel->pushstring(sqvm, mod.Version.c_str(), -1); g_pSquirrel->sealstructslot(sqvm, 2); // download link g_pSquirrel->pushstring(sqvm, mod.DownloadLink.c_str(), -1); g_pSquirrel->sealstructslot(sqvm, 3); // load priority g_pSquirrel->pushinteger(sqvm, mod.LoadPriority); g_pSquirrel->sealstructslot(sqvm, 4); // enabled g_pSquirrel->pushbool(sqvm, mod.m_bEnabled); g_pSquirrel->sealstructslot(sqvm, 5); // required on client g_pSquirrel->pushbool(sqvm, mod.RequiredOnClient); g_pSquirrel->sealstructslot(sqvm, 6); // is remote g_pSquirrel->pushbool(sqvm, mod.m_bIsRemote); g_pSquirrel->sealstructslot(sqvm, 7); // convars g_pSquirrel->newarray(sqvm); for (ModConVar* cvar : mod.ConVars) { g_pSquirrel->pushstring(sqvm, cvar->Name.c_str()); g_pSquirrel->arrayappend(sqvm, -2); } g_pSquirrel->sealstructslot(sqvm, 8); // add current object to squirrel array g_pSquirrel->arrayappend(sqvm, -2); } ADD_SQFUNC("array", NSGetModsInformation, "", "", ScriptContext::SERVER | ScriptContext::CLIENT | ScriptContext::UI) { g_pSquirrel->newarray(sqvm, 0); for (Mod& mod : g_pModManager->m_LoadedMods) { ModToSquirrel(sqvm, mod); } return SQRESULT_NOTNULL; } ADD_SQFUNC("array", NSGetModInformation, "string modName", "", ScriptContext::SERVER | ScriptContext::CLIENT | ScriptContext::UI) { const SQChar* modName = g_pSquirrel->getstring(sqvm, 1); g_pSquirrel->newarray(sqvm, 0); for (Mod& mod : g_pModManager->m_LoadedMods) { if (mod.Name.compare(modName) != 0) { continue; } ModToSquirrel(sqvm, mod); } return SQRESULT_NOTNULL; } ADD_SQFUNC("array", NSGetModNames, "", "", ScriptContext::SERVER | ScriptContext::CLIENT | ScriptContext::UI) { g_pSquirrel->newarray(sqvm, 0); for (Mod& mod : g_pModManager->m_LoadedMods) { g_pSquirrel->pushstring(sqvm, mod.Name.c_str()); g_pSquirrel->arrayappend(sqvm, -2); } return SQRESULT_NOTNULL; } 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->m_LoadedMods) { if (!mod.Name.compare(modName)) { mod.m_bEnabled = enabled; return SQRESULT_NULL; } } return SQRESULT_NULL; } ADD_SQFUNC("void", NSReloadMods, "", "", ScriptContext::UI) { NOTE_UNUSED(sqvm); g_pModManager->LoadMods(); return SQRESULT_NULL; }