From 824ccd1ac60c9f38e9dc6267e331f558b54d31cf Mon Sep 17 00:00:00 2001 From: gamemasterplc Date: Thu, 23 Nov 2023 12:18:50 -0600 Subject: [PATCH] Decompile subchrdll.c --- config/GMPE01_00/rels/subchrselDll/splits.txt | 9 + .../GMPE01_00/rels/subchrselDll/symbols.txt | 58 +++--- config/GMPE01_00/symbols.txt | 12 +- configure.py | 12 ++ include/common_structs.h | 18 +- include/functions.h | 9 +- src/REL/subchrselDll/subchrselDll.c | 175 ++++++++++++++++-- src/REL/subchrselDll/subchrselDll.h | 38 ---- 8 files changed, 240 insertions(+), 91 deletions(-) delete mode 100644 src/REL/subchrselDll/subchrselDll.h diff --git a/config/GMPE01_00/rels/subchrselDll/splits.txt b/config/GMPE01_00/rels/subchrselDll/splits.txt index 531cd645..62fd2695 100644 --- a/config/GMPE01_00/rels/subchrselDll/splits.txt +++ b/config/GMPE01_00/rels/subchrselDll/splits.txt @@ -5,3 +5,12 @@ Sections: .rodata type:rodata align:8 .data type:data align:8 .bss type:bss align:8 + +REL/executor.c: + .text start:0x00000000 end:0x000000A0 + +REL/subchrselDll/subchrselDll.c: + .text start:0x000000A0 end:0x000007B8 + .rodata start:0x00000000 end:0x00000018 + .data start:0x00000000 end:0x000000E1 + .bss start:0x00000000 end:0x00000004 diff --git a/config/GMPE01_00/rels/subchrselDll/symbols.txt b/config/GMPE01_00/rels/subchrselDll/symbols.txt index 4b25743d..8f028b97 100644 --- a/config/GMPE01_00/rels/subchrselDll/symbols.txt +++ b/config/GMPE01_00/rels/subchrselDll/symbols.txt @@ -1,33 +1,33 @@ _prolog = .text:0x00000000; // type:function size:0x54 scope:global _epilog = .text:0x00000054; // type:function size:0x4C scope:global -fn_1_A0 = .text:0x000000A0; // type:function size:0x6C -fn_1_10C = .text:0x0000010C; // type:function size:0x58 -fn_1_164 = .text:0x00000164; // type:function size:0x654 +ModuleProlog = .text:0x000000A0; // type:function size:0x6C +GetBtns = .text:0x0000010C; // type:function size:0x58 scope:local +SubchrMain = .text:0x00000164; // type:function size:0x654 scope:local _ctors = .ctors:0x00000000; // type:label scope:global data:4byte _dtors = .dtors:0x00000000; // type:label scope:global data:4byte -lbl_1_rodata_10 = .rodata:0x00000010; // type:object size:0x4 data:float -lbl_1_rodata_14 = .rodata:0x00000014; // type:object size:0x4 data:float -lbl_1_data_0 = .data:0x00000000; // type:object size:0x8 data:string -lbl_1_data_8 = .data:0x00000008; // type:object size:0x8 data:string -lbl_1_data_10 = .data:0x00000010; // type:object size:0x8 data:string -lbl_1_data_18 = .data:0x00000018; // type:object size:0x8 data:string -lbl_1_data_20 = .data:0x00000020; // type:object size:0x10 -lbl_1_data_30 = .data:0x00000030; // type:object size:0x6 data:string -lbl_1_data_36 = .data:0x00000036; // type:object size:0x6 data:string -lbl_1_data_3C = .data:0x0000003C; // type:object size:0x6 data:string -lbl_1_data_42 = .data:0x00000042; // type:object size:0x6 data:string -lbl_1_data_48 = .data:0x00000048; // type:object size:0x6 data:string -lbl_1_data_4E = .data:0x0000004E; // type:object size:0x7 data:string -lbl_1_data_55 = .data:0x00000055; // type:object size:0x6 data:string -lbl_1_data_5B = .data:0x0000005B; // type:object size:0x9 -lbl_1_data_64 = .data:0x00000064; // type:object size:0x20 -lbl_1_data_84 = .data:0x00000084; // type:object size:0x1 -lbl_1_data_85 = .data:0x00000085; // type:object size:0x6 data:string -lbl_1_data_8B = .data:0x0000008B; // type:object size:0x8 data:string -lbl_1_data_93 = .data:0x00000093; // type:object size:0x7 data:string -lbl_1_data_9A = .data:0x0000009A; // type:object size:0x7 data:string -lbl_1_data_A1 = .data:0x000000A1; // type:object size:0x6 data:string -lbl_1_data_A7 = .data:0x000000A7; // type:object size:0x9 -lbl_1_data_B0 = .data:0x000000B0; // type:object size:0x1C -lbl_1_data_CC = .data:0x000000CC; // type:object size:0x15 data:string -lbl_1_bss_0 = .bss:0x00000000; // type:object size:0x4 data:byte +lbl_1_rodata_10 = .rodata:0x00000010; // type:object size:0x4 scope:local data:float +lbl_1_rodata_14 = .rodata:0x00000014; // type:object size:0x4 scope:local data:float +lbl_1_data_0 = .data:0x00000000; // type:object size:0x8 scope:local data:string +lbl_1_data_8 = .data:0x00000008; // type:object size:0x8 scope:local data:string +lbl_1_data_10 = .data:0x00000010; // type:object size:0x8 scope:local data:string +lbl_1_data_18 = .data:0x00000018; // type:object size:0x8 scope:local data:string +player_numstr = .data:0x00000020; // type:object size:0x10 scope:local +lbl_1_data_30 = .data:0x00000030; // type:object size:0x6 scope:local data:string +lbl_1_data_36 = .data:0x00000036; // type:object size:0x6 scope:local data:string +lbl_1_data_3C = .data:0x0000003C; // type:object size:0x6 scope:local data:string +lbl_1_data_42 = .data:0x00000042; // type:object size:0x6 scope:local data:string +lbl_1_data_48 = .data:0x00000048; // type:object size:0x6 scope:local data:string +lbl_1_data_4E = .data:0x0000004E; // type:object size:0x7 scope:local data:string +lbl_1_data_55 = .data:0x00000055; // type:object size:0x6 scope:local data:string +lbl_1_data_5B = .data:0x0000005B; // type:object size:0x9 scope:local +character_str = .data:0x00000064; // type:object size:0x20 scope:local +lbl_1_data_84 = .data:0x00000084; // type:object size:0x1 scope:local +lbl_1_data_85 = .data:0x00000085; // type:object size:0x6 scope:local data:string +lbl_1_data_8B = .data:0x0000008B; // type:object size:0x8 scope:local data:string +lbl_1_data_93 = .data:0x00000093; // type:object size:0x7 scope:local data:string +lbl_1_data_9A = .data:0x0000009A; // type:object size:0x7 scope:local data:string +lbl_1_data_A1 = .data:0x000000A1; // type:object size:0x6 scope:local data:string +lbl_1_data_A7 = .data:0x000000A7; // type:object size:0x9 scope:local +ext_character_str = .data:0x000000B0; // type:object size:0x1C scope:local +lbl_1_data_CC = .data:0x000000CC; // type:object size:0x15 scope:local data:string +lbl_1_bss_0 = .bss:0x00000000; // type:object size:0x4 scope:local data:byte diff --git a/config/GMPE01_00/symbols.txt b/config/GMPE01_00/symbols.txt index 0d89aaa5..e33b7341 100644 --- a/config/GMPE01_00/symbols.txt +++ b/config/GMPE01_00/symbols.txt @@ -511,8 +511,8 @@ fn_8002EA6C = .text:0x8002EA6C; // type:function size:0x16C fn_8002EBD8 = .text:0x8002EBD8; // type:function size:0x90 fn_8002EC68 = .text:0x8002EC68; // type:function size:0x170 fn_8002EDD8 = .text:0x8002EDD8; // type:function size:0xE8 -fn_8002EEC0 = .text:0x8002EEC0; // type:function size:0x60 -fn_8002EF20 = .text:0x8002EF20; // type:function size:0xF4 +omOvlGotoEx = .text:0x8002EEC0; // type:function size:0x60 +omOvlReturnEx = .text:0x8002EF20; // type:function size:0xF4 fn_8002F014 = .text:0x8002F014; // type:function size:0xB8 omOvlHisChg = .text:0x8002F0CC; // type:function size:0xA0 omOvlHisGet = .text:0x8002F16C; // type:function size:0x78 @@ -728,7 +728,7 @@ fn_80040D60 = .text:0x80040D60; // type:function size:0x36C fn_800410CC = .text:0x800410CC; // type:function size:0xA4 fn_80041170 = .text:0x80041170; // type:function size:0xB4 fn_80041224 = .text:0x80041224; // type:function size:0x288 -fn_800414AC = .text:0x800414AC; // type:function size:0x12C +WipeCreate = .text:0x800414AC; // type:function size:0x12C fn_800415D8 = .text:0x800415D8; // type:function size:0x28 fn_80041600 = .text:0x80041600; // type:function size:0x10 fn_80041610 = .text:0x80041610; // type:function size:0x8 @@ -5400,7 +5400,7 @@ lbl_8018F790 = .bss:0x8018F790; // type:object size:0x370 lbl_8018FB00 = .bss:0x8018FB00; // type:object size:0x38 lbl_8018FB38 = .bss:0x8018FB38; // type:object size:0xC0 lbl_8018FBF8 = .bss:0x8018FBF8; // type:object size:0x18 -lbl_8018FC10 = .bss:0x8018FC10; // type:object size:0x28 +gPlayerConfig = .bss:0x8018FC10; // type:object size:0x28 gPlayerData = .bss:0x8018FC38; // type:object size:0xC0 data:byte lbl_8018FCF8 = .bss:0x8018FCF8; // type:object size:0xE0 data:byte lbl_8018FDD8 = .bss:0x8018FDD8; // type:object size:0x230 @@ -5419,8 +5419,8 @@ lbl_80190E60 = .bss:0x80190E60; // type:object size:0x1200 data:4byte lbl_80192060 = .bss:0x80192060; // type:object size:0x100 lbl_80192160 = .bss:0x80192160; // type:object size:0x100 lbl_80192260 = .bss:0x80192260; // type:object size:0x100 -lbl_80192360 = .bss:0x80192360; // type:object size:0x60 data:4byte -winData = .bss:0x801923C0; // type:object size:0x3000 data:byte +wipeData = .bss:0x80192360; // type:object size:0x60 data:4byte +winData = .bss:0x801923C0; // type:object size:0x3000 align:32 data:byte lbl_801953C0 = .bss:0x801953C0; // type:object size:0x10 lbl_801953D0 = .bss:0x801953D0; // type:object size:0x1410 lbl_801967E0 = .bss:0x801967E0; // type:object size:0x400 data:byte diff --git a/configure.py b/configure.py index 14180103..658075f8 100755 --- a/configure.py +++ b/configure.py @@ -176,6 +176,7 @@ cflags_rel = [ "-char unsigned", "-sdata 0", "-sdata2 0", + "-pool off", ] # Game flags @@ -230,6 +231,7 @@ config.libs = [ Object(NonMatching, "game/data.c"), Object(Matching, "game/decode.c"), Object(NonMatching, "game/font.c"), + Object(NonMatching, "game/jmp.c"), Object(Matching, "game/malloc.c"), Object(Matching, "game/memory.c"), Object(NonMatching, "game/printfunc.c"), @@ -268,6 +270,16 @@ config.libs = [ Object(Matching, "REL/_minigameDLL/_minigameDLL.c"), ], }, + { + "lib": "subchrselDll", + "mw_version": config.linker_version, + "cflags": cflags_rel, + "host": False, + "objects": [ + Object(Matching, "REL/executor.c"), + Object(Matching, "REL/subchrselDll/subchrselDll.c"), + ], + }, ] if args.mode == "configure": diff --git a/include/common_structs.h b/include/common_structs.h index 734a40e3..c17271d7 100644 --- a/include/common_structs.h +++ b/include/common_structs.h @@ -43,10 +43,18 @@ typedef struct process { void *user_data; } Process; -typedef struct unkStruct1D3B44 { - struct unkStruct1D3B44 *prev; - char unk_04[0x1A]; - u16 unk_1E; -} unkStruct1D3B44; // sizeof ??? +typedef struct player_config { + s16 character; + s16 pad_idx; + s16 diff; + s16 group; + s16 iscom; +} PlayerConfig; + +typedef struct wipe_state { + u8 unk[52]; + float duration; + u8 unk2[20]; +} WipeState; #endif diff --git a/include/functions.h b/include/functions.h index 9978fd3c..0f0fb250 100644 --- a/include/functions.h +++ b/include/functions.h @@ -14,7 +14,8 @@ void* omInitObjMan(s32, s32); void fn_80044920(s16); void fn_80045F74(s16, s32); s32 fn_800578E4(void); -void fn_1_26C(void); +void fn_80032A58(int arg0); +void fn_80035A0C(void); void HuDecodeData(void *src, void *dst, u32 size, int decode_type); void HuMemInitAll(void); @@ -62,4 +63,10 @@ void HuPrcResetStat(Process *process, u16 value); void HuPrcAllPause(int flag); void HuPrcAllUPause(int flag); +void omOvlGotoEx(int id, s16 end_mode, int stat, int event); +void omOvlReturnEx(int level, s16 end_mode); +void WipeCreate(char dir, char type, short duration); + +u16 print8(s16 x, s16 y, float scale, char *str, ...); + #endif diff --git a/src/REL/subchrselDll/subchrselDll.c b/src/REL/subchrselDll/subchrselDll.c index 3c5a4c59..8d2279c8 100644 --- a/src/REL/subchrselDll/subchrselDll.c +++ b/src/REL/subchrselDll/subchrselDll.c @@ -1,20 +1,171 @@ -#include "subchrselDll.h" +#include "common.h" -void fn_1_A0(void) { +//HACK: Force 0.5 and 3.0 double constants to appear in REL +const double _half = 0.5; +const double _three = 3.0; + +extern WipeState wipeData; + +extern PlayerConfig gPlayerConfig[4]; +extern u16 HuPadBtnDown[4]; +extern u8 HuPadDStk[4]; +extern int fontcolor; + +static void SubchrMain(void); + +static u8 cur_direction[4]; + +static char *player_numstr[4] = { + "PLAYER1", + "PLAYER2", + "PLAYER3", + "PLAYER4" +}; + +static char *character_str[8] = { + "MARIO", + "LUIGI", + "PEACH", + "YOSHI", + "WARIO", + "DONKEY", + "DAISY", + "WALUIGI" +}; + +static char *ext_character_str[7] = { + "", + "KOOPA", + "KINOPIO", + "HEIHOH", + "TERESA", + "NOKO2", + "MKOOPA" +}; + +void ModuleProlog(void) +{ void* sp8 = omInitObjMan(0x32, 0x2000); - Hu3DBGColorSet(0U, 0U, 0U); - fn_8000C760(&fn_1_164, 0x1000, 0x3000, 0, fn_8000CA3C()); - fn_800414AC(1, 0, -1); + Hu3DBGColorSet(0, 0, 0); + HuPrcChildCreate(SubchrMain, 4096, 12288, 0, HuPrcCurrentGet()); + WipeCreate(1, 0, -1); } -u16 fn_1_10C(void) { - u16 var_r31; +static u16 GetBtns(void) +{ + u16 btns; - var_r31 = lbl_801D3AD0; - if (lbl_1_bss_0 != lbl_801D3AAC) { - var_r31 |= lbl_801D3AAC; + btns = HuPadBtnDown[0]; + if (cur_direction[0] != HuPadDStk[0]) { + btns |= HuPadDStk[0]; } - return var_r31; + return btns; } -// void fn_1_164(void) +static void SubchrMain() +{ + int prev_character[4]; + int character[4]; + int i, cursor_pos; + for(i=0; i<4; i++) { + prev_character[i] = gPlayerConfig[i].character; + character[i] = 0; + cur_direction[i] = 0; + } + cursor_pos = 0; + while(1) { + int y, x; + u16 btns; + fontcolor = 14; + print8(150, 64, 2.0f, "Sub Character Select"); + x = 170; + y = 120; + for(i=0; i<4; i++, y += 16) { + fontcolor = 12; + print8(x, y, 2.0f, player_numstr[i]); + if(i == cursor_pos) { + fontcolor = 13; + } else { + fontcolor = 12; + } + if(character[i] != 0) { + print8(x+200, y, 2.0f, ext_character_str[character[i]]); + } else { + print8(x+200, y, 2.0f, character_str[prev_character[i]]); + } + } + if(GetBtns() & 0x1000) { + for(i=0; i<4; i++) { + if(character[i] != 0) { + gPlayerConfig[i]. character = character[i]+7; + } + } + fn_80032A58(30); + WipeCreate(2, 0, -1); + HuPrcSleep(wipeData.duration+1.0f); + fn_80035A0C(); + omOvlGotoEx(41, 1, 0, 0); + do { + HuPrcVSleep(); + } while(1); + } else { + if(GetBtns() & 0x1) { + do { + character[cursor_pos]--; + if(character[cursor_pos] < 0) { + character[cursor_pos] = 6; + } + for(i=0; i<4; i++) { + if(cursor_pos != i) { + if(character[cursor_pos] == character[i] && character[cursor_pos] != 0) { + break; + } + } + } + } while(i < 4); + } + if(GetBtns() & 0x2) { + do { + character[cursor_pos]++; + if(character[cursor_pos] > 6) { + character[cursor_pos] = 0; + } + for(i=0; i<4; i++) { + if(cursor_pos != i) { + if(character[cursor_pos] == character[i] && character[cursor_pos] != 0) { + break; + } + } + } + } while(i < 4); + } + if(GetBtns() & 0x4) { + cursor_pos++; + } + if(GetBtns() & 0x8) { + cursor_pos--; + } + if(cursor_pos < 0) { + cursor_pos = 3; + } + if(cursor_pos > 3) { + cursor_pos = 0; + } + if(GetBtns() & 0x200) { + fn_80032A58(30); + WipeCreate(2, 0, -1); + HuPrcSleep(wipeData.duration+1.0f); + fn_80035A0C(); + omOvlReturnEx(1, 1); + do { + HuPrcVSleep(); + } while(1); + } else { + if(cur_direction[0] != HuPadDStk[0]) { + cur_direction[0] = HuPadDStk[0]; + } + } + } + HuPrcVSleep(); + } +} \ No newline at end of file diff --git a/src/REL/subchrselDll/subchrselDll.h b/src/REL/subchrselDll/subchrselDll.h deleted file mode 100644 index 9c0762c0..00000000 --- a/src/REL/subchrselDll/subchrselDll.h +++ /dev/null @@ -1,38 +0,0 @@ -#include "common.h" -#include "REL/executor.h" - -void fn_8000C760(void*, s32, s32, s32, s32); -s32 fn_8000CA3C(); -void fn_800414AC(s16, s16, s16); - -extern u8 lbl_1_bss_0; -extern u8 lbl_801D3AAC; -extern u16 lbl_801D3AD0; - -typedef struct unkStruct192360 { - char unk_00[0x34]; - f32 unk_34; -} unkStruct192360; - -s16 fn_8000AFF4(s16, s16, f32, char*, ...); /* extern */ -void fn_8000CF0C(s32, f32); /* extern */ -void fn_8000CF8C(); /* extern */ -void fn_8002EEC0(s32, s16, s32, s32); /* extern */ -void fn_8002EF20(s16, s16); /* extern */ -void fn_80032A58(s32); /* extern */ -void fn_80035A0C(void); /* extern */ -void fn_800414AC(s16, s16, s16); /* extern */ -extern s32 debugFontColor; -extern u8 lbl_1_bss_0; -extern char *lbl_1_data_20[4]; -extern char *lbl_1_data_64[8]; -extern char *lbl_1_data_B0[7]; -extern char lbl_1_data_CC[20]; -extern s16 lbl_8018FC10[]; -extern unkStruct192360 lbl_80192360; -extern u8 lbl_801D3AAC; -extern u16 lbl_801D3AD0; - -void fn_1_A0(void); -u16 fn_1_10C(void); -void fn_1_164(void);