From a6a08198ea4258d1473f826401a20730b2345797 Mon Sep 17 00:00:00 2001 From: eperdew Date: Sun, 20 Oct 2024 00:44:10 -0400 Subject: [PATCH] Decompile a handful of functions in mplib.c (#1483) * Decompile a few functions in mplib * Revert an errant header change * Add missing .sdata for mplib.c * Add a comment explaining the problems with an OSReport call. * Clean up argument names --- src/melee/mp/forward.h | 1 + src/melee/mp/mplib.c | 142 +++++++++++++++++++++++++++++++++++++++-- src/melee/mp/mplib.h | 7 +- src/melee/mp/types.h | 11 ++++ 4 files changed, 153 insertions(+), 8 deletions(-) diff --git a/src/melee/mp/forward.h b/src/melee/mp/forward.h index e262371933..4a098ac2a8 100644 --- a/src/melee/mp/forward.h +++ b/src/melee/mp/forward.h @@ -12,6 +12,7 @@ typedef struct mp_UnkStruct3 mp_UnkStruct3; typedef struct mp_UnkStruct4 mp_UnkStruct4; typedef struct mp_UnkStruct5 mp_UnkStruct5; typedef struct mp_UnkStruct6 mp_UnkStruct6; +typedef struct mp_UnkStruct7 mp_UnkStruct7; typedef struct mpisland mpisland; typedef void (*mpLib_Callback)(s32, s32, CollData*, s32, s32, f32); diff --git a/src/melee/mp/mplib.c b/src/melee/mp/mplib.c index 6c23521107..52ba2c950d 100644 --- a/src/melee/mp/mplib.c +++ b/src/melee/mp/mplib.c @@ -1,14 +1,27 @@ +#include "mp/forward.h" + #include "mplib.h" #include "mp/types.h" #include +#include +#include /* 4D64B0 */ static int mpLib_804D64B0; /* 4D64B4 */ static int mpLib_804D64B4; /* 4D64B8 */ static int mpLib_804D64B8; /* 4D64BC */ static mp_UnkStruct2* mpLib_804D64BC; /* 4D64C0 */ static int mpLib_804D64C0; +/* 4D64C4 */ static mp_UnkStruct7* mpLib_804D64C4; +/* 4D64C8 */ static s32 mpLib_804D64C8; +/* 4D64CC */ static s32 mpLib_804D64CC; +/* 4D64D0 */ static s32 mpLib_804D64D0; +/* 4D64D4 */ static s32 mpLib_804D64D4; +/* 4D64D8 */ static s32 mpLib_804D64D8; +/* 4D64DC */ static s32 mpLib_804D64DC; +/* 4D64E0 */ static s32 mpLib_804D64E0; +/* 4D64E4 */ static s32 mpLib_804D64E4; int mpLib_8004D164(void) { @@ -348,13 +361,113 @@ int mpLib_800588C8(void) return mpLib_804D64B0; } -/// #mpLib_800588D0 +void mpLib_800588D0(f32 left, f32 bottom, f32 right, f32 top) +{ + mp_UnkStruct7* curr = mpLib_804D64C4; + + while (curr != NULL) { + s32 flags = curr->x8; + + if ((flags & 0x10000) && !(flags & 0x40000)) { + if (flags & 0x400) { + curr->x8 = flags & 0xFFFFEFFF; + } else if ((left > curr->x18) || (right < curr->x10) || + (bottom > curr->x1C) || (top < curr->x14)) + { + curr->x8 |= 0x1000; + } else { + curr->x8 = flags & 0xFFFFEFFF; + } + } else { + curr->x8 |= 0x1000; + } + + curr = curr->next; + } + + mpLib_804D64B0 = 1; +} + +void mpLib_80058970(f32 arg0, f32 arg1, f32 arg2, f32 arg3) +{ + f32 right; + f32 left; + f32 bottom; + f32 var_f5; + + left = arg2; + bottom = arg3; + if (arg0 > left) { + right = arg0; + } else { + right = left; + left = arg0; + } + if (arg1 > bottom) { + var_f5 = arg1; + } else { + var_f5 = bottom; + bottom = arg1; + } + mpLib_800588D0(left, bottom, right, var_f5); +} + +void mpLib_800589D0(f32 arg0, f32 arg1, f32 arg2, f32 arg3, f32 arg4, f32 arg5, + f32 arg6, f32 arg7) +{ + f32 right; + f32 left; + f32 bottom; + f32 top; + + left = arg2; + bottom = arg3; + if (arg0 > left) { + right = arg0; + } else { + right = left; + left = arg0; + } + if (arg1 > bottom) { + top = arg1; + } else { + top = bottom; + bottom = arg1; + } + if (right < arg4) { + right = arg4; + } else if (left > arg4) { + left = arg4; + } + if (top < arg5) { + top = arg5; + } else if (bottom > arg5) { + bottom = arg5; + } + if (right < arg6) { + right = arg6; + } else if (left > arg6) { + left = arg6; + } + if (top < arg7) { + top = arg7; + } else if (bottom > arg7) { + bottom = arg7; + } + mpLib_800588D0(left, bottom, right, top); +} -/// #mpLib_80058970 +void mpLib_80058AA0(void) +{ + mp_UnkStruct7* curr = mpLib_804D64C4; -/// #mpLib_800589D0 + while (curr != NULL) { + curr->x8 = curr->x8 & 0xFFFFEFFF; + curr = curr->next; + } -/// #mpLib_80058AA0 + mpLib_804D64B0 = 0; +} /// #mpLib_80058ACC @@ -372,6 +485,25 @@ int mpLib_800588C8(void) /// #mpLib_8005A220 -/// #mpLib_8005A2DC +void mpLib_8005A2DC(void) +{ + f32 temp_f1; + + mpLib_800590F4(); + temp_f1 = mpLib_80059E60(); + if (mpLib_804D64D0 == 0) { + mpLib_804D64D0 = 1; + // Should the following be... + // + // "]ap coll unddr=%d upper=%d left=%d right=%d bbox-%d" + // + // instead? It looks like a clear typo on upper=$d, as suggested by the + // number of arguments. + OSReport("]ap coll unddr=%d upper=$d left=%d rhght=%d bbox-%d", + mpLib_804D64D4, mpLib_804D64D8, mpLib_804D64DC, + mpLib_804D64E0, mpLib_804D64E4); + } + HSD_StateInvalidate(-1); +} /// #mpLib_8005A340 diff --git a/src/melee/mp/mplib.h b/src/melee/mp/mplib.h index fd7506d03c..d67378a043 100644 --- a/src/melee/mp/mplib.h +++ b/src/melee/mp/mplib.h @@ -131,15 +131,16 @@ /* 0588C8 */ int mpLib_800588C8(void); /* 0588D0 */ void mpLib_800588D0(float left, float bottom, float right, float top); -/* 058970 */ UNK_RET mpLib_80058970(UNK_PARAMS); -/* 0589D0 */ UNK_RET mpLib_800589D0(UNK_PARAMS); +/* 058970 */ void mpLib_80058970(f32 arg8, f32 arg9, f32 argA, f32 argB); +/* 0589D0 */ void mpLib_800589D0(f32 arg8, f32 arg9, f32 argA, f32 argB, + f32 argC, f32 argD, f32 argE, f32 argF); /* 058AA0 */ void mpLib_80058AA0(void); /* 058ACC */ UNK_RET mpLib_80058ACC(UNK_PARAMS); /* 058B5C */ UNK_RET mpLib_80058B5C(UNK_PARAMS); /* 0590F4 */ UNK_RET mpLib_800590F4(UNK_PARAMS); /* 059404 */ UNK_RET mpLib_80059404(UNK_PARAMS); /* 059554 */ UNK_RET mpLib_80059554(UNK_PARAMS); -/* 059E60 */ UNK_RET mpLib_80059E60(UNK_PARAMS); +/* 059E60 */ float mpLib_80059E60(UNK_PARAMS); /* 059FE0 */ UNK_RET mpLib_80059FE0(UNK_PARAMS); /* 05A220 */ UNK_RET mpLib_8005A220(UNK_PARAMS); /* 05A2DC */ UNK_RET mpLib_8005A2DC(UNK_PARAMS); diff --git a/src/melee/mp/types.h b/src/melee/mp/types.h index 1b17fd5865..6abe636cf7 100644 --- a/src/melee/mp/types.h +++ b/src/melee/mp/types.h @@ -70,4 +70,15 @@ struct mp_UnkStruct6 { /* +4 */ short* x4; }; +struct mp_UnkStruct7 { + /* +0 */ struct mp_UnkStruct7* next; + /* +4 */ s32 x4; + /* +8 */ s32 x8; + /* +C */ u8 xC[0x10 - 0xC]; + /* +10 */ float x10; + /* +14 */ float x14; + /* +18 */ float x18; + /* +1C */ float x1C; +}; + #endif