From 346edbc9fd6fdaf14e0134778f03198ca9afceff Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sun, 6 Sep 2020 17:28:33 +1000 Subject: [PATCH] Decompile tagsAllocatePtrs --- src/game/game_0109d0.c | 12 +-- src/game/game_095320.c | 155 +++++++++++---------------------- src/game/game_097ba0.c | 4 +- src/game/game_167ae0.c | 2 +- src/game/propobj.c | 2 +- src/gvars/gvars.c | 2 +- src/include/game/game_095320.h | 4 +- src/include/gvars/gvars.h | 2 +- src/include/types.h | 9 +- tools/patchpiracysums | 2 +- 10 files changed, 67 insertions(+), 127 deletions(-) diff --git a/src/game/game_0109d0.c b/src/game/game_0109d0.c index 1c285d315..3d5021666 100644 --- a/src/game/game_0109d0.c +++ b/src/game/game_0109d0.c @@ -23,9 +23,9 @@ glabel func0f0109d0 /* f0109e8: 240effff */ addiu $t6,$zero,-1 /* f0109ec: 3c018007 */ lui $at,%hi(g_ObjectiveLastIndex) /* f0109f0: 3c02800a */ lui $v0,%hi(g_ObjectiveStatuses) -/* f0109f4: 3c03800a */ lui $v1,%hi(var8009d0b0) +/* f0109f4: 3c03800a */ lui $v1,%hi(g_TagsLinkedList) /* f0109f8: ac2eae70 */ sw $t6,%lo(g_ObjectiveLastIndex)($at) -/* f0109fc: 2463d0b0 */ addiu $v1,$v1,%lo(var8009d0b0) +/* f0109fc: 2463d0b0 */ addiu $v1,$v1,%lo(g_TagsLinkedList) /* f010a00: 2442d088 */ addiu $v0,$v0,%lo(g_ObjectiveStatuses) .L0f010a04: /* f010a04: 24420004 */ addiu $v0,$v0,0x4 @@ -42,8 +42,8 @@ glabel func0f0109d0 /* f010a28: 24420004 */ addiu $v0,$v0,0x4 /* f010a2c: 1443fffe */ bne $v0,$v1,.L0f010a28 /* f010a30: ac40fffc */ sw $zero,-0x4($v0) -/* f010a34: 3c01800a */ lui $at,%hi(var8009d0b0) -/* f010a38: ac20d0b0 */ sw $zero,%lo(var8009d0b0)($at) +/* f010a34: 3c01800a */ lui $at,%hi(g_TagsLinkedList) +/* f010a38: ac20d0b0 */ sw $zero,%lo(g_TagsLinkedList)($at) /* f010a3c: 3c01800a */ lui $at,%hi(var8009d0b4) /* f010a40: ac20d0b4 */ sw $zero,%lo(var8009d0b4)($at) /* f010a44: 3c01800a */ lui $at,%hi(g_RoomEnteredCriterias) @@ -59,8 +59,8 @@ glabel func0f0109d0 GLOBAL_ASM( glabel func0f010a68 -/* f010a68: 3c02800a */ lui $v0,%hi(var8009d0b0) -/* f010a6c: 2442d0b0 */ addiu $v0,$v0,%lo(var8009d0b0) +/* f010a68: 3c02800a */ lui $v0,%hi(g_TagsLinkedList) +/* f010a6c: 2442d0b0 */ addiu $v0,$v0,%lo(g_TagsLinkedList) /* f010a70: 8c4e0000 */ lw $t6,0x0($v0) /* f010a74: ac8e0008 */ sw $t6,0x8($a0) /* f010a78: 03e00008 */ jr $ra diff --git a/src/game/game_095320.c b/src/game/game_095320.c index af682cba1..91d4fbf83 100644 --- a/src/game/game_095320.c +++ b/src/game/game_095320.c @@ -68,104 +68,51 @@ void func0f095350(u32 arg0, u32 *arg1) func00049b24(); } -GLOBAL_ASM( -glabel func0f0953cc -/* f0953cc: 3c02800a */ lui $v0,%hi(var8009d0b0) -/* f0953d0: 8c42d0b0 */ lw $v0,%lo(var8009d0b0)($v0) -/* f0953d4: 27bdffc8 */ addiu $sp,$sp,-56 -/* f0953d8: afbf0014 */ sw $ra,0x14($sp) -/* f0953dc: 10400009 */ beqz $v0,.L0f095404 -/* f0953e0: 00003025 */ or $a2,$zero,$zero -/* f0953e4: 94430004 */ lhu $v1,0x4($v0) -.L0f0953e8: -/* f0953e8: 0066082a */ slt $at,$v1,$a2 -/* f0953ec: 54200003 */ bnezl $at,.L0f0953fc -/* f0953f0: 8c420008 */ lw $v0,0x8($v0) -/* f0953f4: 24660001 */ addiu $a2,$v1,0x1 -/* f0953f8: 8c420008 */ lw $v0,0x8($v0) -.L0f0953fc: -/* f0953fc: 5440fffa */ bnezl $v0,.L0f0953e8 -/* f095400: 94430004 */ lhu $v1,0x4($v0) -.L0f095404: -/* f095404: 3c07800a */ lui $a3,%hi(g_NumTags) -/* f095408: 24e7d0c4 */ addiu $a3,$a3,%lo(g_NumTags) -/* f09540c: 10c0001b */ beqz $a2,.L0f09547c -/* f095410: ace60000 */ sw $a2,0x0($a3) -/* f095414: 00062080 */ sll $a0,$a2,0x2 -/* f095418: 2484000f */ addiu $a0,$a0,0xf -/* f09541c: 348f000f */ ori $t7,$a0,0xf -/* f095420: 39e4000f */ xori $a0,$t7,0xf -/* f095424: 00003025 */ or $a2,$zero,$zero -/* f095428: 24050004 */ addiu $a1,$zero,0x4 -/* f09542c: 0c0048f2 */ jal malloc -/* f095430: afa00034 */ sw $zero,0x34($sp) -/* f095434: 3c07800a */ lui $a3,%hi(g_NumTags) -/* f095438: 24e7d0c4 */ addiu $a3,$a3,%lo(g_NumTags) -/* f09543c: 8cf90000 */ lw $t9,0x0($a3) -/* f095440: 3c03800a */ lui $v1,%hi(g_TagPtrs) -/* f095444: 2463d0c8 */ addiu $v1,$v1,%lo(g_TagPtrs) -/* f095448: ac620000 */ sw $v0,0x0($v1) -/* f09544c: 1b20000b */ blez $t9,.L0f09547c -/* f095450: 8fa60034 */ lw $a2,0x34($sp) -/* f095454: 00001025 */ or $v0,$zero,$zero -/* f095458: 8c680000 */ lw $t0,0x0($v1) -.L0f09545c: -/* f09545c: 24c60001 */ addiu $a2,$a2,0x1 -/* f095460: 01024821 */ addu $t1,$t0,$v0 -/* f095464: ad200000 */ sw $zero,0x0($t1) -/* f095468: 8cea0000 */ lw $t2,0x0($a3) -/* f09546c: 24420004 */ addiu $v0,$v0,4 -/* f095470: 00ca082a */ slt $at,$a2,$t2 -/* f095474: 5420fff9 */ bnezl $at,.L0f09545c -/* f095478: 8c680000 */ lw $t0,0x0($v1) -.L0f09547c: -/* f09547c: 3c02800a */ lui $v0,%hi(var8009d0b0) -/* f095480: 8c42d0b0 */ lw $v0,%lo(var8009d0b0)($v0) -/* f095484: 3c03800a */ lui $v1,%hi(g_TagPtrs) -/* f095488: 2463d0c8 */ addiu $v1,$v1,%lo(g_TagPtrs) -/* f09548c: 10400009 */ beqz $v0,.L0f0954b4 -/* f095490: 3c040aff */ lui $a0,0xaff -/* f095494: 944c0004 */ lhu $t4,0x4($v0) -.L0f095498: -/* f095498: 8c6b0000 */ lw $t3,0x0($v1) -/* f09549c: 000c6880 */ sll $t5,$t4,0x2 -/* f0954a0: 016d7021 */ addu $t6,$t3,$t5 -/* f0954a4: adc20000 */ sw $v0,0x0($t6) -/* f0954a8: 8c420008 */ lw $v0,0x8($v0) -/* f0954ac: 5440fffa */ bnezl $v0,.L0f095498 -/* f0954b0: 944c0004 */ lhu $t4,0x4($v0) -.L0f0954b4: -/* f0954b4: 0fc254c8 */ jal xorBaffbeff -/* f0954b8: 3484b4a3 */ ori $a0,$a0,0xb4a3 -/* f0954bc: 3c04adfe */ lui $a0,0xadfe -/* f0954c0: 0fc254cc */ jal xorBabeffff -/* f0954c4: 34840006 */ ori $a0,$a0,0x6 -/* f0954c8: 0c0057f4 */ jal func00015fd0 -/* f0954cc: afa20024 */ sw $v0,0x24($sp) -/* f0954d0: 8faf0024 */ lw $t7,0x24($sp) -/* f0954d4: 504f0011 */ beql $v0,$t7,.L0f09551c -/* f0954d8: 8fbf0014 */ lw $ra,0x14($sp) -/* f0954dc: 0c004b70 */ jal random -/* f0954e0: 00000000 */ nop -/* f0954e4: 0c004b70 */ jal random -/* f0954e8: afa2001c */ sw $v0,0x1c($sp) -/* f0954ec: 8fa4001c */ lw $a0,0x1c($sp) -/* f0954f0: 3c010001 */ lui $at,0x1 -/* f0954f4: 3421fff8 */ ori $at,$at,0xfff8 -/* f0954f8: 0081c024 */ and $t8,$a0,$at -/* f0954fc: 3c018001 */ lui $at,0x8001 -/* f095500: 03012021 */ addu $a0,$t8,$at -/* f095504: 3c010001 */ lui $at,0x1 -/* f095508: 3421fffe */ ori $at,$at,0xfffe -/* f09550c: 00412824 */ and $a1,$v0,$at -/* f095510: 0c003504 */ jal func0000d410 -/* f095514: 24061000 */ addiu $a2,$zero,0x1000 -/* f095518: 8fbf0014 */ lw $ra,0x14($sp) -.L0f09551c: -/* f09551c: 27bd0038 */ addiu $sp,$sp,0x38 -/* f095520: 03e00008 */ jr $ra -/* f095524: 00000000 */ nop -); +void tagsAllocatePtrs(void) +{ + s32 index = 0; + struct tag *tag = g_TagsLinkedList; + + while (tag) { + if (tag->tagnum >= index) { + index = tag->tagnum + 1; + } + + tag = tag->next; + } + + g_NumTags = index; + + if (g_NumTags) { + u32 size = index * 4; + g_TagPtrs = malloc(ALIGN16(size), 4); + + for (index = 0; index < g_NumTags; index++) { + g_TagPtrs[index] = NULL; + } + } + + tag = g_TagsLinkedList; + + while (tag) { + g_TagPtrs[tag->tagnum] = tag; + tag = tag->next; + } + +#if PIRACYCHECKS + { + u32 a = xorBaffbeff(0xb0000a5c ^ 0xbaffbeff); + u32 b = xorBabeffff(0x1740fff9 ^ 0xbabeffff); + + if (func00015fd0() != b) { + // Read 4KB from a random ROM location within 128KB from the start of + // the ROM, and write it to a random memory location between 0x80010000 + // and 0x80030ff8. This will corrupt instructions in the lib segment. + func0000d410((u8 *)((random() & 0x1fff8) + 0x80010000), (u8 *)(random() & 0x1fffe), 0x1000); + } + } +#endif +} struct tag *tagFindById(s32 tag_id) { @@ -178,17 +125,17 @@ struct tag *tagFindById(s32 tag_id) return tag; } -s32 func0f095560(struct defaultobj *obj) +s32 objGetTagNum(struct defaultobj *obj) { - struct var8009d0b0 *thing = var8009d0b0; + struct tag *tag = g_TagsLinkedList; if (obj && (obj->hidden & OBJHFLAG_00000010)) { - while (thing) { - if (obj == thing->obj) { - return thing->unk04; + while (tag) { + if (obj == tag->obj) { + return tag->tagnum; } - thing = thing->next; + tag = tag->next; } } diff --git a/src/game/game_097ba0.c b/src/game/game_097ba0.c index ad7a3b6ba..b0b3859f3 100644 --- a/src/game/game_097ba0.c +++ b/src/game/game_097ba0.c @@ -8481,10 +8481,10 @@ glabel func0f09e144 /* f09e438: 3b2f003f */ xori $t7,$t9,0x3f /* f09e43c: accf0000 */ sw $t7,0x0($a2) /* f09e440: 8e4a15bc */ lw $t2,0x15bc($s2) -/* f09e444: 3c097f09 */ lui $t1,%hi(func0f0953cc) +/* f09e444: 3c097f09 */ lui $t1,%hi(tagsAllocatePtrs) /* f09e448: 3c087f09 */ lui $t0,%hi(tagFindById) /* f09e44c: 01ee6023 */ subu $t4,$t7,$t6 -/* f09e450: 252953cc */ addiu $t1,$t1,%lo(func0f0953cc) +/* f09e450: 252953cc */ addiu $t1,$t1,%lo(tagsAllocatePtrs) /* f09e454: 25055528 */ addiu $a1,$t0,%lo(tagFindById) /* f09e458: 020c8023 */ subu $s0,$s0,$t4 /* f09e45c: 240d0004 */ addiu $t5,$zero,0x4 diff --git a/src/game/game_167ae0.c b/src/game/game_167ae0.c index a365891e6..fb78403f0 100644 --- a/src/game/game_167ae0.c +++ b/src/game/game_167ae0.c @@ -358,7 +358,7 @@ void func0f167e7c(s32 stagenum) func0f00b510(); func0f00b820(stagenum); func0f00f174(stagenum); - func0f0953cc(); + tagsAllocatePtrs(); func0f013010(); func0f013130(); sparksReset(); diff --git a/src/game/propobj.c b/src/game/propobj.c index 5dde9e125..82e7e4a25 100644 --- a/src/game/propobj.c +++ b/src/game/propobj.c @@ -28136,7 +28136,7 @@ s32 objTick(struct prop *prop) model->anim = NULL; func00015be4(currentPlayerGetUnk174c(), model->unk0c, sp248); func00015da0(sp248, obj->realrot); - tagnum = func0f095560(obj); + tagnum = objGetTagNum(obj); if (tagnum >= 0) { numchrs = getNumChrs(); diff --git a/src/gvars/gvars.c b/src/gvars/gvars.c index e1efe496b..b6e61e5e0 100644 --- a/src/gvars/gvars.c +++ b/src/gvars/gvars.c @@ -15220,7 +15220,7 @@ u32 var8009d058 = 0; u32 var8009d05c = 0; struct objective *g_Objectives[MAX_OBJECTIVES] = {0}; u32 g_ObjectiveStatuses[MAX_OBJECTIVES] = {0}; -struct var8009d0b0 *var8009d0b0 = NULL; +struct tag *g_TagsLinkedList = NULL; struct objectivething *var8009d0b4 = NULL; struct criteria_roomentered *g_RoomEnteredCriterias = NULL; struct criteria_multiroomentered *g_MultiroomEnteredCriterias = NULL; diff --git a/src/include/game/game_095320.h b/src/include/game/game_095320.h index 5a3048cb7..8d4de15f7 100644 --- a/src/include/game/game_095320.h +++ b/src/include/game/game_095320.h @@ -6,8 +6,8 @@ u32 xorBaffbeff(u32 value); u32 xorBabeffff(u32 value); u32 xorBoobless(u32 value); -void func0f0953cc(void); -s32 func0f095560(struct defaultobj *obj); +void tagsAllocatePtrs(void); +s32 objGetTagNum(struct defaultobj *obj); s32 objectiveGetCount(void); u32 objectiveGetDifficultyBits(s32 index); s32 objectiveCheck(s32 index); diff --git a/src/include/gvars/gvars.h b/src/include/gvars/gvars.h index a458c04a7..08a69517c 100644 --- a/src/include/gvars/gvars.h +++ b/src/include/gvars/gvars.h @@ -576,7 +576,7 @@ extern struct stagesetup g_StageSetup; extern u8 *g_GeCreditsData; extern struct objective *g_Objectives[MAX_OBJECTIVES]; extern u32 g_ObjectiveStatuses[MAX_OBJECTIVES]; -extern struct var8009d0b0 *var8009d0b0; +extern struct tag *g_TagsLinkedList; extern struct objectivething *var8009d0b4; extern struct criteria_roomentered *g_RoomEnteredCriterias; extern struct criteria_multiroomentered *g_MultiroomEnteredCriterias; diff --git a/src/include/types.h b/src/include/types.h index 519886c34..fc06a7170 100644 --- a/src/include/types.h +++ b/src/include/types.h @@ -1423,7 +1423,7 @@ struct tag { /*0x00*/ u32 identifier; // always 0x00000016 /*0x04*/ u16 tagnum; /*0x06*/ s16 cmdoffset; - /*0x08*/ u32 unk08; + /*0x08*/ struct tag *next; /*0x0c*/ struct defaultobj *obj; }; @@ -6185,13 +6185,6 @@ struct healthdamagetype { s32 unk10; }; -struct var8009d0b0 { - u32 unk00; - u16 unk04; - struct var8009d0b0 *next; - struct defaultobj *obj; -}; - struct padlockeddoor { u32 unk00; struct doorobj *door; diff --git a/tools/patchpiracysums b/tools/patchpiracysums index 2351d33b3..b4f9f8c10 100755 --- a/tools/patchpiracysums +++ b/tools/patchpiracysums @@ -193,7 +193,7 @@ class Tool: self.patch(algo06, 'func0f167e7c', 'getEffectiveSlowMotion') self.patch(algo07, 'propAllocateEyespy', 'func0f167e7c') self.patch(algo08, 'chrConsiderGrenadeThrow', 'func0f15b534') - self.patch(algo09, 'func0f09e144', 'func0f0953cc') + self.patch(algo09, 'func0f09e144', 'tagsAllocatePtrs') self.patch(algo10, 'explosionAlertChrs', 'func0f084cf0') self.patch(algo11, 'func0f0069dc', 'func00015fd0') self.patch(algo12, 'func0f15c920', 'func0f0069dc')