From 2f5b0c4880e97933101a236bc30549d617d124ea Mon Sep 17 00:00:00 2001 From: Isaac0-dev <62234577+Isaac0-dev@users.noreply.github.com> Date: Tue, 14 May 2024 10:12:20 +1000 Subject: [PATCH] reset mario state on player disconnect (#44) fixes some mod related bugs --- src/game/mario.c | 4 ++-- src/game/mario.h | 1 + src/pc/network/network_player.c | 4 ++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/game/mario.c b/src/game/mario.c index 08575e686..b1d7cbb02 100644 --- a/src/game/mario.c +++ b/src/game/mario.c @@ -123,7 +123,7 @@ s16 set_character_animation(struct MarioState *m, s32 targetAnimID) { struct Animation *targetAnim = m->animation->targetAnim; s32 charAnimID = get_character_anim(m, targetAnimID); if (!targetAnim) { return 0; } - + if (load_patchable_table(m->animation, charAnimID)) { targetAnim->values = (void *) VIRTUAL_TO_PHYSICAL((u8 *) targetAnim + (uintptr_t) targetAnim->values); targetAnim->index = (void *) VIRTUAL_TO_PHYSICAL((u8 *) targetAnim + (uintptr_t) targetAnim->index); @@ -2379,7 +2379,7 @@ void init_mario(void) { } } -static void init_mario_single_from_save_file(struct MarioState* m, u16 index) { +void init_mario_single_from_save_file(struct MarioState* m, u16 index) { if (!m) { return; } m->playerIndex = index; m->flags = 0; diff --git a/src/game/mario.h b/src/game/mario.h index 6cd282ace..f0ff3d97f 100644 --- a/src/game/mario.h +++ b/src/game/mario.h @@ -64,6 +64,7 @@ s32 execute_mario_action(UNUSED struct Object *o); s32 force_idle_state(struct MarioState* m); void init_single_mario(struct MarioState* m); void init_mario(void); +void init_mario_single_from_save_file(struct MarioState* m, u16 index); void init_mario_from_save_file(void); void set_mario_particle_flags(struct MarioState* m, u32 flags, u8 clear); void mario_update_wall(struct MarioState* m, struct WallCollisionData* wcd); diff --git a/src/pc/network/network_player.c b/src/pc/network/network_player.c index 7f332b3b5..662d735a3 100644 --- a/src/pc/network/network_player.c +++ b/src/pc/network/network_player.c @@ -15,6 +15,7 @@ #ifdef DISCORD_SDK #include "pc/discord/discord.h" #endif +#include "game/mario.h" struct NetworkPlayer gNetworkPlayers[MAX_PLAYERS] = { 0 }; struct NetworkPlayer *gNetworkPlayerLocal = NULL; @@ -374,6 +375,9 @@ u8 network_player_disconnected(u8 globalIndex) { discord_activity_update(); #endif + // reset mario state + init_mario_single_from_save_file(&gMarioStates[i], i); + return i; } return UNKNOWN_GLOBAL_INDEX;