diff --git a/asm/battle_frontier_2.s b/asm/battle_frontier_2.s index 5d48ce87c..ee5f37944 100644 --- a/asm/battle_frontier_2.s +++ b/asm/battle_frontier_2.s @@ -8,1243 +8,6 @@ - thumb_func_start sub_819FD64 -sub_819FD64: @ 819FD64 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x20 - movs r5, 0 - mov r0, sp - adds r0, 0xC - str r0, [sp, 0x14] - mov r1, sp - adds r1, 0x10 - str r1, [sp, 0x18] - adds r1, r0, 0 -_0819FD80: - adds r0, r1, r5 - strb r5, [r0] - adds r0, r5, 0x1 - lsls r0, 24 - lsrs r5, r0, 24 - cmp r5, 0x2 - bls _0819FD80 - movs r5, 0 - ldr r6, [sp, 0x14] -_0819FD92: - bl Random - lsls r0, 16 - lsrs r0, 16 - movs r1, 0x3 - bl __umodsi3 - lsls r0, 24 - lsrs r4, r0, 24 - bl Random - lsls r0, 16 - lsrs r0, 16 - movs r1, 0x3 - bl __umodsi3 - lsls r0, 24 - lsrs r0, 24 - adds r2, r6, r4 - ldrb r3, [r2] - adds r1, r6, r0 - ldrb r0, [r1] - strb r0, [r2] - strb r3, [r1] - adds r0, r5, 0x1 - lsls r0, 24 - lsrs r5, r0, 24 - cmp r5, 0x9 - bls _0819FD92 - movs r5, 0 - ldr r2, =gUnknown_086114D3 -_0819FDD0: - mov r4, sp - adds r1, r4, r5 - adds r0, r5, r2 - ldrb r0, [r0] - strb r0, [r1] - adds r0, r5, 0x1 - lsls r0, 24 - lsrs r5, r0, 24 - cmp r5, 0x9 - bls _0819FDD0 - movs r5, 0 -_0819FDE6: - bl Random - lsls r0, 16 - lsrs r0, 16 - movs r1, 0xA - bl __umodsi3 - lsls r0, 24 - lsrs r4, r0, 24 - bl Random - lsls r0, 16 - lsrs r0, 16 - movs r1, 0xA - bl __umodsi3 - lsls r0, 24 - lsrs r0, 24 - mov r6, sp - adds r2, r6, r4 - ldrb r3, [r2] - adds r1, r6, r0 - ldrb r0, [r1] - strb r0, [r2] - strb r3, [r1] - adds r0, r5, 0x1 - lsls r0, 24 - lsrs r5, r0, 24 - cmp r5, 0x31 - bls _0819FDE6 - ldr r4, =gUnknown_030062EC - movs r0, 0x30 - bl AllocZeroed - str r0, [r4] - movs r1, 0 - strb r1, [r0] - movs r5, 0 - movs r2, 0x4 -_0819FE34: - movs r3, 0 -_0819FE36: - ldr r0, [r4] - lsls r1, r3, 2 - adds r1, r3 - adds r1, r5, r1 - adds r0, 0x20 - adds r0, r1 - strb r2, [r0] - adds r0, r3, 0x1 - lsls r0, 24 - lsrs r3, r0, 24 - cmp r3, 0x2 - bls _0819FE36 - adds r0, r5, 0x1 - lsls r0, 24 - lsrs r5, r0, 24 - cmp r5, 0x4 - bls _0819FE34 - movs r0, 0 - ldr r7, [sp, 0x18] - strb r0, [r7] - movs r5, 0 -_0819FE60: - ldr r0, =gSaveBlock2Ptr - ldr r3, [r0] - lsls r4, r5, 2 - adds r3, r4 - mov r1, sp - adds r6, r1, r5 - ldrb r0, [r6] - adds r3, 0xB8 - movs r2, 0x3 - ands r2, r0 - ldrb r0, [r3] - movs r7, 0x4 - negs r7, r7 - adds r1, r7, 0 - ands r0, r1 - orrs r0, r2 - strb r0, [r3] - ldrb r0, [r6] - adds r5, 0x1 - str r5, [sp, 0x1C] - mov r8, r4 - cmp r0, 0x3 - beq _0819FF62 - ldrb r0, [r6] - ldr r1, [sp, 0x14] - ldr r2, [sp, 0x18] - bl sub_819FCF8 - ldr r1, =gSaveBlock2Ptr - ldr r3, [r1] - add r3, r8 - adds r3, 0xB8 - movs r2, 0x3 - ands r2, r0 - lsls r2, 2 - ldrb r0, [r3] - movs r4, 0xD - negs r4, r4 - adds r1, r4, 0 - ands r0, r1 - orrs r0, r2 - strb r0, [r3] - ldr r7, =gSaveBlock2Ptr - ldr r0, [r7] - add r0, r8 - adds r0, 0xB8 - ldrb r0, [r0] - lsls r0, 28 - lsrs r7, r0, 30 - ldrb r0, [r6] - cmp r0, 0x2 - bne _0819FF62 - lsls r0, r7, 2 - adds r0, r7 - mov r10, r0 - ldr r0, =gUnknown_030062EC - mov r9, r0 -_0819FED2: - bl Random - lsls r0, 16 - lsrs r4, r0, 16 - movs r1, 0x3 - ands r4, r1 - movs r3, 0 - mov r6, r9 - ldr r2, [r6] - ldrb r0, [r2] - adds r1, r0, 0x1 - lsls r5, r7, 2 - cmp r3, r1 - bge _0819FF12 - adds r2, 0x20 - mov r6, r10 - adds r0, r2, r6 - ldrb r0, [r0] - cmp r0, r4 - beq _0819FF12 - adds r6, r1, 0 - adds r1, r5, r7 -_0819FEFE: - adds r0, r3, 0x1 - lsls r0, 24 - lsrs r3, r0, 24 - cmp r3, r6 - bge _0819FF12 - adds r0, r3, r1 - adds r0, r2, r0 - ldrb r0, [r0] - cmp r0, r4 - bne _0819FEFE -_0819FF12: - mov r1, r9 - ldr r0, [r1] - ldrb r0, [r0] - adds r0, 0x1 - ldr r1, =gUnknown_030062EC - cmp r3, r0 - bne _0819FED2 - ldr r0, [r1] - orrs r5, r7 - ldrb r2, [r0] - adds r1, r5, r2 - adds r0, 0x20 - adds r0, r1 - strb r4, [r0] - ldr r6, =gSaveBlock2Ptr - ldr r2, [r6] - add r2, r8 - adds r2, 0xB8 - movs r7, 0x3 - ands r4, r7 - lsls r3, r4, 4 - ldrb r0, [r2] - movs r4, 0x31 - negs r4, r4 - adds r1, r4, 0 - ands r0, r1 - orrs r0, r3 - strb r0, [r2] - ldr r0, [r6] - add r0, r8 - adds r0, 0xB8 - ldrb r0, [r0] - lsls r0, 28 - lsrs r0, 30 - bl sub_819FF98 - ldr r1, [r6] - add r1, r8 - adds r1, 0xBA - strh r0, [r1] -_0819FF62: - ldr r6, [sp, 0x1C] - lsls r0, r6, 24 - lsrs r5, r0, 24 - cmp r5, 0x8 - bhi _0819FF6E - b _0819FE60 -_0819FF6E: - ldr r4, =gUnknown_030062EC - ldr r0, [r4] - bl Free - movs r0, 0 - str r0, [r4] - add sp, 0x20 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_819FD64 - - thumb_func_start sub_819FF98 -sub_819FF98: @ 819FF98 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x10 - lsls r0, 24 - lsrs r0, 24 - str r0, [sp] - movs r0, 0 - str r0, [sp, 0xC] - movs r7, 0 - ldr r1, [sp] - cmp r1, 0x2 - bhi _0819FFE0 - ldr r2, =gSaveBlock2Ptr - ldr r1, [r2] - adds r0, r1, 0 - adds r0, 0xB4 - ldr r3, [sp] - adds r0, r3 - ldrb r4, [r0] - adds r1, 0xB2 - ldrb r0, [r1] - lsls r0, 29 - lsrs r0, 29 - asrs r0, r3 - movs r1, 0x1 - ands r0, r1 - lsls r0, 2 - asrs r4, r0 - movs r0, 0xF - ands r4, r0 - b _0819FFE4 - .pool -_0819FFE0: - movs r4, 0 - ldr r2, =gSaveBlock2Ptr -_0819FFE4: - ldr r3, =gUnknown_08610970 - lsls r1, r4, 1 - ldr r4, [r2] - adds r0, r4, 0 - adds r0, 0xB0 - ldrb r2, [r0] - movs r0, 0x58 - muls r0, r2 - adds r1, r0 - adds r3, 0x34 - adds r1, r3 - ldrh r1, [r1] - str r1, [sp, 0x8] - ldr r1, =gLevelUpLearnsets - ldr r2, [sp, 0x8] - lsls r0, r2, 2 - adds r0, r1 - ldr r6, [r0] - movs r3, 0 - adds r4, 0xB1 - ldrb r1, [r4] - movs r0, 0x3 - ands r0, r1 - movs r5, 0x3C - cmp r0, 0x1 - bne _081A001A - movs r5, 0x32 -_081A001A: - ldrh r1, [r6] - ldr r4, =0x0000ffff - cmp r1, r4 - beq _081A004C - movs r2, 0xFE - lsls r2, 8 - adds r0, r2, 0 - ands r0, r1 - lsls r1, r5, 9 - cmp r0, r1 - bgt _081A004C - adds r5, r2, 0 - adds r2, r1, 0 -_081A0034: - adds r0, r3, 0x1 - lsls r0, 24 - lsrs r3, r0, 24 - lsls r0, r3, 1 - adds r0, r6 - ldrh r1, [r0] - cmp r1, r4 - beq _081A004C - adds r0, r5, 0 - ands r0, r1 - cmp r0, r2 - ble _081A0034 -_081A004C: - adds r5, r3, 0 - movs r3, 0 - str r3, [sp, 0x4] -_081A0052: - bl Random - lsls r0, 16 - lsrs r0, 16 - movs r1, 0x1 - ands r0, r1 - cmp r0, 0 - beq _081A0068 - ldr r0, [sp, 0xC] - cmp r0, 0x1 - bne _081A00E0 -_081A0068: - ldr r1, =0x000001ff - mov r8, r1 -_081A006C: - bl Random - lsls r0, 16 - lsrs r0, 16 - movs r1, 0x3A - bl __umodsi3 - lsls r0, 24 - lsrs r4, r0, 24 - ldr r0, [sp, 0x8] - adds r1, r4, 0 - bl CanSpeciesLearnTMHM - adds r2, r0, 0 - cmp r2, 0 - beq _081A006C - ldr r2, =0x00000121 - adds r0, r4, r2 - bl ItemIdToBattleMoveId - lsls r0, 16 - lsrs r7, r0, 16 - movs r2, 0x1 - cmp r5, 0x4 - bhi _081A00BC - movs r3, 0 - b _081A00C6 - .pool -_081A00BC: - subs r0, r5, 0x4 - b _081A00C2 -_081A00C0: - adds r0, r3, 0x1 -_081A00C2: - lsls r0, 24 - lsrs r3, r0, 24 -_081A00C6: - cmp r3, r5 - bcs _081A00DA - lsls r0, r3, 1 - adds r0, r6 - ldrh r0, [r0] - mov r1, r8 - ands r0, r1 - cmp r0, r7 - bne _081A00C0 - movs r2, 0 -_081A00DA: - cmp r2, 0x1 - bne _081A006C - b _081A0146 -_081A00E0: - cmp r5, 0x4 - bhi _081A00EA - movs r2, 0x1 - str r2, [sp, 0xC] - b _081A0168 -_081A00EA: - subs r4, r5, 0x4 - ldr r3, =0x000001ff - mov r10, r3 - mov r8, r3 - lsls r0, r4, 24 - mov r9, r0 -_081A00F6: - bl Random - lsls r0, 16 - lsrs r0, 16 - adds r1, r4, 0 - bl __modsi3 - lsls r0, 24 - lsrs r0, 23 - adds r0, r6 - ldrh r0, [r0] - mov r7, r8 - ands r7, r0 - movs r2, 0x1 - mov r1, r9 - lsrs r3, r1, 24 - cmp r3, r5 - bcs _081A0142 - lsls r0, r3, 1 - adds r0, r6 - ldrh r1, [r0] - mov r0, r8 - b _081A013A - .pool -_081A0128: - adds r0, r3, 0x1 - lsls r0, 24 - lsrs r3, r0, 24 - cmp r3, r5 - bcs _081A0142 - lsls r0, r3, 1 - adds r0, r6 - ldrh r0, [r0] - mov r1, r10 -_081A013A: - ands r0, r1 - cmp r0, r7 - bne _081A0128 - movs r2, 0 -_081A0142: - cmp r2, 0x1 - bne _081A00F6 -_081A0146: - ldr r0, [sp] - adds r1, r7, 0 - bl sub_81A0194 - lsls r0, 24 - cmp r0, 0 - beq _081A0168 - ldr r0, =gUnknown_08611370 - adds r0, r7, r0 - ldrb r0, [r0] - cmp r0, 0 - bne _081A0170 - ldr r0, [sp, 0x4] - adds r0, 0x1 - lsls r0, 24 - lsrs r0, 24 - str r0, [sp, 0x4] -_081A0168: - ldr r2, [sp, 0x4] - cmp r2, 0x4 - bhi _081A0170 - b _081A0052 -_081A0170: - ldr r0, =gUnknown_030062EC - ldr r1, [r0] - ldrb r0, [r1] - adds r0, 0x1 - strb r0, [r1] - adds r0, r7, 0 - add sp, 0x10 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r1} - bx r1 - .pool - thumb_func_end sub_819FF98 - - thumb_func_start sub_81A0194 -sub_81A0194: @ 81A0194 - push {r4-r7,lr} - lsls r0, 24 - lsrs r4, r0, 24 - lsls r1, 16 - lsrs r5, r1, 16 - movs r3, 0 - ldr r0, =gUnknown_030062EC - mov r12, r0 - ldr r2, [r0] - lsls r1, r4, 2 - adds r0, r1, r4 - lsls r6, r0, 1 - adds r2, 0x2 - adds r7, r1, 0 -_081A01B0: - lsls r0, r3, 1 - adds r0, r6 - adds r0, r2, r0 - ldrh r0, [r0] - cmp r0, r5 - bne _081A01C4 - movs r0, 0 - b _081A01E2 - .pool -_081A01C4: - adds r0, r3, 0x1 - lsls r0, 24 - lsrs r3, r0, 24 - cmp r3, 0x4 - bls _081A01B0 - mov r2, r12 - ldr r1, [r2] - adds r0, r7, r4 - ldrb r2, [r1] - adds r0, r2 - lsls r0, 1 - adds r1, 0x2 - adds r1, r0 - strh r5, [r1] - movs r0, 0x1 -_081A01E2: - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end sub_81A0194 - - thumb_func_start sub_81A01E8 -sub_81A01E8: @ 81A01E8 - push {r4-r7,lr} - mov r12, r1 - lsls r0, 16 - lsrs r2, r0, 16 - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - adds r0, 0xB1 - ldrb r1, [r0] - movs r0, 0x3 - ands r0, r1 - movs r4, 0x3C - cmp r0, 0x1 - bne _081A0204 - movs r4, 0x32 -_081A0204: - ldr r1, =gLevelUpLearnsets - lsls r0, r2, 2 - adds r0, r1 - ldr r6, [r0] - movs r5, 0 - ldrh r1, [r6] - ldr r3, =0x0000ffff - cmp r1, r3 - beq _081A0240 - movs r2, 0xFE - lsls r2, 8 - adds r0, r2, 0 - ands r0, r1 - lsls r1, r4, 9 - cmp r0, r1 - bgt _081A0240 - adds r4, r2, 0 - adds r2, r1, 0 -_081A0228: - adds r0, r5, 0x1 - lsls r0, 24 - lsrs r5, r0, 24 - lsls r0, r5, 1 - adds r0, r6 - ldrh r1, [r0] - cmp r1, r3 - beq _081A0240 - adds r0, r4, 0 - ands r0, r1 - cmp r0, r2 - ble _081A0228 -_081A0240: - adds r4, r5, 0 - cmp r4, 0x4 - bls _081A0248 - movs r4, 0x4 -_081A0248: - movs r2, 0 - cmp r2, r4 - bcs _081A026C - ldr r7, =0x000001ff -_081A0250: - lsls r3, r2, 1 - add r3, r12 - adds r2, 0x1 - subs r0, r5, r2 - lsls r0, 1 - adds r0, r6 - ldrh r1, [r0] - adds r0, r7, 0 - ands r0, r1 - strh r0, [r3] - lsls r2, 24 - lsrs r2, 24 - cmp r2, r4 - bcc _081A0250 -_081A026C: - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A01E8 - - thumb_func_start sub_81A0284 -sub_81A0284: @ 81A0284 - push {r4-r7,lr} - mov r7, r9 - mov r6, r8 - push {r6,r7} - sub sp, 0x8 - lsls r0, 24 - lsrs r0, 24 - mov r8, r0 - lsls r1, 24 - lsrs r6, r1, 24 - lsls r2, 24 - lsrs r5, r2, 24 - ldr r1, =gSaveBlock2Ptr - ldr r2, [r1] - adds r0, r2, 0 - adds r0, 0xB1 - ldrb r0, [r0] - lsls r0, 26 - lsrs r0, 28 - adds r7, r1, 0 - cmp r0, 0x2 - bhi _081A02B8 - movs r0, 0 - b _081A037C - .pool -_081A02B8: - movs r4, 0 - movs r3, 0 - adds r0, r2, 0 - adds r0, 0xB8 - ldrb r0, [r0] - lsls r0, 30 - ldr r1, =gUnknown_08610970 - mov r12, r1 - lsls r6, 1 - lsls r5, 1 - mov r9, r5 - cmp r0, 0 - beq _081A02F4 - adds r2, r7, 0 -_081A02D4: - adds r0, r4, 0x1 - lsls r0, 24 - lsrs r4, r0, 24 - adds r0, r3, 0x1 - lsls r0, 24 - lsrs r3, r0, 24 - cmp r3, 0x8 - bhi _081A02F4 - ldr r0, [r2] - lsls r1, r3, 2 - adds r0, r1 - adds r0, 0xB8 - ldrb r0, [r0] - lsls r0, 30 - cmp r0, 0 - bne _081A02D4 -_081A02F4: - ldr r0, [r7] - adds r0, 0xB0 - ldrb r1, [r0] - movs r0, 0x58 - muls r0, r1 - adds r0, r6, r0 - mov r1, r12 - adds r1, 0x34 - adds r0, r1 - ldrh r0, [r0] - mov r1, sp - bl sub_81A01E8 - movs r3, 0 - cmp r3, r4 - bcs _081A0376 - ldr r1, [r7] - adds r0, r1, 0 - adds r0, 0xB1 - ldrb r0, [r0] - lsls r0, 26 - lsrs r0, 28 - subs r0, 0x3 - cmp r3, r0 - bge _081A0376 - adds r6, r7, 0 - adds r5, r1, 0 -_081A032A: - lsls r0, r3, 2 - adds r2, r5, r0 - adds r0, r2, 0 - adds r0, 0xB8 - ldrb r1, [r0] - lsls r0, r1, 30 - lsrs r0, 30 - cmp r0, 0x2 - bne _081A035C - lsls r0, r1, 28 - lsrs r0, 30 - cmp r0, r8 - bne _081A035C - lsrs r0, r1, 6 - cmp r0, 0 - beq _081A035C - lsls r0, r1, 26 - lsrs r0, 30 - lsls r0, 1 - mov r7, sp - adds r1, r7, r0 - adds r0, r2, 0 - adds r0, 0xBA - ldrh r0, [r0] - strh r0, [r1] -_081A035C: - adds r0, r3, 0x1 - lsls r0, 24 - lsrs r3, r0, 24 - cmp r3, r4 - bcs _081A0376 - ldr r0, [r6] - adds r0, 0xB1 - ldrb r0, [r0] - lsls r0, 26 - lsrs r0, 28 - subs r0, 0x3 - cmp r3, r0 - blt _081A032A -_081A0376: - mov r0, sp - add r0, r9 - ldrh r0, [r0] -_081A037C: - add sp, 0x8 - pop {r3,r4} - mov r8, r3 - mov r9, r4 - pop {r4-r7} - pop {r1} - bx r1 - .pool - thumb_func_end sub_81A0284 - - thumb_func_start sub_81A0390 -sub_81A0390: @ 81A0390 - push {r4-r7,lr} - mov r7, r8 - push {r7} - sub sp, 0xC - lsls r0, 24 - lsrs r0, 24 - mov r8, r0 - movs r5, 0 - ldr r7, =gSaveBlock2Ptr - adds r6, r7, 0 - movs r4, 0 -_081A03A6: - ldr r0, [r6] - lsls r2, r5, 1 - adds r2, r5 - lsls r2, 2 - adds r0, r2 - adds r1, r0, 0 - adds r1, 0xE0 - strh r4, [r1] - adds r0, 0xEA - strh r4, [r0] - movs r3, 0 -_081A03BC: - ldr r0, [r6] - lsls r1, r3, 1 - adds r1, r2 - adds r0, 0xE2 - adds r0, r1 - strh r4, [r0] - adds r0, r3, 0x1 - lsls r0, 24 - lsrs r3, r0, 24 - cmp r3, 0x3 - bls _081A03BC - adds r0, r5, 0x1 - lsls r0, 24 - lsrs r5, r0, 24 - cmp r5, 0x2 - bls _081A03A6 - ldr r0, [r7] - adds r0, 0xB1 - ldrb r0, [r0] - lsrs r3, r0, 6 - movs r5, 0 -_081A03E6: - lsls r0, r3, 2 - mov r1, sp - adds r2, r1, r0 - lsls r0, r5, 1 - adds r0, r5 - lsls r0, 2 - adds r0, 0xE0 - ldr r1, [r7] - adds r1, r0 - str r1, [r2] - adds r0, r3, 0x1 - movs r1, 0x3 - bl __modsi3 - lsls r0, 24 - lsrs r3, r0, 24 - adds r0, r5, 0x1 - lsls r0, 24 - lsrs r5, r0, 24 - cmp r5, 0x2 - bls _081A03E6 - movs r5, 0 - ldr r7, =gSaveBlock2Ptr - ldr r6, =gUnknown_08610970+0x34 -_081A0416: - ldr r0, [r7] - mov r12, r0 - adds r0, 0xB4 - adds r0, r5 - ldrb r2, [r0] - mov r0, r12 - adds r0, 0xB2 - ldrb r0, [r0] - lsls r0, 29 - lsrs r0, 29 - asrs r0, r5 - movs r1, 0x1 - ands r0, r1 - lsls r0, 2 - asrs r2, r0 - movs r0, 0xF - ands r2, r0 - lsls r0, r5, 2 - mov r1, sp - adds r3, r1, r0 - ldr r4, [r3] - lsls r2, 1 - mov r0, r12 - adds r0, 0xB0 - ldrb r1, [r0] - movs r0, 0x58 - muls r0, r1 - adds r2, r0 - adds r2, r6 - ldrh r0, [r2] - strh r0, [r4] - ldr r1, [r3] - ldrh r0, [r1] - adds r1, 0x2 - bl sub_81A01E8 - adds r0, r5, 0x1 - lsls r0, 24 - lsrs r5, r0, 24 - cmp r5, 0x2 - bls _081A0416 - movs r5, 0 - cmp r5, r8 - bcs _081A04D6 - ldr r7, =gSaveBlock2Ptr -_081A0470: - ldr r1, [r7] - lsls r0, r5, 2 - adds r4, r1, r0 - adds r0, r4, 0 - adds r0, 0xB8 - ldrb r2, [r0] - lsls r0, r2, 30 - lsrs r1, r0, 30 - lsls r0, r2, 28 - lsrs r3, r0, 30 - adds r6, r3, 0 - cmp r1, 0x1 - bne _081A04A8 - lsrs r0, r2, 6 - cmp r0, 0 - beq _081A04CC - lsls r0, r3, 2 - add r0, sp - ldr r1, [r0] - adds r0, r4, 0 - adds r0, 0xBA - ldrh r0, [r0] - strh r0, [r1, 0xA] - b _081A04CC - .pool -_081A04A8: - cmp r1, 0x2 - bne _081A04CC - lsls r0, r2, 24 - lsrs r0, 30 - cmp r0, 0 - beq _081A04CC - lsls r2, 26 - lsrs r2, 30 - lsls r0, r6, 2 - add r0, sp - ldr r1, [r0] - lsls r2, 1 - adds r1, 0x2 - adds r1, r2 - adds r0, r4, 0 - adds r0, 0xBA - ldrh r0, [r0] - strh r0, [r1] -_081A04CC: - adds r0, r5, 0x1 - lsls r0, 24 - lsrs r5, r0, 24 - cmp r5, r8 - bcc _081A0470 -_081A04D6: - add sp, 0xC - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end sub_81A0390 - - thumb_func_start sub_81A04E4 -sub_81A04E4: @ 81A04E4 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x18 - lsls r0, 24 - lsrs r0, 24 - movs r7, 0x2 - cmp r0, 0x6 - bls _081A04FC - b _081A064C -_081A04FC: - lsls r0, 2 - ldr r1, =_081A050C - adds r0, r1 - ldr r0, [r0] - mov pc, r0 - .pool - .align 2, 0 -_081A050C: - .4byte _081A0528 - .4byte _081A0540 - .4byte _081A05B4 - .4byte _081A05F4 - .4byte _081A061C - .4byte _081A064C - .4byte _081A0634 -_081A0528: - movs r0, 0x12 - mov r10, r0 - movs r6, 0x8 - ldr r0, =gText_Lv50 - str r0, [sp, 0xC] - ldr r0, =gText_OpenLevel - str r0, [sp, 0x10] - b _081A0652 - .pool -_081A0540: - movs r7, 0x3 - movs r1, 0x12 - mov r10, r1 - movs r6, 0x6 - movs r4, 0 - ldr r0, =gSpeciesNames - mov r9, r0 - ldr r0, =gSaveBlock2Ptr - ldr r3, [r0] - movs r1, 0xB2 - adds r1, r3 - mov r12, r1 - adds r5, r3, 0 - adds r5, 0xB0 - ldr r0, =gUnknown_08610970+0x34 - mov r8, r0 -_081A0560: - adds r0, r3, 0 - adds r0, 0xB4 - adds r0, r4 - ldrb r2, [r0] - mov r1, r12 - ldrb r0, [r1] - lsls r0, 29 - lsrs r0, 29 - asrs r0, r4 - movs r1, 0x1 - ands r0, r1 - lsls r0, 2 - asrs r2, r0 - movs r0, 0xF - ands r2, r0 - lsls r2, 1 - ldrb r1, [r5] - movs r0, 0x58 - muls r0, r1 - adds r2, r0 - add r2, r8 - ldrh r1, [r2] - lsls r0, r4, 2 - mov r2, sp - adds r2, r0 - adds r2, 0xC - movs r0, 0xB - muls r0, r1 - add r0, r9 - str r0, [r2] - adds r0, r4, 0x1 - lsls r0, 24 - lsrs r4, r0, 24 - cmp r4, 0x2 - bls _081A0560 - b _081A0652 - .pool -_081A05B4: - movs r0, 0x12 - mov r10, r0 - movs r6, 0x8 - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - adds r0, 0xB1 - ldrb r0, [r0] - lsls r0, 26 - lsrs r0, 28 - cmp r0, 0x2 - bls _081A05CC - b _081A06FA -_081A05CC: - ldr r0, =gUnknown_030062F0 - ldr r3, [r0] - ldrh r0, [r3, 0x2] - movs r2, 0xB - muls r0, r2 - ldr r1, =gSpeciesNames - adds r0, r1 - str r0, [sp, 0x10] - ldrh r0, [r3] - muls r0, r2 - adds r0, r1 - str r0, [sp, 0xC] - b _081A0652 - .pool -_081A05F4: - movs r1, 0x11 - mov r10, r1 - movs r6, 0x8 - ldr r0, =gUnknown_030062F0 - ldr r3, [r0] - ldrh r0, [r3, 0x4] - movs r2, 0xD - muls r0, r2 - ldr r1, =gMoveNames - adds r0, r1 - str r0, [sp, 0xC] - ldrh r0, [r3, 0x6] - muls r0, r2 - adds r0, r1 - str r0, [sp, 0x10] - b _081A0652 - .pool -_081A061C: - movs r0, 0x12 - mov r10, r0 - movs r6, 0x8 - ldr r0, =gText_Give - str r0, [sp, 0xC] - ldr r0, =gText_NoNeed - str r0, [sp, 0x10] - b _081A0652 - .pool -_081A0634: - movs r1, 0x14 - mov r10, r1 - movs r6, 0x8 - ldr r0, =gText_Yes - str r0, [sp, 0xC] - ldr r0, =gText_No - str r0, [sp, 0x10] - b _081A0652 - .pool -_081A064C: - movs r0, 0 - mov r10, r0 - movs r6, 0 -_081A0652: - movs r5, 0 - movs r4, 0 - lsls r1, r7, 25 - mov r8, r1 - cmp r4, r7 - bcs _081A067E -_081A065E: - lsls r0, r4, 2 - add r0, sp - adds r0, 0xC - ldr r1, [r0] - movs r0, 0x1 - movs r2, 0 - bl GetStringWidth - cmp r0, r5 - ble _081A0674 - adds r5, r0, 0 -_081A0674: - adds r0, r4, 0x1 - lsls r0, 24 - lsrs r4, r0, 24 - cmp r4, r7 - bcc _081A065E -_081A067E: - adds r0, r5, 0 - bl convert_pixel_width_to_tile_width - adds r4, r0, 0 - lsls r4, 24 - lsrs r4, 24 - mov r0, r10 - adds r1, r4, 0 - bl sub_80E2D5C - lsls r0, 24 - lsrs r0, 24 - mov r10, r0 - mov r0, r8 - lsrs r3, r0, 24 - mov r0, r10 - adds r1, r6, 0 - adds r2, r4, 0 - bl sub_81A0784 - lsls r0, 24 - lsrs r5, r0, 24 - adds r0, r5, 0 - movs r1, 0 - bl SetStandardWindowBorderStyle - movs r4, 0 - cmp r4, r7 - bcs _081A06E6 -_081A06B8: - lsls r0, r4, 2 - add r0, sp - adds r0, 0xC - ldr r2, [r0] - lsls r0, r4, 4 - adds r0, 0x1 - lsls r0, 24 - lsrs r0, 24 - str r0, [sp] - movs r0, 0xFF - str r0, [sp, 0x4] - movs r0, 0 - str r0, [sp, 0x8] - adds r0, r5, 0 - movs r1, 0x1 - movs r3, 0x8 - bl AddTextPrinterParameterized - adds r0, r4, 0x1 - lsls r0, 24 - lsrs r4, r0, 24 - cmp r4, r7 - bcc _081A06B8 -_081A06E6: - adds r0, r5, 0 - adds r1, r7, 0 - movs r2, 0 - bl InitMenuInUpperLeftCornerPlaySoundWhenAPressed - movs r0, 0x1 - adds r1, r7, 0 - adds r2, r5, 0 - bl sub_81A0804 -_081A06FA: - add sp, 0x18 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end sub_81A04E4 - thumb_func_start sub_81A070C sub_81A070C: @ 81A070C push {r4,r5,lr} @@ -2143,7 +906,7 @@ _081A0E3C: adds r0, r2, r0 ldrb r0, [r0] lsrs r4, r0, 4 - ldr r3, =gUnknown_08610970 + ldr r3, =gApprentices lsls r1, r4, 1 adds r5, 0xB0 ldrb r0, [r5] @@ -2226,7 +989,7 @@ _081A0EC4: asrs r4, r1 movs r0, 0xF ands r4, r0 - ldr r2, =gUnknown_08610970 + ldr r2, =gApprentices lsls r1, r4, 1 adds r0, r5, 0 adds r0, 0xB0 @@ -2320,7 +1083,7 @@ _081A0F54: asrs r0, r1 movs r1, 0xF ands r0, r1 - ldr r2, =gUnknown_08610970 + ldr r2, =gApprentices lsls r0, 1 adds r1, r3, 0 adds r1, 0xB0 @@ -2554,7 +1317,7 @@ _081A1184: _081A11C0: movs r2, 0 _081A11C2: - ldr r3, =gUnknown_08610970 + ldr r3, =gApprentices lsls r1, r2, 1 ldr r0, [r6] adds r0, 0xB0 @@ -2983,7 +1746,7 @@ _081A14C2: thumb_func_start sub_81A150C sub_81A150C: @ 81A150C push {lr} - ldr r2, =gUnknown_08610970 + ldr r2, =gApprentices ldr r0, =gSaveBlock2Ptr ldr r0, [r0] adds r0, 0xDC @@ -3053,7 +1816,7 @@ _081A1594: thumb_func_start sub_81A15A4 sub_81A15A4: @ 81A15A4 push {lr} - ldr r2, =gUnknown_08610970 + ldr r2, =gApprentices ldr r0, =gSaveBlock2Ptr ldr r0, [r0] adds r0, 0xB0 @@ -3141,7 +1904,7 @@ sub_81A1650: @ 81A1650 push {lr} movs r2, 0x58 muls r2, r0 - ldr r0, =gUnknown_08610970 + ldr r0, =gApprentices adds r2, r0 subs r0, r1, 0x1 cmp r0, 0x6 @@ -7047,7 +5810,7 @@ _081A38A8: lsrs r3, r0, 24 movs r0, 0x58 muls r0, r3 - ldr r1, =gUnknown_08610970+0x4A + ldr r1, =gApprentices+0x4A _081A38C4: adds r0, r1 bl ConvertBattleFrontierTrainerSpeechToString @@ -7068,7 +5831,7 @@ _081A38D4: lsrs r3, r0, 27 movs r0, 0x58 muls r0, r3 - ldr r1, =gUnknown_08610970+0x4A + ldr r1, =gApprentices+0x4A adds r0, r1 bl ConvertBattleFrontierTrainerSpeechToString _081A38F8: diff --git a/asm/battle_tower.s b/asm/battle_tower.s index 2312b63bd..e017e3b83 100644 --- a/asm/battle_tower.s +++ b/asm/battle_tower.s @@ -576,7 +576,7 @@ _0816266C: b _081626BA .pool _08162698: - ldr r3, =gUnknown_08610970 + ldr r3, =gApprentices ldr r0, =gSaveBlock2Ptr ldr r1, [r0] ldr r0, =0xfffffe70 @@ -747,7 +747,7 @@ _081627E8: b _08162836 .pool _08162814: - ldr r3, =gUnknown_08610970 + ldr r3, =gApprentices ldr r0, =gSaveBlock2Ptr ldr r1, [r0] ldr r0, =0xfffffe70 @@ -1161,7 +1161,7 @@ _08162B64: cmp r0, 0 bne _08162BB0 ldr r4, =gFacilityClassToPicIndex - ldr r3, =gUnknown_08610970 + ldr r3, =gApprentices ldr r0, =gSaveBlock2Ptr ldr r1, [r0] ldr r0, =0xfffffe70 @@ -1184,7 +1184,7 @@ _08162B64: .pool _08162BB0: ldr r5, =gFacilityClassToPicIndex - ldr r4, =gUnknown_08610970 + ldr r4, =gApprentices bl sub_81864A8 lsls r0, 24 lsrs r0, 24 @@ -1301,7 +1301,7 @@ _08162CBC: cmp r0, 0 beq _08162CF4 ldr r5, =gFacilityClassToTrainerClass - ldr r4, =gUnknown_08610970 + ldr r4, =gApprentices bl sub_81864A8 lsls r0, 24 lsrs r0, 24 @@ -1316,7 +1316,7 @@ _08162CBC: .pool _08162CF4: ldr r4, =gFacilityClassToTrainerClass - ldr r3, =gUnknown_08610970 + ldr r3, =gApprentices ldr r0, =gSaveBlock2Ptr ldr r1, [r0] ldr r0, =0xfffffe70 @@ -1407,7 +1407,7 @@ _08162DC0: ands r0, r1 cmp r0, 0 beq _08162DE8 - ldr r4, =gUnknown_08610970 + ldr r4, =gApprentices bl sub_81864A8 lsls r0, 24 lsrs r0, 24 @@ -1417,7 +1417,7 @@ _08162DC0: b _08162E08 .pool _08162DE8: - ldr r3, =gUnknown_08610970 + ldr r3, =gApprentices ldr r0, =gSaveBlock2Ptr ldr r1, [r0] ldr r0, =0xfffffe70 @@ -1648,7 +1648,7 @@ _08162FC0: b _0816300E .pool _08162FEC: - ldr r3, =gUnknown_08610970 + ldr r3, =gApprentices ldr r0, =gSaveBlock2Ptr ldr r1, [r0] ldr r0, =0xfffffe70 @@ -1927,7 +1927,7 @@ _08163230: ldr r1, [r6] adds r1, r5 lsrs r2, r4, 24 - bl sub_8068528 + bl CreateApprenticeMon movs r2, 0x80 lsls r2, 17 adds r4, r2 @@ -6295,7 +6295,7 @@ _08165812: adds r0, r5 ldrb r2, [r0] adds r0, r4, 0 - bl sub_8068528 + bl CreateApprenticeMon movs r3, 0xC8 lsls r3, 1 adds r0, r7, r3 diff --git a/data/battle_frontier_2.s b/data/battle_frontier_2.s index dc38826a7..a05b0143c 100644 --- a/data/battle_frontier_2.s +++ b/data/battle_frontier_2.s @@ -8,7 +8,7 @@ .align 2 @ struct, eight bytes x6 for names in different languages, then 0x28 more bytes of data -gUnknown_08610970:: @ 8610970 +gApprentices:: @ 8610970 .string "サダヒロ$", 8 .string "ALANN$", 8 .string "ALAIN$", 8 diff --git a/include/apprentice.h b/include/apprentice.h new file mode 100644 index 000000000..98185e3c2 --- /dev/null +++ b/include/apprentice.h @@ -0,0 +1,17 @@ +#ifndef GUARD_APPRENTICE_H +#define GUARD_APPRENTICE_H + +#define APPRENTICE_SPECIES_COUNT 10 + +struct ApprenticeTrainer +{ + u8 name[6][PLAYER_NAME_LENGTH + 1]; // For all six languages. + u16 otId; + u16 facilityClass; + u16 species[APPRENTICE_SPECIES_COUNT]; + u8 rest[14]; +}; + +extern const struct ApprenticeTrainer gApprentices[]; + +#endif // GUARD_APPRENTICE_H diff --git a/include/global.h b/include/global.h index 9b66f7da6..ec9fc99bf 100644 --- a/include/global.h +++ b/include/global.h @@ -295,13 +295,21 @@ struct UnknownSaveBlock2Struct u8 field_EB; }; // sizeof = 0xEC -struct UnkRecordMixingStruct +struct ApprenticeMon +{ + u16 species; + u16 moves[4]; + u16 item; +}; + +struct Apprentice { u8 field_0_0:5; u8 field_0_1:2; u8 field_1; u8 field_2; - u8 field_3[37]; + u8 field_3; + struct ApprenticeMon monData[3]; u16 unk28[6]; u8 playerId[4]; u8 playerName[PLAYER_NAME_LENGTH]; @@ -473,6 +481,15 @@ struct BattleFrontier /*0xEFC*/ struct FrontierMonData field_EFC[3]; }; +struct Sav2_B8 +{ + u8 unk0_0:2; + u8 unk0_1:2; + u8 unk0_2:2; + u8 unk0_3:2; + u16 unk2; +}; + struct SaveBlock2 { /*0x00*/ u8 playerName[PLAYER_NAME_LENGTH + 1]; @@ -500,12 +517,14 @@ struct SaveBlock2 // TODO: fix and verify labels /*0xB0*/ u8 field_B0; /*0xB1*/ u8 field_B1_0:2; - /*0xB1*/ u8 field_B1_1:6; + /*0xB1*/ u8 field_B1_1:4; + /*0xB1*/ u8 field_B1_2:2; /*0xB2*/ u8 field_B2_0:3; /*0xB2*/ u8 field_B2_1:2; /*0xB3*/ u8 field_B3; - /*0xB4*/ u8 field_B4[0x28]; - /*0xDC*/ struct UnkRecordMixingStruct field_DC[4]; + /*0xB4*/ u8 field_B4[3]; + /*0xB8*/ struct Sav2_B8 field_B8[9]; + /*0xDC*/ struct Apprentice field_DC[4]; /*0x1EC*/ struct BerryCrush berryCrush; /*0x1FC*/ struct PokemonJumpResults pokeJump; /*0x20C*/ struct BerryPickingResults berryPick; diff --git a/include/pokemon.h b/include/pokemon.h index 9eddd8155..d261fba85 100644 --- a/include/pokemon.h +++ b/include/pokemon.h @@ -240,32 +240,6 @@ struct PokemonStorage /*0x83C2*/ u8 boxWallpapers[14]; }; -struct UnknownPokemonSubStruct2 -{ - u16 species; - u16 moves[4]; - u16 item; -}; - -struct UnknownPokemonStruct2 -{ - u8 field_0_0 : 5; - u8 field_0_1 : 2; - u8 field_1; - u8 field_2; - u8 field_3; - struct UnknownPokemonSubStruct2 mons[3]; - u8 field_28[23]; - u8 language; -}; - -struct UnknownPokemonStruct3 -{ - u8 field_0[48]; - u16 field_30; - u8 field_32[38]; -}; - struct Unknown_806F160_Struct { u8 field_0_0:4; @@ -472,7 +446,7 @@ void CreateMonWithIVsOTID(struct Pokemon *mon, u16 species, u8 level, u8 *ivs, u void CreateMonWithEVSpread(struct Pokemon *mon, u16 species, u8 level, u8 fixedIV, u8 evSpread); void sub_806819C(struct Pokemon *mon, struct UnknownPokemonStruct *src); void sub_8068338(struct Pokemon *mon, struct UnknownPokemonStruct *src, bool8 lvl50); -void sub_8068528(struct Pokemon *mon, const struct UnknownPokemonStruct2 *src, u8 monId); +void CreateApprenticeMon(struct Pokemon *mon, const struct Apprentice *src, u8 monId); void CreateMonWithEVSpreadPersonalityOTID(struct Pokemon *mon, u16 species, u8 level, u8 nature, u8 fixedIV, u8 evSpread, u32 otId); void sub_80686FC(struct Pokemon *mon, struct UnknownPokemonStruct *dest); void CreateObedientMon(struct Pokemon *mon, u16 species, u8 level, u8 fixedIV, u8 hasFixedPersonality, u32 fixedPersonality, u8 otIdType, u32 fixedOtId); diff --git a/include/script_menu.h b/include/script_menu.h index c50bef00f..8870e80b9 100644 --- a/include/script_menu.h +++ b/include/script_menu.h @@ -13,5 +13,6 @@ s32 convert_pixel_width_to_tile_width(s32); u8 CreateWindowFromRect(u8, u8, u8, u8); void sub_80E2A78(u8); u32 display_text_and_get_width(const u8*, u32); +u8 sub_80E2D5C(u8 arg0, u8 tileWidth); #endif //GUARD_SCRIPT_MENU_H diff --git a/ld_script.txt b/ld_script.txt index 8e73eaef8..7728a498b 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -247,6 +247,7 @@ SECTIONS { asm/battle_frontier_1.o(.text); src/menu.o(.text); src/battle_factory.o(.text); + src/battle_frontier_2.o(.text); asm/battle_frontier_2.o(.text); src/item_menu.o(.text); src/list_menu.o(.text); diff --git a/src/battle_frontier_2.c b/src/battle_frontier_2.c index e21e972cd..45e4a1683 100644 --- a/src/battle_frontier_2.c +++ b/src/battle_frontier_2.c @@ -1,23 +1,53 @@ #include "global.h" +#include "apprentice.h" #include "string_util.h" #include "script.h" #include "text.h" #include "random.h" #include "main.h" +#include "malloc.h" +#include "strings.h" +#include "menu.h" +#include "script_menu.h" +#include "party_menu.h" +#include "data2.h" +#include "constants/items.h" struct Unk030062ECStruct { u8 unk0; u16 unk2[3][5]; + u8 unk20[3][5]; +}; + +struct Unk030062F0Struct +{ + u16 unk0; + u16 unk2; + u16 unk4; + u16 unk6; }; extern struct Unk030062ECStruct *gUnknown_030062EC; +extern struct Unk030062F0Struct *gUnknown_030062F0; extern const u8 *const gUnknown_08611330[]; extern const u8 gUnknown_08611548[8]; +extern const u8 gUnknown_086114D3[]; +extern const bool8 gUnknown_08611370[]; + +// text +extern const u8 gText_Give[]; +extern const u8 gText_NoNeed[]; +extern const u8 gText_Yes[]; +extern const u8 gText_No[]; // This file's functions. void sub_81A087C(void); +u16 sub_819FF98(u8 arg0); +bool8 sub_81A0194(u8 arg0, u16 moveId); +void sub_81A0804(u8 arg0, u8 itemsCount, u8 windowId); +u8 sub_81A0784(u8 arg0, u8 arg1, u8 arg2, u8 arg3); void sub_819F99C(u8 id) { @@ -42,15 +72,15 @@ void sub_819FA50(void) EnableBothScriptContexts(); } -void sub_819FA5C(struct UnkRecordMixingStruct *structPtr) +void sub_819FA5C(struct Apprentice *apprentice) { u8 i; for (i = 0; i < 6; i++) - structPtr->unk28[i] |= 0xFFFF; + apprentice->unk28[i] |= 0xFFFF; - structPtr->playerName[0] = EOS; - structPtr->field_0_0 = 16; + apprentice->playerName[0] = EOS; + apprentice->field_0_0 = 16; } void sub_819FAA0(void) @@ -149,3 +179,385 @@ u8 sub_819FCF8(u8 val, u8 *arg1, u8 *arg2) return ret; } + +void sub_819FD64(void) +{ + u8 sp_0[10]; + u8 sp_C[3]; + u8 sp_10; + u8 i, j; + u8 rand1, rand2; + u8 id; + + for (i = 0; i < 3; i++) + sp_C[i] = i; + for (i = 0; i < 10; i++) + { + u8 temp; + rand1 = Random() % ARRAY_COUNT(sp_C); + rand2 = Random() % ARRAY_COUNT(sp_C); + SWAP(sp_C[rand1], sp_C[rand2], temp); + } + + for (i = 0; i < 10; i++) + sp_0[i] = gUnknown_086114D3[i]; + for (i = 0; i < 50; i++) + { + u8 temp; + rand1 = Random() % ARRAY_COUNT(sp_0); + rand2 = Random() % ARRAY_COUNT(sp_0); + SWAP(sp_0[rand1], sp_0[rand2], temp); + } + + gUnknown_030062EC = AllocZeroed(sizeof(*gUnknown_030062EC)); + gUnknown_030062EC->unk0 = 0; + for (i = 0; i < 5; i++) + { + for (j = 0; j < 3; j++) + gUnknown_030062EC->unk20[j][i] = 4; + } + + sp_10 = 0; + for (i = 0; i < 9; i++) + { + gSaveBlock2Ptr->field_B8[i].unk0_0 = sp_0[i]; + if (sp_0[i] != 3) + { + gSaveBlock2Ptr->field_B8[i].unk0_1 = sub_819FCF8(sp_0[i], sp_C, &sp_10); + id = gSaveBlock2Ptr->field_B8[i].unk0_1; + if (sp_0[i] == 2) + { + do + { + rand1 = Random() % 4; + for (j = 0; j < gUnknown_030062EC->unk0 + 1; j++) + { + if (gUnknown_030062EC->unk20[id][j] == rand1) + break; + } + } while (j != gUnknown_030062EC->unk0 + 1); + + gUnknown_030062EC->unk20[id][gUnknown_030062EC->unk0] = rand1; + gSaveBlock2Ptr->field_B8[i].unk0_2 = rand1; + gSaveBlock2Ptr->field_B8[i].unk2 = sub_819FF98(gSaveBlock2Ptr->field_B8[i].unk0_1); + } + } + } + + FREE_AND_SET_NULL(gUnknown_030062EC); +} + +// No idea why a do-while loop is needed, but it will not match without it. + +#define APPRENTICE_SPECIES_ID(speciesArrId, monId) speciesArrId = (gSaveBlock2Ptr->field_B4[monId] >> \ + (((gSaveBlock2Ptr->field_B2_0 >> monId) & 1) << 2)) & 0xF; \ + do {} while (0) + +u16 sub_819FF98(u8 arg0) +{ + u8 i, j; + u8 id; + u8 knownMovesCount; + u16 species; + const u16 *learnset; + bool32 var_24 = FALSE; + u16 moveId = 0; + bool32 valid; + u8 level; + + if (arg0 < 3) + { + APPRENTICE_SPECIES_ID(id, arg0); + } + else + { + id = 0; + } + + species = gApprentices[gSaveBlock2Ptr->field_B0].species[id]; + learnset = gLevelUpLearnsets[species]; + j = 0; + if (gSaveBlock2Ptr->field_B1_0 == 1) + level = 50; + else + level = 60; + + for (j = 0; learnset[j] != 0xFFFF; j++) + { + if ((learnset[j] & 0xFE00) > (level << 9)) + break; + } + + knownMovesCount = j; + i = 0; + while (i < 5) + { + if (Random() % 2 == 0 || var_24 == TRUE) + { + do + { + do + { + id = Random() % (NUM_TECHNICAL_MACHINES + NUM_HIDDEN_MACHINES); + valid = CanSpeciesLearnTMHM(species, id); + } + while (!valid); + + moveId = ItemIdToBattleMoveId(ITEM_TM01 + id); + valid = TRUE; + + if (knownMovesCount < 5) + j = 0; + else + j = knownMovesCount - 4; + + for (; j < knownMovesCount; j++) + { + if ((learnset[j] & 0x1FF) == moveId) + { + valid = FALSE; + break; + } + } + } while (valid != TRUE); + } + else + { + if (knownMovesCount < 5) + { + var_24 = TRUE; + continue; + } + else + { + do + { + u8 learnsetId = Random() % (knownMovesCount - 4); + moveId = learnset[learnsetId] & 0x1FF; + valid = TRUE; + for (j = knownMovesCount - 4; j < knownMovesCount; j++) + { + if ((learnset[j] & 0x1FF) == moveId) + { + valid = FALSE; + break; + } + } + } while (valid != TRUE); + } + } + + if (sub_81A0194(arg0, moveId)) + { + if (gUnknown_08611370[moveId]) + break; + i++; + } + } + + gUnknown_030062EC->unk0++; + return moveId; +} + +bool8 sub_81A0194(u8 arg0, u16 moveId) +{ + u8 i; + + for (i = 0; i < 5; i++) + { + if (gUnknown_030062EC->unk2[arg0][i] == moveId) + return FALSE; + } + + gUnknown_030062EC->unk2[arg0][gUnknown_030062EC->unk0] = moveId; + return TRUE; +} + +void GetLatestLearnedMoves(u16 species, u16 *moves) +{ + u8 i, j; + u8 level, knownMovesCount; + const u16 *learnset; + + if (gSaveBlock2Ptr->field_B1_0 == 1) + level = 50; + else + level = 60; + + learnset = gLevelUpLearnsets[species]; + for (i = 0; learnset[i] != 0xFFFF; i++) + { + if ((learnset[i] & 0xFE00) > (level << 9)) + break; + } + + knownMovesCount = i; + if (knownMovesCount > 4) + knownMovesCount = 4; + + for (j = 0; j < knownMovesCount; j++) + moves[j] = learnset[(i - 1) - j] & 0x1FF; +} + +u16 sub_81A0284(u8 arg0, u8 speciesTableId, u8 arg2) +{ + u16 moves[4]; + u8 i, count; + + if (gSaveBlock2Ptr->field_B1_1 < 3) + return 0; + + count = 0; + for (i = 0; i < 9; i++) + { + if (gSaveBlock2Ptr->field_B8[i].unk0_0 == 0) + break; + count++; + } + + GetLatestLearnedMoves(gApprentices[gSaveBlock2Ptr->field_B0].species[speciesTableId], moves); + for (i = 0; i < count && i < gSaveBlock2Ptr->field_B1_1 - 3; i++) + { + if (gSaveBlock2Ptr->field_B8[i].unk0_0 == 2 + && gSaveBlock2Ptr->field_B8[i].unk0_1 == arg0 + && gSaveBlock2Ptr->field_B8[i].unk0_3 != 0) + { + moves[gSaveBlock2Ptr->field_B8[i].unk0_2] = gSaveBlock2Ptr->field_B8[i].unk2; + } + } + + return moves[arg2]; +} + +void sub_81A0390(u8 arg0) +{ + struct ApprenticeMon *apprenticeMons[3]; + u8 i, j; + u32 speciesTableId; + + for (i = 0; i < 3; i++) + { + gSaveBlock2Ptr->field_DC[0].monData[i].species = 0; + gSaveBlock2Ptr->field_DC[0].monData[i].item = 0; + for (j = 0; j < 4; j++) + gSaveBlock2Ptr->field_DC[0].monData[i].moves[j] = 0; + } + + j = gSaveBlock2Ptr->field_B1_2; + for (i = 0; i < 3; i++) + { + apprenticeMons[j] = &gSaveBlock2Ptr->field_DC[0].monData[i]; + j = (j + 1) % 3; + } + + for (i = 0; i < 3; i++) + { + APPRENTICE_SPECIES_ID(speciesTableId, i); + apprenticeMons[i]->species = gApprentices[gSaveBlock2Ptr->field_B0].species[speciesTableId]; + GetLatestLearnedMoves(apprenticeMons[i]->species, apprenticeMons[i]->moves); + } + + for (i = 0; i < arg0; i++) + { + u8 var1 = gSaveBlock2Ptr->field_B8[i].unk0_0; + u8 monId = gSaveBlock2Ptr->field_B8[i].unk0_1; + if (var1 == 1) + { + if (gSaveBlock2Ptr->field_B8[i].unk0_3 != 0) + apprenticeMons[monId]->item = gSaveBlock2Ptr->field_B8[i].unk2; + } + else if (var1 == 2) + { + if (gSaveBlock2Ptr->field_B8[i].unk0_3 != 0) + { + u32 moveSlot = gSaveBlock2Ptr->field_B8[i].unk0_2; + apprenticeMons[monId]->moves[moveSlot] = gSaveBlock2Ptr->field_B8[i].unk2; + } + } + } +} + +void sub_81A04E4(u8 arg0) +{ + u8 i; + u8 windowId; + const u8 *strings[3]; + u8 count = 2; + u8 tileWidth; + u8 r10; + u8 r6; + s32 pixelWidth; + + switch (arg0) + { + case 0: + r10 = 0x12; + r6 = 8; + strings[0] = gText_Lv50; + strings[1] = gText_OpenLevel; + break; + case 1: + count = 3; + r10 = 0x12; + r6 = 6; + for (i = 0; i < 3; i++) + { + u16 species; + u32 speciesTableId; + + APPRENTICE_SPECIES_ID(speciesTableId, i); + species = gApprentices[gSaveBlock2Ptr->field_B0].species[speciesTableId]; + strings[i] = gSpeciesNames[species]; + } + break; + case 2: + r10 = 0x12; + r6 = 8; + if (gSaveBlock2Ptr->field_B1_1 > 2) + return; + strings[1] = gSpeciesNames[gUnknown_030062F0->unk2]; + strings[0] = gSpeciesNames[gUnknown_030062F0->unk0]; + break; + case 3: + r10 = 0x11; + r6 = 8; + strings[0] = gMoveNames[gUnknown_030062F0->unk4]; + strings[1] = gMoveNames[gUnknown_030062F0->unk6]; + break; + case 4: + r10 = 0x12; + r6 = 8; + strings[0] = gText_Give; + strings[1] = gText_NoNeed; + break; + case 6: + r10 = 0x14; + r6 = 8; + strings[0] = gText_Yes; + strings[1] = gText_No; + break; + default: + r10 = 0; + r6 = 0; + break; + } + + pixelWidth = 0; + for (i = 0; i < count; i++) + { + s32 width = GetStringWidth(1, strings[i], 0); + if (width > pixelWidth) + pixelWidth = width; + } + + tileWidth = convert_pixel_width_to_tile_width(pixelWidth); + r10 = sub_80E2D5C(r10, tileWidth); + windowId = sub_81A0784(r10, r6, tileWidth, count * 2); + SetStandardWindowBorderStyle(windowId, 0); + + for (i = 0; i < count; i++) + AddTextPrinterParameterized(windowId, 1, strings[i], 8, (i * 16) + 1, TEXT_SPEED_FF, NULL); + + InitMenuInUpperLeftCornerPlaySoundWhenAPressed(windowId, count, 0); + sub_81A0804(1, count, windowId); +} diff --git a/src/pokemon.c b/src/pokemon.c index 8e2e3b764..bb2fc753c 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -35,6 +35,7 @@ #include "pokenav.h" #include "pokemon_storage_system.h" #include "recorded_battle.h" +#include "apprentice.h" struct SpeciesItem { @@ -69,7 +70,6 @@ extern const union AnimCmd *const *const gMonAnimationsSpriteAnimsPtrTable[]; extern const union AnimCmd *const *const gTrainerBackAnimsPtrTable[]; extern const union AnimCmd *const *const gTrainerFrontAnimsPtrTable[]; extern const u8 gSpeciesNames[][POKEMON_NAME_LENGTH + 1]; -extern const struct UnknownPokemonStruct3 gUnknown_08610970[]; extern const struct CompressedSpritePalette gMonPaletteTable[]; extern const struct CompressedSpritePalette gMonShinyPaletteTable[]; extern const u8 gTrainerClassNames[][13]; @@ -2873,17 +2873,17 @@ void sub_8068338(struct Pokemon *mon, struct UnknownPokemonStruct *src, bool8 lv CalculateMonStats(mon); } -void sub_8068528(struct Pokemon *mon, const struct UnknownPokemonStruct2 *src, u8 monId) +void CreateApprenticeMon(struct Pokemon *mon, const struct Apprentice *src, u8 monId) { s32 i; u16 evAmount; u8 language; - u32 otId = gUnknown_08610970[src->field_0_0].field_30; - u32 personality = ((gUnknown_08610970[src->field_0_0].field_30 >> 8) | ((gUnknown_08610970[src->field_0_0].field_30 & 0xFF) << 8)) - + src->mons[monId].species + src->field_2; + u32 otId = gApprentices[src->field_0_0].otId; + u32 personality = ((gApprentices[src->field_0_0].otId >> 8) | ((gApprentices[src->field_0_0].otId & 0xFF) << 8)) + + src->monData[monId].species + src->field_2; CreateMon(mon, - src->mons[monId].species, + src->monData[monId].species, GetFrontierEnemyMonLevel(src->field_0_1 - 1), 0x1F, TRUE, @@ -2891,9 +2891,9 @@ void sub_8068528(struct Pokemon *mon, const struct UnknownPokemonStruct2 *src, u TRUE, otId); - SetMonData(mon, MON_DATA_HELD_ITEM, &src->mons[monId].item); + SetMonData(mon, MON_DATA_HELD_ITEM, &src->monData[monId].item); for (i = 0; i < 4; i++) - SetMonMoveSlot(mon, src->mons[monId].moves[i], i); + SetMonMoveSlot(mon, src->monData[monId].moves[i], i); evAmount = MAX_TOTAL_EVS / NUM_STATS; for (i = 0; i < NUM_STATS; i++) diff --git a/src/record_mixing.c b/src/record_mixing.c index 6c6f69fa8..8d0022f17 100644 --- a/src/record_mixing.c +++ b/src/record_mixing.c @@ -83,7 +83,7 @@ struct PlayerRecordsEmerald /* 0x1124 */ struct EmeraldBattleTowerRecord battleTowerRecord; /* 0x1210 */ u16 unk_1210; /* 0x1214 */ LilycoveLady lilycoveLady; - /* 0x1254 */ struct UnkRecordMixingStruct unk_1254[2]; + /* 0x1254 */ struct Apprentice apprentice[2]; /* 0x12dc */ struct UnkRecordMixingStruct2 unk_12dc; /* 0x1434 */ u8 field_1434[0x10]; }; // 0x1444 @@ -134,8 +134,8 @@ static void sub_80E7B2C(const u8 *); static void ReceiveDaycareMailData(struct RecordMixingDayCareMail *, size_t, u8, TVShow *); static void sub_80E7F68(u16 *item, u8 which); static void sub_80E7FF8(u8 taskId); -static void sub_80E8110(struct UnkRecordMixingStruct *arg0, struct UnkRecordMixingStruct *arg1); -static void sub_80E8468(struct UnkRecordMixingStruct *arg0, size_t arg1, u32 arg2); +static void sub_80E8110(struct Apprentice *arg0, struct Apprentice *arg1); +static void ReceiveApprenticeData(struct Apprentice *arg0, size_t arg1, u32 arg2); static void sub_80E89AC(struct UnkRecordMixingStruct2 *arg0, size_t arg1, u32 arg2); static void sub_80E89F8(struct RecordMixingDayCareMail *dst); static void SanitizeDayCareMailForRuby(struct RecordMixingDayCareMail *src); @@ -265,7 +265,7 @@ static void PrepareExchangePacket(void) if (GetMultiplayerId() == 0) sSentRecord->emerald.unk_1210 = GetRecordMixingGift(); - sub_80E8110(sSentRecord->emerald.unk_1254, gUnknown_03001154); + sub_80E8110(sSentRecord->emerald.apprentice, gUnknown_03001154); sub_80E8260(&sSentRecord->emerald.unk_12dc); } } @@ -298,7 +298,7 @@ static void ReceiveExchangePacket(u32 which) ReceiveBattleTowerData(&sReceivedRecords->emerald.battleTowerRecord, sizeof(struct PlayerRecordsEmerald), which); sub_80E7F68(&sReceivedRecords->emerald.unk_1210, which); ReceiveLilycoveLadyData(&sReceivedRecords->emerald.lilycoveLady, sizeof(struct PlayerRecordsEmerald), which); - sub_80E8468(sReceivedRecords->emerald.unk_1254, sizeof(struct PlayerRecordsEmerald), (u8) which); + ReceiveApprenticeData(sReceivedRecords->emerald.apprentice, sizeof(struct PlayerRecordsEmerald), (u8) which); sub_80E89AC(&sReceivedRecords->emerald.unk_12dc, sizeof(struct PlayerRecordsEmerald), (u8) which); } } @@ -1551,13 +1551,13 @@ static void sub_80E7FF8(u8 taskId) // New Emerald functions -static void sub_80E8110(struct UnkRecordMixingStruct *dst, struct UnkRecordMixingStruct *src) +static void sub_80E8110(struct Apprentice *dst, struct Apprentice *src) { s32 i, id; s32 var_2C, var_28, var_24, r8; - dst[0].field_38[0] = 0xFF; - dst[1].field_38[0] = 0xFF; + dst[0].playerName[0] = EOS; + dst[1].playerName[0] = EOS; dst[0] = src[0]; @@ -1568,7 +1568,7 @@ static void sub_80E8110(struct UnkRecordMixingStruct *dst, struct UnkRecordMixin for (i = 0; i < 2; i++) { id = ((i + gSaveBlock2Ptr->field_B2_1) % 3) + 1; - if (src[id].field_38[0] != 0xFF) + if (src[id].playerName[0] != EOS) { if (ReadUnalignedWord(src[id].playerId) != ReadUnalignedWord(gSaveBlock2Ptr->playerTrainerId)) { @@ -1646,14 +1646,14 @@ void sub_80E8260(struct UnkRecordMixingStruct2 *dst) } } -static bool32 sub_80E841C(struct UnkRecordMixingStruct *arg0, struct UnkRecordMixingStruct *arg1) +static bool32 sub_80E841C(struct Apprentice *arg0, struct Apprentice *arg1) { s32 i; for (i = 0; i < 4; i++) { if (ReadUnalignedWord(arg0->playerId) == ReadUnalignedWord(arg1[i].playerId) - && arg0->field_0[2] == arg1[i].field_0[2]) + && arg0->field_2 == arg1[i].field_2) { return TRUE; } @@ -1662,10 +1662,10 @@ static bool32 sub_80E841C(struct UnkRecordMixingStruct *arg0, struct UnkRecordMi return FALSE; } -static void sub_80E8468(struct UnkRecordMixingStruct *arg0, size_t arg1, u32 arg2) +static void ReceiveApprenticeData(struct Apprentice *arg0, size_t arg1, u32 arg2) { s32 i, r7, r8; - struct UnkRecordMixingStruct *structPtr; + struct Apprentice *structPtr; u32 mixIndices[4]; u32 structId; @@ -1675,7 +1675,7 @@ static void sub_80E8468(struct UnkRecordMixingStruct *arg0, size_t arg1, u32 arg r8 = 0; for (i = 0; i < 2; i++) { - if (structPtr[i].field_38[0] != 0xFF && !sub_80E841C(&structPtr[i], gSaveBlock2Ptr->field_DC)) + if (structPtr[i].playerName[0] != EOS && !sub_80E841C(&structPtr[i], gSaveBlock2Ptr->field_DC)) { r7++; r8 = i;