From e30e026e3e9f219bcec1d6b3aa47ef2aba21f5d0 Mon Sep 17 00:00:00 2001 From: Baconator2558 <77943363+Baconator2558@users.noreply.github.com> Date: Fri, 16 May 2025 11:58:51 -0500 Subject: [PATCH] Add actionArg to HOOK_BEFORE_SET_MARIO_ACTION (#810) * Update mario.c * Update smlua_hooks.h * Update smlua_hooks.c * Update hooks.md --- docs/lua/guides/hooks.md | 2 +- src/game/mario.c | 2 +- src/pc/lua/smlua_hooks.c | 7 +++++-- src/pc/lua/smlua_hooks.h | 2 +- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/docs/lua/guides/hooks.md b/docs/lua/guides/hooks.md index e77e13c27..79474a1c5 100644 --- a/docs/lua/guides/hooks.md +++ b/docs/lua/guides/hooks.md @@ -123,7 +123,7 @@ The lua functions sent to `hook_event()` will be automatically called by SM64 wh | HOOK_ON_CHAT_MESSAGE | Called when a chat message gets sent. Return `false` to prevent the message from being sent | [MarioState](../structs.md#MarioState) messageSender, `string` messageSent | | HOOK_OBJECT_SET_MODEL | Called when a behavior changes models. Also runs when a behavior spawns | [Object](../structs.md#Object) obj, `integer` modelID | | HOOK_CHARACTER_SOUND | Called when mario retrieves a character sound to play, return a character sound or `0` to override it | [MarioState](../structs.md#MarioState) mario, [enum CharacterSound](../constants.md#enum-CharacterSound) characterSound | -| HOOK_BEFORE_SET_MARIO_ACTION | Called before Mario's action changes Return an action to change the incoming action or `1` to cancel the action change | [MarioState](../structs.md#MarioState) mario, `integer` incomingAction | +| HOOK_BEFORE_SET_MARIO_ACTION | Called before Mario's action changes Return an action to change the incoming action or `1` to cancel the action change | [MarioState](../structs.md#MarioState) mario, `integer` incomingAction, `integer` actionArg | | HOOK_JOINED_GAME | Called when the local player finishes the join process (if the player isn't the host) | None | | HOOK_ON_OBJECT_ANIM_UPDATE | Called when an object's animation is updated | [Object](../structs.md#Object) objNode | | HOOK_ON_DIALOG | Called when a dialog appears. Return `false` to prevent it from appearing. Return a second parameter as any string to override the text in the textbox | `integer` dialogId | diff --git a/src/game/mario.c b/src/game/mario.c index 5075b5169..c9908398c 100644 --- a/src/game/mario.c +++ b/src/game/mario.c @@ -1138,7 +1138,7 @@ static u32 set_mario_action_cutscene(struct MarioState *m, u32 action, UNUSED u3 u32 set_mario_action(struct MarioState *m, u32 action, u32 actionArg) { if (!m) { return FALSE; } u32 returnValue = 0; - smlua_call_event_hooks_mario_action_params_ret_int(HOOK_BEFORE_SET_MARIO_ACTION, m, action, &returnValue); + smlua_call_event_hooks_mario_action_and_arg_ret_int(HOOK_BEFORE_SET_MARIO_ACTION, m, action, actionArg, &returnValue); if (returnValue == 1) { return TRUE; } else if (returnValue) { action = returnValue; } switch (action & ACT_GROUP_MASK) { diff --git a/src/pc/lua/smlua_hooks.c b/src/pc/lua/smlua_hooks.c index 5ef2e9bab..6554c762c 100644 --- a/src/pc/lua/smlua_hooks.c +++ b/src/pc/lua/smlua_hooks.c @@ -968,7 +968,7 @@ bool smlua_call_event_hooks_mario_character_sound_param_ret_int(enum LuaHookedEv return false; } -void smlua_call_event_hooks_mario_action_params_ret_int(enum LuaHookedEventType hookType, struct MarioState *m, u32 action, u32* returnValue) { +void smlua_call_event_hooks_mario_action_and_arg_ret_int(enum LuaHookedEventType hookType, struct MarioState *m, u32 action, u32 arg, u32* returnValue) { lua_State* L = gLuaState; if (L == NULL) { return; } struct LuaHookedEvent* hook = &sHookedEvents[hookType]; @@ -987,8 +987,11 @@ void smlua_call_event_hooks_mario_action_params_ret_int(enum LuaHookedEventType // push action lua_pushinteger(L, action); + // push arg + lua_pushinteger(L, arg); + // call the callback - if (0 != smlua_call_hook(L, 2, 1, 0, hook->mod[i])) { + if (0 != smlua_call_hook(L, 3, 1, 0, hook->mod[i])) { LOG_LUA("Failed to call the callback: %u", hookType); continue; } diff --git a/src/pc/lua/smlua_hooks.h b/src/pc/lua/smlua_hooks.h index 18bca97b9..03b4b47f5 100644 --- a/src/pc/lua/smlua_hooks.h +++ b/src/pc/lua/smlua_hooks.h @@ -199,7 +199,7 @@ void smlua_call_event_hooks_use_act_select(enum LuaHookedEventType hookType, int void smlua_call_event_hooks_ret_bool(enum LuaHookedEventType hookType, bool* returnValue); void smlua_call_event_hooks_on_chat_message(enum LuaHookedEventType hookType, struct MarioState* m, const char* message, bool* returnValue); bool smlua_call_event_hooks_mario_character_sound_param_ret_int(enum LuaHookedEventType hookType, struct MarioState* m, enum CharacterSound characterSound, s32* returnValue); -void smlua_call_event_hooks_mario_action_params_ret_int(enum LuaHookedEventType hookType, struct MarioState *m, u32 action, u32* returnValue); +void smlua_call_event_hooks_mario_action_and_arg_ret_int(enum LuaHookedEventType hookType, struct MarioState *m, u32 action, u32 arg, u32* returnValue); void smlua_call_event_hooks_mario_param_and_int_ret_bool(enum LuaHookedEventType hookType, struct MarioState* m, s32 param, bool* returnValue); bool smlua_call_event_hooks_mario_param_and_int_ret_int(enum LuaHookedEventType hookType, struct MarioState* m, s32 param, s32* returnValue); void smlua_call_event_hooks_mario_param_and_bool_ret_bool(enum LuaHookedEventType hookType, struct MarioState* m, bool param, bool* returnValue);