From 8957a6a29e40b56d9720894310035bad64e03558 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Wed, 10 Feb 2021 00:40:06 +1000 Subject: [PATCH] Decompile coverUnpack --- src/game/chr/chraction.c | 12 ++--- src/game/game_013ee0.c | 2 +- src/game/game_19aa80.c | 4 +- src/game/pad.c | 98 ++++++++++------------------------------ src/include/game/pad.h | 2 +- src/include/types.h | 2 +- 6 files changed, 36 insertions(+), 84 deletions(-) diff --git a/src/game/chr/chraction.c b/src/game/chr/chraction.c index a7545bd60..e0e45aa79 100644 --- a/src/game/chr/chraction.c +++ b/src/game/chr/chraction.c @@ -513,7 +513,7 @@ bool chrFaceCover(struct chrdata *chr) { struct cover cover; - if (!coverLoad(chr->cover, &cover)) { + if (!coverUnpack(chr->cover, &cover)) { return false; } @@ -25795,7 +25795,7 @@ bool chrCheckCoverOutOfSight(struct chrdata *chr, s32 covernum, bool arg2) bool targetcanseecover; // @bug: Should be >= coverGetCount() - if (covernum < 0 || covernum > coverGetCount() || !coverLoad(covernum, &cover)) { + if (covernum < 0 || covernum > coverGetCount() || !coverUnpack(covernum, &cover)) { return false; } @@ -25886,7 +25886,7 @@ glabel func0f04ba34 /* f04bb18: afa400c0 */ sw $a0,0xc0($sp) /* f04bb1c: 02002025 */ or $a0,$s0,$zero .L0f04bb20: -/* f04bb20: 0fc458b8 */ jal coverLoad +/* f04bb20: 0fc458b8 */ jal coverUnpack /* f04bb24: 27a50098 */ addiu $a1,$sp,0x98 /* f04bb28: 504000b0 */ beqzl $v0,.L0f04bdec /* f04bb2c: 8fae0078 */ lw $t6,0x78($sp) @@ -26300,7 +26300,7 @@ glabel chrAssignCoverAwayFromDanger /* f04c0d8: 27b20064 */ addiu $s2,$sp,0x64 /* f04c0dc: 02002025 */ or $a0,$s0,$zero .L0f04c0e0: -/* f04c0e0: 0fc458b8 */ jal coverLoad +/* f04c0e0: 0fc458b8 */ jal coverUnpack /* f04c0e4: 02402825 */ or $a1,$s2,$zero /* f04c0e8: 5040003e */ beqzl $v0,.L0f04c1e4 /* f04c0ec: 26100001 */ addiu $s0,$s0,0x1 @@ -26481,7 +26481,7 @@ glabel chrAssignCoverAwayFromDanger // guNormalize(&vecfromdanger[0], &y, &vecfromdanger[1]); // // for (i = 0; i < numcovers; i++) { -// if (coverLoad(i, &cover) +// if (coverUnpack(i, &cover) // && !coverIsInUse(i) // && !(cover.pos->y > ymax) // && !coverHasSomeFlags(&cover)) { @@ -26526,7 +26526,7 @@ s16 chrGoToCover(struct chrdata *chr, u8 speed) return 0; } - if (chrIsReadyForOrders(chr) && chr->cover != -1 && coverLoad(chr->cover, &cover)) { + if (chrIsReadyForOrders(chr) && chr->cover != -1 && coverUnpack(chr->cover, &cover)) { chrGoToPos(chr, cover.pos, &cover.room, speed); return chr->cover; } diff --git a/src/game/game_013ee0.c b/src/game/game_013ee0.c index 0cb4c1bce..a1b6d9bdc 100644 --- a/src/game/game_013ee0.c +++ b/src/game/game_013ee0.c @@ -386,7 +386,7 @@ glabel func0f0142e8 /* f014418: 02802025 */ or $a0,$s4,$zero /* f01441c: 03324021 */ addu $t0,$t9,$s2 /* f014420: a5000000 */ sh $zero,0x0($t0) -/* f014424: 0fc458b8 */ jal coverLoad +/* f014424: 0fc458b8 */ jal coverUnpack /* f014428: 27a508dc */ addiu $a1,$sp,0x8dc /* f01442c: 104000c2 */ beqz $v0,.L0f014738 /* f014430: 8fa908e0 */ lw $t1,0x8e0($sp) diff --git a/src/game/game_19aa80.c b/src/game/game_19aa80.c index ca39c9713..f518c7306 100644 --- a/src/game/game_19aa80.c +++ b/src/game/game_19aa80.c @@ -143,7 +143,7 @@ glabel func0f19ab70 /* f19abdc: 0040f025 */ or $s8,$v0,$zero /* f19abe0: 02402025 */ or $a0,$s2,$zero .L0f19abe4: -/* f19abe4: 0fc458b8 */ jal coverLoad +/* f19abe4: 0fc458b8 */ jal coverUnpack /* f19abe8: 27a50158 */ addiu $a1,$sp,0x158 /* f19abec: 50400027 */ beqzl $v0,.L0f19ac8c /* f19abf0: 26520001 */ addiu $s2,$s2,0x1 @@ -299,7 +299,7 @@ glabel func0f19ab70 /* f19ae0c: 27aa016c */ addiu $t2,$sp,0x16c /* f19ae10: 01aa8021 */ addu $s0,$t5,$t2 /* f19ae14: 8e040000 */ lw $a0,0x0($s0) -/* f19ae18: 0fc458b8 */ jal coverLoad +/* f19ae18: 0fc458b8 */ jal coverUnpack /* f19ae1c: 27a50158 */ addiu $a1,$sp,0x158 /* f19ae20: 8fae0158 */ lw $t6,0x158($sp) /* f19ae24: 8faf021c */ lw $t7,0x21c($sp) diff --git a/src/game/pad.c b/src/game/pad.c index dfaddfa74..876451d41 100644 --- a/src/game/pad.c +++ b/src/game/pad.c @@ -610,85 +610,37 @@ s32 coverGetCount(void) return g_PadsFile[1]; } -GLOBAL_ASM( -glabel coverLoad -/* f1162e0: 3c0e800a */ lui $t6,%hi(g_PadsFile) -/* f1162e4: 8dce2350 */ lw $t6,%lo(g_PadsFile)($t6) -/* f1162e8: 00a03025 */ or $a2,$a1,$zero -/* f1162ec: 8dcf0004 */ lw $t7,0x4($t6) -/* f1162f0: 008f082a */ slt $at,$a0,$t7 -/* f1162f4: 10200008 */ beqz $at,.L0f116318 -/* f1162f8: 00000000 */ nop -/* f1162fc: 04800006 */ bltz $a0,.L0f116318 -/* f116300: 3c03800a */ lui $v1,%hi(g_StageSetup+0x8) -/* f116304: 8c63d038 */ lw $v1,%lo(g_StageSetup+0x8)($v1) -/* f116308: 3c09800a */ lui $t1,%hi(g_CoverFlags) -/* f11630c: 25292360 */ addiu $t1,$t1,%lo(g_CoverFlags) -/* f116310: 14600003 */ bnez $v1,.L0f116320 -/* f116314: 309800ff */ andi $t8,$a0,0xff -.L0f116318: -/* f116318: 03e00008 */ jr $ra -/* f11631c: 00001025 */ or $v0,$zero,$zero -.L0f116320: -/* f116320: 0018c8c0 */ sll $t9,$t8,0x3 -/* f116324: 0338c823 */ subu $t9,$t9,$t8 -/* f116328: 0019c880 */ sll $t9,$t9,0x2 -/* f11632c: 00792821 */ addu $a1,$v1,$t9 -/* f116330: 24aa000c */ addiu $t2,$a1,0xc -/* f116334: acc50000 */ sw $a1,0x0($a2) -/* f116338: acca0004 */ sw $t2,0x4($a2) -/* f11633c: 8d2b0000 */ lw $t3,0x0($t1) -/* f116340: 00043840 */ sll $a3,$a0,0x1 -/* f116344: 94ad0018 */ lhu $t5,0x18($a1) -/* f116348: 01674021 */ addu $t0,$t3,$a3 -/* f11634c: 950c0000 */ lhu $t4,0x0($t0) -/* f116350: 3c0a800a */ lui $t2,%hi(g_CoverRooms) -/* f116354: 00045880 */ sll $t3,$a0,0x2 -/* f116358: 018d7025 */ or $t6,$t4,$t5 -/* f11635c: a50e0000 */ sh $t6,0x0($t0) -/* f116360: 8d2f0000 */ lw $t7,0x0($t1) -/* f116364: 240effff */ addiu $t6,$zero,-1 -/* f116368: 24020001 */ addiu $v0,$zero,0x1 -/* f11636c: 01e7c021 */ addu $t8,$t7,$a3 -/* f116370: 97190000 */ lhu $t9,0x0($t8) -/* f116374: a4d9000c */ sh $t9,0xc($a2) -/* f116378: 8d4a2364 */ lw $t2,%lo(g_CoverRooms)($t2) -/* f11637c: 014b6021 */ addu $t4,$t2,$t3 -/* f116380: 8d8d0000 */ lw $t5,0x0($t4) -/* f116384: a4ce000a */ sh $t6,0xa($a2) -/* f116388: a4cd0008 */ sh $t5,0x8($a2) -/* f11638c: 03e00008 */ jr $ra -/* f116390: 00000000 */ nop -); +bool coverUnpack(s32 covernum, struct cover *cover) +{ + struct coverdefinition *def; -// Mismatch because it swaps the addu arguments when calculating def -//bool coverLoad(s32 covernum, struct cover *cover) -//{ -// struct coverdefinition *def; -// -// if (covernum >= g_PadsFile[1] || covernum < 0 || !g_StageSetup.cover) { -// return false; -// } -// -// // Possible @bug: Cast to u8 means it would load the position from an -// // incorrect cover if covernum is greater than 255. -// def = &g_StageSetup.cover[(u8)covernum]; -// cover->pos = &def->pos; -// cover->look = &def->look; -// g_CoverFlags[covernum] |= def->flags; -// cover->flags = g_CoverFlags[covernum]; -// cover->room = g_CoverRooms[covernum]; -// cover->unk0a = -1; -// -// return true; -//} + if (covernum >= g_PadsFile[1] || covernum < 0 || !g_StageSetup.cover) { + return false; + } + + // @bug: Cast to u8 means it loads the pos, look and flags + // from an incorrect cover if covernum is greater than 255. + def = g_StageSetup.cover; + def += (u8)covernum; + + cover->pos = &def->pos; + cover->look = &def->look; + + g_CoverFlags[covernum] |= def->flags; + + cover->flags = g_CoverFlags[covernum]; + cover->room = g_CoverRooms[covernum]; + cover->unk0a = -1; + + return true; +} u16 getVar800a236c(void) { return var800a236c; } -bool coverLoadByIndex(s32 index, struct cover *cover) +bool coverUnpackByIndex(s32 index, struct cover *cover) { // Probable @bug: last check should be index >= var800a236c // This function is never called though. @@ -696,7 +648,7 @@ bool coverLoadByIndex(s32 index, struct cover *cover) return false; } - if (coverLoad(g_CoverNums[index], cover)) { + if (coverUnpack(g_CoverNums[index], cover)) { return true; } diff --git a/src/include/game/pad.h b/src/include/game/pad.h index 602c5f932..3cce74b3d 100644 --- a/src/include/game/pad.h +++ b/src/include/game/pad.h @@ -11,7 +11,7 @@ void padCopyBboxFromPad(s32 padnum, struct pad *src); void padSetFlag(s32 padnum, u32 flag); void padUnsetFlag(s32 padnum, u32 flag); s32 coverGetCount(void); -bool coverLoad(s32 covernum, struct cover *cover); +bool coverUnpack(s32 covernum, struct cover *cover); bool coverIsInUse(s32 covernum); void coverSetInUse(s32 covernum, bool enable); void coverSetFlag(s32 covernum, u32 flag); diff --git a/src/include/types.h b/src/include/types.h index 1df2c85a7..c45839cc5 100644 --- a/src/include/types.h +++ b/src/include/types.h @@ -2861,7 +2861,7 @@ struct cover { struct stagesetup { /*0x00*/ struct waypoint *waypoints; /*0x04*/ struct waygroup *waygroups; - /*0x08*/ struct coverdefinition *cover; + /*0x08*/ void *cover; /*0x0c*/ s32 *intro; /*0x10*/ u32 *props; /*0x14*/ struct path *paths;