From a35f067f26e65159f769596b09ba5ac3f34d21a6 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Wed, 12 Jun 2024 12:11:27 +0200 Subject: [PATCH 1/2] Fix Baton Pass breaking on Memento --- src/battle_main.c | 6 +++--- src/battle_script_commands.c | 16 ++++++++++------ test/battle/move_effect/baton_pass.c | 27 +++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 9 deletions(-) diff --git a/src/battle_main.c b/src/battle_main.c index af073cafb6c..3d2c74d8425 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -3677,8 +3677,8 @@ const u8* FaintClearSetData(u32 battler) gBattleStruct->zmove.toBeUsed[battler] = MOVE_NONE; gBattleStruct->zmove.effect = EFFECT_HIT; // Clear Dynamax data - UndoDynamax(battler); - + UndoDynamax(battler); + return result; } @@ -5835,7 +5835,7 @@ static void TryEvolvePokemon(void) sTriedEvolving |= gBitTable[i]; if (species == SPECIES_NONE && (gLeveledUpInBattle & gBitTable[i])) - { + { gLeveledUpInBattle &= ~(gBitTable[i]); species = GetEvolutionTargetSpecies(&gPlayerParty[i], EVO_MODE_BATTLE_ONLY, gLeveledUpInBattle, NULL); } diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index d2274562249..085973aa7c4 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -2106,7 +2106,7 @@ static void Cmd_adjustdamage(void) gLastUsedItem = gBattleMons[gBattlerTarget].item; gSpecialStatuses[gBattlerTarget].focusBanded = FALSE; gSpecialStatuses[gBattlerTarget].focusSashed = FALSE; - + } else if (gSpecialStatuses[gBattlerTarget].sturdied) { @@ -3225,8 +3225,8 @@ void SetMoveEffect(bool32 primary, bool32 certain) { gBattleMons[gEffectBattler].status2 |= sStatusFlagsForMoveEffects[gBattleScripting.moveEffect]; gBattlescriptCurrInstr++; - } - else + } + else { gBattlescriptCurrInstr++; } @@ -6285,7 +6285,7 @@ static void Cmd_moveend(void) break; } } - + if (!(gBattleStruct->lastMoveFailed & gBitTable[gBattlerAttacker] || (!gSpecialStatuses[gBattlerAttacker].dancerUsedMove && gBattleStruct->bouncedMoveIsUsed))) @@ -7030,8 +7030,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 6fad1c1605a..b04aaa298a7 100644 --- a/test/battle/move_effect/baton_pass.c +++ b/test/battle/move_effect/baton_pass.c @@ -1,6 +1,33 @@ #include "global.h" #include "test/battle.h" +#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"); From 459c8414a1e9c7fa6aacc589c0c2e6105175184c Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Wed, 12 Jun 2024 12:12:54 +0200 Subject: [PATCH 2/2] doubled headers --- test/battle/move_effect/baton_pass.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/test/battle/move_effect/baton_pass.c b/test/battle/move_effect/baton_pass.c index b04aaa298a7..02d8a8839ea 100644 --- a/test/battle/move_effect/baton_pass.c +++ b/test/battle/move_effect/baton_pass.c @@ -1,9 +1,6 @@ #include "global.h" #include "test/battle.h" -#include "global.h" -#include "test/battle.h" - ASSUMPTIONS { ASSUME(gMovesInfo[MOVE_BATON_PASS].effect == EFFECT_BATON_PASS);