From f626fac9dced2ae2e800fb9afe3a458c190baae6 Mon Sep 17 00:00:00 2001 From: luckytyphlosion <10688458+luckytyphlosion@users.noreply.github.com> Date: Tue, 12 Jan 2021 18:43:16 -0500 Subject: [PATCH 1/2] Fix AI corruption bug. --- src/battle_controllers.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/battle_controllers.c b/src/battle_controllers.c index eb6d73ba78..f76d5d37b8 100644 --- a/src/battle_controllers.c +++ b/src/battle_controllers.c @@ -62,7 +62,20 @@ void SetUpBattleVarsAndBirchZigzagoon(void) ClearBattleMonForms(); BattleAI_SetupItems(); BattleAI_SetupFlags(); - BattleAI_SetupAIData(0xF); + // this isn't necessary, and is dangerous + // if we just finished a double battle + // as this function modifies array elements + // by using gActiveBattler as the index + // and gActiveBattler isn't reset upon + // entering a battle + + // this bug affects vanilla as well, but vanilla + // does not perform any array element writes + // and any garbage values due to the result of + // reading an invalid array element are reset + // when the AI chooses its move + + // BattleAI_SetupAIData(0xF); if (gBattleTypeFlags & BATTLE_TYPE_FIRST_BATTLE) { From cb7b77500f20c227b3bab3f95b7a64be916d41ab Mon Sep 17 00:00:00 2001 From: luckytyphlosion <10688458+luckytyphlosion@users.noreply.github.com> Date: Tue, 12 Jan 2021 18:52:37 -0500 Subject: [PATCH 2/2] Just remove the commented out function and notes. --- src/battle_controllers.c | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/src/battle_controllers.c b/src/battle_controllers.c index f76d5d37b8..79f1ff7ad0 100644 --- a/src/battle_controllers.c +++ b/src/battle_controllers.c @@ -62,20 +62,6 @@ void SetUpBattleVarsAndBirchZigzagoon(void) ClearBattleMonForms(); BattleAI_SetupItems(); BattleAI_SetupFlags(); - // this isn't necessary, and is dangerous - // if we just finished a double battle - // as this function modifies array elements - // by using gActiveBattler as the index - // and gActiveBattler isn't reset upon - // entering a battle - - // this bug affects vanilla as well, but vanilla - // does not perform any array element writes - // and any garbage values due to the result of - // reading an invalid array element are reset - // when the AI chooses its move - - // BattleAI_SetupAIData(0xF); if (gBattleTypeFlags & BATTLE_TYPE_FIRST_BATTLE) {