diff --git a/autogen/lua_definitions/constants.lua b/autogen/lua_definitions/constants.lua index 3dbf19a26..262de37e2 100644 --- a/autogen/lua_definitions/constants.lua +++ b/autogen/lua_definitions/constants.lua @@ -3354,6 +3354,9 @@ WARP_TYPE_CHANGE_AREA = 2 --- @type integer WARP_TYPE_SAME_AREA = 3 +--- @type integer +WARP_ARG_EXIT_COURSE = -1 + --- @type integer PRESS_START_DEMO_TIMER = 800 diff --git a/docs/lua/constants.md b/docs/lua/constants.md index 2b33f2407..8350d19b3 100644 --- a/docs/lua/constants.md +++ b/docs/lua/constants.md @@ -1592,6 +1592,7 @@ - WARP_TYPE_CHANGE_LEVEL - WARP_TYPE_CHANGE_AREA - WARP_TYPE_SAME_AREA +- WARP_ARG_EXIT_COURSE - PRESS_START_DEMO_TIMER - PAINTING_WARP_INDEX_START - PAINTING_WARP_INDEX_FA diff --git a/docs/lua/guides/hooks.md b/docs/lua/guides/hooks.md index 9da9e9012..e77e13c27 100644 --- a/docs/lua/guides/hooks.md +++ b/docs/lua/guides/hooks.md @@ -146,7 +146,7 @@ The lua functions sent to `hook_event()` will be automatically called by SM64 wh | HOOK_MARIO_OVERRIDE_GEOMETRY_INPUTS | Called before running Mario's geometry input logic, return `false` to not run it. | [MarioState](../structs.md) m | | HOOK_ON_INTERACTIONS | Called when the Mario interactions are processed | [MarioState](../structs.md#MarioState) mario | | 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`, `destAreaWarpNode`, and `arg` to override the warp | `integer` destLevel, `integer` destArea, `integer` destAreaWarpNode, `integer` arg | +| 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| ### Parameters diff --git a/src/game/level_update.c b/src/game/level_update.c index 20262587f..17ff7e22a 100644 --- a/src/game/level_update.c +++ b/src/game/level_update.c @@ -747,12 +747,15 @@ s16 music_changed_through_warp(s16 arg) { /** * Set the current warp type and destination level/area/node. */ -void initiate_warp(s16 destLevel, s16 destArea, s16 destWarpNode, s32 arg) {// +void initiate_warp(s16 destLevel, s16 destArea, s16 destWarpNode, s32 arg) { smlua_call_event_hooks_before_warp(HOOK_BEFORE_WARP, &destLevel, &destArea, &destWarpNode, &arg); if (destWarpNode >= WARP_NODE_CREDITS_MIN) { sWarpDest.type = WARP_TYPE_CHANGE_LEVEL; + } else if (arg == WARP_ARG_EXIT_COURSE) { + sWarpDest.type = WARP_TYPE_CHANGE_LEVEL; + arg = 0; } else if (destLevel != gCurrLevelNum) { sWarpDest.type = WARP_TYPE_CHANGE_LEVEL; } else if (destArea != gCurrentArea->index) { @@ -919,6 +922,7 @@ s16 level_trigger_warp(struct MarioState *m, s32 warpOp) { case WARP_OP_EXIT: sSourceWarpNodeId = WARP_NODE_DEATH; sDelayedWarpTimer = 20; + sDelayedWarpArg = WARP_ARG_EXIT_COURSE; play_transition(WARP_TRANSITION_FADE_INTO_CIRCLE, 0x14, 0x00, 0x00, 0x00); break; @@ -1352,7 +1356,7 @@ s32 play_mode_paused(void) { if (gDebugLevelSelect) { fade_into_special_warp(-9, 1); } else { - initiate_warp(gLevelValues.exitCastleLevel, gLevelValues.exitCastleArea, gLevelValues.exitCastleWarpNode, 0); + initiate_warp(gLevelValues.exitCastleLevel, gLevelValues.exitCastleArea, gLevelValues.exitCastleWarpNode, WARP_ARG_EXIT_COURSE); fade_into_special_warp(0, 0); gSavedCourseNum = COURSE_NONE; } diff --git a/src/game/level_update.h b/src/game/level_update.h index 1e653fe1a..55bf2d09b 100644 --- a/src/game/level_update.h +++ b/src/game/level_update.h @@ -80,6 +80,8 @@ enum MarioSpawnType { #define WARP_TYPE_CHANGE_AREA 2 #define WARP_TYPE_SAME_AREA 3 +#define WARP_ARG_EXIT_COURSE -1 + #define PRESS_START_DEMO_TIMER 800 // From Surface 0xD3 to 0xFC diff --git a/src/pc/lua/smlua_constants_autogen.c b/src/pc/lua/smlua_constants_autogen.c index f76efdff8..bcd13c14d 100644 --- a/src/pc/lua/smlua_constants_autogen.c +++ b/src/pc/lua/smlua_constants_autogen.c @@ -1586,6 +1586,7 @@ char gSmluaConstants[] = "" "WARP_TYPE_CHANGE_LEVEL=1\n" "WARP_TYPE_CHANGE_AREA=2\n" "WARP_TYPE_SAME_AREA=3\n" +"WARP_ARG_EXIT_COURSE=-1\n" "PRESS_START_DEMO_TIMER=800\n" "PAINTING_WARP_INDEX_START=0x00\n" "PAINTING_WARP_INDEX_FA=0x2A\n" diff --git a/src/pc/lua/smlua_hooks.c b/src/pc/lua/smlua_hooks.c index 2953ca061..c7875011f 100644 --- a/src/pc/lua/smlua_hooks.c +++ b/src/pc/lua/smlua_hooks.c @@ -814,6 +814,7 @@ void smlua_call_event_hooks_before_warp(enum LuaHookedEventType hookType, s16 *d // if the hook returns a table, use it to override the warp parameters if (lua_istable(L, -1)) { + lua_getfield(L, -1, "destLevel"); if (lua_isnumber(L, -1)) { *destLevel = (s16)lua_tointeger(L, -1); @@ -832,12 +833,6 @@ void smlua_call_event_hooks_before_warp(enum LuaHookedEventType hookType, s16 *d } lua_pop(L, 1); - lua_getfield(L, -1, "arg"); - if (lua_isnumber(L, -1)) { - *arg = (s32)lua_tointeger(L, -1); - } - lua_pop(L, 1); - lua_settop(L, prevTop); return; } @@ -845,7 +840,6 @@ void smlua_call_event_hooks_before_warp(enum LuaHookedEventType hookType, s16 *d } } - void smlua_call_event_hooks_on_seq_load(enum LuaHookedEventType hookType, u32 player, u32 seqId, s32 loadAsync, s16* returnValue) { lua_State* L = gLuaState; if (L == NULL) { return; }