diff options
Diffstat (limited to 'src/battle_ai_script_commands.c')
-rw-r--r-- | src/battle_ai_script_commands.c | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/src/battle_ai_script_commands.c b/src/battle_ai_script_commands.c index 9fdd4d0c3..b72875036 100644 --- a/src/battle_ai_script_commands.c +++ b/src/battle_ai_script_commands.c @@ -1761,7 +1761,11 @@ static void Cmd_if_cant_faint(void) gBattleMoveDamage = gBattleMoveDamage * AI_THINKING_STRUCT->simulatedRNG[AI_THINKING_STRUCT->movesetIndex] / 100; - // This macro is missing the damage 0 = 1 assumption. +#ifdef BUGFIX + // Moves always do at least 1 damage. + if (gBattleMoveDamage == 0) + gBattleMoveDamage = 1; +#endif if (gBattleMons[gBattlerTarget].hp > gBattleMoveDamage) gAIScriptPtr = T1_READ_PTR(gAIScriptPtr + 1); @@ -1877,9 +1881,14 @@ static void Cmd_if_has_move_with_effect(void) case AI_TARGET_PARTNER: for (i = 0; i < MAX_MON_MOVES; i++) { - // UB: checks sBattler_AI instead of gBattlerTarget. + // BUG: checks sBattler_AI instead of gBattlerTarget. + #ifndef BUGFIX if (gBattleMons[sBattler_AI].moves[i] != 0 && gBattleMoves[BATTLE_HISTORY->usedMoves[gBattlerTarget].moves[i]].effect == gAIScriptPtr[2]) break; + #else + if (gBattleMons[gBattlerTarget].moves[i] != 0 && gBattleMoves[BATTLE_HISTORY->usedMoves[gBattlerTarget].moves[i]].effect == gAIScriptPtr[2]) + break; + #endif } if (i == MAX_MON_MOVES) gAIScriptPtr += 7; @@ -2014,18 +2023,24 @@ static void Cmd_if_holds_item(void) { u8 battlerId = BattleAI_GetWantedBattler(gAIScriptPtr[1]); u16 item; - u8 var1, var2; + u8 itemLo, itemHi; if ((battlerId & BIT_SIDE) == (sBattler_AI & BIT_SIDE)) item = gBattleMons[battlerId].item; else item = BATTLE_HISTORY->itemEffects[battlerId]; - // UB: doesn't properly read an unaligned u16 - var2 = gAIScriptPtr[2]; - var1 = gAIScriptPtr[3]; + itemHi = gAIScriptPtr[2]; + itemLo = gAIScriptPtr[3]; - if ((var1 | var2) == item) +#ifdef BUGFIX + // This bug doesn't affect the vanilla game because this script command + // is only used to check ITEM_PERSIM_BERRY, whose high byte happens to + // be 0. + if (((itemHi << 8) | itemLo) == item) +#else + if ((itemLo | itemHi) == item) +#endif gAIScriptPtr = T1_READ_PTR(gAIScriptPtr + 4); else gAIScriptPtr += 8; |