diff --git a/asm/pokemon_2.s b/asm/pokemon_2.s index a13c6951c4..4b88cfb4f3 100644 --- a/asm/pokemon_2.s +++ b/asm/pokemon_2.s @@ -5,2059 +5,6 @@ .text - thumb_func_start GetBoxMonData -@ int GetBoxMonData(pokemon *mon, enum pokemon_data_request req, void *data) -GetBoxMonData: @ 806A674 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x4 - mov r8, r0 - str r1, [sp] - adds r6, r2, 0 - movs r4, 0 - mov r9, r4 - mov r10, r4 - movs r7, 0 - movs r5, 0 - cmp r1, 0xA - ble _0806A6F2 - ldr r1, [r0] - movs r2, 0 - bl GetSubstruct - mov r9, r0 - mov r0, r8 - ldr r1, [r0] - movs r2, 0x1 - bl GetSubstruct - mov r10, r0 - mov r2, r8 - ldr r1, [r2] - mov r0, r8 - movs r2, 0x2 - bl GetSubstruct - adds r7, r0, 0 - mov r0, r8 - ldr r1, [r0] - movs r2, 0x3 - bl GetSubstruct - adds r5, r0, 0 - mov r0, r8 - bl DecryptBoxMon - mov r0, r8 - bl CalculateBoxMonChecksum - lsls r0, 16 - lsrs r0, 16 - mov r1, r8 - ldrh r1, [r1, 0x1C] - cmp r0, r1 - beq _0806A6F2 - mov r2, r8 - ldrb r0, [r2, 0x13] - movs r1, 0x1 - orrs r0, r1 - movs r1, 0x4 - orrs r0, r1 - strb r0, [r2, 0x13] - ldrb r0, [r5, 0x7] - movs r1, 0x40 - orrs r0, r1 - strb r0, [r5, 0x7] -_0806A6F2: - ldr r0, [sp] - cmp r0, 0x53 - bls _0806A6FA - b _0806AC8C -_0806A6FA: - lsls r0, 2 - ldr r1, =_0806A708 - adds r0, r1 - ldr r0, [r0] - mov pc, r0 - .pool - .align 2, 0 -_0806A708: - .4byte _0806A858 - .4byte _0806A85E - .4byte _0806A864 - .4byte _0806A918 - .4byte _0806A91E - .4byte _0806A924 - .4byte _0806A92A - .4byte _0806A930 - .4byte _0806A94C - .4byte _0806A952 - .4byte _0806A958 - .4byte _0806A95E - .4byte _0806A976 - .4byte _0806A98E - .4byte _0806A98E - .4byte _0806A98E - .4byte _0806A98E - .4byte _0806A99A - .4byte _0806A99A - .4byte _0806A99A - .4byte _0806A99A - .4byte _0806A982 - .4byte _0806A9BC - .4byte _0806A9C0 - .4byte _0806A9C4 - .4byte _0806A97C - .4byte _0806A9A4 - .4byte _0806A9A8 - .4byte _0806A9AC - .4byte _0806A9B0 - .4byte _0806A9B4 - .4byte _0806A9B8 - .4byte _0806A988 - .4byte _0806A9C8 - .4byte _0806A9D4 - .4byte _0806A9D8 - .4byte _0806A9DC - .4byte _0806A9E4 - .4byte _0806A9EC - .4byte _0806A9F6 - .4byte _0806A9FE - .4byte _0806AA06 - .4byte _0806AA0E - .4byte _0806AA16 - .4byte _0806AA1E - .4byte _0806AA26 - .4byte _0806AA2A - .4byte _0806A9CC - .4byte _0806A9D0 - .4byte _0806A9F0 - .4byte _0806AA30 - .4byte _0806AA38 - .4byte _0806AA40 - .4byte _0806AA48 - .4byte _0806AA50 - .4byte _0806AC8C - .4byte _0806AC8C - .4byte _0806AC8C - .4byte _0806AC8C - .4byte _0806AC8C - .4byte _0806AC8C - .4byte _0806AC8C - .4byte _0806AC8C - .4byte _0806AC8C - .4byte _0806AC8C - .4byte _0806AAB6 - .4byte _0806AADC - .4byte _0806AA58 - .4byte _0806AA5E - .4byte _0806AA62 - .4byte _0806AA66 - .4byte _0806AA6A - .4byte _0806AA72 - .4byte _0806AA7A - .4byte _0806AA82 - .4byte _0806AA8A - .4byte _0806AA90 - .4byte _0806AA98 - .4byte _0806AAA0 - .4byte _0806AAA8 - .4byte _0806AAB0 - .4byte _0806AB16 - .4byte _0806AB70 - .4byte _0806ABF2 -_0806A858: - mov r1, r8 - ldr r4, [r1] - b _0806AC8C -_0806A85E: - mov r2, r8 - ldr r4, [r2, 0x4] - b _0806AC8C -_0806A864: - mov r0, r8 - ldrb r1, [r0, 0x13] - movs r0, 0x1 - ands r0, r1 - cmp r0, 0 - beq _0806A89C - movs r4, 0 - ldr r0, =gBadEggNickname - ldrb r1, [r0] - adds r2, r0, 0 - cmp r1, 0xFF - beq _0806A944 - adds r3, r2, 0 -_0806A87E: - adds r0, r6, r4 - adds r1, r4, r3 - ldrb r1, [r1] - strb r1, [r0] - adds r4, 0x1 - cmp r4, 0x9 - bhi _0806A944 - adds r0, r4, r2 - ldrb r0, [r0] - cmp r0, 0xFF - bne _0806A87E - b _0806A944 - .pool -_0806A89C: - movs r0, 0x4 - ands r0, r1 - cmp r0, 0 - beq _0806A8BC - ldr r1, =gEggNickname - adds r0, r6, 0 - bl StringCopy - adds r0, r6, 0 - bl StringLength - lsls r0, 16 - lsrs r4, r0, 16 - b _0806AC8C - .pool -_0806A8BC: - mov r1, r8 - ldrb r0, [r1, 0x12] - cmp r0, 0x1 - bne _0806A902 - movs r0, 0xFC - strb r0, [r6] - movs r0, 0x15 - strb r0, [r6, 0x1] - movs r4, 0x2 - movs r3, 0 - ldrb r0, [r1, 0x8] - cmp r0, 0xFF - beq _0806A8F0 - mov r2, r8 - adds r2, 0x8 -_0806A8DA: - adds r1, r6, r4 - ldrb r0, [r2] - strb r0, [r1] - adds r4, 0x1 - adds r2, 0x1 - adds r3, 0x1 - cmp r3, 0x4 - bgt _0806A8F0 - ldrb r0, [r2] - cmp r0, 0xFF - bne _0806A8DA -_0806A8F0: - adds r1, r6, r4 - movs r0, 0xFC - strb r0, [r1] - adds r4, 0x1 - adds r1, r6, r4 - movs r0, 0x16 - strb r0, [r1] - adds r4, 0x1 - b _0806A944 -_0806A902: - movs r4, 0 - mov r2, r8 - adds r2, 0x8 -_0806A908: - adds r0, r6, r4 - adds r1, r2, r4 - ldrb r1, [r1] - strb r1, [r0] - adds r4, 0x1 - cmp r4, 0x9 - bls _0806A908 - b _0806A944 -_0806A918: - mov r2, r8 - ldrb r4, [r2, 0x12] - b _0806AC8C -_0806A91E: - mov r6, r8 - ldrb r0, [r6, 0x13] - b _0806AA92 -_0806A924: - mov r1, r8 - ldrb r0, [r1, 0x13] - b _0806AA9A -_0806A92A: - mov r2, r8 - ldrb r0, [r2, 0x13] - b _0806AAA2 -_0806A930: - movs r4, 0 - mov r2, r8 - adds r2, 0x14 -_0806A936: - adds r0, r6, r4 - adds r1, r2, r4 - ldrb r1, [r1] - strb r1, [r0] - adds r4, 0x1 - cmp r4, 0x6 - bls _0806A936 -_0806A944: - adds r1, r6, r4 - movs r0, 0xFF - strb r0, [r1] - b _0806AC8C -_0806A94C: - mov r6, r8 - ldrb r4, [r6, 0x1B] - b _0806AC8C -_0806A952: - mov r0, r8 - ldrh r4, [r0, 0x1C] - b _0806AC8C -_0806A958: - mov r1, r8 - ldrh r4, [r1, 0x1E] - b _0806AC8C -_0806A95E: - mov r2, r8 - ldrb r1, [r2, 0x13] - movs r0, 0x1 - ands r0, r1 - movs r4, 0xCE - lsls r4, 1 - cmp r0, 0 - beq _0806A970 - b _0806AC8C -_0806A970: - mov r6, r9 - ldrh r4, [r6] - b _0806AC8C -_0806A976: - mov r0, r9 - ldrh r4, [r0, 0x2] - b _0806AC8C -_0806A97C: - mov r1, r9 - ldr r4, [r1, 0x4] - b _0806AC8C -_0806A982: - mov r2, r9 - ldrb r4, [r2, 0x8] - b _0806AC8C -_0806A988: - mov r6, r9 - ldrb r4, [r6, 0x9] - b _0806AC8C -_0806A98E: - ldr r0, [sp] - subs r0, 0xD - lsls r0, 1 - add r0, r10 - ldrh r4, [r0] - b _0806AC8C -_0806A99A: - ldr r0, [sp] - add r0, r10 - subs r0, 0x9 - ldrb r4, [r0] - b _0806AC8C -_0806A9A4: - ldrb r4, [r7] - b _0806AC8C -_0806A9A8: - ldrb r4, [r7, 0x1] - b _0806AC8C -_0806A9AC: - ldrb r4, [r7, 0x2] - b _0806AC8C -_0806A9B0: - ldrb r4, [r7, 0x3] - b _0806AC8C -_0806A9B4: - ldrb r4, [r7, 0x4] - b _0806AC8C -_0806A9B8: - ldrb r4, [r7, 0x5] - b _0806AC8C -_0806A9BC: - ldrb r4, [r7, 0x6] - b _0806AC8C -_0806A9C0: - ldrb r4, [r7, 0x7] - b _0806AC8C -_0806A9C4: - ldrb r4, [r7, 0x8] - b _0806AC8C -_0806A9C8: - ldrb r4, [r7, 0x9] - b _0806AC8C -_0806A9CC: - ldrb r4, [r7, 0xA] - b _0806AC8C -_0806A9D0: - ldrb r4, [r7, 0xB] - b _0806AC8C -_0806A9D4: - ldrb r4, [r5] - b _0806AC8C -_0806A9D8: - ldrb r4, [r5, 0x1] - b _0806AC8C -_0806A9DC: - ldrb r0, [r5, 0x2] - lsls r0, 25 - lsrs r4, r0, 25 - b _0806AC8C -_0806A9E4: - ldrh r0, [r5, 0x2] - lsls r0, 21 - lsrs r4, r0, 28 - b _0806AC8C -_0806A9EC: - ldrb r0, [r5, 0x3] - b _0806AAAA -_0806A9F0: - ldrb r0, [r5, 0x3] - lsrs r4, r0, 7 - b _0806AC8C -_0806A9F6: - ldrb r0, [r5, 0x4] - lsls r0, 27 - lsrs r4, r0, 27 - b _0806AC8C -_0806A9FE: - ldrh r0, [r5, 0x4] - lsls r0, 22 - lsrs r4, r0, 27 - b _0806AC8C -_0806AA06: - ldrb r0, [r5, 0x5] - lsls r0, 25 - lsrs r4, r0, 27 - b _0806AC8C -_0806AA0E: - ldr r0, [r5, 0x4] - lsls r0, 12 - lsrs r4, r0, 27 - b _0806AC8C -_0806AA16: - ldrh r0, [r5, 0x6] - lsls r0, 23 - lsrs r4, r0, 27 - b _0806AC8C -_0806AA1E: - ldrb r0, [r5, 0x7] - lsls r0, 26 - lsrs r4, r0, 27 - b _0806AC8C -_0806AA26: - ldrb r0, [r5, 0x7] - b _0806AA84 -_0806AA2A: - ldrb r0, [r5, 0x7] - lsrs r4, r0, 7 - b _0806AC8C -_0806AA30: - ldrb r0, [r5, 0x8] - lsls r0, 29 - lsrs r4, r0, 29 - b _0806AC8C -_0806AA38: - ldrb r0, [r5, 0x8] - lsls r0, 26 - lsrs r4, r0, 29 - b _0806AC8C -_0806AA40: - ldrh r0, [r5, 0x8] - lsls r0, 23 - lsrs r4, r0, 29 - b _0806AC8C -_0806AA48: - ldrb r0, [r5, 0x9] - lsls r0, 28 - lsrs r4, r0, 29 - b _0806AC8C -_0806AA50: - ldrb r0, [r5, 0x9] - lsls r0, 25 - lsrs r4, r0, 29 - b _0806AC8C -_0806AA58: - ldrb r0, [r5, 0x9] - lsrs r4, r0, 7 - b _0806AC8C -_0806AA5E: - ldrb r0, [r5, 0xA] - b _0806AA92 -_0806AA62: - ldrb r0, [r5, 0xA] - b _0806AA9A -_0806AA66: - ldrb r0, [r5, 0xA] - b _0806AAA2 -_0806AA6A: - ldrb r0, [r5, 0xA] - lsls r0, 28 - lsrs r4, r0, 31 - b _0806AC8C -_0806AA72: - ldrb r0, [r5, 0xA] - lsls r0, 27 - lsrs r4, r0, 31 - b _0806AC8C -_0806AA7A: - ldrb r0, [r5, 0xA] - lsls r0, 26 - lsrs r4, r0, 31 - b _0806AC8C -_0806AA82: - ldrb r0, [r5, 0xA] -_0806AA84: - lsls r0, 25 - lsrs r4, r0, 31 - b _0806AC8C -_0806AA8A: - ldrb r0, [r5, 0xA] - lsrs r4, r0, 7 - b _0806AC8C -_0806AA90: - ldrb r0, [r5, 0xB] -_0806AA92: - lsls r0, 31 - lsrs r4, r0, 31 - b _0806AC8C -_0806AA98: - ldrb r0, [r5, 0xB] -_0806AA9A: - lsls r0, 30 - lsrs r4, r0, 31 - b _0806AC8C -_0806AAA0: - ldrb r0, [r5, 0xB] -_0806AAA2: - lsls r0, 29 - lsrs r4, r0, 31 - b _0806AC8C -_0806AAA8: - ldrb r0, [r5, 0xB] -_0806AAAA: - lsls r0, 25 - lsrs r4, r0, 28 - b _0806AC8C -_0806AAB0: - ldrb r0, [r5, 0xB] - lsrs r4, r0, 7 - b _0806AC8C -_0806AAB6: - mov r0, r9 - ldrh r4, [r0] - cmp r4, 0 - bne _0806AAC0 - b _0806AC8C -_0806AAC0: - ldrb r0, [r5, 0x7] - lsls r0, 25 - cmp r0, 0 - blt _0806AAD6 - mov r2, r8 - ldrb r1, [r2, 0x13] - movs r0, 0x1 - ands r0, r1 - cmp r0, 0 - bne _0806AAD6 - b _0806AC8C -_0806AAD6: - movs r4, 0xCE - lsls r4, 1 - b _0806AC8C -_0806AADC: - ldrb r0, [r5, 0x4] - lsls r0, 27 - lsrs r4, r0, 27 - ldrh r1, [r5, 0x4] - movs r0, 0xF8 - lsls r0, 2 - ands r0, r1 - orrs r4, r0 - ldrb r0, [r5, 0x5] - lsls r0, 25 - lsrs r0, 27 - lsls r0, 10 - orrs r4, r0 - ldr r0, [r5, 0x4] - movs r1, 0xF8 - lsls r1, 12 - ands r0, r1 - orrs r4, r0 - ldrh r0, [r5, 0x6] - lsls r0, 23 - lsrs r0, 27 - lsls r0, 20 - orrs r4, r0 - ldrb r0, [r5, 0x7] - lsls r0, 26 - lsrs r0, 27 - lsls r0, 25 - orrs r4, r0 - b _0806AC8C -_0806AB16: - mov r1, r9 - ldrh r0, [r1] - cmp r0, 0 - bne _0806AB20 - b _0806AC8C -_0806AB20: - ldrb r0, [r5, 0x7] - lsls r0, 25 - cmp r0, 0 - bge _0806AB2A - b _0806AC8C -_0806AB2A: - ldrh r0, [r6] - ldr r1, =0x00000163 - cmp r0, r1 - bne _0806AB34 - b _0806AC8C -_0806AB34: - mov r2, r10 - ldrh r5, [r2] - adds r7, r1, 0 - adds r2, r6, 0 - ldr r1, =gBitTable -_0806AB3E: - ldrh r3, [r2] - cmp r5, r3 - beq _0806AB58 - mov r6, r10 - ldrh r0, [r6, 0x2] - cmp r0, r3 - beq _0806AB58 - ldrh r0, [r6, 0x4] - cmp r0, r3 - beq _0806AB58 - ldrh r0, [r6, 0x6] - cmp r0, r3 - bne _0806AB5C -_0806AB58: - ldr r0, [r1] - orrs r4, r0 -_0806AB5C: - adds r2, 0x2 - adds r1, 0x4 - ldrh r0, [r2] - cmp r0, r7 - bne _0806AB3E - b _0806AC8C - .pool -_0806AB70: - movs r4, 0 - mov r1, r9 - ldrh r0, [r1] - cmp r0, 0 - bne _0806AB7C - b _0806AC8C -_0806AB7C: - ldrb r0, [r5, 0x7] - lsls r0, 25 - cmp r0, 0 - bge _0806AB86 - b _0806AC8C -_0806AB86: - ldrb r0, [r5, 0x8] - lsls r1, r0, 29 - lsrs r4, r1, 29 - lsls r0, 26 - lsrs r0, 29 - adds r4, r0 - ldrh r0, [r5, 0x8] - lsls r0, 23 - lsrs r0, 29 - adds r4, r0 - ldrb r1, [r5, 0x9] - lsls r0, r1, 28 - lsrs r0, 29 - adds r4, r0 - lsls r0, r1, 25 - lsrs r0, 29 - adds r4, r0 - lsrs r1, 7 - adds r4, r1 - ldrb r1, [r5, 0xA] - lsls r0, r1, 31 - lsrs r0, 31 - adds r4, r0 - lsls r0, r1, 30 - lsrs r0, 31 - adds r4, r0 - lsls r0, r1, 29 - lsrs r0, 31 - adds r4, r0 - lsls r0, r1, 28 - lsrs r0, 31 - adds r4, r0 - lsls r0, r1, 27 - lsrs r0, 31 - adds r4, r0 - lsls r0, r1, 26 - lsrs r0, 31 - adds r4, r0 - lsls r0, r1, 25 - lsrs r0, 31 - adds r4, r0 - lsrs r1, 7 - adds r4, r1 - ldrb r1, [r5, 0xB] - lsls r0, r1, 31 - lsrs r0, 31 - adds r4, r0 - lsls r0, r1, 30 - lsrs r0, 31 - adds r4, r0 - lsls r1, 29 - lsrs r1, 31 - adds r4, r1 - b _0806AC8C -_0806ABF2: - movs r4, 0 - mov r2, r9 - ldrh r0, [r2] - cmp r0, 0 - beq _0806AC8C - ldrb r0, [r5, 0x7] - lsls r0, 25 - cmp r0, 0 - blt _0806AC8C - ldrb r2, [r5, 0x9] - lsrs r4, r2, 7 - ldrb r1, [r5, 0x8] - lsls r0, r1, 29 - lsrs r0, 28 - orrs r4, r0 - lsls r1, 26 - lsrs r1, 29 - lsls r1, 4 - orrs r4, r1 - ldrh r0, [r5, 0x8] - lsls r0, 23 - lsrs r0, 29 - lsls r0, 7 - orrs r4, r0 - lsls r0, r2, 28 - lsrs r0, 29 - lsls r0, 10 - orrs r4, r0 - lsls r2, 25 - lsrs r2, 29 - lsls r2, 13 - orrs r4, r2 - ldrb r1, [r5, 0xA] - lsls r0, r1, 31 - lsrs r0, 31 - lsls r0, 16 - orrs r4, r0 - lsls r0, r1, 30 - lsrs r0, 31 - lsls r0, 17 - orrs r4, r0 - lsls r0, r1, 29 - lsrs r0, 31 - lsls r0, 18 - orrs r4, r0 - lsls r0, r1, 28 - lsrs r0, 31 - lsls r0, 19 - orrs r4, r0 - lsls r0, r1, 27 - lsrs r0, 31 - lsls r0, 20 - orrs r4, r0 - lsls r0, r1, 26 - lsrs r0, 31 - lsls r0, 21 - orrs r4, r0 - lsls r0, r1, 25 - lsrs r0, 31 - lsls r0, 22 - orrs r4, r0 - lsrs r1, 7 - lsls r1, 23 - orrs r4, r1 - ldrb r1, [r5, 0xB] - lsls r0, r1, 31 - lsrs r0, 31 - lsls r0, 24 - orrs r4, r0 - lsls r0, r1, 30 - lsrs r0, 31 - lsls r0, 25 - orrs r4, r0 - lsls r1, 29 - lsrs r1, 31 - lsls r1, 26 - orrs r4, r1 -_0806AC8C: - ldr r6, [sp] - cmp r6, 0xA - ble _0806AC98 - mov r0, r8 - bl EncryptBoxMon -_0806AC98: - adds r0, r4, 0 - add sp, 0x4 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end GetBoxMonData - - thumb_func_start SetMonData -@ int SetMonData(pokemon *mon, enum pokemon_data_request req, void *data) -SetMonData: @ 806ACAC - push {lr} - adds r3, r0, 0 - adds r0, r1, 0 - subs r0, 0x37 - cmp r0, 0xA - bhi _0806AD90 - lsls r0, 2 - ldr r1, =_0806ACC8 - adds r0, r1 - ldr r0, [r0] - mov pc, r0 - .pool - .align 2, 0 -_0806ACC8: - .4byte _0806ACF4 - .4byte _0806AD0C - .4byte _0806AD16 - .4byte _0806AD26 - .4byte _0806AD36 - .4byte _0806AD46 - .4byte _0806AD56 - .4byte _0806AD66 - .4byte _0806AD76 - .4byte _0806AD86 - .4byte _0806AD96 -_0806ACF4: - ldrb r1, [r2] - ldrb r0, [r2, 0x1] - lsls r0, 8 - adds r1, r0 - ldrb r0, [r2, 0x2] - lsls r0, 16 - adds r1, r0 - ldrb r0, [r2, 0x3] - lsls r0, 24 - adds r1, r0 - str r1, [r3, 0x50] - b _0806AD96 -_0806AD0C: - ldrb r1, [r2] - adds r0, r3, 0 - adds r0, 0x54 - strb r1, [r0] - b _0806AD96 -_0806AD16: - ldrb r0, [r2] - ldrb r1, [r2, 0x1] - lsls r1, 8 - adds r0, r1 - adds r1, r3, 0 - adds r1, 0x56 - strh r0, [r1] - b _0806AD96 -_0806AD26: - ldrb r0, [r2] - ldrb r1, [r2, 0x1] - lsls r1, 8 - adds r0, r1 - adds r1, r3, 0 - adds r1, 0x58 - strh r0, [r1] - b _0806AD96 -_0806AD36: - ldrb r0, [r2] - ldrb r1, [r2, 0x1] - lsls r1, 8 - adds r0, r1 - adds r1, r3, 0 - adds r1, 0x5A - strh r0, [r1] - b _0806AD96 -_0806AD46: - ldrb r0, [r2] - ldrb r1, [r2, 0x1] - lsls r1, 8 - adds r0, r1 - adds r1, r3, 0 - adds r1, 0x5C - strh r0, [r1] - b _0806AD96 -_0806AD56: - ldrb r0, [r2] - ldrb r1, [r2, 0x1] - lsls r1, 8 - adds r0, r1 - adds r1, r3, 0 - adds r1, 0x5E - strh r0, [r1] - b _0806AD96 -_0806AD66: - ldrb r0, [r2] - ldrb r1, [r2, 0x1] - lsls r1, 8 - adds r0, r1 - adds r1, r3, 0 - adds r1, 0x60 - strh r0, [r1] - b _0806AD96 -_0806AD76: - ldrb r0, [r2] - ldrb r1, [r2, 0x1] - lsls r1, 8 - adds r0, r1 - adds r1, r3, 0 - adds r1, 0x62 - strh r0, [r1] - b _0806AD96 -_0806AD86: - ldrb r1, [r2] - adds r0, r3, 0 - adds r0, 0x55 - strb r1, [r0] - b _0806AD96 -_0806AD90: - adds r0, r3, 0 - bl SetBoxMonData -_0806AD96: - pop {r0} - bx r0 - thumb_func_end SetMonData - - thumb_func_start SetBoxMonData -@ int SetBoxMonData(pokemon *mon, enum pokemon_data_request req, void *data) -SetBoxMonData: @ 806AD9C - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - adds r7, r0, 0 - mov r10, r1 - adds r4, r2, 0 - movs r0, 0 - mov r8, r0 - mov r9, r0 - movs r6, 0 - movs r5, 0 - cmp r1, 0xA - ble _0806AE1C - ldr r1, [r7] - adds r0, r7, 0 - movs r2, 0 - bl GetSubstruct - mov r8, r0 - ldr r1, [r7] - adds r0, r7, 0 - movs r2, 0x1 - bl GetSubstruct - mov r9, r0 - ldr r1, [r7] - adds r0, r7, 0 - movs r2, 0x2 - bl GetSubstruct - adds r6, r0, 0 - ldr r1, [r7] - adds r0, r7, 0 - movs r2, 0x3 - bl GetSubstruct - adds r5, r0, 0 - adds r0, r7, 0 - bl DecryptBoxMon - adds r0, r7, 0 - bl CalculateBoxMonChecksum - lsls r0, 16 - lsrs r0, 16 - ldrh r1, [r7, 0x1C] - cmp r0, r1 - beq _0806AE1C - ldrb r0, [r7, 0x13] - movs r1, 0x1 - orrs r0, r1 - movs r1, 0x4 - orrs r0, r1 - strb r0, [r7, 0x13] - ldrb r0, [r5, 0x7] - movs r1, 0x40 - orrs r0, r1 - strb r0, [r5, 0x7] - adds r0, r7, 0 - bl EncryptBoxMon - b _0806B3EC -_0806AE1C: - mov r0, r10 - cmp r0, 0x50 - bls _0806AE24 - b _0806B3D8 -_0806AE24: - lsls r0, 2 - ldr r1, =_0806AE34 - adds r0, r1 - ldr r0, [r0] - mov pc, r0 - .pool - .align 2, 0 -_0806AE34: - .4byte _0806AF78 - .4byte _0806AF90 - .4byte _0806AFA8 - .4byte _0806AFBE - .4byte _0806AFC4 - .4byte _0806AFD4 - .4byte _0806AFE6 - .4byte _0806AFF8 - .4byte _0806B00E - .4byte _0806B014 - .4byte _0806B020 - .4byte _0806B02C - .4byte _0806B04C - .4byte _0806B084 - .4byte _0806B084 - .4byte _0806B084 - .4byte _0806B084 - .4byte _0806B098 - .4byte _0806B098 - .4byte _0806B098 - .4byte _0806B098 - .4byte _0806B074 - .4byte _0806B0C8 - .4byte _0806B0CE - .4byte _0806B0D4 - .4byte _0806B05A - .4byte _0806B0A4 - .4byte _0806B0AA - .4byte _0806B0B0 - .4byte _0806B0B6 - .4byte _0806B0BC - .4byte _0806B0C2 - .4byte _0806B07C - .4byte _0806B0DA - .4byte _0806B0EC - .4byte _0806B0F2 - .4byte _0806B0F8 - .4byte _0806B10C - .4byte _0806B124 - .4byte _0806B14A - .4byte _0806B15E - .4byte _0806B178 - .4byte _0806B18E - .4byte _0806B1A8 - .4byte _0806B1C0 - .4byte _0806B1D4 - .4byte _0806B204 - .4byte _0806B0E0 - .4byte _0806B0E6 - .4byte _0806B13A - .4byte _0806B214 - .4byte _0806B222 - .4byte _0806B238 - .4byte _0806B250 - .4byte _0806B260 - .4byte _0806B3D8 - .4byte _0806B3D8 - .4byte _0806B3D8 - .4byte _0806B3D8 - .4byte _0806B3D8 - .4byte _0806B3D8 - .4byte _0806B3D8 - .4byte _0806B3D8 - .4byte _0806B3D8 - .4byte _0806B3D8 - .4byte _0806B3D8 - .4byte _0806B35E - .4byte _0806B276 - .4byte _0806B286 - .4byte _0806B294 - .4byte _0806B2A4 - .4byte _0806B2B4 - .4byte _0806B2C4 - .4byte _0806B2D4 - .4byte _0806B2E4 - .4byte _0806B2FA - .4byte _0806B30A - .4byte _0806B318 - .4byte _0806B328 - .4byte _0806B338 - .4byte _0806B34E -_0806AF78: - ldrb r1, [r4] - ldrb r0, [r4, 0x1] - lsls r0, 8 - adds r1, r0 - ldrb r0, [r4, 0x2] - lsls r0, 16 - adds r1, r0 - ldrb r0, [r4, 0x3] - lsls r0, 24 - adds r1, r0 - str r1, [r7] - b _0806B3D8 -_0806AF90: - ldrb r1, [r4] - ldrb r0, [r4, 0x1] - lsls r0, 8 - adds r1, r0 - ldrb r0, [r4, 0x2] - lsls r0, 16 - adds r1, r0 - ldrb r0, [r4, 0x3] - lsls r0, 24 - adds r1, r0 - str r1, [r7, 0x4] - b _0806B3D8 -_0806AFA8: - movs r2, 0 - adds r3, r7, 0 - adds r3, 0x8 -_0806AFAE: - adds r0, r3, r2 - adds r1, r4, r2 - ldrb r1, [r1] - strb r1, [r0] - adds r2, 0x1 - cmp r2, 0x9 - ble _0806AFAE - b _0806B3D8 -_0806AFBE: - ldrb r0, [r4] - strb r0, [r7, 0x12] - b _0806B3D8 -_0806AFC4: - ldrb r0, [r4] - movs r1, 0x1 - ands r1, r0 - ldrb r2, [r7, 0x13] - movs r0, 0x2 - negs r0, r0 - ands r0, r2 - b _0806B1F2 -_0806AFD4: - ldrb r0, [r4] - movs r1, 0x1 - ands r1, r0 - lsls r1, 1 - ldrb r2, [r7, 0x13] - movs r0, 0x3 - negs r0, r0 - ands r0, r2 - b _0806B1F2 -_0806AFE6: - ldrb r0, [r4] - movs r1, 0x1 - ands r1, r0 - lsls r1, 2 - ldrb r2, [r7, 0x13] - movs r0, 0x5 - negs r0, r0 - ands r0, r2 - b _0806B1F2 -_0806AFF8: - movs r2, 0 - adds r3, r7, 0 - adds r3, 0x14 -_0806AFFE: - adds r0, r3, r2 - adds r1, r4, r2 - ldrb r1, [r1] - strb r1, [r0] - adds r2, 0x1 - cmp r2, 0x6 - ble _0806AFFE - b _0806B3D8 -_0806B00E: - ldrb r0, [r4] - strb r0, [r7, 0x1B] - b _0806B3D8 -_0806B014: - ldrb r1, [r4] - ldrb r0, [r4, 0x1] - lsls r0, 8 - adds r1, r0 - strh r1, [r7, 0x1C] - b _0806B3D8 -_0806B020: - ldrb r1, [r4] - ldrb r0, [r4, 0x1] - lsls r0, 8 - adds r1, r0 - strh r1, [r7, 0x1E] - b _0806B3D8 -_0806B02C: - ldrb r1, [r4] - ldrb r0, [r4, 0x1] - lsls r0, 8 - adds r1, r0 - mov r0, r8 - strh r1, [r0] - lsls r1, 16 - cmp r1, 0 - beq _0806B044 - ldrb r0, [r7, 0x13] - movs r1, 0x2 - b _0806B1F2 -_0806B044: - ldrb r1, [r7, 0x13] - movs r0, 0x3 - negs r0, r0 - b _0806B1FE -_0806B04C: - ldrb r1, [r4] - ldrb r0, [r4, 0x1] - lsls r0, 8 - adds r1, r0 - mov r0, r8 - strh r1, [r0, 0x2] - b _0806B3D8 -_0806B05A: - ldrb r1, [r4] - ldrb r0, [r4, 0x1] - lsls r0, 8 - adds r1, r0 - ldrb r0, [r4, 0x2] - lsls r0, 16 - adds r1, r0 - ldrb r0, [r4, 0x3] - lsls r0, 24 - adds r1, r0 - mov r0, r8 - str r1, [r0, 0x4] - b _0806B3D8 -_0806B074: - ldrb r0, [r4] - mov r1, r8 - strb r0, [r1, 0x8] - b _0806B3D8 -_0806B07C: - ldrb r0, [r4] - mov r1, r8 - strb r0, [r1, 0x9] - b _0806B3D8 -_0806B084: - mov r2, r10 - subs r2, 0xD - lsls r2, 1 - add r2, r9 - ldrb r1, [r4] - ldrb r0, [r4, 0x1] - lsls r0, 8 - adds r1, r0 - strh r1, [r2] - b _0806B3D8 -_0806B098: - mov r0, r9 - add r0, r10 - subs r0, 0x9 - ldrb r1, [r4] - strb r1, [r0] - b _0806B3D8 -_0806B0A4: - ldrb r0, [r4] - strb r0, [r6] - b _0806B3D8 -_0806B0AA: - ldrb r0, [r4] - strb r0, [r6, 0x1] - b _0806B3D8 -_0806B0B0: - ldrb r0, [r4] - strb r0, [r6, 0x2] - b _0806B3D8 -_0806B0B6: - ldrb r0, [r4] - strb r0, [r6, 0x3] - b _0806B3D8 -_0806B0BC: - ldrb r0, [r4] - strb r0, [r6, 0x4] - b _0806B3D8 -_0806B0C2: - ldrb r0, [r4] - strb r0, [r6, 0x5] - b _0806B3D8 -_0806B0C8: - ldrb r0, [r4] - strb r0, [r6, 0x6] - b _0806B3D8 -_0806B0CE: - ldrb r0, [r4] - strb r0, [r6, 0x7] - b _0806B3D8 -_0806B0D4: - ldrb r0, [r4] - strb r0, [r6, 0x8] - b _0806B3D8 -_0806B0DA: - ldrb r0, [r4] - strb r0, [r6, 0x9] - b _0806B3D8 -_0806B0E0: - ldrb r0, [r4] - strb r0, [r6, 0xA] - b _0806B3D8 -_0806B0E6: - ldrb r0, [r4] - strb r0, [r6, 0xB] - b _0806B3D8 -_0806B0EC: - ldrb r0, [r4] - strb r0, [r5] - b _0806B3D8 -_0806B0F2: - ldrb r0, [r4] - strb r0, [r5, 0x1] - b _0806B3D8 -_0806B0F8: - ldrb r1, [r4] - movs r0, 0x7F - ands r1, r0 - ldrb r2, [r5, 0x2] - movs r0, 0x80 - negs r0, r0 - ands r0, r2 - orrs r0, r1 - strb r0, [r5, 0x2] - b _0806B3D8 -_0806B10C: - ldrb r1, [r4] - movs r0, 0xF - ands r1, r0 - lsls r1, 7 - ldrh r2, [r5, 0x2] - ldr r0, =0xfffff87f - ands r0, r2 - orrs r0, r1 - strh r0, [r5, 0x2] - b _0806B3D8 - .pool -_0806B124: - ldrb r1, [r4] - movs r0, 0xF - ands r1, r0 - lsls r1, 3 - ldrb r2, [r5, 0x3] - movs r0, 0x79 - negs r0, r0 - ands r0, r2 - orrs r0, r1 - strb r0, [r5, 0x3] - b _0806B3D8 -_0806B13A: - ldrb r0, [r4] - lsls r0, 7 - ldrb r2, [r5, 0x3] - movs r1, 0x7F - ands r1, r2 - orrs r1, r0 - strb r1, [r5, 0x3] - b _0806B3D8 -_0806B14A: - ldrb r1, [r4] - movs r0, 0x1F - ands r1, r0 - ldrb r2, [r5, 0x4] - movs r0, 0x20 - negs r0, r0 - ands r0, r2 - orrs r0, r1 - strb r0, [r5, 0x4] - b _0806B3D8 -_0806B15E: - ldrb r1, [r4] - movs r0, 0x1F - ands r1, r0 - lsls r1, 5 - ldrh r2, [r5, 0x4] - ldr r0, =0xfffffc1f - ands r0, r2 - orrs r0, r1 - strh r0, [r5, 0x4] - b _0806B3D8 - .pool -_0806B178: - ldrb r1, [r4] - movs r0, 0x1F - ands r1, r0 - lsls r1, 2 - ldrb r2, [r5, 0x5] - movs r0, 0x7D - negs r0, r0 - ands r0, r2 - orrs r0, r1 - strb r0, [r5, 0x5] - b _0806B3D8 -_0806B18E: - ldrb r2, [r4] - movs r0, 0x1F - ands r2, r0 - lsls r2, 15 - ldr r0, [r5, 0x4] - ldr r1, =0xfff07fff - ands r0, r1 - orrs r0, r2 - str r0, [r5, 0x4] - b _0806B3D8 - .pool -_0806B1A8: - ldrb r1, [r4] - movs r0, 0x1F - ands r1, r0 - lsls r1, 4 - ldrh r2, [r5, 0x6] - ldr r0, =0xfffffe0f - ands r0, r2 - orrs r0, r1 - strh r0, [r5, 0x6] - b _0806B3D8 - .pool -_0806B1C0: - ldrb r1, [r4] - movs r0, 0x1F - ands r1, r0 - lsls r1, 1 - ldrb r2, [r5, 0x7] - movs r0, 0x3F - negs r0, r0 - ands r0, r2 - orrs r0, r1 - b _0806B3D6 -_0806B1D4: - ldrb r1, [r4] - movs r0, 0x1 - ands r1, r0 - lsls r1, 6 - ldrb r2, [r5, 0x7] - movs r0, 0x41 - negs r0, r0 - ands r0, r2 - orrs r0, r1 - strb r0, [r5, 0x7] - lsls r0, 25 - cmp r0, 0 - bge _0806B1F8 - ldrb r0, [r7, 0x13] - movs r1, 0x4 -_0806B1F2: - orrs r0, r1 - strb r0, [r7, 0x13] - b _0806B3D8 -_0806B1F8: - ldrb r1, [r7, 0x13] - movs r0, 0x5 - negs r0, r0 -_0806B1FE: - ands r0, r1 - strb r0, [r7, 0x13] - b _0806B3D8 -_0806B204: - ldrb r0, [r4] - lsls r0, 7 - ldrb r2, [r5, 0x7] - movs r1, 0x7F - ands r1, r2 - orrs r1, r0 - strb r1, [r5, 0x7] - b _0806B3D8 -_0806B214: - ldrb r1, [r4] - movs r0, 0x7 - ands r1, r0 - ldrb r2, [r5, 0x8] - movs r0, 0x8 - negs r0, r0 - b _0806B230 -_0806B222: - ldrb r1, [r4] - movs r0, 0x7 - ands r1, r0 - lsls r1, 3 - ldrb r2, [r5, 0x8] - movs r0, 0x39 - negs r0, r0 -_0806B230: - ands r0, r2 - orrs r0, r1 - strb r0, [r5, 0x8] - b _0806B3D8 -_0806B238: - ldrb r1, [r4] - movs r0, 0x7 - ands r1, r0 - lsls r1, 6 - ldrh r2, [r5, 0x8] - ldr r0, =0xfffffe3f - ands r0, r2 - orrs r0, r1 - strh r0, [r5, 0x8] - b _0806B3D8 - .pool -_0806B250: - ldrb r1, [r4] - movs r0, 0x7 - ands r1, r0 - lsls r1, 1 - ldrb r2, [r5, 0x9] - movs r0, 0xF - negs r0, r0 - b _0806B26E -_0806B260: - ldrb r1, [r4] - movs r0, 0x7 - ands r1, r0 - lsls r1, 4 - ldrb r2, [r5, 0x9] - movs r0, 0x71 - negs r0, r0 -_0806B26E: - ands r0, r2 - orrs r0, r1 - strb r0, [r5, 0x9] - b _0806B3D8 -_0806B276: - ldrb r0, [r4] - lsls r0, 7 - ldrb r2, [r5, 0x9] - movs r1, 0x7F - ands r1, r2 - orrs r1, r0 - strb r1, [r5, 0x9] - b _0806B3D8 -_0806B286: - ldrb r1, [r4] - movs r0, 0x1 - ands r1, r0 - ldrb r2, [r5, 0xA] - movs r0, 0x2 - negs r0, r0 - b _0806B2F2 -_0806B294: - ldrb r1, [r4] - movs r0, 0x1 - ands r1, r0 - lsls r1, 1 - ldrb r2, [r5, 0xA] - movs r0, 0x3 - negs r0, r0 - b _0806B2F2 -_0806B2A4: - ldrb r1, [r4] - movs r0, 0x1 - ands r1, r0 - lsls r1, 2 - ldrb r2, [r5, 0xA] - movs r0, 0x5 - negs r0, r0 - b _0806B2F2 -_0806B2B4: - ldrb r1, [r4] - movs r0, 0x1 - ands r1, r0 - lsls r1, 3 - ldrb r2, [r5, 0xA] - movs r0, 0x9 - negs r0, r0 - b _0806B2F2 -_0806B2C4: - ldrb r1, [r4] - movs r0, 0x1 - ands r1, r0 - lsls r1, 4 - ldrb r2, [r5, 0xA] - movs r0, 0x11 - negs r0, r0 - b _0806B2F2 -_0806B2D4: - ldrb r1, [r4] - movs r0, 0x1 - ands r1, r0 - lsls r1, 5 - ldrb r2, [r5, 0xA] - movs r0, 0x21 - negs r0, r0 - b _0806B2F2 -_0806B2E4: - ldrb r1, [r4] - movs r0, 0x1 - ands r1, r0 - lsls r1, 6 - ldrb r2, [r5, 0xA] - movs r0, 0x41 - negs r0, r0 -_0806B2F2: - ands r0, r2 - orrs r0, r1 - strb r0, [r5, 0xA] - b _0806B3D8 -_0806B2FA: - ldrb r0, [r4] - lsls r0, 7 - ldrb r2, [r5, 0xA] - movs r1, 0x7F - ands r1, r2 - orrs r1, r0 - strb r1, [r5, 0xA] - b _0806B3D8 -_0806B30A: - ldrb r1, [r4] - movs r0, 0x1 - ands r1, r0 - ldrb r2, [r5, 0xB] - movs r0, 0x2 - negs r0, r0 - b _0806B346 -_0806B318: - ldrb r1, [r4] - movs r0, 0x1 - ands r1, r0 - lsls r1, 1 - ldrb r2, [r5, 0xB] - movs r0, 0x3 - negs r0, r0 - b _0806B346 -_0806B328: - ldrb r1, [r4] - movs r0, 0x1 - ands r1, r0 - lsls r1, 2 - ldrb r2, [r5, 0xB] - movs r0, 0x5 - negs r0, r0 - b _0806B346 -_0806B338: - ldrb r1, [r4] - movs r0, 0xF - ands r1, r0 - lsls r1, 3 - ldrb r2, [r5, 0xB] - movs r0, 0x79 - negs r0, r0 -_0806B346: - ands r0, r2 - orrs r0, r1 - strb r0, [r5, 0xB] - b _0806B3D8 -_0806B34E: - ldrb r0, [r4] - lsls r0, 7 - ldrb r2, [r5, 0xB] - movs r1, 0x7F - ands r1, r2 - orrs r1, r0 - strb r1, [r5, 0xB] - b _0806B3D8 -_0806B35E: - ldrb r3, [r4] - ldrb r0, [r4, 0x1] - lsls r0, 8 - orrs r3, r0 - ldrb r0, [r4, 0x2] - lsls r0, 16 - orrs r3, r0 - ldrb r0, [r4, 0x3] - lsls r0, 24 - orrs r3, r0 - movs r4, 0x1F - adds r1, r3, 0 - ands r1, r4 - ldrb r2, [r5, 0x4] - movs r0, 0x20 - negs r0, r0 - ands r0, r2 - orrs r0, r1 - strb r0, [r5, 0x4] - lsrs r1, r3, 5 - ands r1, r4 - lsls r1, 5 - ldrh r2, [r5, 0x4] - ldr r0, =0xfffffc1f - ands r0, r2 - orrs r0, r1 - strh r0, [r5, 0x4] - lsrs r1, r3, 10 - ands r1, r4 - lsls r1, 2 - ldrb r2, [r5, 0x5] - movs r0, 0x7D - negs r0, r0 - ands r0, r2 - orrs r0, r1 - strb r0, [r5, 0x5] - lsrs r1, r3, 15 - ands r1, r4 - lsls r1, 15 - ldr r0, [r5, 0x4] - ldr r2, =0xfff07fff - ands r0, r2 - orrs r0, r1 - str r0, [r5, 0x4] - lsrs r1, r3, 20 - ands r1, r4 - lsls r1, 4 - ldrh r2, [r5, 0x6] - ldr r0, =0xfffffe0f - ands r0, r2 - orrs r0, r1 - strh r0, [r5, 0x6] - lsrs r3, 25 - ands r3, r4 - lsls r3, 1 - ldrb r1, [r5, 0x7] - movs r0, 0x3F - negs r0, r0 - ands r0, r1 - orrs r0, r3 -_0806B3D6: - strb r0, [r5, 0x7] -_0806B3D8: - mov r0, r10 - cmp r0, 0xA - ble _0806B3EC - adds r0, r7, 0 - bl CalculateBoxMonChecksum - strh r0, [r7, 0x1C] - adds r0, r7, 0 - bl EncryptBoxMon -_0806B3EC: - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end SetBoxMonData - - thumb_func_start CopyMon -@ void *CopyMon(void *dest, void *src, unsigned int size) -CopyMon: @ 806B408 - push {lr} - bl memcpy - pop {r0} - bx r0 - thumb_func_end CopyMon - - thumb_func_start GiveMonToPlayer -@ int GiveMonToPlayer(pokemon *mon) -GiveMonToPlayer: @ 806B414 - push {r4-r6,lr} - adds r6, r0, 0 - ldr r4, =gSaveBlock2Ptr - ldr r2, [r4] - movs r1, 0x7 - bl SetMonData - ldr r2, [r4] - adds r2, 0x8 - adds r0, r6, 0 - movs r1, 0x31 - bl SetMonData - ldr r2, [r4] - adds r2, 0xA - adds r0, r6, 0 - movs r1, 0x1 - bl SetMonData - movs r5, 0 - b _0806B446 - .pool -_0806B444: - adds r5, 0x1 -_0806B446: - cmp r5, 0x5 - bgt _0806B480 - movs r0, 0x64 - adds r1, r5, 0 - muls r1, r0 - ldr r0, =gPlayerParty - adds r4, r1, r0 - adds r0, r4, 0 - movs r1, 0xB - movs r2, 0 - bl GetMonData - cmp r0, 0 - bne _0806B444 - adds r0, r4, 0 - adds r1, r6, 0 - movs r2, 0x64 - bl CopyMon - ldr r1, =gPlayerPartyCount - adds r0, r5, 0x1 - strb r0, [r1] - movs r0, 0 - b _0806B48A - .pool -_0806B480: - adds r0, r6, 0 - bl SendMonToPC - lsls r0, 24 - lsrs r0, 24 -_0806B48A: - pop {r4-r6} - pop {r1} - bx r1 - thumb_func_end GiveMonToPlayer - - thumb_func_start SendMonToPC -@ int SendMonToPC(pokemon *mon) -SendMonToPC: @ 806B490 - push {r4-r7,lr} - mov r7, r8 - push {r7} - mov r8, r0 - ldr r0, =0x00004036 - bl VarGet - lsls r0, 24 - lsrs r0, 24 - bl set_unknown_box_id - bl get_preferred_box - lsls r0, 24 - lsrs r5, r0, 24 -_0806B4AE: - movs r6, 0 - lsls r7, r5, 24 -_0806B4B2: - lsls r1, r6, 24 - lsrs r1, 24 - lsrs r0, r7, 24 - bl get_pokemon_by_box_and_pos - adds r4, r0, 0 - movs r1, 0xB - movs r2, 0 - bl GetBoxMonData - cmp r0, 0 - bne _0806B514 - mov r0, r8 - bl MonRestorePP - adds r0, r4, 0 - mov r1, r8 - movs r2, 0x50 - bl CopyMon - ldr r0, =gSpecialVar_0x8012 - strh r5, [r0] - ldr r0, =gSpecialVar_0x8013 - strh r6, [r0] - bl get_unknown_box_id - lsls r0, 16 - lsrs r0, 16 - cmp r0, r5 - beq _0806B4F4 - ldr r0, =0x000008d7 - bl FlagReset -_0806B4F4: - lsls r1, r5, 16 - ldr r0, =0x00004036 - lsrs r1, 16 - bl VarSet - movs r0, 0x1 - b _0806B530 - .pool -_0806B514: - adds r6, 0x1 - cmp r6, 0x1D - ble _0806B4B2 - adds r5, 0x1 - cmp r5, 0xE - bne _0806B522 - movs r5, 0 -_0806B522: - bl get_preferred_box - lsls r0, 24 - lsrs r0, 24 - cmp r5, r0 - bne _0806B4AE - movs r0, 0x2 -_0806B530: - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end SendMonToPC - - thumb_func_start CalculatePlayerPartyCount -@ u8 CalculatePlayerPartyCount() -CalculatePlayerPartyCount: @ 806B53C - push {r4,lr} - ldr r0, =gPlayerPartyCount - movs r1, 0 - strb r1, [r0] - b _0806B554 - .pool -_0806B54C: - ldrb r0, [r4] - adds r0, 0x1 - strb r0, [r4] - adds r0, r4, 0 -_0806B554: - adds r4, r0, 0 - ldrb r0, [r4] - cmp r0, 0x5 - bhi _0806B572 - adds r1, r0, 0 - movs r0, 0x64 - muls r0, r1 - ldr r1, =gPlayerParty - adds r0, r1 - movs r1, 0xB - movs r2, 0 - bl GetMonData - cmp r0, 0 - bne _0806B54C -_0806B572: - ldrb r0, [r4] - pop {r4} - pop {r1} - bx r1 - .pool - thumb_func_end CalculatePlayerPartyCount - - thumb_func_start CalculateEnemyPartyCount -@ u8 CalculateEnemyPartyCount() -CalculateEnemyPartyCount: @ 806B580 - push {r4,lr} - ldr r0, =gUnknown_020244EA - movs r1, 0 - strb r1, [r0] - b _0806B598 - .pool -_0806B590: - ldrb r0, [r4] - adds r0, 0x1 - strb r0, [r4] - adds r0, r4, 0 -_0806B598: - adds r4, r0, 0 - ldrb r0, [r4] - cmp r0, 0x5 - bhi _0806B5B6 - adds r1, r0, 0 - movs r0, 0x64 - muls r0, r1 - ldr r1, =gEnemyParty - adds r0, r1 - movs r1, 0xB - movs r2, 0 - bl GetMonData - cmp r0, 0 - bne _0806B590 -_0806B5B6: - ldrb r0, [r4] - pop {r4} - pop {r1} - bx r1 - .pool - thumb_func_end CalculateEnemyPartyCount - - thumb_func_start GetMonsStateToDoubles -GetMonsStateToDoubles: @ 806B5C4 - push {r4-r6,lr} - movs r6, 0 - bl CalculatePlayerPartyCount - ldr r1, =gPlayerPartyCount - ldrb r0, [r1] - cmp r0, 0x1 - beq _0806B628 - movs r5, 0 - ldrb r1, [r1] - cmp r6, r1 - bge _0806B620 -_0806B5DC: - movs r0, 0x64 - adds r1, r5, 0 - muls r1, r0 - ldr r0, =gPlayerParty - adds r4, r1, r0 - adds r0, r4, 0 - movs r1, 0x41 - movs r2, 0 - bl GetMonData - movs r1, 0xCE - lsls r1, 1 - cmp r0, r1 - beq _0806B616 - adds r0, r4, 0 - movs r1, 0x39 - movs r2, 0 - bl GetMonData - cmp r0, 0 - beq _0806B616 - adds r0, r4, 0 - movs r1, 0x41 - movs r2, 0 - bl GetMonData - cmp r0, 0 - beq _0806B616 - adds r6, 0x1 -_0806B616: - adds r5, 0x1 - ldr r0, =gPlayerPartyCount - ldrb r0, [r0] - cmp r5, r0 - blt _0806B5DC -_0806B620: - movs r0, 0 - cmp r6, 0x1 - bgt _0806B628 - movs r0, 0x2 -_0806B628: - pop {r4-r6} - pop {r1} - bx r1 - .pool - thumb_func_end GetMonsStateToDoubles - - thumb_func_start GetMonsStateToDoubles_2 -@ u8 GetMonsStateToDoubles_2() -GetMonsStateToDoubles_2: @ 806B638 - push {r4-r6,lr} - movs r6, 0 - movs r5, 0 -_0806B63E: - movs r0, 0x64 - adds r1, r5, 0 - muls r1, r0 - ldr r0, =gPlayerParty - adds r4, r1, r0 - adds r0, r4, 0 - movs r1, 0x41 - movs r2, 0 - bl GetMonData - adds r1, r0, 0 - movs r0, 0xCE - lsls r0, 1 - cmp r1, r0 - beq _0806B670 - cmp r1, 0 - beq _0806B670 - adds r0, r4, 0 - movs r1, 0x39 - movs r2, 0 - bl GetMonData - cmp r0, 0 - beq _0806B670 - adds r6, 0x1 -_0806B670: - adds r5, 0x1 - cmp r5, 0x5 - ble _0806B63E - cmp r6, 0x1 - bne _0806B684 - movs r0, 0x1 - b _0806B68C - .pool -_0806B684: - movs r0, 0 - cmp r6, 0x1 - bgt _0806B68C - movs r0, 0x2 -_0806B68C: - pop {r4-r6} - pop {r1} - bx r1 - thumb_func_end GetMonsStateToDoubles_2 - thumb_func_start GetAbilityBySpecies @ int GetAbilityBySpecies(u16 a1, int a2) GetAbilityBySpecies: @ 806B694 diff --git a/asm/rom6.s b/asm/rom6.s index 5f604448d8..be10762763 100644 --- a/asm/rom6.s +++ b/asm/rom6.s @@ -11184,7 +11184,7 @@ sub_813B21C: @ 813B21C lsls r0, 24 cmp r0, 0 bne _0813B258 - bl get_preferred_box + bl StorageGetCurrentBox adds r4, r0, 0 lsls r4, 24 lsrs r4, 24 @@ -11215,7 +11215,7 @@ sub_813B260: @ 813B260 lsls r0, 24 lsrs r0, 24 bl set_unknown_box_id - bl get_preferred_box + bl StorageGetCurrentBox lsls r0, 24 lsrs r4, r0, 24 _0813B278: @@ -11226,7 +11226,7 @@ _0813B27E: lsls r1, r5, 24 lsrs r1, 24 lsrs r0, r6, 24 - bl get_pokemon_by_box_and_pos + bl GetBoxedMonPtr movs r1, 0xB movs r2, 0 bl GetBoxMonData @@ -11257,7 +11257,7 @@ _0813B2C0: bne _0813B2CE movs r4, 0 _0813B2CE: - bl get_preferred_box + bl StorageGetCurrentBox lsls r0, 24 lsrs r0, 24 cmp r4, r0 diff --git a/asm/rom_80C6FA0.s b/asm/rom_80C6FA0.s index 442c83cfa3..a0093d516e 100644 --- a/asm/rom_80C6FA0.s +++ b/asm/rom_80C6FA0.s @@ -1763,7 +1763,7 @@ _080C7DA8: bl CreateTask ldr r1, [r4] strb r0, [r1, 0x4] - bl get_preferred_box + bl StorageGetCurrentBox ldr r1, =gUnknown_02039D10 strb r0, [r1] ldr r0, =c2_Box @@ -2102,7 +2102,7 @@ _080C80EC: bl sub_80CA704 b _080C8198 _080C80F2: - bl get_preferred_box + bl StorageGetCurrentBox lsls r0, 24 lsrs r0, 24 bl sub_80CC32C @@ -2459,7 +2459,7 @@ _080C8440: _080C844C: movs r0, 0x5 bl PlaySE - bl get_preferred_box + bl StorageGetCurrentBox ldr r4, =gUnknown_02039D08 ldr r1, [r4] lsls r0, 24 @@ -2483,7 +2483,7 @@ _080C846E: _080C8484: movs r0, 0x5 bl PlaySE - bl get_preferred_box + bl StorageGetCurrentBox ldr r4, =gUnknown_02039D08 ldr r1, [r4] lsls r0, 24 @@ -4859,7 +4859,7 @@ _080C99FE: movs r1, 0xA movs r3, 0x3 bl sub_80C77E8 - bl get_preferred_box + bl StorageGetCurrentBox lsls r0, 24 lsrs r0, 24 bl sub_80C78D4 @@ -4888,7 +4888,7 @@ _080C9A2C: cmp r0, 0xC9 beq _080C9A6C adds r4, r0, 0 - bl get_preferred_box + bl StorageGetCurrentBox lsls r0, 24 lsrs r0, 24 cmp r4, r0 @@ -5421,7 +5421,7 @@ _080C9F04: .pool _080C9F1C: bl sub_80C9FC8 - bl get_preferred_box + bl StorageGetCurrentBox lsls r0, 24 lsrs r0, 24 bl sav3_get_box_name @@ -6895,7 +6895,7 @@ _080CABDA: sub_80CABE0: @ 80CABE0 push {r4,lr} ldr r4, =gUnknown_02039D10 - bl get_preferred_box + bl StorageGetCurrentBox ldrb r1, [r4] lsls r0, 24 lsrs r0, 24 @@ -6904,7 +6904,7 @@ sub_80CABE0: @ 80CABE0 ldr r0, =0x000008d7 bl FlagReset ldr r4, =0x00004036 - bl get_preferred_box + bl StorageGetCurrentBox adds r1, r0, 0 lsls r1, 24 lsrs r1, 24 @@ -10143,7 +10143,7 @@ sub_80CC644: @ 80CC644 push {r4,lr} lsls r0, 24 lsrs r4, r0, 24 - bl get_preferred_box + bl StorageGetCurrentBox lsls r0, 24 lsrs r1, r0, 24 movs r2, 0 @@ -10180,7 +10180,7 @@ sub_80CC680: @ 80CC680 adds r4, r0, 0 lsls r4, 24 lsrs r4, 24 - bl get_preferred_box + bl StorageGetCurrentBox lsls r0, 24 lsrs r0, 24 adds r1, r4, 0 @@ -10244,7 +10244,7 @@ _080CC718: lsls r0, 24 cmp r0, 0 bne _080CC794 - bl get_preferred_box + bl StorageGetCurrentBox lsls r0, 24 lsrs r0, 24 movs r1, 0 @@ -11229,7 +11229,7 @@ _080CCF96: thumb_func_start sub_80CCF9C sub_80CCF9C: @ 80CCF9C push {lr} - bl get_preferred_box + bl StorageGetCurrentBox lsls r0, 24 lsrs r0, 24 bl sub_80D20F8 @@ -12975,7 +12975,7 @@ _080CDDFE: b _080CDE2A .pool _080CDE20: - bl get_preferred_box + bl StorageGetCurrentBox ldr r1, [r4] ldr r2, =0x00000d91 adds r1, r2 @@ -13141,7 +13141,7 @@ _080CDF68: ldrb r0, [r0] cmp r0, 0 bne _080CDF8E - bl get_preferred_box + bl StorageGetCurrentBox lsls r0, 24 lsrs r0, 24 ldr r4, =gUnknown_02039D79 @@ -13182,7 +13182,7 @@ sub_80CDFAC: @ 80CDFAC b _080CDFF8 .pool _080CDFDC: - bl get_preferred_box + bl StorageGetCurrentBox adds r4, r0, 0 lsls r4, 24 lsrs r4, 24 @@ -13417,7 +13417,7 @@ _080CE1DC: ldrb r0, [r5] bl sub_80CBB68 _080CE1F6: - bl get_preferred_box + bl StorageGetCurrentBox lsls r0, 24 lsrs r0, 24 cmp r6, r0 @@ -13539,7 +13539,7 @@ _080CE2F0: b _080CE30C .pool _080CE304: - bl get_preferred_box + bl StorageGetCurrentBox lsls r0, 24 lsrs r2, r0, 24 _080CE30C: @@ -13687,7 +13687,7 @@ _080CE418: b _080CE488 .pool _080CE464: - bl get_preferred_box + bl StorageGetCurrentBox lsls r0, 24 lsrs r0, 24 ldr r1, =gUnknown_02039D79 @@ -13697,7 +13697,7 @@ _080CE464: ldr r3, =0x00002108 adds r2, r3 bl sub_80D2054 - bl get_preferred_box + bl StorageGetCurrentBox ldr r1, [r4] ldr r2, =0x00002170 adds r1, r2 @@ -14140,11 +14140,11 @@ _080CE838: b _080CE8CA .pool _080CE894: - bl get_preferred_box + bl StorageGetCurrentBox lsls r0, 24 lsrs r0, 24 movs r1, 0 - bl get_pokemon_by_box_and_pos + bl GetBoxedMonPtr ldr r3, =gUnknown_02039D08 ldr r2, [r3] ldr r4, =0x0000218c @@ -14527,12 +14527,12 @@ _080CEBB0: bl sub_80CEC00 b _080CEBD0 _080CEBBA: - bl get_preferred_box + bl StorageGetCurrentBox lsls r0, 24 lsrs r0, 24 ldr r1, =gUnknown_02039D79 ldrb r1, [r1] - bl get_pokemon_by_box_and_pos + bl GetBoxedMonPtr movs r1, 0x1 bl sub_80CEC00 _080CEBD0: @@ -15491,7 +15491,7 @@ _080CF428: adds r1, r0 movs r0, 0x2 strb r0, [r1] - bl get_preferred_box + bl StorageGetCurrentBox ldr r1, =gUnknown_02039D7B strb r0, [r1] movs r0, 0x17 @@ -18075,7 +18075,7 @@ _080D0902: _080D0914: adds r0, 0x1 strb r0, [r2, 0xB] - bl get_preferred_box + bl StorageGetCurrentBox lsls r0, 24 lsrs r0, 24 mov r10, r0 @@ -18111,7 +18111,7 @@ _080D093C: _080D095A: mov r0, r10 adds r1, r5, 0 - bl get_pokemon_by_box_and_pos + bl GetBoxedMonPtr adds r1, r0, 0 ldr r2, =gUnknown_02039D80 ldr r0, [r2] @@ -18161,7 +18161,7 @@ sub_80D09A4: @ 80D09A4 ldrb r0, [r0, 0xB] adds r1, r0 mov r9, r1 - bl get_preferred_box + bl StorageGetCurrentBox lsls r0, 24 lsrs r0, 24 mov r8, r0 @@ -18305,7 +18305,7 @@ sub_80D0AAC: @ 80D0AAC ldrb r0, [r0, 0xB] adds r1, r0 str r1, [sp] - bl get_preferred_box + bl StorageGetCurrentBox lsls r0, 24 lsrs r0, 24 str r0, [sp, 0x4] @@ -20559,15 +20559,15 @@ nullsub_98: @ 80D1D08 bx lr thumb_func_end nullsub_98 - thumb_func_start get_preferred_box -@ char get_preferred_box() -get_preferred_box: @ 80D1D0C + thumb_func_start StorageGetCurrentBox +@ char StorageGetCurrentBox() +StorageGetCurrentBox: @ 80D1D0C ldr r0, =gPokemonStoragePtr ldr r0, [r0] ldrb r0, [r0] bx lr .pool - thumb_func_end get_preferred_box + thumb_func_end StorageGetCurrentBox thumb_func_start sub_80D1D18 sub_80D1D18: @ 80D1D18 @@ -21050,9 +21050,9 @@ _080D2088: .pool thumb_func_end sub_80D2054 - thumb_func_start get_pokemon_by_box_and_pos -@ pokemon *get_pokemon_by_box_and_pos(u8 box_id, u8 pos) -get_pokemon_by_box_and_pos: @ 80D2094 + thumb_func_start GetBoxedMonPtr +@ pokemon *GetBoxedMonPtr(u8 box_id, u8 pos) +GetBoxedMonPtr: @ 80D2094 push {r4,lr} lsls r0, 24 lsrs r3, r0, 24 @@ -21083,7 +21083,7 @@ _080D20CA: pop {r4} pop {r1} bx r1 - thumb_func_end get_pokemon_by_box_and_pos + thumb_func_end GetBoxedMonPtr thumb_func_start sav3_get_box_name sav3_get_box_name: @ 80D20D0 diff --git a/asm/rom_81BE66C.s b/asm/rom_81BE66C.s index fb7027a590..748c1e92c1 100644 --- a/asm/rom_81BE66C.s +++ b/asm/rom_81BE66C.s @@ -28946,7 +28946,7 @@ _081CD690: _081CD6E0: mov r0, r8 mov r1, r9 - bl get_pokemon_by_box_and_pos + bl GetBoxedMonPtr adds r4, r0, 0 bl GetBoxMonGender lsls r0, 24 @@ -33128,7 +33128,7 @@ sub_81CF8E4: @ 81CF8E4 _081CF924: ldrb r0, [r2] ldrb r1, [r2, 0x1] - bl get_pokemon_by_box_and_pos + bl GetBoxedMonPtr adds r4, r0, 0 bl GetBoxMonGender lsls r0, 24 @@ -34505,7 +34505,7 @@ sub_81D035C: @ 81D035C _081D03A4: ldrb r0, [r7] ldrb r1, [r7, 0x1] - bl get_pokemon_by_box_and_pos + bl GetBoxedMonPtr adds r4, r0, 0 bl GetBoxMonGender lsls r0, 24 @@ -34992,7 +34992,7 @@ sub_81D06E4: @ 81D06E4 _081D0730: ldrb r0, [r1] ldrb r1, [r1, 0x1] - bl get_pokemon_by_box_and_pos + bl GetBoxedMonPtr adds r4, r0, 0 bl GetBoxMonGender strb r0, [r6] @@ -35049,7 +35049,7 @@ sub_81D0760: @ 81D0760 _081D07AC: ldrb r0, [r1] ldrb r1, [r1, 0x1] - bl get_pokemon_by_box_and_pos + bl GetBoxedMonPtr adds r4, r0, 0 movs r1, 0xB bl GetBoxMonData @@ -39990,7 +39990,7 @@ _081D2D70: lsrs r0, 24 lsls r1, r6, 24 lsrs r1, 24 - bl get_pokemon_by_box_and_pos + bl GetBoxedMonPtr adds r4, r0, 0 bl GetBoxMonGender lsls r0, 24 diff --git a/asm/trade.s b/asm/trade.s index 56fba40c30..dc37912d7f 100644 --- a/asm/trade.s +++ b/asm/trade.s @@ -288,7 +288,7 @@ sub_80773AC: @ 80773AC ldr r0, =gMain movs r1, 0 str r1, [r0] - ldr r0, =gUnknown_020244EA + ldr r0, =gEnemyPartyCount strb r1, [r0] pop {r0} bx r0 @@ -600,7 +600,7 @@ _080776A8: adds r0, 0x36 strb r1, [r0] ldr r0, [r2] - ldr r1, =gUnknown_020244EA + ldr r1, =gEnemyPartyCount ldrb r1, [r1] adds r0, 0x37 strb r1, [r0] @@ -1211,7 +1211,7 @@ _08077C6C: adds r0, 0x36 strb r1, [r0] ldr r0, [r4] - ldr r1, =gUnknown_020244EA + ldr r1, =gEnemyPartyCount ldrb r1, [r1] adds r0, 0x37 strb r1, [r0] diff --git a/asm/tv.s b/asm/tv.s index 12f1852ff3..35abb9918e 100644 --- a/asm/tv.s +++ b/asm/tv.s @@ -7570,7 +7570,7 @@ sub_80EFEC4: @ 80EFEC4 ldrb r0, [r0] ldr r1, =gSpecialVar_0x8013 ldrb r1, [r1] - bl get_pokemon_by_box_and_pos + bl GetBoxedMonPtr adds r6, r0, 0 ldr r2, =gStringVar3 movs r1, 0x2 diff --git a/include/flags.h b/include/flags.h index 56e87b895f..362e1be534 100644 --- a/include/flags.h +++ b/include/flags.h @@ -84,6 +84,8 @@ #define SYS_CTRL_OBJ_DELETE CODE_FLAGS + 0x61 #define SYS_RESET_RTC_ENABLE CODE_FLAGS + 0x62 +#define SYS_STORAGE_UNKNOWN_FLAG CODE_FLAGS + 0x77 + #define SYS_MYSTERY_GIFT_ENABLE CODE_FLAGS + 0x7B // SPECIAL FLAGS (unknown purpose) diff --git a/include/pokemon.h b/include/pokemon.h index dc81b28e23..dfb035133d 100644 --- a/include/pokemon.h +++ b/include/pokemon.h @@ -81,10 +81,10 @@ #define MON_DATA_GIFT_RIBBON_6 77 #define MON_DATA_GIFT_RIBBON_7 78 #define MON_DATA_FATEFUL_ENCOUNTER 79 -#define MON_DATA_KNOWN_MOVES 80 -#define MON_DATA_RIBBON_COUNT 81 -#define MON_DATA_RIBBONS 82 -#define MON_DATA_83 83 +#define MON_DATA_OBEDIENCE 80 +#define MON_DATA_KNOWN_MOVES 81 +#define MON_DATA_RIBBON_COUNT 82 +#define MON_DATA_RIBBONS 83 #define MON_DATA_ATK2 84 #define MON_DATA_DEF2 85 #define MON_DATA_SPD2 86 @@ -95,6 +95,14 @@ #define OT_ID_PRESET 1 #define OT_ID_PLAYER_ID 0 +#define MON_GIVEN_TO_PARTY 0x0 +#define MON_GIVEN_TO_PC 0x1 +#define MON_CANT_GIVE 0x2 + +#define PLAYER_HAS_TWO_USABLE_MONS 0x0 +#define PLAYER_HAS_ONE_MON 0x1 +#define PLAYER_HAS_ONE_USABLE_MON 0x2 + #define MON_MALE 0x00 #define MON_FEMALE 0xFE #define MON_GENDERLESS 0xFF @@ -240,7 +248,8 @@ struct PokemonSubstruct3 /* 0x0B */ u32 giftRibbon5:1; /* 0x0B */ u32 giftRibbon6:1; /* 0x0B */ u32 giftRibbon7:1; - /* 0x0B */ u32 fatefulEncounter:5; // unused in Ruby/Sapphire, but the high bit must be set for Mew/Deoxys to obey in FR/LG/Emerald + /* 0x0B */ u32 fatefulEncounter:4; + /* 0x0B */ u32 obedient:1; }; union PokemonSubstruct diff --git a/include/text.h b/include/text.h index f52336d845..73e6e54372 100644 --- a/include/text.h +++ b/include/text.h @@ -74,6 +74,7 @@ #define EOS 0xFF // end of string #define EXT_CTRL_CODE_JPN 0x15 +#define EXT_CTRL_CODE_ENG 0x16 #define NUM_TEXT_PRINTERS 32 diff --git a/include/vars.h b/include/vars.h index 8a779dccfe..5da960640c 100644 --- a/include/vars.h +++ b/include/vars.h @@ -28,6 +28,7 @@ #define VAR_DAYS 0x4040 #define VAR_DEPT_STORE_FLOOR 0x4043 +#define VAR_STORAGE_UNKNOWN 0x4036 #define VAR_POKELOT_PRIZE 0x4045 #define VAR_NATIONAL_DEX 0x4046 #define VAR_SEEDOT_SIZE_RECORD 0x4047 diff --git a/src/pokemon_2.c b/src/pokemon_2.c index f06e9c215b..9c6e50dc60 100644 --- a/src/pokemon_2.c +++ b/src/pokemon_2.c @@ -302,9 +302,10 @@ union PokemonSubstruct *GetSubstruct(struct BoxPokemon *boxMon, u32 personality, extern u16 GetDeoxysStat(struct Pokemon *mon, s32 statId); -u32 GetMonData(struct Pokemon *mon, s32 field, u8 *data) +u32 GetMonData(struct Pokemon *mon, s32 field, u8* data) { u32 ret; + switch (field) { case MON_DATA_STATUS: @@ -368,3 +369,801 @@ u32 GetMonData(struct Pokemon *mon, s32 field, u8 *data) } return ret; } + +u32 GetBoxMonData(struct BoxPokemon *boxMon, s32 field, u8 *data) +{ + s32 i; + u32 retVal = 0; + struct PokemonSubstruct0 *substruct0 = NULL; + struct PokemonSubstruct1 *substruct1 = NULL; + struct PokemonSubstruct2 *substruct2 = NULL; + struct PokemonSubstruct3 *substruct3 = NULL; + + if (field > MON_DATA_10) + { + substruct0 = &(GetSubstruct(boxMon, boxMon->personality, 0)->type0); + substruct1 = &(GetSubstruct(boxMon, boxMon->personality, 1)->type1); + substruct2 = &(GetSubstruct(boxMon, boxMon->personality, 2)->type2); + substruct3 = &(GetSubstruct(boxMon, boxMon->personality, 3)->type3); + + DecryptBoxMon(boxMon); + + if (CalculateBoxMonChecksum(boxMon) != boxMon->checksum) + { + boxMon->isBadEgg = 1; + boxMon->isEgg = 1; + substruct3->isEgg = 1; + } + } + + switch (field) + { + case MON_DATA_PERSONALITY: + retVal = boxMon->personality; + break; + case MON_DATA_OT_ID: + retVal = boxMon->otId; + break; + case MON_DATA_NICKNAME: + { + if (boxMon->isBadEgg) + { + for (retVal = 0; + retVal < POKEMON_NAME_LENGTH && gBadEggNickname[retVal] != EOS; + data[retVal] = gBadEggNickname[retVal], retVal++) {} + + data[retVal] = EOS; + } + else if (boxMon->isEgg) + { + StringCopy(data, gEggNickname); + retVal = StringLength(data); + } + else if (boxMon->language == LANGUAGE_JAPANESE) + { + data[0] = EXT_CTRL_CODE_BEGIN; + data[1] = EXT_CTRL_CODE_JPN; + + for (retVal = 2, i = 0; + i < 5 && boxMon->nickname[i] != EOS; + data[retVal] = boxMon->nickname[i], retVal++, i++) {} + + data[retVal++] = EXT_CTRL_CODE_BEGIN; + data[retVal++] = EXT_CTRL_CODE_ENG; + data[retVal] = EOS; + } + else + { + for (retVal = 0; + retVal < POKEMON_NAME_LENGTH; + data[retVal] = boxMon->nickname[retVal], retVal++){} + + data[retVal] = EOS; + } + break; + } + case MON_DATA_LANGUAGE: + retVal = boxMon->language; + break; + case MON_DATA_SANITY_BIT1: + retVal = boxMon->isBadEgg; + break; + case MON_DATA_SANITY_BIT2: + retVal = boxMon->hasSpecies; + break; + case MON_DATA_SANITY_BIT3: + retVal = boxMon->isEgg; + break; + case MON_DATA_OT_NAME: + { + retVal = 0; + + while (retVal < OT_NAME_LENGTH) + { + data[retVal] = boxMon->otName[retVal]; + retVal++; + } + + data[retVal] = EOS; + break; + } + case MON_DATA_MARKINGS: + retVal = boxMon->markings; + break; + case MON_DATA_CHECKSUM: + retVal = boxMon->checksum; + break; + case MON_DATA_10: + retVal = boxMon->unknown; + break; + case MON_DATA_SPECIES: + retVal = boxMon->isBadEgg ? SPECIES_EGG : substruct0->species; + break; + case MON_DATA_HELD_ITEM: + retVal = substruct0->heldItem; + break; + case MON_DATA_EXP: + retVal = substruct0->experience; + break; + case MON_DATA_PP_BONUSES: + retVal = substruct0->ppBonuses; + break; + case MON_DATA_FRIENDSHIP: + retVal = substruct0->friendship; + break; + case MON_DATA_MOVE1: + case MON_DATA_MOVE2: + case MON_DATA_MOVE3: + case MON_DATA_MOVE4: + retVal = substruct1->moves[field - MON_DATA_MOVE1]; + break; + case MON_DATA_PP1: + case MON_DATA_PP2: + case MON_DATA_PP3: + case MON_DATA_PP4: + retVal = substruct1->pp[field - MON_DATA_PP1]; + break; + case MON_DATA_HP_EV: + retVal = substruct2->hpEV; + break; + case MON_DATA_ATK_EV: + retVal = substruct2->attackEV; + break; + case MON_DATA_DEF_EV: + retVal = substruct2->defenseEV; + break; + case MON_DATA_SPD_EV: + retVal = substruct2->speedEV; + break; + case MON_DATA_SPATK_EV: + retVal = substruct2->spAttackEV; + break; + case MON_DATA_SPDEF_EV: + retVal = substruct2->spDefenseEV; + break; + case MON_DATA_COOL: + retVal = substruct2->cool; + break; + case MON_DATA_BEAUTY: + retVal = substruct2->beauty; + break; + case MON_DATA_CUTE: + retVal = substruct2->cute; + break; + case MON_DATA_SMART: + retVal = substruct2->smart; + break; + case MON_DATA_TOUGH: + retVal = substruct2->tough; + break; + case MON_DATA_SHEEN: + retVal = substruct2->sheen; + break; + case MON_DATA_POKERUS: + retVal = substruct3->pokerus; + break; + case MON_DATA_MET_LOCATION: + retVal = substruct3->metLocation; + break; + case MON_DATA_MET_LEVEL: + retVal = substruct3->metLevel; + break; + case MON_DATA_MET_GAME: + retVal = substruct3->metGame; + break; + case MON_DATA_POKEBALL: + retVal = substruct3->pokeball; + break; + case MON_DATA_OT_GENDER: + retVal = substruct3->otGender; + break; + case MON_DATA_HP_IV: + retVal = substruct3->hpIV; + break; + case MON_DATA_ATK_IV: + retVal = substruct3->attackIV; + break; + case MON_DATA_DEF_IV: + retVal = substruct3->defenseIV; + break; + case MON_DATA_SPD_IV: + retVal = substruct3->speedIV; + break; + case MON_DATA_SPATK_IV: + retVal = substruct3->spAttackIV; + break; + case MON_DATA_SPDEF_IV: + retVal = substruct3->spDefenseIV; + break; + case MON_DATA_IS_EGG: + retVal = substruct3->isEgg; + break; + case MON_DATA_ALT_ABILITY: + retVal = substruct3->altAbility; + break; + case MON_DATA_COOL_RIBBON: + retVal = substruct3->coolRibbon; + break; + case MON_DATA_BEAUTY_RIBBON: + retVal = substruct3->beautyRibbon; + break; + case MON_DATA_CUTE_RIBBON: + retVal = substruct3->cuteRibbon; + break; + case MON_DATA_SMART_RIBBON: + retVal = substruct3->smartRibbon; + break; + case MON_DATA_TOUGH_RIBBON: + retVal = substruct3->toughRibbon; + break; + case MON_DATA_CHAMPION_RIBBON: + retVal = substruct3->championRibbon; + break; + case MON_DATA_WINNING_RIBBON: + retVal = substruct3->winningRibbon; + break; + case MON_DATA_VICTORY_RIBBON: + retVal = substruct3->victoryRibbon; + break; + case MON_DATA_ARTIST_RIBBON: + retVal = substruct3->artistRibbon; + break; + case MON_DATA_EFFORT_RIBBON: + retVal = substruct3->effortRibbon; + break; + case MON_DATA_GIFT_RIBBON_1: + retVal = substruct3->giftRibbon1; + break; + case MON_DATA_GIFT_RIBBON_2: + retVal = substruct3->giftRibbon2; + break; + case MON_DATA_GIFT_RIBBON_3: + retVal = substruct3->giftRibbon3; + break; + case MON_DATA_GIFT_RIBBON_4: + retVal = substruct3->giftRibbon4; + break; + case MON_DATA_GIFT_RIBBON_5: + retVal = substruct3->giftRibbon5; + break; + case MON_DATA_GIFT_RIBBON_6: + retVal = substruct3->giftRibbon6; + break; + case MON_DATA_GIFT_RIBBON_7: + retVal = substruct3->giftRibbon7; + break; + case MON_DATA_FATEFUL_ENCOUNTER: + retVal = substruct3->fatefulEncounter; + break; + case MON_DATA_OBEDIENCE: + retVal = substruct3->obedient; + break; + case MON_DATA_SPECIES2: + retVal = substruct0->species; + if (substruct0->species && (substruct3->isEgg || boxMon->isBadEgg)) + retVal = SPECIES_EGG; + break; + case MON_DATA_IVS: + retVal = substruct3->hpIV | (substruct3->attackIV << 5) | (substruct3->defenseIV << 10) | (substruct3->speedIV << 15) | (substruct3->spAttackIV << 20) | (substruct3->spDefenseIV << 25); + break; + case MON_DATA_KNOWN_MOVES: + if (substruct0->species && !substruct3->isEgg) + { + u16 *moves = (u16 *)data; + s32 i = 0; + + while (moves[i] != 355) + { + u16 move = moves[i]; + if (substruct1->moves[0] == move + || substruct1->moves[1] == move + || substruct1->moves[2] == move + || substruct1->moves[3] == move) + retVal |= gBitTable[i]; + i++; + } + } + break; + case MON_DATA_RIBBON_COUNT: + retVal = 0; + if (substruct0->species && !substruct3->isEgg) + { + retVal += substruct3->coolRibbon; + retVal += substruct3->beautyRibbon; + retVal += substruct3->cuteRibbon; + retVal += substruct3->smartRibbon; + retVal += substruct3->toughRibbon; + retVal += substruct3->championRibbon; + retVal += substruct3->winningRibbon; + retVal += substruct3->victoryRibbon; + retVal += substruct3->artistRibbon; + retVal += substruct3->effortRibbon; + retVal += substruct3->giftRibbon1; + retVal += substruct3->giftRibbon2; + retVal += substruct3->giftRibbon3; + retVal += substruct3->giftRibbon4; + retVal += substruct3->giftRibbon5; + retVal += substruct3->giftRibbon6; + retVal += substruct3->giftRibbon7; + } + break; + case MON_DATA_RIBBONS: + retVal = 0; + if (substruct0->species && !substruct3->isEgg) + { + retVal = substruct3->championRibbon + | (substruct3->coolRibbon << 1) + | (substruct3->beautyRibbon << 4) + | (substruct3->cuteRibbon << 7) + | (substruct3->smartRibbon << 10) + | (substruct3->toughRibbon << 13) + | (substruct3->winningRibbon << 16) + | (substruct3->victoryRibbon << 17) + | (substruct3->artistRibbon << 18) + | (substruct3->effortRibbon << 19) + | (substruct3->giftRibbon1 << 20) + | (substruct3->giftRibbon2 << 21) + | (substruct3->giftRibbon3 << 22) + | (substruct3->giftRibbon4 << 23) + | (substruct3->giftRibbon5 << 24) + | (substruct3->giftRibbon6 << 25) + | (substruct3->giftRibbon7 << 26); + } + break; + default: + break; + } + + if (field > MON_DATA_10) + EncryptBoxMon(boxMon); + + return retVal; +} + +#define SET8(lhs) (lhs) = *data +#define SET16(lhs) (lhs) = data[0] + (data[1] << 8) +#define SET32(lhs) (lhs) = data[0] + (data[1] << 8) + (data[2] << 16) + (data[3] << 24) + +void SetMonData(struct Pokemon *mon, s32 field, const void *dataArg) +{ + const u8* data = dataArg; + switch (field) + { + case MON_DATA_STATUS: + SET32(mon->status); + break; + case MON_DATA_LEVEL: + SET8(mon->level); + break; + case MON_DATA_HP: + SET16(mon->hp); + break; + case MON_DATA_MAX_HP: + SET16(mon->maxHP); + break; + case MON_DATA_ATK: + SET16(mon->attack); + break; + case MON_DATA_DEF: + SET16(mon->defense); + break; + case MON_DATA_SPD: + SET16(mon->speed); + break; + case MON_DATA_SPATK: + SET16(mon->spAttack); + break; + case MON_DATA_SPDEF: + SET16(mon->spDefense); + break; + case MON_DATA_MAIL: + SET8(mon->mail); + break; + case MON_DATA_SPECIES2: + break; + default: + SetBoxMonData(&mon->box, field, data); + break; + } +} + +void SetBoxMonData(struct BoxPokemon *boxMon, s32 field, const void *dataArg) +{ + const u8* data = dataArg; + + struct PokemonSubstruct0 *substruct0 = NULL; + struct PokemonSubstruct1 *substruct1 = NULL; + struct PokemonSubstruct2 *substruct2 = NULL; + struct PokemonSubstruct3 *substruct3 = NULL; + + if (field > MON_DATA_10) + { + substruct0 = &(GetSubstruct(boxMon, boxMon->personality, 0)->type0); + substruct1 = &(GetSubstruct(boxMon, boxMon->personality, 1)->type1); + substruct2 = &(GetSubstruct(boxMon, boxMon->personality, 2)->type2); + substruct3 = &(GetSubstruct(boxMon, boxMon->personality, 3)->type3); + + DecryptBoxMon(boxMon); + + if (CalculateBoxMonChecksum(boxMon) != boxMon->checksum) + { + boxMon->isBadEgg = 1; + boxMon->isEgg = 1; + substruct3->isEgg = 1; + EncryptBoxMon(boxMon); + return; + } + } + + switch (field) + { + case MON_DATA_PERSONALITY: + SET32(boxMon->personality); + break; + case MON_DATA_OT_ID: + SET32(boxMon->otId); + break; + case MON_DATA_NICKNAME: + { + s32 i; + for (i = 0; i < POKEMON_NAME_LENGTH; i++) + boxMon->nickname[i] = data[i]; + break; + } + case MON_DATA_LANGUAGE: + SET8(boxMon->language); + break; + case MON_DATA_SANITY_BIT1: + SET8(boxMon->isBadEgg); + break; + case MON_DATA_SANITY_BIT2: + SET8(boxMon->hasSpecies); + break; + case MON_DATA_SANITY_BIT3: + SET8(boxMon->isEgg); + break; + case MON_DATA_OT_NAME: + { + s32 i; + for (i = 0; i < OT_NAME_LENGTH; i++) + boxMon->otName[i] = data[i]; + break; + } + case MON_DATA_MARKINGS: + SET8(boxMon->markings); + break; + case MON_DATA_CHECKSUM: + SET16(boxMon->checksum); + break; + case MON_DATA_10: + SET16(boxMon->unknown); + break; + case MON_DATA_SPECIES: + { + SET16(substruct0->species); + if (substruct0->species) + boxMon->hasSpecies = 1; + else + boxMon->hasSpecies = 0; + break; + } + case MON_DATA_HELD_ITEM: + SET16(substruct0->heldItem); + break; + case MON_DATA_EXP: + SET32(substruct0->experience); + break; + case MON_DATA_PP_BONUSES: + SET8(substruct0->ppBonuses); + break; + case MON_DATA_FRIENDSHIP: + SET8(substruct0->friendship); + break; + case MON_DATA_MOVE1: + case MON_DATA_MOVE2: + case MON_DATA_MOVE3: + case MON_DATA_MOVE4: + SET16(substruct1->moves[field - MON_DATA_MOVE1]); + break; + case MON_DATA_PP1: + case MON_DATA_PP2: + case MON_DATA_PP3: + case MON_DATA_PP4: + SET8(substruct1->pp[field - MON_DATA_PP1]); + break; + case MON_DATA_HP_EV: + SET8(substruct2->hpEV); + break; + case MON_DATA_ATK_EV: + SET8(substruct2->attackEV); + break; + case MON_DATA_DEF_EV: + SET8(substruct2->defenseEV); + break; + case MON_DATA_SPD_EV: + SET8(substruct2->speedEV); + break; + case MON_DATA_SPATK_EV: + SET8(substruct2->spAttackEV); + break; + case MON_DATA_SPDEF_EV: + SET8(substruct2->spDefenseEV); + break; + case MON_DATA_COOL: + SET8(substruct2->cool); + break; + case MON_DATA_BEAUTY: + SET8(substruct2->beauty); + break; + case MON_DATA_CUTE: + SET8(substruct2->cute); + break; + case MON_DATA_SMART: + SET8(substruct2->smart); + break; + case MON_DATA_TOUGH: + SET8(substruct2->tough); + break; + case MON_DATA_SHEEN: + SET8(substruct2->sheen); + break; + case MON_DATA_POKERUS: + SET8(substruct3->pokerus); + break; + case MON_DATA_MET_LOCATION: + SET8(substruct3->metLocation); + break; + case MON_DATA_MET_LEVEL: + { + u8 metLevel = *data; + substruct3->metLevel = metLevel; + break; + } + case MON_DATA_MET_GAME: + SET8(substruct3->metGame); + break; + case MON_DATA_POKEBALL: + { + u8 pokeball = *data; + substruct3->pokeball = pokeball; + break; + } + case MON_DATA_OT_GENDER: + SET8(substruct3->otGender); + break; + case MON_DATA_HP_IV: + SET8(substruct3->hpIV); + break; + case MON_DATA_ATK_IV: + SET8(substruct3->attackIV); + break; + case MON_DATA_DEF_IV: + SET8(substruct3->defenseIV); + break; + case MON_DATA_SPD_IV: + SET8(substruct3->speedIV); + break; + case MON_DATA_SPATK_IV: + SET8(substruct3->spAttackIV); + break; + case MON_DATA_SPDEF_IV: + SET8(substruct3->spDefenseIV); + break; + case MON_DATA_IS_EGG: + SET8(substruct3->isEgg); + if (substruct3->isEgg) + boxMon->isEgg = 1; + else + boxMon->isEgg = 0; + break; + case MON_DATA_ALT_ABILITY: + SET8(substruct3->altAbility); + break; + case MON_DATA_COOL_RIBBON: + SET8(substruct3->coolRibbon); + break; + case MON_DATA_BEAUTY_RIBBON: + SET8(substruct3->beautyRibbon); + break; + case MON_DATA_CUTE_RIBBON: + SET8(substruct3->cuteRibbon); + break; + case MON_DATA_SMART_RIBBON: + SET8(substruct3->smartRibbon); + break; + case MON_DATA_TOUGH_RIBBON: + SET8(substruct3->toughRibbon); + break; + case MON_DATA_CHAMPION_RIBBON: + SET8(substruct3->championRibbon); + break; + case MON_DATA_WINNING_RIBBON: + SET8(substruct3->winningRibbon); + break; + case MON_DATA_VICTORY_RIBBON: + SET8(substruct3->victoryRibbon); + break; + case MON_DATA_ARTIST_RIBBON: + SET8(substruct3->artistRibbon); + break; + case MON_DATA_EFFORT_RIBBON: + SET8(substruct3->effortRibbon); + break; + case MON_DATA_GIFT_RIBBON_1: + SET8(substruct3->giftRibbon1); + break; + case MON_DATA_GIFT_RIBBON_2: + SET8(substruct3->giftRibbon2); + break; + case MON_DATA_GIFT_RIBBON_3: + SET8(substruct3->giftRibbon3); + break; + case MON_DATA_GIFT_RIBBON_4: + SET8(substruct3->giftRibbon4); + break; + case MON_DATA_GIFT_RIBBON_5: + SET8(substruct3->giftRibbon5); + break; + case MON_DATA_GIFT_RIBBON_6: + SET8(substruct3->giftRibbon6); + break; + case MON_DATA_GIFT_RIBBON_7: + SET8(substruct3->giftRibbon7); + break; + case MON_DATA_FATEFUL_ENCOUNTER: + SET8(substruct3->fatefulEncounter); + break; + case MON_DATA_OBEDIENCE: + SET8(substruct3->obedient); + break; + case MON_DATA_IVS: + { + u32 ivs = data[0] | (data[1] << 8) | (data[2] << 16) | (data[3] << 24); + substruct3->hpIV = ivs & 0x1F; + substruct3->attackIV = (ivs >> 5) & 0x1F; + substruct3->defenseIV = (ivs >> 10) & 0x1F; + substruct3->speedIV = (ivs >> 15) & 0x1F; + substruct3->spAttackIV = (ivs >> 20) & 0x1F; + substruct3->spDefenseIV = (ivs >> 25) & 0x1F; + break; + } + default: + break; + } + + if (field > MON_DATA_10) + { + boxMon->checksum = CalculateBoxMonChecksum(boxMon); + EncryptBoxMon(boxMon); + } +} + +void CopyMon(void *dest, void *src, size_t size) +{ + memcpy(dest, src, size); +} + +u8 GiveMonToPlayer(struct Pokemon *mon) +{ + s32 i; + + SetMonData(mon, MON_DATA_OT_NAME, gSaveBlock2Ptr->playerName); + SetMonData(mon, MON_DATA_OT_GENDER, &gSaveBlock2Ptr->playerGender); + SetMonData(mon, MON_DATA_OT_ID, gSaveBlock2Ptr->playerTrainerId); + + i = 0; + + while (i < 6 && GetMonData(&gPlayerParty[i], MON_DATA_SPECIES, NULL) != SPECIES_NONE) + i++; + + if (i >= 6) + return SendMonToPC(mon); + + CopyMon(&gPlayerParty[i], mon, sizeof(*mon)); + gPlayerPartyCount = i + 1; + return MON_GIVEN_TO_PARTY; +} + +extern u16 get_unknown_box_id(void); +extern u8 StorageGetCurrentBox(void); +extern void set_unknown_box_id(u8); +extern struct BoxPokemon* GetBoxedMonPtr(u8 boxNumber, u8 boxPosition); + +u8 SendMonToPC(struct Pokemon* mon) +{ + s32 boxNo, boxPos; + + set_unknown_box_id(VarGet(VAR_STORAGE_UNKNOWN)); + + boxNo = StorageGetCurrentBox(); + + do + { + for (boxPos = 0; boxPos < 30; boxPos++) + { + struct BoxPokemon* checkingMon = GetBoxedMonPtr(boxNo, boxPos); + if (GetBoxMonData(checkingMon, MON_DATA_SPECIES, NULL) == SPECIES_NONE) + { + MonRestorePP(mon); + CopyMon(checkingMon, &mon->box, sizeof(mon->box)); + gSpecialVar_0x8012 = boxNo; + gSpecialVar_0x8013 = boxPos; + if (get_unknown_box_id() != boxNo) + FlagReset(SYS_STORAGE_UNKNOWN_FLAG); + VarSet(VAR_STORAGE_UNKNOWN, boxNo); + return MON_GIVEN_TO_PC; + } + } + + boxNo++; + if (boxNo == 14) + boxNo = 0; + } while (boxNo != StorageGetCurrentBox()); + + return MON_CANT_GIVE; +} + +u8 CalculatePlayerPartyCount(void) +{ + gPlayerPartyCount = 0; + + while (gPlayerPartyCount < 6 + && GetMonData(&gPlayerParty[gPlayerPartyCount], MON_DATA_SPECIES, NULL) != SPECIES_NONE) + { + gPlayerPartyCount++; + } + + return gPlayerPartyCount; +} + +u8 CalculateEnemyPartyCount(void) +{ + gEnemyPartyCount = 0; + + while (gEnemyPartyCount < 6 + && GetMonData(&gEnemyParty[gEnemyPartyCount], MON_DATA_SPECIES, NULL) != SPECIES_NONE) + { + gEnemyPartyCount++; + } + + return gEnemyPartyCount; +} + +u8 GetMonsStateToDoubles(void) +{ + s32 aliveCount = 0; + s32 i; + CalculatePlayerPartyCount(); + + if (gPlayerPartyCount == 1) + return gPlayerPartyCount; // PLAYER_HAS_ONE_MON + + for (i = 0; i < gPlayerPartyCount; i++) + { + if (GetMonData(&gPlayerParty[i], MON_DATA_SPECIES2, NULL) != SPECIES_EGG + && GetMonData(&gPlayerParty[i], MON_DATA_HP, NULL) != 0 + && GetMonData(&gPlayerParty[i], MON_DATA_SPECIES2, NULL) != SPECIES_NONE) + aliveCount++; + } + + return (aliveCount > 1) ? PLAYER_HAS_TWO_USABLE_MONS : PLAYER_HAS_ONE_USABLE_MON; +} + +u8 GetMonsStateToDoubles_2(void) +{ + s32 aliveCount = 0; + s32 i; + + for (i = 0; i < 6; i++) + { + u32 species = GetMonData(&gPlayerParty[i], MON_DATA_SPECIES2, NULL); + if (species != SPECIES_EGG && species != SPECIES_NONE + && GetMonData(&gPlayerParty[i], MON_DATA_HP, NULL) != 0) + aliveCount++; + } + + if (aliveCount == 1) + return PLAYER_HAS_ONE_MON; // may have more than one, but only one is alive + + return (aliveCount > 1) ? PLAYER_HAS_TWO_USABLE_MONS : PLAYER_HAS_ONE_USABLE_MON; +} diff --git a/sym_ewram.txt b/sym_ewram.txt index 22f87fc721..a1257cab54 100644 --- a/sym_ewram.txt +++ b/sym_ewram.txt @@ -550,7 +550,7 @@ sLearningMoveTableID: @ 20244E8 gPlayerPartyCount: @ 20244E9 .space 0x1 -gUnknown_020244EA: @ 20244EA +gEnemyPartyCount: @ 20244EA .space 0x2 gPlayerParty: @ 20244EC