From 68aaad2c7975ab8d7ccccfde25ee2dd80d833fe0 Mon Sep 17 00:00:00 2001 From: Miran Date: Sat, 28 Dec 2024 12:26:37 +0100 Subject: [PATCH 1/5] Fix CLEO modules path --- source/CScriptEngine.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/CScriptEngine.cpp b/source/CScriptEngine.cpp index d5c46c89..9a64590c 100644 --- a/source/CScriptEngine.cpp +++ b/source/CScriptEngine.cpp @@ -706,7 +706,7 @@ namespace CLEO case VPref::Script: resolved = GetScriptFileDir(); break; case VPref::Game: resolved = Filepath_Game; break; case VPref::Cleo: resolved = Filepath_Cleo; break; - case VPref::Modules: resolved = Filepath_Cleo + "\\modules"; break; + case VPref::Modules: resolved = Filepath_Cleo + "\\cleo_modules"; break; default : resolved = ""; break; // should never happen } From 3afcc1e0616932bb84ca7550e72b93ac272ea1a2 Mon Sep 17 00:00:00 2001 From: Miran Date: Sat, 28 Dec 2024 19:34:38 +0100 Subject: [PATCH 2/5] Fixes and refactoring of legacy CLEO support. Added legacy option for native scripts to config.ini --- source/CCustomOpcodeSystem.cpp | 23 ++++++++++------------- source/CScriptEngine.cpp | 32 +++++++++++++++++++++----------- source/CScriptEngine.h | 1 + source/cleo_config.ini | 5 ++++- 4 files changed, 36 insertions(+), 25 deletions(-) diff --git a/source/CCustomOpcodeSystem.cpp b/source/CCustomOpcodeSystem.cpp index 69197846..cb1fa933 100644 --- a/source/CCustomOpcodeSystem.cpp +++ b/source/CCustomOpcodeSystem.cpp @@ -892,9 +892,6 @@ namespace CLEO SetScriptCondResult(thread, cs && cs->IsOK()); if (cs && cs->IsOK()) { - auto csscript = reinterpret_cast(thread); - if (csscript->IsCustom()) - cs->SetCompatibility(csscript->GetCompatibility()); CleoInstance.ScriptEngine.AddCustomScript(cs); memset(missionLocals, 0, 1024 * sizeof(SCRIPT_VAR)); // same as CTheScripts::WipeLocalVariableMemoryForMissionScript TransmitScriptParams(thread, (CRunningScript*)((BYTE*)missionLocals - 0x3C)); @@ -939,9 +936,13 @@ namespace CLEO //0AA9=0, is_game_version_original OpcodeResult __stdcall opcode_0AA9(CRunningScript *thread) { - auto gv = CleoInstance.VersionManager.GetGameVersion(); - auto cs = (CCustomScript*)thread; - SetScriptCondResult(thread, gv == GV_US10 || (cs->IsCustom() && cs->GetCompatibility() <= CLEO_VER_4_MIN && gv == GV_EU10)); + auto gameVer = CleoInstance.VersionManager.GetGameVersion(); + auto scriptVer = CLEO_GetScriptVersion(thread); + + bool result = (gameVer == GV_US10) || + (scriptVer <= CLEO_VER_4_MIN && gameVer == GV_EU10); + + OPCODE_CONDITION_RESULT(result); return OR_CONTINUE; } @@ -1088,12 +1089,12 @@ namespace CLEO memcpy(locals, arguments, nParams * sizeof(SCRIPT_VAR)); // initialize rest of new scope local variables - auto cs = reinterpret_cast(thread); - if (cs->IsCustom() && cs->GetCompatibility() >= CLEO_VER_4_MIN) // CLEO 3 did not initialised local variables + auto scriptVer = CLEO_GetScriptVersion(thread); + if (scriptVer >= CLEO_VER_4_MIN) // CLEO 3 did not initialised local variables { for (DWORD i = nParams; i < 32; i++) { - cs->SetIntVar(i, 0); // fill with zeros + thread->SetIntVar(i, 0); // fill with zeros } } @@ -1859,10 +1860,6 @@ extern "C" { CleoInstance.ScriptEngine.AddCustomScript(cs); if (fromThread) TransmitScriptParams(fromThread, cs); - - cs->SetDebugMode(fromThread ? - reinterpret_cast(fromThread)->GetDebugMode() : // from parent - CleoInstance.ScriptEngine.NativeScriptsDebugMode); // global } else { diff --git a/source/CScriptEngine.cpp b/source/CScriptEngine.cpp index 9a64590c..0ae39e0f 100644 --- a/source/CScriptEngine.cpp +++ b/source/CScriptEngine.cpp @@ -265,7 +265,7 @@ namespace CLEO if (thread->IsCustom()) return reinterpret_cast(thread)->GetCompatibility(); else - return CLEO::eCLEO_Version::CLEO_VER_CUR; + return CleoInstance.ScriptEngine.NativeScriptsVersion; } LPCSTR WINAPI CLEO_GetScriptFilename(const CRunningScript* thread) @@ -937,6 +937,16 @@ namespace CLEO } NativeScriptsDebugMode = GetPrivateProfileInt("General", "DebugMode", 0, Filepath_Config.c_str()) != 0; + + int ver = GetPrivateProfileInt("General", "MainScmLegacyMode", 0, Filepath_Config.c_str()); + switch(ver) + { + case 3: NativeScriptsVersion = eCLEO_Version::CLEO_VER_3; break; + case 4: NativeScriptsVersion = eCLEO_Version::CLEO_VER_4; break; + case 5: NativeScriptsVersion = eCLEO_Version::CLEO_VER_5; break; + default: NativeScriptsVersion = eCLEO_Version::CLEO_VER_CUR; break; + } + MainScriptCurWorkDir = Filepath_Game; CleoInstance.ModuleSystem.LoadCleoModules(); @@ -1537,13 +1547,13 @@ namespace CLEO if (path.extension() == cs4_ext) CompatVer = CLEO_VER_4; else - if (path.extension() == cs3_ext) - CompatVer = CLEO_VER_3; + if (path.extension() == cs3_ext) + CompatVer = CLEO_VER_3; - if (CompatVer == CLEO_VER_CUR && parent != nullptr && parent - IsCustom()) + if (CompatVer == CLEO_VER_CUR && parent != nullptr) { // inherit compatibility mode from parent - CompatVer = ((CCustomScript*)parent)->GetCompatibility(); + CompatVer = CLEO_GetScriptVersion(parent); // try loading file with same compatibility mode filetype extension auto compatPath = path; @@ -1554,12 +1564,12 @@ namespace CLEO path = compatPath; } else - if (CompatVer == CLEO_VER_3) - { - compatPath.replace_extension(cs3_ext); - if (FS::is_regular_file(compatPath)) - path = compatPath; - } + if (CompatVer == CLEO_VER_3) + { + compatPath.replace_extension(cs3_ext); + if (FS::is_regular_file(compatPath)) + path = compatPath; + } } scriptFileDir = path.parent_path().string(); diff --git a/source/CScriptEngine.h b/source/CScriptEngine.h index 6197ef4e..2d1e0660 100644 --- a/source/CScriptEngine.h +++ b/source/CScriptEngine.h @@ -115,6 +115,7 @@ namespace CLEO CCustomScript *LoadScript(const char *szFilePath); bool NativeScriptsDebugMode; // debug mode enabled? + CLEO::eCLEO_Version NativeScriptsVersion; // allows using legacy modes std::string MainScriptFileDir; std::string MainScriptFileName; std::string MainScriptCurWorkDir; diff --git a/source/cleo_config.ini b/source/cleo_config.ini index 2253e7a7..3aa8501b 100644 --- a/source/cleo_config.ini +++ b/source/cleo_config.ini @@ -1,3 +1,6 @@ [General] -; debug opcodes, on screen prints etc.: 0 - off, 1 - enabled +; default debug mode state for all scripts (see opcode debug_on/debug_off): 0 - off, 1 - enabled DebugMode=0 + +; legacy mode for main script(s): 0 - off, 3 - CLEO3, 4 - CLEO4 +MainScmLegacyMode=0 From 588b3ab4ce4641fe408724e1691457c084a0e60b Mon Sep 17 00:00:00 2001 From: Miran Date: Sat, 28 Dec 2024 19:44:10 +0100 Subject: [PATCH 3/5] fixup! Fixes and refactoring of legacy CLEO support. --- source/CCustomOpcodeSystem.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/source/CCustomOpcodeSystem.cpp b/source/CCustomOpcodeSystem.cpp index cb1fa933..af8406f6 100644 --- a/source/CCustomOpcodeSystem.cpp +++ b/source/CCustomOpcodeSystem.cpp @@ -1088,9 +1088,8 @@ namespace CLEO // pass arguments as new scope local variables memcpy(locals, arguments, nParams * sizeof(SCRIPT_VAR)); - // initialize rest of new scope local variables - auto scriptVer = CLEO_GetScriptVersion(thread); - if (scriptVer >= CLEO_VER_4_MIN) // CLEO 3 did not initialised local variables + // initialize (clear) rest of new scope local variables + if (CLEO_GetScriptVersion(thread) >= CLEO_VER_4_MIN) // CLEO 3 did not cleared local variables { for (DWORD i = nParams; i < 32; i++) { From 2bd597c188dde86a4afde30b26b7ced5bcac8043 Mon Sep 17 00:00:00 2001 From: Miran Date: Sat, 28 Dec 2024 19:47:50 +0100 Subject: [PATCH 4/5] fixup! Fixes and refactoring of legacy CLEO support. --- source/CScriptEngine.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/CScriptEngine.cpp b/source/CScriptEngine.cpp index 0ae39e0f..c6a1d437 100644 --- a/source/CScriptEngine.cpp +++ b/source/CScriptEngine.cpp @@ -706,7 +706,7 @@ namespace CLEO case VPref::Script: resolved = GetScriptFileDir(); break; case VPref::Game: resolved = Filepath_Game; break; case VPref::Cleo: resolved = Filepath_Cleo; break; - case VPref::Modules: resolved = Filepath_Cleo + "\\cleo_modules"; break; + case VPref::Modules: resolved = Filepath_Cleo + "\\modules"; break; default : resolved = ""; break; // should never happen } From 79c1dae8b0009216b9529e4bca622efc869d57bc Mon Sep 17 00:00:00 2001 From: Miran Date: Sat, 28 Dec 2024 22:40:25 +0100 Subject: [PATCH 5/5] fixup! Fixes and refactoring of legacy CLEO support. --- cleo_plugins/Text/CTextManager.cpp | 2 ++ source/CScriptEngine.cpp | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/cleo_plugins/Text/CTextManager.cpp b/cleo_plugins/Text/CTextManager.cpp index be39e23d..41128c7a 100644 --- a/cleo_plugins/Text/CTextManager.cpp +++ b/cleo_plugins/Text/CTextManager.cpp @@ -115,6 +115,8 @@ namespace CLEO } } CLEO::CLEO_StringListFree(list); + + TRACE(""); // separator } void CTextManager::Clear() diff --git a/source/CScriptEngine.cpp b/source/CScriptEngine.cpp index c6a1d437..0b40f7fc 100644 --- a/source/CScriptEngine.cpp +++ b/source/CScriptEngine.cpp @@ -938,14 +938,18 @@ namespace CLEO NativeScriptsDebugMode = GetPrivateProfileInt("General", "DebugMode", 0, Filepath_Config.c_str()) != 0; + // global native scripts legacy mode int ver = GetPrivateProfileInt("General", "MainScmLegacyMode", 0, Filepath_Config.c_str()); switch(ver) { case 3: NativeScriptsVersion = eCLEO_Version::CLEO_VER_3; break; case 4: NativeScriptsVersion = eCLEO_Version::CLEO_VER_4; break; - case 5: NativeScriptsVersion = eCLEO_Version::CLEO_VER_5; break; - default: NativeScriptsVersion = eCLEO_Version::CLEO_VER_CUR; break; + default: + NativeScriptsVersion = eCLEO_Version::CLEO_VER_CUR; + ver = 0; + break; } + if (ver != 0) TRACE("Legacy mode for native scripts active: CLEO%d", ver); MainScriptCurWorkDir = Filepath_Game;