From 73e72e1b777c8110b24699a34b7486aafdfc20bd Mon Sep 17 00:00:00 2001 From: Isaac0-dev <62234577+Isaac0-dev@users.noreply.github.com> Date: Tue, 3 Jun 2025 17:16:49 +1000 Subject: [PATCH] fix mirror mario with custom animations again [build] --- data/dynos_mgr_anim.cpp | 18 ++++++++++++------ src/game/mario_misc.c | 32 ++++++++++++++++++++++++++------ 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/data/dynos_mgr_anim.cpp b/data/dynos_mgr_anim.cpp index f409eba37..a3567b5e4 100644 --- a/data/dynos_mgr_anim.cpp +++ b/data/dynos_mgr_anim.cpp @@ -5,6 +5,10 @@ extern "C" { #include "game/object_list_processor.h" #include "pc/configfile.h" #include "pc/lua/utils/smlua_anim_utils.h" +#include "behavior_data.h" +#include "pc/lua/smlua_hooks.h" + +s16 geo_get_processing_mario_index(void); } // @@ -24,7 +28,6 @@ static s32 RetrieveCurrentMarioAnimationIndex(u32 aPlayerIndex) { } // Retrieve the current animation index -// As we don't know the length of the table, let's hope that we'll always find the animation... static s32 RetrieveCurrentAnimationIndex(struct Object *aObject) { if (!aObject->oAnimations || !aObject->header.gfx.animInfo.curAnim || smlua_anim_util_get_current_animation_name(aObject)) { return -1; @@ -74,11 +77,14 @@ void DynOS_Anim_Swap(void *aPtr) { // Animation index s32 _AnimIndex = -1; - for (u32 i = 0; i < MAX_PLAYERS; i++) { - if (gMarioStates[i].marioObj == NULL) { continue; } - if (_Object == gMarioStates[i].marioObj) { - _AnimIndex = RetrieveCurrentMarioAnimationIndex(i); - break; + u8 index = geo_get_processing_mario_index(); + if (index != -1) { + _AnimIndex = RetrieveCurrentMarioAnimationIndex(index); + + // Don't allow Mario animations to be treated as regular objects + // because DynOS doesn't properly build an AnimationTable + if (_AnimIndex == -1) { + return; } } if (_AnimIndex == -1) { diff --git a/src/game/mario_misc.c b/src/game/mario_misc.c index c995a878b..9977a8e3a 100644 --- a/src/game/mario_misc.c +++ b/src/game/mario_misc.c @@ -333,20 +333,40 @@ static Gfx *make_gfx_mario_alpha(struct GraphNodeGenerated *node, s16 alpha) { return gfxHead; } +// Calculates if the processing geo is a mirror mario +static s8 geo_get_processing_mirror_mario_index() { + ptrdiff_t ptrDiff = (struct GraphNodeObject *) gCurGraphNodeProcessingObject - gMirrorMario; + return (ptrDiff >= 0 && ptrDiff < MAX_PLAYERS) ? ptrDiff : -1; +} + static u8 geo_get_processing_object_index(void) { - // sloppy way to fix mirror marios - for (s32 i = 0; i < MAX_PLAYERS; i++) { - if ((struct GraphNodeObject*)gCurGraphNodeObject == &gMirrorMario[i]) { - return i; - } + s8 index = geo_get_processing_mirror_mario_index(); + if (index != -1) { + return index; } if (gCurGraphNodeProcessingObject == NULL) { return 0; } struct NetworkPlayer* np = network_player_from_global_index(gCurGraphNodeProcessingObject->globalPlayerIndex); - u8 index = (np == NULL) ? 0 : np->localIndex; + index = (np == NULL) ? 0 : np->localIndex; return (index >= MAX_PLAYERS) ? 0 : index; } +s16 geo_get_processing_mario_index(void) { + if (gCurGraphNodeProcessingObject == NULL) { return -1; } + + s8 index = geo_get_processing_mirror_mario_index(); + if (index != -1) { + return index; + } + + if (gCurGraphNodeProcessingObject->behavior != smlua_override_behavior(bhvMario)) { + return -1; + } + + index = gCurGraphNodeProcessingObject->oBehParams - 1; + return (index >= MAX_PLAYERS) ? -1 : index; +} + struct MarioState *geo_get_mario_state(void) { u8 index = geo_get_processing_object_index(); return &gMarioStates[index];