diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 8cef961abea8..44825a54f0a3 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -7032,8 +7032,12 @@ static void Cmd_openpartyscreen(void) if (gAbsentBattlerFlags & gBitTable[battlerOpposite]) battlerOpposite ^= BIT_FLANK; - BtlController_EmitLinkStandbyMsg(battlerOpposite, BUFFER_A, LINK_STANDBY_MSG_ONLY, FALSE); - MarkBattlerForControllerExec(battlerOpposite); + // Make sure we're checking a valid battler. In edge case scenarios - battler could be absent and battlerOpposite would become a non-existent one softlocking the game. + if (battlerOpposite < gBattlersCount) + { + BtlController_EmitLinkStandbyMsg(battlerOpposite, BUFFER_A, LINK_STANDBY_MSG_ONLY, FALSE); + MarkBattlerForControllerExec(battlerOpposite); + } } } } diff --git a/test/battle/move_effect/baton_pass.c b/test/battle/move_effect/baton_pass.c index 6fad1c1605a2..02d8a8839ead 100644 --- a/test/battle/move_effect/baton_pass.c +++ b/test/battle/move_effect/baton_pass.c @@ -1,6 +1,30 @@ #include "global.h" #include "test/battle.h" +ASSUMPTIONS +{ + ASSUME(gMovesInfo[MOVE_BATON_PASS].effect == EFFECT_BATON_PASS); +} + +// This softlocked the game before. +SINGLE_BATTLE_TEST("Baton Pass used after Memento works correctly") +{ + GIVEN { + PLAYER(SPECIES_WOBBUFFET); + PLAYER(SPECIES_WOBBUFFET); + OPPONENT(SPECIES_WYNAUT); + OPPONENT(SPECIES_CATERPIE); + } WHEN { + TURN { MOVE(player, MOVE_MEMENTO); SEND_OUT(player, 1); MOVE(opponent, MOVE_BATON_PASS); SEND_OUT(opponent, 1); } + } SCENE { + MESSAGE("Wobbuffet used Memento!"); + MESSAGE("Wobbuffet fainted!"); + MESSAGE("Foe Wynaut used Baton Pass!"); + MESSAGE("2 sent out Caterpie!"); + MESSAGE("Go! Wobbuffet!"); + } +} + TO_DO_BATTLE_TEST("Baton Pass switches out the user"); TO_DO_BATTLE_TEST("Baton Pass fails if there's no valid party Pokémon left"); TO_DO_BATTLE_TEST("Baton Pass passes both positive and negative stat changes");