2248D50
2248D94 Tick trigger
2248DBF
2246ee0 Base Pointer table address
2249B31 Store Rand 1 (B)
2249B32 Store Rand 2 (W)
N.B. Rand(x)=(u32*x)>>32 (result in [0,x-1])
C-Gear LCRNG advancement
Two timers alternate: short period (1 frame) / long period (2 frames)
Run as long as the C-Gear is on
--
Short Advance
rand(40)+60
--
Long Advance
rand(3)
rand(152)+60
--------------------------------------------------
MEMORY:02178010 Adv1
MEMORY:02178010 PUSH {R4,LR}
MEMORY:02178012 MOVS R4, R0
MEMORY:02178014 BL getTick @ 0x2248D50
MEMORY:02178018 CMP R0, #1
MEMORY:0217801A BNE __return
MEMORY:0217801C LDR R0, =0x2177401
MEMORY:0217801E MOVS R1, #0
MEMORY:02178020 MOVS R2, #0
MEMORY:02178022 BL loc_21785D4
MEMORY:02178026 CMP R0, #0
MEMORY:02178028 BEQ locret_2178040
MEMORY:0217802A MOVS R0, #0x28 @ '('
MEMORY:0217802C BL rand__
MEMORY:02178030 LDR R1, =0xCF2
MEMORY:02178032 ADDS R0, #0x3C @ '<'
MEMORY:02178034 STRB R0, [R4,R1] @ Store rand(0x28)+0x3C at 0x2249B32
MEMORY:02178036 LDR R0, =dword_21797C4
MEMORY:02178038 LDR R1, =0x2177FE5
MEMORY:0217803A LDR R0, [R0]
MEMORY:0217803C BL sub_217729C
--------------------------------------------------
MEMORY:02177F68 Adv2:
MEMORY:02177F68 PUSH {R3-R5,LR}
MEMORY:02177F6A MOVS R4, R0
MEMORY:02177F6C BL IsTickOne
MEMORY:02177F70 CMP R0, #0
MEMORY:02177F72 BEQ __return
MEMORY:02177F74 LDR R1, =byte_2179698
MEMORY:02177F76 ADD R0, SP, #0
MEMORY:02177F78 LDRB R2, [R1]
MEMORY:02177F7A STRB R2, [R0]
MEMORY:02177F7C LDRB R2, [R1,#(byte_2179699 - 0x2179698)]
MEMORY:02177F7E STRB R2, [R0,#1]
MEMORY:02177F80 LDRB R1, [R1,#(byte_217969A - 0x2179698)]
MEMORY:02177F82 STRB R1, [R0,#2]
MEMORY:02177F84 MOVS R0, #3
MEMORY:02177F86 BL rand__
MEMORY:02177F8A LDR R1, =0xCF1
MEMORY:02177F8C STRB R0, [R4,R1] @ Store rand(3) at 0x2249B31 (1byte)
MEMORY:02177F8E LDRB R0, [R4,R1]
MEMORY:02177F90 CMP R0, #3
MEMORY:02177F92 BCC Adv3
MEMORY:02177F94 MOVS R0, #0
MEMORY:02177F96 STRB R0, [R4,R1] @ If rolled 3 replace with 0 (why?)
--------------------------------------------------
MEMORY:02177F98 Adv3:
MEMORY:02177F98 BL loc_21777AC
MEMORY:02177F9C LDR R5, =0xC68
MEMORY:02177F9E MOVS R0, #0
MEMORY:02177FA0 MOVS R2, R5
MEMORY:02177FA2 ADDS R2, #0x89 @ 'ë'
MEMORY:02177FA4 LDRB R3, [R4,R2]
MEMORY:02177FA6 ADD R2, SP, #0
MEMORY:02177FA8 LDRH R1, [R4,R5]
MEMORY:02177FAA LDRB R2, [R2,R3]
MEMORY:02177FAC MOVS R3, #1
MEMORY:02177FAE BL unk_21792A8
MEMORY:02177FB2 CMP R0, #0
MEMORY:02177FB4 BEQ locret_2177FCC
MEMORY:02177FB6 MOVS R0, #0x98 @ 'ÿ'
MEMORY:02177FB8 BL rand__
MEMORY:02177FBC ADDS R0, #0x3C @ '<'
MEMORY:02177FBE ADDS R5, #0x8A @ 'è'
MEMORY:02177FC0 STRB R0, [R4,R5] @ Store rand(0x98)+0x3C at 0x2249B32
MEMORY:02177FC2 LDR R0, =dword_21797C4
MEMORY:02177FC4 LDR R1, =0x2177F1D
MEMORY:02177FC6 LDR R0, [R0]
MEMORY:02177FC8 BL sub_217729C
--------------------------------------------------
Loading any area of Entree Forest that contains Pokémon
will advance the RNG by 2 frames:
--------------------------------------------------
MEMORY:0217C3FA loc_217C3FA:
MEMORY:0217C3FA LSLS R7, R4, #2
MEMORY:0217C3FC LDR R0, [R6,R7]
MEMORY:0217C3FE LSLS R0, R0, #0x15
MEMORY:0217C400 LSRS R0, R0, #0x15
MEMORY:0217C402 BEQ loc_217C45C
MEMORY:0217C404 MOVS R0, #2
MEMORY:0217C406 BL rand.event__
MEMORY:0217C40A SUBS R5, R0, #1
MEMORY:0217C40C MOVS R0, #2
MEMORY:0217C40E BL rand.event__
MEMORY:0217C412 SUBS R1, R0, #1
MEMORY:0217C414 LDR R2, [SP,#0x10]
MEMORY:0217C416 LSLS R3, R4, #1
MEMORY:0217C418 LDR R0, [SP,#0x10]
MEMORY:0217C41A LDRB R2, [R2,R3]
MEMORY:0217C41C ADDS R0, R0, R3
MEMORY:0217C41E LDRB R0, [R0,#1]
MEMORY:0217C420 ADDS R3, R5, R2
MEMORY:0217C422 LDR R2, [SP,#0xC]
MEMORY:0217C424 ADDS R0, R1, R0
MEMORY:0217C426 CMP R2, R3
MEMORY:0217C428 BNE loc_217C442
MEMORY:0217C42A LDR R2, [SP,#8]
MEMORY:0217C42C CMP R2, R0
MEMORY:0217C42E BNE loc_217C442
MEMORY:0217C430 CMP R5, #0
MEMORY:0217C432 BEQ loc_217C438
MEMORY:0217C434 SUBS R3, R3, R5
MEMORY:0217C436 B loc_217C442
--------------------------------------------------
For some reason, some Pokémon like Nidoran have
static movement (not RNG based). For all purposes,
consider that they're not here. (more research needed
for exhaustive list).
When in Entralink Forest with at least one Pokémon,
the function used to move each around (@0x225249a)
consumes 2 frame: timer is (rand(4)+1)*16 (possible
values 0x10, 0x20, 0x30, 0x40) and direction is
rand(4) with 0=N, 1=S, 2=E and 3=W.
This function is also used to move NPC in overworld.
The relevant memory locations for the timers are
0x255239A+(i*0x100) (i is the NPC#) and 0x255239C
+(i*0x100) for the direction.
If the timer is shifted 16 bits to the left the
movement is static (not RNG controlled).
!!! The "Do you want <x> to join your party" dialog
will stop the NPC timer but not the main C-Gear one
!!! As soon as you interact, there is a dummy call to
makePKM that will consume the usual frames of a Pokémon
creation (6 for the PIDRNG). The call to MakePKM that is
actually used is when you press yes.
!!! The PID method for entralink is set ability, set
gender. The generated PID will have its last byte and
17th bit modified accordingly
--------------------------------------------------
MEMORY:0219A1C8 MoveNPC:
MEMORY:0219A1C8 LDRH R0, [R4]
MEMORY:0219A1CA CMP R0, #0
MEMORY:0219A1CC BNE loc_219A1FA
MEMORY:0219A1CE MOVS R1, #2
MEMORY:0219A1D0 LDRSH R0, [R4,R1]
MEMORY:0219A1D2 SUBS R0, R0, #1
MEMORY:0219A1D4 STRH R0, [R4,#2]
MEMORY:0219A1D6 LDRSH R0, [R4,R1]
MEMORY:0219A1D8 CMP R0, #0
MEMORY:0219A1DA BGT loc_219A1FA @ Skip if [0x225249a]>0
MEMORY:0219A1DC LDR R0, loc_219A204
MEMORY:0219A1DE SUBS R1, R1, #3
MEMORY:0219A1E0 BL NPCTimer
MEMORY:0219A1E4 STRH R0, [R4,#2]
MEMORY:0219A1E6 LDR R0, [R4,#4]
MEMORY:0219A1E8 MOVS R1, R6
MEMORY:0219A1EA BL NPCDirection @ Not sure what this rand(4) is used for
MEMORY:0219A1EE ADDS R1, R0, #0
--------------------------------------------------
MEMORY:0219B110 NPCTimer:
MEMORY:0219B110 PUSH {R4,LR}
MEMORY:0219B112 MOVS R4, R0
MEMORY:0219B114 BL loc_219B0F8 @ This returns 4
MEMORY:0219B118 BL rand__
MEMORY:0219B11C LSLS R0, R0, #2
MEMORY:0219B11E LDR R0, [R4,R0] @ [R4] is {0x10,0x20,0x30,0x40}
MEMORY:0219B120 POP {R4,PC}
--------------------------------------------------
MEMORY:0219B124 NPCDirection:
MEMORY:0219B124 PUSH {R3-R5,LR}
MEMORY:0219B126 MOVS R5, R1
MEMORY:0219B128 BL loc_219B140
MEMORY:0219B12C MOVS R1, R5
MEMORY:0219B12E MOVS R4, R0
MEMORY:0219B130 BL loc_219B0F8 @ This returns 4
MEMORY:0219B134 BL rand__
MEMORY:0219B138 LSLS R0, R0, #2
MEMORY:0219B13A LDR R0, [R4,R0] @ [R4] is {0,1,2,3}
MEMORY:0219B13C POP {R3-R5,PC}
--------------------------------------------------
Comments