Skip to content

Commit

Permalink
Simplify vscript stub function (#627)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ASpoonPlaysGames authored Dec 30, 2023
1 parent f5ab6fb commit a78b7d8
Showing 1 changed file with 10 additions and 18 deletions.
28 changes: 10 additions & 18 deletions primedev/squirrel/squirrel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -619,33 +619,25 @@ template <ScriptContext context> void ConCommand_script(const CCommand& args)
g_pSquirrel<context>->ExecuteCode(args.ArgS());
}

// literal class type that wraps a constant expression string
template <size_t N> struct TemplateStringLiteral
template <ScriptContext context> SQRESULT SQ_StubbedFunc(HSquirrelVM* sqvm)
{
constexpr TemplateStringLiteral(const char (&str)[N])
{
std::copy_n(str, N, value);
}
SQStackInfos si;
g_pSquirrel<context>->sq_stackinfos(sqvm, 0, si);

char value[N];
};

template <ScriptContext context, TemplateStringLiteral funcName> 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;
}

template <ScriptContext context> void StubUnsafeSQFuncs()
{
if (!CommandLine()->CheckParm("-allowunsafesqfuncs"))
{
g_pSquirrel<context>->AddFuncOverride("DevTextBufferWrite", SQ_StubbedFunc<context, "DevTextBufferWrite">);
g_pSquirrel<context>->AddFuncOverride("DevTextBufferClear", SQ_StubbedFunc<context, "DevTextBufferClear">);
g_pSquirrel<context>->AddFuncOverride("DevTextBufferDumpToFile", SQ_StubbedFunc<context, "DevTextBufferDumpToFile">);
g_pSquirrel<context>->AddFuncOverride("Dev_CommandLineAddParam", SQ_StubbedFunc<context, "Dev_CommandLineAddParam">);
g_pSquirrel<context>->AddFuncOverride("DevP4Checkout", SQ_StubbedFunc<context, "DevP4Checkout">);
g_pSquirrel<context>->AddFuncOverride("DevP4Add", SQ_StubbedFunc<context, "DevP4Add">);
g_pSquirrel<context>->AddFuncOverride("DevTextBufferWrite", SQ_StubbedFunc<context>);
g_pSquirrel<context>->AddFuncOverride("DevTextBufferClear", SQ_StubbedFunc<context>);
g_pSquirrel<context>->AddFuncOverride("DevTextBufferDumpToFile", SQ_StubbedFunc<context>);
g_pSquirrel<context>->AddFuncOverride("Dev_CommandLineAddParam", SQ_StubbedFunc<context>);
g_pSquirrel<context>->AddFuncOverride("DevP4Checkout", SQ_StubbedFunc<context>);
g_pSquirrel<context>->AddFuncOverride("DevP4Add", SQ_StubbedFunc<context>);
}
}

Expand Down

0 comments on commit a78b7d8

Please sign in to comment.