From dea7247d9f0bf0c65a25f7e69899cf6e16ba5dda Mon Sep 17 00:00:00 2001 From: NitroDisPro <80155758+NitroDisPro@users.noreply.github.com> Date: Wed, 28 May 2025 18:13:46 -0400 Subject: [PATCH] Add HOOK_MARIO_OVERRIDE_FLOOR_CLASS (#812) * Update lua_definitions constants.lua * you kiddin' dude * Update lua docs constants.md * Update smlua_constants_autogen.c * Update smlua_hooks.h * Update mario.c to add HOOK_MARIO_OVERRIDE_FLOOR_CLASS to mario_get_floor_class(m) yeah i sure love using web interface * Update lua guide hooks.md * Whoops --- autogen/lua_definitions/constants.lua | 4 +++- docs/lua/constants.md | 3 ++- docs/lua/guides/hooks.md | 1 + src/game/mario.c | 3 +++ src/pc/lua/smlua_constants_autogen.c | 5 +++-- src/pc/lua/smlua_hooks.h | 2 ++ 6 files changed, 14 insertions(+), 4 deletions(-) diff --git a/autogen/lua_definitions/constants.lua b/autogen/lua_definitions/constants.lua index 5c3fb854e..a468c8e96 100644 --- a/autogen/lua_definitions/constants.lua +++ b/autogen/lua_definitions/constants.lua @@ -7667,7 +7667,8 @@ HOOK_ON_INTERACTIONS = 52 --- @type LuaHookedEventType HOOK_ALLOW_FORCE_WATER_ACTION = 53 --- @type LuaHookedEventType HOOK_BEFORE_WARP = 54 --- @type LuaHookedEventType HOOK_ON_INSTANT_WARP = 55 --- @type LuaHookedEventType -HOOK_MAX = 56 --- @type LuaHookedEventType +HOOK_MARIO_OVERRIDE_FLOOR_CLASS = 56 --- @type LuaHookedEventType +HOOK_MAX = 57 --- @type LuaHookedEventType --- @alias LuaHookedEventType --- | `HOOK_UPDATE` @@ -7726,6 +7727,7 @@ HOOK_MAX = 56 --- @type LuaHookedEventType --- | `HOOK_ALLOW_FORCE_WATER_ACTION` --- | `HOOK_BEFORE_WARP` --- | `HOOK_ON_INSTANT_WARP` +--- | `HOOK_MARIO_OVERRIDE_FLOOR_CLASS` --- | `HOOK_MAX` ACTION_HOOK_EVERY_FRAME = 0 --- @type LuaActionHookType diff --git a/docs/lua/constants.md b/docs/lua/constants.md index 210a2cb81..aa8f03e3c 100644 --- a/docs/lua/constants.md +++ b/docs/lua/constants.md @@ -3438,7 +3438,8 @@ | HOOK_ALLOW_FORCE_WATER_ACTION | 53 | | HOOK_BEFORE_WARP | 54 | | HOOK_ON_INSTANT_WARP | 55 | -| HOOK_MAX | 56 | +| HOOK_MARIO_OVERRIDE_FLOOR_CLASS | 56 | +| HOOK_MAX | 57 | ### [enum LuaActionHookType](#LuaActionHookType) | Identifier | Value | diff --git a/docs/lua/guides/hooks.md b/docs/lua/guides/hooks.md index 79474a1c5..50a3d28e9 100644 --- a/docs/lua/guides/hooks.md +++ b/docs/lua/guides/hooks.md @@ -148,6 +148,7 @@ The lua functions sent to `hook_event()` will be automatically called by SM64 wh | HOOK_ALLOW_FORCE_WATER_ACTION | Called when executing a non-water action while under the water's surface, or vice versa. Return `false` to prevent the player from being forced out of the action at the water's surface | [MarioState](../structs.md#MarioState) mario, `boolean` isInWaterAction | | HOOK_BEFORE_WARP | Called before the local player warps. Return a table with `destLevel`, `destArea`, `destWarpNode`, to override the warp | `integer` destLevel, `integer` destArea, `integer` destWarpNode, `integer` arg | | HOOK_ON_INSTANT_WARP | Called when the local player goes through an instant warp.| `integer` area, `integer` id, `Vec3s` displacement| +| HOOK_MARIO_OVERRIDE_FLOOR_CLASS | Called when Mario's floor class logic updates, return a `SURFACE_CLASS_*` constant to override the type. | [MarioState](../structs.md#MarioState) mario, `integer` surfaceClass | ### Parameters diff --git a/src/game/mario.c b/src/game/mario.c index c9908398c..c2dcb9a73 100644 --- a/src/game/mario.c +++ b/src/game/mario.c @@ -524,6 +524,9 @@ s32 mario_get_floor_class(struct MarioState *m) { floorClass = SURFACE_CLASS_NOT_SLIPPERY; } + s32 returnValue = 0; + if (smlua_call_event_hooks_mario_param_and_int_ret_int(HOOK_MARIO_OVERRIDE_FLOOR_CLASS, m, floorClass, &returnValue)) return returnValue; + return floorClass; } diff --git a/src/pc/lua/smlua_constants_autogen.c b/src/pc/lua/smlua_constants_autogen.c index 06debcbac..e287922f0 100644 --- a/src/pc/lua/smlua_constants_autogen.c +++ b/src/pc/lua/smlua_constants_autogen.c @@ -3158,7 +3158,8 @@ char gSmluaConstants[] = "" "HOOK_ALLOW_FORCE_WATER_ACTION=53\n" "HOOK_BEFORE_WARP=54\n" "HOOK_ON_INSTANT_WARP=55\n" -"HOOK_MAX=56\n" +"HOOK_MARIO_OVERRIDE_FLOOR_CLASS=56\n" +"HOOK_MAX=57\n" "ACTION_HOOK_EVERY_FRAME=0\n" "ACTION_HOOK_GRAVITY=1\n" "ACTION_HOOK_MAX=2\n" @@ -4294,4 +4295,4 @@ char gSmluaConstants[] = "" "VERSION_NUMBER=40\n" "MINOR_VERSION_NUMBER=2\n" "MAX_VERSION_LENGTH=128\n" -; \ No newline at end of file +; diff --git a/src/pc/lua/smlua_hooks.h b/src/pc/lua/smlua_hooks.h index 060cce741..eb18b5242 100644 --- a/src/pc/lua/smlua_hooks.h +++ b/src/pc/lua/smlua_hooks.h @@ -68,6 +68,7 @@ enum LuaHookedEventType { HOOK_ALLOW_FORCE_WATER_ACTION, HOOK_BEFORE_WARP, HOOK_ON_INSTANT_WARP, + HOOK_MARIO_OVERRIDE_FLOOR_CLASS, HOOK_MAX, }; @@ -128,6 +129,7 @@ static const char* LuaHookedEventTypeName[] = { "HOOK_ALLOW_FORCE_WATER_ACTION", "HOOK_BEFORE_WARP", "HOOK_ON_INSTANT_WARP", + "HOOK_MARIO_OVERRIDE_FLOOR_CLASS", "HOOK_MAX" };