Skip to content

Commit

Permalink
Simplify vscript stub functions
Browse files Browse the repository at this point in the history
  • Loading branch information
F1F7Y authored and ASpoonPlaysGames committed Dec 24, 2023
1 parent 7bb8789 commit 1383765
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions primedev/squirrel/squirrel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -620,32 +620,26 @@ template <ScriptContext context> void ConCommand_script(const CCommand& 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 1383765

Please sign in to comment.