summaryrefslogtreecommitdiff
path: root/src/poweruphax.S
blob: cf6ecb6a0f6319254bfed4050f0255eb7d7f34fe (plain)
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
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
.text
.align 4
.set sp, 1

.extern returnFromGPSFASixth
.extern daEnItem_c__GetWhetherPlayerCanGetPowerupOrNot
.extern dAcPy_c__ChangePowerupWithAnimation
.extern PlayPlayerSound
.extern CreateActor
.extern PlayerProjectileShooting
.extern Actor_SearchByName
.extern SomeTable_802F5440
.extern SomeTable_802F5580
.extern SomeTable_802F56C0
.extern BlahTable
.extern continuePlumberSetPowerupTexture
.extern doneSettingThePowerupTexture
.extern doneSettingThePowerupTexture2
.extern returnFromPowerupSoundChange

#ifndef __MWERKS__
.set r0,0;   .set r1,1;   .set r2,2; .set r3,3;   .set r4,4
.set r5,5;   .set r6,6;   .set r7,7;   .set r8,8;   .set r9,9
.set r10,10; .set r11,11; .set r12,12; .set r13,13; .set r14,14
.set r15,15; .set r16,16; .set r17,17; .set r18,18; .set r19,19
.set r20,20; .set r21,21; .set r22,22; .set r23,23; .set r24,24
.set r25,25; .set r26,26; .set r27,27; .set r28,28; .set r29,29
.set r30,30; .set r31,31; .set f0,0; .set f2,2; .set f3,3
.set f1,1;   .set f30,30; .set f31,31
#endif

.global GetInfoFromDumbTable
GetInfoFromDumbTable:
	lis r3, SomeTable@h
	ori r3, r3, SomeTable@l

	slwi r4, r4, 2
	slwi r0, r5, 6

	lwzx r3, r3, r4
	add r3, r3, r0
	blr




.global FukidashiFix
FukidashiFix:
	lis r7, ZeroFloat@h
	ori r7, r7, ZeroFloat@l
	
	lis r8, FukidashiTable2@h
	ori r8, r8, FukidashiTable2@l
	
	mulli r6, r4, 0x20
	slwi r0, r5, 2
	add r0, r0, r6
	
	lfs f0, 0(r7)
	lfsx f1, r8, r0
	
	stfs f0, 0x1DC(r3)
	stfs f1, 0x1E0(r3)
	stfs f0, 0x1E4(r3)
	
	blr




.global PlayerGetHeight
PlayerGetHeight:
	lwz r0, 0x14D4(r3)
	
	lwz r4, 0x1090(r3)
	slwi r4, r4, 3
	
	cmpwi r0, 0
	beq useNormal
	cmpwi r0, 1
	bne useDucking
	
useNormal:
	lis r3, PlayerHeightsNormal@h
	ori r3, r3, PlayerHeightsNormal@l
	b gotOffset
	
useDucking:
	lis r3, PlayerHeightsDucking@h
	ori r3, r3, PlayerHeightsDucking@l
	
gotOffset:
	lfsx f1, r3, r4
	blr



.global WtfEver
WtfEver:
	lis r3, WtfEverTable@h
	ori r3, r3, WtfEverTable@l
	lfsx f0, r3, r0
	blr



.global YetAnother
YetAnother:
	lis r3, YetAnotherTable@h
	ori r3, r3, YetAnotherTable@l
	lfsx f0, r3, r0
	blr




.global GetWeirdScaleTable
GetWeirdScaleTable:
	lis r5, WeirdScaleTable@h
	ori r5, r5, WeirdScaleTable@l
	lfsx f1, r5, r0
	blr





.global GetAsdfTable
GetAsdfTable:
	extsb r0, r4
	cmpwi r0, -1
	bne dontGetThisOne
	
	lwz r0, 0x1090(r3)
	extsb r4, r0
	
