From f606c18e2d06ab897f87ca92ac6ea6ef8ecc645a Mon Sep 17 00:00:00 2001 From: MiranDMC Date: Thu, 2 Nov 2023 05:20:38 +0100 Subject: [PATCH] Fixes (#23) * Compilation warnings fixes * fixed global debug mode state not initialized in spawned scripts --- source/CCustomOpcodeSystem.cpp | 11 ++++------- source/CScriptEngine.cpp | 34 ++++++++++++++++++++-------------- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/source/CCustomOpcodeSystem.cpp b/source/CCustomOpcodeSystem.cpp index a41a7bea..e9449bb5 100644 --- a/source/CCustomOpcodeSystem.cpp +++ b/source/CCustomOpcodeSystem.cpp @@ -764,9 +764,6 @@ namespace CLEO std::pair GetStringParamWriteBuffer(CRunningScript* thread) { - char* targetBuff; - DWORD targetSize; - lastErrorMsg.clear(); auto paramType = CLEO_GetOperandType(thread); @@ -1278,7 +1275,7 @@ namespace CLEO cs->LogicalOp = eLogicalOperation::NONE; cs->NotFlag = false; - cs->SetScmFunction(thisScmFunctionId = allocationPlace); + cs->SetScmFunction(thisScmFunctionId = (unsigned short)allocationPlace); } void Return(CRunningScript *thread) @@ -1348,13 +1345,13 @@ namespace CLEO switch (size) { default: - GetInstance().CodeInjector.MemoryWrite(Address, value, vp, size); + GetInstance().CodeInjector.MemoryWrite(Address, (BYTE)value, vp, size); break; case 2: - GetInstance().CodeInjector.MemoryWrite(Address, value, vp); + GetInstance().CodeInjector.MemoryWrite(Address, (WORD)value, vp); break; case 4: - GetInstance().CodeInjector.MemoryWrite(Address, value, vp); + GetInstance().CodeInjector.MemoryWrite(Address, (DWORD)value, vp); break; } return OR_CONTINUE; diff --git a/source/CScriptEngine.cpp b/source/CScriptEngine.cpp index 985e1bff..cfbe5323 100644 --- a/source/CScriptEngine.cpp +++ b/source/CScriptEngine.cpp @@ -1002,25 +1002,31 @@ namespace CLEO TRACE("Searching for CLEO scripts"); - CCustomScript* cs = nullptr; - FilesWalk(scriptsDir.c_str(), cs_ext, [&](const char* fullPath, const char* filename) { - cs = LoadScript(fullPath); - }); - - FilesWalk(scriptsDir.c_str(), cs4_ext, [&](const char* fullPath, const char* filename) { - cs = LoadScript(fullPath); - if (cs) cs->SetCompatibility(CLEO_VER_4); + FilesWalk(scriptsDir.c_str(), cs_ext, [&](const char* fullPath, const char* filename) + { + if(auto cs = LoadScript(fullPath)) + { + cs->SetDebugMode(NativeScriptsDebugMode); // inherit from global state + } }); - FilesWalk(scriptsDir.c_str(), cs3_ext, [&](const char* fullPath, const char* filename) { - cs = LoadScript(fullPath); - if (cs) cs->SetCompatibility(CLEO_VER_3); + FilesWalk(scriptsDir.c_str(), cs4_ext, [&](const char* fullPath, const char* filename) + { + if (auto cs = LoadScript(fullPath)) + { + cs->SetCompatibility(CLEO_VER_4); + cs->SetDebugMode(NativeScriptsDebugMode); // inherit from global state + } }); - if (cs != nullptr) + FilesWalk(scriptsDir.c_str(), cs3_ext, [&](const char* fullPath, const char* filename) { - cs->SetDebugMode(NativeScriptsDebugMode); // inherit from global state - } + if (auto cs = LoadScript(fullPath)) + { + cs->SetCompatibility(CLEO_VER_3); + cs->SetDebugMode(NativeScriptsDebugMode); // inherit from global state + } + }); for (void* func : GetInstance().GetCallbacks(eCallbackId::ScriptsLoaded)) {