From 7e241054885a662c4a4c658a34a864890d6a5515 Mon Sep 17 00:00:00 2001 From: Unnunu Date: Thu, 3 Jul 2025 13:05:56 +0300 Subject: [PATCH] match func_8006017C (#659) --- README.md | 12 +++--- include/structs.h | 23 +++-------- src/object_models.c | 96 ++++++++++++++++++++++----------------------- src/objects.c | 24 ++++++------ 4 files changed, 72 insertions(+), 83 deletions(-) diff --git a/README.md b/README.md index 2fa97c11..dba6f5c5 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ All versions are supported, and the US 1.0 version (SHA1 = 0cb115d8716dbbc2922fd As of July 3, 2025, this is our current score: -    Decomp progress: 96.21% +    Decomp progress: 96.43%     Documentation progress: 62.00% @@ -121,16 +121,16 @@ As of July 3, 2025, this is our current score: ``` =============================================================== ADVENTURE ONE (ASM -> C Decompilation) - ------------ 96.21% Complete (96.91% NON_MATCHING) ------------ - # Decompiled functions: 1938 - # GLOBAL_ASM remaining: 14 + ------------ 96.43% Complete (97.13% NON_MATCHING) ------------ + # Decompiled functions: 1939 + # GLOBAL_ASM remaining: 13 # NON_MATCHING functions: 4 - # NON_EQUIVALENT WIP functions: 10 + # NON_EQUIVALENT WIP functions: 9 ------------------------- Game Status ------------------------- Balloons: 46/47, Keys: 4/4, Trophies: 4/5 T.T. Amulets: 4/4, Wizpig Amulets: 4/4 --------------------------------------------------------------- - We are collecting silver coins in Star City. (4/8 silver coins) + We are collecting silver coins in Star City. (5/8 silver coins) =============================================================== ADVENTURE TWO (Cleanup & Documentation) ----------------------- 62.00% Complete ----------------------- diff --git a/include/structs.h b/include/structs.h index 242b2015..64c5126f 100644 --- a/include/structs.h +++ b/include/structs.h @@ -636,23 +636,17 @@ typedef struct ObjectModel_44 { /* 0x04 */ s32 animLength; // Animation length is the result of 16-frame length keyframes. } ObjectModel_44; -typedef struct ObjectModel_C { - u16 unk0[4]; -} ObjectModel_C; - -typedef struct ObjectModel_10 { - f32 A; - f32 B; - f32 C; - f32 D; -} ObjectModel_10; +typedef struct CollisionFacetPlanes { + u16 basePlaneIndex; // Index of the triangle's main collision plane + u16 edgeBisectorPlane[3]; // Indices of edge bisector planes for triangle edges +} CollisionFacetPlanes; typedef struct ObjectModel { /* 0x00 */ TextureInfo *textures; /* 0x04 */ Vertex *vertices; /* 0x08 */ Triangle *triangles; - /* 0x0C */ ObjectModel_C *unkC; - /* 0x10 */ ObjectModel_10 *unk10; + /* 0x0C */ CollisionFacetPlanes *unkC; + /* 0x10 */ f32 *unk10; /* 0x14 */ s16 *unk14; /* 0x18 */ s16 unk18; /* 0x1A */ s16 unk1A; @@ -696,11 +690,6 @@ typedef struct ModelInstance { /* 0x20 */ s8 animUpdateTimer; } ModelInstance; -typedef struct CollisionFacetPlanes { - u16 basePlaneIndex; // Index of the triangle's main collision plane - u16 edgeBisectorPlane[3]; // Indices of edge bisector planes for triangle edges -} CollisionFacetPlanes; - /* Size: 0x44 bytes */ typedef struct LevelModelSegment { /* 0x00 */ Vertex *vertices; diff --git a/src/object_models.c b/src/object_models.c index 43842527..c726c76a 100644 --- a/src/object_models.c +++ b/src/object_models.c @@ -383,27 +383,26 @@ void free_model_data(ObjectModel *mdl) { mempool_free(mdl); } -// https://decomp.me/scratch/VJ34p -#ifdef NON_EQUIVALENT void func_8006017C(ObjectModel *arg0) { - s32 facesOffset; // v1 - s32 verticesOffset; // s5 - s32 nextFacesOffset; // spF4 + s32 facesOffset; + s32 verticesOffset; + s32 nextFacesOffset; s32 s4; - s32 i; // spEC - s32 j; // s6 + s32 i; + s32 j; Vertex *v; s32 v1, v2; - f32 x5, y5, z5; // f20, f24, f26 - f32 x1, y1, z1; // spCC, spC8, spC4 - f32 x2, y2, z2; // f14, f16, f18 - f32 x3, y3, z3; // f22, spB0, f0 - f32 nx, ny, nz; // spA8, spA4, spA0 + f32 x5, y5, z5; + f32 x1, y1, z1; + f32 x2, y2, z2; + f32 x3, y3, z3; + f32 nx, ny, nz; f32 mag; s32 s3; s32 k; s32 l; - s32 temp1, temp2, temp3; + s32 index; + s32 temp1, temp2; if (arg0->unkC != NULL) { return; @@ -419,13 +418,13 @@ void func_8006017C(ObjectModel *arg0) { s4 += nextFacesOffset - facesOffset; } - arg0->unkC = (ObjectModel_C *) mempool_alloc(s4 * sizeof(ObjectModel_C), COLOUR_TAG_RED); - if (v) {} // FAKE + arg0->unkC = (CollisionFacetPlanes *) mempool_alloc(s4 * sizeof(CollisionFacetPlanes), COLOUR_TAG_RED); + if (arg0->unkC == NULL) { return; } - arg0->unk10 = (ObjectModel_10 *) mempool_alloc(s4 * 64, COLOUR_TAG_RED); + arg0->unk10 = (f32 *) mempool_alloc(s4 * 64, COLOUR_TAG_RED); if (arg0->unk10 == NULL) { mempool_free(arg0->unkC); arg0->unkC = NULL; @@ -468,15 +467,16 @@ void func_8006017C(ObjectModel *arg0) { nz /= mag; } - arg0->unk10[s4].A = nx; - arg0->unk10[s4].B = ny; - arg0->unk10[s4].C = nz; - arg0->unk10[s4].D = -(x1 * nx + y1 * ny + z1 * nz); + temp1 = s4 << 2; + *(arg0->unk10 + temp1 + 0) = nx; + *(arg0->unk10 + temp1 + 1) = ny; + *(arg0->unk10 + temp1 + 2) = nz; + *(arg0->unk10 + temp1 + 3) = -(x1 * nx + y1 * ny + z1 * nz); - arg0->unkC[s4].unk0[0] = s4; - arg0->unkC[s4].unk0[1] = s4; - arg0->unkC[s4].unk0[2] = s4; - arg0->unkC[s4].unk0[3] = s4; + arg0->unkC[s4].basePlaneIndex = s4; + arg0->unkC[s4].edgeBisectorPlane[0] = s4; + arg0->unkC[s4].edgeBisectorPlane[1] = s4; + arg0->unkC[s4].edgeBisectorPlane[2] = s4; s4++; } @@ -495,10 +495,11 @@ void func_8006017C(ObjectModel *arg0) { nextFacesOffset = facesOffset - 1; } - for (j = facesOffset; j < nextFacesOffset; j++) { - nx = arg0->unk10[arg0->unkC[s3].unk0[0]].A; - ny = arg0->unk10[arg0->unkC[s3].unk0[0]].B; - nz = arg0->unk10[arg0->unkC[s3].unk0[0]].C; + for (j = facesOffset; j < nextFacesOffset; j++, s3++) { + index = arg0->unkC[s3].basePlaneIndex << 2; + nx = *(arg0->unk10 + index + 0); + ny = *(arg0->unk10 + index + 1); + nz = *(arg0->unk10 + index + 2); for (k = 0; k < 3; k++) { l = k + 1; @@ -506,19 +507,20 @@ void func_8006017C(ObjectModel *arg0) { l = 0; } - v1 = arg0->triangles[j].verticesArray[1 + k]; - v2 = arg0->triangles[j].verticesArray[1 + l]; + v1 = arg0->triangles[j].verticesArray[1 + k] + verticesOffset; + v2 = arg0->triangles[j].verticesArray[1 + l] + verticesOffset; - x5 = nx + arg0->unk10[arg0->unkC[s3].unk0[l + 1]].A; - y5 = ny + arg0->unk10[arg0->unkC[s3].unk0[l + 1]].B; - z5 = nz + arg0->unk10[arg0->unkC[s3].unk0[l + 1]].C; + index = arg0->unkC[s3].edgeBisectorPlane[k] << 2; + x5 = nx + *(arg0->unk10 + index + 0); + y5 = ny + *(arg0->unk10 + index + 1); + z5 = nz + *(arg0->unk10 + index + 2); - v = &arg0->vertices[v1 + verticesOffset]; + v = &arg0->vertices[v1]; x1 = v->x; y1 = v->y; z1 = v->z; - v = &arg0->vertices[v2 + verticesOffset]; + v = &arg0->vertices[v2]; x2 = v->x; y2 = v->y; z2 = v->z; @@ -538,21 +540,19 @@ void func_8006017C(ObjectModel *arg0) { z5 /= mag; } - arg0->unkC[s3].unk0[k + 1] = s4; - arg0->unk10[s4].A = x5; - arg0->unk10[s4].B = y5; - arg0->unk10[s4].C = z5; - arg0->unk10[s4].D = -(x1 * x5 + y1 * y5 + z1 * z5); + arg0->unkC[s3].edgeBisectorPlane[k] = s4; + + temp2 = s4 << 2; + *(arg0->unk10 + temp2 + 0) = x5; + *(arg0->unk10 + temp2 + 1) = y5; + *(arg0->unk10 + temp2 + 2) = z5; + *(arg0->unk10 + temp2 + 3) = -(x1 * x5 + y1 * y5 + z1 * z5); + s4++; } - - s3++; } } } -#else -#pragma GLOBAL_ASM("asm/nonmatchings/object_models/func_8006017C.s") -#endif void func_80060910(ObjectModel *mdl) { s32 count; @@ -579,7 +579,7 @@ void func_80060910(ObjectModel *mdl) { } for (triIndex = startTri; triIndex < endTri; triIndex++, count++) { - mdl->unkC[count].unk0[0] = count; + mdl->unkC[count].basePlaneIndex = count; for (vertIndex = 0; vertIndex < 3; vertIndex++) { nextVertIndex = vertIndex + 1; @@ -592,9 +592,9 @@ void func_80060910(ObjectModel *mdl) { result = func_80060AC8(mdl, triIndex, vertIndex0, vertIndex1, &sp5C, &sp60); if (result != -1) { - mdl->unkC[count].unk0[1 + vertIndex] = result; + mdl->unkC[count].edgeBisectorPlane[vertIndex] = result; } else { - mdl->unkC[count].unk0[1 + vertIndex] = count; + mdl->unkC[count].edgeBisectorPlane[vertIndex] = count; } } } diff --git a/src/objects.c b/src/objects.c index 5e3d7140..d2c45a3e 100644 --- a/src/objects.c +++ b/src/objects.c @@ -5477,7 +5477,7 @@ s32 func_80017A18(ObjectModel *arg0, s32 arg1, s32 *arg2, f32 *arg3, f32 *arg4, s32 k; s32 spF8; s32 var_t4; - ObjectModel_10 *var_a0; + f32 *var_a0; f32 spE4; f32 spDC; f32 spD8; @@ -5499,8 +5499,8 @@ s32 func_80017A18(ObjectModel *arg0, s32 arg1, s32 *arg2, f32 *arg3, f32 *arg4, f32 temp_f26; f32 var_f2; f32 var_f30; - ObjectModel_10 *temp_t0; - ObjectModel_10 *temp_v0; + f32 *temp_t0; + f32 *temp_v0; s32 redoLoop; s32 pad1; @@ -5519,11 +5519,11 @@ s32 func_80017A18(ObjectModel *arg0, s32 arg1, s32 *arg2, f32 *arg3, f32 *arg4, do { redoLoop = FALSE; for (j = 0; j < arg0->unk32; j++) { - temp_v0 = &temp_t0[arg0->unkC->unk0[j]]; - temp_f26 = temp_v0->B; - sp74 = temp_v0->A; - temp_f12 = temp_v0->C; - temp_f10 = temp_v0->D; + temp_v0 = &temp_t0[arg0->unkC[j].basePlaneIndex]; + temp_f26 = temp_v0[1]; + sp74 = temp_v0[0]; + temp_f12 = temp_v0[2]; + temp_f10 = temp_v0[3]; spE4 = sp74; spDC = temp_f12; sp64 = spA0; @@ -5544,10 +5544,10 @@ s32 func_80017A18(ObjectModel *arg0, s32 arg1, s32 *arg2, f32 *arg3, f32 *arg4, } for (k = 0; (k < 3) && (var_a2 == 1); k++) { - temp_v0 = &temp_t0[arg0->unkC->unk0[k + 1]]; - if (((temp_v0->A * (((spBC - sp60) * var_f2) + spA4)) + - (temp_v0->B * (((var_f30 - sp64) * var_f2) + spA0)) + - (temp_v0->C * (((spB4 - sp68) * var_f2) + sp9C)) + temp_v0->D) > 4.0f) { + temp_v0 = &temp_t0[arg0->unkC->edgeBisectorPlane[k]]; + if (((temp_v0[0] * (((spBC - sp60) * var_f2) + spA4)) + + (temp_v0[1] * (((var_f30 - sp64) * var_f2) + spA0)) + + (temp_v0[2] * (((spB4 - sp68) * var_f2) + sp9C)) + temp_v0[3]) > 4.0f) { var_a2 = 0; } }