diff --git a/cleo_plugins/MemoryOperations/MemoryOperations.cpp b/cleo_plugins/MemoryOperations/MemoryOperations.cpp index 4c57558e..2fd5dfd2 100644 --- a/cleo_plugins/MemoryOperations/MemoryOperations.cpp +++ b/cleo_plugins/MemoryOperations/MemoryOperations.cpp @@ -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(numArg, inputArgCount); i++) { auto& param = arguments[i]; @@ -128,7 +128,7 @@ class MemoryOperations // read result from 0@ */ param.pParam = CLEO_GetPointerToScriptVariable(thread); - } + } else { if (currTextParam >= Max_Text_Params) @@ -155,6 +155,8 @@ class MemoryOperations } } + SCRIPT_VAR* arguments_end = arguments + numArg; + numPop *= 4; // bytes peer argument DWORD result; _asm {