Fix ShouldPivot overwriting random memory (#7882)

Co-authored-by: Alex <93446519+AlexOn1ine@users.noreply.github.com>
This commit is contained in:
DizzyEggg 2025-10-08 19:44:31 +02:00 committed by GitHub
parent 015a0fea03
commit ffe0936ff1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -3174,14 +3174,16 @@ enum AIPivot ShouldPivot(u32 battlerAtk, u32 battlerDef, u32 defAbility, u32 mov
u32 battlerToSwitch;
u32 predictedMoveSpeedCheck = GetIncomingMoveSpeedCheck(battlerAtk, battlerDef, gAiLogicData);
battlerToSwitch = gBattleStruct->AI_monToSwitchIntoId[battlerAtk];
// Palafin always wants to activate Zero to Hero
if (gBattleMons[battlerAtk].species == SPECIES_PALAFIN_ZERO
&& gBattleMons[battlerAtk].ability == ABILITY_ZERO_TO_HERO
&& CountUsablePartyMons(battlerAtk) != 0)
return SHOULD_PIVOT;
battlerToSwitch = gAiLogicData->mostSuitableMonId[battlerAtk];
// This shouldn't ever happen, but it's there to make sure we don't accidentally read past the gParty array.
if (battlerToSwitch >= PARTY_SIZE)
battlerToSwitch = 0;
if (PartyBattlerShouldAvoidHazards(battlerAtk, battlerToSwitch))
return DONT_PIVOT;