From 6aeb73751a8b018318cc8408e1aaa0a470cbcd92 Mon Sep 17 00:00:00 2001 From: MiranDMC Date: Fri, 2 Aug 2024 04:39:07 +0200 Subject: [PATCH] =?UTF-8?q?Standardized=20warning=20messages=20of=20termin?= =?UTF-8?q?ate=5Fthis=5Fscript=20and=20terminate=5F=E2=80=A6=20(#174)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/CCustomOpcodeSystem.cpp | 8 ++++---- source/CScriptEngine.cpp | 25 ++++++++----------------- source/CScriptEngine.h | 4 +++- 3 files changed, 15 insertions(+), 22 deletions(-) diff --git a/source/CCustomOpcodeSystem.cpp b/source/CCustomOpcodeSystem.cpp index b6d899db..3c3566b7 100644 --- a/source/CCustomOpcodeSystem.cpp +++ b/source/CCustomOpcodeSystem.cpp @@ -863,11 +863,11 @@ namespace CLEO CCustomScript *cs = reinterpret_cast(thread); if (thread->IsMission() || !cs->IsCustom()) { - LOG_WARNING(0, "Incorrect usage of opcode [0A93] in script %s", ((CCustomScript*)thread)->GetInfoStr().c_str()); - - return OR_CONTINUE; + LOG_WARNING(0, "Incorrect usage of opcode [0A93] in script %s. Use [004E] instead.", ((CCustomScript*)thread)->GetInfoStr().c_str()); + return OR_CONTINUE; // legacy behavior } - GetInstance().ScriptEngine.RemoveCustomScript(cs); + + GetInstance().ScriptEngine.RemoveScript(thread); return OR_INTERRUPT; } diff --git a/source/CScriptEngine.cpp b/source/CScriptEngine.cpp index 53e8d602..cae3f7b8 100644 --- a/source/CScriptEngine.cpp +++ b/source/CScriptEngine.cpp @@ -313,16 +313,6 @@ namespace CLEO extern "C" void __stdcall opcode_004E(CCustomScript *pScript) // terminate_this_script { - if (pScript->IsCustom()) - { - if (pScript->IsMission()) - *MissionLoaded = false; - else - { - TRACE("Incorrect usage of opcode [004E] in script %s.", pScript->GetName().c_str()); - } - } - GetInstance().ScriptEngine.RemoveScript(pScript); } @@ -1369,17 +1359,18 @@ namespace CLEO void CScriptEngine::RemoveScript(CRunningScript* thread) { - if (!thread->IsCustom()) + if (thread->IsMission()) *MissionLoaded = false; + + if (thread->IsCustom()) + { + RemoveCustomScript((CCustomScript*)thread); + } + else // native script { - if (thread->IsMission()) *MissionLoaded = false; RemoveScriptFromQueue(thread, activeThreadQueue); AddScriptToQueue(thread, inactiveThreadQueue); StopScript(thread); } - else - { - RemoveCustomScript((CCustomScript*)thread); - } } void CScriptEngine::RemoveCustomScript(CCustomScript *cs) @@ -1397,7 +1388,7 @@ namespace CLEO } for (auto childThread : cs->childThreads) { - CScriptEngine::RemoveCustomScript(childThread); + CScriptEngine::RemoveScript(childThread); } if (cs == CustomMission) { diff --git a/source/CScriptEngine.h b/source/CScriptEngine.h index 636bf925..6197ef4e 100644 --- a/source/CScriptEngine.h +++ b/source/CScriptEngine.h @@ -142,7 +142,6 @@ namespace CLEO bool IsValidScriptPtr(const CRunningScript*) const; // leads to any script? (regular or custom) void AddCustomScript(CCustomScript*); void RemoveScript(CRunningScript*); // native or custom - void RemoveCustomScript(CCustomScript*); void RemoveAllCustomScripts(); void UnregisterAllScripts(); void ReregisterAllScripts(); @@ -151,6 +150,9 @@ namespace CLEO inline CCustomScript* GetCustomMission() { return CustomMission; } inline size_t WorkingScriptsCount() { return CustomScripts.size(); } + + private: + void RemoveCustomScript(CCustomScript*); }; extern void(__thiscall * AddScriptToQueue)(CRunningScript *, CRunningScript **queue);