From 539c2df378040513f31a0dbce6e5d4755ec204fb Mon Sep 17 00:00:00 2001 From: smallmodel <15067410+smallmodel@users.noreply.github.com> Date: Thu, 16 Jan 2025 23:25:26 +0100 Subject: [PATCH] Check for valid event on listener and print an error if the command cannot be executed --- code/script/scriptvm.cpp | 17 +++++++++++++++++ code/script/scriptvm.h | 1 + 2 files changed, 18 insertions(+) diff --git a/code/script/scriptvm.cpp b/code/script/scriptvm.cpp index 3e70d985..cc48908f 100644 --- a/code/script/scriptvm.cpp +++ b/code/script/scriptvm.cpp @@ -541,6 +541,8 @@ void ScriptVM::executeCommandInternal( ) { transferVarsToEvent(ev, fromVar, iParamCount); + checkValidEvent(ev, listener); + listener->ProcessScriptEvent(ev); } @@ -550,6 +552,7 @@ void ScriptVM::executeCommandInternal( ) { transferVarsToEvent(ev, fromVar, iParamCount); + checkValidEvent(ev, listener); try { listener->ProcessScriptEvent(ev); @@ -595,6 +598,20 @@ void ScriptVM::transferVarsToEvent(Event& ev, ScriptVariable *fromVar, op_parmNu ev.CopyValues(fromVar, count); } +void ScriptVM::checkValidEvent(Event& ev, Listener* listener) { + ClassDef *c = listener->classinfo(); + + if (!c->GetDef(&ev)) { + if (listener == m_Thread) { + ScriptError("Failed execution of command '%s'", ev.getName()); + } else if (listener->isSubclassOf(SimpleEntity)) { + ScriptError("Failed execution of command '%s' for class '%s' Targetname '%s'", ev.getName(), c->classname, static_cast(listener)->targetname.c_str()); + } else { + ScriptError("Failed execution of command '%s' for class '%s'", ev.getName(), c->classname); + } + } +} + bool ScriptVM::executeGetter(Listener *listener, op_evName_t eventName) { int eventNum = Event::FindGetterEventNum(eventName); diff --git a/code/script/scriptvm.h b/code/script/scriptvm.h index 7f4b0e6c..ece0af2f 100644 --- a/code/script/scriptvm.h +++ b/code/script/scriptvm.h @@ -177,6 +177,7 @@ private: bool executeGetter(Listener *listener, op_evName_t eventName); bool executeSetter(Listener *listener, op_evName_t eventName); void transferVarsToEvent(Event& ev, ScriptVariable *fromVar, op_parmNum_t count); + void checkValidEvent(Event& ev, Listener *listener); void loadTopInternal(Listener *listener); ScriptVariable *storeTopInternal(Listener *listener);