Fix Beat Up's battle script to avoid an out-of-bounds array access

This commit is contained in:
SphericalIce 2022-12-27 10:49:57 +00:00
parent b74997f82e
commit 200b71be02
6 changed files with 21 additions and 11 deletions

View File

@ -1022,7 +1022,7 @@
.4byte \ptr .4byte \ptr
.endm .endm
.macro trydobeatup endPtr:req, failPtr:req .macro trydobeatup endPtr=NULL, failPtr=NULL
.byte 0xc4 .byte 0xc4
.4byte \endPtr .4byte \endPtr
.4byte \failPtr .4byte \failPtr

View File

@ -5183,10 +5183,18 @@ BattleScript_EffectTeleportNew:
BattleScript_EffectTeleportNewEnd: BattleScript_EffectTeleportNewEnd:
goto BattleScript_MoveEnd goto BattleScript_MoveEnd
.if B_BEAT_UP < GEN_5
BattleScript_EffectBeatUp:: BattleScript_EffectBeatUp::
attackcanceler attackcanceler
accuracycheck BattleScript_PrintMoveMissed, ACC_CURR_MOVE accuracycheck BattleScript_PrintMoveMissed, ACC_CURR_MOVE
.if B_BEAT_UP >= GEN_5
attackstring
ppreduce
critcalc
damagecalc
adjustdamage
trydobeatup
goto BattleScript_HitFromAtkAnimation
.else
attackstring attackstring
pause B_WAIT_TIME_SHORT pause B_WAIT_TIME_SHORT
ppreduce ppreduce
@ -5216,12 +5224,6 @@ BattleScript_BeatUpAttack::
goto BattleScript_BeatUpLoop goto BattleScript_BeatUpLoop
BattleScript_BeatUpEnd:: BattleScript_BeatUpEnd::
end end
.else
BattleScript_EffectBeatUp::
attackcanceler
accuracycheck BattleScript_PrintMoveMissed, ACC_CURR_MOVE
addbyte gBattleCommunication, 1
goto BattleScript_HitFromAtkString
.endif .endif
BattleScript_EffectSemiInvulnerable:: BattleScript_EffectSemiInvulnerable::

View File

@ -650,6 +650,7 @@ struct BattleStruct
u8 skyDropTargets[MAX_BATTLERS_COUNT]; // For Sky Drop, to account for if multiple Pokemon use Sky Drop in a double battle. u8 skyDropTargets[MAX_BATTLERS_COUNT]; // For Sky Drop, to account for if multiple Pokemon use Sky Drop in a double battle.
// When using a move which hits multiple opponents which is then bounced by a target, we need to make sure, the move hits both opponents, the one with bounce, and the one without. // When using a move which hits multiple opponents which is then bounced by a target, we need to make sure, the move hits both opponents, the one with bounce, and the one without.
u8 attackerBeforeBounce:2; u8 attackerBeforeBounce:2;
u8 beatUpSlot:3;
u8 targetsDone[MAX_BATTLERS_COUNT]; // Each battler as a bit. u8 targetsDone[MAX_BATTLERS_COUNT]; // Each battler as a bit.
u16 overwrittenAbilities[MAX_BATTLERS_COUNT]; // abilities overwritten during battle (keep separate from battle history in case of switching) u16 overwrittenAbilities[MAX_BATTLERS_COUNT]; // abilities overwritten during battle (keep separate from battle history in case of switching)
}; };

View File

@ -3039,6 +3039,7 @@ static void BattleStartClearSetData(void)
gBattleStruct->stickyWebUser = 0xFF; gBattleStruct->stickyWebUser = 0xFF;
gBattleStruct->appearedInBattle = 0; gBattleStruct->appearedInBattle = 0;
gBattleStruct->beatUpSlot = 0;
for (i = 0; i < PARTY_SIZE; i++) for (i = 0; i < PARTY_SIZE; i++)
{ {

View File

@ -12855,6 +12855,10 @@ static void Cmd_trysetfutureattack(void)
static void Cmd_trydobeatup(void) static void Cmd_trydobeatup(void)
{ {
#if B_BEAT_UP >= GEN_5
gBattleStruct->beatUpSlot++;
gBattlescriptCurrInstr += 9;
#else
struct Pokemon *party; struct Pokemon *party;
if (GetBattlerSide(gBattlerAttacker) == B_SIDE_PLAYER) if (GetBattlerSide(gBattlerAttacker) == B_SIDE_PLAYER)
@ -12898,6 +12902,7 @@ static void Cmd_trydobeatup(void)
else else
gBattlescriptCurrInstr = T1_READ_PTR(gBattlescriptCurrInstr + 5); gBattlescriptCurrInstr = T1_READ_PTR(gBattlescriptCurrInstr + 5);
} }
#endif
} }
static void Cmd_setsemiinvulnerablebit(void) static void Cmd_setsemiinvulnerablebit(void)

View File

@ -230,8 +230,9 @@ static u8 CalcBeatUpPower(void)
party = gPlayerParty; party = gPlayerParty;
else else
party = gEnemyParty; party = gEnemyParty;
// Party slot is set in the battle script for Beat Up
species = GetMonData(&party[gBattleCommunication[0] - 1], MON_DATA_SPECIES); // Party slot is incremented by the battle script for Beat Up after this damage calculation
species = GetMonData(&party[gBattleStruct->beatUpSlot], MON_DATA_SPECIES);
basePower = (gSpeciesInfo[species].baseAttack / 10) + 5; basePower = (gSpeciesInfo[species].baseAttack / 10) + 5;
return basePower; return basePower;
@ -3875,7 +3876,7 @@ u8 AtkCanceller_UnableToUseMove(void)
gMultiHitCounter++; gMultiHitCounter++;
} }
gBattleCommunication[0] = 0; // For later gBattleStruct->beatUpSlot = 0;
PREPARE_BYTE_NUMBER_BUFFER(gBattleScripting.multihitString, 1, 0) PREPARE_BYTE_NUMBER_BUFFER(gBattleScripting.multihitString, 1, 0)
} }
#endif #endif