diff --git a/asm/pokenav_unk_1.s b/asm/pokenav_unk_1.s index c9342ebe8c..459369a5bf 100644 --- a/asm/pokenav_unk_1.s +++ b/asm/pokenav_unk_1.s @@ -3,461 +3,6 @@ .syntax unified - thumb_func_start sub_81C92CC -sub_81C92CC: @ 81C92CC - push {r4,lr} - movs r0, 0x1 - movs r1, 0x10 - bl AllocSubstruct - adds r4, r0, 0 - cmp r4, 0 - beq _081C92FA - bl sub_81C9268 - lsls r0, 24 - lsrs r0, 24 - movs r1, 0 - strh r0, [r4] - movs r0, 0x2 - strh r0, [r4, 0x2] - strh r0, [r4, 0x4] - strh r1, [r4, 0x6] - adds r0, r4, 0 - bl sub_81C939C - movs r0, 0x1 - b _081C92FC -_081C92FA: - movs r0, 0 -_081C92FC: - pop {r4} - pop {r1} - bx r1 - thumb_func_end sub_81C92CC - - thumb_func_start sub_81C9304 -sub_81C9304: @ 81C9304 - push {r4,lr} - movs r0, 0x1 - movs r1, 0x10 - bl AllocSubstruct - adds r4, r0, 0 - cmp r4, 0 - beq _081C932E - bl sub_81C9268 - lsls r0, 24 - lsrs r0, 24 - strh r0, [r4] - movs r0, 0x3 - strh r0, [r4, 0x2] - strh r0, [r4, 0x4] - adds r0, r4, 0 - bl sub_81C939C - movs r0, 0x1 - b _081C9330 -_081C932E: - movs r0, 0 -_081C9330: - pop {r4} - pop {r1} - bx r1 - thumb_func_end sub_81C9304 - - thumb_func_start sub_81C9338 -sub_81C9338: @ 81C9338 - push {lr} - movs r0, 0x1 - movs r1, 0x10 - bl AllocSubstruct - adds r2, r0, 0 - cmp r2, 0 - beq _081C9360 - movs r0, 0 - movs r1, 0x3 - strh r1, [r2] - strh r0, [r2, 0x2] - movs r1, 0x5 - strh r1, [r2, 0x4] - strh r0, [r2, 0x6] - adds r0, r2, 0 - bl sub_81C939C - movs r0, 0x1 - b _081C9362 -_081C9360: - movs r0, 0 -_081C9362: - pop {r1} - bx r1 - thumb_func_end sub_81C9338 - - thumb_func_start sub_81C9368 -sub_81C9368: @ 81C9368 - push {r4,r5,lr} - movs r0, 0x1 - movs r1, 0x10 - bl AllocSubstruct - adds r5, r0, 0 - cmp r5, 0 - beq _081C9394 - movs r4, 0 - movs r0, 0x4 - strh r0, [r5] - bl sub_81C76AC - strh r0, [r5, 0x2] - adds r0, 0x8 - strh r0, [r5, 0x4] - strh r4, [r5, 0x6] - adds r0, r5, 0 - bl sub_81C939C - movs r0, 0x1 - b _081C9396 -_081C9394: - movs r0, 0 -_081C9396: - pop {r4,r5} - pop {r1} - bx r1 - thumb_func_end sub_81C9368 - - thumb_func_start sub_81C939C -sub_81C939C: @ 81C939C - push {r4,lr} - adds r4, r0, 0 - ldrh r0, [r4] - cmp r0, 0x4 - bhi _081C93E0 - lsls r0, 2 - ldr r1, =_081C93B4 - adds r0, r1 - ldr r0, [r0] - mov pc, r0 - .pool - .align 2, 0 -_081C93B4: - .4byte _081C93C8 - .4byte _081C93CE - .4byte _081C93CE - .4byte _081C93D4 - .4byte _081C93DC -_081C93C8: - movs r0, 0 - bl SetPokenavMode -_081C93CE: - bl sub_81C93EC - b _081C93DE -_081C93D4: - ldr r0, =sub_81C963C - b _081C93DE - .pool -_081C93DC: - ldr r0, =sub_81C96FC -_081C93DE: - str r0, [r4, 0xC] -_081C93E0: - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81C939C - - thumb_func_start sub_81C93EC -sub_81C93EC: @ 81C93EC - push {lr} - bl GetPokenavMode - cmp r0, 0x1 - beq _081C9408 - cmp r0, 0x1 - bcc _081C93FE - cmp r0, 0x2 - beq _081C9410 -_081C93FE: - ldr r0, =sub_81C943C - b _081C9412 - .pool -_081C9408: - ldr r0, =sub_81C9520 - b _081C9412 - .pool -_081C9410: - ldr r0, =c2_pre_battle_1 -_081C9412: - pop {r1} - bx r1 - .pool - thumb_func_end sub_81C93EC - - thumb_func_start sub_81C941C -sub_81C941C: @ 81C941C - push {lr} - movs r0, 0x1 - bl GetSubstructPtr - ldr r1, [r0, 0xC] - bl _call_via_r1 - pop {r1} - bx r1 - thumb_func_end sub_81C941C - - thumb_func_start sub_81C9430 -sub_81C9430: @ 81C9430 - push {lr} - movs r0, 0x1 - bl FreePokenavSubstruct - pop {r0} - bx r0 - thumb_func_end sub_81C9430 - - thumb_func_start sub_81C943C -sub_81C943C: @ 81C943C - push {r4,r5,lr} - adds r4, r0, 0 - bl sub_81C9814 - cmp r0, 0 - beq _081C944C - movs r0, 0x1 - b _081C951A -_081C944C: - ldr r2, =gMain - ldrh r1, [r2, 0x2E] - movs r0, 0x1 - ands r0, r1 - adds r5, r2, 0 - cmp r0, 0 - beq _081C9508 - ldr r3, =gUnknown_0861FC59 - movs r0, 0x2 - ldrsh r1, [r4, r0] - ldrh r2, [r4] - lsls r0, r2, 1 - adds r0, r2 - lsls r0, 1 - adds r1, r0 - adds r1, r3 - ldrb r0, [r1] - cmp r0, 0x4 - bhi _081C9508 - lsls r0, 2 - ldr r1, =_081C9488 - adds r0, r1 - ldr r0, [r0] - mov pc, r0 - .pool - .align 2, 0 -_081C9488: - .4byte _081C949C - .4byte _081C94BC - .4byte _081C94D4 - .4byte _081C94E0 - .4byte _081C9516 -_081C949C: - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldrb r1, [r0, 0x15] - movs r0, 0x8 - ands r0, r1 - movs r1, 0x1 - cmp r0, 0 - beq _081C94AE - movs r1, 0x2 -_081C94AE: - strh r1, [r4, 0x6] - ldr r1, =0x000186a6 - b _081C94EE - .pool -_081C94BC: - movs r1, 0 - movs r0, 0x3 - strh r0, [r4] - strh r1, [r4, 0x2] - ldrb r0, [r3, 0x12] - strh r0, [r4, 0x4] - ldr r0, =sub_81C963C - str r0, [r4, 0xC] - movs r0, 0x2 - b _081C951A - .pool -_081C94D4: - movs r0, 0x6 - strh r0, [r4, 0x6] - ldr r1, =0x000186ab - b _081C94EE - .pool -_081C94E0: - bl CanViewRibbonsMenu - cmp r0, 0 - beq _081C94FC - movs r0, 0x9 - strh r0, [r4, 0x6] - ldr r1, =0x000186ac -_081C94EE: - adds r0, r4, 0 - bl sub_81C97B0 - movs r0, 0x8 - b _081C951A - .pool -_081C94FC: - ldr r0, =sub_81C9600 - str r0, [r4, 0xC] - movs r0, 0x6 - b _081C951A - .pool -_081C9508: - ldrh r1, [r5, 0x2E] - movs r0, 0x2 - ands r0, r1 - cmp r0, 0 - bne _081C9516 - movs r0, 0 - b _081C951A -_081C9516: - movs r0, 0x1 - negs r0, r0 -_081C951A: - pop {r4,r5} - pop {r1} - bx r1 - thumb_func_end sub_81C943C - - thumb_func_start sub_81C9520 -sub_81C9520: @ 81C9520 - push {r4,lr} - adds r4, r0, 0 - bl sub_81C9814 - cmp r0, 0 - beq _081C9530 - movs r0, 0x1 - b _081C9580 -_081C9530: - ldr r0, =gMain - ldrh r1, [r0, 0x2E] - movs r0, 0x1 - ands r0, r1 - cmp r0, 0 - beq _081C9570 - ldr r3, =gUnknown_0861FC59 - movs r0, 0x2 - ldrsh r1, [r4, r0] - ldrh r2, [r4] - lsls r0, r2, 1 - adds r0, r2 - lsls r0, 1 - adds r1, r0 - adds r1, r3 - ldrb r0, [r1] - cmp r0, 0x2 - bne _081C9578 - movs r0, 0x6 - strh r0, [r4, 0x6] - ldr r1, =0x000186ab - adds r0, r4, 0 - bl sub_81C97B0 - movs r0, 0x8 - b _081C9580 - .pool -_081C9570: - movs r0, 0x2 - ands r0, r1 - cmp r0, 0 - beq _081C957E -_081C9578: - movs r0, 0x20 - bl PlaySE -_081C957E: - movs r0, 0 -_081C9580: - pop {r4} - pop {r1} - bx r1 - thumb_func_end sub_81C9520 - - thumb_func_start c2_pre_battle_1 -c2_pre_battle_1: @ 81C9588 - push {r4,lr} - adds r4, r0, 0 - bl sub_81C9814 - cmp r0, 0 - beq _081C9598 - movs r0, 0x1 - b _081C95F8 -_081C9598: - ldr r0, =gMain - ldrh r1, [r0, 0x2E] - movs r0, 0x1 - ands r0, r1 - cmp r0, 0 - beq _081C95E8 - ldr r3, =gUnknown_0861FC59 - movs r0, 0x2 - ldrsh r1, [r4, r0] - ldrh r2, [r4] - lsls r0, r2, 1 - adds r0, r2 - lsls r0, 1 - adds r1, r0 - adds r1, r3 - ldrb r0, [r1] - cmp r0, 0x2 - beq _081C95D4 - cmp r0, 0x4 - beq _081C95F4 - movs r0, 0x20 - bl PlaySE - movs r0, 0 - b _081C95F8 - .pool -_081C95D4: - movs r0, 0x6 - strh r0, [r4, 0x6] - ldr r1, =0x000186ab - adds r0, r4, 0 - bl sub_81C97B0 - movs r0, 0x8 - b _081C95F8 - .pool -_081C95E8: - movs r0, 0x2 - ands r0, r1 - cmp r0, 0 - bne _081C95F4 - movs r0, 0 - b _081C95F8 -_081C95F4: - movs r0, 0x1 - negs r0, r0 -_081C95F8: - pop {r4} - pop {r1} - bx r1 - thumb_func_end c2_pre_battle_1 - - thumb_func_start sub_81C9600 -sub_81C9600: @ 81C9600 - push {r4,lr} - adds r4, r0, 0 - bl sub_81C9814 - cmp r0, 0 - beq _081C9616 - bl sub_81C93EC - str r0, [r4, 0xC] - movs r0, 0x1 - b _081C9634 -_081C9616: - ldr r0, =gMain - ldrh r1, [r0, 0x2E] - movs r0, 0x3 - ands r0, r1 - cmp r0, 0 - bne _081C962C - movs r0, 0 - b _081C9634 - .pool -_081C962C: - bl sub_81C93EC - str r0, [r4, 0xC] - movs r0, 0x7 -_081C9634: - pop {r4} - pop {r1} - bx r1 - thumb_func_end sub_81C9600 - thumb_func_start sub_81C963C sub_81C963C: @ 81C963C push {r4-r6,lr} diff --git a/asm/pokenav_unk_4.s b/asm/pokenav_unk_4.s index 350609f7dd..38c362fa49 100644 --- a/asm/pokenav_unk_4.s +++ b/asm/pokenav_unk_4.s @@ -1506,7 +1506,7 @@ sub_81CBE50: @ 81CBE50 movs r0, 0x9 bl GetGameStat adds r1, r0, 0 - ldr r0, =0x0001869f @ Note to decompiler: See UNKNOWN_OFFSET + ldr r0, =0x0001869f @ Note to decompiler: See UNKNOWN_POKENAV_OFFSET cmp r1, r0 ble _081CBE68 adds r1, r0, 0 diff --git a/include/pokenav.h b/include/pokenav.h index 4c928068c4..f541760c0c 100644 --- a/include/pokenav.h +++ b/include/pokenav.h @@ -11,6 +11,8 @@ typedef u32 (*LoopedTask)(s32 state); #define LT_FINISH 4 #define LT_SET_STATE(newState) (newState + 5) +#define UNKNOWN_POKENAV_OFFSET 100000 + // pokenav.c extern u32 sub_81C99D4(void); @@ -22,10 +24,20 @@ void FreePokenavSubstruct(u32 index); void *AllocSubstruct(u32 index, u32 size); void Pokenav_AllocAndLoadPalettes(const struct SpritePalette *palettes); bool32 IsLoopedTaskActive(u32 taskId); +void SetPokenavMode(u16 mode); +u32 GetPokenavMode(void); +bool32 CanViewRibbonsMenu(void); // pokenav_match_call_ui.c // pokenav_unk_1.c u32 sub_81C9298(void); +u32 sub_81C92CC(void); +u32 sub_81C9304(void); +u32 sub_81C9338(void); +u32 sub_81C9368(void); +u32 sub_81C941C(void); +void sub_81C9430(void); + #endif //GUARD_POKENAV_H diff --git a/src/pokedex.c b/src/pokedex.c index 3343854cd1..cf144f6196 100644 --- a/src/pokedex.c +++ b/src/pokedex.c @@ -4039,7 +4039,7 @@ void sub_80C0460(u16 weight, u8 left, u8 top) lsls r2, 24\n\ lsrs r2, 24\n\ str r2, [sp, 0x10]\n\ - ldr r5, =0x000186a0 @ Note to decompiler: See UNKNOWN_OFFSET\n\ + ldr r5, =0x000186a0 @ Note to decompiler: See UNKNOWN_POKENAV_OFFSET\n\ muls r0, r5\n\ ldr r1, =0x000011b8\n\ bl __divsi3\n\ @@ -4073,7 +4073,7 @@ _080C04C0:\n\ mov r8, r1\n\ movs r6, 0x1\n\ _080C04C6:\n\ - ldr r1, =0x000186a0 @ Note to decompiler: See UNKNOWN_OFFSET\n\ + ldr r1, =0x000186a0 @ Note to decompiler: See UNKNOWN_POKENAV_OFFSET\n\ adds r0, r7, 0\n\ bl __umodsi3\n\ adds r7, r0, 0\n\ diff --git a/src/pokenav.c b/src/pokenav.c index fba5bd1a60..a5fb155dae 100644 --- a/src/pokenav.c +++ b/src/pokenav.c @@ -15,25 +15,12 @@ enum MODE_FORCE_CALL_2, // Set after making a call, has to exit Pokenav. }; -enum -{ - NAVMENU_CB_UNK_0, - NAVMENU_CB_UNK_1, - NAVMENU_CB_UNK_2, - NAVMENU_CB_UNK_3, - NAVMENU_CB_UNK_4, - NAVMENU_CB_UNK_5, - NAVMENU_CB_UNK_6 -}; - #define LOOPED_TASK_DECODE_STATE(action) (action - 5) #define LOOPED_TASK_ID(primary, secondary) (((secondary) << 16) |(primary)) #define LOOPED_TASK_PRIMARY_ID(taskId) (taskId & 0xFFFF) #define LOOPED_TASK_SECONDARY_ID(taskId) (taskId >> 16) -#define UNKNOWN_OFFSET 100000 - #define SUBSTRUCT_COUNT 19 struct PokenavResources @@ -46,36 +33,41 @@ struct PokenavResources void *field10[SUBSTRUCT_COUNT]; }; -extern u32 sub_81C9430(void); -extern u32 sub_81C941C(void); +struct UnknownPokenavCallbackStruct +{ + u32 (*unk0)(void); + u32 (*unk4)(void); + u32 (*unk8)(void); + u32 (*unkC)(void); + u32 (*unk10)(void); + void (*unk14)(void); + u32 (*unk18)(void); +}; + extern u32 sub_81C9924(void); extern u32 sub_81C99C0(void); extern u32 sub_81C9990(void); extern u32 sub_81C9940(void); -extern u32 sub_81C9338(void); -extern u32 sub_81C9368(void); -extern u32 sub_81C92CC(void); -extern u32 sub_81C9304(void); extern u32 sub_81CC4D4(void); extern u32 sub_81CC554(void); extern u32 sub_81CC5F4(void); extern u32 sub_81CC62C(void); extern u32 sub_81CC65C(void); -extern u32 sub_81CC524(void); +extern void sub_81CC524(void); extern u32 sub_81CC670(void); extern u32 sub_81CCFD8(void); extern u32 sub_81CD070(void); extern u32 sub_81CDDD4(void); extern u32 sub_81CDE2C(void); extern u32 sub_81CDE64(void); -extern u32 sub_81CD1C0(void); +extern void sub_81CD1C0(void); extern u32 sub_81CECA0(void); extern u32 sub_81CEF3C(void); extern u32 sub_81CEFDC(void); extern u32 sub_81CF330(void); extern u32 sub_81CF3A0(void); extern u32 sub_81CF3D0(void); -extern u32 sub_81CEFF0(void); +extern void sub_81CEFF0(void); extern u32 sub_81CF3F8(void); extern u32 sub_81CD024(void); extern u32 sub_81CEF98(void); @@ -85,21 +77,21 @@ extern u32 sub_81CAB24(void); extern u32 sub_81CB260(void); extern u32 sub_81CB29C(void); extern u32 sub_81CB2CC(void); -extern u32 sub_81CAB38(void); +extern void sub_81CAB38(void); extern u32 sub_81CB2E0(void); extern u32 sub_81CF9BC(void); extern u32 sub_81CFA34(void); extern u32 sub_81CFDD0(void); extern u32 sub_81CFE40(void); extern u32 sub_81CFE70(void); -extern u32 sub_81CFA48(void); +extern void sub_81CFA48(void); extern u32 sub_81CFE98(void); extern u32 sub_81D0450(void); extern u32 sub_81D04A0(void); extern u32 sub_81D0978(void); extern u32 sub_81D09B0(void); extern u32 sub_81D09E0(void); -extern u32 sub_81D04B8(void); +extern void sub_81D04B8(void); extern u32 sub_81D09F4(void); extern u32 sub_81CFA04(void); extern u32 sub_81CFE08(void); @@ -126,142 +118,142 @@ static void CB2_Pokenav(void); void sub_81C72BC(void); // Const rom data. -u32 (*const PokenavMenuCallbacks[15][7])(void) = +const struct UnknownPokenavCallbackStruct PokenavMenuCallbacks[15] = { { - sub_81C9298, - sub_81C941C, - sub_81C9924, - sub_81C9990, - sub_81C99C0, - sub_81C9430, - sub_81C99D4, + .unk0 = sub_81C9298, + .unk4 = sub_81C941C, + .unk8 = sub_81C9924, + .unkC = sub_81C9990, + .unk10 = sub_81C99C0, + .unk14 = sub_81C9430, + .unk18 = sub_81C99D4, }, { - sub_81C9298, - sub_81C941C, - sub_81C9940, - sub_81C9990, - sub_81C99C0, - sub_81C9430, - sub_81C99D4, + .unk0 = sub_81C9298, + .unk4 = sub_81C941C, + .unk8 = sub_81C9940, + .unkC = sub_81C9990, + .unk10 = sub_81C99C0, + .unk14 = sub_81C9430, + .unk18 = sub_81C99D4, }, { - sub_81C9338, - sub_81C941C, - sub_81C9940, - sub_81C9990, - sub_81C99C0, - sub_81C9430, - sub_81C99D4, + .unk0 = sub_81C9338, + .unk4 = sub_81C941C, + .unk8 = sub_81C9940, + .unkC = sub_81C9990, + .unk10 = sub_81C99C0, + .unk14 = sub_81C9430, + .unk18 = sub_81C99D4, }, { - sub_81C9368, - sub_81C941C, - sub_81C9940, - sub_81C9990, - sub_81C99C0, - sub_81C9430, - sub_81C99D4, + .unk0 = sub_81C9368, + .unk4 = sub_81C941C, + .unk8 = sub_81C9940, + .unkC = sub_81C9990, + .unk10 = sub_81C99C0, + .unk14 = sub_81C9430, + .unk18 = sub_81C99D4, }, { - sub_81C92CC, - sub_81C941C, - sub_81C9940, - sub_81C9990, - sub_81C99C0, - sub_81C9430, - sub_81C99D4, + .unk0 = sub_81C92CC, + .unk4 = sub_81C941C, + .unk8 = sub_81C9940, + .unkC = sub_81C9990, + .unk10 =sub_81C99C0, + .unk14 = sub_81C9430, + .unk18 = sub_81C99D4, }, { - sub_81C9304, - sub_81C941C, - sub_81C9940, - sub_81C9990, - sub_81C99C0, - sub_81C9430, - sub_81C99D4, + .unk0 = sub_81C9304, + .unk4 = sub_81C941C, + .unk8 = sub_81C9940, + .unkC = sub_81C9990, + .unk10 = sub_81C99C0, + .unk14 = sub_81C9430, + .unk18 = sub_81C99D4, }, { - sub_81CC4D4, - sub_81CC554, - sub_81CC5F4, - sub_81CC62C, - sub_81CC65C, - sub_81CC524, - sub_81CC670, + .unk0 = sub_81CC4D4, + .unk4 = sub_81CC554, + .unk8 = sub_81CC5F4, + .unkC = sub_81CC62C, + .unk10 = sub_81CC65C, + .unk14 = sub_81CC524, + .unk18 = sub_81CC670, }, { - sub_81CCFD8, - sub_81CD070, - sub_81CDDD4, - sub_81CDE2C, - sub_81CDE64, - sub_81CD1C0, - sub_81CECA0, + .unk0 = sub_81CCFD8, + .unk4 = sub_81CD070, + .unk8 = sub_81CDDD4, + .unkC = sub_81CDE2C, + .unk10 = sub_81CDE64, + .unk14 = sub_81CD1C0, + .unk18 = sub_81CECA0, }, { - sub_81CEF3C, - sub_81CEFDC, - sub_81CF330, - sub_81CF3A0, - sub_81CF3D0, - sub_81CEFF0, - sub_81CF3F8, + .unk0 = sub_81CEF3C, + .unk4 = sub_81CEFDC, + .unk8 = sub_81CF330, + .unkC = sub_81CF3A0, + .unk10 = sub_81CF3D0, + .unk14 = sub_81CEFF0, + .unk18 = sub_81CF3F8, }, { - sub_81CD024, - sub_81CD070, - sub_81CDDD4, - sub_81CDE2C, - sub_81CDE64, - sub_81CD1C0, - sub_81CECA0, + .unk0 = sub_81CD024, + .unk4 = sub_81CD070, + .unk8 = sub_81CDDD4, + .unkC = sub_81CDE2C, + .unk10 = sub_81CDE64, + .unk14 = sub_81CD1C0, + .unk18 = sub_81CECA0, }, { - sub_81CEF98, - sub_81CEFDC, - sub_81CF368, - sub_81CF3A0, - sub_81CF3D0, - sub_81CEFF0, - sub_81CF3F8, + .unk0 = sub_81CEF98, + .unk4 = sub_81CEFDC, + .unk8 = sub_81CF368, + .unkC = sub_81CF3A0, + .unk10 = sub_81CF3D0, + .unk14 = sub_81CEFF0, + .unk18 = sub_81CF3F8, }, { - sub_81CAAE8, - sub_81CAB24, - sub_81CB260, - sub_81CB29C, - sub_81CB2CC, - sub_81CAB38, - sub_81CB2E0, + .unk0 = sub_81CAAE8, + .unk4 = sub_81CAB24, + .unk8 = sub_81CB260, + .unkC = sub_81CB29C, + .unk10 = sub_81CB2CC, + .unk14 = sub_81CAB38, + .unk18 = sub_81CB2E0, }, { - sub_81CF9BC, - sub_81CFA34, - sub_81CFDD0, - sub_81CFE40, - sub_81CFE70, - sub_81CFA48, - sub_81CFE98, + .unk0 = sub_81CF9BC, + .unk4 = sub_81CFA34, + .unk8 = sub_81CFDD0, + .unkC = sub_81CFE40, + .unk10 = sub_81CFE70, + .unk14 = sub_81CFA48, + .unk18 = sub_81CFE98, }, { - sub_81D0450, - sub_81D04A0, - sub_81D0978, - sub_81D09B0, - sub_81D09E0, - sub_81D04B8, - sub_81D09F4, + .unk0 = sub_81D0450, + .unk4 = sub_81D04A0, + .unk8 = sub_81D0978, + .unkC = sub_81D09B0, + .unk10 = sub_81D09E0, + .unk14 = sub_81D04B8, + .unk18 = sub_81D09F4, }, { - sub_81CFA04, - sub_81CFA34, - sub_81CFE08, - sub_81CFE40, - sub_81CFE70, - sub_81CFA48, - sub_81CFE98, + .unk0 = sub_81CFA04, + .unk4 = sub_81CFA34, + .unk8 = sub_81CFE08, + .unkC = sub_81CFE40, + .unk10 = sub_81CFE70, + .unk14 = sub_81CFA48, + .unk18 = sub_81CFE98, }, }; @@ -506,7 +498,7 @@ void sub_81C742C(u8 taskId) // Wait for LoopedTask_InitPokenavMenu to finish if (PokenavMainMenuLoopedTaskIsActive()) break; - SetActivePokenavMenu(0 + UNKNOWN_OFFSET); + SetActivePokenavMenu(0 + UNKNOWN_POKENAV_OFFSET); data[0] = 4; break; case 2: @@ -520,10 +512,10 @@ void sub_81C742C(u8 taskId) ShutdownPokenav(); data[0] = 5; } - else if (v1 >= UNKNOWN_OFFSET) + else if (v1 >= UNKNOWN_POKENAV_OFFSET) { - PokenavMenuCallbacks[gPokenavResources->currentMenuIndex][NAVMENU_CB_UNK_6](); - PokenavMenuCallbacks[gPokenavResources->currentMenuIndex][NAVMENU_CB_UNK_5](); + PokenavMenuCallbacks[gPokenavResources->currentMenuIndex].unk18(); + PokenavMenuCallbacks[gPokenavResources->currentMenuIndex].unk14(); if (SetActivePokenavMenu(v1)) { data[0] = 4; @@ -563,16 +555,16 @@ void sub_81C742C(u8 taskId) bool32 SetActivePokenavMenu(u32 indexWithOffset) { - u32 index = indexWithOffset - UNKNOWN_OFFSET; + u32 index = indexWithOffset - UNKNOWN_POKENAV_OFFSET; InitKeys_(); - if (!PokenavMenuCallbacks[index][NAVMENU_CB_UNK_0]()) + if (!PokenavMenuCallbacks[index].unk0()) return FALSE; - if (!PokenavMenuCallbacks[index][NAVMENU_CB_UNK_2]()) + if (!PokenavMenuCallbacks[index].unk8()) return FALSE; - sub_81C7834(PokenavMenuCallbacks[index][NAVMENU_CB_UNK_3], PokenavMenuCallbacks[index][NAVMENU_CB_UNK_4]); - gPokenavResources->currentMenuCb1 = PokenavMenuCallbacks[index][NAVMENU_CB_UNK_1]; + sub_81C7834(PokenavMenuCallbacks[index].unkC, PokenavMenuCallbacks[index].unk10); + gPokenavResources->currentMenuCb1 = PokenavMenuCallbacks[index].unk4; gPokenavResources->currentMenuIndex = index; return TRUE; } @@ -618,7 +610,7 @@ void FreePokenavSubstruct(u32 index) FREE_AND_SET_NULL(gPokenavResources->field10[index]); } -u16 GetPokenavMode(void) +u32 GetPokenavMode(void) { return gPokenavResources->mode; } diff --git a/src/pokenav_unk_1.c b/src/pokenav_unk_1.c index dd2411e017..da05657cb8 100644 --- a/src/pokenav_unk_1.c +++ b/src/pokenav_unk_1.c @@ -1,17 +1,35 @@ #include "global.h" #include "pokenav.h" #include "event_data.h" +#include "main.h" +#include "sound.h" +#include "constants/songs.h" struct Pokenav1Struct { u16 unk0; - u16 unk2; + s16 unk2; u16 unk4; u16 unk6; - u8 unk8[8]; + u32 unk8; + u32 (*unkC)(struct Pokenav1Struct*); }; -extern void sub_81C939C(struct Pokenav1Struct *state); + +extern u32 sub_81C76AC(void); +extern u32 sub_81C963C(struct Pokenav1Struct *a0); +extern u32 sub_81C96FC(struct Pokenav1Struct *a0); +extern u32 sub_81C9814(void); +extern void sub_81C97B0(struct Pokenav1Struct *a0, u32 a1); + +u32 sub_81C9600(struct Pokenav1Struct *a0); +u32 sub_81C9588(struct Pokenav1Struct *a0); +u32 sub_81C9520(struct Pokenav1Struct *a0); +u32 sub_81C943C(struct Pokenav1Struct *a0); +u32 (*sub_81C93EC(void))(struct Pokenav1Struct*); +void sub_81C939C(struct Pokenav1Struct *state); + +extern u8 gUnknown_0861FC59[]; u8 sub_81C9268(void) { @@ -40,4 +58,239 @@ u32 sub_81C9298(void) sub_81C939C(state); return 1; +} + +u32 sub_81C92CC(void) +{ + struct Pokenav1Struct *state = AllocSubstruct(1, sizeof(struct Pokenav1Struct)); + u8 v0; + + if (state == NULL) + return 0; + + state->unk0 = sub_81C9268(); + state->unk2 = 2; + state->unk4 = 2; + state->unk6 = 0; + sub_81C939C(state); + + return 1; +} + +u32 sub_81C9304(void) +{ + struct Pokenav1Struct *state = AllocSubstruct(1, sizeof(struct Pokenav1Struct)); + u8 v0; + + if (state == NULL) + return 0; + + state->unk0 = sub_81C9268(); + state->unk2 = 3; + state->unk4 = 3; + sub_81C939C(state); + + return 1; +} + +u32 sub_81C9338(void) +{ + struct Pokenav1Struct *state = AllocSubstruct(1, sizeof(struct Pokenav1Struct)); + u8 v0; + + if (state == NULL) + return 0; + + state->unk0 = 3; + state->unk2 = 0; + state->unk4 = 5; + state->unk6 = 0; + sub_81C939C(state); + + return 1; +} + +u32 sub_81C9368(void) +{ + struct Pokenav1Struct *state = AllocSubstruct(1, sizeof(struct Pokenav1Struct)); + u8 v0; + + if (state == NULL) + return 0; + + state->unk0 = 4; + state->unk2 = sub_81C76AC(); + state->unk4 = 8 + state->unk2; + state->unk6 = 0; + sub_81C939C(state); + + return 1; +} + +void sub_81C939C(struct Pokenav1Struct *state) +{ + switch (state->unk0) + { + case 0: + SetPokenavMode(0); + // fallthrough + case 1: + case 2: + state->unkC = sub_81C93EC(); + break; + case 3: + state->unkC = sub_81C963C; + break; + case 4: + state->unkC = sub_81C96FC; + break; + } +} + +u32 (*sub_81C93EC(void))(struct Pokenav1Struct*) +{ + switch (GetPokenavMode()) + { + default: + case 0: + return sub_81C943C; + case 1: + return sub_81C9520; + case 2: + return sub_81C9588; + } +} + +u32 sub_81C941C(void) +{ + struct Pokenav1Struct *state = GetSubstructPtr(1); + return state->unkC(state); +} + +void sub_81C9430(void) +{ + FreePokenavSubstruct(1); +} + +u32 sub_81C943C(struct Pokenav1Struct *a0) +{ + if (sub_81C9814() != 0) + return 1; + + if (gMain.newKeys & A_BUTTON) + { + switch (gUnknown_0861FC59[a0->unk2 + a0->unk0 * 6]) + { + case 0: + a0->unk6 = gSaveBlock2Ptr->regionMapZoom ? 2 : 1; + sub_81C97B0(a0, UNKNOWN_POKENAV_OFFSET + 6); + return 8; + case 1: + a0->unk0 = 3; + a0->unk2 = 0; + a0->unk4 = gUnknown_0861FC59[18]; + a0->unkC = sub_81C963C; + return 2; + case 2: + a0->unk6 = 6; + sub_81C97B0(a0, UNKNOWN_POKENAV_OFFSET + 11); + return 8; + case 3: + if (CanViewRibbonsMenu()) + { + a0->unk6 = 9; + sub_81C97B0(a0, UNKNOWN_POKENAV_OFFSET + 12); + return 8; + } + else + { + a0->unkC = sub_81C9600; + return 6; + } + case 4: + return -1; + } + } + + if (gMain.newKeys & B_BUTTON) + return -1; + + return 0; +} + +u32 sub_81C9520(struct Pokenav1Struct *a0) +{ + if (sub_81C9814() != 0) + return 1; + + if (gMain.newKeys & A_BUTTON) + { + if (gUnknown_0861FC59[a0->unk2 + a0->unk0 * 6] == 2) + { + a0->unk6 = 6; + sub_81C97B0(a0, UNKNOWN_POKENAV_OFFSET + 11); + return 8; + } + else + { + PlaySE(SE_HAZURE); + return 0; + } + } + + if (gMain.newKeys & B_BUTTON) + { + PlaySE(SE_HAZURE); + return 0; + } + + return 0; +} + +u32 sub_81C9588(struct Pokenav1Struct *a0) +{ + if (sub_81C9814() != 0) + return 1; + + if (gMain.newKeys & A_BUTTON) + { + u32 v0 = gUnknown_0861FC59[a0->unk2 + a0->unk0 * 6]; + if (v0 != 2 && v0 != 4) + { + PlaySE(SE_HAZURE); + return 0; + } + else if (v0 == 2) + { + a0->unk6 = 6; + sub_81C97B0(a0, UNKNOWN_POKENAV_OFFSET + 11); + return 8; + } + else + { + return -1; + } + } + else if (gMain.newKeys & B_BUTTON) + { + return -1; + } + return 0; +} + +u32 sub_81C9600(struct Pokenav1Struct *a0) +{ + if (sub_81C9814() != 0) + { + a0->unkC = sub_81C93EC(); + return 1; + } + + if (gMain.newKeys & (A_BUTTON | B_BUTTON)) + { + a0->unkC = sub_81C93EC(); + return 7; + } + + return 0; } \ No newline at end of file