From 65b1b191376eb73cc6e420a8057155ce12141da3 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sun, 23 Jan 2022 09:52:35 +1000 Subject: [PATCH] Attempt to decompile func0f0f1d6c --- src/game/game_0f09f0.c | 114 +++++++++++++++++++++++++-------- src/game/menu/items.c | 60 ++++++++--------- src/include/constants.h | 18 ++++++ src/include/game/game_0f09f0.h | 2 +- src/include/types.h | 10 +-- 5 files changed, 142 insertions(+), 62 deletions(-) diff --git a/src/game/game_0f09f0.c b/src/game/game_0f09f0.c index 0b556efa0..41ea16a37 100644 --- a/src/game/game_0f09f0.c +++ b/src/game/game_0f09f0.c @@ -1627,38 +1627,38 @@ char *menuResolveDialogTitle(struct menudialog *dialog) return menuResolveText(dialog->title, dialog); } -void func0f0f15a4(u8 *arg0, u32 *arg1) +void func0f0f15a4(struct menuitem *item, s32 *arg1) { - switch (*arg0) { - case 8: - case 9: - case 14: - case 20: - case 24: + switch (item->type) { + case MENUITEMTYPE_SLIDER: + case MENUITEMTYPE_CHECKBOX: + case MENUITEMTYPE_RANKING: + case MENUITEMTYPE_14: + case MENUITEMTYPE_18: *arg1 = 1; break; #if VERSION < VERSION_PAL_FINAL - case 5: + case MENUITEMTYPE_SCROLLABLE: #endif - case 23: - case 25: + case MENUITEMTYPE_MARQUEE: + case MENUITEMTYPE_CONTROLLER: *arg1 = 2; break; - case 2: + case MENUITEMTYPE_LIST: #if VERSION >= VERSION_PAL_FINAL - case 5: + case MENUITEMTYPE_SCROLLABLE: #endif *arg1 = 3; break; - case 12: + case MENUITEMTYPE_DROPDOWN: *arg1 = 4; break; - case 15: + case MENUITEMTYPE_PLAYERSTATS: *arg1 = 5; break; - case 13: - case 16: - case 22: + case MENUITEMTYPE_KEYBOARD: + case MENUITEMTYPE_10: + case MENUITEMTYPE_16: *arg1 = 3; break; } @@ -3583,6 +3583,68 @@ glabel func0f0f1d6c ); #endif +// Mismatch: Goal stores index660 in v0 while the below stores it in v0 +// initially but then all the increments in v1, resulting in one less +// instruction. Removing the + 1 from the assign to frame->unk04 or +// menu->unk6d8 causes the below to use v0 only, which is a closer +// match but is functionally incorrect. +//void func0f0f1d6c(struct menudialog *dialog, struct menuframe *frame, struct menu *menu) +//{ +// s32 index660 = menu->unk6d8 - 1; // 64 +// s32 index4fc = menu->unk65c; +// s32 numitems = 0; +// s32 numblocksthisitem; // 58 +// struct menuitem *item = dialog->items; +// s16 totalblocksused = menu->unk81c; +// +// frame->unk05 = 0; +// frame->unk04 = index660 + 1; +// frame->unk06 = totalblocksused; +// +// if (item) { +// bool append = true; +// +// while (item->type != MENUITEMTYPE_END) { +// if (item->flags & MENUITEMFLAG_00000001) { +// append = true; +// } +// +// if (append) { +// frame->unk05++; +// index660++; +// +// menu->unk660[index660].unk00 = 0; +// menu->unk660[index660].unk02 = 0; +// menu->unk660[index660].unk04 = 0; +// menu->unk660[index660].unk08 = 0; +// menu->unk660[index660].unk06 = index4fc; +// +// append = false; +// } +// +// numblocksthisitem = -1; +// func0f0f15a4(item, &numblocksthisitem); +// +// if (numblocksthisitem != -1) { +// menu->unk4fc[index4fc].blockindex = totalblocksused; +// totalblocksused += (s16)numblocksthisitem; +// } else { +// menu->unk4fc[index4fc].blockindex = -1; +// } +// +// menu->unk4fc[index4fc].itemindex = numitems; +// menu->unk660[index660].unk08++; +// index4fc++; +// item++; +// numitems++; +// } +// } +// +// menu->unk6d8 = index660 + 1; +// menu->unk65c = index4fc; +// menu->unk81c = totalblocksused; +//} + #if VERSION >= VERSION_NTSC_1_0 GLOBAL_ASM( glabel func0f0f1ef4 @@ -4497,11 +4559,11 @@ bool menuIsItemDisabled(struct menuitem *item, struct menuframe *frame) s16 sp2c; u32 stack[2]; - if (item->param1 & 0x00000400) { + if (item->flags & MENUITEMFLAG_00000400) { return true; } - if (mpIsPlayerLockedOut(g_MpPlayerNum) && item->param1 & 0x00040000) { + if (mpIsPlayerLockedOut(g_MpPlayerNum) && item->flags & MENUITEMFLAG_00040000) { return true; } @@ -4510,7 +4572,7 @@ bool menuIsItemDisabled(struct menuitem *item, struct menuframe *frame) } if (item->handler - && (item->param1 & 0x00000004) == 0 + && (item->flags & MENUITEMFLAG_00000004) == 0 && item->handler(MENUOP_CHECKDISABLED, item, &sp30)) { return true; } @@ -4563,7 +4625,7 @@ struct menuitem *func0f0f26fc(s32 arg0, s32 arg1, struct menudialog *dialog, s32 s32 i; for (i = 0, sum = 0; !done && i < g_Menus[g_MpPlayerNum].unk660[arg1].unk08; index++, i++) { - struct menuitem *item = &dialog->items[g_Menus[g_MpPlayerNum].unk4fc[index].unk02]; + struct menuitem *item = &dialog->items[g_Menus[g_MpPlayerNum].unk4fc[index].itemindex]; if (func0f0f2674(item, frame, 1)) { result = item; @@ -5022,7 +5084,7 @@ void menuOpenDialog(struct menudialog *dialog, struct menuframe *frame, struct m while (item->type != MENUITEMTYPE_END) { if (item->handler - && (item->param1 & 0x04) == 0 + && (item->flags & MENUITEMFLAG_00000004) == 0 && item->handler(MENUOP_CHECKPREFOCUSED, item, &data1)) { frame->focuseditem = item; } @@ -5033,7 +5095,7 @@ void menuOpenDialog(struct menudialog *dialog, struct menuframe *frame, struct m // Run focus handler if (frame->focuseditem && frame->focuseditem->handler - && (frame->focuseditem->param1 & 0x04) == 0) { + && (frame->focuseditem->flags & MENUITEMFLAG_00000004) == 0) { frame->focuseditem->handler(MENUOP_FOCUS, frame->focuseditem, &data2); } @@ -22961,11 +23023,11 @@ void func0f0fa574(struct menuframe *frame) for (j = 0; j < menu->unk660[index1].unk08; j++) { s32 index2 = menu->unk660[index1].unk06 + j; - struct menuitem *item = &frame->dialog->items[menu->unk4fc[index2].unk02]; + struct menuitem *item = &frame->dialog->items[menu->unk4fc[index2].itemindex]; union menuitemdata *data = NULL; - if (menu->unk4fc[index2].handlerdataindex != -1) { - data = (union menuitemdata *)&menu->handlerdatabuffer[menu->unk4fc[index2].handlerdataindex]; + if (menu->unk4fc[index2].blockindex != -1) { + data = (union menuitemdata *)&menu->blocks[menu->unk4fc[index2].blockindex]; } menuInitItem(item, data); diff --git a/src/game/menu/items.c b/src/game/menu/items.c index b0b64a4e5..f4dbc5cbe 100644 --- a/src/game/menu/items.c +++ b/src/game/menu/items.c @@ -2973,7 +2973,7 @@ bool menuTickItemList(struct menuitem *item, struct menuinputs *inputs, u32 arg2 return true; } - if (item->param1 & 0x00200000) { + if (item->flags & MENUITEMFLAG_00200000) { item->handler(MENUOP_GETOPTIONHEIGHT, item, &handlerdata2); g_LineHeight = handlerdata2.list.value; } else { @@ -3104,7 +3104,7 @@ void menuInitItemDropdown(struct menuitem *item, union menuitemdata *data) handler = item->handler; - if (item->param1 & 0x00200000) { + if (item->flags & MENUITEMFLAG_00200000) { handler(MENUOP_GETOPTIONHEIGHT, item, &handlerdata2); g_LineHeight = handlerdata2.dropdown.value; } else { @@ -3596,7 +3596,7 @@ bool menuTickItemDropdown(struct menuitem *item, struct menuframe *frame, struct menuTickItemList(item, inputs, arg3, data); if (mpIsPlayerLockedOut(g_MpPlayerNum)) { - if ((item->param1 & 0x00040000) || (frame->dialog->unk10 & 0x10)) { + if ((item->flags & MENUITEMFLAG_00040000) || (frame->dialog->unk10 & 0x10)) { frame->dimmed = false; } } @@ -4036,7 +4036,7 @@ glabel menuRenderOverlayDropdown // } // // // 334 -// if (item->param1 & 0x00000080) { +// if (item->flags & MENUITEMFLAG_00000080) { // context.x = x + 30; // } // @@ -4053,7 +4053,7 @@ glabel menuRenderOverlayDropdown // // 380 // union handlerdata handlerdata; // 5c // -// if (item->param1 & 0x00200000) { +// if (item->flags & MENUITEMFLAG_00200000) { // union handlerdata handlerdata2; // 4c // item->handler(MENUOP_GETOPTIONHEIGHT, item, &handlerdata2); // g_LineHeight = handlerdata2.dropdown.value; @@ -6639,7 +6639,7 @@ Gfx *menuRenderItemObjectives(Gfx *gdl, struct menurendercontext *context) Gfx *menuRenderItemModel(Gfx *gdl, struct menurendercontext *context) { - if (context->item->param1 & 0x00200000) { + if (context->item->flags & MENUITEMFLAG_00200000) { struct menuitemrenderdata renderdata; union handlerdata data; @@ -6687,7 +6687,7 @@ Gfx *menuRenderItemLabel(Gfx *gdl, struct menurendercontext *context) x = context->x + 10; y = context->y + 2; - if (context->item->param1 & 0x00000010) { + if (context->item->flags & MENUITEMFLAG_00000010) { x -= 6; } @@ -6697,13 +6697,13 @@ Gfx *menuRenderItemLabel(Gfx *gdl, struct menurendercontext *context) return gdl; } - if (context->item->param1 & 0x00000200) { + if (context->item->flags & MENUITEMFLAG_00000200) { font1 = g_CharsHandelGothicXs; font2 = g_FontHandelGothicXs; y -= 2; } - if (context->item->param1 & 0x00000020) { + if (context->item->flags & MENUITEMFLAG_00000020) { // Center s32 textheight; s32 textwidth; @@ -6711,7 +6711,7 @@ Gfx *menuRenderItemLabel(Gfx *gdl, struct menurendercontext *context) x = context->x + (context->width - textwidth) / 2; } - if (context->item->param1 & 0x00000100) { + if (context->item->flags & MENUITEMFLAG_00000100) { if (context->frame->transitiontimer < 0) { colour1 = g_MenuColourPalettes[context->frame->type].checkedunfocused; } else { @@ -6780,7 +6780,7 @@ Gfx *menuRenderItemLabel(Gfx *gdl, struct menurendercontext *context) colour2 = colour1; - if (context->item->param1 & 0x01000000) { + if (context->item->flags & MENUITEMFLAG_01000000) { union handlerdata data; data.label.colour2 = colour2; data.label.colour1 = colour1; @@ -6800,7 +6800,7 @@ Gfx *menuRenderItemLabel(Gfx *gdl, struct menurendercontext *context) gdl = textRenderProjected(gdl, &x, &y, text, font1, font2, colour1, context->width, context->height, 0, 0); - if ((context->item->param1 & 0x00008000) == 0) { + if ((context->item->flags & MENUITEMFLAG_00008000) == 0) { // Right side text text = menuResolveText(context->item->param3, context->item); @@ -6811,14 +6811,14 @@ Gfx *menuRenderItemLabel(Gfx *gdl, struct menurendercontext *context) y = context->y + 2; - if (context->item->param1 & 0x00000200) { + if (context->item->flags & MENUITEMFLAG_00000200) { y -= 2; } textMeasure(&textheight, &textwidth, text, font1, font2, 0); x = context->x + context->width - textwidth - 10; - if (context->item->param1 & 0x00000010) { + if (context->item->flags & MENUITEMFLAG_00000010) { x += 6; } @@ -6839,7 +6839,7 @@ Gfx *menuRenderItemLabel(Gfx *gdl, struct menurendercontext *context) func0f153c88(); } - if (context->item->param1 & 0x00200000) { + if (context->item->flags & MENUITEMFLAG_00200000) { struct menuitemrenderdata renderdata; union handlerdata data; @@ -7317,11 +7317,11 @@ const char var7f1adfb8[] = ""; // struct fontchar *font1 = g_CharsHandelGothicSm; // struct font *font2 = g_FontHandelGothicSm; // -// if (context->item->param1 & 0x00000010) { +// if (context->item->flags & MENUITEMFLAG_00000010) { // x -= 6; // } // -// if (context->item->param1 & 0x00400000) { +// if (context->item->flags & MENUITEMFLAG_00400000) { // font1 = g_CharsHandelGothicMd; // font2 = g_FontHandelGothicMd; // } @@ -7392,7 +7392,7 @@ const char var7f1adfb8[] = ""; // g_MenuColourPalettes2[context->frame->type].disabled); // } // -// if (context->item->param1 & 0x00000020) { +// if (context->item->flags & MENUITEMFLAG_00000020) { // // Center text // s32 textheight; // s32 textwidth; @@ -7400,7 +7400,7 @@ const char var7f1adfb8[] = ""; // x = context->x + (context->width - textwidth) / 2; // } // -// if (context->item->param1 & 0x00400000) { +// if (context->item->flags & MENUITEMFLAG_00400000) { // x += 35; // y += 6; // } @@ -7409,7 +7409,7 @@ const char var7f1adfb8[] = ""; // gdl = textRenderProjected(gdl, &x, &y, text, font1, font2, // leftcolour, context->width, context->height, 0, 0); // -// if ((context->item->param1 & 0x00408000) == 0) { +// if ((context->item->flags & (MENUITEMFLAG_00008000 | MENUITEMFLAG_00400000)) == 0) { // // Right side text // text = menuResolveText(context->item->param3, context->item); // @@ -7435,11 +7435,11 @@ bool menuTickItemSelectable(struct menuitem *item, struct menuinputs *inputs, u3 if ((arg2 & 2) && inputs->select) { menuPlaySound(MENUSOUND_SELECT); - if (item->param1 & 0x00000008) { + if (item->flags & MENUITEMFLAG_00000008) { menuPopDialog(); } - if (item->param1 & 0x00000004) { + if (item->flags & MENUITEMFLAG_00000004) { menuPushDialog((struct menudialog *)item->handler); } else if (item->handler) { union handlerdata data; @@ -8139,7 +8139,7 @@ bool menuTickItemSlider(struct menuitem *item, struct menuframe *frame, struct m index = 0; } - if ((item->param1 & 0x00000800) == 0 && !g_Menus[g_MpPlayerNum].unk82c) { + if ((item->flags & MENUITEMFLAG_00000800) == 0 && !g_Menus[g_MpPlayerNum].unk82c) { index = index + inputs->leftright; } else { f0 = data->slider.unk00 / 1000.0f; @@ -8166,7 +8166,7 @@ bool menuTickItemSlider(struct menuitem *item, struct menuframe *frame, struct m f2 = f14; } - if ((item->param1 & 0x00000800) == 0 && f2 < 40) { + if ((item->flags & MENUITEMFLAG_00000800) == 0 && f2 < 40) { if (g_Menus[g_MpPlayerNum].unk82c) { index = index + inputs->leftright; } @@ -8291,9 +8291,9 @@ bool menuTickItemCarousel(struct menuitem *item, struct menuinputs *inputs, u32 bool done; u32 stack; - if (((arg2 & 2) || (item->param1 & 0x04000000)) && item->handler) { + if (((arg2 & 2) || (item->flags & MENUITEMFLAG_04000000)) && item->handler) { if (inputs->leftright != 0) { - if (mpIsPlayerLockedOut(g_MpPlayerNum) == 0 || (item->param1 & 0x00020000) == 0) { + if (mpIsPlayerLockedOut(g_MpPlayerNum) == 0 || (item->flags & MENUITEMFLAG_00020000) == 0) { done = false; item->handler(MENUOP_GETOPTIONCOUNT, item, &data); @@ -8739,7 +8739,7 @@ glabel menuRenderItemCheckbox // struct font *font2 = g_FontHandelGothicSm; // struct fontchar *font1 = g_CharsHandelGothicSm; // -// if (context->item->param1 & 0x00000200) { +// if (context->item->flags & MENUITEMFLAG_00000200) { // font2 = g_FontHandelGothicXs; // font1 = g_CharsHandelGothicXs; // } @@ -9745,7 +9745,7 @@ u32 var800711ec = 0x20000000; // struct font *font2 = g_FontHandelGothicSm; // 5c // struct fontchar *font1 = g_CharsHandelGothicSm; // 58 // -// if (context->item->param1 & 0x00000200) { +// if (context->item->flags & MENUITEMFLAG_00000200) { // font2 = g_FontHandelGothicXs; // font1 = g_CharsHandelGothicXs; // } @@ -9843,7 +9843,7 @@ u32 var800711ec = 0x20000000; // // func0f153d24(); // -// if (context->item->param1 & 0x00000800) { +// if (context->item->flags & MENUITEMFLAG_00000800) { // func0f153ce8(context->x, context->x + context->width, 0xe); // } else { // func0f153ce8(context->x, context->x, 0xe); @@ -9967,7 +9967,7 @@ bool menuTickItemMarquee(struct menuitem *item, union menuitemdata *data) font2 = g_FontHandelGothicSm; font1 = g_CharsHandelGothicSm; - if (item->param1 & 0x00000200) { + if (item->flags & MENUITEMFLAG_00000200) { font2 = g_FontHandelGothicXs; font1 = g_CharsHandelGothicXs; } diff --git a/src/include/constants.h b/src/include/constants.h index 3f7237afd..349ca2a6c 100644 --- a/src/include/constants.h +++ b/src/include/constants.h @@ -1427,6 +1427,24 @@ #define MENUDIALOGTYPE_DANGER 2 #define MENUDIALOGTYPE_SUCCESS 3 +#define MENUITEMFLAG_00000001 0x00000001 +#define MENUITEMFLAG_00000004 0x00000004 +#define MENUITEMFLAG_00000008 0x00000008 +#define MENUITEMFLAG_00000010 0x00000010 +#define MENUITEMFLAG_00000020 0x00000020 +#define MENUITEMFLAG_00000080 0x00000080 +#define MENUITEMFLAG_00000100 0x00000100 +#define MENUITEMFLAG_00000200 0x00000200 +#define MENUITEMFLAG_00000400 0x00000400 +#define MENUITEMFLAG_00000800 0x00000800 +#define MENUITEMFLAG_00008000 0x00008000 +#define MENUITEMFLAG_00020000 0x00020000 +#define MENUITEMFLAG_00040000 0x00040000 +#define MENUITEMFLAG_00200000 0x00200000 +#define MENUITEMFLAG_00400000 0x00400000 +#define MENUITEMFLAG_01000000 0x01000000 +#define MENUITEMFLAG_04000000 0x04000000 + #define MENUITEMTYPE_LABEL 0x01 #define MENUITEMTYPE_LIST 0x02 #define MENUITEMTYPE_SELECTABLE 0x04 diff --git a/src/include/game/game_0f09f0.h b/src/include/game/game_0f09f0.h index 0cd4127b5..29735bfdc 100644 --- a/src/include/game/game_0f09f0.h +++ b/src/include/game/game_0f09f0.h @@ -22,7 +22,7 @@ void func0f0f1494(void); char *menuResolveText(u32 thing, void *dialogoritem); char *menuResolveParam2Text(struct menuitem *item); char *menuResolveDialogTitle(struct menudialog *dialog); -void func0f0f15a4(u8 *arg0, u32 *arg1); +void func0f0f15a4(struct menuitem *item, s32 *arg1); void func0f0f1618(struct menuitem *item, void *arg1, void *arg2, struct menuframe *frame); void func0f0f1d6c(struct menudialog *dialog, struct menuframe *frame, struct menu *menu); u32 func0f0f1ef4(void); diff --git a/src/include/types.h b/src/include/types.h index 8038f8f25..199e2b98b 100644 --- a/src/include/types.h +++ b/src/include/types.h @@ -3550,7 +3550,7 @@ union handlerdata { struct menuitem { u8 type; u8 param; - u32 param1; + u32 flags; s32 param2; s32 param3; @@ -3924,14 +3924,14 @@ struct perfectheadtexturelist { struct menu4fc { s16 unk00; - u8 unk02; - s8 handlerdataindex; + u8 itemindex; + s8 blockindex; }; struct menu660 { u16 unk00; u16 unk02; - u16 unk04; + u8 unk04; u16 unk06; u8 unk08; }; @@ -3946,7 +3946,7 @@ struct menu { /*0x65c*/ s32 unk65c; /*0x660*/ struct menu660 unk660[VERSION >= VERSION_NTSC_1_0 ? 12 : 10]; /*0x6d8*/ s32 unk6d8; - /*0x6dc*/ u32 handlerdatabuffer[80]; + /*0x6dc*/ u32 blocks[80]; // for menuitemdata /*0x81c*/ s32 unk81c; /*0x820*/ u32 unk820; /*0x824*/ u32 unk824;