From aec8574171b3d6919128b6f253ab05e2a68afbbb Mon Sep 17 00:00:00 2001 From: user Date: Mon, 29 Jul 2024 00:34:27 +0200 Subject: [PATCH] Decomp ov31_02382B54 (mismatch) --- ...1002382B54.inc => overlay_31002382DAC.inc} | 8 +- ...ay_31002382B54.s => overlay_31002382DAC.s} | 167 +----------------- include/overlay_3102382820.h | 26 ++- main.lsf | 2 +- src/overlay_3102382820.c | 118 +++++++++++-- 5 files changed, 129 insertions(+), 192 deletions(-) rename asm/include/{overlay_31002382B54.inc => overlay_31002382DAC.inc} (97%) rename asm/{overlay_31002382B54.s => overlay_31002382DAC.s} (97%) diff --git a/asm/include/overlay_31002382B54.inc b/asm/include/overlay_31002382DAC.inc similarity index 97% rename from asm/include/overlay_31002382B54.inc rename to asm/include/overlay_31002382DAC.inc index bef43a7c..acbb1f24 100644 --- a/asm/include/overlay_31002382B54.inc +++ b/asm/include/overlay_31002382DAC.inc @@ -29,12 +29,10 @@ .public CreateScrollBoxSingle .public CreateTextBox .public CreateTextBoxWithArg -.public DUNGEON_MAIN_MENU_ITEMS .public DUNGEON_PTR .public DUNGEON_SUBMENU_ITEMS_1 .public DUNGEON_SUBMENU_ITEMS_5 .public DUNGEON_SUBMENU_ITEMS_6 -.public DUNGEON_WINDOW_PARAMS_1 .public DUNGEON_WINDOW_PARAMS_10 .public DUNGEON_WINDOW_PARAMS_11 .public DUNGEON_WINDOW_PARAMS_12 @@ -45,7 +43,6 @@ .public DUNGEON_WINDOW_PARAMS_17 .public DUNGEON_WINDOW_PARAMS_18 .public DUNGEON_WINDOW_PARAMS_19 -.public DUNGEON_WINDOW_PARAMS_2 .public DUNGEON_WINDOW_PARAMS_20 .public DUNGEON_WINDOW_PARAMS_21 .public DUNGEON_WINDOW_PARAMS_22 @@ -59,7 +56,6 @@ .public DUNGEON_WINDOW_PARAMS_30 .public DUNGEON_WINDOW_PARAMS_31 .public DUNGEON_WINDOW_PARAMS_32 -.public DUNGEON_WINDOW_PARAMS_4 .public DUNGEON_WINDOW_PARAMS_5 .public DUNGEON_WINDOW_PARAMS_6 .public DUNGEON_WINDOW_PARAMS_7 @@ -68,10 +64,8 @@ .public Debug_Print0 .public DisableDungeonSubMenuOption .public DisplayMessage -.public DrawDungeonMenuStatusWindow .public DrawTextInWindow .public DrawTileGrid -.public DungeonMenuSwitch .public FormatMoveString .public FormatMoveStringMore .public GetActiveTeamMember @@ -152,7 +146,6 @@ .public SetAdvancedTextBoxField0x1C4 .public SetAdvancedTextBoxState5 .public SetMonsterActionFields -.public ShouldMonsterRunAwayVariation .public ShowStringInDialogueBox .public SortItemsInBag .public SpecificRecruitCheck @@ -231,6 +224,7 @@ .public ov29_0235352C .public ov29_0237C91C .public ov29_0238280C +.public ov31_02382B54 .public ov31_02389E22 .public ov31_02389F5C .public ov31_0238A044 diff --git a/asm/overlay_31002382B54.s b/asm/overlay_31002382DAC.s similarity index 97% rename from asm/overlay_31002382B54.s rename to asm/overlay_31002382DAC.s index c8f9064f..165f975e 100644 --- a/asm/overlay_31002382B54.s +++ b/asm/overlay_31002382DAC.s @@ -1,173 +1,8 @@ .include "asm/macros.inc" - .include "overlay_31002382B54.inc" + .include "overlay_31002382DAC.inc" .text - arm_func_start ov31_02382B54 -ov31_02382B54: ; 0x02382B54 - stmdb sp!, {lr} - sub sp, sp, #0x9c - ldr r0, _02382D8C ; =OVERLAY31_UNKNOWN_POINTER__NA_238A260 - ldr r2, [r0] - ldr r1, [r2, #4] - cmp r1, #3 - addls pc, pc, r1, lsl #2 - b _02382D80 -_02382B74: ; jump table - b _02382B84 ; case 0 - b _02382B90 ; case 1 - b _02382C6C ; case 2 - b _02382D58 ; case 3 -_02382B84: - add r0, r1, #1 - str r0, [r2, #4] - b _02382D80 -_02382B90: - mov r3, #0 - mov r2, r3 -_02382B98: - ldr r1, [r0] - add r1, r1, r3 - add r3, r3, #1 - strb r2, [r1, #8] - cmp r3, #7 - blt _02382B98 - bl GetLeader - mov r1, #1 - bl ShouldMonsterRunAwayVariation - cmp r0, #0 - beq _02382BEC - ldr r0, _02382D8C ; =OVERLAY31_UNKNOWN_POINTER__NA_238A260 - mov r2, #3 - ldr r1, [r0] - strb r2, [r1, #8] - ldr r1, [r0] - strb r2, [r1, #9] - ldr r1, [r0] - strb r2, [r1, #0xa] - ldr r0, [r0] - strb r2, [r0, #0xc] -_02382BEC: - ldr r1, _02382D8C ; =OVERLAY31_UNKNOWN_POINTER__NA_238A260 - mov r0, #5 - ldr r1, [r1] - add r1, r1, #8 - str r1, [sp, #0x64] - bl Arm9LoadUnkFieldNa0x2029EC8 - str r0, [sp, #4] - ldr r0, _02382D90 ; =DUNGEON_WINDOW_PARAMS_1 - ldr r1, _02382D94 ; =0x00000233 - ldr r3, _02382D98 ; =DUNGEON_MAIN_MENU_ITEMS - add r2, sp, #4 - bl CreateParentMenuFromStringIds - ldr r2, _02382D8C ; =OVERLAY31_UNKNOWN_POINTER__NA_238A260 - ldr r1, _02382D9C ; =DrawDungeonMenuStatusWindow - ldr r2, [r2] - strb r0, [r2] - ldr r0, _02382DA0 ; =DUNGEON_WINDOW_PARAMS_4 - bl CreateTextBox - ldr r2, _02382D8C ; =OVERLAY31_UNKNOWN_POINTER__NA_238A260 - ldr r1, _02382DA4 ; =DungeonMenuSwitch - ldr r2, [r2] - strb r0, [r2, #2] - ldr r0, _02382DA8 ; =DUNGEON_WINDOW_PARAMS_2 - bl CreateTextBox - ldr r1, _02382D8C ; =OVERLAY31_UNKNOWN_POINTER__NA_238A260 - ldr r2, [r1] - strb r0, [r2, #1] - ldr r1, [r1] - ldr r0, [r1, #4] - add r0, r0, #1 - str r0, [r1, #4] - b _02382D80 -_02382C6C: - ldrsb r0, [r2] - bl IsParentMenuActive - cmp r0, #0 - beq _02382D20 - ldr r0, _02382D8C ; =OVERLAY31_UNKNOWN_POINTER__NA_238A260 - ldr r0, [r0] - ldrsb r0, [r0] - bl sub_0202AB80 - and r1, r0, #0xff - mov r0, #5 - bl Arm9StoreUnkFieldNa0x2029ED8 - add r1, sp, #0 - mov r0, #0 - bl GetPressedButtons - ldrh r0, [sp] - tst r0, #0x400 - beq _02382D80 - bl GetLeader - mov r1, #1 - bl ShouldMonsterRunAwayVariation - cmp r0, #0 - bne _02382D80 - ldr r0, _02382D8C ; =OVERLAY31_UNKNOWN_POINTER__NA_238A260 - mov r1, #0 - ldr r0, [r0] - ldrsb r0, [r0] - bl sub_0202AB94 - ldr r0, _02382D8C ; =OVERLAY31_UNKNOWN_POINTER__NA_238A260 - ldr r0, [r0] - ldrsb r0, [r0] - bl sub_0202B030 - ldr r0, _02382D8C ; =OVERLAY31_UNKNOWN_POINTER__NA_238A260 - ldr r0, [r0] - ldrsb r0, [r0, #1] - bl sub_0202F954 - ldr r0, _02382D8C ; =OVERLAY31_UNKNOWN_POINTER__NA_238A260 - ldr r0, [r0] - ldrsb r0, [r0, #2] - bl sub_0202F954 - ldr r0, _02382D8C ; =OVERLAY31_UNKNOWN_POINTER__NA_238A260 - ldr r1, [r0] - ldr r0, [r1, #4] - add r0, r0, #1 - str r0, [r1, #4] - b _02382D80 -_02382D20: - ldr r0, _02382D8C ; =OVERLAY31_UNKNOWN_POINTER__NA_238A260 - ldr r0, [r0] - ldrsb r0, [r0, #1] - bl sub_0202F954 - ldr r0, _02382D8C ; =OVERLAY31_UNKNOWN_POINTER__NA_238A260 - ldr r0, [r0] - ldrsb r0, [r0, #2] - bl sub_0202F954 - ldr r0, _02382D8C ; =OVERLAY31_UNKNOWN_POINTER__NA_238A260 - ldr r1, [r0] - ldr r0, [r1, #4] - add r0, r0, #1 - str r0, [r1, #4] - b _02382D80 -_02382D58: - ldrsb r0, [r2] - bl sub_0202ABB0 - ldr r1, _02382D8C ; =OVERLAY31_UNKNOWN_POINTER__NA_238A260 - str r0, [r1, #4] - ldr r2, [r1] - mov r0, #4 - ldr r1, [r2, #4] - add r1, r1, #1 - str r1, [r2, #4] - b _02382D84 -_02382D80: - mov r0, #1 -_02382D84: - add sp, sp, #0x9c - ldmia sp!, {pc} - .align 2, 0 -_02382D8C: .word OVERLAY31_UNKNOWN_POINTER__NA_238A260 -_02382D90: .word DUNGEON_WINDOW_PARAMS_1 -_02382D94: .word 0x00000233 -_02382D98: .word DUNGEON_MAIN_MENU_ITEMS -_02382D9C: .word DrawDungeonMenuStatusWindow -_02382DA0: .word DUNGEON_WINDOW_PARAMS_4 -_02382DA4: .word DungeonMenuSwitch -_02382DA8: .word DUNGEON_WINDOW_PARAMS_2 - arm_func_end ov31_02382B54 - arm_func_start ov31_02382DAC ov31_02382DAC: ; 0x02382DAC stmdb sp!, {r3, lr} diff --git a/include/overlay_3102382820.h b/include/overlay_3102382820.h index b60445dc..48422320 100644 --- a/include/overlay_3102382820.h +++ b/include/overlay_3102382820.h @@ -5,7 +5,10 @@ #include "preprocessString.h" #include "dungeon_mode.h" -struct Window; +struct Window { + u8 PAD[6]; + u8 width; // 0x6: Window width in multiples of 8 pixels +}; void EntryOverlay31(void); @@ -29,7 +32,26 @@ void EntryOverlay31(void); #define LINE_HEIGHT 12 #define X_OFFSET 115 void DrawDungeonMenuStatusWindow(struct Window* window); -u32 DungeonMenuSwitch(struct Window* window); +void DungeonMenuSwitch(struct Window* window); + +struct struct_1 { + union { // 0x0 + s8 f[4]; + s32 d; + }; + u32 a; // 0x4 + u8 b[7]; // 0x8 +}; + +struct struct_2 { + u32 b; // 0x0 + u8 PAD1[92]; + u8* c; // 0x60 + u8 PAD2[50]; +}; + +#define OV31_02382B54_CONST_1 (0x00000233) +u32 ov31_02382B54(void); diff --git a/main.lsf b/main.lsf index e4c9ed2f..5261b10d 100644 --- a/main.lsf +++ b/main.lsf @@ -306,7 +306,7 @@ Overlay OVY_31 { After OVY_29 Object src/overlay_3102382820.o - Object asm/overlay_31002382B54.o + Object asm/overlay_31002382DAC.o } Overlay OVY_32 { diff --git a/src/overlay_3102382820.c b/src/overlay_3102382820.c index 9ef7410d..544b90c7 100644 --- a/src/overlay_3102382820.c +++ b/src/overlay_3102382820.c @@ -1,20 +1,19 @@ #include "overlay_3102382820.h" -extern u32 DUNGEON_WINDOW_PARAMS_3[]; -extern struct {u32* a; u32 b;} OVERLAY31_UNKNOWN_POINTER__NA_238A260; extern struct dungeon* DUNGEON_PTR; extern const u8 DUNGEON_MENU_SWITCH_STR1[];// = "[dungeon:0]"; +extern struct struct_1* OVERLAY31_UNKNOWN_POINTER__NA_238A260[2]; +extern u32 DUNGEON_WINDOW_PARAMS_1; +extern u32 DUNGEON_WINDOW_PARAMS_2; +extern u32 DUNGEON_WINDOW_PARAMS_3; +extern u32 DUNGEON_WINDOW_PARAMS_4; +extern u32 DUNGEON_MAIN_MENU_ITEMS; + + extern void* MemAlloc(u32 len, u32 flags); -extern void* sub_020348E4(u32*); - - -struct Window { - u8 PAD[6]; - u8 width; // 0x6: Window width in multiples of 8 pixels -}; - +extern struct struct_1* sub_020348E4(u32*); extern struct entity* GetLeader(void); extern s32 CeilFixedPoint(struct fixed_point); @@ -32,15 +31,29 @@ extern u8* sub_02025888(void); extern struct Window* GetWindow(struct Window*); extern s32 sub_020265A8(u8*); // Measures the text's width in pixels +extern u32 ShouldMonsterRunAwayVariation(struct entity*, u32); +extern u32 Arm9LoadUnkFieldNa0x2029EC8(u32, u8*); +extern u8 CreateParentMenuFromStringIds(u32*, u32, struct struct_2*, u32*); +extern u8 CreateTextBox(u32*, void (*fun)(struct Window*)); +extern u32 IsParentMenuActive(s8); +extern u32 sub_0202AB80(s8); +extern void Arm9StoreUnkFieldNa0x2029ED8(u32, u8); +extern u32 GetPressedButtons(u32, u16*); +extern u32 ShouldMonsterRunAwayVariation(struct entity*, u32); +extern void sub_0202AB94(s8, u32); +extern void sub_0202B030(s8); +extern void sub_0202F954(s8); +extern struct struct_1* sub_0202ABB0(s8); + void EntryOverlay31(void) { - u32* r0 = (u32*)sub_020348E4(DUNGEON_WINDOW_PARAMS_3); + struct struct_1* r0 = sub_020348E4(&DUNGEON_WINDOW_PARAMS_3); if (r0 == NULL) { return; } - r0 = (u32*)MemAlloc(16, 0x8); - OVERLAY31_UNKNOWN_POINTER__NA_238A260.a = r0; - r0[1] = 0; - OVERLAY31_UNKNOWN_POINTER__NA_238A260.b = 0xa; + r0 = (struct struct_1*)MemAlloc(16, 0x8); + OVERLAY31_UNKNOWN_POINTER__NA_238A260[0] = r0; + r0->d = 0; + OVERLAY31_UNKNOWN_POINTER__NA_238A260[1] = (struct struct_1*)0xa; } @@ -112,7 +125,7 @@ void DrawDungeonMenuStatusWindow(struct Window* window) UpdateWindow(window); } -u32 DungeonMenuSwitch(struct Window* window) +void DungeonMenuSwitch(struct Window* window) { struct PPStrValues str_values; str_values.dungeon_0 = DUNGEON_PTR->dungeon | 0x40000; @@ -125,3 +138,76 @@ u32 DungeonMenuSwitch(struct Window* window) DrawTextInWindow(window, x_offset, 2, str_buff); UpdateWindow(window); } + +u32 ov31_02382B54(void) +{ + u16 pressed_buttons; + struct struct_2 sp; + struct entity* leader; + + switch (OVERLAY31_UNKNOWN_POINTER__NA_238A260[0]->a) { + case 0: + OVERLAY31_UNKNOWN_POINTER__NA_238A260[0]->a++; + break; + + case 1: + for (int i = 0; i<7; i++) { + OVERLAY31_UNKNOWN_POINTER__NA_238A260[0]->b[i] = 0; + } + leader = GetLeader(); + if (ShouldMonsterRunAwayVariation(leader, 1)) { + OVERLAY31_UNKNOWN_POINTER__NA_238A260[0]->b[0] = 3; + OVERLAY31_UNKNOWN_POINTER__NA_238A260[0]->b[1] = 3; + OVERLAY31_UNKNOWN_POINTER__NA_238A260[0]->b[2] = 3; + OVERLAY31_UNKNOWN_POINTER__NA_238A260[0]->b[4] = 3; + } + sp.c = OVERLAY31_UNKNOWN_POINTER__NA_238A260[0]->b; + sp.b = Arm9LoadUnkFieldNa0x2029EC8(5, sp.c); + + OVERLAY31_UNKNOWN_POINTER__NA_238A260[0]->f[0] = CreateParentMenuFromStringIds(&DUNGEON_WINDOW_PARAMS_1, OV31_02382B54_CONST_1, &sp, &DUNGEON_MAIN_MENU_ITEMS); + + OVERLAY31_UNKNOWN_POINTER__NA_238A260[0]->f[2] = CreateTextBox(&DUNGEON_WINDOW_PARAMS_4, DrawDungeonMenuStatusWindow); + OVERLAY31_UNKNOWN_POINTER__NA_238A260[0]->f[1] = CreateTextBox(&DUNGEON_WINDOW_PARAMS_2, DungeonMenuSwitch); + OVERLAY31_UNKNOWN_POINTER__NA_238A260[0]->a++; + break; + + case 2: + if (IsParentMenuActive(OVERLAY31_UNKNOWN_POINTER__NA_238A260[0]->f[0])) { + u8 tmp4 = sub_0202AB80(OVERLAY31_UNKNOWN_POINTER__NA_238A260[0]->f[0]); + + Arm9StoreUnkFieldNa0x2029ED8(5, tmp4); + + GetPressedButtons(0, &pressed_buttons); + if ((pressed_buttons & 0x400) == 0) + break; + + struct entity* leader = GetLeader(); + + if (ShouldMonsterRunAwayVariation(leader, 1)) + break; + + sub_0202AB94(OVERLAY31_UNKNOWN_POINTER__NA_238A260[0]->f[0], 0); + + sub_0202B030(OVERLAY31_UNKNOWN_POINTER__NA_238A260[0]->f[0]); + + sub_0202F954(OVERLAY31_UNKNOWN_POINTER__NA_238A260[0]->f[1]); + + sub_0202F954(OVERLAY31_UNKNOWN_POINTER__NA_238A260[0]->f[2]); + + OVERLAY31_UNKNOWN_POINTER__NA_238A260[0]->a++; + } else { + sub_0202F954(OVERLAY31_UNKNOWN_POINTER__NA_238A260[0]->f[1]); + + sub_0202F954(OVERLAY31_UNKNOWN_POINTER__NA_238A260[0]->f[2]); + OVERLAY31_UNKNOWN_POINTER__NA_238A260[0]->a++; + } + break; + + case 3: + OVERLAY31_UNKNOWN_POINTER__NA_238A260[1] = sub_0202ABB0(OVERLAY31_UNKNOWN_POINTER__NA_238A260[0]->f[0]); + OVERLAY31_UNKNOWN_POINTER__NA_238A260[0]->a++; + return 4; + break; + } + return 1; +}