From ff889f16820430461dec797bb34eeab195b5e930 Mon Sep 17 00:00:00 2001 From: Emma Miler Date: Thu, 22 Dec 2022 20:05:45 +0100 Subject: 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 --- NorthstarDLL/squirrel/squirrel.h | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'NorthstarDLL/squirrel/squirrel.h') diff --git a/NorthstarDLL/squirrel/squirrel.h b/NorthstarDLL/squirrel/squirrel.h index 51fa93b3..82825b3c 100644 --- a/NorthstarDLL/squirrel/squirrel.h +++ b/NorthstarDLL/squirrel/squirrel.h @@ -1,9 +1,9 @@ #pragma once -#include "logging/logging.h" #include "squirrelclasstypes.h" #include "squirrelautobind.h" #include "core/math/vector.h" +#include "mods/modmanager.h" // stolen from ttf2sdk: sqvm types typedef float SQFloat; @@ -39,8 +39,6 @@ const char* SQTypeNameFromID(const int iTypeId); ScriptContext ScriptContextFromString(std::string string); -std::shared_ptr getSquirrelLoggerByContext(ScriptContext context); - namespace NS::log { template std::shared_ptr squirrel_logger(); @@ -98,6 +96,8 @@ class SquirrelManagerBase sq_getthisentityType __sq_getthisentity; sq_getobjectType __sq_getobject; + sq_stackinfosType __sq_stackinfos; + sq_createuserdataType __sq_createuserdata; sq_setuserdatatypeidType __sq_setuserdatatypeid; sq_getfunctionType __sq_getfunction; @@ -230,6 +230,28 @@ class SquirrelManagerBase return __sq_getasset(sqvm, stackpos, result); } + inline long long sq_stackinfos(HSquirrelVM* sqvm, int level, SQStackInfos& out) + { + return __sq_stackinfos(sqvm, level, &out, sqvm->_callstacksize); + } + + inline Mod* getcallingmod(HSquirrelVM* sqvm, int depth = 0) + { + SQStackInfos stackInfo {}; + if (1 + depth >= sqvm->_callstacksize) + { + return nullptr; + } + sq_stackinfos(sqvm, 1 + depth, stackInfo); + std::string sourceName = stackInfo._sourceName; + std::replace(sourceName.begin(), sourceName.end(), '/', '\\'); + std::string filename = "scripts\\vscripts\\" + sourceName; + if (auto res = g_pModManager->m_ModFiles.find(filename); res != g_pModManager->m_ModFiles.end()) + { + return res->second.m_pOwningMod; + } + return nullptr; + } template inline SQRESULT getuserdata(HSquirrelVM* sqvm, const SQInteger stackpos, T* data, uint64_t* typeId) { return __sq_getuserdata(sqvm, stackpos, (void**)data, typeId); // this sometimes crashes idk -- cgit v1.2.3