dontGetThisOne:
	extsb r0, r4
	
	lis r3, AsdfTable@h
	ori r3, r3, AsdfTable@l
	lbzx r3, r3, r0
	
	blr





.global GetBlahTableOffset
GetBlahTableOffset:
	lis r5, BlahTableOffsets@h
	ori r5, r5, BlahTableOffsets@l
	lwzx r30, r5, r4
	blr


.global DealWithBlahTable
DealWithBlahTable:
	lis r5, BlahTableOffsets@h
	ori r5, r5, BlahTableOffsets@l
	
	# points to BlahTable
	lis r4, BlahTable@h
	ori r4, r4, BlahTable@l
	
	# get blahtableoffset entry based on powerup
	lwz r0, 0x1090(r3)
	slwi r0, r0, 2
	lwzx r0, r5, r0
	
	# now get the entry from the blahtable
	slwi r0, r0, 2
	lwzx r4, r4, r0
	
	# do shit here
	
	lfs f3, 0(r4)
	stfs f3, 0x14E4(r3)
	stfs f3, 0x164(r3)
	
	lfs f1, 0x2A70(r3)
	lfs f0, 0x2A74(r3)
	
	lfs f2, 4(r4)
	fadds f1, f2, f1
	fadds f0, f0, f1
	stfs f0, 0x14E8(r3)
	stfs f0, 0x168(r3)
	
	lfs f0, 0x8(r4)
	lfs f1, 0xC(r4)
	stfs f0, 0x16C(r3)
	stfs f1, 0x170(r3)
	
	# hope I did this right
	blr





.global GetPowerupScaleFloatAddr_r6_trash_r0_valshl2_r4_dest
GetPowerupScaleFloatAddr_r6_trash_r0_valshl2_r4_dest:
	lis r6, PowerupScaleFloats@h
	ori r6, r6, PowerupScaleFloats@l
	add r4, r6, r0
	blr

.global GetPowerupScaleFloatAddr_r6_trash_r0_valshl2_r3_dest
GetPowerupScaleFloatAddr_r6_trash_r0_valshl2_r3_dest:
	lis r6, PowerupScaleFloats@h
	ori r6, r6, PowerupScaleFloats@l
	add r3, r6, r0
	blr

.global GetPowerupScaleFloatAddr_r8_trash_r0_valshl2_r7_dest
GetPowerupScaleFloatAddr_r8_trash_r0_valshl2_r7_dest:
	lis r8, PowerupScaleFloats@h
	ori r8, r8, PowerupScaleFloats@l
	add r7, r8, r0
	blr

.global GetPowerupScaleFloatAddr_fixForSixth
GetPowerupScaleFloatAddr_fixForSixth:
	lis r5, PowerupScaleFloats@h
	ori r5, r5, PowerupScaleFloats@l
	add r4, r5, r4
	b returnFromGPSFASixth



.global PlumberSetPowerupFix
PlumberSetPowerupFix:
	lbz r0, 0x152(r31) # get powerup id
	
	cmpwi r0, 2
	beq doFireTex
	
	cmpwi r0, 6
	beq doIceTex
	
	cmpwi r0, 7
	beq doHammerTex
	
	li r4, 0
	b gotTexID
	
doFireTex:
	li r4, 1
	b gotTexID
	
doIceTex:
	li r4, 2
	b gotTexID
	
doHammerTex:
	li r4, 3
	
gotTexID:
	lwz r12, 0(r31)
	mr r3, r31
	lwz r12, 0x34(r12)
	mtctr r12
	bctrl
	
	b doneSettingThePowerupTexture



.global PlumberSetPowerupFix2
PlumberSetPowerupFix2:
	cmpwi r31, 2
	beq doFireTex2
	
	cmpwi r31, 6
	beq doIceTex2
	
	cmpwi r31, 7
	beq doHammerTex2
	
	li r4, 0
	b gotTexID2
	
