-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNaturePIDGen.asm
More file actions
executable file
·360 lines (307 loc) · 5.41 KB
/
NaturePIDGen.asm
File metadata and controls
executable file
·360 lines (307 loc) · 5.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
.thumb
.align 2
.equ div, 0x81E4684
.equ decrypt, 0x803FBE8
.equ start, 0x8XXXXXX @Unless you have custom functions for decrypting and dividing, this offset needs to be at a range where it can "bl" div and decrypt. I just replaced some vanilla text with the routine.
.org decrypt
.org start
PokeCheck:
push {r0-r7, lr}
ldr r0, var8000
ldr r2, party
ldrh r1, [r0, #0x8]
mov r0, #0x64
mul r0, r1
add r4, r2, r0
ldr r0, [r4]
mov r1, #0x19
bl div
ldr r5, var8000
ldrh r1, [r5]
cmp r0, r1
bne GenderCheck
mov r0, #0x0
b End
GenderCheck:
mov r6, r1
mov r0, r4
mov r1, #0xB
bl decrypt
mov r1, #0x1C
mul r0, r1
ldr r1, pokedata
add r0, r1, r0
ldrb r0, [r0, #0x10]
lsl r1, r0, #0x8
orr r6, r1
cmp r0, #0xFE
beq Female
ldrb r1, [r4]
cmp r1, r0
bcs AbilityCheck
Female:
mov r0, #0x20
orr r6, r0
AbilityCheck:
lsl r1, r1, #0x1F
lsr r1, r1, #0x1F
cmp r1, #0x0
beq ShinyCheck
mov r0, #0x40
orr r6, r0
ShinyCheck:
ldrh r0, [r4]
ldrh r1, [r4, #0x2]
ldrh r2, [r4, #0x4]
ldrh r3, [r4, #0x6]
eor r0, r1
eor r0, r2
eor r0, r3
cmp r0, #0x8
bcs PIDGen
mov r0, #0x80
orr r6, r0
PIDGen:
lsl r7, r6, #0x1B
lsr r7, r7, #0x1B
mov r1, #0x1
and r1, r7
lsl r0, r6, #0x19
lsr r0, r0, #0x1F
cmp r0, r1
beq GenderGen
add r7, r7, #0x19
GenderGen:
lsr r1, r6, #0x8
cmp r1, #0xFF
beq ShinyGen
lsl r2, r6, #0x1A
lsr r2, r2, #0x1F
GenderLoop:
lsl r0, r7, #0x18
lsr r0, r0, #0x18
cmp r0, r1
bcc IfFemale
cmp r2, #0x0
beq ShinyGen
TryAgain:
add r7, #0x32
b GenderLoop
IfFemale:
cmp r2, #0x1
beq ShinyGen
b TryAgain
ShinyGen:
lsl r7, r7, #0x10
lsr r0, r7, #0x10
lsr r7, r7, #0x10
ldrh r1, [r4, #0x4]
ldrh r2, [r4, #0x6]
eor r0, r1
eor r0, r2
lsl r1, r6, #0x18
lsr r1, r1, #0x1F
cmp r1, #0x1
beq ShinyPID
neg r0, r0
sub r0, #0x1
ShinyPID:
lsl r0, r0, #0x10
orr r7, r0
ldr r6, ram
str r7, [r6]
str r4, [r6, #0x4]
mov r0, #0x1
End:
strh r0, [r5, #0x18]
pop {r0-r7, pc}
.align 2
var8000: .word 0x020370B8
party: .word 0x02024284
pokedata: .word 0x08254784
ram: .word 0x0203F448
SubstructureOrder:
push {r0-r7, lr}
ldr r5, ram2
ldr r0, [r5, #0x48]
mov r1, #0x18
bl div
mov r1, #0x6
swi #0x6
g_in_first: @This is JPAN:s routine for figuring out the substructure order of a PID.
cmp r0, #0x0
bne g_in_second
mov r2, #0x0
B g_final
g_in_second:
cmp r1, #0x1
bgt g_in_third
mov r2, #0xC
b g_final
g_in_third:
mov r2, #1
and r2, r1
cmp r2, #1
beq g_in_fourth
mov r2, #0x18
b g_final
g_in_fourth:
mov r2, #0x24
g_final:
lsl r6, r2, #0x18
m_in_first:
cmp r0, #0x3
bne m_in_second
mov r2, #0x0
b m_final
m_in_second:
cmp r1, #0x4
blt m_in_third
mov r2, #0xC
b m_final
m_in_third:
mov r2, #0x1
and r2, r1
cmp r2, #0x1
bne m_in_fourth
mov r2, #0x18
b m_final
m_in_fourth:
mov r2, #0x24
m_final:
add r6, r2, r6
a_first:
cmp r0, #0x1
bgt a_second
cmp r0, #0x0
beq a_lesser_second
mov r2, #0x0
b a_final
a_second:
mov r3, #0x2
beq a_greater_second
cmp r1, #0x3
beq a_greater_second
cmp r1, #0x0
beq a_greater_third
cmp r1, #0x5
beq a_greater_third
mov r2, #0x24
b a_final
a_greater_second:
mov r2, #0xC
b a_final
a_greater_third:
mov r2, #0x18
b a_final
a_lesser_second:
cmp r1, #0x1
bgt a_lesser_third
mov r2, #0xC
b a_final
a_lesser_third:
mov r2, #0x1
and r2, r1
cmp r2, #0x2
bne a_lesser_fourth
mov r2, #0x18
b a_final
a_lesser_fourth:
mov r2, #0x24
a_final:
lsl r2, r2, #0x10
add r6, r2, r6
e_first:
cmp r0, #0x2
blt e_second
cmp r0, #0x2
bgt e_greater_second
mov r2, #0x0
b e_final
e_second:
cmp r1, #0x2
beq e_lesser_second
cmp r1, #0x3
beq e_lesser_second
cmp r1, #0x0
beq e_lesser_third
cmp r1, #0x5
beq e_lesser_third
mov r2, #0x24
b e_final
e_lesser_second:
mov r2, #0xC
b e_final
e_lesser_third:
mov r2, #0x18
b e_final
e_greater_second:
cmp r1, #0x5
blt e_greater_third
mov r2, #0xC
b e_final
e_greater_third:
mov r2, #1
and r2, r1
cmp r2, #0
beq e_greater_fourth
mov r2, #0x18
b e_final
e_greater_fourth:
mov r2, #0x24
e_final:
lsl r2, r2, #0x8
add r6, r2, r6
WriteData:
ldr r7, [r5, #0x48]
ldr r4, [r5, #0x4C]
str r7, [r4]
ldr r0, [r4, #0x4]
eor r0, r7
add r4, #0x20
lsr r1, r6, #0x18
ldr r2, [r5, #0x8]
bl Write
lsl r1, r6, #0x8
lsr r1, r1, #0x18
ldr r2, [r5, #0xC]
bl Write
lsl r1, r6, #0x10
lsr r1, r1, #0x18
ldr r2, [r5, #0x10]
bl Write
lsl r1, r6, #0x18
lsr r1, r1, #0x18
ldr r2, [r5, #0x14]
bl Write
pop {r0-r7, pc}
Write:
ldr r3, [r2]
eor r3, r0
str r3, [r4, r1]
add r1, #0x4
ldr r3, [r2, #0x4]
eor r3, r0
str r3, [r4, r1]
add r1, #0x4
ldr r3, [r2, #0x8]
eor r3, r0
str r3, [r4, r1]
bx lr
.align 2
ram2: .word 0x0203F400
.org div @Needs to be above everything if the routine is located after 0x1E4684.
r0: New 32-bit enc-key
r1: Where to store the encrypted data
r2: Fångar upp decrypted values in ram
r3: Decrypted values. To be Xor:ed with r0
r4: Location of selected Poke
r5: RAM address
r6: New Data Structure Byte1: Micellaneous|Byte2: IVs etc|Byte3: Attacks|Byte4: Growth (Position from data)
r7: Generated PID
r4: Location of selected Poke
r5: var8000
r6: Bit 0-4: Random Nature|Bit 5: Gender|Bit 6: Ability|Bit 7: Shinyness|Bit 8-15: Gender Ratio
r7: Generated PID
Returns 0 to lastresult if nature is unchanged, and 1 if the PID was updated.
Requires a random 0x19 saved to var8000 and a position in var8004, random again if nature didn't change.