From 48d517ab0dd987a51200903cfb221e8c7edb9819 Mon Sep 17 00:00:00 2001 From: David Joslin Date: Thu, 26 Oct 2023 16:08:43 -0700 Subject: [PATCH] Add a 1 second window to prevent a warp from instantly warping you back (a workaround for broken romhack ports) --- include/types.h | 1 + src/game/interaction.c | 8 ++++++++ src/game/level_update.c | 4 ++++ 3 files changed, 13 insertions(+) diff --git a/include/types.h b/include/types.h index 28efb63f..1c301a13 100644 --- a/include/types.h +++ b/include/types.h @@ -420,6 +420,7 @@ struct MarioState /*????*/ u8 visibleToEnemies; /*????*/ u32 cap; /*????*/ u8 bounceSquishTimer; + /*????*/ u8 skipWarpInteractionsTimer; }; struct TextureInfo diff --git a/src/game/interaction.c b/src/game/interaction.c index 28db2776..0f7c5af9 100644 --- a/src/game/interaction.c +++ b/src/game/interaction.c @@ -1043,6 +1043,10 @@ u32 interact_warp(struct MarioState *m, UNUSED u32 interactType, struct Object * if (!m || !o) { return FALSE; } u32 action; + if (m->skipWarpInteractionsTimer > 0) { + return FALSE; + } + if (m != &gMarioStates[0]) { // don't do for remote players return FALSE; @@ -2295,6 +2299,10 @@ void mario_process_interactions(struct MarioState *m) { sDelayInvincTimer = FALSE; gInteractionInvulnerable = (m->action & ACT_FLAG_INVULNERABLE) || m->invincTimer != 0; + if (m->skipWarpInteractionsTimer) { + m->skipWarpInteractionsTimer--; + } + if (!(m->action & ACT_FLAG_INTANGIBLE) && m->collidedObjInteractTypes != 0 && is_player_active(m)) { s32 i; for (i = 0; i < 32; i++) { diff --git a/src/game/level_update.c b/src/game/level_update.c index 4b2a0bbb..f267db6e 100644 --- a/src/game/level_update.c +++ b/src/game/level_update.c @@ -536,6 +536,10 @@ void init_mario_after_warp(void) { gMarioState->health = 0x880; } + if (gMarioState) { + gMarioState->skipWarpInteractionsTimer = 30; + } + smlua_call_event_hooks(HOOK_ON_WARP); }