Skip to content

Commit

Permalink
Fixed opcodes 0A8D, 2401, 2402 types invalid data type restrictions. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
MiranDMC authored Mar 1, 2024
1 parent 77e52a2 commit 32e59cf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
12 changes: 6 additions & 6 deletions cleo_plugins/MemoryOperations/MemoryOperations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,11 @@ class MemoryOperations
const void* source;
auto paramType = thread->PeekDataType();
bool sourceText = false;
if (IsVariable(paramType))
if (IsVariable(paramType) || IsVarString(paramType))
{
source = CLEO_GetPointerToScriptVariable(thread);
}
else if (IsImmString(paramType) || IsVarString(paramType))
else if (IsImmString(paramType))
{
static char buffer[MAX_STR_LEN];

Expand Down Expand Up @@ -286,7 +286,7 @@ class MemoryOperations
memcpy(&value, address, size);
}

OPCODE_WRITE_PARAM_UINT(value);
OPCODE_WRITE_PARAM_ANY32(value);
return OR_CONTINUE;
}

Expand Down Expand Up @@ -662,7 +662,7 @@ class MemoryOperations
{
if (size == 0)
{
OPCODE_WRITE_PARAM_INT(0);
OPCODE_WRITE_PARAM_ANY32(0);
return OR_CONTINUE; // done
}

Expand All @@ -674,7 +674,7 @@ class MemoryOperations
}
if (size > 0) memcpy(&result, (void*)(ptr + offset), size);

OPCODE_WRITE_PARAM_INT(result);
OPCODE_WRITE_PARAM_ANY32(result);
return OR_CONTINUE;
}
else if (IsVarString(resultType))
Expand Down Expand Up @@ -716,7 +716,7 @@ class MemoryOperations
size = sizeof(DWORD);
}

auto value = OPCODE_READ_PARAM_INT();
auto value = OPCODE_READ_PARAM_ANY32();
memcpy(ptr + offset, &value, size);

return OR_CONTINUE;
Expand Down
8 changes: 8 additions & 0 deletions cleo_sdk/CLEO_Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ namespace CLEO
OPCODE_READ_PARAM_INT()
OPCODE_READ_PARAM_UINT()
OPCODE_READ_PARAM_FLOAT()
OPCODE_READ_PARAM_ANY32() // get raw data of simple-type value (practically integers and floats)
OPCODE_READ_PARAM_STRING(varName) // reads param and creates const char* variable named 'varName' with pointer to null-terminated string
OPCODE_READ_PARAM_STRING_LEN(varName, maxLength) // same as above, but text length is clamped to maxLength
OPCODE_READ_PARAM_FILEPATH(varName) // reads param and creates const char* variable named 'varName' with pointer to resolved, null-terminated, filepath
Expand All @@ -51,6 +52,7 @@ namespace CLEO
OPCODE_WRITE_PARAM_INT(value)
OPCODE_WRITE_PARAM_UINT(value)
OPCODE_WRITE_PARAM_FLOAT(value)
OPCODE_WRITE_PARAM_ANY32(value) // write raw data into simple-type variable (practically integers and floats)
OPCODE_WRITE_PARAM_STRING(value)
OPCODE_WRITE_PARAM_PTR(value) // memory address
*/
Expand Down Expand Up @@ -418,6 +420,9 @@ namespace CLEO
#define OPCODE_READ_PARAM_FLOAT() _readParamFloat(thread).fParam; \
if (!IsLegacyScript(thread) && !_paramWasFloat()) { SHOW_ERROR("Input argument #%d expected to be float, got %s in script %s\nScript suspended.", CLEO_GetParamsHandledCount(), CLEO::ToKindStr(_lastParamType, _lastParamArrayType), CLEO::ScriptInfoStr(thread).c_str()); return thread->Suspend(); }

#define OPCODE_READ_PARAM_ANY32() _readParam(thread).dwParam; \
if (!_paramWasInt() && !_paramWasFloat()) { SHOW_ERROR("Input argument #%d expected to be int or float, got %s in script %s\nScript suspended.", CLEO_GetParamsHandledCount(), CLEO::ToKindStr(_lastParamType, _lastParamArrayType), CLEO::ScriptInfoStr(thread).c_str()); return thread->Suspend(); }

#define OPCODE_READ_PARAM_STRING(_varName) char _buff_##_varName[MAX_STR_LEN + 1]; const char* ##_varName = _readParamText(thread, _buff_##_varName, MAX_STR_LEN + 1); if(!_paramWasString()) { return OpcodeResult::OR_INTERRUPT; }

#define OPCODE_READ_PARAM_STRING_LEN(_varName, _maxLen) char _buff_##_varName[_maxLen + 1]; const char* ##_varName = _readParamText(thread, _buff_##_varName, _maxLen + 1); if(##_varName != nullptr) ##_varName = _buff_##_varName; if(!_paramWasString()) { return OpcodeResult::OR_INTERRUPT; }
Expand Down Expand Up @@ -474,6 +479,9 @@ namespace CLEO
#define OPCODE_WRITE_PARAM_UINT(value) _writeParam(thread, value); \
if (!_paramWasInt(true)) { SHOW_ERROR("Output argument #%d expected to be variable int, got %s in script %s\nScript suspended.", CLEO_GetParamsHandledCount(), CLEO::ToKindStr(_lastParamType, _lastParamArrayType), CLEO::ScriptInfoStr(thread).c_str()); return thread->Suspend(); }

#define OPCODE_WRITE_PARAM_ANY32(value) _writeParam(thread, value); \
if (!_paramWasInt(true) && !_paramWasFloat(true)) { SHOW_ERROR("Output argument #%d expected to be int or float variable, got %s in script %s\nScript suspended.", CLEO_GetParamsHandledCount(), CLEO::ToKindStr(_lastParamType, _lastParamArrayType), CLEO::ScriptInfoStr(thread).c_str()); return thread->Suspend(); }

#define OPCODE_WRITE_PARAM_FLOAT(value) _writeParam(thread, value); \
if (!IsLegacyScript(thread) && !_paramWasFloat(true)) { SHOW_ERROR("Output argument #%d expected to be variable float, got %s in script %s\nScript suspended.", CLEO_GetParamsHandledCount(), CLEO::ToKindStr(_lastParamType, _lastParamArrayType), CLEO::ScriptInfoStr(thread).c_str()); return thread->Suspend(); }

Expand Down

0 comments on commit 32e59cf

Please sign in to comment.