aboutsummaryrefslogtreecommitdiff
path: root/NorthstarDLL/squirrel/squirrel.cpp
diff options
context:
space:
mode:
authorEmma Miler <emma.pi@protonmail.com>2022-12-22 20:05:45 +0100
committerGitHub <noreply@github.com>2022-12-22 20:05:45 +0100
commitff889f16820430461dec797bb34eeab195b5e930 (patch)
treec145c0285d779975ff521319824c0f7210e3933a /NorthstarDLL/squirrel/squirrel.cpp
parent64100065b55f79e76542ba689545c60e6fb0dcef (diff)
downloadNorthstarLauncher-ff889f16820430461dec797bb34eeab195b5e930.tar.gz
NorthstarLauncher-ff889f16820430461dec797bb34eeab195b5e930.zip
Add NSGetModName (#366)
* Stackinfos * Formatting * Add option for depth * Revert "Merge branch 'main' into stackinfos" This reverts commit e9e8948d2ae9ab72095eb2162de40383b7211276, reversing changes made to d1cf18f7165a9d4fbe7f8ae2f1dfacbba36e4852. * Move macros header * Add macro header to filters * Fix merge conflict mistake * Fix stuff * I hate git * create `NSGetCurrentModName` * Fix merge issues
Diffstat (limited to 'NorthstarDLL/squirrel/squirrel.cpp')
-rw-r--r--NorthstarDLL/squirrel/squirrel.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/NorthstarDLL/squirrel/squirrel.cpp b/NorthstarDLL/squirrel/squirrel.cpp
index 8761fb13..d594ede9 100644
--- a/NorthstarDLL/squirrel/squirrel.cpp
+++ b/NorthstarDLL/squirrel/squirrel.cpp
@@ -561,6 +561,45 @@ template <ScriptContext context> void SquirrelManager<context>::ProcessMessageBu
_call(m_pSQVM->sqvm, message.args.size());
}
+ADD_SQFUNC(
+ "string",
+ NSGetCurrentModName,
+ "",
+ "Returns the mod name of the script running this function",
+ ScriptContext::UI | ScriptContext::CLIENT | ScriptContext::SERVER)
+{
+ int depth = g_pSquirrel<context>->getinteger(sqvm, 1);
+ if (auto mod = g_pSquirrel<context>->getcallingmod(sqvm, depth); mod == nullptr)
+ {
+ g_pSquirrel<context>->raiseerror(sqvm, "NSGetModName was called from a non-mod script. This shouldn't be possible");
+ return SQRESULT_ERROR;
+ }
+ else
+ {
+ g_pSquirrel<context>->pushstring(sqvm, mod->Name.c_str());
+ }
+ return SQRESULT_NOTNULL;
+}
+
+ADD_SQFUNC(
+ "string",
+ NSGetCallingModName,
+ "int depth = 0",
+ "Returns the mod name of the script running this function",
+ ScriptContext::UI | ScriptContext::CLIENT | ScriptContext::SERVER)
+{
+ int depth = g_pSquirrel<context>->getinteger(sqvm, 1);
+ if (auto mod = g_pSquirrel<context>->getcallingmod(sqvm, depth); mod == nullptr)
+ {
+ g_pSquirrel<context>->pushstring(sqvm, "Unknown");
+ }
+ else
+ {
+ g_pSquirrel<context>->pushstring(sqvm, mod->Name.c_str());
+ }
+ return SQRESULT_NOTNULL;
+}
+
ON_DLL_LOAD_RELIESON("client.dll", ClientSquirrel, ConCommand, (CModule module))
{
AUTOHOOK_DISPATCH_MODULE(client.dll)
@@ -637,6 +676,8 @@ ON_DLL_LOAD_RELIESON("client.dll", ClientSquirrel, ConCommand, (CModule module))
g_pSquirrel<ScriptContext::UI>->messageBuffer = g_pSquirrel<ScriptContext::CLIENT>->messageBuffer;
g_pSquirrel<ScriptContext::CLIENT>->__sq_getfunction = module.Offset(0x572FB0).As<sq_getfunctionType>();
g_pSquirrel<ScriptContext::UI>->__sq_getfunction = g_pSquirrel<ScriptContext::CLIENT>->__sq_getfunction;
+ g_pSquirrel<ScriptContext::CLIENT>->__sq_stackinfos = module.Offset(0x35970).As<sq_stackinfosType>();
+ g_pSquirrel<ScriptContext::UI>->__sq_stackinfos = g_pSquirrel<ScriptContext::CLIENT>->__sq_stackinfos;
MAKEHOOK(
module.Offset(0x108E0),
@@ -718,6 +759,7 @@ ON_DLL_LOAD_RELIESON("server.dll", ServerSquirrel, ConCommand, (CModule module))
g_pSquirrel<ScriptContext::SERVER>->logger = NS::log::SCRIPT_SV;
// Message buffer stuff
g_pSquirrel<ScriptContext::SERVER>->__sq_getfunction = module.Offset(0x6C85).As<sq_getfunctionType>();
+ g_pSquirrel<ScriptContext::SERVER>->__sq_stackinfos = module.Offset(0x35920).As<sq_stackinfosType>();
MAKEHOOK(
module.Offset(0x1DD10),