aboutsummaryrefslogtreecommitdiff
path: root/NorthstarDLL/scriptmodmenu.cpp
diff options
context:
space:
mode:
authorMaya <malte.hoermeyer@web.de>2022-11-13 04:01:14 +0100
committerGitHub <noreply@github.com>2022-11-13 03:01:14 +0000
commit23fda0b842560d2f3cf64ecf9a57d5ad2861e488 (patch)
tree9527c91bd744fb0562963e43e212c1bc5536847d /NorthstarDLL/scriptmodmenu.cpp
parentd237401bb97c1fa2d6ee87220d49e4b3343e7201 (diff)
downloadNorthstarLauncher-23fda0b842560d2f3cf64ecf9a57d5ad2861e488.tar.gz
NorthstarLauncher-23fda0b842560d2f3cf64ecf9a57d5ad2861e488.zip
Squirrel functions auto bind (#299)
* Add defines to auto add squirrel funcs it brokey * Make it Work changed all squirrel function definitions to this system * Add defines to auto add squirrel funcs it brokey Co-authored-by: Emma-Miler <27428383+emma-miler@users.noreply.github.com> * Make it Work changed all squirrel function definitions to this system Co-authored-by: Emma-Miler <27428383+emma-miler@users.noreply.github.com> * Formatting * Good old Formatting commit * HelloGecko * Formatting Finalv2ForRealThisTime * idk anymore * i hate formatting * Rename some * Rename macro * Change function names to more human-readable * Revert to using old ScriptContext definition * Formatting Co-authored-by: RoyalBlue1 <realEmail@veryRealURL.com> Co-authored-by: Emma-Miler <27428383+emma-miler@users.noreply.github.com> Co-authored-by: Emma Miler <emma.pi@protonmail.com> Co-authored-by: BobTheBob <32057864+BobTheBob9@users.noreply.github.com>
Diffstat (limited to 'NorthstarDLL/scriptmodmenu.cpp')
-rw-r--r--NorthstarDLL/scriptmodmenu.cpp100
1 files changed, 31 insertions, 69 deletions
diff --git a/NorthstarDLL/scriptmodmenu.cpp b/NorthstarDLL/scriptmodmenu.cpp
index d2f35285..df5dc101 100644
--- a/NorthstarDLL/scriptmodmenu.cpp
+++ b/NorthstarDLL/scriptmodmenu.cpp
@@ -2,31 +2,29 @@
#include "modmanager.h"
#include "squirrel.h"
-// array<string> function NSGetModNames()
-SQRESULT SQ_GetModNames(HSquirrelVM* sqvm)
+ADD_SQFUNC("array<string>", NSGetModNames, "", "", ScriptContext::UI)
{
- g_pSquirrel<ScriptContext::UI>->newarray(sqvm, 0);
+ g_pSquirrel<context>->newarray(sqvm, 0);
for (Mod& mod : g_pModManager->m_LoadedMods)
{
- g_pSquirrel<ScriptContext::UI>->pushstring(sqvm, mod.Name.c_str());
- g_pSquirrel<ScriptContext::UI>->arrayappend(sqvm, -2);
+ g_pSquirrel<context>->pushstring(sqvm, mod.Name.c_str());
+ g_pSquirrel<context>->arrayappend(sqvm, -2);
}
return SQRESULT_NOTNULL;
}
-// bool function NSIsModEnabled(string modName)
-SQRESULT SQ_IsModEnabled(HSquirrelVM* sqvm)
+ADD_SQFUNC("bool", NSIsModEnabled, "string modName", "", ScriptContext::UI)
{
- const SQChar* modName = g_pSquirrel<ScriptContext::UI>->getstring(sqvm, 1);
+ 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<ScriptContext::UI>->pushbool(sqvm, mod.m_bEnabled);
+ g_pSquirrel<context>->pushbool(sqvm, mod.m_bEnabled);
return SQRESULT_NOTNULL;
}
}
@@ -34,11 +32,10 @@ SQRESULT SQ_IsModEnabled(HSquirrelVM* sqvm)
return SQRESULT_NULL;
}
-// void function NSSetModEnabled(string modName, bool enabled)
-SQRESULT SQ_SetModEnabled(HSquirrelVM* sqvm)
+ADD_SQFUNC("void", NSSetModEnabled, "string modName, bool enabled", "", ScriptContext::UI)
{
- const SQChar* modName = g_pSquirrel<ScriptContext::UI>->getstring(sqvm, 1);
- const SQBool enabled = g_pSquirrel<ScriptContext::UI>->getbool(sqvm, 2);
+ 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)
@@ -53,17 +50,16 @@ SQRESULT SQ_SetModEnabled(HSquirrelVM* sqvm)
return SQRESULT_NULL;
}
-// string function NSGetModDescriptionByModName(string modName)
-SQRESULT SQ_GetModDescription(HSquirrelVM* sqvm)
+ADD_SQFUNC("string", NSGetModDescriptionByModName, "string modName", "", ScriptContext::UI)
{
- const SQChar* modName = g_pSquirrel<ScriptContext::UI>->getstring(sqvm, 1);
+ 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<ScriptContext::UI>->pushstring(sqvm, mod.Description.c_str());
+ g_pSquirrel<context>->pushstring(sqvm, mod.Description.c_str());
return SQRESULT_NOTNULL;
}
}
@@ -71,17 +67,16 @@ SQRESULT SQ_GetModDescription(HSquirrelVM* sqvm)
return SQRESULT_NULL;
}
-// string function NSGetModVersionByModName(string modName)
-SQRESULT SQ_GetModVersion(HSquirrelVM* sqvm)
+ADD_SQFUNC("string", NSGetModVersionByModName, "string modName", "", ScriptContext::UI)
{
- const SQChar* modName = g_pSquirrel<ScriptContext::UI>->getstring(sqvm, 1);
+ 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<ScriptContext::UI>->pushstring(sqvm, mod.Version.c_str());
+ g_pSquirrel<context>->pushstring(sqvm, mod.Version.c_str());
return SQRESULT_NOTNULL;
}
}
@@ -89,17 +84,16 @@ SQRESULT SQ_GetModVersion(HSquirrelVM* sqvm)
return SQRESULT_NULL;
}
-// string function NSGetModDownloadLinkByModName(string modName)
-SQRESULT SQ_GetModDownloadLink(HSquirrelVM* sqvm)
+ADD_SQFUNC("string", NSGetModDownloadLinkByModName, "string modName", "", ScriptContext::UI)
{
- const SQChar* modName = g_pSquirrel<ScriptContext::UI>->getstring(sqvm, 1);
+ 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<ScriptContext::UI>->pushstring(sqvm, mod.DownloadLink.c_str());
+ g_pSquirrel<context>->pushstring(sqvm, mod.DownloadLink.c_str());
return SQRESULT_NOTNULL;
}
}
@@ -107,17 +101,16 @@ SQRESULT SQ_GetModDownloadLink(HSquirrelVM* sqvm)
return SQRESULT_NULL;
}
-// int function NSGetModLoadPriority(string modName)
-SQRESULT SQ_GetModLoadPriority(HSquirrelVM* sqvm)
+ADD_SQFUNC("int", NSGetModLoadPriority, "string modName", "", ScriptContext::UI)
{
- const SQChar* modName = g_pSquirrel<ScriptContext::UI>->getstring(sqvm, 1);
+ 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<ScriptContext::UI>->pushinteger(sqvm, mod.LoadPriority);
+ g_pSquirrel<context>->pushinteger(sqvm, mod.LoadPriority);
return SQRESULT_NOTNULL;
}
}
@@ -125,17 +118,16 @@ SQRESULT SQ_GetModLoadPriority(HSquirrelVM* sqvm)
return SQRESULT_NULL;
}
-// bool function NSIsModRequiredOnClient(string modName)
-SQRESULT SQ_IsModRequiredOnClient(HSquirrelVM* sqvm)
+ADD_SQFUNC("bool", NSIsModRequiredOnClient, "string modName", "", ScriptContext::UI)
{
- const SQChar* modName = g_pSquirrel<ScriptContext::UI>->getstring(sqvm, 1);
+ 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<ScriptContext::UI>->pushbool(sqvm, mod.RequiredOnClient);
+ g_pSquirrel<context>->pushbool(sqvm, mod.RequiredOnClient);
return SQRESULT_NOTNULL;
}
}
@@ -143,11 +135,10 @@ SQRESULT SQ_IsModRequiredOnClient(HSquirrelVM* sqvm)
return SQRESULT_NULL;
}
-// array<string> function NSGetModConvarsByModName(string modName)
-SQRESULT SQ_GetModConvars(HSquirrelVM* sqvm)
+ADD_SQFUNC("array<string>", NSGetModConvarsByModName, "string modName", "", ScriptContext::UI)
{
- const SQChar* modName = g_pSquirrel<ScriptContext::UI>->getstring(sqvm, 1);
- g_pSquirrel<ScriptContext::UI>->newarray(sqvm, 0);
+ 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)
@@ -156,8 +147,8 @@ SQRESULT SQ_GetModConvars(HSquirrelVM* sqvm)
{
for (ModConVar* cvar : mod.ConVars)
{
- g_pSquirrel<ScriptContext::UI>->pushstring(sqvm, cvar->Name.c_str());
- g_pSquirrel<ScriptContext::UI>->arrayappend(sqvm, -2);
+ g_pSquirrel<context>->pushstring(sqvm, cvar->Name.c_str());
+ g_pSquirrel<context>->arrayappend(sqvm, -2);
}
return SQRESULT_NOTNULL;
@@ -167,37 +158,8 @@ SQRESULT SQ_GetModConvars(HSquirrelVM* sqvm)
return SQRESULT_NOTNULL; // return empty array
}
-// void function NSReloadMods()
-SQRESULT SQ_ReloadMods(HSquirrelVM* sqvm)
+ADD_SQFUNC("void", NSReloadMods, "", "", ScriptContext::UI)
{
g_pModManager->LoadMods();
return SQRESULT_NULL;
}
-
-ON_DLL_LOAD_CLIENT_RELIESON("client.dll", ScriptModMenu, ClientSquirrel, (CModule module))
-{
- g_pSquirrel<ScriptContext::UI>->AddFuncRegistration(
- "array<string>", "NSGetModNames", "", "Returns the names of all loaded mods", SQ_GetModNames);
- g_pSquirrel<ScriptContext::UI>->AddFuncRegistration(
- "bool", "NSIsModEnabled", "string modName", "Returns whether a given mod is enabled", SQ_IsModEnabled);
- g_pSquirrel<ScriptContext::UI>->AddFuncRegistration(
- "void", "NSSetModEnabled", "string modName, bool enabled", "Sets whether a given mod is enabled", SQ_SetModEnabled);
- g_pSquirrel<ScriptContext::UI>->AddFuncRegistration(
- "string", "NSGetModDescriptionByModName", "string modName", "Returns a given mod's description", SQ_GetModDescription);
- g_pSquirrel<ScriptContext::UI>->AddFuncRegistration(
- "string", "NSGetModVersionByModName", "string modName", "Returns a given mod's version", SQ_GetModVersion);
- g_pSquirrel<ScriptContext::UI>->AddFuncRegistration(
- "string", "NSGetModDownloadLinkByModName", "string modName", "Returns a given mod's download link", SQ_GetModDownloadLink);
- g_pSquirrel<ScriptContext::UI>->AddFuncRegistration(
- "bool",
- "NSIsModRequiredOnClient",
- "string modName",
- "Returns whether a given mod is required on connecting clients",
- SQ_IsModRequiredOnClient);
- g_pSquirrel<ScriptContext::UI>->AddFuncRegistration(
- "int", "NSGetModLoadPriority", "string modName", "Returns a given mod's load priority", SQ_GetModLoadPriority);
- g_pSquirrel<ScriptContext::UI>->AddFuncRegistration(
- "array<string>", "NSGetModConvarsByModName", "string modName", "Returns the names of all a given mod's cvars", SQ_GetModConvars);
-
- g_pSquirrel<ScriptContext::UI>->AddFuncRegistration("void", "NSReloadMods", "", "Reloads mods", SQ_ReloadMods);
-}