From 2c332d4db665a5eed2e558b91a09db1cea7aafe1 Mon Sep 17 00:00:00 2001 From: PeachyPeachSM64 <72323920+PeachyPeachSM64@users.noreply.github.com> Date: Sat, 13 Sep 2025 01:26:15 +0200 Subject: [PATCH] Fix HOOK_ON_DIALOG --- autogen/gen_hooks.py | 7 +++++-- src/pc/lua/smlua_hook_events_autogen.inl | 8 ++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/autogen/gen_hooks.py b/autogen/gen_hooks.py index 98aea889b..73d74769f 100644 --- a/autogen/gen_hooks.py +++ b/autogen/gen_hooks.py @@ -309,17 +309,20 @@ def main(): name=input["name"] ) + n_outputs = len(hook_event["outputs"]) generated += SMLUA_CALL_EVENT_HOOKS_CALLBACK.format( n_inputs=len(hook_event["inputs"]) - mod_index_found, - n_outputs=len(hook_event["outputs"]), + n_outputs=n_outputs, hook_type=hook_event["type"], set_hook_result=set_hook_result ) + # Note: relative indexes for return values are reversed in the Lua stack + # -1 is the last value, -2 the penultimate, ... and -N the first for i, output in enumerate(hook_event["outputs"]): generated += SMLUA_TYPES[output["type"]]["output"].format( name=output["name"], - output_index=i+1, + output_index=n_outputs - i, return_on_output_set=return_on_output_set ) diff --git a/src/pc/lua/smlua_hook_events_autogen.inl b/src/pc/lua/smlua_hook_events_autogen.inl index 84fe42ee5..eb2b7647f 100644 --- a/src/pc/lua/smlua_hook_events_autogen.inl +++ b/src/pc/lua/smlua_hook_events_autogen.inl @@ -1082,13 +1082,13 @@ bool smlua_call_event_hooks_HOOK_ON_DIALOG(s32 dialogID, bool *openDialogBox, co hookResult = true; // return openDialogBox - if (lua_type(L, -1) == LUA_TBOOLEAN) { - *openDialogBox = smlua_to_boolean(L, -1); + if (lua_type(L, -2) == LUA_TBOOLEAN) { + *openDialogBox = smlua_to_boolean(L, -2); } // return dialogTextOverride - if (lua_type(L, -2) == LUA_TSTRING) { - *dialogTextOverride = smlua_to_string(L, -2); + if (lua_type(L, -1) == LUA_TSTRING) { + *dialogTextOverride = smlua_to_string(L, -1); } lua_settop(L, prevTop);