Skip to content

Commit

Permalink
Allowed argument count missmatch in call function opcodes in legacy m…
Browse files Browse the repository at this point in the history
…ode.
  • Loading branch information
MiranDMC committed Jul 21, 2024
1 parent 733598c commit b0097b6
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions cleo_plugins/MemoryOperations/MemoryOperations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,32 +85,32 @@ class MemoryOperations
// opcodes 0AA5 - 0AA8
static OpcodeResult CallFunctionGeneric(CLEO::CRunningScript* thread, void* func, void* obj, int numArg, int numPop, bool returnArg)
{
int nVarArg = CLEO_GetVarArgCount(thread);
if (numArg + returnArg != nVarArg) // and return argument
int inputArgCount = (int)CLEO_GetVarArgCount(thread);

constexpr size_t Max_Args = 32;
if (inputArgCount > Max_Args)
{
SHOW_ERROR("Declared %d input args, but provided %d in script %s\nScript suspended.", numArg, (int)nVarArg - returnArg, CLEO::ScriptInfoStr(thread).c_str());
SHOW_ERROR("Provided more (%d) than supported (%d) arguments in script %s\nScript suspended.", inputArgCount, Max_Args, CLEO::ScriptInfoStr(thread).c_str());
return thread->Suspend();
}

constexpr size_t Max_Args = 32;
if (nVarArg > Max_Args)
inputArgCount -= returnArg; // return slot not counted as input argument

if (numArg != inputArgCount && !IsLegacyScript(thread)) // CLEO4 ignored param count missmatch (by providing zeros for missing)
{
SHOW_ERROR("Provided more (%d) than supported (%d) arguments in script %s\nScript suspended.", nVarArg, Max_Args, CLEO::ScriptInfoStr(thread).c_str());
SHOW_ERROR("Declared %d input args, but provided %d in script %s\nScript suspended.", numArg, inputArgCount, CLEO::ScriptInfoStr(thread).c_str());
return thread->Suspend();
}

static SCRIPT_VAR arguments[Max_Args] = { 0 };
SCRIPT_VAR* arguments_end = arguments + numArg;

constexpr size_t Max_Text_Params = 5;
static char textParams[Max_Text_Params][MAX_STR_LEN];
size_t currTextParam = 0;

numPop *= 4; // bytes peer argument

// retrieve parameters
auto scriptParams = CLEO_GetOpcodeParamsArray();
for (size_t i = 0; i < (size_t)numArg; i++)
for (size_t i = 0; i < std::min<size_t>(numArg, inputArgCount); i++)
{
auto& param = arguments[i];

Expand All @@ -128,7 +128,7 @@ class MemoryOperations
// read result from 0@
*/
param.pParam = CLEO_GetPointerToScriptVariable(thread);
}
}
else
{
if (currTextParam >= Max_Text_Params)
Expand All @@ -155,6 +155,8 @@ class MemoryOperations
}
}

SCRIPT_VAR* arguments_end = arguments + numArg;
numPop *= 4; // bytes peer argument
DWORD result;
_asm
{
Expand Down

0 comments on commit b0097b6

Please sign in to comment.