diff --git a/asm/macros/scrcmd.inc b/asm/macros/scrcmd.inc index 6a0182e247..e9b71c1b9a 100644 --- a/asm/macros/scrcmd.inc +++ b/asm/macros/scrcmd.inc @@ -2732,9 +2732,9 @@ .short \destVar .endm - .macro ScrCmd_1D7 arg0 - .short SCRCMD_1D7 - .short \arg0 + .macro OpenPoffinCooking isInGroup + .short SCRCMD_OPENPOFFINCOOKING + .short \isInGroup .endm .macro CheckCanCookPoffin destVar diff --git a/include/applications/poffin_berry_selection.h b/include/applications/poffin_berry_selection.h new file mode 100644 index 0000000000..374584c1a2 --- /dev/null +++ b/include/applications/poffin_berry_selection.h @@ -0,0 +1,68 @@ +#ifndef POKEPLATINUM_POFFIN_BERRY_SELECTION_H +#define POKEPLATINUM_POFFIN_BERRY_SELECTION_H + +#include "bag.h" +#include "game_options.h" +#include "journal.h" +#include "overlay_manager.h" +#include "poffin.h" +#include "savedata.h" +#include "trainer_info.h" + +enum { + MAIN_STATE_GET_BERRY_SELECTION, + MAIN_STATE_LOAD_POFFIN_COOKING_APP, + MAIN_STATE_RUN_POFFIN_COOKING_APP, + MAIN_STATE_END, + MAIN_STATE_EXIT, +}; + +enum { + SUB_STATE_LOAD_BAG_APP, + SUB_STATE_RUN_BAG_APP, + SUB_STATE_LOAD_BERRY_TAG_APP, + SUB_STATE_RUN_BERRY_TAG_APP, + SUB_STATE_LOAD_POFFIN_COOKING_APP, + SUB_STATE_EXIT, +}; + +typedef struct PoffinBerrySelectionContext { + int unused; + int isInGroup; + PoffinCase *poffinCase; + SaveData *saveData; + TrainerInfo *trainerInfo; + Bag *bag; + Options *options; + JournalEntry *journalEntry; + BOOL unk_20; + BOOL voiceChat; +} PoffinBerrySelectionContext; + +typedef struct PoffinBerrySelectionData { + enum HeapID heapID; + u16 unk_04; + u16 isInGroup : 8; // yes, it needs to be as such to match + u16 unused2 : 8; + int item; + BagCursor *bagCursor; + PoffinBerrySelectionContext *ctx; + int subState; + void *buffer; + ApplicationManager *appMan; + BOOL unk_20; + s16 unk_24; + u8 unk_26; + u8 voiceChat; +} PoffinBerrySelectionData; + +BOOL PoffinBerrySelection_RunSubApplication(ApplicationManager **appManPtr); +BOOL PoffinBerrySelection_Init(ApplicationManager *appMan, int *state); +BOOL PoffinBerrySelection_Main(ApplicationManager *appMan, int *state); +BOOL PoffinBerrySelection_Exit(ApplicationManager *appMan, int *state); +int PoffinBerrySelection_GetBerrySelection(PoffinBerrySelectionData *data, int *subState); +int PoffinBerrySelection_LoadPoffinCookingApp(PoffinBerrySelectionData *data, int *subState); +int PoffinBerrySelection_RunPoffinCookingApp(PoffinBerrySelectionData *data, int *subState); +int PoffinBerrySelection_End(PoffinBerrySelectionData *data, int *subState); + +#endif // POKEPLATINUM_POFFIN_BERRY_SELECTION_H diff --git a/include/constants/heap.h b/include/constants/heap.h index 02c0be97f9..a6cfbc232b 100644 --- a/include/constants/heap.h +++ b/include/constants/heap.h @@ -57,7 +57,7 @@ enum HeapID { HEAP_ID_52, HEAP_ID_53, HEAP_ID_54, - HEAP_ID_55, + HEAP_ID_POFFIN_BERRY_SELECTION, HEAP_ID_56, HEAP_ID_57, HEAP_ID_58, diff --git a/include/data/scripts/scrcmd.h b/include/data/scripts/scrcmd.h index 4c31faac1a..c4cc03d55c 100644 --- a/include/data/scripts/scrcmd.h +++ b/include/data/scripts/scrcmd.h @@ -476,7 +476,7 @@ ScriptCommand(SCRCMD_CANFITACCESSORY, ScrCm ScriptCommand(SCRCMD_UNUSED_1D4, ScrCmd_Unused_1D4) ScriptCommand(SCRCMD_ADDCONTESTBACKDROP, ScrCmd_AddContestBackdrop) ScriptCommand(SCRCMD_CHECKBACKDROP, ScrCmd_CheckBackdrop) -ScriptCommand(SCRCMD_1D7, ScrCmd_1D7) +ScriptCommand(SCRCMD_OPENPOFFINCOOKING, ScrCmd_OpenPoffinCooking) ScriptCommand(SCRCMD_CHECKCANCOOKPOFFIN, ScrCmd_CheckCanCookPoffin) ScriptCommand(SCRCMD_OPENBATTLETOWERRECORDSAPP, ScrCmd_OpenBattleTowerRecordsApp) ScriptCommand(SCRCMD_SETBATTLETOWERNULL, ScrCmd_SetBattleTowerNull) diff --git a/include/overlay082/ov82_0223B140.h b/include/overlay082/ov82_0223B140.h deleted file mode 100644 index e6df4d047a..0000000000 --- a/include/overlay082/ov82_0223B140.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef POKEPLATINUM_OV82_0223B140_H -#define POKEPLATINUM_OV82_0223B140_H - -#include "overlay_manager.h" - -BOOL ov82_0223B140(ApplicationManager **appManPtr); -int ov82_0223B164(ApplicationManager *appMan, int *param1); -int ov82_0223B1D4(ApplicationManager *appMan, int *param1); -int ov82_0223B24C(ApplicationManager *appMan, int *param1); - -#endif // POKEPLATINUM_OV82_0223B140_H diff --git a/include/overlay082/ov82_0223B2E0.h b/include/overlay082/ov82_0223B2E0.h deleted file mode 100644 index 612eb79e5b..0000000000 --- a/include/overlay082/ov82_0223B2E0.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef POKEPLATINUM_OV82_0223B2E0_H -#define POKEPLATINUM_OV82_0223B2E0_H - -#include "overlay083/struct_ov83_0223C344.h" - -int ov82_0223B2E0(UnkStruct_ov83_0223C344 *param0, int *param1); -int ov82_0223B330(UnkStruct_ov83_0223C344 *param0, int *param1); -int ov82_0223B35C(UnkStruct_ov83_0223C344 *param0, int *param1); -int ov82_0223B37C(UnkStruct_ov83_0223C344 *param0, int *param1); - -#endif // POKEPLATINUM_OV82_0223B2E0_H diff --git a/include/overlay082/struct_ov82_0223B164.h b/include/overlay082/struct_ov82_0223B164.h deleted file mode 100644 index f74bb116be..0000000000 --- a/include/overlay082/struct_ov82_0223B164.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef POKEPLATINUM_STRUCT_OV82_0223B164_H -#define POKEPLATINUM_STRUCT_OV82_0223B164_H - -#include "bag.h" -#include "game_options.h" -#include "journal.h" -#include "poffin.h" -#include "savedata.h" -#include "trainer_info.h" - -typedef struct { - u8 padding_00[4]; - int unk_04; - PoffinCase *poffinCase; - SaveData *saveData; - TrainerInfo *trainerInfo; - Bag *bag; - Options *options; - JournalEntry *journalEntry; - BOOL unk_20; - BOOL unk_24; -} UnkStruct_ov82_0223B164; - -#endif // POKEPLATINUM_STRUCT_OV82_0223B164_H diff --git a/include/overlay083/ov83_0223B5A0.h b/include/overlay083/ov83_0223B5A0.h index f948b326f5..de7c9d7f5c 100644 --- a/include/overlay083/ov83_0223B5A0.h +++ b/include/overlay083/ov83_0223B5A0.h @@ -3,6 +3,11 @@ #include "overlay083/struct_ov83_0223B784.h" +#include "overlay_manager.h" + +BOOL ov83_0223B5B0(ApplicationManager *appMan, int *state); +BOOL ov83_0223B65C(ApplicationManager *appMan, int *state); +BOOL ov83_0223B710(ApplicationManager *appMan, int *state); void ov83_0223B774(UnkStruct_ov83_0223B784 *param0, int param1); void ov83_0223B77C(UnkStruct_ov83_0223B784 *param0, int param1); void ov83_0223B784(UnkStruct_ov83_0223B784 *param0); diff --git a/include/overlay083/struct_ov83_0223C344.h b/include/overlay083/struct_ov83_0223C344.h deleted file mode 100644 index 85ce80640d..0000000000 --- a/include/overlay083/struct_ov83_0223C344.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef POKEPLATINUM_STRUCT_OV83_0223C344_H -#define POKEPLATINUM_STRUCT_OV83_0223C344_H - -#include "overlay082/struct_ov82_0223B164.h" - -#include "bag.h" -#include "overlay_manager.h" - -typedef struct { - enum HeapID heapID; - u16 unk_04; - u16 unk_06_0 : 8; - u16 unk_06_8 : 4; - u16 unk_06_12 : 4; - int unk_08; // Item? - BagCursor *unk_0C; - UnkStruct_ov82_0223B164 *unk_10; - int unk_14; - void *unk_18; - ApplicationManager *appMan; - BOOL unk_20; - s16 unk_24; - u8 unk_26; - u8 unk_27; -} UnkStruct_ov83_0223C344; - -#endif // POKEPLATINUM_STRUCT_OV83_0223C344_H diff --git a/include/poffin_berry_selection_context.h b/include/poffin_berry_selection_context.h new file mode 100644 index 0000000000..efe5518dc6 --- /dev/null +++ b/include/poffin_berry_selection_context.h @@ -0,0 +1,12 @@ +#ifndef POKEPLATINUM_POFFIN_BERRY_SELECTION_CONTEXT_H +#define POKEPLATINUM_POFFIN_BERRY_SELECTION_CONTEXT_H + +#include "applications/poffin_berry_selection.h" +#include "field/field_system_decl.h" + +#include "savedata.h" + +PoffinBerrySelectionContext *PoffinBerrySelectionContext_Create(FieldSystem *fieldSystem, BOOL isInGroup, enum HeapID heapID); +PoffinBerrySelectionContext *PoffinBerrySelectionContext_CreateVoiceChat(FieldSystem *fieldSystem, enum HeapID heapID, BOOL voiceChat); + +#endif // POKEPLATINUM_POFFIN_BERRY_SELECTION_CONTEXT_H diff --git a/include/unk_02099604.h b/include/unk_02099604.h deleted file mode 100644 index e3214dfc95..0000000000 --- a/include/unk_02099604.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef POKEPLATINUM_UNK_02099604_H -#define POKEPLATINUM_UNK_02099604_H - -#include "field/field_system_decl.h" -#include "overlay082/struct_ov82_0223B164.h" - -#include "savedata.h" - -UnkStruct_ov82_0223B164 *sub_02099674(FieldSystem *fieldSystem, int param1, enum HeapID heapID); -UnkStruct_ov82_0223B164 *sub_020996A0(FieldSystem *fieldSystem, enum HeapID heapID, BOOL param2); - -#endif // POKEPLATINUM_UNK_02099604_H diff --git a/platinum.us/main.lsf b/platinum.us/main.lsf index ae13d0d7cf..50b7cc7a54 100644 --- a/platinum.us/main.lsf +++ b/platinum.us/main.lsf @@ -347,7 +347,7 @@ Static main Object main.nef.p/src_poffin_sprite.c.o Object main.nef.p/src_unk_02099500.c.o Object main.nef.p/src_wifi_overlays.c.o - Object main.nef.p/src_unk_02099604.c.o + Object main.nef.p/src_poffin_berry_selection_context.c.o Object main.nef.p/src_unk_020996D0.c.o Object main.nef.p/src_move_reminder_data.c.o Object main.nef.p/src_easy_chat_word_list.c.o @@ -1323,16 +1323,16 @@ Overlay journal_display Object main.nef.p/src_applications_journal_display_journal_printer.c.o } -Overlay overlay82 +Overlay poffin_berry_selection { After battle_anim - Object main.nef.p/src_overlay082_ov82_0223B140.c.o - Object main.nef.p/src_overlay082_ov82_0223B2E0.c.o + Object main.nef.p/src_applications_poffin_berry_selection_main.c.o + Object main.nef.p/src_applications_poffin_berry_selection_callbacks.c.o } Overlay overlay83 { - After overlay82 + After poffin_berry_selection Object main.nef.p/src_overlay083_ov83_0223B5A0.c.o Object main.nef.p/src_overlay083_ov83_0223C958.c.o Object main.nef.p/src_overlay083_ov83_0223D144.c.o @@ -1344,7 +1344,7 @@ Overlay overlay83 Overlay bag { - After overlay82 + After poffin_berry_selection Object main.nef.p/src_applications_bag_main.c.o Object main.nef.p/src_applications_bag_windows.c.o Object main.nef.p/src_applications_bag_sprites.c.o diff --git a/platinum.us/sbins_shared.sha1 b/platinum.us/sbins_shared.sha1 index 1506930733..46915f928b 100644 --- a/platinum.us/sbins_shared.sha1 +++ b/platinum.us/sbins_shared.sha1 @@ -81,7 +81,7 @@ d7a304050d0049809b21cf75937e4d14aaf858c5 *game_opening.sbin b8c85f32459d20b3a6cfde5a1e349215dd0157a0 *poffin_case.sbin 0ba83af5f2cafb311dbc552d77cb1b6b4f45d34e *town_map.sbin 1982ed52ba9469dd625dc5951277fd1c001b26af *journal_display.sbin -429a576c3e5a24f25167051957b22f194d2af781 *overlay82.sbin +429a576c3e5a24f25167051957b22f194d2af781 *poffin_berry_selection.sbin 1904a30bcfb722856130ab7b3d0e79fd0070520d *overlay83.sbin 8bd6a805631e2d661f9d5889e568a72e60f93a04 *bag.sbin c197c9edb988d64dec0a56427dfc6960646dc1f7 *berry_tag.sbin diff --git a/res/field/scripts/scripts_poffin_common.s b/res/field/scripts/scripts_poffin_common.s index 24ede6fbce..a49c0ef4d0 100644 --- a/res/field/scripts/scripts_poffin_common.s +++ b/res/field/scripts/scripts_poffin_common.s @@ -84,7 +84,7 @@ PoffinCommon_CookAlone: GoToIfEq VAR_RESULT, 2, PoffinCommon_PoffinCaseIsFull WaitTime 30, VAR_RESULT Call PoffinCommon_FadeOut - ScrCmd_1D7 0 + OpenPoffinCooking FALSE Call PoffinCommon_ReturnToFieldFadeIn GoTo PoffinCommon_PleaseVisitAgain End @@ -161,7 +161,7 @@ PoffinCommon_DoCookingInAGroup: FadeScreenOut WaitFadeScreen ReleaseAll - ScrCmd_1D7 1 + OpenPoffinCooking TRUE EndCommunication Call PoffinCommon_ReturnToFieldFadeIn GoTo PoffinCommon_PleaseVisitAgain diff --git a/src/applications/poffin_berry_selection/callbacks.c b/src/applications/poffin_berry_selection/callbacks.c new file mode 100644 index 0000000000..c85f123d3a --- /dev/null +++ b/src/applications/poffin_berry_selection/callbacks.c @@ -0,0 +1,182 @@ +#include +#include + +#include "applications/bag/application.h" +#include "applications/berry_tag.h" +#include "applications/poffin_berry_selection.h" +#include "overlay083/ov83_0223B5A0.h" + +#include "bag.h" +#include "bag_context.h" +#include "berry_tag_data.h" +#include "heap.h" +#include "item.h" +#include "overlay_manager.h" + +static int PoffinBerrySelection_LoadBagApp(PoffinBerrySelectionData *data); +static int PoffinBerrySelection_RunBagApp(PoffinBerrySelectionData *data); +static int PoffinBerrySelection_LoadBerryTagApp(PoffinBerrySelectionData *data); +static int PoffinBerrySelection_RunBerryTagApp(PoffinBerrySelectionData *data); + +int PoffinBerrySelection_GetBerrySelection(PoffinBerrySelectionData *data, int *subState) +{ + switch (*subState) { + case SUB_STATE_LOAD_BAG_APP: + *subState = PoffinBerrySelection_LoadBagApp(data); + break; + case SUB_STATE_RUN_BAG_APP: + *subState = PoffinBerrySelection_RunBagApp(data); + break; + case SUB_STATE_LOAD_BERRY_TAG_APP: + *subState = PoffinBerrySelection_LoadBerryTagApp(data); + break; + case SUB_STATE_RUN_BERRY_TAG_APP: + *subState = PoffinBerrySelection_RunBerryTagApp(data); + break; + case SUB_STATE_LOAD_POFFIN_COOKING_APP: + return MAIN_STATE_LOAD_POFFIN_COOKING_APP; + case SUB_STATE_EXIT: + return MAIN_STATE_EXIT; + } + + return MAIN_STATE_GET_BERRY_SELECTION; +} + +int PoffinBerrySelection_LoadPoffinCookingApp(PoffinBerrySelectionData *data, int *subState) +{ + FS_EXTERN_OVERLAY(overlay83); + + const ApplicationManagerTemplate appTemplate = { + ov83_0223B5B0, + ov83_0223B65C, + ov83_0223B710, + FS_OVERLAY_ID(overlay83) + }; + + data->appMan = ApplicationManager_New(&appTemplate, data, data->heapID); + return MAIN_STATE_RUN_POFFIN_COOKING_APP; +} + +int PoffinBerrySelection_RunPoffinCookingApp(PoffinBerrySelectionData *data, int *subState) +{ + if (!PoffinBerrySelection_RunSubApplication(&data->appMan)) { + return MAIN_STATE_RUN_POFFIN_COOKING_APP; + } + + return (data->unk_20 == TRUE) ? MAIN_STATE_GET_BERRY_SELECTION : MAIN_STATE_END; +} + +int PoffinBerrySelection_End(PoffinBerrySelectionData *data, int *subState) +{ + return MAIN_STATE_EXIT; +} + +static int PoffinBerrySelection_LoadBagApp(PoffinBerrySelectionData *data) +{ + FS_EXTERN_OVERLAY(bag); + + const ApplicationManagerTemplate gBagApplicationTemplate = { + BagApplication_Init, + BagApplication_Main, + BagApplication_Exit, + FS_OVERLAY_ID(bag) + }; + static const u8 pockets[] = { POCKET_BERRIES, POCKET_LIST_END }; + + BagContext *bagContext = BagContext_CreateWithPockets(data->ctx->bag, pockets, data->heapID); + enum BagApplicationMode mode = (data->isInGroup == TRUE) ? BAG_MODE_POFFIN_MULTIPLAYER : BAG_MODE_POFFIN_SINGLEPLAYER; + BagContext_Init(bagContext, data->ctx->saveData, mode, data->bagCursor); + + data->appMan = ApplicationManager_New(&gBagApplicationTemplate, bagContext, data->heapID); + data->buffer = bagContext; + + return SUB_STATE_RUN_BAG_APP; +} + +static int PoffinBerrySelection_RunBagApp(PoffinBerrySelectionData *data) +{ + BagContext *bagCtx = NULL; + + if (!PoffinBerrySelection_RunSubApplication(&data->appMan)) { + return SUB_STATE_RUN_BAG_APP; + } + + bagCtx = BagContext_New(data->heapID); + memcpy(bagCtx, data->buffer, BagContext_GetSize()); + Heap_Free(data->buffer); + + data->buffer = NULL; + data->item = BagContext_GetItem(bagCtx); + + Heap_Free(bagCtx); + + switch (BagContext_GetExitCode(bagCtx)) { + case BAG_EXIT_CODE_CHECK_BERRY_TAG: + return SUB_STATE_LOAD_BERRY_TAG_APP; + case BAG_EXIT_CODE_USE_ITEM: + case BAG_EXIT_CODE_GIVE_ITEM: + case BAG_EXIT_CODE_GIVE_FROM_MON_MENU: + case BAG_EXIT_CODE_POFFIN_BERRY_CHOSEN: + break; + case BAG_EXIT_CODE_DONE: + return SUB_STATE_EXIT; + default: + GF_ASSERT(FALSE); + data->item = ITEM_CHERI_BERRY; + break; + } + + GF_ASSERT(Bag_TryRemoveItem(data->ctx->bag, data->item, 1, data->heapID)); + + return SUB_STATE_LOAD_POFFIN_COOKING_APP; +} + +static int PoffinBerrySelection_LoadBerryTagApp(PoffinBerrySelectionData *data) +{ + Bag *bag = data->ctx->bag; + + FS_EXTERN_OVERLAY(berry_tag); + + const ApplicationManagerTemplate appTemplate = { + BerryTag_Init, + BerryTag_Main, + BerryTag_Exit, + FS_OVERLAY_ID(berry_tag) + }; + + data->buffer = BerryTagData_Alloc(data->heapID); + BerryTagData_Add(data->buffer, data->item, TRUE); + + u8 count = 0; + for (u8 i = 0; i < NUM_BERRIES; i++) { + u8 item = Item_ForBerryNumber(i); + + if (Bag_CanRemoveItem(bag, item, 1, data->heapID) == TRUE) { + BerryTagData_Add(data->buffer, item, FALSE); + count++; + } + } + + u8 scroll, index; + BagCursor_GetFieldPocketPosition(data->bagCursor, POCKET_BERRIES, &index, &scroll); + BerryTagData_SetScroll(data->buffer, scroll, index, count + 2); + + data->appMan = ApplicationManager_New(&appTemplate, data->buffer, data->heapID); + return SUB_STATE_RUN_BERRY_TAG_APP; +} + +static int PoffinBerrySelection_RunBerryTagApp(PoffinBerrySelectionData *data) +{ + if (!PoffinBerrySelection_RunSubApplication(&data->appMan)) { + return SUB_STATE_RUN_BERRY_TAG_APP; + } + + u8 scroll, index; + BerryTagData_GetScroll(data->buffer, &scroll, &index); + BagCursor_SetFieldPocketPosition(data->bagCursor, POCKET_BERRIES, index, scroll); + + Heap_Free(data->buffer); + data->buffer = NULL; + + return SUB_STATE_LOAD_BAG_APP; +} diff --git a/src/applications/poffin_berry_selection/main.c b/src/applications/poffin_berry_selection/main.c new file mode 100644 index 0000000000..0c052bb5d0 --- /dev/null +++ b/src/applications/poffin_berry_selection/main.c @@ -0,0 +1,126 @@ +#include "nintendo_wfc/main.h" + +#include +#include + +#include "constants/communication/comm_sync.h" + +#include "applications/poffin_berry_selection.h" + +#include "bag.h" +#include "comm_manager.h" +#include "communication_information.h" +#include "communication_system.h" +#include "heap.h" +#include "overlay_manager.h" +#include "unk_020363E8.h" + +BOOL PoffinBerrySelection_RunSubApplication(ApplicationManager **appManPtr) +{ + if (*appManPtr && ApplicationManager_Exec(*appManPtr)) { + ApplicationManager_Free(*appManPtr); + *appManPtr = NULL; + return TRUE; + } + + return FALSE; +} + +int PoffinBerrySelection_Init(ApplicationManager *appMan, int *state) +{ + PoffinBerrySelectionData *data = NULL; + PoffinBerrySelectionContext *ctx = ApplicationManager_Args(appMan); + + Heap_Create(HEAP_ID_APPLICATION, HEAP_ID_POFFIN_BERRY_SELECTION, 0x20000); + data = ApplicationManager_NewData(appMan, sizeof(PoffinBerrySelectionData), HEAP_ID_POFFIN_BERRY_SELECTION); + MI_CpuClear8(data, sizeof(PoffinBerrySelectionData)); + + data->heapID = HEAP_ID_POFFIN_BERRY_SELECTION; + data->ctx = ctx; + + if (ctx->unk_20 && ctx->voiceChat) { + NintendoWFC_StartVoiceChat(HEAP_ID_POFFIN_BERRY_SELECTION); + } + + data->unk_26 = ctx->unk_20; + data->voiceChat = ctx->voiceChat; + data->bagCursor = BagCursor_New(data->heapID); + + if (ctx->isInGroup == TRUE) { + data->isInGroup = TRUE; + } + + return TRUE; +} + +int PoffinBerrySelection_Main(ApplicationManager *appMan, int *state) +{ + PoffinBerrySelectionData *data = ApplicationManager_Data(appMan); + PoffinBerrySelectionContext *ctx = ApplicationManager_Args(appMan); + + int prevState = *state; + + switch (*state) { + case MAIN_STATE_GET_BERRY_SELECTION: + *state = PoffinBerrySelection_GetBerrySelection(data, &data->subState); + break; + case MAIN_STATE_LOAD_POFFIN_COOKING_APP: + *state = PoffinBerrySelection_LoadPoffinCookingApp(data, &data->subState); + break; + case MAIN_STATE_RUN_POFFIN_COOKING_APP: + *state = PoffinBerrySelection_RunPoffinCookingApp(data, &data->subState); + break; + case MAIN_STATE_END: + *state = PoffinBerrySelection_End(data, &data->subState); + break; + case MAIN_STATE_EXIT: + return TRUE; + } + + if (prevState != *state) { + data->subState = SUB_STATE_LOAD_BAG_APP; + } + + return FALSE; +} + +int PoffinBerrySelection_Exit(ApplicationManager *appMan, int *state) +{ + int heapID = HEAP_ID_SYSTEM; + PoffinBerrySelectionData *data = ApplicationManager_Data(appMan); + PoffinBerrySelectionContext *ctx = ApplicationManager_Args(appMan); + + switch (*state) { + case MAIN_STATE_GET_BERRY_SELECTION: + heapID = data->heapID; + + Heap_Free(data->bagCursor); + MI_CpuClear8(data, sizeof(PoffinBerrySelectionData)); + ApplicationManager_FreeData(appMan); + + if (ctx->unk_20 && ctx->voiceChat) { + NintendoWFC_TerminateVoiceChat(); + } + + Heap_Destroy(heapID); + + if (!ctx->unk_20) { + return TRUE; + } + + CommManager_SetErrorHandling(FALSE, TRUE); + CommTiming_StartSync(SYNC_START_VS_LINK_BATTLE); + (*state)++; + break; + case MAIN_STATE_LOAD_POFFIN_COOKING_APP: + if (CommTiming_IsSyncState(SYNC_START_VS_LINK_BATTLE) || CommSys_ConnectedCount() < CommInfo_CountReceived()) { + return TRUE; + } + break; + default: + GF_ASSERT(FALSE); + break; + } + + return FALSE; +} diff --git a/src/meson.build b/src/meson.build index d131bfcd6e..30c3abfe8b 100644 --- a/src/meson.build +++ b/src/meson.build @@ -329,7 +329,7 @@ pokeplatinum_c = files( 'poffin_sprite.c', 'unk_02099500.c', 'wifi_overlays.c', - 'unk_02099604.c', + 'poffin_berry_selection_context.c', 'unk_020996D0.c', 'move_reminder_data.c', 'easy_chat_word_list.c', @@ -821,8 +821,8 @@ pokeplatinum_c = files( 'applications/town_map/map_blocks.c', 'applications/journal_display/journal_controller.c', 'applications/journal_display/journal_printer.c', - 'overlay082/ov82_0223B140.c', - 'overlay082/ov82_0223B2E0.c', + 'applications/poffin_berry_selection/main.c', + 'applications/poffin_berry_selection/callbacks.c', 'overlay083/ov83_0223B5A0.c', 'overlay083/ov83_0223C958.c', 'overlay083/ov83_0223D144.c', diff --git a/src/overlay082/ov82_0223B140.c b/src/overlay082/ov82_0223B140.c deleted file mode 100644 index 60034cbb6b..0000000000 --- a/src/overlay082/ov82_0223B140.c +++ /dev/null @@ -1,130 +0,0 @@ -#include "overlay082/ov82_0223B140.h" - -#include -#include - -#include "nintendo_wfc/main.h" -#include "overlay082/ov82_0223B2E0.h" -#include "overlay082/struct_ov82_0223B164.h" -#include "overlay083/struct_ov83_0223C344.h" - -#include "bag.h" -#include "comm_manager.h" -#include "communication_information.h" -#include "communication_system.h" -#include "heap.h" -#include "overlay_manager.h" -#include "unk_020363E8.h" - -BOOL ov82_0223B140(ApplicationManager **appManPtr) -{ - if (*appManPtr) { - if (ApplicationManager_Exec(*appManPtr)) { - ApplicationManager_Free(*appManPtr); - *appManPtr = NULL; - return 1; - } - } - - return 0; -} - -int ov82_0223B164(ApplicationManager *appMan, int *param1) -{ - UnkStruct_ov83_0223C344 *v0 = NULL; - UnkStruct_ov82_0223B164 *v1 = (UnkStruct_ov82_0223B164 *)ApplicationManager_Args(appMan); - - Heap_Create(HEAP_ID_APPLICATION, HEAP_ID_55, 0x20000); - v0 = ApplicationManager_NewData(appMan, sizeof(UnkStruct_ov83_0223C344), HEAP_ID_55); - MI_CpuClear8(v0, sizeof(UnkStruct_ov83_0223C344)); - - v0->heapID = HEAP_ID_55; - v0->unk_10 = v1; - - if ((v1->unk_20) && (v1->unk_24)) { - NintendoWFC_StartVoiceChat(HEAP_ID_55); - } - - v0->unk_26 = v1->unk_20; - v0->unk_27 = v1->unk_24; - v0->unk_0C = BagCursor_New(v0->heapID); - - if (v1->unk_04 == 1) { - v0->unk_06_0 = 1; - } - - return 1; -} - -int ov82_0223B1D4(ApplicationManager *appMan, int *param1) -{ - int v0; - UnkStruct_ov83_0223C344 *v1 = ApplicationManager_Data(appMan); - UnkStruct_ov82_0223B164 *v2 = (UnkStruct_ov82_0223B164 *)ApplicationManager_Args(appMan); - - v0 = *param1; - - switch (*param1) { - case 0: - *param1 = ov82_0223B2E0(v1, &(v1->unk_14)); - break; - case 1: - *param1 = ov82_0223B330(v1, &(v1->unk_14)); - break; - case 2: - *param1 = ov82_0223B35C(v1, &(v1->unk_14)); - break; - case 3: - *param1 = ov82_0223B37C(v1, &(v1->unk_14)); - break; - case 4: - return 1; - } - - if (v0 != *param1) { - v1->unk_14 = 0; - } - - return 0; -} - -int ov82_0223B24C(ApplicationManager *appMan, int *param1) -{ - int heapID = HEAP_ID_SYSTEM; - UnkStruct_ov83_0223C344 *v1 = ApplicationManager_Data(appMan); - UnkStruct_ov82_0223B164 *v2 = (UnkStruct_ov82_0223B164 *)ApplicationManager_Args(appMan); - - switch (*param1) { - case 0: - heapID = v1->heapID; - - Heap_Free(v1->unk_0C); - MI_CpuClear8(v1, sizeof(UnkStruct_ov83_0223C344)); - ApplicationManager_FreeData(appMan); - - if ((v2->unk_20) && (v2->unk_24)) { - NintendoWFC_TerminateVoiceChat(); - } - - Heap_Destroy(heapID); - - if (v2->unk_20 == 0) { - return 1; - } - - CommManager_SetErrorHandling(0, 1); - CommTiming_StartSync(4); - (*param1)++; - break; - case 1: - if ((CommTiming_IsSyncState(4)) || (CommSys_ConnectedCount() < CommInfo_CountReceived())) { - return 1; - } - break; - default: - GF_ASSERT(FALSE); - break; - } - - return 0; -} diff --git a/src/overlay082/ov82_0223B2E0.c b/src/overlay082/ov82_0223B2E0.c deleted file mode 100644 index 4b30be7c81..0000000000 --- a/src/overlay082/ov82_0223B2E0.c +++ /dev/null @@ -1,205 +0,0 @@ -#include "overlay082/ov82_0223B2E0.h" - -#include -#include - -#include "applications/bag/application.h" -#include "applications/berry_tag.h" -#include "overlay082/ov82_0223B140.h" -#include "overlay083/struct_ov83_0223C344.h" - -#include "bag.h" -#include "bag_context.h" -#include "berry_tag_data.h" -#include "heap.h" -#include "item.h" -#include "overlay_manager.h" - -FS_EXTERN_OVERLAY(overlay83); -FS_EXTERN_OVERLAY(bag); -FS_EXTERN_OVERLAY(berry_tag); - -static int ov82_0223B380(UnkStruct_ov83_0223C344 *param0); -static int ov82_0223B3DC(UnkStruct_ov83_0223C344 *param0); -static int ov82_0223B470(UnkStruct_ov83_0223C344 *param0); -static int ov82_0223B510(UnkStruct_ov83_0223C344 *param0); -int ov83_0223B5B0(ApplicationManager *appMan, int *param1); -int ov83_0223B65C(ApplicationManager *appMan, int *param1); -int ov83_0223B710(ApplicationManager *appMan, int *param1); - -int ov82_0223B2E0(UnkStruct_ov83_0223C344 *param0, int *param1) -{ - switch (*param1) { - case 0: - *param1 = ov82_0223B380(param0); - break; - case 1: - *param1 = ov82_0223B3DC(param0); - break; - case 2: - *param1 = ov82_0223B470(param0); - break; - case 3: - *param1 = ov82_0223B510(param0); - break; - case 4: - return 1; - case 5: - return 4; - } - - return 0; -} - -int ov82_0223B330(UnkStruct_ov83_0223C344 *param0, int *param1) -{ - FS_EXTERN_OVERLAY(overlay83); - - const ApplicationManagerTemplate v0 = { - ov83_0223B5B0, - ov83_0223B65C, - ov83_0223B710, - FS_OVERLAY_ID(overlay83) - }; - - param0->appMan = ApplicationManager_New(&v0, param0, param0->heapID); - return 2; -} - -int ov82_0223B35C(UnkStruct_ov83_0223C344 *param0, int *param1) -{ - if (ov82_0223B140(¶m0->appMan) == 0) { - return 2; - } - - if (param0->unk_20 == 1) { - return 0; - } else { - return 3; - } -} - -int ov82_0223B37C(UnkStruct_ov83_0223C344 *param0, int *param1) -{ - return 4; -} - -static int ov82_0223B380(UnkStruct_ov83_0223C344 *param0) -{ - void *v0; - u32 v1; - - FS_EXTERN_OVERLAY(bag); - - const ApplicationManagerTemplate Unk_ov84_02241130 = { - BagApplication_Init, BagApplication_Main, BagApplication_Exit, FS_OVERLAY_ID(bag) - }; - static const u8 v3[] = { - 4, 0xff - }; - - v0 = BagContext_CreateWithPockets(param0->unk_10->bag, v3, param0->heapID); - - if (param0->unk_06_0 == 1) { - v1 = 5; - } else { - v1 = 4; - } - - BagContext_Init(v0, param0->unk_10->saveData, v1, param0->unk_0C); - - param0->appMan = ApplicationManager_New(&Unk_ov84_02241130, v0, param0->heapID); - param0->unk_18 = v0; - - return 1; -} - -static int ov82_0223B3DC(UnkStruct_ov83_0223C344 *param0) -{ - BagContext *v0 = NULL; - BOOL v1; - - if (!ov82_0223B140(¶m0->appMan)) { - return 1; - } - - v0 = BagContext_New(param0->heapID); - memcpy(v0, param0->unk_18, BagContext_GetSize()); - Heap_Free(param0->unk_18); - - param0->unk_18 = NULL; - param0->unk_08 = BagContext_GetItem(v0); // - - Heap_Free(v0); - - switch (BagContext_GetExitCode(v0)) { - case 1: - return 2; - case 0: - case 2: - case 4: - case 3: - break; - case 5: - return 5; - default: - GF_ASSERT(FALSE); - param0->unk_08 = 149; - break; - } - - v1 = Bag_TryRemoveItem(param0->unk_10->bag, param0->unk_08, 1, param0->heapID); - GF_ASSERT(v1); - - return 4; -} - -static int ov82_0223B470(UnkStruct_ov83_0223C344 *param0) -{ - u8 i; - u8 v1, v2, v3, item; - Bag *bag = param0->unk_10->bag; - - FS_EXTERN_OVERLAY(berry_tag); - - const ApplicationManagerTemplate v6 = { - BerryTag_Init, BerryTag_Main, BerryTag_Exit, FS_OVERLAY_ID(berry_tag) - }; - - param0->unk_18 = BerryTagData_Alloc(param0->heapID); - BerryTagData_Add(param0->unk_18, param0->unk_08, TRUE); - - v3 = 0; - - for (i = 0; i < NUM_BERRIES; i++) { - item = Item_ForBerryNumber(i); - - if (Bag_CanRemoveItem(bag, item, 1, param0->heapID) == TRUE) { - BerryTagData_Add(param0->unk_18, item, FALSE); - v3++; - } - } - - BagCursor_GetFieldPocketPosition(param0->unk_0C, 4, &v2, &v1); - BerryTagData_SetScroll(param0->unk_18, v1, v2, v3 + 2); - - param0->appMan = ApplicationManager_New(&v6, param0->unk_18, param0->heapID); - return 3; -} - -static int ov82_0223B510(UnkStruct_ov83_0223C344 *param0) -{ - u8 v0, v1; - - if (!ov82_0223B140(¶m0->appMan)) { - return 3; - } - - BerryTagData_GetScroll(param0->unk_18, &v0, &v1); - BagCursor_SetFieldPocketPosition(param0->unk_0C, 4, v1, v0); - - Heap_Free(param0->unk_18); - param0->unk_18 = NULL; - - return 0; -} diff --git a/src/overlay083/ov83_0223B5A0.c b/src/overlay083/ov83_0223B5A0.c index 6cd2dd2664..a34da38b60 100644 --- a/src/overlay083/ov83_0223B5A0.c +++ b/src/overlay083/ov83_0223B5A0.c @@ -9,6 +9,7 @@ #include "struct_decls/tv_broadcast.h" #include "struct_decls/wi_fi_list.h" +#include "applications/poffin_berry_selection.h" #include "nintendo_wfc/main.h" #include "overlay083/ov83_0223C958.h" #include "overlay083/ov83_0223D150.h" @@ -16,7 +17,6 @@ #include "overlay083/ov83_0223D6A8.h" #include "overlay083/ov83_0223F7F4.h" #include "overlay083/struct_ov83_0223B784.h" -#include "overlay083/struct_ov83_0223C344.h" #include "overlay083/struct_ov83_0223FCE8.h" #include "savedata/save_table.h" @@ -43,7 +43,7 @@ #include "vram_transfer.h" #include "wifi_list.h" -typedef int (*UnkFuncPtr_ov83_0224024C)(UnkStruct_ov83_0223C344 *, UnkStruct_ov83_0223B784 *, int *); +typedef int (*UnkFuncPtr_ov83_0224024C)(PoffinBerrySelectionData *, UnkStruct_ov83_0223B784 *, int *); typedef struct { UnkFuncPtr_ov83_0224024C unk_00; @@ -53,17 +53,17 @@ typedef struct { int ov83_0223B5B0(ApplicationManager *appMan, int *param1); int ov83_0223B65C(ApplicationManager *appMan, int *param1); int ov83_0223B710(ApplicationManager *appMan, int *param1); -static int ov83_0223C344(UnkStruct_ov83_0223C344 *param0, UnkStruct_ov83_0223B784 *param1, int *param2); -static int ov83_0223B78C(UnkStruct_ov83_0223C344 *param0, UnkStruct_ov83_0223B784 *param1, int *param2); -static int ov83_0223B920(UnkStruct_ov83_0223C344 *param0, UnkStruct_ov83_0223B784 *param1, int *param2); -static int ov83_0223B950(UnkStruct_ov83_0223C344 *param0, UnkStruct_ov83_0223B784 *param1, int *param2); -static int ov83_0223B964(UnkStruct_ov83_0223C344 *param0, UnkStruct_ov83_0223B784 *param1, int *param2); -static int ov83_0223B9EC(UnkStruct_ov83_0223C344 *param0, UnkStruct_ov83_0223B784 *param1, int *param2); -static int ov83_0223BB40(UnkStruct_ov83_0223C344 *param0, UnkStruct_ov83_0223B784 *param1, int *param2); -static int ov83_0223BCEC(UnkStruct_ov83_0223C344 *param0, UnkStruct_ov83_0223B784 *param1, int *param2); -static int ov83_0223BF74(UnkStruct_ov83_0223C344 *param0, UnkStruct_ov83_0223B784 *param1, int *param2); -static int ov83_0223C24C(UnkStruct_ov83_0223C344 *param0, UnkStruct_ov83_0223B784 *param1, int *param2); -static int ov83_0223C258(UnkStruct_ov83_0223C344 *param0, UnkStruct_ov83_0223B784 *param1, int *param2); +static int ov83_0223C344(PoffinBerrySelectionData *param0, UnkStruct_ov83_0223B784 *param1, int *param2); +static int ov83_0223B78C(PoffinBerrySelectionData *param0, UnkStruct_ov83_0223B784 *param1, int *param2); +static int ov83_0223B920(PoffinBerrySelectionData *param0, UnkStruct_ov83_0223B784 *param1, int *param2); +static int ov83_0223B950(PoffinBerrySelectionData *param0, UnkStruct_ov83_0223B784 *param1, int *param2); +static int ov83_0223B964(PoffinBerrySelectionData *param0, UnkStruct_ov83_0223B784 *param1, int *param2); +static int ov83_0223B9EC(PoffinBerrySelectionData *param0, UnkStruct_ov83_0223B784 *param1, int *param2); +static int ov83_0223BB40(PoffinBerrySelectionData *param0, UnkStruct_ov83_0223B784 *param1, int *param2); +static int ov83_0223BCEC(PoffinBerrySelectionData *param0, UnkStruct_ov83_0223B784 *param1, int *param2); +static int ov83_0223BF74(PoffinBerrySelectionData *param0, UnkStruct_ov83_0223B784 *param1, int *param2); +static int ov83_0223C24C(PoffinBerrySelectionData *param0, UnkStruct_ov83_0223B784 *param1, int *param2); +static int ov83_0223C258(PoffinBerrySelectionData *param0, UnkStruct_ov83_0223B784 *param1, int *param2); static void ov83_0223C3E8(UnkStruct_ov83_0223B784 *param0); static void ov83_0223C480(UnkStruct_ov83_0223B784 *param0); static void ov83_0223C558(UnkStruct_ov83_0223B784 *param0); @@ -72,9 +72,9 @@ static void ov83_0223C6D4(UnkStruct_ov83_0223B784 *param0); static void ov83_0223C758(UnkStruct_ov83_0223B784 *param0); static void ov83_0223C7FC(UnkStruct_ov83_0223B784 *param0); static void ov83_0223C90C(UnkStruct_ov83_0223B784 *param0); -static void ov83_0223C82C(UnkStruct_ov83_0223C344 *param0, UnkStruct_ov83_0223B784 *param1); -static void ov83_0223C87C(UnkStruct_ov83_0223C344 *param0, UnkStruct_ov83_0223B784 *param1); -static BOOL ov83_0223C8B0(UnkStruct_ov83_0223C344 *param0, Poffin *param1, int param2); +static void ov83_0223C82C(PoffinBerrySelectionData *param0, UnkStruct_ov83_0223B784 *param1); +static void ov83_0223C87C(PoffinBerrySelectionData *param0, UnkStruct_ov83_0223B784 *param1); +static BOOL ov83_0223C8B0(PoffinBerrySelectionData *param0, Poffin *param1, int param2); static const UnkStruct_ov83_0224024C Unk_ov83_0224024C[] = { { ov83_0223B78C, 0x1 }, @@ -95,8 +95,8 @@ static const UnkStruct_ov83_0224024C Unk_ov83_0224024C[] = { static void ov83_0223B5A0(void *param0) { - UnkStruct_ov83_0223C344 *v0 = (UnkStruct_ov83_0223C344 *)param0; - UnkStruct_ov83_0223B784 *v1 = (v0->unk_18); + PoffinBerrySelectionData *v0 = (PoffinBerrySelectionData *)param0; + UnkStruct_ov83_0223B784 *v1 = v0->buffer; ov83_0223CBFC(v1); VramTransfer_Process(); @@ -104,32 +104,28 @@ static void ov83_0223B5A0(void *param0) int ov83_0223B5B0(ApplicationManager *appMan, int *param1) { - UnkStruct_ov83_0223C344 *v0 = ApplicationManager_Args(appMan); + PoffinBerrySelectionData *v0 = ApplicationManager_Args(appMan); UnkStruct_ov83_0223B784 *v1; Heap_Create(HEAP_ID_APPLICATION, HEAP_ID_56, 0x20000); v1 = ApplicationManager_NewData(appMan, sizeof(UnkStruct_ov83_0223B784), HEAP_ID_56); memset(v1, 0, sizeof(UnkStruct_ov83_0223B784)); - v0->unk_18 = v1; + v0->buffer = v1; v1->heapID = HEAP_ID_56; VramTransfer_New(16, v1->heapID); - if (v0->unk_06_0 == 1) { - v1->unk_1490 = 1; - } else { - v1->unk_1490 = 0; - } + v1->unk_1490 = v0->isInGroup == TRUE; - ov83_0223D150(v1, v0->unk_10->trainerInfo); + ov83_0223D150(v1, v0->ctx->trainerInfo); if (v0->unk_26) { sub_0203632C(1); } - v1->unk_24 = Options_Frame(v0->unk_10->options); - v1->unk_28 = Options_TextFrameDelay(v0->unk_10->options); + v1->unk_24 = Options_Frame(v0->ctx->options); + v1->unk_28 = Options_TextFrameDelay(v0->ctx->options); v1->unk_31C = 1; SetVBlankCallback(ov83_0223B5A0, v0); @@ -142,7 +138,7 @@ int ov83_0223B5B0(ApplicationManager *appMan, int *param1) int ov83_0223B65C(ApplicationManager *appMan, int *param1) { int v0, v1; - UnkStruct_ov83_0223C344 *v2 = ApplicationManager_Args(appMan); + PoffinBerrySelectionData *v2 = ApplicationManager_Args(appMan); UnkStruct_ov83_0223B784 *v3 = (UnkStruct_ov83_0223B784 *)ApplicationManager_Data(appMan); const UnkStruct_ov83_0224024C *v4; @@ -169,7 +165,7 @@ int ov83_0223B65C(ApplicationManager *appMan, int *param1) v3->unk_10 = 0; - if (!v2->unk_06_0) { + if (!v2->isInGroup) { break; } @@ -207,7 +203,7 @@ int ov83_0223B65C(ApplicationManager *appMan, int *param1) int ov83_0223B710(ApplicationManager *appMan, int *param1) { int heapID; - UnkStruct_ov83_0223C344 *v1 = ApplicationManager_Args(appMan); + PoffinBerrySelectionData *v1 = ApplicationManager_Args(appMan); UnkStruct_ov83_0223B784 *v2 = (UnkStruct_ov83_0223B784 *)ApplicationManager_Data(appMan); heapID = v2->heapID; @@ -226,7 +222,7 @@ int ov83_0223B710(ApplicationManager *appMan, int *param1) MI_CpuClear8(v2, sizeof(UnkStruct_ov83_0223B784)); ApplicationManager_FreeData(appMan); - v1->unk_18 = NULL; + v1->buffer = NULL; Heap_Destroy(heapID); return 1; @@ -249,7 +245,7 @@ void ov83_0223B784(UnkStruct_ov83_0223B784 *param0) param0->unk_04 = 1; } -static int ov83_0223B78C(UnkStruct_ov83_0223C344 *param0, UnkStruct_ov83_0223B784 *param1, int *param2) +static int ov83_0223B78C(PoffinBerrySelectionData *param0, UnkStruct_ov83_0223B784 *param1, int *param2) { switch (*param2) { case 0: @@ -300,7 +296,7 @@ static int ov83_0223B78C(UnkStruct_ov83_0223C344 *param0, UnkStruct_ov83_0223B78 return param1->unk_0C; } -static int ov83_0223B920(UnkStruct_ov83_0223C344 *param0, UnkStruct_ov83_0223B784 *param1, int *param2) +static int ov83_0223B920(PoffinBerrySelectionData *param0, UnkStruct_ov83_0223B784 *param1, int *param2) { BOOL v0; @@ -315,7 +311,7 @@ static int ov83_0223B920(UnkStruct_ov83_0223C344 *param0, UnkStruct_ov83_0223B78 return param1->unk_0C + 1; } -static int ov83_0223B950(UnkStruct_ov83_0223C344 *param0, UnkStruct_ov83_0223B784 *param1, int *param2) +static int ov83_0223B950(PoffinBerrySelectionData *param0, UnkStruct_ov83_0223B784 *param1, int *param2) { if (param1->unk_14) { param1->unk_0C = param1->unk_18; @@ -325,7 +321,7 @@ static int ov83_0223B950(UnkStruct_ov83_0223C344 *param0, UnkStruct_ov83_0223B78 return param1->unk_0C; } -static int ov83_0223B964(UnkStruct_ov83_0223C344 *param0, UnkStruct_ov83_0223B784 *param1, int *param2) +static int ov83_0223B964(PoffinBerrySelectionData *param0, UnkStruct_ov83_0223B784 *param1, int *param2) { BOOL v0; @@ -335,7 +331,7 @@ static int ov83_0223B964(UnkStruct_ov83_0223C344 *param0, UnkStruct_ov83_0223B78 (*param2)++; break; case 1: - param1->unk_1494.unk_00.unk_00 = param0->unk_08; + param1->unk_1494.unk_00.unk_00 = param0->item; { int v1; @@ -363,7 +359,7 @@ static int ov83_0223B964(UnkStruct_ov83_0223C344 *param0, UnkStruct_ov83_0223B78 return param1->unk_0C; } -static int ov83_0223B9EC(UnkStruct_ov83_0223C344 *param0, UnkStruct_ov83_0223B784 *param1, int *param2) +static int ov83_0223B9EC(PoffinBerrySelectionData *param0, UnkStruct_ov83_0223B784 *param1, int *param2) { u32 v0; int v1; @@ -436,7 +432,7 @@ static int ov83_0223B9EC(UnkStruct_ov83_0223C344 *param0, UnkStruct_ov83_0223B78 return param1->unk_0C; } -static int ov83_0223BB40(UnkStruct_ov83_0223C344 *param0, UnkStruct_ov83_0223B784 *param1, int *param2) +static int ov83_0223BB40(PoffinBerrySelectionData *param0, UnkStruct_ov83_0223B784 *param1, int *param2) { BOOL v0; @@ -515,7 +511,7 @@ static int ov83_0223BB40(UnkStruct_ov83_0223C344 *param0, UnkStruct_ov83_0223B78 return param1->unk_0C; } -static int ov83_0223BCEC(UnkStruct_ov83_0223C344 *param0, UnkStruct_ov83_0223B784 *param1, int *param2) +static int ov83_0223BCEC(PoffinBerrySelectionData *param0, UnkStruct_ov83_0223B784 *param1, int *param2) { Poffin *v0; BOOL v1; @@ -559,7 +555,7 @@ static int ov83_0223BCEC(UnkStruct_ov83_0223C344 *param0, UnkStruct_ov83_0223B78 } break; case 3: { - GameRecords *v2 = SaveData_GetGameRecords(param0->unk_10->saveData); + GameRecords *v2 = SaveData_GetGameRecords(param0->ctx->saveData); if (param1->unk_1490 == 0) { GameRecords_IncrementTrainerScore(v2, TRAINER_SCORE_EVENT_UNK_12); @@ -571,7 +567,7 @@ static int ov83_0223BCEC(UnkStruct_ov83_0223C344 *param0, UnkStruct_ov83_0223B78 } if (param1->unk_1490 != 0) { - WiFiList *v3 = SaveData_GetWiFiList(param0->unk_10->saveData); + WiFiList *v3 = SaveData_GetWiFiList(param0->ctx->saveData); int v4; int v5, v6; int v7; @@ -580,7 +576,7 @@ static int ov83_0223BCEC(UnkStruct_ov83_0223C344 *param0, UnkStruct_ov83_0223B78 for (v4 = 0; v4 < param1->unk_1488; v4++) { v5 = param1->unk_1494.unk_130[v4]; v8 = CommInfo_DWCFriendData(v5); - v6 = sub_0203909C(param0->unk_10->saveData, v8, &v7); + v6 = sub_0203909C(param0->ctx->saveData, v8, &v7); switch (v6) { case 0: @@ -631,7 +627,7 @@ static int ov83_0223BCEC(UnkStruct_ov83_0223C344 *param0, UnkStruct_ov83_0223B78 return param1->unk_0C; } -static int ov83_0223BF74(UnkStruct_ov83_0223C344 *param0, UnkStruct_ov83_0223B784 *param1, int *param2) +static int ov83_0223BF74(PoffinBerrySelectionData *param0, UnkStruct_ov83_0223B784 *param1, int *param2) { u32 v0; BOOL v1; @@ -712,14 +708,14 @@ static int ov83_0223BF74(UnkStruct_ov83_0223C344 *param0, UnkStruct_ov83_0223B78 if (v0 == YES_NO_TOUCH_MENU_YES || v0 == YES_NO_TOUCH_MENU_NO) { if (v0 == YES_NO_TOUCH_MENU_YES) { - if (PoffinCase_CountFilledSlots(param0->unk_10->poffinCase) >= MAX_POFFINS) { + if (PoffinCase_CountFilledSlots(param0->ctx->poffinCase) >= MAX_POFFINS) { ov83_0223EC8C(¶m1->unk_6A0, 2); (*param2) = 10; param1->unk_1C = (30 * 5); break; } - if (Bag_HasItemsInPocket(param0->unk_10->bag, POCKET_BERRIES) == FALSE) { + if (Bag_HasItemsInPocket(param0->ctx->bag, POCKET_BERRIES) == FALSE) { ov83_0223EC8C(¶m1->unk_6A0, 5); (*param2) = 10; param1->unk_1C = (30 * 5); @@ -772,20 +768,20 @@ static int ov83_0223BF74(UnkStruct_ov83_0223C344 *param0, UnkStruct_ov83_0223B78 return param1->unk_0C; } -static int ov83_0223C24C(UnkStruct_ov83_0223C344 *param0, UnkStruct_ov83_0223B784 *param1, int *param2) +static int ov83_0223C24C(PoffinBerrySelectionData *param0, UnkStruct_ov83_0223B784 *param1, int *param2) { return ov83_0223CB5C(param1, param2); } -static int ov83_0223C258(UnkStruct_ov83_0223C344 *param0, UnkStruct_ov83_0223B784 *param1, int *param2) +static int ov83_0223C258(PoffinBerrySelectionData *param0, UnkStruct_ov83_0223B784 *param1, int *param2) { switch (*param2) { case 0: if (param1->unk_1494.unk_145 == 1) { ov83_0223EC8C(¶m1->unk_6A0, 3); - param0->unk_20 = 1; + param0->unk_20 = TRUE; } else { - param0->unk_20 = 0; + param0->unk_20 = FALSE; if (param1->unk_1488 <= 1) { (*param2) = 2; @@ -798,7 +794,7 @@ static int ov83_0223C258(UnkStruct_ov83_0223C344 *param0, UnkStruct_ov83_0223B78 if (param1->unk_1490 == 1) { journalEntryOnlineEvent = JournalEntry_CreateEventMadePoffins(param1->heapID); - JournalEntry_SaveData(param0->unk_10->journalEntry, journalEntryOnlineEvent, JOURNAL_ONLINE_EVENT); + JournalEntry_SaveData(param0->ctx->journalEntry, journalEntryOnlineEvent, JOURNAL_ONLINE_EVENT); } } @@ -831,7 +827,7 @@ static int ov83_0223C258(UnkStruct_ov83_0223C344 *param0, UnkStruct_ov83_0223B78 return param1->unk_0C; } -static int ov83_0223C344(UnkStruct_ov83_0223C344 *param0, UnkStruct_ov83_0223B784 *param1, int *param2) +static int ov83_0223C344(PoffinBerrySelectionData *param0, UnkStruct_ov83_0223B784 *param1, int *param2) { ov83_0223DB30(¶m1->unk_3C0); ov83_0223DEC4(¶m1->unk_5B0); @@ -1053,7 +1049,7 @@ static void ov83_0223C7FC(UnkStruct_ov83_0223B784 *param0) } } -static void ov83_0223C82C(UnkStruct_ov83_0223C344 *param0, UnkStruct_ov83_0223B784 *param1) +static void ov83_0223C82C(PoffinBerrySelectionData *param0, UnkStruct_ov83_0223B784 *param1) { int v0; @@ -1070,7 +1066,7 @@ static void ov83_0223C82C(UnkStruct_ov83_0223C344 *param0, UnkStruct_ov83_0223B7 } } -static void ov83_0223C87C(UnkStruct_ov83_0223C344 *param0, UnkStruct_ov83_0223B784 *param1) +static void ov83_0223C87C(PoffinBerrySelectionData *param0, UnkStruct_ov83_0223B784 *param1) { GF_ASSERT(param1->unk_1494.unk_100); @@ -1082,16 +1078,16 @@ static void ov83_0223C87C(UnkStruct_ov83_0223C344 *param0, UnkStruct_ov83_0223B7 } } -static BOOL ov83_0223C8B0(UnkStruct_ov83_0223C344 *param0, Poffin *param1, int param2) +static BOOL ov83_0223C8B0(PoffinBerrySelectionData *param0, Poffin *param1, int param2) { int v0; u16 v1; int v2; BOOL v3 = 1; - TVBroadcast *broadcast = SaveData_GetTVBroadcast(param0->unk_10->saveData); + TVBroadcast *broadcast = SaveData_GetTVBroadcast(param0->ctx->saveData); for (v0 = 0; v0 < param2; v0++) { - v1 = PoffinCase_AddPoffin(param0->unk_10->poffinCase, param1); + v1 = PoffinCase_AddPoffin(param0->ctx->poffinCase, param1); if (v1 == POFFIN_NONE) { v3 = 0; diff --git a/src/poffin_berry_selection_context.c b/src/poffin_berry_selection_context.c new file mode 100644 index 0000000000..c285625e93 --- /dev/null +++ b/src/poffin_berry_selection_context.c @@ -0,0 +1,65 @@ +#include "poffin_berry_selection_context.h" + +#include +#include + +#include "applications/poffin_berry_selection.h" +#include "field/field_system.h" + +#include "bag.h" +#include "field_system.h" +#include "heap.h" +#include "journal.h" +#include "poffin.h" +#include "save_player.h" +#include "savedata.h" + +static PoffinBerrySelectionContext *CreateContext(int isInGroup, SaveData *saveData, enum HeapID heapID, JournalEntry *journalEntry) +{ + PoffinBerrySelectionContext *ctx = Heap_Alloc(heapID, sizeof(PoffinBerrySelectionContext)); + MI_CpuClear8(ctx, sizeof(PoffinBerrySelectionContext)); + + ctx->saveData = saveData; + ctx->poffinCase = SaveData_GetPoffinCase(saveData); + ctx->trainerInfo = SaveData_GetTrainerInfo(saveData); + ctx->bag = SaveData_GetBag(saveData); + ctx->options = SaveData_GetOptions(saveData); + ctx->journalEntry = journalEntry; + ctx->unk_20 = FALSE; + ctx->isInGroup = isInGroup; + + return ctx; +} + +static void FieldTask_OpenPoffinBerrySelection(FieldSystem *fieldSystem, PoffinBerrySelectionContext *ctx) +{ + FS_EXTERN_OVERLAY(poffin_berry_selection); + + ApplicationManagerTemplate appTemplate = { + PoffinBerrySelection_Init, + PoffinBerrySelection_Main, + PoffinBerrySelection_Exit, + FS_OVERLAY_ID(poffin_berry_selection) + }; + + FieldSystem_StartChildProcess(fieldSystem, &appTemplate, ctx); +} + +PoffinBerrySelectionContext *PoffinBerrySelectionContext_Create(FieldSystem *fieldSystem, BOOL isInGroup, enum HeapID heapID) +{ + PoffinBerrySelectionContext *ctx = CreateContext(isInGroup, FieldSystem_GetSaveData(fieldSystem), heapID, fieldSystem->journalEntry); + FieldTask_OpenPoffinBerrySelection(fieldSystem, ctx); + + return ctx; +} + +PoffinBerrySelectionContext *PoffinBerrySelectionContext_CreateVoiceChat(FieldSystem *fieldSystem, enum HeapID heapID, BOOL voiceChat) +{ + PoffinBerrySelectionContext *ctx = CreateContext(TRUE, FieldSystem_GetSaveData(fieldSystem), heapID, fieldSystem->journalEntry); + ctx->unk_20 = TRUE; + ctx->voiceChat = voiceChat; + + FieldTask_OpenPoffinBerrySelection(fieldSystem, ctx); + + return ctx; +} diff --git a/src/scrcmd.c b/src/scrcmd.c index 735d56a4bb..faf7808a5d 100644 --- a/src/scrcmd.c +++ b/src/scrcmd.c @@ -138,6 +138,7 @@ #include "platform_lift.h" #include "player_avatar.h" #include "poffin.h" +#include "poffin_berry_selection_context.h" #include "pokedex.h" #include "pokemon.h" #include "pokeradar.h" @@ -214,7 +215,6 @@ #include "unk_02097B18.h" #include "unk_020985E4.h" #include "unk_02099500.h" -#include "unk_02099604.h" #include "unk_0209ACF4.h" #include "unk_0209B344.h" #include "unk_0209C194.h" @@ -380,7 +380,7 @@ static BOOL ScrCmd_ContestPhotoHasData(ScriptContext *ctx); static BOOL ScrCmd_SetDressUpPhotoTitle(ScriptContext *ctx); static BOOL ScrCmd_OpenSealCapsuleEditor(ScriptContext *ctx); static BOOL ScrCmd_OpenRegionMap(ScriptContext *ctx); -static BOOL ScrCmd_1D7(ScriptContext *ctx); +static BOOL ScrCmd_OpenPoffinCooking(ScriptContext *ctx); static BOOL ScrCmd_CheckCanCookPoffin(ScriptContext *ctx); static BOOL ScrCmd_OpenBattleTowerRecordsApp(ScriptContext *ctx); static BOOL ScrCmd_OpenPokemonStorage(ScriptContext *ctx); @@ -3237,12 +3237,12 @@ static BOOL ScrCmd_OpenRegionMap(ScriptContext *ctx) return TRUE; } -static BOOL ScrCmd_1D7(ScriptContext *ctx) +static BOOL ScrCmd_OpenPoffinCooking(ScriptContext *ctx) { - void **v2 = FieldSystem_GetScriptMemberPtr(ctx->fieldSystem, SCRIPT_MANAGER_PARTY_MANAGEMENT_DATA); + void **poffinBerrySelectionCtx = FieldSystem_GetScriptMemberPtr(ctx->fieldSystem, SCRIPT_MANAGER_PARTY_MANAGEMENT_DATA); - u8 v0 = ScriptContext_ReadHalfWord(ctx); - *v2 = sub_02099674(ctx->fieldSystem, v0, HEAP_ID_FIELD2); + u8 isInGroup = ScriptContext_ReadHalfWord(ctx); + *poffinBerrySelectionCtx = PoffinBerrySelectionContext_Create(ctx->fieldSystem, isInGroup, HEAP_ID_FIELD2); ScriptContext_Pause(ctx, sub_02041CC8); return TRUE; diff --git a/src/unk_0203D1B8.c b/src/unk_0203D1B8.c index e99e3fae1b..a4a0c2b925 100644 --- a/src/unk_0203D1B8.c +++ b/src/unk_0203D1B8.c @@ -260,14 +260,14 @@ void sub_0203D1E4(FieldSystem *fieldSystem, BagContext *param1) { FS_EXTERN_OVERLAY(bag); - const ApplicationManagerTemplate Unk_ov84_02241130 = { + const ApplicationManagerTemplate gBagApplicationTemplate = { BagApplication_Init, BagApplication_Main, BagApplication_Exit, FS_OVERLAY_ID(bag) }; - FieldSystem_StartChildProcess(fieldSystem, &Unk_ov84_02241130, param1); + FieldSystem_StartChildProcess(fieldSystem, &gBagApplicationTemplate, param1); } BagContext *FieldSystem_OpenBag(FieldSystem *fieldSystem, ItemUseContext *itemUseCtx) diff --git a/src/unk_0207DA28.c b/src/unk_0207DA28.c index 91deabd13e..0979202651 100644 --- a/src/unk_0207DA28.c +++ b/src/unk_0207DA28.c @@ -28,10 +28,10 @@ #include "game_overlay.h" #include "game_records.h" #include "heap.h" +#include "poffin_berry_selection_context.h" #include "system_flags.h" #include "unk_02038FFC.h" #include "unk_0203D1B8.h" -#include "unk_02099604.h" #include "vars_flags.h" #include "wifi_overlays.h" @@ -209,7 +209,7 @@ static BOOL sub_0207DA28(FieldTask *task) } break; case 14: - v2->unk_10 = (void *)sub_020996A0(fieldSystem, HEAP_ID_FIELD2, v2->unk_14); + v2->unk_10 = PoffinBerrySelectionContext_CreateVoiceChat(fieldSystem, HEAP_ID_FIELD2, v2->unk_14); v2->unk_04++; break; case 15: diff --git a/src/unk_02099604.c b/src/unk_02099604.c deleted file mode 100644 index c51ee2d886..0000000000 --- a/src/unk_02099604.c +++ /dev/null @@ -1,68 +0,0 @@ -#include -#include - -#include "field/field_system.h" -#include "overlay082/ov82_0223B140.h" -#include "overlay082/struct_ov82_0223B164.h" - -#include "bag.h" -#include "field_system.h" -#include "heap.h" -#include "journal.h" -#include "poffin.h" -#include "save_player.h" -#include "savedata.h" - -FS_EXTERN_OVERLAY(overlay82); - -static UnkStruct_ov82_0223B164 *sub_02099604(int param0, SaveData *saveData, enum HeapID heapID, JournalEntry *journalEntry) -{ - UnkStruct_ov82_0223B164 *v0 = Heap_Alloc(heapID, sizeof(UnkStruct_ov82_0223B164)); - MI_CpuClear8(v0, sizeof(UnkStruct_ov82_0223B164)); - - v0->saveData = saveData; - v0->poffinCase = SaveData_GetPoffinCase(saveData); - v0->trainerInfo = SaveData_GetTrainerInfo(saveData); - v0->bag = SaveData_GetBag(saveData); - v0->options = SaveData_GetOptions(saveData); - v0->journalEntry = journalEntry; - v0->unk_20 = 0; - v0->unk_04 = param0; - - return v0; -} - -static void sub_0209964C(FieldSystem *fieldSystem, UnkStruct_ov82_0223B164 *param1) -{ - FS_EXTERN_OVERLAY(overlay82); - - { - ApplicationManagerTemplate v0 = { - ov82_0223B164, - ov82_0223B1D4, - ov82_0223B24C, - FS_OVERLAY_ID(overlay82) - }; - - FieldSystem_StartChildProcess(fieldSystem, &v0, param1); - } -} - -UnkStruct_ov82_0223B164 *sub_02099674(FieldSystem *fieldSystem, int param1, enum HeapID heapID) -{ - UnkStruct_ov82_0223B164 *v0 = sub_02099604(param1, FieldSystem_GetSaveData(fieldSystem), heapID, fieldSystem->journalEntry); - sub_0209964C(fieldSystem, v0); - - return v0; -} - -UnkStruct_ov82_0223B164 *sub_020996A0(FieldSystem *fieldSystem, enum HeapID heapID, BOOL param2) -{ - UnkStruct_ov82_0223B164 *v0 = sub_02099604(1, FieldSystem_GetSaveData(fieldSystem), heapID, fieldSystem->journalEntry); - v0->unk_20 = 1; - v0->unk_24 = param2; - - sub_0209964C(fieldSystem, v0); - - return v0; -}