doFireTex2:
	li r4, 1
	b gotTexID2
	
doIceTex2:
	li r4, 2
	b gotTexID2
	
doHammerTex2:
	li r4, 3
	
gotTexID2:
	lwz r3, 0x2A64(r30)
	lwz r12, 0(r3)
	lwz r12, 0x34(r12)
	mtctr r12
	bctrl
	
	b doneSettingThePowerupTexture2




.global PlumberSetPowerupTextureFix
PlumberSetPowerupTextureFix:
	stb r4, 0x153(r3)
	
	lis r5, PowerupTextures@h
	ori r5, r5, PowerupTextures@l
	
	slwi r4, r4, 2
	lfsx f31, r5, r4
	
	b continuePlumberSetPowerupTexture



.global SetHammerToEnItemDCA
SetHammerToEnItemDCA:
	bl daEnItem_c__GetWhetherPlayerCanGetPowerupOrNot
	cmpwi r3, 1
	bne DontSetHammer
	
	li r0, 5
	sth r0, 0xDCA(r31)
	
DontSetHammer:
	lwz r0, 0x14(sp)
	lwz r31, 0xC(sp)
	mtlr r0
	addi sp, sp, 0x10
	blr

.global SetHammerToEnItemDCASpecial
SetHammerToEnItemDCASpecial:
	cmplwi r4, 0x19
	b _not19
	li r0, 0xD
	sth r0, 0xDCA(r3)
_not19:
	cmplwi r4, 6
	bnelr
	li r0, 5
	sth r0, 0xDCA(r3)
	blr


#.global EnItem_BindAnimation_Fix
#EnItem_BindAnimation_Fix:
#	lhz r0, 0xDCA(r3)
#	cmpwi r0, 5
#	beqlr
#	stwu sp, -0x20(sp)
#	b EnItem_BindAnimation_Continued


.global FixPowerupSound
FixPowerupSound:
	#lis r3, DBString@h
	#ori r3, r3, DBString@l
	#lwz r4, 0x1090(r29)
	#crclr 4*cr1+eq
	#bl OSReport

	lwz r5, 0x14DC(r29) # Original powerup
	lwz r0, 0x1090(r29) # New powerup
	# if NEW is 1 (big) and OLD is not 0 or 3, then play 273 (powerdown)
	cmpwi r0, 1
	bne dontConsiderPowerdown

	cmpwi r5, 0
	beq dontConsiderPowerdown
	cmpwi r5, 3
	beq dontConsiderPowerdown
	# If the player is here, he was downgraded from a higher powerup to Big Mario
	# So play the powerdown sound
	mr r3, r29
	li r4, 273
	li r5, 0
	b returnFromPowerupSoundChange

dontConsiderPowerdown:
	lis r3, PowerupSounds@h
	ori r3, r3, PowerupSounds@l
	slwi r4, r0, 2
	lwzx r4, r3, r4
	mr r3, r29
	li r5, 0

	b returnFromPowerupSoundChange


.global WeirdAnimLoadHack
WeirdAnimLoadHack:
	cmplwi r4, 5 #hammersuit
	beqlr
	cmplwi r4, 6 #1up
	beqlr
	# neither of those succeeded
	crclr 4*cr0+eq
	blr



.global TryToGiveMarioHammerSuit
TryToGiveMarioHammerSuit:
	stwu sp, -0x10(sp)
	mflr r0
	stw r0, 0x14(sp)
	
	# check the obtained item number
	cmplwi r3, 5
	bne IsntGettingHammerSuit
	
	# check the current player powerup
	cmplwi r4, 7
	bne DontHaveHammerSuit
	
	li r28, 0
	li r29, 2
	b ReturnFromTTGMHS
	
DontHaveHammerSuit:
	mr r3, r30
	li r4, 7
	bl dAcPy_c__ChangePowerupWithAnimation
	
	cmpwi r3, 0
	beq ReturnFromTTGMHS
	
	li r29, 1
	
