From a2809acfd1d6818acb6d39c5d8f1520746201c20 Mon Sep 17 00:00:00 2001 From: CallmeEchoo Date: Wed, 26 Apr 2023 01:02:47 +0200 Subject: [PATCH] fix gChosenMovePos not being assigned correctly for battle items thanks griffin <3 Co-Authored-By: Martin Griffin <838573+mrgriffin@users.noreply.github.com> --- include/recorded_battle.h | 1 + src/battle_controller_recorded_opponent.c | 1 + src/battle_controller_recorded_player.c | 1 + src/battle_script_commands.c | 10 +++++++--- test/test_runner_battle.c | 8 ++------ 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/include/recorded_battle.h b/include/recorded_battle.h index ea66096d7..02bbe8fc3 100644 --- a/include/recorded_battle.h +++ b/include/recorded_battle.h @@ -46,6 +46,7 @@ enum RECORDED_BATTLE_PALACE_ACTION, RECORDED_ITEM_ID, RECORDED_ITEM_TARGET, + RECORDED_ITEM_MOVE, }; extern u32 gRecordedBattleRngSeed; diff --git a/src/battle_controller_recorded_opponent.c b/src/battle_controller_recorded_opponent.c index bb41b42d6..8255abcab 100644 --- a/src/battle_controller_recorded_opponent.c +++ b/src/battle_controller_recorded_opponent.c @@ -1442,6 +1442,7 @@ static void RecordedOpponentHandleChooseItem(void) u8 byte2 = RecordedBattle_GetBattlerAction(RECORDED_ITEM_ID, gActiveBattler); gBattleStruct->chosenItem[gActiveBattler] = (byte1 << 8) | byte2; gBattleStruct->itemPartyIndex[gActiveBattler] = RecordedBattle_GetBattlerAction(RECORDED_ITEM_TARGET, gActiveBattler); + gChosenMovePos = RecordedBattle_GetBattlerAction(RECORDED_ITEM_MOVE, gActiveBattler); BtlController_EmitOneReturnValue(BUFFER_B, gBattleStruct->chosenItem[gActiveBattler]); RecordedOpponentBufferExecCompleted(); } diff --git a/src/battle_controller_recorded_player.c b/src/battle_controller_recorded_player.c index efbd60f18..8350e8594 100644 --- a/src/battle_controller_recorded_player.c +++ b/src/battle_controller_recorded_player.c @@ -1466,6 +1466,7 @@ static void RecordedPlayerHandleChooseItem(void) u8 byte2 = RecordedBattle_GetBattlerAction(RECORDED_ITEM_ID, gActiveBattler); gBattleStruct->chosenItem[gActiveBattler] = (byte1 << 8) | byte2; gBattleStruct->itemPartyIndex[gActiveBattler] = RecordedBattle_GetBattlerAction(RECORDED_ITEM_TARGET, gActiveBattler); + gChosenMovePos = RecordedBattle_GetBattlerAction(RECORDED_ITEM_MOVE, gActiveBattler); BtlController_EmitOneReturnValue(BUFFER_B, gBattleStruct->chosenItem[gActiveBattler]); RecordedPlayerBufferExecCompleted(); } diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 07669635e..31ef4cea7 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -16563,8 +16563,7 @@ void BS_ItemIncreaseStat(void) { void BS_ItemRestorePP(void) { NATIVE_ARGS(); const u8 *effect = GetItemEffect(gLastUsedItem); - u32 i, pp, maxPP, moveId; - u32 loopEnd = MAX_MON_MOVES; + u32 i, pp, maxPP, moveId, loopEnd; u32 battlerId = MAX_BATTLERS_COUNT; struct Pokemon *mon = (GetBattlerSide(gBattlerAttacker) == B_SIDE_PLAYER) ? &gPlayerParty[gBattleStruct->itemPartyIndex[gBattlerAttacker]] : &gEnemyParty[gBattleStruct->itemPartyIndex[gBattlerAttacker]]; @@ -16574,6 +16573,11 @@ void BS_ItemRestorePP(void) { i = gChosenMovePos; loopEnd = gChosenMovePos + 1; } + else + { + i = 0; + loopEnd = MAX_MON_MOVES; + } // Check if the recipient is an active battler. if (gBattleStruct->itemPartyIndex[gBattlerAttacker] == gBattlerPartyIndexes[gBattlerAttacker]) @@ -16583,7 +16587,7 @@ void BS_ItemRestorePP(void) { battlerId = BATTLE_PARTNER(gBattlerAttacker); // Heal PP! - for (i = 0; i < loopEnd; i++) + for (; i < loopEnd; i++) { pp = GetMonData(mon, MON_DATA_PP1 + i, NULL); moveId = GetMonData(mon, MON_DATA_MOVE1 + i, NULL); diff --git a/test/test_runner_battle.c b/test/test_runner_battle.c index 75e459e49..f10291262 100644 --- a/test/test_runner_battle.c +++ b/test/test_runner_battle.c @@ -1554,12 +1554,8 @@ void UseItem(u32 sourceLine, struct BattlePokemon *battler, struct ItemContext c PushBattlerAction(sourceLine, battlerId, RECORDED_ACTION_TYPE, B_ACTION_USE_ITEM); PushBattlerAction(sourceLine, battlerId, RECORDED_ITEM_ID, (ctx.itemId >> 8) & 0xFF); PushBattlerAction(sourceLine, battlerId, RECORDED_ITEM_ID, ctx.itemId & 0xFF); - if (ctx.explicitPartyIndex) - PushBattlerAction(sourceLine, battlerId, RECORDED_ITEM_TARGET, ctx.partyIndex); - else if (ctx.explicitMove) - PushBattlerAction(sourceLine, battlerId, RECORDED_ITEM_TARGET, i); - else - PushBattlerAction(sourceLine, battlerId, RECORDED_ITEM_TARGET, 0); + PushBattlerAction(sourceLine, battlerId, RECORDED_ITEM_TARGET, ctx.partyIndex); + PushBattlerAction(sourceLine, battlerId, RECORDED_ITEM_MOVE, i); DATA.actionBattlers |= 1 << battlerId; }