From 92309bd65e4b9bc1ddf23ee8a511f7be363aa565 Mon Sep 17 00:00:00 2001 From: PeachyPeachSM64 <72323920+PeachyPeachSM64@users.noreply.github.com> Date: Sun, 14 Dec 2025 15:03:42 +0100 Subject: [PATCH] Restrict special value to -1 (so more values could be added in the future); fix format --- src/game/mario_actions_airborne.c | 2 +- src/game/mario_actions_automatic.c | 2 +- src/game/mario_actions_cutscene.c | 2 +- src/game/mario_actions_moving.c | 2 +- src/game/mario_actions_object.c | 2 +- src/game/mario_actions_stationary.c | 2 +- src/game/mario_actions_submerged.c | 2 +- src/pc/lua/smlua_hooks.c | 9 ++++++--- src/pc/lua/smlua_hooks.h | 2 ++ 9 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/game/mario_actions_airborne.c b/src/game/mario_actions_airborne.c index 60ac72ffe..5bf71f395 100644 --- a/src/game/mario_actions_airborne.c +++ b/src/game/mario_actions_airborne.c @@ -2385,7 +2385,7 @@ s32 mario_execute_airborne_action(struct MarioState *m) { case ACT_TOP_OF_POLE_JUMP: cancel = act_top_of_pole_jump(m); break; case ACT_VERTICAL_WIND: cancel = act_vertical_wind(m); break; default: - LOG_ERROR("Attempted to execute unimplemented action '%04X'", m->action); + LOG_ERROR("Attempted to execute unimplemented action '%08X'", m->action); set_mario_action(m, ACT_FREEFALL, 0); return FALSE; } diff --git a/src/game/mario_actions_automatic.c b/src/game/mario_actions_automatic.c index bb3ea807f..7fae880c8 100644 --- a/src/game/mario_actions_automatic.c +++ b/src/game/mario_actions_automatic.c @@ -1219,7 +1219,7 @@ s32 mario_execute_automatic_action(struct MarioState *m) { case ACT_TORNADO_TWIRLING: cancel = act_tornado_twirling(m); break; case ACT_BUBBLED: cancel = act_bubbled(m); break; default: - LOG_ERROR("Attempted to execute unimplemented action '%04X'", m->action); + LOG_ERROR("Attempted to execute unimplemented action '%08X'", m->action); set_mario_action(m, ACT_IDLE, 0); return FALSE; } diff --git a/src/game/mario_actions_cutscene.c b/src/game/mario_actions_cutscene.c index 694e86352..013f20dc1 100644 --- a/src/game/mario_actions_cutscene.c +++ b/src/game/mario_actions_cutscene.c @@ -3190,7 +3190,7 @@ s32 mario_execute_cutscene_action(struct MarioState *m) { case ACT_FEET_STUCK_IN_GROUND: cancel = act_feet_stuck_in_ground(m); break; case ACT_PUTTING_ON_CAP: cancel = act_putting_on_cap(m); break; default: - LOG_ERROR("Attempted to execute unimplemented action '%04X'", m->action); + LOG_ERROR("Attempted to execute unimplemented action '%08X'", m->action); set_mario_action(m, ACT_IDLE, 0); return FALSE; } diff --git a/src/game/mario_actions_moving.c b/src/game/mario_actions_moving.c index 400d30cad..6a21d45d5 100644 --- a/src/game/mario_actions_moving.c +++ b/src/game/mario_actions_moving.c @@ -2262,7 +2262,7 @@ s32 mario_execute_moving_action(struct MarioState *m) { case ACT_HOLD_QUICKSAND_JUMP_LAND: cancel = act_hold_quicksand_jump_land(m); break; case ACT_LONG_JUMP_LAND: cancel = act_long_jump_land(m); break; default: - LOG_ERROR("Attempted to execute unimplemented action '%04X'", m->action); + LOG_ERROR("Attempted to execute unimplemented action '%08X'", m->action); set_mario_action(m, ACT_IDLE, 0); return FALSE; } diff --git a/src/game/mario_actions_object.c b/src/game/mario_actions_object.c index 3da4ac87e..02d8dbdf0 100644 --- a/src/game/mario_actions_object.c +++ b/src/game/mario_actions_object.c @@ -534,7 +534,7 @@ s32 mario_execute_object_action(struct MarioState *m) { case ACT_HOLDING_BOWSER: cancel = act_holding_bowser(m); break; case ACT_RELEASING_BOWSER: cancel = act_releasing_bowser(m); break; default: - LOG_ERROR("Attempted to execute unimplemented action '%04X'", m->action); + LOG_ERROR("Attempted to execute unimplemented action '%08X'", m->action); set_mario_action(m, ACT_IDLE, 0); return FALSE; } diff --git a/src/game/mario_actions_stationary.c b/src/game/mario_actions_stationary.c index d9df47584..3a7ae400b 100644 --- a/src/game/mario_actions_stationary.c +++ b/src/game/mario_actions_stationary.c @@ -1300,7 +1300,7 @@ s32 mario_execute_stationary_action(struct MarioState *m) { case ACT_HOLD_BUTT_SLIDE_STOP: cancel = act_hold_butt_slide_stop(m); break; case ACT_PALETTE_EDITOR_CAP: cancel = act_palette_editor_cap(m); break; default: - LOG_ERROR("Attempted to execute unimplemented action '%04X'", m->action); + LOG_ERROR("Attempted to execute unimplemented action '%08X'", m->action); set_mario_action(m, ACT_IDLE, 0); return FALSE; } diff --git a/src/game/mario_actions_submerged.c b/src/game/mario_actions_submerged.c index 08faaf044..2aa40500b 100644 --- a/src/game/mario_actions_submerged.c +++ b/src/game/mario_actions_submerged.c @@ -1710,7 +1710,7 @@ s32 mario_execute_submerged_action(struct MarioState *m) { case ACT_HOLD_METAL_WATER_JUMP: cancel = act_hold_metal_water_jump(m); break; case ACT_HOLD_METAL_WATER_JUMP_LAND: cancel = act_hold_metal_water_jump_land(m); break; default: - LOG_ERROR("Attempted to execute unimplemented action '%04X'", m->action); + LOG_ERROR("Attempted to execute unimplemented action '%08X'", m->action); set_mario_action(m, ACT_WATER_IDLE, 0); return FALSE; } diff --git a/src/pc/lua/smlua_hooks.c b/src/pc/lua/smlua_hooks.c index db87bd8f4..d487aa2ac 100644 --- a/src/pc/lua/smlua_hooks.c +++ b/src/pc/lua/smlua_hooks.c @@ -343,12 +343,13 @@ bool smlua_call_action_hook(enum LuaActionHookType hookType, struct MarioState* // call the callback if (0 != smlua_call_hook(L, 1, 1, 0, hook->mod, hook->modFile)) { - LOG_LUA("Failed to call the action callback: %u", m->action); + LOG_LUA("Failed to call the action callback: '%08X'", m->action); continue; } // output the return value - // returning a negative value allows to continue the execution, useful when overriding vanilla actions + // special return values: + // - returning -1 allows to continue the execution, useful when overriding vanilla actions bool stopActionHook = true; *cancel = FALSE; @@ -363,8 +364,10 @@ bool smlua_call_action_hook(enum LuaActionHookType hookType, struct MarioState* *cancel = TRUE; } else if (returnValue == 0) { *cancel = FALSE; - } else { + } else if (returnValue == ACTION_HOOK_CONTINUE_EXECUTION) { stopActionHook = false; + } else { + LOG_LUA("Invalid return value when calling the action callback: '%08X' returned %d", m->action, returnValue); } } break; } diff --git a/src/pc/lua/smlua_hooks.h b/src/pc/lua/smlua_hooks.h index 6e1c9d296..edfcc975f 100644 --- a/src/pc/lua/smlua_hooks.h +++ b/src/pc/lua/smlua_hooks.h @@ -95,6 +95,8 @@ static const char* LuaActionHookTypeArgName[] = { "max (dummy)", }; +#define ACTION_HOOK_CONTINUE_EXECUTION -1 + #define MAX_HOOKED_MOD_MENU_ELEMENTS 256 enum LuaModMenuElementType {