Touch up new hooks

This commit is contained in:
Agent X 2023-02-28 22:39:16 -05:00
parent c22c03a823
commit 32c5eab54f
4 changed files with 15 additions and 9 deletions

View File

@ -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;
}

View File

@ -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) {

View File

@ -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;
}

View File

@ -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);