Thread: RNG Research
View Single Post
Old Aug 23rd, 2012, 2:45:46 PM   #956
Bond697
Dies, died, will die.
is a Pokémon Researcher
 
Bond697's Avatar
 
Join Date: Jun 2010
Posts: 302
Default

so this morning chiizu was asking me about a function in the breeding module that has to do with checking for a ditto then advancing the rng once if one exists. i hadn't had time yet, so i put a copy on pastebin for him(and a copy of the dwAbil function) and fired up ida and we went to work.

turns out that the game checks the ability of the ditto(or mother) and if it's ability 0, the baby has an 80% chance of abil 0, if abil 1 an 80% chance of abil 1, and if it's the dw abil, the percentages become 20/20/60 leaning towards the dw abil.

Code:
RAM_OVL36:021BD6D8             ; =============== S U B R O U T I N E =======================================
RAM_OVL36:021BD6D8
RAM_OVL36:021BD6D8
RAM_OVL36:021BD6D8             abilDecision                            ; CODE XREF: breedingSetup+130p
RAM_OVL36:021BD6D8 70 B5       PUSH    {R4-R6,LR}
RAM_OVL36:021BD6DA 40 68       LDR     R0, [R0,#4]
RAM_OVL36:021BD6DC 1C 1C       MOVS    R4, R3
RAM_OVL36:021BD6DE 0D 1C       MOVS    R5, R1
RAM_OVL36:021BD6E0 5F F6 2A FC BL      getParentAbil
RAM_OVL36:021BD6E4 06 1C       MOVS    R6, R0
RAM_OVL36:021BD6E6 A0 68       LDR     R0, [R4,#8]                     ; num1
RAM_OVL36:021BD6E8 E1 68       LDR     R1, [R4,#0xC]
RAM_OVL36:021BD6EA 22 68       LDR     R2, [R4]                        ; num2
RAM_OVL36:021BD6EC 63 68       LDR     R3, [R4,#4]
RAM_OVL36:021BD6EE CF F6 14 EE BLX     mul64
RAM_OVL36:021BD6F2 22 69       LDR     R2, [R4,#0x10]
RAM_OVL36:021BD6F4 63 69       LDR     R3, [R4,#0x14]
RAM_OVL36:021BD6F6 10 18       ADDS    R0, R2, R0
RAM_OVL36:021BD6F8 4B 41       ADCS    R3, R1
RAM_OVL36:021BD6FA 20 60       STR     R0, [R4]
RAM_OVL36:021BD6FC 63 60       STR     R3, [R4,#4]
RAM_OVL36:021BD6FE 18 1C       MOVS    R0, R3                          ; num1
RAM_OVL36:021BD700 00 21       MOVS    R1, #0
RAM_OVL36:021BD702 64 22       MOVS    R2, #0x64 ; 'd'                 ; num2
RAM_OVL36:021BD704 00 23       MOVS    R3, #0
RAM_OVL36:021BD706 00 24       MOVS    R4, #0
RAM_OVL36:021BD708 CF F6 06 EE BLX     mul64
RAM_OVL36:021BD70C 00 2E       CMP     R6, #0
RAM_OVL36:021BD70E 03 D0       BEQ     loc_21BD718
RAM_OVL36:021BD710 01 2E       CMP     R6, #1
RAM_OVL36:021BD712 09 D0       BEQ     loc_21BD728
RAM_OVL36:021BD714 02 2E       CMP     R6, #2
RAM_OVL36:021BD716 0E D0       BEQ     loc_21BD736
RAM_OVL36:021BD718
RAM_OVL36:021BD718             loc_21BD718                             ; CODE XREF: abilDecision+36j
RAM_OVL36:021BD718 50 29       CMP     R1, #0x50 ; 'P'
RAM_OVL36:021BD71A 02 D2       BCS     loc_21BD722
RAM_OVL36:021BD71C 00 20       MOVS    R0, #0
RAM_OVL36:021BD71E A8 64       STR     R0, [R5,#0x48]
RAM_OVL36:021BD720 70 BD       POP     {R4-R6,PC}
RAM_OVL36:021BD722             ; ---------------------------------------------------------------------------
RAM_OVL36:021BD722
RAM_OVL36:021BD722             loc_21BD722                             ; CODE XREF: abilDecision+42j
RAM_OVL36:021BD722 01 20       MOVS    R0, #1
RAM_OVL36:021BD724 A8 64       STR     R0, [R5,#0x48]
RAM_OVL36:021BD726 70 BD       POP     {R4-R6,PC}
RAM_OVL36:021BD728             ; ---------------------------------------------------------------------------
RAM_OVL36:021BD728
RAM_OVL36:021BD728             loc_21BD728                             ; CODE XREF: abilDecision+3Aj
RAM_OVL36:021BD728 14 29       CMP     R1, #0x14
RAM_OVL36:021BD72A 01 D2       BCS     loc_21BD730
RAM_OVL36:021BD72C AC 64       STR     R4, [R5,#0x48]
RAM_OVL36:021BD72E 70 BD       POP     {R4-R6,PC}
RAM_OVL36:021BD730             ; ---------------------------------------------------------------------------
RAM_OVL36:021BD730
RAM_OVL36:021BD730             loc_21BD730                             ; CODE XREF: abilDecision+52j
RAM_OVL36:021BD730 01 20       MOVS    R0, #1
RAM_OVL36:021BD732 A8 64       STR     R0, [R5,#0x48]
RAM_OVL36:021BD734 70 BD       POP     {R4-R6,PC}
RAM_OVL36:021BD736             ; ---------------------------------------------------------------------------
RAM_OVL36:021BD736
RAM_OVL36:021BD736             loc_21BD736                             ; CODE XREF: abilDecision+3Ej
RAM_OVL36:021BD736 14 29       CMP     R1, #0x14
RAM_OVL36:021BD738 01 D2       BCS     loc_21BD73E
RAM_OVL36:021BD73A AC 64       STR     R4, [R5,#0x48]
RAM_OVL36:021BD73C 70 BD       POP     {R4-R6,PC}
RAM_OVL36:021BD73E             ; ---------------------------------------------------------------------------
RAM_OVL36:021BD73E
RAM_OVL36:021BD73E             loc_21BD73E                             ; CODE XREF: abilDecision+60j
RAM_OVL36:021BD73E 28 29       CMP     R1, #0x28 ; '('
RAM_OVL36:021BD740 02 D2       BCS     loc_21BD748
RAM_OVL36:021BD742 01 20       MOVS    R0, #1
RAM_OVL36:021BD744 A8 64       STR     R0, [R5,#0x48]
RAM_OVL36:021BD746 70 BD       POP     {R4-R6,PC}
RAM_OVL36:021BD748             ; ---------------------------------------------------------------------------
RAM_OVL36:021BD748
RAM_OVL36:021BD748             loc_21BD748                             ; CODE XREF: abilDecision+68j
RAM_OVL36:021BD748 02 20       MOVS    R0, #2
RAM_OVL36:021BD74A A8 64       STR     R0, [R5,#0x48]
RAM_OVL36:021BD74C 70 BD       POP     {R4-R6,PC}
RAM_OVL36:021BD74C             ; End of function abilDecision

here's where it gets sort of interesting. if you have a ditto, the previous function still runs. however, right after it another function runs that checks if you have a ditto. if you do have one, it advances the rng and does u32 >> 31 and stores the result of that calculation as the ability. this limits ditto-based breeding to abil 0/1.


Code:
RAM_OVL36:021BD750             ; =============== S U B R O U T I N E =======================================
RAM_OVL36:021BD750
RAM_OVL36:021BD750
RAM_OVL36:021BD750             dittoAbilFix                            ; CODE XREF: breedingSetup+13Ap
RAM_OVL36:021BD750 F8 B5       PUSH    {R3-R7,LR}
RAM_OVL36:021BD752 05 1C       MOVS    R5, R0
RAM_OVL36:021BD754 28 68       LDR     R0, [R5]
RAM_OVL36:021BD756 0E 1C       MOVS    R6, R1
RAM_OVL36:021BD758 14 1C       MOVS    R4, R2
RAM_OVL36:021BD75A 05 21       MOVS    R1, #5
RAM_OVL36:021BD75C 00 22       MOVS    R2, #0
RAM_OVL36:021BD75E 5F F6 BF FA BL      getPKMStat
RAM_OVL36:021BD762 07 1C       MOVS    R7, R0
RAM_OVL36:021BD764 68 68       LDR     R0, [R5,#4]
RAM_OVL36:021BD766 05 21       MOVS    R1, #5
RAM_OVL36:021BD768 00 22       MOVS    R2, #0
RAM_OVL36:021BD76A 5F F6 B9 FA BL      getPKMStat
RAM_OVL36:021BD76E 84 2F       CMP     R7, #0x84 ; '¦'
RAM_OVL36:021BD770 01 D0       BEQ     loc_21BD776
RAM_OVL36:021BD772 84 28       CMP     R0, #0x84 ; '¦'
RAM_OVL36:021BD774 15 D1       BNE     locret_21BD7A2
RAM_OVL36:021BD776
RAM_OVL36:021BD776             loc_21BD776                             ; CODE XREF: dittoAbilFix+20j
RAM_OVL36:021BD776 A0 68       LDR     R0, [R4,#8]                     ; num1
RAM_OVL36:021BD778 E1 68       LDR     R1, [R4,#0xC]
RAM_OVL36:021BD77A 22 68       LDR     R2, [R4]                        ; num2
RAM_OVL36:021BD77C 63 68       LDR     R3, [R4,#4]
RAM_OVL36:021BD77E CF F6 CC ED BLX     mul64
RAM_OVL36:021BD782 22 69       LDR     R2, [R4,#0x10]
RAM_OVL36:021BD784 63 69       LDR     R3, [R4,#0x14]
RAM_OVL36:021BD786 10 18       ADDS    R0, R2, R0
RAM_OVL36:021BD788 4B 41       ADCS    R3, R1
RAM_OVL36:021BD78A 00 21       MOVS    R1, #0
RAM_OVL36:021BD78C 20 60       STR     R0, [R4]
RAM_OVL36:021BD78E D8 0F       LSRS    R0, R3, #0x1F
RAM_OVL36:021BD790 49 00       LSLS    R1, R1, #1
RAM_OVL36:021BD792 63 60       STR     R3, [R4,#4]
RAM_OVL36:021BD794 01 43       ORRS    R1, R0
RAM_OVL36:021BD796 02 D1       BNE     loc_21BD79E
RAM_OVL36:021BD798 00 20       MOVS    R0, #0
RAM_OVL36:021BD79A B0 64       STR     R0, [R6,#0x48]
RAM_OVL36:021BD79C F8 BD       POP     {R3-R7,PC}
RAM_OVL36:021BD79E             ; ---------------------------------------------------------------------------
RAM_OVL36:021BD79E
RAM_OVL36:021BD79E             loc_21BD79E                             ; CODE XREF: dittoAbilFix+46j
RAM_OVL36:021BD79E 01 20       MOVS    R0, #1
RAM_OVL36:021BD7A0 B0 64       STR     R0, [R6,#0x48]
RAM_OVL36:021BD7A2
RAM_OVL36:021BD7A2             locret_21BD7A2                          ; CODE XREF: dittoAbilFix+24j
RAM_OVL36:021BD7A2 F8 BD       POP     {R3-R7,PC}
RAM_OVL36:021BD7A2             ; End of function dittoAbilFix

all the mul64 calls are for the inlined rng that gets used with breeding.
__________________
[12:27] <xfr> it's game freak doing it wrong as always

[14:48] <~Nexus> Pokemon has no magic after OmegaDonut ruined it with his RNG

[19:52] <~Shii> I NEED MAT'S TOUCH

Last edited by Bond697; Aug 24th, 2012 at 4:50:35 PM.
Bond697 is offline   Reply With Quote