IsntGettingHammerSuit:
ReturnFromTTGMHS:
	# end of function
	lwz r0, 0x14(sp)
	mtlr r0
	addi sp, sp, 0x10
	
	# leftover instruction from what we replaced to add the bl
	cmpwi r29, 0
	blr



.global ThrowHammer
ThrowHammer:
	# continues on from PlayerProjectileShooting
	
	# get powerup
	lwz r3, 0x1090(r30)
	cmplwi r3, 7
	bne ReturnFromThrowHammer
	
	mr r3, r30
	li r4, 498
	li r5, 0
	bl PlayPlayerSound
	
	li r3, 0x73			# Hammer
	li r4, 0				# Settings
	addi r5, sp, 0x2C		# Position
	li r6, 0				# Rotation
	lbz r7, 0x38F(r30)	# Layer
	bl CreateActor
	
	# Store player ID
	lwz r4, 0(r30)
	stw r4, 0x450(r3)
	
	# store player number, but add 0x100 to differentiate it from 0
	lbz r4, 0x38D(r30)
	addi r4, r4, 0x100
	stw r4, 0x458(r3)
	
	# Fix scale
	lis r4, OneFloat@h
	ori r4, r4, OneFloat@l
	lfs f0, 0(r4)
	stfs f0, 0xDC(r3)
	stfs f0, 0xE0(r3)
	stfs f0, 0xE4(r3)
	
	mr r4, r30
	lwz r12, 0x60(r3)
	lwz r12, 0x8C(r12)
	mtctr r12
	bctrl
	
ReturnFromThrowHammer:
	lwz r0, 0xC4(sp)
	psq_l f31, 0xB8(sp), 1, 0
	lfd f31, 0xB0(sp)
	psq_l f30, 0xA8(sp), 1, 0
	lfd f30, 0xA0(sp)
	lwz r31, 0x9C(sp)
	lwz r30, 0x98(sp)
	mtlr r0
	addi sp, sp, 0xC0
	blr



.global MoreProjectileStuff_Fix
MoreProjectileStuff_Fix:
	lwz r3, 0x1090(r31)
	cmplwi r3, 7
	bne ReturnFromMPSFix
	
	mr r3, r31
	li r4, 1
	bl PlayerProjectileShooting
	
ReturnFromMPSFix:
	lwz r0, 0x14(sp)
	lwz r31, 0xC(sp)
	mtlr r0
	addi sp, sp, 0x10
	blr



.global ProjectileShootCheck_Fix
ProjectileShootCheck_Fix:
	lwz r3, 0x1090(r31)
	cmplwi r3, 7
	bne Return0fromPSCFix
	
	lbz r3, 0x38D(r31)
	li r4, 0
	extsb r3, r3
	bl CheckHammerLimit
	
	cmpwi r3, 0
	beq Return0fromPSCFix
	
	b Return1fromPSCFix

Return0fromPSCFix:
	li r3, 0
	b ReturnFromPSCFix
	
Return1fromPSCFix:
	li r3, 1
	
ReturnFromPSCFix:
	lwz r0, 0x14(sp)
	lwz r31, 0xC(sp)
	mtlr r0
	addi sp, sp, 0x10
	blr


.global CheckHammerLimit
CheckHammerLimit:
	stwu sp, -0x10(sp)
	mflr r0
	stw r0, 0x14(sp)
	stw r31, 0xC(sp)
	stw r30, 0x8(sp)
	
	# r30 = player number
	mr r30, r3
	addi r30, r30, 0x100
	
	# r31 = hammer count so far
	li r31, 0
	
	# search for every Hammer
	
	li r3, 0
	b startOrContinueLoop
loop:
	
	lwz r4, 0x458(r3)
	cmpw r4, r30
	bne startOrContinueLoop
	
	addi r31, r31, 1
	
