From 3ad668e37aa03c1c6705962bb12b879a809c0824 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Fri, 22 Apr 2022 02:27:35 +0200 Subject: [PATCH] Fix script command Fixed problem where in certain cases input doesn't get compiled at all. Fixed problem where quote marks don't get passed correctly to the execute wrapper function. problems: passing non-string object as reference to constructor. using CCommand::Arg(index) seems to 'strip' quote marks from the actual buffer. --- r5dev/squirrel/sqtype.h | 8 ++++---- r5dev/squirrel/sqvm.cpp | 8 +------- r5dev/vstdlib/completion.cpp | 21 +++------------------ 3 files changed, 8 insertions(+), 29 deletions(-) diff --git a/r5dev/squirrel/sqtype.h b/r5dev/squirrel/sqtype.h index e3827d2c..2681ce9e 100644 --- a/r5dev/squirrel/sqtype.h +++ b/r5dev/squirrel/sqtype.h @@ -33,11 +33,11 @@ struct SQBufState const SQChar* bufTail; const SQChar* bufCopy; - SQBufState(const std::string& code) + SQBufState(const SQChar* code) { - buf = code.c_str(); - bufTail = code.c_str() + code.size(); - bufCopy = code.c_str(); + buf = code; + bufTail = code + strlen(code); + bufCopy = code; } }; diff --git a/r5dev/squirrel/sqvm.cpp b/r5dev/squirrel/sqvm.cpp index 21d0c9f7..a656931c 100644 --- a/r5dev/squirrel/sqvm.cpp +++ b/r5dev/squirrel/sqvm.cpp @@ -451,17 +451,11 @@ void SQVM_Execute(const SQChar* code, SQCONTEXT context) HSQUIRRELVM v = SQVM_GetVM(context); if (!v) { - Error(eDLL_T::ENGINE, "Attempted to execute %s script while VM isn't initialized\n", SQVM_GetContextName(context)); + Error(eDLL_T::ENGINE, "Attempted to run %s script while VM isn't initialized\n", SQVM_GetContextName(context)); return; } SQVM* vTable = v->GetVTable(); - if (!vTable) - { - Error(eDLL_T::ENGINE, "Attempted to execute %s script while VM isn't initialized\n", SQVM_GetContextName(context)); - return; - } - SQRESULT compileResult{}; SQBufState bufState = SQBufState(code); diff --git a/r5dev/vstdlib/completion.cpp b/r5dev/vstdlib/completion.cpp index 541544c7..81039b50 100644 --- a/r5dev/vstdlib/completion.cpp +++ b/r5dev/vstdlib/completion.cpp @@ -801,12 +801,7 @@ void _SQVM_ServerScript_f_CompletionFunc(const CCommand& args) { if (args.ArgC() >= 2) { - string svBuf; - for (int i = 1; i < args.ArgC(); i++) - { - svBuf.append(args.Arg(i)); - } - SQVM_Execute(svBuf.c_str(), SQCONTEXT::SERVER); + SQVM_Execute(args.ArgS(), SQCONTEXT::SERVER); } } @@ -823,12 +818,7 @@ void _SQVM_ClientScript_f_CompletionFunc(const CCommand& args) { if (args.ArgC() >= 2) { - string svBuf; - for (int i = 1; i < args.ArgC(); i++) - { - svBuf.append(args.Arg(i)); - } - SQVM_Execute(svBuf.c_str(), SQCONTEXT::CLIENT); + SQVM_Execute(args.ArgS(), SQCONTEXT::CLIENT); } } @@ -844,12 +834,7 @@ void _SQVM_UIScript_f_CompletionFunc(const CCommand& args) { if (args.ArgC() >= 2) { - string svBuf; - for (int i = 1; i < args.ArgC(); i++) - { - svBuf.append(args.Arg(i)); - } - SQVM_Execute(svBuf.c_str(), SQCONTEXT::UI); + SQVM_Execute(args.ArgS(), SQCONTEXT::UI); } }