diff options
author | PikalaxALT <pikalaxalt@gmail.com> | 2020-06-12 12:50:21 -0400 |
---|---|---|
committer | PikalaxALT <pikalaxalt@gmail.com> | 2020-06-12 12:50:21 -0400 |
commit | 5dcce3a7303e45667967689361513cb2920be3f4 (patch) | |
tree | 0cb277ac6d494fa4c2d50ff15c2022d9d6f4d5b8 | |
parent | 1dd706599353a285534398ccdc34a9ef8bc6e549 (diff) |
through GenPersonalityByGenderAndNature
-rw-r--r-- | arm9/asm/pokemon_s.s | 554 | ||||
-rw-r--r-- | arm9/asm/scrcmd.s | 2 | ||||
-rw-r--r-- | arm9/asm/scrcmd_12.s | 2 | ||||
-rw-r--r-- | arm9/asm/unk_020476CC.s | 2 | ||||
-rw-r--r-- | arm9/asm/unk_0206C700.s | 6 | ||||
-rw-r--r-- | arm9/asm/unk_020828BC.s | 2 | ||||
-rw-r--r-- | arm9/asm/unk_020842DC.s | 14 | ||||
-rw-r--r-- | arm9/global.inc | 6 | ||||
-rw-r--r-- | arm9/modules/05/asm/module_05.s | 4 | ||||
-rw-r--r-- | arm9/modules/06/asm/module_06.s | 8 | ||||
-rw-r--r-- | arm9/modules/67/asm/module_67.s | 2 | ||||
-rw-r--r-- | arm9/src/pokemon.c | 208 | ||||
-rw-r--r-- | include/global.h | 3 | ||||
-rw-r--r-- | include/math_util.h | 6 | ||||
-rw-r--r-- | include/pokemon.h | 49 | ||||
-rw-r--r-- | include/seals.h | 12 |
16 files changed, 287 insertions, 593 deletions
diff --git a/arm9/asm/pokemon_s.s b/arm9/asm/pokemon_s.s index 2395e7f1..97650972 100644 --- a/arm9/asm/pokemon_s.s +++ b/arm9/asm/pokemon_s.s @@ -116,552 +116,6 @@ UNK_021C5AC0: ; 0x021C5AC0 .text - thumb_func_start TryEncryptMon -TryEncryptMon: ; 0x02066A20 - push {r3-r5, lr} - add r5, r0, #0x0 - ldrh r2, [r5, #0x4] - mov r4, #0x0 - lsl r0, r2, #0x1f - lsr r0, r0, #0x1f - cmp r0, #0x1 - bne _02066A68 - cmp r1, #0x1 - bne _02066A68 - mov r0, #0x1 - bic r2, r0 - strh r2, [r5, #0x4] - ldrh r1, [r5, #0x4] - mov r0, #0x2 - mov r4, #0x1 - bic r1, r0 - strh r1, [r5, #0x4] - add r0, r5, #0x0 - ldr r2, [r5, #0x0] - add r0, #0x88 - mov r1, #0x64 - bl MonEncryptSegment - add r0, r5, #0x0 - add r0, #0x8 - mov r1, #0x80 - bl CalcMonChecksum - strh r0, [r5, #0x6] - add r0, r5, #0x0 - ldrh r2, [r5, #0x6] - add r0, #0x8 - mov r1, #0x80 - bl MonEncryptSegment -_02066A68: - add r0, r4, #0x0 - pop {r3-r5, pc} - - thumb_func_start TryDecryptBoxMon -TryDecryptBoxMon: ; 0x02066A6C - push {r4, lr} - add r2, r0, #0x0 - ldrh r1, [r2, #0x4] - mov r4, #0x0 - lsl r0, r1, #0x1e - lsr r0, r0, #0x1f - bne _02066A8E - mov r0, #0x2 - orr r0, r1 - strh r0, [r2, #0x4] - add r0, r2, #0x0 - ldrh r2, [r2, #0x6] - add r0, #0x8 - mov r1, #0x80 - mov r4, #0x1 - bl MonDecryptSegment -_02066A8E: - add r0, r4, #0x0 - pop {r4, pc} - .balign 4 - - thumb_func_start TryEncryptBoxMon -TryEncryptBoxMon: ; 0x02066A94 - push {r3-r5, lr} - add r5, r0, #0x0 - ldrh r2, [r5, #0x4] - mov r4, #0x0 - lsl r0, r2, #0x1e - lsr r0, r0, #0x1f - cmp r0, #0x1 - bne _02066AC8 - cmp r1, #0x1 - bne _02066AC8 - mov r0, #0x2 - bic r2, r0 - add r0, r5, #0x0 - strh r2, [r5, #0x4] - add r0, #0x8 - mov r1, #0x80 - mov r4, #0x1 - bl CalcMonChecksum - strh r0, [r5, #0x6] - add r0, r5, #0x0 - ldrh r2, [r5, #0x6] - add r0, #0x8 - mov r1, #0x80 - bl MonEncryptSegment -_02066AC8: - add r0, r4, #0x0 - pop {r3-r5, pc} - - thumb_func_start CreateMon -CreateMon: ; 0x02066ACC - push {r0-r3} - push {r3-r6, lr} - sub sp, #0x2c - add r5, r0, #0x0 - add r4, r1, #0x0 - add r6, r3, #0x0 - bl ZeroMonData - ldr r0, [sp, #0x50] - add r1, r4, #0x0 - str r0, [sp, #0x0] - ldr r0, [sp, #0x54] - add r3, r6, #0x0 - str r0, [sp, #0x4] - ldr r0, [sp, #0x58] - str r0, [sp, #0x8] - ldr r0, [sp, #0x5c] - str r0, [sp, #0xc] - ldr r2, [sp, #0x48] - add r0, r5, #0x0 - bl CreateBoxMon - add r0, r5, #0x0 - add r0, #0x88 - mov r1, #0x64 - mov r2, #0x0 - bl MonEncryptSegment - add r0, r5, #0x0 - ldr r2, [r5, #0x0] - add r0, #0x88 - mov r1, #0x64 - bl MonEncryptSegment - add r0, r5, #0x0 - mov r1, #0xa0 - add r2, sp, #0x48 - bl SetMonDataEncrypted - mov r0, #0x0 - bl CreateNewSealsObject - add r4, r0, #0x0 - add r0, r5, #0x0 - mov r1, #0xa9 - add r2, r4, #0x0 - bl SetMonDataEncrypted - add r0, r4, #0x0 - bl FreeToHeap - mov r0, #0x0 - str r0, [sp, #0x10] - add r0, r5, #0x0 - mov r1, #0xa1 - add r2, sp, #0x10 - bl SetMonDataEncrypted - mov r0, #0x0 - add r1, sp, #0x14 - mov r2, #0x18 - bl MIi_CpuClearFast - add r0, r5, #0x0 - mov r1, #0xaa - add r2, sp, #0x14 - bl SetMonDataEncrypted - add r0, r5, #0x0 - bl UpdateMonLevelAndRecalcStats - add sp, #0x2c - pop {r3-r6} - pop {r3} - add sp, #0x10 - bx r3 - - thumb_func_start CreateBoxMon -CreateBoxMon: ; 0x02066B64 - push {r0-r3} - push {r4-r7, lr} - sub sp, #0xc - add r5, r0, #0x0 - bl ZeroBoxMonData - add r0, r5, #0x0 - bl TryDecryptBoxMon - str r0, [sp, #0x0] - ldr r0, [sp, #0x30] - cmp r0, #0x0 - bne _02066B8E - bl rand_LC - add r4, r0, #0x0 - bl rand_LC - lsl r0, r0, #0x10 - orr r0, r4 - str r0, [sp, #0x34] -_02066B8E: - add r0, r5, #0x0 - mov r1, #0x0 - add r2, sp, #0x34 - bl SetBoxMonDataEncrypted - // If otIdType == 2, generate a random OT ID that prevents shininess - ldr r0, [sp, #0x38] - cmp r0, #0x2 - bne _02066BD6 - ldr r7, _02066D84 ; =0xFFFF0000 - add r6, r7, #0x0 -_02066BA2: - bl rand_LC - add r4, r0, #0x0 - bl rand_LC - ldr r1, [sp, #0x34] - lsl r0, r0, #0x10 - add r3, r4, #0x0 - orr r3, r0 - lsl r0, r1, #0x10 - lsr r2, r0, #0x10 - add r0, r1, #0x0 - and r0, r7 - lsr r1, r0, #0x10 - add r0, r3, #0x0 - str r3, [sp, #0x3c] - and r0, r6 - lsl r3, r3, #0x10 - lsr r0, r0, #0x10 - lsr r3, r3, #0x10 - eor r0, r3 - eor r0, r1 - eor r0, r2 - cmp r0, #0x8 - blo _02066BA2 - b _02066BDE -_02066BD6: - cmp r0, #0x1 - beq _02066BDE - mov r0, #0x0 - str r0, [sp, #0x3c] -_02066BDE: - add r0, r5, #0x0 - mov r1, #0x7 - add r2, sp, #0x3c - bl SetBoxMonDataEncrypted - ldr r2, _02066D88 ; =gGameLanguage - add r0, r5, #0x0 - mov r1, #0xc - bl SetBoxMonDataEncrypted - add r0, r5, #0x0 - mov r1, #0x5 - add r2, sp, #0x24 - bl SetBoxMonDataEncrypted - add r0, r5, #0x0 - mov r1, #0xb2 - mov r2, #0x0 - bl SetBoxMonDataEncrypted - ldr r0, [sp, #0x24] - ldr r1, [sp, #0x28] - bl GetMonExpBySpeciesAndLevel - str r0, [sp, #0x8] - add r0, r5, #0x0 - mov r1, #0x8 - add r2, sp, #0x8 - bl SetBoxMonDataEncrypted - ldr r0, [sp, #0x24] - mov r1, #0x14 - bl GetMonBaseStat - str r0, [sp, #0x8] - add r0, r5, #0x0 - mov r1, #0x9 - add r2, sp, #0x8 - bl SetBoxMonDataEncrypted - add r0, r5, #0x0 - mov r1, #0x9b - add r2, sp, #0x28 - bl SetBoxMonDataEncrypted - ldr r2, _02066D8C ; =gGameVersion - add r0, r5, #0x0 - mov r1, #0x79 - bl SetBoxMonDataEncrypted - mov r0, #0x4 - str r0, [sp, #0x8] - add r0, r5, #0x0 - mov r1, #0x9a - add r2, sp, #0x8 - bl SetBoxMonDataEncrypted - ldr r0, [sp, #0x2c] - cmp r0, #0x20 - bge _02066C94 - add r0, r5, #0x0 - mov r1, #0x46 - add r2, sp, #0x2c - bl SetBoxMonDataEncrypted - add r0, r5, #0x0 - mov r1, #0x47 - add r2, sp, #0x2c - bl SetBoxMonDataEncrypted - add r0, r5, #0x0 - mov r1, #0x48 - add r2, sp, #0x2c - bl SetBoxMonDataEncrypted - add r0, r5, #0x0 - mov r1, #0x49 - add r2, sp, #0x2c - bl SetBoxMonDataEncrypted - add r0, r5, #0x0 - mov r1, #0x4a - add r2, sp, #0x2c - bl SetBoxMonDataEncrypted - add r0, r5, #0x0 - mov r1, #0x4b - add r2, sp, #0x2c - bl SetBoxMonDataEncrypted - b _02066D18 -_02066C94: - bl rand_LC - mov r1, #0x1f - str r0, [sp, #0x8] - and r0, r1 - str r0, [sp, #0x4] - add r0, r5, #0x0 - mov r1, #0x46 - add r2, sp, #0x4 - bl SetBoxMonDataEncrypted - mov r0, #0x3e - ldr r1, [sp, #0x8] - lsl r0, r0, #0x4 - and r0, r1 - lsr r0, r0, #0x5 - str r0, [sp, #0x4] - add r0, r5, #0x0 - mov r1, #0x47 - add r2, sp, #0x4 - bl SetBoxMonDataEncrypted - mov r0, #0x1f - ldr r1, [sp, #0x8] - lsl r0, r0, #0xa - and r0, r1 - lsr r0, r0, #0xa - str r0, [sp, #0x4] - add r0, r5, #0x0 - mov r1, #0x48 - add r2, sp, #0x4 - bl SetBoxMonDataEncrypted - bl rand_LC - mov r1, #0x1f - str r0, [sp, #0x8] - and r0, r1 - str r0, [sp, #0x4] - add r0, r5, #0x0 - mov r1, #0x49 - add r2, sp, #0x4 - bl SetBoxMonDataEncrypted - mov r0, #0x3e - ldr r1, [sp, #0x8] - lsl r0, r0, #0x4 - and r0, r1 - lsr r0, r0, #0x5 - str r0, [sp, #0x4] - add r0, r5, #0x0 - mov r1, #0x4a - add r2, sp, #0x4 - bl SetBoxMonDataEncrypted - mov r0, #0x1f - ldr r1, [sp, #0x8] - lsl r0, r0, #0xa - and r0, r1 - lsr r0, r0, #0xa - str r0, [sp, #0x4] - add r0, r5, #0x0 - mov r1, #0x4b - add r2, sp, #0x4 - bl SetBoxMonDataEncrypted -_02066D18: - ldr r0, [sp, #0x24] - mov r1, #0x18 - bl GetMonBaseStat - str r0, [sp, #0x8] - ldr r0, [sp, #0x24] - mov r1, #0x19 - bl GetMonBaseStat - str r0, [sp, #0x4] - cmp r0, #0x0 - beq _02066D50 - ldr r1, [sp, #0x34] - mov r0, #0x1 - tst r0, r1 - beq _02066D44 - add r0, r5, #0x0 - mov r1, #0xa - add r2, sp, #0x4 - bl SetBoxMonDataEncrypted - b _02066D5A -_02066D44: - add r0, r5, #0x0 - mov r1, #0xa - add r2, sp, #0x8 - bl SetBoxMonDataEncrypted - b _02066D5A -_02066D50: - add r0, r5, #0x0 - mov r1, #0xa - add r2, sp, #0x8 - bl SetBoxMonDataEncrypted -_02066D5A: - add r0, r5, #0x0 - bl GetBoxMonGenderEncrypted - str r0, [sp, #0x8] - add r0, r5, #0x0 - mov r1, #0x6f - add r2, sp, #0x8 - bl SetBoxMonDataEncrypted - add r0, r5, #0x0 - bl InitBoxMonMoveset - ldr r1, [sp, #0x0] - add r0, r5, #0x0 - bl TryEncryptBoxMon - add sp, #0xc - pop {r4-r7} - pop {r3} - add sp, #0x10 - bx r3 - .balign 4 -_02066D84: .word 0xFFFF0000 -_02066D88: .word gGameLanguage -_02066D8C: .word gGameVersion - - thumb_func_start CreateMonWithNature -CreateMonWithNature: ; 0x02066D90 - push {r3-r7, lr} - sub sp, #0x18 - str r2, [sp, #0x10] - str r3, [sp, #0x14] - ldr r4, [sp, #0x30] - add r6, r0, #0x0 - add r7, r1, #0x0 -_02066D9E: - bl rand_LC - add r5, r0, #0x0 - bl rand_LC - lsl r0, r0, #0x10 - orr r5, r0 - add r0, r5, #0x0 - bl GetNatureFromPersonality - cmp r4, r0 - bne _02066D9E - mov r0, #0x1 - str r0, [sp, #0x0] - str r5, [sp, #0x4] - mov r0, #0x0 - str r0, [sp, #0x8] - str r0, [sp, #0xc] - ldr r2, [sp, #0x10] - ldr r3, [sp, #0x14] - add r0, r6, #0x0 - add r1, r7, #0x0 - bl CreateMon - add sp, #0x18 - pop {r3-r7, pc} - .balign 4 - - thumb_func_start CreateMonWithNatureGenderLetter -CreateMonWithNatureGenderLetter: ; 0x02066DD4 - push {r4-r7, lr} - sub sp, #0x24 - str r1, [sp, #0x14] - str r2, [sp, #0x18] - str r3, [sp, #0x1c] - str r0, [sp, #0x10] - add r0, sp, #0x28 - ldrb r0, [r0, #0x18] - ldr r6, [sp, #0x38] - ldr r7, [sp, #0x3c] - cmp r0, #0x0 - beq _02066E4C - cmp r0, #0x1d - bhs _02066E4C - sub r0, r0, #0x1 - str r0, [sp, #0x20] -_02066DF4: - bl rand_LC - add r4, r0, #0x0 - bl rand_LC - lsl r0, r0, #0x10 - orr r4, r0 - mov r3, #0x3 - lsl r3, r3, #0x10 - and r3, r4 - mov r0, #0x3 - add r2, r4, #0x0 - and r2, r0 - lsl r0, r0, #0x8 - and r0, r4 - lsr r1, r0, #0x6 - mov r0, #0x3 - lsl r0, r0, #0x18 - and r0, r4 - lsr r0, r0, #0x12 - lsr r3, r3, #0xc - orr r0, r3 - orr r0, r1 - orr r0, r2 - mov r1, #0x1c - bl _u32_div_f - lsl r0, r1, #0x10 - lsr r5, r0, #0x10 - add r0, r4, #0x0 - bl GetNatureFromPersonality - cmp r7, r0 - bne _02066DF4 - ldr r0, [sp, #0x14] - add r1, r4, #0x0 - bl GetGenderBySpeciesAndPersonality - cmp r6, r0 - bne _02066DF4 - ldr r0, [sp, #0x20] - cmp r5, r0 - bne _02066DF4 - b _02066E58 -_02066E4C: - ldr r0, [sp, #0x14] - add r1, r6, #0x0 - add r2, r7, #0x0 - bl AdjustPersonalityToForceGenderAndNature - add r4, r0, #0x0 -_02066E58: - mov r0, #0x1 - str r0, [sp, #0x0] - str r4, [sp, #0x4] - mov r0, #0x0 - str r0, [sp, #0x8] - str r0, [sp, #0xc] - ldr r0, [sp, #0x10] - ldr r1, [sp, #0x14] - ldr r2, [sp, #0x18] - ldr r3, [sp, #0x1c] - bl CreateMon - add sp, #0x24 - pop {r4-r7, pc} - - thumb_func_start AdjustPersonalityToForceGenderAndNature -AdjustPersonalityToForceGenderAndNature: ; 0x02066E74 - push {r3-r5, lr} - add r5, r1, #0x0 - mov r1, #0x12 - add r4, r2, #0x0 - bl GetMonBaseStat - lsl r0, r0, #0x18 - lsr r0, r0, #0x18 - beq _02066EA0 - cmp r0, #0xfe - beq _02066EA0 - cmp r0, #0xff - beq _02066EA0 - cmp r5, #0x0 - bne _02066EA0 - mov r1, #0x19 - bl _s32_div_f - add r1, r0, #0x1 - mov r0, #0x19 - mul r0, r1 - add r4, r0, r4 -_02066EA0: - add r0, r4, #0x0 - pop {r3-r5, pc} - thumb_func_start CreateMonWithFixedIVs CreateMonWithFixedIVs: ; 0x02066EA4 push {r0-r3} @@ -681,15 +135,15 @@ CreateMonWithFixedIVs: ; 0x02066EA4 add r2, sp, #0x24 bl SetMonDataEncrypted add r0, r4, #0x0 - bl UpdateMonLevelAndRecalcStats + bl CalcMonStats add sp, #0x10 pop {r4} pop {r3} add sp, #0x10 bx r3 - thumb_func_start UpdateMonLevelAndRecalcStats -UpdateMonLevelAndRecalcStats: ; 0x02066ED8 + thumb_func_start CalcMonStats +CalcMonStats: ; 0x02066ED8 push {r3-r5, lr} add r5, r0, #0x0 bl TryDecryptMon @@ -6641,7 +6095,7 @@ _02069A8E: add r2, sp, #0x4 bl SetMonDataEncrypted add r0, r4, #0x0 - bl UpdateMonLevelAndRecalcStats + bl CalcMonStats add sp, #0x1c pop {r4-r5, pc} diff --git a/arm9/asm/scrcmd.s b/arm9/asm/scrcmd.s index 275875f4..09f2b266 100644 --- a/arm9/asm/scrcmd.s +++ b/arm9/asm/scrcmd.s @@ -10729,7 +10729,7 @@ _0203EF18: add r2, sp, #0x4 bl SetMonDataEncrypted add r0, r4, #0x0 - bl UpdateMonLevelAndRecalcStats + bl CalcMonStats add r0, r7, #0x0 add r1, r4, #0x0 bl FUN_02024AF0 diff --git a/arm9/asm/scrcmd_12.s b/arm9/asm/scrcmd_12.s index 37665648..d326b254 100644 --- a/arm9/asm/scrcmd_12.s +++ b/arm9/asm/scrcmd_12.s @@ -653,7 +653,7 @@ _0204322C: mov r2, #0x4 bl FUN_0208089C add r0, r4, #0x0 - bl UpdateMonLevelAndRecalcStats + bl CalcMonStats ldr r0, [sp, #0x4] ldr r0, [r0, #0xc] bl FUN_0206BB1C diff --git a/arm9/asm/unk_020476CC.s b/arm9/asm/unk_020476CC.s index dce3e575..24d4a9b4 100644 --- a/arm9/asm/unk_020476CC.s +++ b/arm9/asm/unk_020476CC.s @@ -684,7 +684,7 @@ _02047C40: add r2, sp, #0x18 bl SetMonDataEncrypted add r0, r5, #0x0 - bl UpdateMonLevelAndRecalcStats + bl CalcMonStats _02047C82: add r0, r6, #0x0 add r1, r5, #0x0 diff --git a/arm9/asm/unk_0206C700.s b/arm9/asm/unk_0206C700.s index 561ba6c3..506fbef0 100644 --- a/arm9/asm/unk_0206C700.s +++ b/arm9/asm/unk_0206C700.s @@ -1044,7 +1044,7 @@ _0206CF7E: ldr r0, [r4, #0x28] bl FUN_0206A1C4 ldr r0, [r4, #0x28] - bl UpdateMonLevelAndRecalcStats + bl CalcMonStats ldr r0, [r4, #0x28] bl FUN_020690E4 add r2, r0, #0x0 @@ -2192,7 +2192,7 @@ _0206D8EA: add r0, r5, #0x0 bl FUN_0206A1C4 add r0, r5, #0x0 - bl UpdateMonLevelAndRecalcStats + bl CalcMonStats ldr r0, [r4, #0x24] add r1, r5, #0x0 bl FUN_0206B900 @@ -2583,7 +2583,7 @@ FUN_0206DC80: ; 0x0206DC80 add r2, #0x62 bl SetMonDataEncrypted add r0, r5, #0x0 - bl UpdateMonLevelAndRecalcStats + bl CalcMonStats add r0, sp, #0x10 add r1, r5, #0x0 mov r2, #0x2 diff --git a/arm9/asm/unk_020828BC.s b/arm9/asm/unk_020828BC.s index d3c740aa..8a04ec14 100644 --- a/arm9/asm/unk_020828BC.s +++ b/arm9/asm/unk_020828BC.s @@ -765,7 +765,7 @@ FUN_02082D60: ; 0x02082D60 lsl r1, r1, #0x18 lsr r1, r1, #0x18 mov r2, #0x0 - bl AdjustPersonalityToForceGenderAndNature + bl GenPersonalityByGenderAndNature mov r1, #0x1 str r1, [sp, #0x0] str r0, [sp, #0x4] diff --git a/arm9/asm/unk_020842DC.s b/arm9/asm/unk_020842DC.s index 17aec9b7..15ec2abe 100644 --- a/arm9/asm/unk_020842DC.s +++ b/arm9/asm/unk_020842DC.s @@ -803,7 +803,7 @@ _0208495C: mov r1, #0x8 bl AddMonPartyStatEncrypted add r0, r5, #0x0 - bl UpdateMonLevelAndRecalcStats + bl CalcMonStats ldr r0, [sp, #0x50] cmp r0, #0x0 bne _020849B0 @@ -987,7 +987,7 @@ _02084A66: add r2, sp, #0x50 bl SetMonDataEncrypted add r0, r5, #0x0 - bl UpdateMonLevelAndRecalcStats + bl CalcMonStats mov r6, #0x1 _02084B18: ldr r0, [sp, #0x6c] @@ -1032,7 +1032,7 @@ _02084B20: add r2, sp, #0x54 bl SetMonDataEncrypted add r0, r5, #0x0 - bl UpdateMonLevelAndRecalcStats + bl CalcMonStats mov r6, #0x1 _02084B78: ldr r0, [sp, #0x6c] @@ -1077,7 +1077,7 @@ _02084B80: add r2, sp, #0x58 bl SetMonDataEncrypted add r0, r5, #0x0 - bl UpdateMonLevelAndRecalcStats + bl CalcMonStats mov r6, #0x1 _02084BD8: ldr r0, [sp, #0x6c] @@ -1122,7 +1122,7 @@ _02084BE0: add r2, sp, #0x5c bl SetMonDataEncrypted add r0, r5, #0x0 - bl UpdateMonLevelAndRecalcStats + bl CalcMonStats mov r6, #0x1 _02084C38: ldr r0, [sp, #0x6c] @@ -1167,7 +1167,7 @@ _02084C40: add r2, sp, #0x60 bl SetMonDataEncrypted add r0, r5, #0x0 - bl UpdateMonLevelAndRecalcStats + bl CalcMonStats mov r6, #0x1 _02084C98: ldr r0, [sp, #0x6c] @@ -1212,7 +1212,7 @@ _02084CA0: add r2, sp, #0x64 bl SetMonDataEncrypted add r0, r5, #0x0 - bl UpdateMonLevelAndRecalcStats + bl CalcMonStats mov r6, #0x1 _02084CF8: ldr r0, [sp, #0x6c] diff --git a/arm9/global.inc b/arm9/global.inc index 28f325a6..04644f92 100644 --- a/arm9/global.inc +++ b/arm9/global.inc @@ -4714,10 +4714,10 @@ .extern TryEncryptBoxMon
.extern CreateMon
.extern CreateMonWithNature
-.extern CreateMonWithNatureGenderLetter
-.extern AdjustPersonalityToForceGenderAndNature
+.extern CreateMonWithGenderNatureLetter
+.extern GenPersonalityByGenderAndNature
.extern CreateMonWithFixedIVs
-.extern UpdateMonLevelAndRecalcStats
+.extern CalcMonStats
.extern CalcMonStatsMaybeEncrypted
.extern GetMonDataEncrypted
.extern GetBoxMonDataEncrypted
diff --git a/arm9/modules/05/asm/module_05.s b/arm9/modules/05/asm/module_05.s index 0dba71bb..9a62ca73 100644 --- a/arm9/modules/05/asm/module_05.s +++ b/arm9/modules/05/asm/module_05.s @@ -43275,7 +43275,7 @@ _021EC64E: blt _021EC616 _021EC658: add r0, r5, #0 - bl UpdateMonLevelAndRecalcStats + bl CalcMonStats add sp, #0xc pop {r4, r5, r6, r7, pc} nop @@ -45678,7 +45678,7 @@ MOD05_021ED940: ; 0x021ED940 add r2, sp, #0 bl SetMonDataEncrypted add r0, r4, #0 - bl UpdateMonLevelAndRecalcStats + bl CalcMonStats add sp, #0x1c pop {r4, r5, pc} .balign 4, 0 diff --git a/arm9/modules/06/asm/module_06.s b/arm9/modules/06/asm/module_06.s index bb887c23..c4c4559d 100644 --- a/arm9/modules/06/asm/module_06.s +++ b/arm9/modules/06/asm/module_06.s @@ -6748,7 +6748,7 @@ _0223C9E4: add r0, r4, #0 add r1, r7, #0 mov r3, #0x20 - bl CreateMonWithNatureGenderLetter + bl CreateMonWithGenderNatureLetter add r0, r4, #0 mov r1, #7 add r2, r5, #0 @@ -22071,7 +22071,7 @@ _02244508: add r2, r6, #0 bl SetMonDataEncrypted add r0, r5, #0 - bl UpdateMonLevelAndRecalcStats + bl CalcMonStats add sp, #0x10 pop {r3, r4, r5, r6, r7, pc} nop @@ -22172,7 +22172,7 @@ _022445A6: add r2, sp, #8 bl SetMonDataEncrypted add r0, r4, #0 - bl UpdateMonLevelAndRecalcStats + bl CalcMonStats _022445E8: add r0, r7, #0 add r1, r4, #0 @@ -31213,7 +31213,7 @@ MOD06_022489D4: ; 0x022489D4 mov r2, #1 bl FUN_0208089C add r0, r5, #0 - bl UpdateMonLevelAndRecalcStats + bl CalcMonStats add r0, r5, #0 bl MonIsShiny cmp r0, #0 diff --git a/arm9/modules/67/asm/module_67.s b/arm9/modules/67/asm/module_67.s index 7d7666f9..03dbe420 100644 --- a/arm9/modules/67/asm/module_67.s +++ b/arm9/modules/67/asm/module_67.s @@ -3307,7 +3307,7 @@ MOD67_021D8F00: ; 0x021D8F00 add r1, r7, #0 mov r2, #1 mov r3, #0x20 - bl CreateMonWithNatureGenderLetter + bl CreateMonWithGenderNatureLetter add r0, r6, #0 bl FUN_020690E4 add r2, r0, #0 diff --git a/arm9/src/pokemon.c b/arm9/src/pokemon.c index 60381e75..c59cfe4e 100644 --- a/arm9/src/pokemon.c +++ b/arm9/src/pokemon.c @@ -3,12 +3,15 @@ #include "pokemon.h" #include "heap.h" #include "MI_memory.h" +#include "math_util.h" #pragma thumb on void MonEncryptSegment(void * datap, u32 size, u32 key, ...); void MonDecryptSegment(void * datap, u32 size, u32 key, ...); u16 MonEncryptionLCRNG(u32 * seed); +u16 CalcMonChecksum(void * datap, u32 size); +void InitBoxMonMoveset(struct BoxPokemon * boxmon); #define ENCRY_ARGS_PTY(mon) &(mon)->party, sizeof((mon)->party), (mon)->box.pid #define ENCRY_ARGS_BOX(boxmon) &(boxmon)->substructs, sizeof((boxmon)->substructs), (boxmon)->checksum @@ -16,6 +19,13 @@ u16 MonEncryptionLCRNG(u32 * seed); #define ENCRYPT_BOX(boxmon) MonEncryptSegment(ENCRY_ARGS_BOX(boxmon)) #define DECRYPT_PTY(mon) MonDecryptSegment(ENCRY_ARGS_PTY(mon)) #define DECRYPT_BOX(boxmon) MonDecryptSegment(ENCRY_ARGS_BOX(boxmon)) +#define SHINY_CHECK(otid, pid) (( \ + ((((otid) & 0xFFFF0000u) >> 16u)) ^ \ + (((otid) & 0xFFFFu)) ^ \ + ((((pid) & 0xFFFF0000u) >> 16u))^ \ + (((pid) & 0xFFFFu))) \ + < 8u) +#define CALC_UNOWN_LETTER(pid) ((u32)((((pid) & 0x3000000) >> 18) | (((pid) & 0x30000) >> 12) | (((pid) & 0x300) >> 6) | (((pid) & 0x3) >> 0)) % 28u) void ZeroMonData(struct Pokemon * pokemon) { @@ -46,14 +56,204 @@ BOOL TryDecryptMon(struct Pokemon * mon) { BOOL ret = FALSE; - if (!mon->box.no_encrypt) + if (!mon->box.party_lock) { ret = TRUE; - GF_ASSERT(!mon->box.control_4_1); - mon->box.no_encrypt = TRUE; - mon->box.control_4_1 = TRUE; + GF_ASSERT(!mon->box.box_lock); + mon->box.party_lock = TRUE; + mon->box.box_lock = TRUE; DECRYPT_PTY(mon); DECRYPT_BOX(&mon->box); } return ret; } + +BOOL TryEncryptMon(struct Pokemon * mon, BOOL decrypt_result) +{ + BOOL ret = FALSE; + if (mon->box.party_lock == TRUE && decrypt_result == TRUE) + { + ret = TRUE; + mon->box.party_lock = FALSE; + mon->box.box_lock = FALSE; + ENCRYPT_PTY(mon); + mon->box.checksum = CalcMonChecksum(&mon->box.substructs, sizeof(mon->box.substructs)); + ENCRYPT_BOX(&mon->box); + } + return ret; +} + +BOOL TryDecryptBoxMon(struct BoxPokemon * mon) +{ + BOOL ret = FALSE; + + if (!mon->box_lock) + { + ret = TRUE; + mon->box_lock = TRUE; + DECRYPT_BOX(mon); + } + return ret; +} + +BOOL TryEncryptBoxMon(struct BoxPokemon * mon, BOOL decrypt_result) +{ + BOOL ret = FALSE; + if (mon->box_lock == TRUE && decrypt_result == TRUE) + { + ret = TRUE; + mon->box_lock = FALSE; + mon->checksum = CalcMonChecksum(&mon->substructs, sizeof(mon->substructs)); + ENCRYPT_BOX(mon); + } + return ret; +} + +void CreateMon(struct Pokemon * pokemon, int species, int level, int fixedIV, int hasFixedPersonality, int fixedPersonality, int otIdType, int fixedOtId, ...) +{ + struct SealStruct * seal; + u32 capsule; + u8 seal_coords[0x18]; + ZeroMonData(pokemon); + CreateBoxMon(&pokemon->box, species, level, fixedIV, hasFixedPersonality, fixedPersonality, otIdType, fixedOtId); + // Not your average encryption call + MonEncryptSegment(&pokemon->party, sizeof(pokemon->party), 0); + ENCRYPT_PTY(pokemon); + SetMonDataEncrypted(pokemon, MON_DATA_LEVEL, &level); + seal = CreateNewSealsObject(0); + SetMonDataEncrypted(pokemon, MON_DATA_SEAL_STRUCT, seal); + FreeToHeap(seal); + capsule = 0; + SetMonDataEncrypted(pokemon, MON_DATA_CAPSULE, &capsule); + MIi_CpuClearFast(0, seal_coords, sizeof(seal_coords)); + SetMonDataEncrypted(pokemon, MON_DATA_SEAL_COORDS, seal_coords); + CalcMonStats(pokemon); +} + +void CreateBoxMon(struct BoxPokemon * boxPokemon, int species, int level, int fixedIV, int hasFixedPersonality, int fixedPersonality, int otIdType, int fixedOtId, ...) +{ + BOOL decry; + u32 exp; + u32 iv; + ZeroBoxMonData(boxPokemon); + decry = TryDecryptBoxMon(boxPokemon); + if (hasFixedPersonality == 0) + { + fixedPersonality = (rand_LC() | (rand_LC() << 16)); + } + SetBoxMonDataEncrypted(boxPokemon, MON_DATA_PERSONALITY, &fixedPersonality); + if (otIdType == 2) + { + do + { + fixedOtId = (rand_LC() | (rand_LC() << 16)); + } while (SHINY_CHECK(fixedOtId, fixedPersonality)); + } + else if (otIdType != 1) + fixedOtId = 0; + SetBoxMonDataEncrypted(boxPokemon, MON_DATA_OTID, &fixedOtId); + SetBoxMonDataEncrypted(boxPokemon, MON_DATA_GAME_LANGUAGE, &gGameLanguage); + SetBoxMonDataEncrypted(boxPokemon, MON_DATA_SPECIES, &species); + SetBoxMonDataEncrypted(boxPokemon, MON_DATA_SPECIES_NAME, NULL); + exp = GetMonExpBySpeciesAndLevel(species, level); + SetBoxMonDataEncrypted(boxPokemon, MON_DATA_EXPERIENCE, &exp); + exp = GetMonBaseStat(species, BASE_FRIENDSHIP); + SetBoxMonDataEncrypted(boxPokemon, MON_DATA_FRIENDSHIP, &exp); + SetBoxMonDataEncrypted(boxPokemon, MON_DATA_MET_LEVEL, &level); + SetBoxMonDataEncrypted(boxPokemon, MON_DATA_GAME_VERSION, &gGameVersion); + exp = 4; + SetBoxMonDataEncrypted(boxPokemon, MON_DATA_POKEBALL, &exp); + if (fixedIV < 0x20) + { + SetBoxMonDataEncrypted(boxPokemon, MON_DATA_HP_IV, &fixedIV); + SetBoxMonDataEncrypted(boxPokemon, MON_DATA_ATK_IV, &fixedIV); + SetBoxMonDataEncrypted(boxPokemon, MON_DATA_DEF_IV, &fixedIV); + SetBoxMonDataEncrypted(boxPokemon, MON_DATA_SPEED_IV, &fixedIV); + SetBoxMonDataEncrypted(boxPokemon, MON_DATA_SPATK_IV, &fixedIV); + SetBoxMonDataEncrypted(boxPokemon, MON_DATA_SPDEF_IV, &fixedIV); + } + else + { + exp = rand_LC(); + iv = exp & 0x1F; + SetBoxMonDataEncrypted(boxPokemon, MON_DATA_HP_IV, &iv); + iv = (exp & 0x3E0) >> 5; + SetBoxMonDataEncrypted(boxPokemon, MON_DATA_ATK_IV, &iv); + iv = (exp & 0x7C00) >> 10; + SetBoxMonDataEncrypted(boxPokemon, MON_DATA_DEF_IV, &iv); + exp = rand_LC(); + iv = exp & 0x1F; + SetBoxMonDataEncrypted(boxPokemon, MON_DATA_SPEED_IV, &iv); + iv = (exp & 0x3E0) >> 5; + SetBoxMonDataEncrypted(boxPokemon, MON_DATA_SPATK_IV, &iv); + iv = (exp & 0x7C00) >> 10; + SetBoxMonDataEncrypted(boxPokemon, MON_DATA_SPDEF_IV, &iv); + } + exp = GetMonBaseStat(species, BASE_ABILITY_1); + iv = GetMonBaseStat(species, BASE_ABILITY_2); + if (iv != 0) + { + if (fixedPersonality & 1) + SetBoxMonDataEncrypted(boxPokemon, MON_DATA_ABILITY, &iv); + else + SetBoxMonDataEncrypted(boxPokemon, MON_DATA_ABILITY, &exp); + } + else + SetBoxMonDataEncrypted(boxPokemon, MON_DATA_ABILITY, &exp); + exp = GetBoxMonGenderEncrypted(boxPokemon); + SetBoxMonDataEncrypted(boxPokemon, MON_DATA_GENDER, &exp); + InitBoxMonMoveset(boxPokemon); + TryEncryptBoxMon(boxPokemon, decry); +} + +void CreateMonWithNature(struct Pokemon * pokemon, u16 species, u8 level, u8 fixedIv, u8 nature) +{ + u32 personality; + do + { + personality = (u32)(rand_LC() | (rand_LC() << 16)); + } while (nature != GetNatureFromPersonality(personality)); + CreateMon(pokemon, (int)species, (int)level, (int)fixedIv, 1, (int)personality, (int)0, (int)0); +} + +// FIXME: stack storage of pokemon, fixedIv swapped +void CreateMonWithGenderNatureLetter(struct Pokemon * pokemon, u16 species, u8 level, u8 fixedIv, u8 gender, u8 nature, u8 letter) +{ + u32 pid = 0; + u16 test = 0; + if (letter != 0 && letter < 29) + { + do { + pid = (u32)(rand_LC() | (rand_LC() << 16)); + test = (u16)CALC_UNOWN_LETTER(pid); + } while (nature != GetNatureFromPersonality(pid) || gender != GetGenderBySpeciesAndPersonality(species, pid) || test != letter - 1); + } + else + { + pid = GenPersonalityByGenderAndNature(species, gender, nature); + } + CreateMon(pokemon, (int)species, (int)level, (int)fixedIv, 1, (int)pid, 0, 0); +} + +u32 GenPersonalityByGenderAndNature(u16 species, u8 gender, u8 nature) +{ + int pid = nature; + u8 ratio = (u8)GetMonBaseStat(species, BASE_GENDER_RATIO); + switch (ratio) + { + case MON_RATIO_MALE: + case MON_RATIO_FEMALE: + case MON_RATIO_UNKNOWN: + break; + default: + if (gender == MON_MALE) + { + // Smallest increment that forces the low byte to exceed the + // gender ratio, thus making the mon male + pid = 25 * ((ratio / 25) + 1); + pid += nature; + } + break; + } + return (u32)pid; +} diff --git a/include/global.h b/include/global.h index bffce9f0..35d0c3aa 100644 --- a/include/global.h +++ b/include/global.h @@ -29,4 +29,7 @@ extern void ErrorHandling(void); #define GF_ASSERT(expr) do {if (!(expr)) ErrorHandling();} while (0) +extern const enum GameLanguage gGameLanguage; +extern const enum GameVersion gGameVersion; + #endif //GUARD_GLOBAL_H diff --git a/include/math_util.h b/include/math_util.h new file mode 100644 index 00000000..f7169956 --- /dev/null +++ b/include/math_util.h @@ -0,0 +1,6 @@ +#ifndef POKEDIAMOND_MATH_UTIL_H +#define POKEDIAMOND_MATH_UTIL_H + +u16 rand_LC(void); + +#endif //POKEDIAMOND_MATH_UTIL_H diff --git a/include/pokemon.h b/include/pokemon.h index 410e4bc5..d5ab1fd9 100644 --- a/include/pokemon.h +++ b/include/pokemon.h @@ -6,6 +6,7 @@ // Enums #include "constants/species.h" +#include "seals.h" #define MON_DATA_PERSONALITY 0 #define MON_DATA_IS_ENCRYPTED 1 @@ -110,9 +111,16 @@ #define MON_DATA_TYPE_2 177 #define MON_DATA_SPECIES_NAME 178 -#define MON_MALE 0 -#define MON_FEMALE 254 -#define MON_GENDER_UNKNOWN 255 +#define MON_RATIO_MALE 0 +#define MON_RATIO_FEMALE 254 +#define MON_RATIO_UNKNOWN 255 + +enum MonGender +{ + MON_MALE = 0, + MON_FEMALE = 1, + MON_GENDERLESS = 2 +}; // TODO: Identify the rest of these enum BaseStat { @@ -136,7 +144,7 @@ enum BaseStat { BASE_ITEM_2, BASE_GENDER_RATIO, BASE_EGG_CYCLES, - BASE_FIRENDSHIP, + BASE_FRIENDSHIP, BASE_GROWTH_RATE, BASE_EGG_GROUP_1, GASE_EGG_GROUP_2, @@ -346,8 +354,8 @@ typedef union { struct BoxPokemon { /* 0x000 */ u32 pid; - /* 0x004 */ u16 no_encrypt:1; - u16 control_4_1:1; + /* 0x004 */ u16 party_lock:1; + u16 box_lock:1; u16 control_4_2:1; u16 Unused:13; // Might be used for validity checks /* 0x006 */ u16 checksum; // Stored checksum of pokemon @@ -373,7 +381,7 @@ struct PartyPokemon /* 0x096 */ u16 speed; /* 0x098 */ u16 spatk; /* 0x09A */ u16 spdef; - /* 0x09C */ u8 seal_something[0x38]; // a struct? + /* 0x09C */ struct SealStruct seal_something; // a struct? /* 0x0D4 */ u8 sealCoords[0x18]; // u8 pairs? }; @@ -387,15 +395,24 @@ void ZeroBoxMonData(struct BoxPokemon * boxmon); u32 SizeOfStructPokemon(void); struct Pokemon * AllocMonZeroed(u32 heap_id); BOOL TryDecryptMon(struct Pokemon * mon); -int GetMonBaseStat_HandleFormeConversion(int species, int form, int stat_id); -int GetMonBaseStat(int species, int stat_id); -int GetMonExpBySpeciesAndLevel(int species, int level); +BOOL TryEncryptMon(struct Pokemon * mon, BOOL decrypt_result); +BOOL TryDecryptBoxMon(struct BoxPokemon * mon); +BOOL TryEncryptBoxMon(struct BoxPokemon * mon, BOOL decrypt_result); +void CreateMon(struct Pokemon * pokemon, int species, int level, int fixedIV, int hasFixedPersonality, int fixedPersonality, int otIdType, int fixedOtId, ...); +void CreateBoxMon(struct BoxPokemon * boxPokemon, int species, int level, int fixedIV, int hasFixedPersonality, int fixedPersonality, int otIdType, int fixedOtId, ...); +void CreateMonWithNature(struct Pokemon * pokemon, u16 species, u8 level, u8 fixedIv, u8 nature); +void CreateMonWithGenderNatureLetter(struct Pokemon * pokemon, u16 species, u8 level, u8 fixedIv, u8 gender, u8 nature, u8 letter); +u8 GetNatureFromPersonality(u32 pid); +u8 GetGenderBySpeciesAndPersonality(u16 species, u32 pid); +u32 GenPersonalityByGenderAndNature(u16 species, u8 gender, u8 nature); +void CalcMonStats(struct Pokemon * pokemon); +u32 GetBoxMonGenderEncrypted(struct BoxPokemon * boxmon); +int GetMonBaseStat_HandleFormeConversion(int species, int form, enum BaseStat stat_id); +u32 GetMonBaseStat(int species, enum BaseStat stat_id); +u32 GetMonExpBySpeciesAndLevel(int species, int level); void LoadGrowthTable(int species, int * table); int GetExpByGrowthRateAndLevel(int rate, int level); int CalcLevelBySpeciesAndExp(int species, int experience); -void CreateMon(struct Pokemon * pokemon, u16 species, u8 level, u8 fixedIV, u8 hasFixedPersonality, u32 fixedPersonality, u8 otIdType, u32 fixedOtId, ...); -void CreateBoxMon(struct BoxPokemon * boxPokemon, u16 species, u8 level, u8 fixedIV, u8 hasFixedPersonality, u32 fixedPersonality, u8 otIdType, u32 fixedOtId, ...); -void CreateMonWithNatureGenderLetter(struct Pokemon * pokemon, u16 species, u8 level, u8 nature, u8 gender, u8 letter); #ifndef IN_POKEMON_C u32 GetMonData(); @@ -408,8 +425,10 @@ u32 GetMonDataEncrypted(struct Pokemon * pokemon, u32 attr, void * ptr); u32 GetBoxMonData(struct BoxPokemon * pokemon, u32 attr, void * ptr); u32 GetBoxMonDataEncrypted(struct BoxPokemon * pokemon, u32 attr, void * ptr); #endif -void SetMonData(struct Pokemon * pokemon, u32 attr, void * ptr); -void SetBoxMonData(struct BoxPokemon * pokemon, u32 attr, void * ptr); +void SetMonData(struct Pokemon * pokemon, u32 attr, const void * ptr); +void SetMonDataEncrypted(struct Pokemon * pokemon, u32 attr, const void * ptr); +void SetBoxMonData(struct BoxPokemon * pokemon, u32 attr, const void * ptr); +void SetBoxMonDataEncrypted(struct BoxPokemon * pokemon, u32 attr, const void * ptr); void AddMonData(struct Pokemon * pokemon, u32 attr, u32 amount); void AddBoxMonData(struct Pokemon * pokemon, u32 attr, u32 amount); diff --git a/include/seals.h b/include/seals.h new file mode 100644 index 00000000..89808176 --- /dev/null +++ b/include/seals.h @@ -0,0 +1,12 @@ +#ifndef POKEDIAMOND_SEALS_H +#define POKEDIAMOND_SEALS_H + +struct SealStruct +{ + // TODO: define + u8 filler_00[0x38]; +}; + +struct SealStruct * CreateNewSealsObject(u32 heap_id); + +#endif //POKEDIAMOND_SEALS_H |