diff --git a/asm/pokenav.s b/asm/pokenav.s index ba6d4fca0..01bf2a431 100755 --- a/asm/pokenav.s +++ b/asm/pokenav.s @@ -25722,7 +25722,7 @@ sub_81D3AD8: @ 81D3AD8 adds r5, r0, 0 adds r4, r1, 0 movs r0, 0x1E - bl sub_81535DC + bl TryCopySpecialSaveSection cmp r0, 0x1 bne _081D3B04 ldr r2, =0x00000ee8 diff --git a/asm/recorded_battle.s b/asm/recorded_battle.s index d2255282a..a329fa85b 100644 --- a/asm/recorded_battle.s +++ b/asm/recorded_battle.s @@ -8,2048 +8,6 @@ - thumb_func_start sub_8185290 -sub_8185290: @ 8185290 - push {r4,r5,lr} - movs r0, 0xF8 - lsls r0, 4 - bl AllocZeroed - adds r4, r0, 0 - bl start_ov_to_battle_anim - adds r5, r0, 0 - adds r0, r4, 0 - bl Free - adds r0, r5, 0 - pop {r4,r5} - pop {r1} - bx r1 - thumb_func_end sub_8185290 - - thumb_func_start sub_81852B0 -sub_81852B0: @ 81852B0 - push {r4,r5,lr} - adds r5, r0, 0 - ldr r1, =0x000004ec - adds r0, r5, r1 - ldr r1, [r0] - cmp r1, 0 - beq _081852E8 - ldr r0, =0x7d007e92 - ands r1, r0 - cmp r1, 0 - bne _081852E8 - ldr r4, =0x00000f7c - adds r0, r5, 0 - adds r1, r4, 0 - bl CalcByteArraySum - adds r4, r5, r4 - ldr r1, [r4] - cmp r0, r1 - bne _081852E8 - movs r0, 0x1 - b _081852EA - .pool -_081852E8: - movs r0, 0 -_081852EA: - pop {r4,r5} - pop {r1} - bx r1 - thumb_func_end sub_81852B0 - - thumb_func_start sub_81852F0 -sub_81852F0: @ 81852F0 - push {r4,r5,lr} - adds r4, r0, 0 - adds r5, r1, 0 - movs r2, 0x80 - lsls r2, 5 - adds r0, r5, 0 - movs r1, 0 - bl memset - movs r2, 0xF8 - lsls r2, 4 - adds r0, r5, 0 - adds r1, r4, 0 - bl memcpy - ldr r4, =0x00000f7c - adds r0, r5, 0 - adds r1, r4, 0 - bl CalcByteArraySum - adds r4, r5, r4 - str r0, [r4] - movs r0, 0x1F - adds r1, r5, 0 - bl sub_8153634 - cmp r0, 0x1 - bne _08185330 - movs r0, 0x1 - b _08185332 - .pool -_08185330: - movs r0, 0 -_08185332: - pop {r4,r5} - pop {r1} - bx r1 - thumb_func_end sub_81852F0 - - thumb_func_start MoveRecordedBattleToSaveData -MoveRecordedBattleToSaveData: @ 8185338 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0xC - movs r0, 0 - str r0, [sp, 0x4] - movs r0, 0xF8 - lsls r0, 4 - bl AllocZeroed - adds r7, r0, 0 - movs r0, 0x80 - lsls r0, 5 - bl AllocZeroed - str r0, [sp] - movs r6, 0 -_0818535E: - movs r0, 0x64 - adds r4, r6, 0 - muls r4, r0 - adds r5, r7, r4 - ldr r1, =sSavedPlayerParty - adds r1, r4, r1 - adds r0, r5, 0 - movs r2, 0x64 - bl memcpy - movs r1, 0x96 - lsls r1, 2 - adds r5, r1 - ldr r0, =sSavedOpponentParty - adds r4, r0 - adds r0, r5, 0 - adds r1, r4, 0 - movs r2, 0x64 - bl memcpy - adds r6, 0x1 - cmp r6, 0x5 - ble _0818535E - movs r6, 0 - ldr r2, =gSaveBlock2Ptr - mov r9, r2 - movs r3, 0x9A - lsls r3, 3 - adds r3, r7, r3 - str r3, [sp, 0x8] - ldr r5, =sRecordedBattle_Players - mov r8, r6 - mov r12, r6 - movs r4, 0x96 - lsls r4, 3 - adds r4, r7 - mov r10, r4 - ldr r0, =0x000004e4 - adds r4, r7, r0 -_081853AC: - lsls r1, r6, 3 - ldr r0, =sRecordedBattle_Players - adds r0, 0x4 - mov r3, r8 - adds r2, r3, r0 - add r1, r10 - movs r3, 0x7 -_081853BA: - ldrb r0, [r2] - strb r0, [r1] - adds r2, 0x1 - adds r1, 0x1 - subs r3, 0x1 - cmp r3, 0 - bge _081853BA - ldr r0, [sp, 0x8] - adds r1, r0, r6 - ldrb r0, [r5, 0xC] - strb r0, [r1] - ldrh r0, [r5, 0x10] - strb r0, [r4] - ldrh r0, [r5, 0xE] - strb r0, [r4, 0xC] - ldr r1, =0x000004d4 - adds r0, r7, r1 - add r0, r12 - ldr r1, [r5] - str r1, [r0] - adds r5, 0x14 - movs r2, 0x14 - add r8, r2 - movs r3, 0x4 - add r12, r3 - adds r4, 0x1 - adds r6, 0x1 - cmp r6, 0x3 - ble _081853AC - movs r4, 0x9D - lsls r4, 3 - adds r1, r7, r4 - ldr r5, =gRecordedBattleRngSeed - ldr r0, [r5] - str r0, [r1] - ldr r0, =sRecordedBattle_BattleFlags - ldr r2, [r0] - movs r0, 0x2 - ands r0, r2 - cmp r0, 0 - beq _081854DC - ldr r1, =0x000004ec - adds r3, r7, r1 - movs r1, 0x23 - negs r1, r1 - ands r1, r2 - movs r0, 0x80 - lsls r0, 18 - orrs r1, r0 - str r1, [r3] - movs r0, 0x4 - ands r0, r2 - cmp r0, 0 - beq _08185454 - movs r0, 0x80 - lsls r0, 24 - orrs r1, r0 - str r1, [r3] - b _081854E2 - .pool -_08185454: - movs r0, 0x40 - ands r2, r0 - cmp r2, 0 - beq _081854E2 - ldr r2, =sRecordedBattle_Players - ldrh r0, [r2, 0xE] - cmp r0, 0x1 - beq _081854A8 - cmp r0, 0x1 - bgt _08185474 - cmp r0, 0 - beq _0818547E - b _081854E2 - .pool -_08185474: - cmp r0, 0x2 - beq _0818547E - cmp r0, 0x3 - beq _081854A8 - b _081854E2 -_0818547E: - ldr r3, =gUnknown_0203C7B4 - ldrb r1, [r3] - lsls r0, r1, 2 - adds r0, r1 - lsls r0, 2 - ldr r4, =sRecordedBattle_Players - adds r0, r4 - ldrh r1, [r0, 0xE] - movs r0, 0x1 - ands r0, r1 - cmp r0, 0 - bne _081854E2 - ldr r5, =0x000004ec - adds r0, r7, r5 - b _081854C4 - .pool -_081854A8: - ldr r0, =gUnknown_0203C7B4 - ldrb r1, [r0] - lsls r0, r1, 2 - adds r0, r1 - lsls r0, 2 - ldr r1, =sRecordedBattle_Players - adds r0, r1 - ldrh r1, [r0, 0xE] - movs r0, 0x1 - ands r0, r1 - cmp r0, 0 - beq _081854E2 - ldr r2, =0x000004ec - adds r0, r7, r2 -_081854C4: - ldr r1, [r0] - movs r2, 0x80 - lsls r2, 24 - orrs r1, r2 - str r1, [r0] - b _081854E2 - .pool -_081854DC: - ldr r3, =0x000004ec - adds r0, r7, r3 - str r2, [r0] -_081854E2: - ldr r4, =gTrainerBattleOpponent_A - ldrh r1, [r4] - ldr r5, =0x000004f4 - adds r0, r7, r5 - strh r1, [r0] - ldr r0, =gTrainerBattleOpponent_B - ldrh r1, [r0] - ldr r2, =0x000004f6 - adds r0, r7, r2 - strh r1, [r0] - ldr r3, =gPartnerTrainerId - ldrh r1, [r3] - movs r4, 0x9F - lsls r4, 3 - adds r0, r7, r4 - strh r1, [r0] - ldr r5, =gUnknown_0203C7B4 - ldrb r1, [r5] - adds r2, 0x4 - adds r0, r7, r2 - strh r1, [r0] - mov r3, r9 - ldr r0, [r3] - ldr r4, =0x00000ca9 - adds r0, r4 - ldrb r0, [r0] - lsls r0, 30 - lsrs r0, 30 - ldr r5, =0x000004fc - adds r1, r7, r5 - strb r0, [r1] - ldr r0, =gUnknown_0203C7AE - ldrb r1, [r0] - adds r2, 0x3 - adds r0, r7, r2 - strb r1, [r0] - ldr r3, =gUnknown_0203C7AF - ldrb r1, [r3] - ldr r4, =0x000004fe - adds r0, r7, r4 - strb r1, [r0] - mov r5, r9 - ldr r0, [r5] - ldrb r1, [r0, 0x15] - lsls r1, 29 - ldr r0, =0x000004ff - adds r3, r7, r0 - lsrs r1, 31 - ldrb r2, [r3] - movs r0, 0x2 - negs r0, r0 - ands r0, r2 - orrs r0, r1 - strb r0, [r3] - ldr r1, [r5] - ldrb r1, [r1, 0x14] - lsls r1, 29 - lsrs r1, 28 - movs r2, 0xF - negs r2, r2 - ands r0, r2 - orrs r0, r1 - strb r0, [r3] - movs r2, 0xA0 - lsls r2, 3 - adds r1, r7, r2 - ldr r3, =sRecordedBattle_AI_Scripts - ldr r0, [r3] - str r0, [r1] - ldr r4, =0xfffffed4 - adds r1, r4, 0 - ldr r5, =gTrainerBattleOpponent_A - ldrh r5, [r5] - adds r0, r1, r5 - lsls r0, 16 - lsrs r0, 16 - cmp r0, 0x63 - bls _08185580 - b _081856C4 -_08185580: - movs r6, 0 - ldr r0, =0x00000504 - adds r3, r7, r0 - mov r10, r9 - ldr r1, =gTrainerBattleOpponent_A - mov r12, r1 - adds r2, r4, 0 - mov r8, r2 - ldr r4, =0x0000073c -_08185592: - adds r2, r3, r6 - mov r5, r10 - ldr r1, [r5] - mov r5, r12 - ldrh r0, [r5] - add r0, r8 - movs r5, 0xEC - muls r0, r5 - adds r0, r6, r0 - adds r1, r4 - adds r1, r0 - ldrb r0, [r1] - strb r0, [r2] - adds r6, 0x1 - cmp r6, 0x7 - ble _08185592 - mov r0, r9 - ldr r2, [r0] - ldr r1, =gTrainerBattleOpponent_A - ldrh r0, [r1] - ldr r3, =0xfffffed4 - adds r0, r3 - movs r1, 0xEC - muls r0, r1 - adds r2, r0 - ldr r4, =0x00000739 - adds r2, r4 - ldrb r1, [r2] - ldr r5, =0x0000050c - adds r0, r7, r5 - strb r1, [r0] - ldr r1, =gUnknown_0203CCE8 - ldrb r0, [r1] - cmp r0, 0x1 - bne _08185664 - movs r6, 0 - ldr r2, =0x0000050e - adds r4, r7, r2 - mov r10, r9 - ldr r5, =gTrainerBattleOpponent_A - mov r8, r5 - adds r5, r3, 0 -_081855E6: - lsls r3, r6, 1 - mov r0, r10 - ldr r2, [r0] - mov r1, r8 - ldrh r0, [r1] - adds r0, r5 - movs r1, 0xEC - muls r0, r1 - adds r3, r0 - movs r0, 0xEC - lsls r0, 3 - adds r2, r0 - adds r2, r3 - ldrh r0, [r2] - strh r0, [r4] - adds r4, 0x2 - adds r6, 0x1 - cmp r6, 0x5 - ble _081855E6 - b _08185696 - .pool -_08185664: - movs r6, 0 - ldr r1, =0x0000050e - adds r4, r7, r1 - mov r10, r9 - ldr r2, =gTrainerBattleOpponent_A - mov r8, r2 - adds r5, r3, 0 -_08185672: - lsls r3, r6, 1 - mov r0, r10 - ldr r2, [r0] - mov r1, r8 - ldrh r0, [r1] - adds r0, r5 - movs r1, 0xEC - muls r0, r1 - adds r3, r0 - ldr r0, =0x00000754 - adds r2, r0 - adds r2, r3 - ldrh r0, [r2] - strh r0, [r4] - adds r4, 0x2 - adds r6, 0x1 - cmp r6, 0x5 - ble _08185672 -_08185696: - mov r1, r9 - ldr r2, [r1] - ldr r3, =gTrainerBattleOpponent_A - ldrh r0, [r3] - ldr r4, =0xfffffed4 - adds r0, r4 - movs r1, 0xEC - muls r0, r1 - adds r2, r0 - ldr r5, =0x0000081c - adds r2, r5 - ldrb r1, [r2] - b _08185856 - .pool -_081856C4: - ldr r3, =gTrainerBattleOpponent_B - ldrh r3, [r3] - adds r0, r1, r3 - lsls r0, 16 - lsrs r0, 16 - cmp r0, 0x63 - bls _081856D4 - b _081857E4 -_081856D4: - movs r6, 0 - ldr r4, =0x00000504 - adds r3, r7, r4 - mov r10, r9 - ldr r5, =gTrainerBattleOpponent_B - mov r12, r5 - ldr r0, =0xfffffed4 - mov r8, r0 - ldr r4, =0x0000073c -_081856E6: - adds r2, r3, r6 - mov r5, r10 - ldr r1, [r5] - mov r5, r12 - ldrh r0, [r5] - add r0, r8 - movs r5, 0xEC - muls r0, r5 - adds r0, r6, r0 - adds r1, r4 - adds r1, r0 - ldrb r0, [r1] - strb r0, [r2] - adds r6, 0x1 - cmp r6, 0x7 - ble _081856E6 - mov r0, r9 - ldr r2, [r0] - ldr r1, =gTrainerBattleOpponent_B - ldrh r0, [r1] - ldr r3, =0xfffffed4 - adds r0, r3 - movs r1, 0xEC - muls r0, r1 - adds r2, r0 - ldr r4, =0x00000739 - adds r2, r4 - ldrb r1, [r2] - ldr r5, =0x0000050c - adds r0, r7, r5 - strb r1, [r0] - ldr r1, =gUnknown_0203CCE8 - ldrb r0, [r1] - cmp r0, 0x1 - bne _08185784 - movs r6, 0 - ldr r2, =0x0000050e - adds r4, r7, r2 - mov r10, r9 - ldr r5, =gTrainerBattleOpponent_B - mov r8, r5 - adds r5, r3, 0 -_0818573A: - lsls r3, r6, 1 - mov r0, r10 - ldr r2, [r0] - mov r1, r8 - ldrh r0, [r1] - adds r0, r5 - movs r1, 0xEC - muls r0, r1 - adds r3, r0 - movs r0, 0xEC - lsls r0, 3 - adds r2, r0 - adds r2, r3 - ldrh r0, [r2] - strh r0, [r4] - adds r4, 0x2 - adds r6, 0x1 - cmp r6, 0x5 - ble _0818573A - b _081857B6 - .pool -_08185784: - movs r6, 0 - ldr r1, =0x0000050e - adds r4, r7, r1 - mov r10, r9 - ldr r2, =gTrainerBattleOpponent_B - mov r8, r2 - adds r5, r3, 0 -_08185792: - lsls r3, r6, 1 - mov r0, r10 - ldr r2, [r0] - mov r1, r8 - ldrh r0, [r1] - adds r0, r5 - movs r1, 0xEC - muls r0, r1 - adds r3, r0 - ldr r0, =0x00000754 - adds r2, r0 - adds r2, r3 - ldrh r0, [r2] - strh r0, [r4] - adds r4, 0x2 - adds r6, 0x1 - cmp r6, 0x5 - ble _08185792 -_081857B6: - mov r1, r9 - ldr r2, [r1] - ldr r3, =gTrainerBattleOpponent_B - ldrh r0, [r3] - ldr r4, =0xfffffed4 - adds r0, r4 - movs r1, 0xEC - muls r0, r1 - adds r2, r0 - ldr r5, =0x0000081c - adds r2, r5 - ldrb r1, [r2] - b _08185856 - .pool -_081857E4: - ldr r3, =gPartnerTrainerId - ldrh r3, [r3] - adds r0, r1, r3 - lsls r0, 16 - lsrs r0, 16 - cmp r0, 0x63 - bhi _0818585C - movs r6, 0 - ldr r4, =0x00000504 - adds r3, r7, r4 - mov r10, r9 - ldr r5, =gPartnerTrainerId - mov r12, r5 - ldr r0, =0xfffffed4 - mov r8, r0 - ldr r4, =0x0000073c -_08185804: - adds r2, r3, r6 - mov r5, r10 - ldr r1, [r5] - mov r5, r12 - ldrh r0, [r5] - add r0, r8 - movs r5, 0xEC - muls r0, r5 - adds r0, r6, r0 - adds r1, r4 - adds r1, r0 - ldrb r0, [r1] - strb r0, [r2] - adds r6, 0x1 - cmp r6, 0x7 - ble _08185804 - mov r0, r9 - ldr r1, [r0] - ldr r2, =gPartnerTrainerId - ldrh r0, [r2] - ldr r3, =0xfffffed4 - adds r0, r3 - movs r2, 0xEC - muls r0, r2 - adds r1, r0 - ldr r4, =0x00000739 - adds r1, r4 - ldrb r1, [r1] - ldr r5, =0x0000050c - adds r0, r7, r5 - strb r1, [r0] - mov r0, r9 - ldr r1, [r0] - ldr r4, =gPartnerTrainerId - ldrh r0, [r4] - adds r0, r3 - muls r0, r2 - adds r1, r0 - ldr r5, =0x0000081c - adds r1, r5 - ldrb r1, [r1] -_08185856: - ldr r2, =0x0000051a - adds r0, r7, r2 - strb r1, [r0] -_0818585C: - ldr r3, =gTrainerBattleOpponent_A - ldrh r0, [r3] - ldr r1, =0x0000018f - cmp r0, r1 - bls _08185900 - mov r4, r9 - ldr r2, [r4] - adds r1, r0, 0 - ldr r3, =0xfffffe70 - adds r1, r3 - lsls r0, r1, 4 - adds r0, r1 - lsls r0, 2 - adds r2, r0 - adds r2, 0xDC - ldrb r0, [r2] - lsls r0, 27 - lsrs r0, 27 - ldr r5, =0x0000050d - adds r1, r7, r5 - strb r0, [r1] - movs r6, 0 - ldr r0, =0x0000050e - adds r4, r7, r0 - mov r10, r9 - ldr r1, =gTrainerBattleOpponent_A - mov r8, r1 - adds r5, r3, 0 -_08185894: - lsls r3, r6, 1 - mov r0, r10 - ldr r2, [r0] - mov r0, r8 - ldrh r1, [r0] - adds r1, r5 - lsls r0, r1, 4 - adds r0, r1 - lsls r0, 2 - adds r3, r0 - movs r1, 0x82 - lsls r1, 1 - adds r2, r1 - adds r2, r3 - ldrh r0, [r2] - strh r0, [r4] - adds r4, 0x2 - adds r6, 0x1 - cmp r6, 0x5 - ble _08185894 - mov r3, r9 - ldr r2, [r3] - ldr r4, =gTrainerBattleOpponent_A - ldrh r1, [r4] - ldr r5, =0xfffffe70 - adds r1, r5 - b _081859AC - .pool -_08185900: - ldr r3, =gTrainerBattleOpponent_B - ldrh r0, [r3] - cmp r0, r1 - bls _0818597C - mov r4, r9 - ldr r2, [r4] - adds r1, r0, 0 - ldr r3, =0xfffffe70 - adds r1, r3 - lsls r0, r1, 4 - adds r0, r1 - lsls r0, 2 - adds r2, r0 - adds r2, 0xDC - ldrb r0, [r2] - lsls r0, 27 - lsrs r0, 27 - ldr r5, =0x0000050d - adds r1, r7, r5 - strb r0, [r1] - movs r6, 0 - ldr r0, =0x0000050e - adds r4, r7, r0 - mov r10, r9 - ldr r1, =gTrainerBattleOpponent_B - mov r8, r1 - adds r5, r3, 0 -_08185936: - lsls r3, r6, 1 - mov r0, r10 - ldr r2, [r0] - mov r0, r8 - ldrh r1, [r0] - adds r1, r5 - lsls r0, r1, 4 - adds r0, r1 - lsls r0, 2 - adds r3, r0 - movs r1, 0x82 - lsls r1, 1 - adds r2, r1 - adds r2, r3 - ldrh r0, [r2] - strh r0, [r4] - adds r4, 0x2 - adds r6, 0x1 - cmp r6, 0x5 - ble _08185936 - mov r3, r9 - ldr r2, [r3] - ldr r4, =gTrainerBattleOpponent_B - ldrh r1, [r4] - ldr r5, =0xfffffe70 - adds r1, r5 - b _081859AC - .pool -_0818597C: - ldr r3, =gPartnerTrainerId - ldrh r0, [r3] - cmp r0, r1 - bls _081859C0 - mov r4, r9 - ldr r2, [r4] - adds r1, r0, 0 - ldr r3, =0xfffffe70 - adds r1, r3 - lsls r0, r1, 4 - adds r0, r1 - lsls r0, 2 - adds r2, r0 - adds r2, 0xDC - ldrb r0, [r2] - lsls r0, 27 - lsrs r0, 27 - ldr r5, =0x0000050d - adds r1, r7, r5 - strb r0, [r1] - ldr r2, [r4] - ldr r0, =gPartnerTrainerId - ldrh r1, [r0] - adds r1, r3 -_081859AC: - lsls r0, r1, 4 - adds r0, r1 - lsls r0, 2 - adds r2, r0 - ldr r1, =0x0000011b - adds r0, r2, r1 - ldrb r1, [r0] - ldr r2, =0x0000051b - adds r0, r7, r2 - strb r1, [r0] -_081859C0: - movs r6, 0 - ldr r3, =0x00000297 - mov r10, r3 - ldr r4, =sBattleRecords - mov r9, r4 - movs r5, 0xA6 - lsls r5, 2 - mov r8, r5 - ldr r0, =0x0000051c - adds r5, r7, r0 -_081859D4: - adds r4, r6, 0x1 - mov r0, r8 - muls r0, r6 - mov r1, r9 - adds r2, r0, r1 - adds r1, r0, r5 - mov r3, r10 - adds r3, 0x1 -_081859E4: - ldrb r0, [r2] - strb r0, [r1] - adds r2, 0x1 - adds r1, 0x1 - subs r3, 0x1 - cmp r3, 0 - bne _081859E4 - adds r6, r4, 0 - cmp r6, 0x3 - ble _081859D4 -_081859F8: - adds r0, r7, 0 - ldr r1, [sp] - bl sub_81852F0 - adds r4, r0, 0 - cmp r4, 0x1 - beq _08185A14 - ldr r0, [sp, 0x4] - adds r0, 0x1 - lsls r0, 24 - lsrs r0, 24 - str r0, [sp, 0x4] - cmp r0, 0x2 - bls _081859F8 -_08185A14: - adds r0, r7, 0 - bl Free - ldr r0, [sp] - bl Free - adds r0, r4, 0 - add sp, 0xC - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r1} - bx r1 - .pool - thumb_func_end MoveRecordedBattleToSaveData - - thumb_func_start sub_8185A54 -sub_8185A54: @ 8185A54 - push {r4,r5,lr} - adds r5, r0, 0 - adds r4, r1, 0 - movs r0, 0x1F - bl sub_81535DC - cmp r0, 0x1 - bne _08185A7E - movs r2, 0xF8 - lsls r2, 4 - adds r0, r5, 0 - adds r1, r4, 0 - bl memcpy - adds r0, r5, 0 - bl sub_81852B0 - cmp r0, 0 - beq _08185A7E - movs r0, 0x1 - b _08185A80 -_08185A7E: - movs r0, 0 -_08185A80: - pop {r4,r5} - pop {r1} - bx r1 - thumb_func_end sub_8185A54 - - thumb_func_start start_ov_to_battle_anim -start_ov_to_battle_anim: @ 8185A88 - push {r4,r5,lr} - adds r4, r0, 0 - movs r0, 0x80 - lsls r0, 5 - bl AllocZeroed - adds r5, r0, 0 - adds r0, r4, 0 - adds r1, r5, 0 - bl sub_8185A54 - adds r4, r0, 0 - adds r0, r5, 0 - bl Free - adds r0, r4, 0 - pop {r4,r5} - pop {r1} - bx r1 - thumb_func_end start_ov_to_battle_anim - - thumb_func_start sub_8185AB0 -sub_8185AB0: @ 8185AB0 - push {lr} - ldr r0, =gSaveBlock2Ptr - ldr r2, [r0] - ldr r0, =gUnknown_0203C7AD - ldrb r0, [r0] - ldr r1, =0x00000ca9 - adds r2, r1 - movs r1, 0x3 - ands r1, r0 - ldrb r3, [r2] - movs r0, 0x4 - negs r0, r0 - ands r0, r3 - orrs r0, r1 - strb r0, [r2] - ldr r1, =gBattleOutcome - movs r0, 0 - strb r0, [r1] - ldr r0, =gBattleTypeFlags - movs r1, 0 - str r1, [r0] - ldr r0, =gTrainerBattleOpponent_A - strh r1, [r0] - ldr r0, =gTrainerBattleOpponent_B - strh r1, [r0] - ldr r0, =gPartnerTrainerId - strh r1, [r0] - bl sub_8185EFC - ldr r0, =sRecordedBattle_Callback2 - ldr r0, [r0] - bl SetMainCallback2 - pop {r0} - bx r0 - .pool - thumb_func_end sub_8185AB0 - - thumb_func_start sub_8185B1C -sub_8185B1C: @ 8185B1C - push {r4,lr} - lsls r0, 24 - lsrs r4, r0, 24 - ldr r1, =gTasks - lsls r0, r4, 2 - adds r0, r4 - lsls r0, 3 - adds r0, r1 - ldrh r1, [r0, 0x8] - subs r1, 0x1 - strh r1, [r0, 0x8] - lsls r1, 16 - cmp r1, 0 - bne _08185B4A - ldr r0, =gMain - ldr r1, =sub_8185AB0 - str r1, [r0, 0x8] - ldr r0, =CB2_InitBattle - bl SetMainCallback2 - adds r0, r4, 0 - bl DestroyTask -_08185B4A: - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8185B1C - - thumb_func_start sub_8185B60 -sub_8185B60: @ 8185B60 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x4 - adds r7, r0, 0 - bl ZeroPlayerPartyMons - bl ZeroEnemyPartyMons - movs r6, 0 - ldr r0, =gPlayerParty - mov r8, r0 -_08185B7C: - movs r0, 0x64 - adds r4, r6, 0 - muls r4, r0 - mov r1, r8 - adds r0, r4, r1 - adds r5, r7, r4 - adds r1, r5, 0 - movs r2, 0x64 - bl memcpy - ldr r0, =gEnemyParty - adds r4, r0 - movs r2, 0x96 - lsls r2, 2 - adds r5, r2 - adds r0, r4, 0 - adds r1, r5, 0 - movs r2, 0x64 - bl memcpy - adds r6, 0x1 - cmp r6, 0x5 - ble _08185B7C - movs r6, 0 - ldr r3, =gLinkPlayers - mov r8, r3 - mov r0, r8 - adds r0, 0x8 - str r0, [sp] - mov r4, r8 - adds r4, 0x4 - mov r10, r6 - mov r9, r6 -_08185BBE: - movs r1, 0 - mov r12, r1 - lsls r5, r6, 2 - movs r2, 0x96 - lsls r2, 3 - adds r0, r7, r2 - mov r3, r9 - adds r2, r3, r0 - mov r0, r10 - lsls r1, r0, 2 - mov r0, r8 - adds r0, 0x8 - adds r1, r0 - movs r3, 0x7 -_08185BDA: - ldrb r0, [r2] - strb r0, [r1] - ldrb r0, [r2] - cmp r0, 0xFF - bne _08185BE8 - movs r0, 0x1 - mov r12, r0 -_08185BE8: - adds r2, 0x1 - adds r1, 0x1 - subs r3, 0x1 - cmp r3, 0 - bge _08185BDA - movs r1, 0x9A - lsls r1, 3 - adds r0, r7, r1 - adds r0, r6 - ldrb r0, [r0] - strb r0, [r4, 0xF] - ldr r2, =0x000004e4 - adds r0, r7, r2 - adds r0, r6 - ldrb r1, [r0] - strh r1, [r4, 0x16] - movs r3, 0x9E - lsls r3, 3 - adds r0, r7, r3 - adds r0, r6 - ldrb r0, [r0] - strh r0, [r4, 0x14] - subs r2, 0x10 - adds r0, r7, r2 - adds r0, r5 - ldr r0, [r0] - str r0, [r4] - mov r3, r12 - cmp r3, 0 - beq _08185C2A - ldr r0, [sp] - bl ConvertInternationalString -_08185C2A: - ldr r0, [sp] - adds r0, 0x1C - str r0, [sp] - adds r4, 0x1C - movs r1, 0x7 - add r10, r1 - movs r2, 0x8 - add r9, r2 - adds r6, 0x1 - cmp r6, 0x3 - ble _08185BBE - ldr r1, =gRecordedBattleRngSeed - movs r3, 0x9D - lsls r3, 3 - adds r0, r7, r3 - ldr r0, [r0] - str r0, [r1] - ldr r2, =gBattleTypeFlags - ldr r1, =0x000004ec - adds r0, r7, r1 - ldr r0, [r0] - movs r1, 0x80 - lsls r1, 17 - orrs r0, r1 - str r0, [r2] - ldr r1, =gTrainerBattleOpponent_A - ldr r2, =0x000004f4 - adds r0, r7, r2 - ldrh r0, [r0] - strh r0, [r1] - ldr r1, =gTrainerBattleOpponent_B - adds r3, 0xE - adds r0, r7, r3 - ldrh r0, [r0] - strh r0, [r1] - ldr r1, =gPartnerTrainerId - adds r2, 0x4 - adds r0, r7, r2 - ldrh r0, [r0] - strh r0, [r1] - ldr r1, =gUnknown_0203C7B4 - adds r3, 0x4 - adds r0, r7, r3 - ldrh r0, [r0] - strb r0, [r1] - ldr r1, =gUnknown_0203C7AD - ldr r3, =gSaveBlock2Ptr - ldr r0, [r3] - ldr r2, =0x00000ca9 - adds r0, r2 - ldrb r0, [r0] - lsls r0, 30 - lsrs r0, 30 - strb r0, [r1] - ldr r1, =gUnknown_0203C7AE - ldr r2, =0x000004fd - adds r0, r7, r2 - ldrb r0, [r0] - strb r0, [r1] - ldr r1, =gUnknown_0203C7AF - adds r2, 0x1 - adds r0, r7, r2 - ldrb r0, [r0] - strb r0, [r1] - ldr r2, =gUnknown_0203C7B6 - ldr r1, =0x000004ff - adds r0, r7, r1 - ldrb r1, [r0] - lsls r0, r1, 31 - lsrs r0, 31 - strb r0, [r2] - ldr r0, =gUnknown_0203C7B7 - lsls r1, 28 - lsrs r1, 29 - strb r1, [r0] - ldr r1, =sRecordedBattle_AI_Scripts - movs r2, 0xA0 - lsls r2, 3 - adds r0, r7, r2 - ldr r0, [r0] - str r0, [r1] - movs r6, 0 - mov r10, r3 - ldr r2, =gUnknown_0203CCD9 - ldr r3, =gUnknown_0203CCDA - ldr r0, =gUnknown_03001278 - mov r8, r0 - ldr r1, =gUnknown_03001279 - mov r9, r1 - ldr r5, =gUnknown_0203CCD1 - ldr r0, =0x00000504 - adds r4, r7, r0 -_08185CE2: - adds r0, r6, r5 - adds r1, r4, r6 - ldrb r1, [r1] - strb r1, [r0] - adds r6, 0x1 - cmp r6, 0x7 - ble _08185CE2 - ldr r1, =0x0000050c - adds r0, r7, r1 - ldrb r0, [r0] - strb r0, [r2] - ldr r2, =0x0000050d - adds r0, r7, r2 - ldrb r0, [r0] - strb r0, [r3] - ldr r3, =0x0000051a - adds r0, r7, r3 - ldrb r0, [r0] - mov r1, r8 - strb r0, [r1] - adds r2, 0xE - adds r0, r7, r2 - ldrb r0, [r0] - mov r3, r9 - strb r0, [r3] - ldr r0, =0x0000050e - adds r1, r7, r0 - ldr r4, =gUnknown_0203CCDC - movs r6, 0x5 -_08185D1C: - ldrh r0, [r1] - strh r0, [r4] - adds r1, 0x2 - adds r4, 0x2 - subs r6, 0x1 - cmp r6, 0 - bge _08185D1C - mov r1, r10 - ldr r2, [r1] - ldr r3, =0x000004fc - adds r0, r7, r3 - ldrb r0, [r0] - ldr r1, =0x00000ca9 - adds r2, r1 - movs r1, 0x3 - ands r1, r0 - ldrb r3, [r2] - movs r0, 0x4 - negs r0, r0 - ands r0, r3 - orrs r0, r1 - strb r0, [r2] - movs r6, 0 - ldr r2, =0x00000297 - mov r10, r2 - ldr r3, =sBattleRecords - mov r9, r3 - movs r0, 0xA6 - lsls r0, 2 - mov r8, r0 - ldr r1, =0x0000051c - adds r5, r7, r1 -_08185D5C: - adds r2, r6, 0x1 - mov r0, r8 - muls r0, r6 - adds r1, r0, r5 - mov r3, r9 - adds r4, r0, r3 - mov r3, r10 - adds r3, 0x1 -_08185D6C: - ldrb r0, [r1] - strb r0, [r4] - adds r1, 0x1 - adds r4, 0x1 - subs r3, 0x1 - cmp r3, 0 - bne _08185D6C - adds r6, r2, 0 - cmp r6, 0x3 - ble _08185D5C - add sp, 0x4 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8185B60 - - thumb_func_start sub_8185E24 -sub_8185E24: @ 8185E24 - push {r4,r5,lr} - adds r5, r0, 0 - movs r0, 0xF8 - lsls r0, 4 - bl AllocZeroed - adds r4, r0, 0 - bl start_ov_to_battle_anim - cmp r0, 0x1 - bne _08185E6E - bl sub_8185EB8 - adds r0, r4, 0 - bl sub_8185B60 - ldr r0, =sub_8185B1C - movs r1, 0x1 - bl CreateTask - lsls r0, 24 - lsrs r0, 24 - ldr r2, =gTasks - lsls r1, r0, 2 - adds r1, r0 - lsls r1, 3 - adds r1, r2 - movs r0, 0x80 - strh r0, [r1, 0x8] - ldr r0, =sRecordedBattle_Callback2 - str r5, [r0] - movs r0, 0 - bl PlayMapChosenOrBattleBGM - ldr r0, =sub_8185E8C - bl SetMainCallback2 -_08185E6E: - adds r0, r4, 0 - bl Free - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8185E24 - - thumb_func_start sub_8185E8C -sub_8185E8C: @ 8185E8C - push {lr} - bl AnimateSprites - bl BuildOamBuffer - bl RunTasks - pop {r0} - bx r0 - thumb_func_end sub_8185E8C - - thumb_func_start sub_8185EA0 -sub_8185EA0: @ 8185EA0 - ldr r0, =gUnknown_0203C7AE - ldrb r0, [r0] - bx lr - .pool - thumb_func_end sub_8185EA0 - - thumb_func_start sub_8185EAC -sub_8185EAC: @ 8185EAC - ldr r0, =gUnknown_0203C7AF - ldrb r0, [r0] - bx lr - .pool - thumb_func_end sub_8185EAC - - thumb_func_start sub_8185EB8 -sub_8185EB8: @ 8185EB8 - push {r4-r6,lr} - movs r5, 0 - ldr r6, =sSavedPlayerParty -_08185EBE: - movs r0, 0x64 - adds r4, r5, 0 - muls r4, r0 - adds r0, r4, r6 - ldr r1, =gPlayerParty - adds r1, r4, r1 - movs r2, 0x64 - bl memcpy - ldr r0, =sSavedOpponentParty - adds r0, r4, r0 - ldr r1, =gEnemyParty - adds r4, r1 - adds r1, r4, 0 - movs r2, 0x64 - bl memcpy - adds r5, 0x1 - cmp r5, 0x5 - ble _08185EBE - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8185EB8 - - thumb_func_start sub_8185EFC -sub_8185EFC: @ 8185EFC - push {r4-r6,lr} - movs r5, 0 - ldr r6, =gPlayerParty -_08185F02: - movs r0, 0x64 - adds r4, r5, 0 - muls r4, r0 - adds r0, r4, r6 - ldr r1, =sSavedPlayerParty - adds r1, r4, r1 - movs r2, 0x64 - bl memcpy - ldr r0, =gEnemyParty - adds r0, r4, r0 - ldr r1, =sSavedOpponentParty - adds r4, r1 - adds r1, r4, 0 - movs r2, 0x64 - bl memcpy - adds r5, 0x1 - cmp r5, 0x5 - ble _08185F02 - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8185EFC - - thumb_func_start sub_8185F40 -sub_8185F40: @ 8185F40 - push {r4,r5,lr} - movs r2, 0 - ldr r0, =gLinkPlayers - ldr r3, =gActiveBank - ldrh r1, [r0, 0x18] - adds r4, r0, 0 - ldrb r0, [r3] - cmp r1, r0 - beq _08185F64 - adds r1, r4, 0 -_08185F54: - adds r1, 0x1C - adds r2, 0x1 - cmp r2, 0x3 - bgt _08185F64 - ldrh r0, [r1, 0x18] - ldrb r5, [r3] - cmp r0, r5 - bne _08185F54 -_08185F64: - cmp r2, 0x4 - bne _08185F74 - movs r0, 0 - b _08185F7E - .pool -_08185F74: - lsls r0, r2, 3 - subs r0, r2 - lsls r0, 2 - adds r0, r4 - ldrb r0, [r0, 0x13] -_08185F7E: - pop {r4,r5} - pop {r1} - bx r1 - thumb_func_end sub_8185F40 - - thumb_func_start sub_8185F84 -sub_8185F84: @ 8185F84 - ldr r1, =gUnknown_0203C7B5 - movs r0, 0 - strb r0, [r1] - bx lr - .pool - thumb_func_end sub_8185F84 - - thumb_func_start sub_8185F90 -sub_8185F90: @ 8185F90 - lsls r0, 16 - lsrs r0, 16 - ldr r2, =gUnknown_0203C7B5 - movs r1, 0x80 - lsls r1, 8 - ands r0, r1 - lsls r0, 16 - lsrs r0, 31 - ldrb r1, [r2] - orrs r0, r1 - strb r0, [r2] - bx lr - .pool - thumb_func_end sub_8185F90 - - thumb_func_start sub_8185FAC -sub_8185FAC: @ 8185FAC - ldr r0, =gUnknown_0203C7B5 - ldrb r0, [r0] - bx lr - .pool - thumb_func_end sub_8185FAC - - thumb_func_start sub_8185FB8 -sub_8185FB8: @ 8185FB8 - ldr r0, =gUnknown_0203C7B6 - ldrb r0, [r0] - bx lr - .pool - thumb_func_end sub_8185FB8 - - thumb_func_start sub_8185FC4 -sub_8185FC4: @ 8185FC4 - ldr r0, =gUnknown_0203C7B7 - ldrb r0, [r0] - bx lr - .pool - thumb_func_end sub_8185FC4 - - thumb_func_start sub_8185FD0 -sub_8185FD0: @ 8185FD0 - push {r4-r7,lr} - ldr r4, =gActiveBank - ldrb r0, [r4] - bl GetBankSide - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x1 - beq _0818601C - ldr r0, =gBattleTypeFlags - ldr r0, [r0] - ldr r1, =0x02000002 - ands r0, r1 - cmp r0, 0 - bne _0818601C - ldr r0, =gUnknown_0203C7AC - ldrb r0, [r0] - cmp r0, 0x2 - beq _0818601C - movs r3, 0 - ldr r7, =gUnknown_0203CC70 - adds r6, r4, 0 - ldr r5, =gBattleMons + 0xC - movs r4, 0x58 -_08186000: - lsls r2, r3, 1 - ldrb r1, [r6] - lsrs r0, r1, 1 - lsls r0, 3 - adds r0, r2, r0 - adds r0, r7 - muls r1, r4 - adds r2, r1 - adds r2, r5 - ldrh r1, [r2] - strh r1, [r0] - adds r3, 0x1 - cmp r3, 0x3 - ble _08186000 -_0818601C: - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8185FD0 - - thumb_func_start sub_818603C -sub_818603C: @ 818603C - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x50 - lsls r0, 24 - lsrs r0, 24 - str r0, [sp, 0x24] - ldr r0, =gBattleTypeFlags - ldr r0, [r0] - ldr r1, =0x02000002 - ands r0, r1 - cmp r0, 0 - beq _0818605C - b _081863FC -_0818605C: - movs r0, 0 - mov r10, r0 - b _081863F2 - .pool -_0818606C: - mov r1, r10 - lsls r4, r1, 24 - lsrs r5, r4, 24 - adds r0, r5, 0 - bl GetBankSide - lsls r0, 24 - lsrs r0, 24 - str r4, [sp, 0x4C] - mov r2, r10 - adds r2, 0x1 - str r2, [sp, 0x38] - cmp r0, 0x1 - bne _0818608A - b _081863EE -_0818608A: - ldr r3, [sp, 0x24] - cmp r3, 0x1 - bne _0818611E - movs r5, 0 - ldr r4, =gUnknown_0203CC70 - mov r0, r10 - asrs r6, r0, 31 - subs r0, r6 - asrs r0, 1 - lsls r0, 3 - adds r2, r0, r4 - movs r1, 0x58 - mov r0, r10 - muls r0, r1 - ldr r3, =gBattleMons + 0xC - adds r1, r0, r3 -_081860AA: - ldrh r0, [r1] - ldrh r4, [r2] - cmp r0, r4 - bne _081860BC - adds r2, 0x2 - adds r1, 0x2 - adds r5, 0x1 - cmp r5, 0x3 - ble _081860AA -_081860BC: - cmp r5, 0x4 - bne _081860C2 - b _081863EE -_081860C2: - ldr r1, [sp, 0x4C] - lsrs r0, r1, 24 - movs r1, 0x6 - bl RecordedBattle_SetBankAction - movs r5, 0 - ldr r2, =gUnknown_0203CC70 - mov r8, r2 - movs r3, 0x58 - mov r7, r10 - muls r7, r3 - mov r4, r10 - subs r0, r4, r6 - asrs r4, r0, 1 -_081860DE: - movs r2, 0 - lsls r0, r5, 1 - adds r5, 0x1 - adds r0, r7 - ldr r1, =gBattleMons + 0xC - adds r3, r0, r1 - lsls r0, r4, 3 - mov r6, r8 - adds r1, r0, r6 -_081860F0: - ldrh r0, [r3] - ldrh r6, [r1] - cmp r0, r6 - bne _08186110 - lsls r1, r2, 24 - lsrs r1, 24 - ldr r2, [sp, 0x4C] - lsrs r0, r2, 24 - bl RecordedBattle_SetBankAction - b _08186118 - .pool -_08186110: - adds r1, 0x2 - adds r2, 0x1 - cmp r2, 0x3 - ble _081860F0 -_08186118: - cmp r5, 0x3 - ble _081860DE - b _081863EE -_0818611E: - ldr r3, =sBattleRecords - ldr r1, =sRecordedBytesNo - mov r4, r10 - lsls r2, r4, 1 - adds r1, r2, r1 - movs r0, 0xA6 - lsls r0, 2 - mov r6, r10 - muls r6, r0 - adds r0, r6, 0 - ldrh r1, [r1] - adds r0, r1 - adds r0, r3 - ldrb r0, [r0] - str r2, [sp, 0x44] - cmp r0, 0x6 - beq _08186142 - b _081863EE -_08186142: - adds r0, r5, 0 - bl RecordedBattle_ReadBankAction - movs r5, 0 - mov r0, sp - adds r0, 0x4 - str r0, [sp, 0x28] - mov r1, sp - adds r1, 0xC - str r1, [sp, 0x30] - mov r2, sp - adds r2, 0x14 - str r2, [sp, 0x34] - mov r3, sp - adds r3, 0x18 - str r3, [sp, 0x3C] - mov r4, sp - adds r4, 0x8 - str r4, [sp, 0x2C] - mov r6, r10 - lsls r6, 3 - str r6, [sp, 0x48] - movs r1, 0x58 - mov r0, r10 - muls r0, r1 - ldr r2, =gBattleMons - adds r0, r2 - adds r6, r0, 0 - adds r6, 0x3B - movs r4, 0x3 -_0818617E: - mov r0, sp - adds r3, r0, r5 - ldrb r1, [r6] - lsls r2, r5, 1 - adds r0, r4, 0 - lsls r0, r2 - ands r1, r0 - asrs r1, r2 - strb r1, [r3] - adds r5, 0x1 - cmp r5, 0x3 - ble _0818617E - movs r5, 0 - ldr r1, =gBattleMons - mov r9, r1 - movs r2, 0x58 - mov r7, r10 - muls r7, r2 - ldr r4, [sp, 0x28] - ldr r6, [sp, 0x30] -_081861A6: - ldr r3, [sp, 0x4C] - lsrs r0, r3, 24 - bl RecordedBattle_ReadBankAction - strb r0, [r4] - ldrb r0, [r4] - lsls r0, 1 - adds r0, r7 - movs r1, 0xC - add r1, r9 - mov r8, r1 - add r0, r8 - ldrh r0, [r0] - strh r0, [r6] - ldr r2, [sp, 0x34] - adds r1, r2, r5 - ldrb r0, [r4] - adds r0, r7 - ldr r3, =gBattleMons + 0x24 - adds r0, r3 - ldrb r0, [r0] - strb r0, [r1] - ldr r0, [sp, 0x3C] - adds r1, r0, r5 - ldrb r0, [r4] - add r0, sp - ldrb r0, [r0] - strb r0, [r1] - ldr r1, [sp, 0x2C] - adds r3, r1, r5 - ldr r2, [sp, 0x48] - mov r1, r10 - subs r0, r2, r1 - lsls r0, 2 - ldr r2, =gDisableStructs - adds r0, r2 - ldrb r1, [r0, 0x18] - lsrs r1, 4 - ldr r2, =gBitTable - lsls r0, r5, 2 - adds r0, r2 - ldr r0, [r0] - ands r1, r0 - lsrs r1, r5 - strb r1, [r3] - adds r4, 0x1 - adds r6, 0x2 - adds r5, 0x1 - cmp r5, 0x3 - ble _081861A6 - movs r5, 0 - movs r3, 0xC - negs r3, r3 - add r3, r8 - mov r12, r3 - ldr r4, =gDisableStructs - mov r9, r4 - movs r6, 0x58 - mov r1, r10 - muls r1, r6 - mov r0, r8 - adds r0, 0x18 - adds r4, r1, r0 - adds r3, r1, 0 - mov r7, r8 - ldr r6, [sp, 0x34] - ldr r2, [sp, 0x30] -_0818622C: - adds r1, r3, r7 - ldrh r0, [r2] - strh r0, [r1] - adds r0, r6, r5 - ldrb r0, [r0] - strb r0, [r4] - adds r4, 0x1 - adds r3, 0x2 - adds r2, 0x2 - adds r5, 0x1 - cmp r5, 0x3 - ble _0818622C - movs r0, 0x58 - mov r4, r10 - muls r4, r0 - mov r1, r12 - adds r0, r4, r1 - adds r0, 0x3B - movs r1, 0 - strb r1, [r0] - ldr r2, [sp, 0x48] - mov r6, r10 - subs r3, r2, r6 - lsls r3, 2 - mov r0, r9 - adds r2, r3, r0 - ldrb r1, [r2, 0x18] - movs r0, 0xF - ands r0, r1 - strb r0, [r2, 0x18] - movs r5, 0 - ldr r1, =gBattleMons - adds r4, r1 - adds r4, 0x3B - ldr r0, =gDisableStructs - adds r6, r3, r0 -_08186274: - ldr r2, [sp, 0x3C] - adds r0, r2, r5 - ldrb r0, [r0] - lsls r1, r5, 1 - lsls r0, r1 - ldrb r1, [r4] - orrs r0, r1 - strb r0, [r4] - ldrb r2, [r6, 0x18] - lsrs r3, r2, 4 - ldr r1, [sp, 0x2C] - adds r0, r1, r5 - ldrb r1, [r0] - lsls r1, r5 - orrs r1, r3 - lsls r1, 4 - movs r0, 0xF - ands r0, r2 - orrs r0, r1 - strb r0, [r6, 0x18] - adds r5, 0x1 - cmp r5, 0x3 - ble _08186274 - movs r2, 0x58 - mov r0, r10 - muls r0, r2 - mov r1, r12 - adds r1, 0x50 - adds r0, r1 - ldr r0, [r0] - movs r1, 0x80 - lsls r1, 14 - ands r0, r1 - cmp r0, 0 - beq _081862BC - b _081863CA -_081862BC: - movs r5, 0 - mov r3, sp - adds r3, 0x20 - str r3, [sp, 0x40] - ldr r0, =gBattlePartyID - ldr r4, [sp, 0x44] - adds r6, r4, r0 -_081862CA: - ldrh r1, [r6] - movs r0, 0x64 - muls r0, r1 - ldr r4, =gPlayerParty - adds r0, r4 - movs r1, 0x15 - movs r2, 0 - bl GetMonData - mov r1, sp - adds r3, r1, r5 - lsls r2, r5, 1 - movs r1, 0x3 - lsls r1, r2 - ands r0, r1 - lsrs r0, r2 - strb r0, [r3] - adds r5, 0x1 - cmp r5, 0x3 - ble _081862CA - movs r5, 0 - ldr r0, =gBattlePartyID - ldr r2, [sp, 0x44] - adds r7, r2, r0 - movs r3, 0x64 - mov r9, r3 - mov r8, r4 - ldr r4, [sp, 0x28] - ldr r6, [sp, 0x30] -_08186304: - ldrh r0, [r7] - mov r1, r9 - muls r1, r0 - adds r0, r1, 0 - add r0, r8 - ldrb r1, [r4] - adds r1, 0xD - movs r2, 0 - bl GetMonData - strh r0, [r6] - ldrh r0, [r7] - mov r2, r9 - muls r2, r0 - adds r0, r2, 0 - add r0, r8 - ldrb r1, [r4] - adds r1, 0x11 - movs r2, 0 - bl GetMonData - ldr r3, [sp, 0x34] - adds r1, r3, r5 - strb r0, [r1] - ldr r0, [sp, 0x3C] - adds r1, r0, r5 - ldrb r0, [r4] - add r0, sp - ldrb r0, [r0] - strb r0, [r1] - adds r4, 0x1 - adds r6, 0x2 - adds r5, 0x1 - cmp r5, 0x3 - ble _08186304 - movs r5, 0 - ldr r0, =gBattlePartyID - ldr r1, [sp, 0x44] - adds r7, r1, r0 - movs r2, 0x64 - mov r9, r2 - ldr r3, =gPlayerParty - mov r8, r3 - ldr r6, [sp, 0x30] - adds r6, 0x8 - ldr r4, [sp, 0x30] -_08186360: - ldrh r0, [r7] - mov r1, r9 - muls r1, r0 - adds r0, r1, 0 - add r0, r8 - adds r1, r5, 0 - adds r1, 0xD - adds r2, r4, 0 - bl SetMonData - ldrh r0, [r7] - mov r2, r9 - muls r2, r0 - adds r0, r2, 0 - add r0, r8 - adds r1, r5, 0 - adds r1, 0x11 - adds r2, r6, 0 - bl SetMonData - adds r6, 0x1 - adds r4, 0x2 - adds r5, 0x1 - cmp r5, 0x3 - ble _08186360 - movs r0, 0 - ldr r3, [sp, 0x40] - strb r0, [r3] - movs r5, 0 - ldr r4, =gBattlePartyID - ldr r6, =gPlayerParty - ldr r3, [sp, 0x3C] - ldr r2, [sp, 0x40] -_081863A2: - adds r0, r3, r5 - ldrb r1, [r0] - lsls r0, r5, 1 - lsls r1, r0 - ldrb r0, [r2] - orrs r0, r1 - strb r0, [r2] - adds r5, 0x1 - cmp r5, 0x3 - ble _081863A2 - ldr r1, [sp, 0x44] - adds r0, r1, r4 - ldrh r1, [r0] - movs r0, 0x64 - muls r0, r1 - adds r0, r6 - movs r1, 0x15 - ldr r2, [sp, 0x40] - bl SetMonData -_081863CA: - ldr r2, =gChosenMovesByBanks - ldr r3, [sp, 0x44] - adds r2, r3, r2 - ldr r0, =gBattleStruct - ldr r0, [r0] - add r0, r10 - adds r0, 0x80 - ldrb r0, [r0] - lsls r0, 1 - movs r4, 0x58 - mov r1, r10 - muls r1, r4 - adds r0, r1 - ldr r1, =gBattleMons - adds r1, 0xC - adds r0, r1 - ldrh r0, [r0] - strh r0, [r2] -_081863EE: - ldr r6, [sp, 0x38] - mov r10, r6 -_081863F2: - ldr r0, =gNoOfAllBanks - ldrb r0, [r0] - cmp r10, r0 - bge _081863FC - b _0818606C -_081863FC: - add sp, 0x50 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_818603C thumb_func_start GetAiScriptsInRecordedBattle GetAiScriptsInRecordedBattle: @ 8186438 diff --git a/asm/trainer_card.s b/asm/trainer_card.s index bee1f4f7f..84d0cceab 100644 --- a/asm/trainer_card.s +++ b/asm/trainer_card.s @@ -5000,7 +5000,7 @@ _080C5240: adds r0, r2 ldrh r0, [r0] strh r0, [r1, 0x6] - bl sub_8185290 + bl CanCopyRecordedBattleSaveData ldr r3, [r5] movs r1, 0x1 ands r0, r1 @@ -5825,7 +5825,7 @@ _080C5970: strh r0, [r1, 0x6] bl sub_80C52E4 ldr r0, =sub_80C58D4 - bl sub_8185E24 + bl PlayRecordedBattle b _080C599A .pool _080C5994: diff --git a/include/global.h b/include/global.h index f544ab701..280002896 100644 --- a/include/global.h +++ b/include/global.h @@ -169,6 +169,26 @@ struct BerryCrush #define PLAYER_NAME_LENGTH 8 +struct UnknownSaveBlock2Struct +{ + u8 field_0; + u8 field_1; + u8 field_2[2]; + u8 field_4[8]; + u8 field_C[16]; + u16 field_1C[6]; + u16 field_28[6]; + u8 field_34[176]; + u8 field_E4; + u8 field_E5; + u8 field_E6; + u8 field_E7; + u8 field_E8; + u8 field_E9; + u8 field_EA; + u8 field_EB; +}; // sizeof = 0xEC + struct SaveBlock2 { /*0x00*/ u8 playerName[PLAYER_NAME_LENGTH]; @@ -203,7 +223,8 @@ struct SaveBlock2 // All below could be a one giant struct - /*0x64C*/ u8 field_64C[0x588]; + /*0x64C*/ u8 field_64C[236]; + /*0x738*/ struct UnknownSaveBlock2Struct field_738[5]; // No idea here, it's probably wrong, no clue. /*0xBD4*/ u16 field_BD4; /*0xBD6*/ u16 field_BD6; /*0xBD8*/ u8 field_BD8[11]; @@ -220,7 +241,7 @@ struct SaveBlock2 /*0xCAA*/ u16 field_CAA[0x2e]; /*0xD06*/ u8 field_D06; /*0xD07*/ u8 field_D07; - /*0xd08*/ u8 filler_D08[0x112]; + /*0xD08*/ u8 filler_D08[0x112]; /*0xE1A*/ u16 battlePyramidFloor; // possibly? /*0xE1C*/ u8 field_E1C[16]; /*0xE2C*/ struct PyramidBag pyramidBag; diff --git a/include/link.h b/include/link.h index 7a6563144..ef8370d0e 100644 --- a/include/link.h +++ b/include/link.h @@ -68,7 +68,7 @@ struct LinkPlayer /* 0x08 */ u8 name[11]; /* 0x13 */ u8 gender; /* 0x14 */ u32 linkType; - /* 0x18 */ u16 lp_field_18; + /* 0x18 */ u16 lp_field_18; // battle bank in battles /* 0x1A */ u16 language; }; diff --git a/include/recorded_battle.h b/include/recorded_battle.h index ae2ed1a79..d709dc2c7 100644 --- a/include/recorded_battle.h +++ b/include/recorded_battle.h @@ -12,13 +12,14 @@ void RecordedBattle_ClearBankAction(u8 bank, u8 bytesToClear); void sub_8185F90(u16 arg0); bool8 sub_8186450(void); u8 sub_8185FAC(void); -u8 sub_8185FB8(void); -u8 MoveRecordedBattleToSaveData(void); +u8 GetBattleStyleInRecordedBattle(void); +u32 MoveRecordedBattleToSaveData(void); void sub_818603C(u8); -void sub_8185FD0(void); +void RecordedBattle_CopyBankMoves(void); void sub_8186444(void); void sub_8185EB8(void); u8 sub_81850DC(u8 *arg0); -u8 sub_8185F40(void); +u8 GetActiveBankLinkPlayerGender(void); +void RecordedBattle_SaveParties(void); #endif // GUARD_RECORDED_BATTLE_H diff --git a/include/save.h b/include/save.h index 6c1238cd2..3bd1ff8cf 100644 --- a/include/save.h +++ b/include/save.h @@ -56,41 +56,42 @@ enum HOF_DELETE_SAVE // unused }; +#define SECTION_ID_RECORDED_BATTLE 31 + void ClearSaveData(void); void ResetSaveCounters(void); -//bool32 ManipulateSectorBits(u8 op, u8 bit); -//u8 save_write_to_flash(u16 a1, const struct SaveSectionLocation *a2); -u8 HandleWriteSector(u16, const struct SaveSectionLocation *); -//u8 HandleWriteSectorNBytes(u8 sector, u8 *data, u16 size); -u8 TryWriteSector(u8, u8 *); -//u32 RestoreSaveBackupVarsAndIncrement(const struct SaveSectionLocation *location); -//u32 RestoreSaveBackupVars(const struct SaveSectionLocation *location); -//u8 sub_812550C(u16 a1, const struct SaveSectionLocation *location); +bool32 SetDamagedSectorBits(u8 op, u8 bit); +u8 save_write_to_flash(u16 a1, const struct SaveSectionLocation *location); +u8 HandleWriteSector(u16 a1, const struct SaveSectionLocation *location); +u8 HandleWriteSectorNBytes(u8 sector, u8 *data, u16 size); +u8 TryWriteSector(u8 sector, u8 *data); +u32 RestoreSaveBackupVarsAndIncrement(const struct SaveSectionLocation *location); +u32 RestoreSaveBackupVars(const struct SaveSectionLocation *location); +u8 sub_81529D4(u16 a1, const struct SaveSectionLocation *location); u8 sub_8152A34(u16 a1, const struct SaveSectionLocation *location); -u8 ClearSaveData_2(u16, const struct SaveSectionLocation *location); -//u8 sub_8125758(u16 a1, const struct SaveSectionLocation *location); -//u8 sub_81257F0(u16 a1, const struct SaveSectionLocation *location); -//u8 sub_812587C(u16 a1, const struct SaveSectionLocation *location); -u8 sub_8152E10(u16, const struct SaveSectionLocation *location); +u8 ClearSaveData_2(u16 a1, const struct SaveSectionLocation *location); +u8 sav12_xor_get(u16 a1, const struct SaveSectionLocation *location); +u8 sub_8152CAC(u16 a1, const struct SaveSectionLocation *location); +u8 sub_8152D44(u16 a1, const struct SaveSectionLocation *location); +u8 sub_8152DD0(u16 a1, const struct SaveSectionLocation *location); +u8 sub_8152E10(u16 a1, const struct SaveSectionLocation *location); u8 GetSaveValidStatus(const struct SaveSectionLocation *location); -//u8 sub_8125B88(u8 a1, u8 *data, u16 size); -u8 DoReadFlashWholeSection(u8, struct SaveSection *); -u16 CalculateChecksum(void *, u16); +u8 sub_81530DC(u8 a1, u8 *data, u16 size); +u8 DoReadFlashWholeSection(u8 sector, struct SaveSection *section); +u16 CalculateChecksum(void *data, u16 size); +void UpdateSaveAddresses(void); u8 HandleSavingData(u8 saveType); -//u8 TrySavingData(u8 saveType); -//u8 sub_8125D80(void); -//bool8 sub_8125DA8(void); -//u8 sub_8125DDC(void); -//u8 sub_8125E04(void); -//u8 sub_8125E2C(void); -//bool8 sub_8125E6C(void); -//u8 sub_8125EC8(u8 a1); -//bool8 unref_sub_8125F4C(struct UnkSaveSection *a1); -//u8 unref_sub_8125FA0(void); -//u8 unref_sub_8125FF0(u8 *data, u16 size); -//u8 unref_sub_8126068(u8 sector, u8 *data, u32 size); -//u8 unref_sub_8126080(u8 sector, u8 *data); +u8 TrySavingData(u8 saveType); +u8 sub_8153380(void); +bool8 sub_81533AC(void); +u8 sub_81533E0(void); +u8 sub_8153408(void); +u8 sub_8153430(void); +bool8 sub_8153474(void); +u8 sub_81534D0(u8 a1); u16 sub_815355C(void); -u8 sub_81534D0(u8); +u32 TryCopySpecialSaveSection(u8 sector, u8* dst); +u32 sub_8153634(u8 sector, u8* src); +void sub_8153688(u8 taskId); #endif // GUARD_SAVE_H diff --git a/src/battle_2.c b/src/battle_2.c index e4ee624fb..af5aa4d32 100644 --- a/src/battle_2.c +++ b/src/battle_2.c @@ -2811,7 +2811,7 @@ static void BattleStartClearSetData(void) if (!(gBattleTypeFlags & BATTLE_TYPE_LINK) && gSaveBlock2Ptr->optionsBattleSceneOff == TRUE) gHitMarker |= HITMARKER_NO_ANIMATIONS; } - else if (!(gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_x2000000)) && sub_8185FB8()) + else if (!(gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_x2000000)) && GetBattleStyleInRecordedBattle()) gHitMarker |= HITMARKER_NO_ANIMATIONS; gBattleScripting.battleStyle = gSaveBlock2Ptr->optionsBattleStyle; @@ -3928,7 +3928,7 @@ static void HandleTurnActionSelectionState(void) switch (gBattleCommunication[gActiveBank]) { case STATE_TURN_START_RECORD: // recorded battle related on start of every turn - sub_8185FD0(); + RecordedBattle_CopyBankMoves(); gBattleCommunication[gActiveBank] = STATE_BEFORE_ACTION_CHOSEN; break; case STATE_BEFORE_ACTION_CHOSEN: // choose an action diff --git a/src/battle_controller_recorded_opponent.c b/src/battle_controller_recorded_opponent.c index 914ad9c43..b948a3f9e 100644 --- a/src/battle_controller_recorded_opponent.c +++ b/src/battle_controller_recorded_opponent.c @@ -1261,7 +1261,7 @@ static void RecordedOpponentHandleDrawTrainerPic(void) } else { - trainerPicId = PlayerGenderToFrontTrainerPicId(sub_8185F40()); + trainerPicId = PlayerGenderToFrontTrainerPicId(GetActiveBankLinkPlayerGender()); } } else diff --git a/src/battle_controller_recorded_player.c b/src/battle_controller_recorded_player.c index 8db7b5626..663f64ee2 100644 --- a/src/battle_controller_recorded_player.c +++ b/src/battle_controller_recorded_player.c @@ -1229,7 +1229,7 @@ static void RecordedPlayerHandleDrawTrainerPic(void) if (gBattleTypeFlags & BATTLE_TYPE_x2000000) { if (gBattleTypeFlags & BATTLE_TYPE_MULTI) - trainerPicId = sub_8185F40(); + trainerPicId = GetActiveBankLinkPlayerGender(); else trainerPicId = gLinkPlayers[gUnknown_0203C7B4].gender; } diff --git a/src/battle_controllers.c b/src/battle_controllers.c index 5c874438e..858540a9f 100644 --- a/src/battle_controllers.c +++ b/src/battle_controllers.c @@ -113,7 +113,7 @@ void sub_8032768(void) sub_8184DA4(2); if (!(gBattleTypeFlags & BATTLE_TYPE_RECORDED)) - sub_8185EB8(); + RecordedBattle_SaveParties(); if (gBattleTypeFlags & BATTLE_TYPE_LINK) SetControllersVariablesInLinkBattle(); diff --git a/src/battle_message.c b/src/battle_message.c index 52c0c7af5..8c833276e 100644 --- a/src/battle_message.c +++ b/src/battle_message.c @@ -58,7 +58,7 @@ extern const u8* GetTrainer1LoseText(void); // battle_setup extern const u8* GetTrainer2LoseText(void); // battle_setup extern void GetFrontierTrainerName(u8 *dst, u16 trainerId); extern s32 GetStringCenterAlignXOffsetWithLetterSpacing(u8 fontId, const u8 *str, s32 totalWidth, s16 letterSpacing); -extern u8 sub_8185FC4(void); +extern u8 GetTextSpeedInRecordedBattle(void); extern u8 sav2_get_text_speed(void); // this file's functions @@ -2264,7 +2264,7 @@ void BattleHandleAddTextPrinter(const u8 *text, u8 arg1) if (gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_x2000000)) speed = 1; else if (gBattleTypeFlags & BATTLE_TYPE_RECORDED) - speed = sRecordedBattleTextSpeeds[sub_8185FC4()]; + speed = sRecordedBattleTextSpeeds[GetTextSpeedInRecordedBattle()]; else speed = sav2_get_text_speed(); diff --git a/src/recorded_battle.c b/src/recorded_battle.c index dfff37e90..8ecf943cc 100644 --- a/src/recorded_battle.c +++ b/src/recorded_battle.c @@ -8,20 +8,77 @@ #include "link.h" #include "string_util.h" #include "palette.h" +#include "save.h" +#include "malloc.h" +#include "util.h" +#include "task.h" +#include "text.h" #define BANK_RECORD_SIZE 664 +#define ILLEGAL_BATTLE_TYPES ((BATTLE_TYPE_LINK | BATTLE_TYPE_SAFARI | BATTLE_TYPE_FIRST_BATTLE \ + | BATTLE_TYPE_WALLY_TUTORIAL | BATTLE_TYPE_ROAMER | BATTLE_TYPE_EREADER_TRAINER \ + | BATTLE_TYPE_KYOGRE_GROUDON | BATTLE_TYPE_LEGENDARY | BATTLE_TYPE_REGI \ + | BATTLE_TYPE_RECORDED | BATTLE_TYPE_x4000000 | BATTLE_TYPE_SECRET_BASE \ + | BATTLE_TYPE_GROUDON | BATTLE_TYPE_KYORGE | BATTLE_TYPE_RAYQUAZA)) extern u32 gBattleTypeFlags; +extern u16 gTrainerBattleOpponent_A; +extern u16 gTrainerBattleOpponent_B; +extern u16 gPartnerTrainerId; +extern u8 gActiveBank; +extern u8 gNoOfAllBanks; +extern u16 gBattlePartyID[BATTLE_BANKS_COUNT]; +extern struct BattlePokemon gBattleMons[BATTLE_BANKS_COUNT]; +extern u16 gChosenMovesByBanks[BATTLE_BANKS_COUNT]; +extern u8 gUnknown_03001278; +extern u8 gUnknown_03001279; struct PlayerInfo { u32 trainerId; u8 name[PLAYER_NAME_LENGTH]; u8 gender; - u16 field_E; + u16 bank; u16 language; }; +struct MovePp +{ + u16 moves[4]; + u8 pp[4]; +}; + +struct RecordedBattleSave +{ + struct Pokemon playerParty[PARTY_SIZE]; + struct Pokemon opponentParty[PARTY_SIZE]; + u8 playersName[BATTLE_BANKS_COUNT][PLAYER_NAME_LENGTH]; + u8 playersGender[BATTLE_BANKS_COUNT]; + u32 playersTrainerId[BATTLE_BANKS_COUNT]; + u8 playersLanguage[BATTLE_BANKS_COUNT]; + u32 rngSeed; + u32 battleFlags; + u8 playersBank[BATTLE_BANKS_COUNT]; + u16 opponentA; + u16 opponentB; + u16 partnerId; + u16 field_4FA; + u8 field_4FC; + u8 field_4FD; + u8 field_4FE; + u8 battleStyle : 1; + u8 textSpeed : 3; + u32 AI_scripts; + u8 field_504[8]; + u8 field_50C; + u8 field_50D; + u16 field_50E[6]; + u8 field_51A; + u8 field_51B; + u8 battleRecord[BATTLE_BANKS_COUNT][BANK_RECORD_SIZE]; + u32 checksum; +}; + EWRAM_DATA u32 gRecordedBattleRngSeed = 0; EWRAM_DATA u32 gBattlePalaceMoveSelectionRngValue = 0; EWRAM_DATA u8 sBattleRecords[BATTLE_BANKS_COUNT][BANK_RECORD_SIZE] = {0}; @@ -32,16 +89,16 @@ EWRAM_DATA u8 gUnknown_0203C7AC = 0; EWRAM_DATA u8 gUnknown_0203C7AD = 0; EWRAM_DATA u8 gUnknown_0203C7AE = 0; EWRAM_DATA u8 gUnknown_0203C7AF = 0; -EWRAM_DATA MainCallback sRecordedBattle_Callback2 = NULL; +EWRAM_DATA MainCallback sCallback2_AfterRecordedBattle = NULL; EWRAM_DATA u8 gUnknown_0203C7B4 = 0; EWRAM_DATA u8 gUnknown_0203C7B5 = 0; -EWRAM_DATA u8 gUnknown_0203C7B6 = 0; -EWRAM_DATA u8 gUnknown_0203C7B7 = 0; +EWRAM_DATA u8 sRecordedBattle_BattleStyle = 0; +EWRAM_DATA u8 sRecordedBattle_TextSpeed = 0; EWRAM_DATA u32 sRecordedBattle_BattleFlags = 0; EWRAM_DATA u32 sRecordedBattle_AI_Scripts = 0; EWRAM_DATA struct Pokemon sSavedPlayerParty[PARTY_SIZE] = {0}; EWRAM_DATA struct Pokemon sSavedOpponentParty[PARTY_SIZE] = {0}; -EWRAM_DATA u16 gUnknown_0203CC70[8] = {0}; +EWRAM_DATA u16 sRecordedBattle_PlayerMonMoves[2][4] = {0}; EWRAM_DATA struct PlayerInfo sRecordedBattle_Players[BATTLE_BANKS_COUNT] = {0}; EWRAM_DATA u8 gUnknown_0203CCD0 = 0; EWRAM_DATA u8 gUnknown_0203CCD1[8] = {0}; @@ -51,9 +108,13 @@ EWRAM_DATA u16 gUnknown_0203CCDC[6] = {0}; EWRAM_DATA u8 gUnknown_0203CCE8 = 0; extern u32 sub_81A513C(void); +extern void PlayMapChosenOrBattleBGM(bool8); // this file's functions static u8 sub_8185278(u8 *arg0, u8 *arg1, u8 *arg2); +static bool32 AllocTryCopyRecordedBattleSaveData(struct RecordedBattleSave *dst); +void RecordedBattle_RestoreSavedParties(void); +static void CB2_RecordedBattle(void); void sub_8184DA4(u8 arg0) { @@ -107,7 +168,7 @@ void sub_8184E58(void) { sRecordedBattle_Players[i].trainerId = gLinkPlayers[i].trainerId; sRecordedBattle_Players[i].gender = gLinkPlayers[i].gender; - sRecordedBattle_Players[i].field_E = gLinkPlayers[i].lp_field_18; + sRecordedBattle_Players[i].bank = gLinkPlayers[i].lp_field_18; sRecordedBattle_Players[i].language = gLinkPlayers[i].language; if (i < linkPlayersCount) @@ -131,7 +192,7 @@ void sub_8184E58(void) | (gSaveBlock2Ptr->playerTrainerId[3] << 24); sRecordedBattle_Players[0].gender = gSaveBlock2Ptr->playerGender; - sRecordedBattle_Players[0].field_E = 0; + sRecordedBattle_Players[0].bank = 0; sRecordedBattle_Players[0].language = gGameLanguage; for (i = 0; i < PLAYER_NAME_LENGTH; i++) @@ -241,3 +302,1319 @@ static u8 sub_8185278(u8 *arg0, u8 *arg1, u8 *arg2) (*arg2)--; return arg0[(*arg1)++]; } + +bool32 CanCopyRecordedBattleSaveData(void) +{ + struct RecordedBattleSave *dst = AllocZeroed(sizeof(struct RecordedBattleSave)); + bool32 ret = AllocTryCopyRecordedBattleSaveData(dst); + Free(dst); + return ret; +} + +bool32 IsRecordedBattleSaveValid(struct RecordedBattleSave *save) +{ + if (save->battleFlags == 0) + return FALSE; + if (save->battleFlags & ILLEGAL_BATTLE_TYPES) + return FALSE; + if (CalcByteArraySum((void*)(save), sizeof(*save) - 4) != save->checksum) + return FALSE; + + return TRUE; +} + +bool32 sub_81852F0(struct RecordedBattleSave *battleSave, struct RecordedBattleSave *saveSection) +{ + memset(saveSection, 0, sizeof(struct SaveSection)); + memcpy(saveSection, battleSave, sizeof(*battleSave)); + + saveSection->checksum = CalcByteArraySum((void*)(saveSection), sizeof(*saveSection) - 4); + + if (sub_8153634(31, (void*)(saveSection)) != 1) + return FALSE; + + return TRUE; +} + +#ifdef NONMATCHING +u32 MoveRecordedBattleToSaveData(void) +{ + s32 i, j; + u8 var = 0; + struct RecordedBattleSave *battleSave = AllocZeroed(sizeof(struct RecordedBattleSave)); + struct SaveSection *savSection = AllocZeroed(sizeof(struct SaveSection)); + + for (i = 0; i < PARTY_SIZE; i++) + { + battleSave->playerParty[i] = sSavedPlayerParty[i]; + battleSave->opponentParty[i] = sSavedOpponentParty[i]; + } + + for (i = 0; i < BATTLE_BANKS_COUNT; i++) + { + for (j = 0; j < PLAYER_NAME_LENGTH; j++) + { + battleSave->playersName[i][j] = sRecordedBattle_Players[i].name[j]; + } + battleSave->playersGender[i] = sRecordedBattle_Players[i].gender; + battleSave->playersLanguage[i] = sRecordedBattle_Players[i].language; + battleSave->playersBank[i] = sRecordedBattle_Players[i].bank; + battleSave->playersTrainerId[i] = sRecordedBattle_Players[i].trainerId; + } + + battleSave->rngSeed = gRecordedBattleRngSeed; + + if (sRecordedBattle_BattleFlags & BATTLE_TYPE_LINK) + { + battleSave->battleFlags = (sRecordedBattle_BattleFlags & ~(BATTLE_TYPE_LINK | BATTLE_TYPE_20)); + battleSave->battleFlags |= BATTLE_TYPE_x2000000; + + if (sRecordedBattle_BattleFlags & BATTLE_TYPE_WILD) + { + battleSave->battleFlags |= BATTLE_TYPE_x80000000; + } + else if (sRecordedBattle_BattleFlags & BATTLE_TYPE_MULTI) + { + switch (sRecordedBattle_Players[0].bank) + { + case 0: + case 2: + if (!(sRecordedBattle_Players[gUnknown_0203C7B4].bank & 1)) + battleSave->battleFlags |= BATTLE_TYPE_x80000000; + break; + case 1: + case 3: + if ((sRecordedBattle_Players[gUnknown_0203C7B4].bank & 1)) + battleSave->battleFlags |= BATTLE_TYPE_x80000000; + break; + } + } + } + else + { + battleSave->battleFlags = sRecordedBattle_BattleFlags; + } + + battleSave->opponentA = gTrainerBattleOpponent_A; + battleSave->opponentB = gTrainerBattleOpponent_B; + battleSave->partnerId = gPartnerTrainerId; + battleSave->field_4FA = gUnknown_0203C7B4; + battleSave->field_4FC = gSaveBlock2Ptr->field_CA9_b; + battleSave->field_4FD = gUnknown_0203C7AE; + battleSave->field_4FE = gUnknown_0203C7AF; + battleSave->battleStyle = gSaveBlock2Ptr->optionsBattleStyle; + battleSave->textSpeed = gSaveBlock2Ptr->optionsTextSpeed; + battleSave->AI_scripts = sRecordedBattle_AI_Scripts; + + /* Can't match it without proper knowledge of the Saveblock 2. + if (gTrainerBattleOpponent_A >= 300 && gTrainerBattleOpponent_A <= 399) + { + for (i = 0; i < 8; i++) + { + battleSave->field_504[i] = gSaveBlock2Ptr->field_738[gTrainerBattleOpponent_A - 300].field_4[i]; + } + battleSave->field_50C = gSaveBlock2Ptr->field_738[gTrainerBattleOpponent_A - 300].field_1; + + if (gUnknown_0203CCE8 == 1) + { + for (i = 0; i < 6; i++) + { + battleSave->field_50E[i] = gSaveBlock2Ptr->field_738[gTrainerBattleOpponent_A - 300].field_28[i]; + } + } + else + { + for (i = 0; i < 6; i++) + { + battleSave->field_50E[i] = gSaveBlock2Ptr->field_738[gTrainerBattleOpponent_A - 300].field_1C[i]; + } + } + battleSave->field_51A = gSaveBlock2Ptr->field_738[gTrainerBattleOpponent_A - 300].field_E4; + } + else if (gTrainerBattleOpponent_B >= 300 && gTrainerBattleOpponent_B <= 399) + { + for (i = 0; i < 8; i++) + { + battleSave->field_504[i] = gSaveBlock2Ptr->field_738[gTrainerBattleOpponent_B - 300].field_4[i]; + } + battleSave->field_50C = gSaveBlock2Ptr->field_738[gTrainerBattleOpponent_B - 300].field_1; + + if (gUnknown_0203CCE8 == 1) + { + for (i = 0; i < 6; i++) + { + battleSave->field_50E[i] = gSaveBlock2Ptr->field_738[gTrainerBattleOpponent_B - 300].field_28[i]; + } + } + else + { + for (i = 0; i < 6; i++) + { + battleSave->field_50E[i] = gSaveBlock2Ptr->field_738[gTrainerBattleOpponent_B - 300].field_1C[i]; + } + } + battleSave->field_51A = gSaveBlock2Ptr->field_738[gTrainerBattleOpponent_B - 300].field_E4; + } + else if (gPartnerTrainerId >= 300 && gPartnerTrainerId <= 399) + { + for (i = 0; i < 8; i++) + { + battleSave->field_504[i] = gSaveBlock2Ptr->field_738[gPartnerTrainerId - 300].field_4[i]; + } + battleSave->field_50C = gSaveBlock2Ptr->field_738[gPartnerTrainerId - 300].field_1; + + if (gUnknown_0203CCE8 == 1) + { + for (i = 0; i < 6; i++) + { + battleSave->field_50E[i] = gSaveBlock2Ptr->field_738[gPartnerTrainerId - 300].field_28[i]; + } + } + else + { + for (i = 0; i < 6; i++) + { + battleSave->field_50E[i] = gSaveBlock2Ptr->field_738[gPartnerTrainerId - 300].field_1C[i]; + } + } + battleSave->field_51A = gSaveBlock2Ptr->field_738[gPartnerTrainerId - 300].field_E4; + } + + */ +} + +#else +__attribute__((naked)) +u32 MoveRecordedBattleToSaveData(void) +{ + asm(".syntax unified\n\ + push {r4-r7,lr}\n\ + mov r7, r10\n\ + mov r6, r9\n\ + mov r5, r8\n\ + push {r5-r7}\n\ + sub sp, 0xC\n\ + movs r0, 0\n\ + str r0, [sp, 0x4]\n\ + movs r0, 0xF8\n\ + lsls r0, 4\n\ + bl AllocZeroed\n\ + adds r7, r0, 0\n\ + movs r0, 0x80\n\ + lsls r0, 5\n\ + bl AllocZeroed\n\ + str r0, [sp]\n\ + movs r6, 0\n\ +_0818535E:\n\ + movs r0, 0x64\n\ + adds r4, r6, 0\n\ + muls r4, r0\n\ + adds r5, r7, r4\n\ + ldr r1, =sSavedPlayerParty\n\ + adds r1, r4, r1\n\ + adds r0, r5, 0\n\ + movs r2, 0x64\n\ + bl memcpy\n\ + movs r1, 0x96\n\ + lsls r1, 2\n\ + adds r5, r1\n\ + ldr r0, =sSavedOpponentParty\n\ + adds r4, r0\n\ + adds r0, r5, 0\n\ + adds r1, r4, 0\n\ + movs r2, 0x64\n\ + bl memcpy\n\ + adds r6, 0x1\n\ + cmp r6, 0x5\n\ + ble _0818535E\n\ + movs r6, 0\n\ + ldr r2, =gSaveBlock2Ptr\n\ + mov r9, r2\n\ + movs r3, 0x9A\n\ + lsls r3, 3\n\ + adds r3, r7, r3\n\ + str r3, [sp, 0x8]\n\ + ldr r5, =sRecordedBattle_Players\n\ + mov r8, r6\n\ + mov r12, r6\n\ + movs r4, 0x96\n\ + lsls r4, 3\n\ + adds r4, r7\n\ + mov r10, r4\n\ + ldr r0, =0x000004e4\n\ + adds r4, r7, r0\n\ +_081853AC:\n\ + lsls r1, r6, 3\n\ + ldr r0, =sRecordedBattle_Players\n\ + adds r0, 0x4\n\ + mov r3, r8\n\ + adds r2, r3, r0\n\ + add r1, r10\n\ + movs r3, 0x7\n\ +_081853BA:\n\ + ldrb r0, [r2]\n\ + strb r0, [r1]\n\ + adds r2, 0x1\n\ + adds r1, 0x1\n\ + subs r3, 0x1\n\ + cmp r3, 0\n\ + bge _081853BA\n\ + ldr r0, [sp, 0x8]\n\ + adds r1, r0, r6\n\ + ldrb r0, [r5, 0xC]\n\ + strb r0, [r1]\n\ + ldrh r0, [r5, 0x10]\n\ + strb r0, [r4]\n\ + ldrh r0, [r5, 0xE]\n\ + strb r0, [r4, 0xC]\n\ + ldr r1, =0x000004d4\n\ + adds r0, r7, r1\n\ + add r0, r12\n\ + ldr r1, [r5]\n\ + str r1, [r0]\n\ + adds r5, 0x14\n\ + movs r2, 0x14\n\ + add r8, r2\n\ + movs r3, 0x4\n\ + add r12, r3\n\ + adds r4, 0x1\n\ + adds r6, 0x1\n\ + cmp r6, 0x3\n\ + ble _081853AC\n\ + movs r4, 0x9D\n\ + lsls r4, 3\n\ + adds r1, r7, r4\n\ + ldr r5, =gRecordedBattleRngSeed\n\ + ldr r0, [r5]\n\ + str r0, [r1]\n\ + ldr r0, =sRecordedBattle_BattleFlags\n\ + ldr r2, [r0]\n\ + movs r0, 0x2\n\ + ands r0, r2\n\ + cmp r0, 0\n\ + beq _081854DC\n\ + ldr r1, =0x000004ec\n\ + adds r3, r7, r1\n\ + movs r1, 0x23\n\ + negs r1, r1\n\ + ands r1, r2\n\ + movs r0, 0x80\n\ + lsls r0, 18\n\ + orrs r1, r0\n\ + str r1, [r3]\n\ + movs r0, 0x4\n\ + ands r0, r2\n\ + cmp r0, 0\n\ + beq _08185454\n\ + movs r0, 0x80\n\ + lsls r0, 24\n\ + orrs r1, r0\n\ + str r1, [r3]\n\ + b _081854E2\n\ + .pool\n\ +_08185454:\n\ + movs r0, 0x40\n\ + ands r2, r0\n\ + cmp r2, 0\n\ + beq _081854E2\n\ + ldr r2, =sRecordedBattle_Players\n\ + ldrh r0, [r2, 0xE]\n\ + cmp r0, 0x1\n\ + beq _081854A8\n\ + cmp r0, 0x1\n\ + bgt _08185474\n\ + cmp r0, 0\n\ + beq _0818547E\n\ + b _081854E2\n\ + .pool\n\ +_08185474:\n\ + cmp r0, 0x2\n\ + beq _0818547E\n\ + cmp r0, 0x3\n\ + beq _081854A8\n\ + b _081854E2\n\ +_0818547E:\n\ + ldr r3, =gUnknown_0203C7B4\n\ + ldrb r1, [r3]\n\ + lsls r0, r1, 2\n\ + adds r0, r1\n\ + lsls r0, 2\n\ + ldr r4, =sRecordedBattle_Players\n\ + adds r0, r4\n\ + ldrh r1, [r0, 0xE]\n\ + movs r0, 0x1\n\ + ands r0, r1\n\ + cmp r0, 0\n\ + bne _081854E2\n\ + ldr r5, =0x000004ec\n\ + adds r0, r7, r5\n\ + b _081854C4\n\ + .pool\n\ +_081854A8:\n\ + ldr r0, =gUnknown_0203C7B4\n\ + ldrb r1, [r0]\n\ + lsls r0, r1, 2\n\ + adds r0, r1\n\ + lsls r0, 2\n\ + ldr r1, =sRecordedBattle_Players\n\ + adds r0, r1\n\ + ldrh r1, [r0, 0xE]\n\ + movs r0, 0x1\n\ + ands r0, r1\n\ + cmp r0, 0\n\ + beq _081854E2\n\ + ldr r2, =0x000004ec\n\ + adds r0, r7, r2\n\ +_081854C4:\n\ + ldr r1, [r0]\n\ + movs r2, 0x80\n\ + lsls r2, 24\n\ + orrs r1, r2\n\ + str r1, [r0]\n\ + b _081854E2\n\ + .pool\n\ +_081854DC:\n\ + ldr r3, =0x000004ec\n\ + adds r0, r7, r3\n\ + str r2, [r0]\n\ +_081854E2:\n\ + ldr r4, =gTrainerBattleOpponent_A\n\ + ldrh r1, [r4]\n\ + ldr r5, =0x000004f4\n\ + adds r0, r7, r5\n\ + strh r1, [r0]\n\ + ldr r0, =gTrainerBattleOpponent_B\n\ + ldrh r1, [r0]\n\ + ldr r2, =0x000004f6\n\ + adds r0, r7, r2\n\ + strh r1, [r0]\n\ + ldr r3, =gPartnerTrainerId\n\ + ldrh r1, [r3]\n\ + movs r4, 0x9F\n\ + lsls r4, 3\n\ + adds r0, r7, r4\n\ + strh r1, [r0]\n\ + ldr r5, =gUnknown_0203C7B4\n\ + ldrb r1, [r5]\n\ + adds r2, 0x4\n\ + adds r0, r7, r2\n\ + strh r1, [r0]\n\ + mov r3, r9\n\ + ldr r0, [r3]\n\ + ldr r4, =0x00000ca9\n\ + adds r0, r4\n\ + ldrb r0, [r0]\n\ + lsls r0, 30\n\ + lsrs r0, 30\n\ + ldr r5, =0x000004fc\n\ + adds r1, r7, r5\n\ + strb r0, [r1]\n\ + ldr r0, =gUnknown_0203C7AE\n\ + ldrb r1, [r0]\n\ + adds r2, 0x3\n\ + adds r0, r7, r2\n\ + strb r1, [r0]\n\ + ldr r3, =gUnknown_0203C7AF\n\ + ldrb r1, [r3]\n\ + ldr r4, =0x000004fe\n\ + adds r0, r7, r4\n\ + strb r1, [r0]\n\ + mov r5, r9\n\ + ldr r0, [r5]\n\ + ldrb r1, [r0, 0x15]\n\ + lsls r1, 29\n\ + ldr r0, =0x000004ff\n\ + adds r3, r7, r0\n\ + lsrs r1, 31\n\ + ldrb r2, [r3]\n\ + movs r0, 0x2\n\ + negs r0, r0\n\ + ands r0, r2\n\ + orrs r0, r1\n\ + strb r0, [r3]\n\ + ldr r1, [r5]\n\ + ldrb r1, [r1, 0x14]\n\ + lsls r1, 29\n\ + lsrs r1, 28\n\ + movs r2, 0xF\n\ + negs r2, r2\n\ + ands r0, r2\n\ + orrs r0, r1\n\ + strb r0, [r3]\n\ + movs r2, 0xA0\n\ + lsls r2, 3\n\ + adds r1, r7, r2\n\ + ldr r3, =sRecordedBattle_AI_Scripts\n\ + ldr r0, [r3]\n\ + str r0, [r1]\n\ + ldr r4, =0xfffffed4\n\ + adds r1, r4, 0\n\ + ldr r5, =gTrainerBattleOpponent_A\n\ + ldrh r5, [r5]\n\ + adds r0, r1, r5\n\ + lsls r0, 16\n\ + lsrs r0, 16\n\ + cmp r0, 0x63\n\ + bls _08185580\n\ + b _081856C4\n\ +_08185580:\n\ + movs r6, 0\n\ + ldr r0, =0x00000504\n\ + adds r3, r7, r0\n\ + mov r10, r9\n\ + ldr r1, =gTrainerBattleOpponent_A\n\ + mov r12, r1\n\ + adds r2, r4, 0\n\ + mov r8, r2\n\ + ldr r4, =0x0000073c\n\ +_08185592:\n\ + adds r2, r3, r6\n\ + mov r5, r10\n\ + ldr r1, [r5]\n\ + mov r5, r12\n\ + ldrh r0, [r5]\n\ + add r0, r8\n\ + movs r5, 0xEC\n\ + muls r0, r5\n\ + adds r0, r6, r0\n\ + adds r1, r4\n\ + adds r1, r0\n\ + ldrb r0, [r1]\n\ + strb r0, [r2]\n\ + adds r6, 0x1\n\ + cmp r6, 0x7\n\ + ble _08185592\n\ + mov r0, r9\n\ + ldr r2, [r0]\n\ + ldr r1, =gTrainerBattleOpponent_A\n\ + ldrh r0, [r1]\n\ + ldr r3, =0xfffffed4\n\ + adds r0, r3\n\ + movs r1, 0xEC\n\ + muls r0, r1\n\ + adds r2, r0\n\ + ldr r4, =0x00000739\n\ + adds r2, r4\n\ + ldrb r1, [r2]\n\ + ldr r5, =0x0000050c\n\ + adds r0, r7, r5\n\ + strb r1, [r0]\n\ + ldr r1, =gUnknown_0203CCE8\n\ + ldrb r0, [r1]\n\ + cmp r0, 0x1\n\ + bne _08185664\n\ + movs r6, 0\n\ + ldr r2, =0x0000050e\n\ + adds r4, r7, r2\n\ + mov r10, r9\n\ + ldr r5, =gTrainerBattleOpponent_A\n\ + mov r8, r5\n\ + adds r5, r3, 0\n\ +_081855E6:\n\ + lsls r3, r6, 1\n\ + mov r0, r10\n\ + ldr r2, [r0]\n\ + mov r1, r8\n\ + ldrh r0, [r1]\n\ + adds r0, r5\n\ + movs r1, 0xEC\n\ + muls r0, r1\n\ + adds r3, r0\n\ + movs r0, 0xEC\n\ + lsls r0, 3\n\ + adds r2, r0\n\ + adds r2, r3\n\ + ldrh r0, [r2]\n\ + strh r0, [r4]\n\ + adds r4, 0x2\n\ + adds r6, 0x1\n\ + cmp r6, 0x5\n\ + ble _081855E6\n\ + b _08185696\n\ + .pool\n\ +_08185664:\n\ + movs r6, 0\n\ + ldr r1, =0x0000050e\n\ + adds r4, r7, r1\n\ + mov r10, r9\n\ + ldr r2, =gTrainerBattleOpponent_A\n\ + mov r8, r2\n\ + adds r5, r3, 0\n\ +_08185672:\n\ + lsls r3, r6, 1\n\ + mov r0, r10\n\ + ldr r2, [r0]\n\ + mov r1, r8\n\ + ldrh r0, [r1]\n\ + adds r0, r5\n\ + movs r1, 0xEC\n\ + muls r0, r1\n\ + adds r3, r0\n\ + ldr r0, =0x00000754\n\ + adds r2, r0\n\ + adds r2, r3\n\ + ldrh r0, [r2]\n\ + strh r0, [r4]\n\ + adds r4, 0x2\n\ + adds r6, 0x1\n\ + cmp r6, 0x5\n\ + ble _08185672\n\ +_08185696:\n\ + mov r1, r9\n\ + ldr r2, [r1]\n\ + ldr r3, =gTrainerBattleOpponent_A\n\ + ldrh r0, [r3]\n\ + ldr r4, =0xfffffed4\n\ + adds r0, r4\n\ + movs r1, 0xEC\n\ + muls r0, r1\n\ + adds r2, r0\n\ + ldr r5, =0x0000081c\n\ + adds r2, r5\n\ + ldrb r1, [r2]\n\ + b _08185856\n\ + .pool\n\ +_081856C4:\n\ + ldr r3, =gTrainerBattleOpponent_B\n\ + ldrh r3, [r3]\n\ + adds r0, r1, r3\n\ + lsls r0, 16\n\ + lsrs r0, 16\n\ + cmp r0, 0x63\n\ + bls _081856D4\n\ + b _081857E4\n\ +_081856D4:\n\ + movs r6, 0\n\ + ldr r4, =0x00000504\n\ + adds r3, r7, r4\n\ + mov r10, r9\n\ + ldr r5, =gTrainerBattleOpponent_B\n\ + mov r12, r5\n\ + ldr r0, =0xfffffed4\n\ + mov r8, r0\n\ + ldr r4, =0x0000073c\n\ +_081856E6:\n\ + adds r2, r3, r6\n\ + mov r5, r10\n\ + ldr r1, [r5]\n\ + mov r5, r12\n\ + ldrh r0, [r5]\n\ + add r0, r8\n\ + movs r5, 0xEC\n\ + muls r0, r5\n\ + adds r0, r6, r0\n\ + adds r1, r4\n\ + adds r1, r0\n\ + ldrb r0, [r1]\n\ + strb r0, [r2]\n\ + adds r6, 0x1\n\ + cmp r6, 0x7\n\ + ble _081856E6\n\ + mov r0, r9\n\ + ldr r2, [r0]\n\ + ldr r1, =gTrainerBattleOpponent_B\n\ + ldrh r0, [r1]\n\ + ldr r3, =0xfffffed4\n\ + adds r0, r3\n\ + movs r1, 0xEC\n\ + muls r0, r1\n\ + adds r2, r0\n\ + ldr r4, =0x00000739\n\ + adds r2, r4\n\ + ldrb r1, [r2]\n\ + ldr r5, =0x0000050c\n\ + adds r0, r7, r5\n\ + strb r1, [r0]\n\ + ldr r1, =gUnknown_0203CCE8\n\ + ldrb r0, [r1]\n\ + cmp r0, 0x1\n\ + bne _08185784\n\ + movs r6, 0\n\ + ldr r2, =0x0000050e\n\ + adds r4, r7, r2\n\ + mov r10, r9\n\ + ldr r5, =gTrainerBattleOpponent_B\n\ + mov r8, r5\n\ + adds r5, r3, 0\n\ +_0818573A:\n\ + lsls r3, r6, 1\n\ + mov r0, r10\n\ + ldr r2, [r0]\n\ + mov r1, r8\n\ + ldrh r0, [r1]\n\ + adds r0, r5\n\ + movs r1, 0xEC\n\ + muls r0, r1\n\ + adds r3, r0\n\ + movs r0, 0xEC\n\ + lsls r0, 3\n\ + adds r2, r0\n\ + adds r2, r3\n\ + ldrh r0, [r2]\n\ + strh r0, [r4]\n\ + adds r4, 0x2\n\ + adds r6, 0x1\n\ + cmp r6, 0x5\n\ + ble _0818573A\n\ + b _081857B6\n\ + .pool\n\ +_08185784:\n\ + movs r6, 0\n\ + ldr r1, =0x0000050e\n\ + adds r4, r7, r1\n\ + mov r10, r9\n\ + ldr r2, =gTrainerBattleOpponent_B\n\ + mov r8, r2\n\ + adds r5, r3, 0\n\ +_08185792:\n\ + lsls r3, r6, 1\n\ + mov r0, r10\n\ + ldr r2, [r0]\n\ + mov r1, r8\n\ + ldrh r0, [r1]\n\ + adds r0, r5\n\ + movs r1, 0xEC\n\ + muls r0, r1\n\ + adds r3, r0\n\ + ldr r0, =0x00000754\n\ + adds r2, r0\n\ + adds r2, r3\n\ + ldrh r0, [r2]\n\ + strh r0, [r4]\n\ + adds r4, 0x2\n\ + adds r6, 0x1\n\ + cmp r6, 0x5\n\ + ble _08185792\n\ +_081857B6:\n\ + mov r1, r9\n\ + ldr r2, [r1]\n\ + ldr r3, =gTrainerBattleOpponent_B\n\ + ldrh r0, [r3]\n\ + ldr r4, =0xfffffed4\n\ + adds r0, r4\n\ + movs r1, 0xEC\n\ + muls r0, r1\n\ + adds r2, r0\n\ + ldr r5, =0x0000081c\n\ + adds r2, r5\n\ + ldrb r1, [r2]\n\ + b _08185856\n\ + .pool\n\ +_081857E4:\n\ + ldr r3, =gPartnerTrainerId\n\ + ldrh r3, [r3]\n\ + adds r0, r1, r3\n\ + lsls r0, 16\n\ + lsrs r0, 16\n\ + cmp r0, 0x63\n\ + bhi _0818585C\n\ + movs r6, 0\n\ + ldr r4, =0x00000504\n\ + adds r3, r7, r4\n\ + mov r10, r9\n\ + ldr r5, =gPartnerTrainerId\n\ + mov r12, r5\n\ + ldr r0, =0xfffffed4\n\ + mov r8, r0\n\ + ldr r4, =0x0000073c\n\ +_08185804:\n\ + adds r2, r3, r6\n\ + mov r5, r10\n\ + ldr r1, [r5]\n\ + mov r5, r12\n\ + ldrh r0, [r5]\n\ + add r0, r8\n\ + movs r5, 0xEC\n\ + muls r0, r5\n\ + adds r0, r6, r0\n\ + adds r1, r4\n\ + adds r1, r0\n\ + ldrb r0, [r1]\n\ + strb r0, [r2]\n\ + adds r6, 0x1\n\ + cmp r6, 0x7\n\ + ble _08185804\n\ + mov r0, r9\n\ + ldr r1, [r0]\n\ + ldr r2, =gPartnerTrainerId\n\ + ldrh r0, [r2]\n\ + ldr r3, =0xfffffed4\n\ + adds r0, r3\n\ + movs r2, 0xEC\n\ + muls r0, r2\n\ + adds r1, r0\n\ + ldr r4, =0x00000739\n\ + adds r1, r4\n\ + ldrb r1, [r1]\n\ + ldr r5, =0x0000050c\n\ + adds r0, r7, r5\n\ + strb r1, [r0]\n\ + mov r0, r9\n\ + ldr r1, [r0]\n\ + ldr r4, =gPartnerTrainerId\n\ + ldrh r0, [r4]\n\ + adds r0, r3\n\ + muls r0, r2\n\ + adds r1, r0\n\ + ldr r5, =0x0000081c\n\ + adds r1, r5\n\ + ldrb r1, [r1]\n\ +_08185856:\n\ + ldr r2, =0x0000051a\n\ + adds r0, r7, r2\n\ + strb r1, [r0]\n\ +_0818585C:\n\ + ldr r3, =gTrainerBattleOpponent_A\n\ + ldrh r0, [r3]\n\ + ldr r1, =0x0000018f\n\ + cmp r0, r1\n\ + bls _08185900\n\ + mov r4, r9\n\ + ldr r2, [r4]\n\ + adds r1, r0, 0\n\ + ldr r3, =0xfffffe70\n\ + adds r1, r3\n\ + lsls r0, r1, 4\n\ + adds r0, r1\n\ + lsls r0, 2\n\ + adds r2, r0\n\ + adds r2, 0xDC\n\ + ldrb r0, [r2]\n\ + lsls r0, 27\n\ + lsrs r0, 27\n\ + ldr r5, =0x0000050d\n\ + adds r1, r7, r5\n\ + strb r0, [r1]\n\ + movs r6, 0\n\ + ldr r0, =0x0000050e\n\ + adds r4, r7, r0\n\ + mov r10, r9\n\ + ldr r1, =gTrainerBattleOpponent_A\n\ + mov r8, r1\n\ + adds r5, r3, 0\n\ +_08185894:\n\ + lsls r3, r6, 1\n\ + mov r0, r10\n\ + ldr r2, [r0]\n\ + mov r0, r8\n\ + ldrh r1, [r0]\n\ + adds r1, r5\n\ + lsls r0, r1, 4\n\ + adds r0, r1\n\ + lsls r0, 2\n\ + adds r3, r0\n\ + movs r1, 0x82\n\ + lsls r1, 1\n\ + adds r2, r1\n\ + adds r2, r3\n\ + ldrh r0, [r2]\n\ + strh r0, [r4]\n\ + adds r4, 0x2\n\ + adds r6, 0x1\n\ + cmp r6, 0x5\n\ + ble _08185894\n\ + mov r3, r9\n\ + ldr r2, [r3]\n\ + ldr r4, =gTrainerBattleOpponent_A\n\ + ldrh r1, [r4]\n\ + ldr r5, =0xfffffe70\n\ + adds r1, r5\n\ + b _081859AC\n\ + .pool\n\ +_08185900:\n\ + ldr r3, =gTrainerBattleOpponent_B\n\ + ldrh r0, [r3]\n\ + cmp r0, r1\n\ + bls _0818597C\n\ + mov r4, r9\n\ + ldr r2, [r4]\n\ + adds r1, r0, 0\n\ + ldr r3, =0xfffffe70\n\ + adds r1, r3\n\ + lsls r0, r1, 4\n\ + adds r0, r1\n\ + lsls r0, 2\n\ + adds r2, r0\n\ + adds r2, 0xDC\n\ + ldrb r0, [r2]\n\ + lsls r0, 27\n\ + lsrs r0, 27\n\ + ldr r5, =0x0000050d\n\ + adds r1, r7, r5\n\ + strb r0, [r1]\n\ + movs r6, 0\n\ + ldr r0, =0x0000050e\n\ + adds r4, r7, r0\n\ + mov r10, r9\n\ + ldr r1, =gTrainerBattleOpponent_B\n\ + mov r8, r1\n\ + adds r5, r3, 0\n\ +_08185936:\n\ + lsls r3, r6, 1\n\ + mov r0, r10\n\ + ldr r2, [r0]\n\ + mov r0, r8\n\ + ldrh r1, [r0]\n\ + adds r1, r5\n\ + lsls r0, r1, 4\n\ + adds r0, r1\n\ + lsls r0, 2\n\ + adds r3, r0\n\ + movs r1, 0x82\n\ + lsls r1, 1\n\ + adds r2, r1\n\ + adds r2, r3\n\ + ldrh r0, [r2]\n\ + strh r0, [r4]\n\ + adds r4, 0x2\n\ + adds r6, 0x1\n\ + cmp r6, 0x5\n\ + ble _08185936\n\ + mov r3, r9\n\ + ldr r2, [r3]\n\ + ldr r4, =gTrainerBattleOpponent_B\n\ + ldrh r1, [r4]\n\ + ldr r5, =0xfffffe70\n\ + adds r1, r5\n\ + b _081859AC\n\ + .pool\n\ +_0818597C:\n\ + ldr r3, =gPartnerTrainerId\n\ + ldrh r0, [r3]\n\ + cmp r0, r1\n\ + bls _081859C0\n\ + mov r4, r9\n\ + ldr r2, [r4]\n\ + adds r1, r0, 0\n\ + ldr r3, =0xfffffe70\n\ + adds r1, r3\n\ + lsls r0, r1, 4\n\ + adds r0, r1\n\ + lsls r0, 2\n\ + adds r2, r0\n\ + adds r2, 0xDC\n\ + ldrb r0, [r2]\n\ + lsls r0, 27\n\ + lsrs r0, 27\n\ + ldr r5, =0x0000050d\n\ + adds r1, r7, r5\n\ + strb r0, [r1]\n\ + ldr r2, [r4]\n\ + ldr r0, =gPartnerTrainerId\n\ + ldrh r1, [r0]\n\ + adds r1, r3\n\ +_081859AC:\n\ + lsls r0, r1, 4\n\ + adds r0, r1\n\ + lsls r0, 2\n\ + adds r2, r0\n\ + ldr r1, =0x0000011b\n\ + adds r0, r2, r1\n\ + ldrb r1, [r0]\n\ + ldr r2, =0x0000051b\n\ + adds r0, r7, r2\n\ + strb r1, [r0]\n\ +_081859C0:\n\ + movs r6, 0\n\ + ldr r3, =0x00000297\n\ + mov r10, r3\n\ + ldr r4, =sBattleRecords\n\ + mov r9, r4\n\ + movs r5, 0xA6\n\ + lsls r5, 2\n\ + mov r8, r5\n\ + ldr r0, =0x0000051c\n\ + adds r5, r7, r0\n\ +_081859D4:\n\ + adds r4, r6, 0x1\n\ + mov r0, r8\n\ + muls r0, r6\n\ + mov r1, r9\n\ + adds r2, r0, r1\n\ + adds r1, r0, r5\n\ + mov r3, r10\n\ + adds r3, 0x1\n\ +_081859E4:\n\ + ldrb r0, [r2]\n\ + strb r0, [r1]\n\ + adds r2, 0x1\n\ + adds r1, 0x1\n\ + subs r3, 0x1\n\ + cmp r3, 0\n\ + bne _081859E4\n\ + adds r6, r4, 0\n\ + cmp r6, 0x3\n\ + ble _081859D4\n\ +_081859F8:\n\ + adds r0, r7, 0\n\ + ldr r1, [sp]\n\ + bl sub_81852F0\n\ + adds r4, r0, 0\n\ + cmp r4, 0x1\n\ + beq _08185A14\n\ + ldr r0, [sp, 0x4]\n\ + adds r0, 0x1\n\ + lsls r0, 24\n\ + lsrs r0, 24\n\ + str r0, [sp, 0x4]\n\ + cmp r0, 0x2\n\ + bls _081859F8\n\ +_08185A14:\n\ + adds r0, r7, 0\n\ + bl Free\n\ + ldr r0, [sp]\n\ + bl Free\n\ + adds r0, r4, 0\n\ + add sp, 0xC\n\ + pop {r3-r5}\n\ + mov r8, r3\n\ + mov r9, r4\n\ + mov r10, r5\n\ + pop {r4-r7}\n\ + pop {r1}\n\ + bx r1\n\ + .pool\n\ + .syntax divided"); +} +#endif // NONMATCHING + +bool32 TryCopyRecordedBattleSaveData(struct RecordedBattleSave *dst, struct SaveSection *saveBuffer) +{ + if (TryCopySpecialSaveSection(SECTION_ID_RECORDED_BATTLE, (void*)(saveBuffer)) != 1) + return FALSE; + + memcpy(dst, saveBuffer, sizeof(struct RecordedBattleSave)); + + if (!IsRecordedBattleSaveValid(dst)) + return FALSE; + + return TRUE; +} + +static bool32 AllocTryCopyRecordedBattleSaveData(struct RecordedBattleSave *dst) +{ + struct SaveSection *savBuffer = AllocZeroed(sizeof(struct SaveSection)); + bool32 ret = TryCopyRecordedBattleSaveData(dst, savBuffer); + Free(savBuffer); + + return ret; +} + +static void CB2_RecordedBattleEnd(void) +{ + gSaveBlock2Ptr->frontierChosenLvl = gUnknown_0203C7AD; + gBattleOutcome = 0; + gBattleTypeFlags = 0; + gTrainerBattleOpponent_A = 0; + gTrainerBattleOpponent_B = 0; + gPartnerTrainerId = 0; + + RecordedBattle_RestoreSavedParties(); + SetMainCallback2(sCallback2_AfterRecordedBattle); +} + +#define tFramesToWait data[0] + +static void Task_StartAfterCountdown(u8 taskId) +{ + if (--gTasks[taskId].tFramesToWait == 0) + { + gMain.savedCallback = CB2_RecordedBattleEnd; + SetMainCallback2(CB2_InitBattle); + DestroyTask(taskId); + } +} + +static void SetRecordedBattleVarsFromSave(struct RecordedBattleSave *src) +{ + bool8 var; + s32 i, j; + + ZeroPlayerPartyMons(); + ZeroEnemyPartyMons(); + + for (i = 0; i < PARTY_SIZE; i++) + { + gPlayerParty[i] = src->playerParty[i]; + gEnemyParty[i] = src->opponentParty[i]; + } + + for (i = 0; i < BATTLE_BANKS_COUNT; i++) + { + for (var = FALSE, j = 0; j < PLAYER_NAME_LENGTH; j++) + { + gLinkPlayers[i].name[j] = src->playersName[i][j]; + if (src->playersName[i][j] == EOS) + var = TRUE; + } + gLinkPlayers[i].gender = src->playersGender[i]; + gLinkPlayers[i].language = src->playersLanguage[i]; + gLinkPlayers[i].lp_field_18 = src->playersBank[i]; + gLinkPlayers[i].trainerId = src->playersTrainerId[i]; + + if (var) + ConvertInternationalString(gLinkPlayers[i].name, gLinkPlayers[i].language); + } + + gRecordedBattleRngSeed = src->rngSeed; + gBattleTypeFlags = src->battleFlags | BATTLE_TYPE_RECORDED; + gTrainerBattleOpponent_A = src->opponentA; + gTrainerBattleOpponent_B = src->opponentB; + gPartnerTrainerId = src->partnerId; + gUnknown_0203C7B4 = src->field_4FA; + gUnknown_0203C7AD = gSaveBlock2Ptr->frontierChosenLvl; + gUnknown_0203C7AE = src->field_4FD; + gUnknown_0203C7AF = src->field_4FE; + sRecordedBattle_BattleStyle = src->battleStyle; + sRecordedBattle_TextSpeed = src->textSpeed; + sRecordedBattle_AI_Scripts = src->AI_scripts; + + for (i = 0; i < 8; i++) + { + gUnknown_0203CCD1[i] = src->field_504[i]; + } + + gUnknown_0203CCD9 = src->field_50C; + gUnknown_0203CCDA = src->field_50D; + gUnknown_03001278 = src->field_51A; + gUnknown_03001279 = src->field_51B; + + for (i = 0; i < 6; i++) + { + gUnknown_0203CCDC[i] = src->field_50E[i]; + } + + gSaveBlock2Ptr->frontierChosenLvl = src->field_4FC; + + for (i = 0; i < BATTLE_BANKS_COUNT; i++) + { + for (j = 0; j < BANK_RECORD_SIZE; j++) + { + sBattleRecords[i][j] = src->battleRecord[i][j]; + } + } +} + +void PlayRecordedBattle(void (*CB2_After)(void)) +{ + struct RecordedBattleSave *battleSave = AllocZeroed(sizeof(struct RecordedBattleSave)); + if (AllocTryCopyRecordedBattleSaveData(battleSave) == TRUE) + { + u8 taskId; + + RecordedBattle_SaveParties(); + SetRecordedBattleVarsFromSave(battleSave); + + taskId = CreateTask(Task_StartAfterCountdown, 1); + gTasks[taskId].tFramesToWait = 128; + + sCallback2_AfterRecordedBattle = CB2_After; + PlayMapChosenOrBattleBGM(FALSE); + SetMainCallback2(CB2_RecordedBattle); + } + Free(battleSave); +} + +#undef tFramesToWait + +static void CB2_RecordedBattle(void) +{ + AnimateSprites(); + BuildOamBuffer(); + RunTasks(); +} + +u8 sub_8185EA0(void) +{ + return gUnknown_0203C7AE; +} + +u8 sub_8185EAC(void) +{ + return gUnknown_0203C7AF; +} + +void RecordedBattle_SaveParties(void) +{ + s32 i; + + for (i = 0; i < PARTY_SIZE; i++) + { + sSavedPlayerParty[i] = gPlayerParty[i]; + sSavedOpponentParty[i] = gEnemyParty[i]; + } +} + +void RecordedBattle_RestoreSavedParties(void) +{ + s32 i; + + for (i = 0; i < PARTY_SIZE; i++) + { + gPlayerParty[i] = sSavedPlayerParty[i]; + gEnemyParty[i] = sSavedOpponentParty[i]; + } +} + +u8 GetActiveBankLinkPlayerGender(void) +{ + s32 i; + + for (i = 0; i < MAX_LINK_PLAYERS; i++) + { + if (gLinkPlayers[i].lp_field_18 == gActiveBank) + break; + } + + if (i != MAX_LINK_PLAYERS) + return gLinkPlayers[i].gender; + + return 0; +} + +void sub_8185F84(void) +{ + gUnknown_0203C7B5 = 0; +} + +void sub_8185F90(u16 arg0) +{ + gUnknown_0203C7B5 |= (arg0 & 0x8000) >> 0xF; +} + +u8 sub_8185FAC(void) +{ + return gUnknown_0203C7B5; +} + +u8 GetBattleStyleInRecordedBattle(void) +{ + return sRecordedBattle_BattleStyle; +} + +u8 GetTextSpeedInRecordedBattle(void) +{ + return sRecordedBattle_TextSpeed; +} + +void RecordedBattle_CopyBankMoves(void) +{ + s32 i; + + if (GetBankSide(gActiveBank) == SIDE_OPPONENT) + return; + if (gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_x2000000)) + return; + if (gUnknown_0203C7AC == 2) + return; + + for (i = 0; i < 4; i++) + { + sRecordedBattle_PlayerMonMoves[gActiveBank / 2][i] = gBattleMons[gActiveBank].moves[i]; + } +} + +#define ACTION_MOVE_CHANGE 6 + +void sub_818603C(u8 arg0) +{ + s32 bank, j, k; + + if (gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_x2000000)) + return; + + for (bank = 0; bank < gNoOfAllBanks; bank++) + { + if (GetBankSide(bank) != SIDE_OPPONENT) // player's side only + { + if (arg0 == 1) + { + for (j = 0; j < 4; j++) + { + if (gBattleMons[bank].moves[j] != sRecordedBattle_PlayerMonMoves[bank / 2][j]) + break; + } + if (j != 4) // player's mon's move has been changed + { + RecordedBattle_SetBankAction(bank, ACTION_MOVE_CHANGE); + for (j = 0; j < 4; j++) + { + for (k = 0; k < 4; k++) + { + if (gBattleMons[bank].moves[j] == sRecordedBattle_PlayerMonMoves[bank / 2][k]) + { + RecordedBattle_SetBankAction(bank, k); + break; + } + } + } + } + } + else + { + if (sBattleRecords[bank][sRecordedBytesNo[bank]] == ACTION_MOVE_CHANGE) + { + u8 ppBonuses[4]; + u8 array1[4]; + u8 array2[4]; + struct MovePp movePp; + u8 array3[8]; + u8 var; + + RecordedBattle_ReadBankAction(bank); + for (j = 0; j < 4; j++) + { + ppBonuses[j] = ((gBattleMons[bank].ppBonuses & ((3 << (j << 1)))) >> (j << 1)); + } + for (j = 0; j < 4; j++) + { + array1[j] = RecordedBattle_ReadBankAction(bank); + movePp.moves[j] = gBattleMons[bank].moves[array1[j]]; + movePp.pp[j] = gBattleMons[bank].pp[array1[j]]; + array3[j] = ppBonuses[array1[j]]; + array2[j] = (gDisableStructs[bank].unk18_b & gBitTable[j]) >> j; + } + for (j = 0; j < 4; j++) + { + gBattleMons[bank].moves[j] = movePp.moves[j]; + gBattleMons[bank].pp[j] = movePp.pp[j]; + } + gBattleMons[bank].ppBonuses = 0; + gDisableStructs[bank].unk18_b = 0; + for (j = 0; j < 4; j++) + { + gBattleMons[bank].ppBonuses |= (array3[j]) << (j << 1); + gDisableStructs[bank].unk18_b |= (array2[j]) << (j); + } + + if (!(gBattleMons[bank].status2 & STATUS2_TRANSFORMED)) + { + for (j = 0; j < 4; j++) + { + ppBonuses[j] = ((GetMonData(&gPlayerParty[gBattlePartyID[bank]], MON_DATA_PP_BONUSES, NULL) & ((3 << (j << 1)))) >> (j << 1)); + } + for (j = 0; j < 4; j++) + { + movePp.moves[j] = GetMonData(&gPlayerParty[gBattlePartyID[bank]], MON_DATA_MOVE1 + array1[j], NULL); + movePp.pp[j] = GetMonData(&gPlayerParty[gBattlePartyID[bank]], MON_DATA_PP1 + array1[j], NULL); + array3[j] = ppBonuses[array1[j]]; + } + for (j = 0; j < 4; j++) + { + SetMonData(&gPlayerParty[gBattlePartyID[bank]], MON_DATA_MOVE1 + j, &movePp.moves[j]); + SetMonData(&gPlayerParty[gBattlePartyID[bank]], MON_DATA_PP1 + j, &movePp.pp[j]); + } + var = 0; + for (j = 0; j < 4; j++) + { + var |= (array3[j]) << (j << 1); + } + SetMonData(&gPlayerParty[gBattlePartyID[bank]], MON_DATA_PP_BONUSES, &var); + } + + gChosenMovesByBanks[bank] = gBattleMons[bank].moves[*(gBattleStruct->chosenMovePositions + bank)]; + } + } + } + } +} diff --git a/src/save.c b/src/save.c index 2c1b26ca9..528c67145 100644 --- a/src/save.c +++ b/src/save.c @@ -797,7 +797,7 @@ u16 sub_815355C(void) return 0; } -u32 sub_81535DC(u8 sector, u8* dst) +u32 TryCopySpecialSaveSection(u8 sector, u8* dst) { s32 i; s32 size; @@ -826,6 +826,7 @@ u32 sub_8153634(u8 sector, u8* src) if (sector != 30 && sector != 31) return 0xFF; + savDataBuffer = &gSaveDataBuffer; *(u32*)(savDataBuffer) = 0xB39D;