-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAsmHooks.asm
637 lines (552 loc) · 9.21 KB
/
AsmHooks.asm
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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
.thumb
.macro blh to, reg=r3
ldr \reg, =\to
mov lr, \reg
.short 0xf800
.endm
@ 80266DC
@ 8085244
@80856a0
@ 30033EC - current phase (1, 2, 3, or 4)
.global DefaultPowCoPageHook
.type DefaultPowCoPageHook, %function
DefaultPowCoPageHook:
@ldr r3, =0x3005940 @ page
@mov r1, #4
@strb r1, [r3] @ default to page 4
add r0, #0x64
mov r1, #1
strh r1, [r0] @ redraw ?
mov r1, #0
ldr r0, =0x30033EC
ldrh r0, [r0]
mov r5, r4
bx lr
.ltorg
.global ModNum
.type ModNum, %function
ModNum:
swi 6
mov r0, r1
bx lr
.global GetClassAtt
.type GetClassAtt, %function
GetClassAtt:
push {r4-r5, lr}
sub sp, #8
str r0, [sp]@ CO id
str r2, [sp, #4]@ offset
ldr r0, =0x85D3E2C
add r3, r0
ldr r7, [r3]
mov r0, r2
ldr r3, =0x80432E0
mov lr, r3
.short 0xf800
lsl r0, #2
add r0, r5
add r0, r4
ldr r1, =0x85d3e2c
add r0, r1
ldr r1, [r0]
ldr r0, =0x3003fc0
ldrb r0, [r0, #8]
cmp r0, #0
bne AttCont
mov r0, #0
b ExitAtt
AttCont:
ldrb r0, [r6, #0x18]
mov r2, #0
cmp r0, #0
@beq ReturnDefaultAtt
ldsh r0, [r7, r2]
ldsh r1, [r1, r2]
add r0, r1
ldr r1, [sp]
ldr r2, [sp, #4]
mov r3, r5
bl HashPow @ must be multiples of 10
b ExitAtt
ReturnDefaultAtt:
ldsh r0, [r7, r2]
ExitAtt:
add sp, #8
pop {r4-r5}
pop {r3}
bx r3
.ltorg
.global GetClassDef
.type GetClassDef, %function
GetClassDef:
push {r4-r5, lr}
sub sp, #8
str r0, [sp]@ CO id
str r2, [sp, #4]@ offset
ldr r0, =0x85D3E2C
add r3, r0
ldr r7, [r3]
mov r0, r2
ldr r3, =0x80432E0
mov lr, r3
.short 0xf800
lsl r0, #2
add r0, r5
add r0, r4
ldr r1, =0x85d3e2c
add r0, r1
ldr r1, [r0]
ldr r0, =0x3003fc0
ldrb r0, [r0, #8]
cmp r0, #0
bne DefCont
mov r0, #0
b ExitDef
DefCont:
ldrb r0, [r6, #0x18]
mov r2, #2
cmp r0, #0
@beq ReturnDefaultDef
ldsh r0, [r7, r2]
ldsh r1, [r1, r2]
add r0, r1
ldr r1, [sp]
ldr r2, [sp, #4]
mov r3, r5
bl HashDef @ must be multiples of 10
b ExitDef
ReturnDefaultDef:
ldsh r0, [r7, r2]
ExitDef:
add sp, #8
pop {r4-r5}
pop {r3}
bx r3
.ltorg
.global GetClassMov
.type GetClassMov, %function
GetClassMov:
push {r4-r5, lr}
sub sp, #8
str r0, [sp]@ CO id
str r2, [sp, #4]@ offset
ldr r0, =0x85D3E2C
add r3, r0
ldr r7, [r3]
mov r0, r2
ldr r3, =0x80432E0
mov lr, r3
.short 0xf800
lsl r0, #2
add r0, r5
add r0, r4
ldr r1, =0x85d3e2c
add r0, r1
ldr r1, [r0]
ldr r0, =0x3003fc0
ldrb r0, [r0, #8]
cmp r0, #0
bne MovCont
mov r0, #0
b ExitMov
MovCont:
ldrb r0, [r6, #0x18]
mov r2, #4
cmp r0, #0
@beq ReturnDefaultMov
ldsh r0, [r7, r2]
ldsh r1, [r1, r2]
add r0, r1
ldr r1, [sp]
ldr r2, [sp, #4]
mov r3, r5
bl HashMov
b ExitMov
ReturnDefaultMov:
ldsh r0, [r7, r2]
ExitMov:
add sp, #8
pop {r4-r5}
pop {r3}
bx r3
.ltorg
.global GetClassRange
.type GetClassRange, %function
GetClassRange:
push {r4-r5, lr}
sub sp, #8
str r0, [sp]@ CO id
str r2, [sp, #4]@ offset
ldr r0, =0x85D3E2C
add r3, r0
ldr r7, [r3]
mov r0, r2
ldr r3, =0x80432E0
mov lr, r3
.short 0xf800
lsl r0, #2
add r0, r5
add r0, r4
ldr r1, =0x85d3e2c
add r0, r1
ldr r1, [r0]
ldr r0, =0x3003fc0
ldrb r0, [r0, #8]
cmp r0, #0
bne RangeCont
mov r0, #0
b ExitRange
RangeCont:
ldrb r0, [r6, #0x18]
mov r2, #6
cmp r0, #0
@beq ReturnDefaultRange
mov r4, #4 @ for mov
ldsh r2, [r7, r4]
ldsh r3, [r1, r4]
add r3, r2
mov r4, #6 @ range
ldsh r0, [r7, r4]
ldsh r1, [r1, r4]
add r0, r1
ldr r1, [sp]
ldr r2, [sp, #4]
str r5, [sp]
bl HashRange
b ExitRange
ReturnDefaultRange:
ldsh r0, [r7, r2]
ExitRange:
add sp, #8
pop {r4-r5}
pop {r3}
bx r3
.ltorg
@ 21674
.global MapSizeHook
.type MapSizeHook, %function
MapSizeHook:
push {lr}
mov r0, #0
strh r0, [r4, #0x4]
strh r0, [r4, #0x6]
strh r0, [r4, #0x8]
strh r0, [r4, #0xA]
strh r0, [r4, #0xC]
strh r0, [r4, #0xE]
strh r0, [r4, #0x10]
mov r0, r2 @ map in ram
mov r1, r4 @ ch header
mov r2, r5 @ chID
bl SetMapSize
mov r0, #0
pop {r1}
bx r1
.ltorg
.global ReplaceMapHook
.type ReplaceMapHook, %function
ReplaceMapHook:
push {lr}
strb r0, [r1]
ldr r3, =0x80215FC
mov lr, r3
.short 0xf800 @ blh
ldr r0, =0x3003F68
ldr r0, [r0]
ldr r1, =0x8499590
ldr r1, [r1] @ 0x201E450
mov r2, r5 @ chID
bl GenerateMap
mov r1, #0
ldr r0, [r6]
ldrh r0, [r0, #2]
pop {r3}
bx r3
.ltorg
.global GetPreEventPointerHook
.type GetPreEventPointerHook, %function
GetPreEventPointerHook:
push {lr}
add r0, r1
ldr r4, [r0]
add r2, #0x2c
add r1, r2
ldr r1, [r1]
push {r0-r1}
bl ShouldMapBeRandomized
mov r2, r0
pop {r0-r1}
cmp r2, #0
beq GetPreEventPointerHook_Vanilla
mov r4, #0
GetPreEventPointerHook_Vanilla:
cmp r4, #0
pop {r3}
bx r3
.ltorg
.global GPE_2 @ 74584
.type GPE_2, %function
GPE_2:
push {lr}
ldr r0, =0x3003FC0
ldrb r0, [r0, #2]
blh 0x8035000
ldr r0, [r0, #4]
push {r0}
bl ShouldMapBeRandomized
pop {r1}
cmp r0, #0
beq GPE_2_Vanilla
mov r1, #0
GPE_2_Vanilla:
mov r0, r1
pop {r1}
bx r1
.ltorg
.global UnitPointerHook
.type UnitPointerHook, %function
UnitPointerHook:
push {lr}
ldrb r3, [r0, #2]
mov r0, #0x5c
mul r0, r3
add r1, r0
add r2, #0x34
add r1, r2
ldr r0, [r1]
push {r0}
bl ShouldMapBeRandomized
pop {r1}
cmp r0, #0
beq UnitPointerHook_Vanilla
mov r1, #0
UnitPointerHook_Vanilla:
mov r0, r1
pop {r3}
bx r3
.ltorg
.global GetNumberOfDaysHook
.type GetNumberOfDaysHook, %function
GetNumberOfDaysHook: @ copy of 43630
push {r4-r5, lr}
mov r4, r0
mov r5, r1
bl ShouldMapBeRandomized
cmp r0, #0
beq VanillaDays
mov r0, #0
b ExitDays
VanillaDays:
mov r0, r4
mov r1, r5
ldr r2, =0x8043650
ldr r2, [r2]
ldr r3, =0x8043654
ldr r3, [r3]
ldrb r1, [r3, #2]
mov r0, #0x5c
mul r0, r1
add r1, r0, r2
ldrh r0, [r1, #0x24]
cmp r0, #0
bne ExitDays
mov r1, r3
add r1, #0x30
ldrb r0, [r1]
ExitDays:
pop {r4-r5}
pop {r1}
bx r1
.ltorg
@ 618f8
@0x618a8 callHackNew short 0x46c0
.global EnsureFactoryPointer
.type EnsureFactoryPointer, %function
EnsureFactoryPointer:
push {lr}
add r0, r2
ldr r0, [r0]
cmp r0, #0
bne StoreFactoryPointerVanilla
ldr r0, =GenericFactoryUnits
StoreFactoryPointerVanilla:
str r0, [r5]
blh 0x8061cdc
blh 0x8061cf8
pop {r1}
bx r1
.ltorg
.global ToggleMusicWinCh
.type ToggleMusicWinCh, %function
ToggleMusicWinCh:
push {lr}
blh WinCh_P1
blh WinCh_P2
ldr r3, =0x802CE20
ldr r3, [r3]
ldr r1, [r3]
ldrb r2, [r1, #0xC]
mov r0, #1
sub r0, r2
strb r0, [r1, #0xC]
ldrb r0, [r1, #0xC]
mov r4, r3
pop {r3}
bx r3
.ltorg
.global EnsureFactoryPointer2
.type EnsureFactoryPointer2, %function
EnsureFactoryPointer2:
push {r4-r5, lr}
sub sp, #0x60
ldr r4, [r6]
ldr r5, [r4]
cmp r5, #0
bne UseVanillaFactoryPointer
mov r1, sp
ldr r2, =GenericFactoryUnits
mov r3, #0
DefaultFactoryUnitsLoop:
ldr r0, [r2, r3]
str r0, [r1, r3]
add r3, #4
cmp r3, #0x60
blt DefaultFactoryUnitsLoop
blh 0x803866c @ difficulty
mov r1, sp
str r1, [r4]
bl RandomizeFactoryUnits
UseVanillaFactoryPointer:
blh 0x80607e8
str r5, [r4] @ restore to normal afterwards
add sp, #0x60
pop {r4-r5}
pop {r0}
bx r0
.ltorg
.global GetCampaignHeader
.type GetCampaignHeader, %function
GetCampaignHeader: @ see 0x807733a
push {lr}
blh 0x803866c @ difficulty & checks if we're actually in campaign
lsl r3, r0, #2 @ either 4 or 0
ldr r2, =0x80773a4
ldr r2, [r2] @ldr r2, =0x81CC5A0 @ r5=81CC5A0
ldr r2, [r2]
ldr r0, [r2, #0xC] @ 0202FE08 current mission highlighted
ldr r2, =0x80773a0
ldr r2, [r2] @ldr r3, =0x8615194
lsl r1, r0, #1
add r1, r0
lsl r1, #4
add r0, r1, r2
pop {r1}
bx r1
.ltorg
.global GetFactoryUnitsPointer
.type GetFactoryUnitsPointer, %function
GetFactoryUnitsPointer: @
push {lr}
bl GetCampaignHeader
ldr r0, [r0, #0x24]
pop {r1} @ [0x8615194+0x24]?
bx r1
.ltorg
@mov r3, #0
@ldsh r2, [r0, r3] @ gives 0x8A
@ldr r3, =0x85CC7A0
@mov r0, #0x5C
@mul r0, r2
@add r2, r0, r3
@ldr r0, [r2, #0x24]
@ [0x85CA938+0x24]? 8615194+0x24
.global GetNumberOfPlayers
.type GetNumberOfPlayers, %function
GetNumberOfPlayers: @ see 0x807733a
push {r4-r5, lr}
@ldr r4, =0x8615194
@ldr r5, =0x81cc5a0
@ldr r2, [r5]
@ldr r0, [r2, #0xC]
@lsl r1, r0, #1
@add r1, r0
@lsl r1, #4
@add r0, r1, r4
@mov r3, #0
@ldsh r2, [r0, r3]
ldr r2, =0x3003FC2
ldrb r2, [r2]
ldr r3, =0x85c77a0
mov r0, #0x5C
mul r0, r2
add r2, r0, r3
ldrb r0, [r2, #0x18]
pop {r4-r5}
pop {r1}
bx r1
.ltorg
.global BitSet_UnlockAll
.type BitSet_UnlockAll, %function
BitSet_UnlockAll:
push {r14}
ldr r0,=0x17F @Campaign/Game Modes
ldr r1,=0x02028030
strh r0,[r1]
mov r0,#0x1 @Map Cases
neg r0,r0
add r1,#0x10
strb r0,[r1]
add r1,#2
mov r2,#0 @Maps
Map_Loop_Start:
add r2,#0x1
strb r0,[r1,r2]
cmp r2,#0x11
blt Map_Loop_Start
ldr r0,=0xFFFF @COs
add r1,#0x18
strb r0,[r1]
strb r0,[r1,#0x1]
strb r0,[r1,#0x2]
ldr r0,=0xFFFF @Colour Edits
add r1,#0x3
strb r0,[r1]
strb r0,[r1,#0x1]
strb r0,[r1,#0x2]
pop {r1}
bx r1
.ltorg
.global memset
.type memset, %function
memset:
@ void *memset(void *dest, int val, u32 len)
push {r0}
sub sp, #4
mov r3, #0
str r3, [sp]
lsr r2, #1 @ in SHORT units, not bytes
mov r3, #1
lsl r3, #24 @ fill, not copy
orr r2, r3
lsr r1, r0, #1
lsl r1, #1
mov r0, sp
swi 0xB
add sp, #4
pop {r0}
bx lr
.ltorg
.global memcpy
.type memcpy, %function
memcpy:
@ void *memcpy(void *src, void *dest, u32 len)
push {r0}
lsr r0, #1
lsl r0, #1
lsr r1, #1
lsl r1, #1
lsr r2, #1 @ in SHORT units, not bytes
swi 0xB
pop {r0}
bx lr
.ltorg