From 4af8af677fa21d4261ae398d652ff7e47420a0a7 Mon Sep 17 00:00:00 2001 From: Agent X <44549182+Agent-11@users.noreply.github.com> Date: Tue, 28 Feb 2023 22:39:16 -0500 Subject: [PATCH] Touch up new hooks --- src/game/characters.c | 2 +- src/game/mario.c | 2 +- src/pc/lua/smlua_hooks.c | 16 +++++++++++----- src/pc/lua/smlua_hooks.h | 4 ++-- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/game/characters.c b/src/game/characters.c index 841a3170..b6a53cac 100644 --- a/src/game/characters.c +++ b/src/game/characters.c @@ -458,7 +458,7 @@ static s32 get_character_sound(struct MarioState* m, enum CharacterSound charact if (m == NULL || m->marioObj == NULL) { return 0; } s32 override = 0; - if (smlua_call_event_hooks_mario_charactersound_param_ret_int(HOOK_CHARACTER_SOUND, m, characterSound, &override)) { + if (smlua_call_event_hooks_mario_character_sound_param_ret_int(HOOK_CHARACTER_SOUND, m, characterSound, &override)) { return override; } diff --git a/src/game/mario.c b/src/game/mario.c index 33915df7..fce737d5 100644 --- a/src/game/mario.c +++ b/src/game/mario.c @@ -1094,7 +1094,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) { u32 returnValue = 0; - smlua_call_event_hooks_int_param_ret_int(HOOK_BEFORE_SET_MARIO_ACTION, action, &returnValue); + smlua_call_event_hooks_mario_action_params_ret_int(HOOK_BEFORE_SET_MARIO_ACTION, m, action, &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 62dc571f..a880cf62 100644 --- a/src/pc/lua/smlua_hooks.c +++ b/src/pc/lua/smlua_hooks.c @@ -639,7 +639,7 @@ void smlua_call_event_hooks_on_chat_message(enum LuaHookedEventType hookType, st } } -bool smlua_call_event_hooks_mario_charactersound_param_ret_int(enum LuaHookedEventType hookType, struct MarioState* m, enum CharacterSound characterSound, s32* returnValue) { +bool smlua_call_event_hooks_mario_character_sound_param_ret_int(enum LuaHookedEventType hookType, struct MarioState* m, enum CharacterSound characterSound, s32* returnValue) { lua_State* L = gLuaState; if (L == NULL) { return false; } struct LuaHookedEvent* hook = &sHookedEvents[hookType]; @@ -676,7 +676,7 @@ bool smlua_call_event_hooks_mario_charactersound_param_ret_int(enum LuaHookedEve return false; } -void smlua_call_event_hooks_int_param_ret_int(enum LuaHookedEventType hookType, u32 param, u32* returnValue) { +void smlua_call_event_hooks_mario_action_params_ret_int(enum LuaHookedEventType hookType, struct MarioState *m, u32 action, u32* returnValue) { lua_State* L = gLuaState; if (L == NULL) { return; } struct LuaHookedEvent* hook = &sHookedEvents[hookType]; @@ -686,11 +686,17 @@ void smlua_call_event_hooks_int_param_ret_int(enum LuaHookedEventType hookType, // push the callback onto the stack lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); - // push params - lua_pushinteger(L, param); + // push mario state + lua_getglobal(L, "gMarioStates"); + lua_pushinteger(L, m->playerIndex); + lua_gettable(L, -2); + lua_remove(L, -2); + + // push action + lua_pushinteger(L, action); // call the callback - if (0 != smlua_call_hook(L, 1, 1, 0, hook->mod[i])) { + if (0 != smlua_call_hook(L, 2, 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 f522d867..af3d42f4 100644 --- a/src/pc/lua/smlua_hooks.h +++ b/src/pc/lua/smlua_hooks.h @@ -114,8 +114,8 @@ void smlua_call_event_hooks_value_param(enum LuaHookedEventType hookType, int mo void smlua_call_event_hooks_use_act_select(enum LuaHookedEventType hookType, int value, bool* foundHook, bool* returnValue); 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_charactersound_param_ret_int(enum LuaHookedEventType hookType, struct MarioState* m, enum CharacterSound characterSound, s32* returnValue); -void smlua_call_event_hooks_int_param_ret_int(enum LuaHookedEventType hookType, u32 param, u32* 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); enum BehaviorId smlua_get_original_behavior_id(const BehaviorScript* behavior); const BehaviorScript* smlua_override_behavior(const BehaviorScript* behavior);