startOrContinueLoop:
	mr r4, r3
	li r3, 0x73
	bl Actor_SearchByName
	
	cmpwi r3, 0
	bne loop
	
	# now if the current count is >= 2, return 0
	# otherwise return 1
	cmpwi r31, 2
	bge tooManyHammers
	
	li r3, 1
	b gotHammerStatus
	
tooManyHammers:
	li r3, 0
	
gotHammerStatus:
	lwz r0, 0x14(sp)
	lwz r31, 0xC(sp)
	lwz r30, 0x8(sp)
	mtlr r0
	addi sp, sp, 0x10
	blr




.extern continueToadPowerupSet
.global ToadPowerupFix
ToadPowerupFix:
	lis r8, PowerupTextures@h
	ori r8, r8, PowerupTextures@l
	slwi r9, r4, 2
	lfsx f1, r8, r9
	fadds f31, f31, f1
	b continueToadPowerupSet



.data

PowerupSounds:
	.long 273, 274, 274, 275, 276, 277, 274, 274


SomeTable:
	.long SomeTable_802F5580
	.long SomeTable_802F56C0
	.long SomeTable_802F56C0
	.long SomeTable_802F5440
	.long SomeTable_802F56C0
	.long SomeTable_802F56C0
	.long SomeTable_802F56C0
	.long SomeTable_802F56C0

ZeroFloat:
	.float 0.0

OneFloat:
	.float 1.0

FukidashiTable2:
	.float 20.0, 32.0, 32.0, 12.0, 38.0, 33.0, 32.0, 32.0
	.float 20.0, 34.0, 34.0, 12.0, 39.0, 35.0, 34.0, 34.0
	.float 20.0, 29.0, 29.0, 11.0, 34.0, 29.0, 29.0, 29.0
	.float 20.0, 29.0, 29.0, 11.0, 34.0, 29.0, 29.0, 29.0

PlayerHeightsNormal:
	.float 16.0, 27.0, 27.0, 12.0, 27.0, 27.0, 27.0, 27.0

PlayerHeightsDucking:
	.float 13.0, 21.0, 21.0, 9.0, 21.0, 21.0, 21.0, 21.0

WtfEverTable:
	.float 4.5, 10.0, 10.0, 1.0, 10.0, 9.0, 10.0, 10.0

YetAnotherTable:
	.float 0.0, -4.0, -4.0, 4.0, -6.0, -2.0, -4.0, -4.0

WeirdScaleTable:
	.float 16.0, 31.0, 31.0, 6.0, 34.0, 31.0, 31.0, 31.0

AsdfTable:
	.byte 1, 2, 2, 0, 2, 2, 2, 2

BlahTableOffsets:
	.long 1, 2, 2, 0, 3, 2, 2, 2

PowerupScaleFloats:
	.long 0xDEADBEEF, 0xDEADBEEF # padding
	.float 1.0
	.float 1.0
	.float 1.0
	.float 0.6
	.float 1.0
	.float 1.0
	.float 1.0
	.float 1.0

PowerupTextures:
	.float 0.0
	.float 1.0
	.float 2.0
	.float 3.0

.global BrosArcFileName
BrosArcFileName:
	.string "bros"

.global I_hammerArcFilename
I_hammerArcFilename:
	.string "I_hammer"

.global I_hammerResFile
I_hammerResFile:
#	.string "g3d/I_hammer.brres"
	.string "g3d/I_fireflower.brres"

.global I_hammerModelName
I_hammerModelName:
#	.string "I_hammer"
	.string "I_fireflower"


#PowerupTexDebugStr:
#	.string "Plumber::SetPowerupTexture() called on class %p with texnum %d lr=%p\n"

#DBString:
#	.string "PW:%d\n"

#.global BrosModelFilename
#BrosModelFilename:
#	.string "g3d/bros.brres"

#.global HammerModelName
#HammerModelName:
#	.string "bros_hammer"