From a78b7d857f86318ab69031d844f34587d2d84e86 Mon Sep 17 00:00:00 2001 From: Jack <66967891+ASpoonPlaysGames@users.noreply.github.com> Date: Sat, 30 Dec 2023 22:59:56 +0000 Subject: Simplify vscript stub function (#627) Since we can get stack info from the sqvm, we don't need to give the function name in the template and stuff. Cherry picked from primedev --- primedev/squirrel/squirrel.cpp | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/primedev/squirrel/squirrel.cpp b/primedev/squirrel/squirrel.cpp index ac9a2ce9..43e43398 100644 --- a/primedev/squirrel/squirrel.cpp +++ b/primedev/squirrel/squirrel.cpp @@ -619,20 +619,12 @@ template void ConCommand_script(const CCommand& args) g_pSquirrel->ExecuteCode(args.ArgS()); } -// literal class type that wraps a constant expression string -template struct TemplateStringLiteral +template SQRESULT SQ_StubbedFunc(HSquirrelVM* sqvm) { - constexpr TemplateStringLiteral(const char (&str)[N]) - { - std::copy_n(str, N, value); - } + SQStackInfos si; + g_pSquirrel->sq_stackinfos(sqvm, 0, si); - char value[N]; -}; - -template SQRESULT SQ_StubbedFunc(HSquirrelVM* sqvm) -{ - spdlog::info("Blocking call to stubbed function {} in {}", funcName.value, GetContextName(context)); + spdlog::warn("Blocking call to stubbed function {} in {}", si._name, GetContextName(context)); return SQRESULT_NULL; } @@ -640,12 +632,12 @@ template void StubUnsafeSQFuncs() { if (!CommandLine()->CheckParm("-allowunsafesqfuncs")) { - g_pSquirrel->AddFuncOverride("DevTextBufferWrite", SQ_StubbedFunc); - g_pSquirrel->AddFuncOverride("DevTextBufferClear", SQ_StubbedFunc); - g_pSquirrel->AddFuncOverride("DevTextBufferDumpToFile", SQ_StubbedFunc); - g_pSquirrel->AddFuncOverride("Dev_CommandLineAddParam", SQ_StubbedFunc); - g_pSquirrel->AddFuncOverride("DevP4Checkout", SQ_StubbedFunc); - g_pSquirrel->AddFuncOverride("DevP4Add", SQ_StubbedFunc); + g_pSquirrel->AddFuncOverride("DevTextBufferWrite", SQ_StubbedFunc); + g_pSquirrel->AddFuncOverride("DevTextBufferClear", SQ_StubbedFunc); + g_pSquirrel->AddFuncOverride("DevTextBufferDumpToFile", SQ_StubbedFunc); + g_pSquirrel->AddFuncOverride("Dev_CommandLineAddParam", SQ_StubbedFunc); + g_pSquirrel->AddFuncOverride("DevP4Checkout", SQ_StubbedFunc); + g_pSquirrel->AddFuncOverride("DevP4Add", SQ_StubbedFunc); } } -- cgit v1.2.3