From c392401fd2ba86a3fca147688d56bcaf428a00bc Mon Sep 17 00:00:00 2001 From: Gudf <28691694+Gudf@users.noreply.github.com> Date: Thu, 10 Jul 2025 14:32:55 +0200 Subject: [PATCH] Document main menu utils --- include/constants/graphics.h | 11 +- include/mystery_gift.h | 2 +- include/overlay097/ov97_02237694.h | 120 ++- include/overlay097/struct_ov97_02237808.h | 32 - include/overlay097/struct_ov97_02237AEC.h | 22 - src/overlay097/gba_migrator.c | 4 +- src/overlay097/main_menu.c | 137 ++-- src/overlay097/mystery_gift_app.c | 116 ++- src/overlay097/ov97_0222C174.c | 141 ++-- src/overlay097/ov97_02237694.c | 919 +++++++++++----------- src/overlay097/wonder_cards_app.c | 38 +- 11 files changed, 757 insertions(+), 785 deletions(-) delete mode 100644 include/overlay097/struct_ov97_02237808.h delete mode 100644 include/overlay097/struct_ov97_02237AEC.h diff --git a/include/constants/graphics.h b/include/constants/graphics.h index 048f34c43c..29d4ea60c2 100644 --- a/include/constants/graphics.h +++ b/include/constants/graphics.h @@ -32,10 +32,12 @@ enum DSScreen { #define HW_BG_B_PLTT_COLOR(palette, colorIdx) ((GXRgb *)(HW_DB_BG_PLTT + PLTT_OFFSET(palette) + colorIdx * sizeof(GXRgb))) #define HW_OBJ_B_PLTT_COLOR(palette, colorIdx) ((GXRgb *)(HW_DB_OBJ_PLTT + PLTT_OFFSET(palette) + colorIdx * sizeof(GXRgb))) -#define MON_SPRITE_FRAME_WIDTH_TILES 10 -#define MON_SPRITE_FRAME_HEIGHT_TILES 10 -#define MON_SPRITE_FRAME_WIDTH (MON_SPRITE_FRAME_WIDTH_TILES * TILE_WIDTH_PIXELS) -#define MON_SPRITE_FRAME_HEIGHT (MON_SPRITE_FRAME_HEIGHT_TILES * TILE_HEIGHT_PIXELS) +#define MON_SPRITE_FRAME_WIDTH_TILES 10 +#define MON_SPRITE_FRAME_HEIGHT_TILES 10 +#define MON_SPRITE_FRAME_WIDTH (MON_SPRITE_FRAME_WIDTH_TILES * TILE_WIDTH_PIXELS) +#define MON_SPRITE_FRAME_HEIGHT (MON_SPRITE_FRAME_HEIGHT_TILES * TILE_HEIGHT_PIXELS) +#define MON_SPRITE_FRAME_MAX_SIZE_TILES (MON_SPRITE_FRAME_WIDTH_TILES * MON_SPRITE_FRAME_HEIGHT_TILES) +#define MON_SPRITE_FRAME_MAX_SIZE_BYTES (TILE_SIZE_4BPP * MON_SPRITE_FRAME_MAX_SIZE_TILES) #define SHADOW_SPRITE_FRAME_WIDTH_TILES 8 #define SHADOW_SPRITE_FRAME_HEIGHT_TILES 2 @@ -49,6 +51,7 @@ enum DSScreen { #define COLOR_BLACK GX_RGB(0, 0, 0) #define COLOR_DARK_GRAY GX_RGB(4, 4, 4) +#define COLOR_WHITE GX_RGB(31, 31, 31) #define COLOR_TRANSPARENT GX_RGB(31, 31, 16) #endif // POKEPLATINUM_CONSTANTS_GRAPHICS_H diff --git a/include/mystery_gift.h b/include/mystery_gift.h index 69bb3e2fb6..0006b2ce84 100644 --- a/include/mystery_gift.h +++ b/include/mystery_gift.h @@ -99,7 +99,7 @@ enum MysteryGiftType { MYST_GIFT_POKETCH_APP, MYST_GIFT_SECRET_KEY, MYST_GIFT_UNKNOWN, - MYST_GIFT_TYPE_MAX = 14, + MYST_GIFT_TYPE_MAX, }; typedef struct MysteryGift { diff --git a/include/overlay097/ov97_02237694.h b/include/overlay097/ov97_02237694.h index 7af96d54af..97c1ef5b47 100644 --- a/include/overlay097/ov97_02237694.h +++ b/include/overlay097/ov97_02237694.h @@ -2,49 +2,97 @@ #define POKEPLATINUM_OV97_02237694_H #include "overlay097/mystery_gift_app.h" -#include "overlay097/struct_ov97_02237808.h" -#include "overlay097/struct_ov97_02237AEC.h" #include "bg_window.h" #include "list_menu.h" #include "mystery_gift.h" #include "overlay_manager.h" +#include "palette.h" #include "savedata.h" +#include "screen_fade.h" #include "sprite.h" +#include "sprite_resource.h" +#include "sprite_util.h" -void ov97_02237694(int heapID); -void *ov97_022376C4(ApplicationManager *appMan, int heapID, int param2, int param3); -void ov97_022376FC(BgConfig *bgConfig, int bgLayer, u8 param2, u32 param3, u32 param4); -void ov97_02237784(int param0); -void ov97_02237790(int param0, int param1, int *param2, int param3); -void ov97_022377F0(int *param0); -void ov97_02237808(UnkStruct_ov97_02237808 *param0, Window *param1, int param2, int param3, int param4, int param5); -void ov97_02237858(UnkStruct_ov97_02237808 *param0, int param1, int param2, int param3); -void ov97_02237860(UnkStruct_ov97_02237808 *param0, int param1, int param2); -void ov97_02237868(UnkStruct_ov97_02237808 *param0, int param1, int param2); -int ov97_0223795C(BgConfig *param0, UnkStruct_ov97_02237808 *param1, int param2, int param3, int param4); -int ov97_02237A18(UnkStruct_ov97_02237808 *param0); -void ov97_02237A20(void); -BOOL ov97_02237A60(void); -void ov97_02237A74(void); -UnkStruct_ov97_02237AEC *ov97_02237AEC(void); -void ov97_02237B0C(int param0, int param1, int param2, int param3, int param4, int param5); -void ov97_02237C80(fx32 param0, fx32 param1); -void ov97_02237CA0(void); -void ov97_02237CAC(int param0); -Sprite *ov97_02237D14(int param0, Sprite *param1, int param2, int param3, int param4); -void ov97_02237DA0(void); -u32 ov97_02237E4C(int param0); -void ov97_02238194(BgConfig *param0, WonderCard *param1); -void ov97_0223829C(MysteryGiftEventData *param0, WonderCard *param1, int heapID); -void ov97_02238324(MysteryGiftEventData *param0, WonderCard *param1, int heapID); -void ov97_022383C4(ListMenu *param0, u32 param1, u8 param2); -void ov97_02238400(BOOL param0); -void ov97_02238440(void); -void ov97_0223846C(SaveData *saveData); -int ov97_0223847C(void); -void ov97_022384F4(void); -void ov97_0223850C(void); -int ov97_02238528(void); +enum MainMenuUtilSavingState { + MAIN_MENU_UTIL_INIT_SAVING, + MAIN_MENU_UTIL_SAVING, + MAIN_MENU_UTIL_SAVE_SUCCESS, + MAIN_MENU_UTIL_SAVE_FAILURE, + MAIN_MENU_UTIL_SAVING_IDLE, +}; + +typedef struct MainMenuSpriteManager { + SpriteList *spriteList; + G2dRenderer renderer; + SpriteResourceCollection *resourceCollections[SPRITE_RESOURCE_MAX]; + SpriteResource *resources[DS_SCREEN_MAX][SPRITE_RESOURCE_MAX]; + SpriteResourcesHeader resourceHeaders[DS_SCREEN_MAX]; + int unused_220; + int unused_224; + int unused_228; + int unused_22C; + int unused_230; + int unused_234; +} MainMenuSpriteManager; + +typedef struct MainMenuWindow { + BOOL scrollable; + BOOL drawFrame; + BOOL clearBeforePrinting; + BOOL textRightAligned; + Window *window; + StringTemplate *strTemplate; + int width; + int height; + int textXOffset; + int textYOffset; + int baseTile; + enum BgLayer bgLayer; + enum Palette textPltt; + int textBank; + int frameBaseTile; + enum Palette framePltt; + enum Font font; + TextColor textColor; + u8 backgroundColorIdx; + int textEntryID; + int renderDelay; +} MainMenuWindow; + +void MainMenuUtil_Init(enum HeapId heapID); +void *MainMenuUtil_InitAppAndFadeToBlack(ApplicationManager *appMan, enum HeapId heapID, int appDataSize, enum HeapSize heapSize); +void MainMenuUtil_InitBG(BgConfig *bgConfig, enum BgLayer bgLayer, u8 screenSize, u32 screenBase, u32 charBase); +void MainMenuUtil_SetFadeToWhite(BOOL enable); +void MainMenuUtil_StartScreenFadeToState(enum FadeType fadeType, int destState, int *state, int waitState); +void MainMenuUtil_CheckScreenFadeDone(int *state); +void MainMenuUtil_InitWindow(MainMenuWindow *mainMenuWindow, Window *window, enum Palette textPalette, enum TextBank textBank, int baseTile, enum Palette framePalette); +void MainMenuWindow_SetDimensionsAndBasetile(MainMenuWindow *window, int width, int height, int baseTile); +void MainMenuWindow_SetScrollableAndFont(MainMenuWindow *window, BOOL scrollable, enum Font font); +void MainMenuWindow_SetTextOffsets(MainMenuWindow *window, int xOffset, int yOffset); +int MainMenuUtil_ShowWindowAtPos(BgConfig *param0, MainMenuWindow *window, int xPos, int yPos, int textEntryID); +int MainMenuWindow_GetSize(MainMenuWindow *window); +void MainMenuUtil_InitCharPlttTransferBuffers(void); +BOOL MainMenuUtil_CheckSpriteLoaderInit(void); +void MainMenuUtil_InitSpriteLoader(void); +MainMenuSpriteManager *MainMenuUtil_GetSpriteManager(void); +void MainMenuUtil_LoadSprite(enum NarcID narcID, int tilesID, int plttID, int cellID, int animID, enum DSScreen screen); +void MainMenuUtil_SetSubScreenViewRect(fx32 x, fx32 y); +void MainMenuUtil_UpdateSpritesSkipGift(void); +void MainMenuUtil_UpdateSprites(int skipDrawGift); +Sprite *MainMenuUtil_InitSprite(enum DSScreen screen, Sprite *sprite, int x, int y, int animationIdx); +void MainMenuUtil_FreeSprites(void); +u32 MainMenuUtil_CalcMysteryGiftVersionBit(enum Version version); +void MainMenuUtil_LoadGiftSprite(BgConfig *bgConfig, WonderCard *wonderCard); +void MainMenuUtil_EncryptWonderCard(MysteryGiftEventData *eventData, WonderCard *wonderCard, enum HeapId heapID); +void MainMenuUtil_DecryptReceivedWonderCard(MysteryGiftEventData *param0, WonderCard *param1, enum HeapId heapID); +void MainMenuUtil_ListMenuCursorCB(ListMenu *param0, u32 param1, u8 param2); +void MainMenuUtil_ToggleTerminateOnGBACartRemoved(BOOL enable); +void MainMenuUtil_UnsetGBACartIRQFunc(void); +void MainMenuUtil_InitSaving(SaveData *saveData); +enum SaveResult MainMenuUtil_SaveState(void); +void MainMenuUtil_ContinueSaving(void); +void MainMenuUtil_CancelSave(void); +int MainMenuUtil_GetSavingStatus(void); #endif // POKEPLATINUM_OV97_02237694_H diff --git a/include/overlay097/struct_ov97_02237808.h b/include/overlay097/struct_ov97_02237808.h deleted file mode 100644 index 427fad3efc..0000000000 --- a/include/overlay097/struct_ov97_02237808.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef POKEPLATINUM_STRUCT_OV97_02237808_H -#define POKEPLATINUM_STRUCT_OV97_02237808_H - -#include "bg_window.h" -#include "string_template.h" -#include "text.h" - -typedef struct { - int unk_00; - int unk_04; - int unk_08; - int unk_0C; - Window *unk_10; - StringTemplate *unk_14; - int unk_18; - int unk_1C; - int unk_20; - int unk_24; - int unk_28; - int unk_2C; - int unk_30; - int unk_34; - int unk_38; - int unk_3C; - int unk_40; - TextColor unk_44; - u8 unk_48; - int unk_4C; - int unk_50; -} UnkStruct_ov97_02237808; - -#endif // POKEPLATINUM_STRUCT_OV97_02237808_H diff --git a/include/overlay097/struct_ov97_02237AEC.h b/include/overlay097/struct_ov97_02237AEC.h deleted file mode 100644 index 7e23fe155e..0000000000 --- a/include/overlay097/struct_ov97_02237AEC.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef POKEPLATINUM_STRUCT_OV97_02237AEC_H -#define POKEPLATINUM_STRUCT_OV97_02237AEC_H - -#include "sprite.h" -#include "sprite_resource.h" -#include "sprite_util.h" - -typedef struct { - SpriteList *unk_00; - G2dRenderer unk_04; - SpriteResourceCollection *unk_190[6]; - SpriteResource *unk_1A8[2][6]; - SpriteResourcesHeader unk_1D8[2]; - int unk_220; - int unk_224; - int unk_228; - int unk_22C; - int unk_230; - int unk_234; -} UnkStruct_ov97_02237AEC; - -#endif // POKEPLATINUM_STRUCT_OV97_02237AEC_H diff --git a/src/overlay097/gba_migrator.c b/src/overlay097/gba_migrator.c index b913400fe3..e09020b22c 100644 --- a/src/overlay097/gba_migrator.c +++ b/src/overlay097/gba_migrator.c @@ -1845,7 +1845,7 @@ static int GBAMigrator_Init(ApplicationManager *appMan, int *state) OS_InitTick(); } - ov97_02238440(); + MainMenuUtil_UnsetGBACartIRQFunc(); Unk_ov97_0223F434 = migrator->unk_E8FC; return 1; @@ -2196,7 +2196,7 @@ static int GBAMigrator_Exit(ApplicationManager *appMan, int *state) ApplicationManager_FreeData(appMan); Heap_Destroy(HEAP_ID_MIGRATE_FROM_GBA); - ov97_02238400(FALSE); + MainMenuUtil_ToggleTerminateOnGBACartRemoved(FALSE); return 1; } diff --git a/src/overlay097/main_menu.c b/src/overlay097/main_menu.c index 0a425a34fc..a2978b17be 100644 --- a/src/overlay097/main_menu.c +++ b/src/overlay097/main_menu.c @@ -15,7 +15,6 @@ #include "overlay097/distribution_cartridge.h" #include "overlay097/ov97_02235D18.h" #include "overlay097/ov97_02237694.h" -#include "overlay097/struct_ov97_02237808.h" #include "savedata/save_table.h" #include "bg_window.h" @@ -234,7 +233,7 @@ typedef struct MainMenuAppData { * Must not set appData->optionApps[option] nor render the option and return * FALSE if it's not available. */ -typedef BOOL (*MainMenuOptionRenderFuncPtr)(MainMenuAppData *appData, enum MainMenuOption optionIdx, UnkStruct_ov97_02237808 *, int yPos); +typedef BOOL (*MainMenuOptionRenderFuncPtr)(MainMenuAppData *appData, enum MainMenuOption optionIdx, MainMenuWindow *, int yPos); typedef struct { enum MainMenuNextApp appToLoad; @@ -243,13 +242,13 @@ typedef struct { MainMenuOptionRenderFuncPtr renderFunc; // If NULL, the option is always always available and simply shows the string indicated by textEntryID in the main menu text bank. } MainMenuOptionTemplate; -static BOOL RenderContinueOption(MainMenuAppData *appData, enum MainMenuOption option, UnkStruct_ov97_02237808 *param2, int yPos); -static BOOL RenderMysteryGiftOption(MainMenuAppData *appData, enum MainMenuOption option, UnkStruct_ov97_02237808 *param2, int yPos); -static BOOL RenderRangerLinkOption(MainMenuAppData *appData, enum MainMenuOption option, UnkStruct_ov97_02237808 *param2, int yPos); -static BOOL RenderGBAMigrationOption(MainMenuAppData *appData, enum MainMenuOption option, UnkStruct_ov97_02237808 *param2, int yPos); -static BOOL RenderWiiConnectionOption(MainMenuAppData *appData, enum MainMenuOption option, UnkStruct_ov97_02237808 *param2, int yPos); -static BOOL RenderWFCSettingsOption(MainMenuAppData *appData, enum MainMenuOption option, UnkStruct_ov97_02237808 *param2, int yPos); -static BOOL RenderWiiMsgSettingsOption(MainMenuAppData *appData, enum MainMenuOption option, UnkStruct_ov97_02237808 *param2, int yPos); +static BOOL RenderContinueOption(MainMenuAppData *appData, enum MainMenuOption option, MainMenuWindow *param2, int yPos); +static BOOL RenderMysteryGiftOption(MainMenuAppData *appData, enum MainMenuOption option, MainMenuWindow *param2, int yPos); +static BOOL RenderRangerLinkOption(MainMenuAppData *appData, enum MainMenuOption option, MainMenuWindow *param2, int yPos); +static BOOL RenderGBAMigrationOption(MainMenuAppData *appData, enum MainMenuOption option, MainMenuWindow *param2, int yPos); +static BOOL RenderWiiConnectionOption(MainMenuAppData *appData, enum MainMenuOption option, MainMenuWindow *param2, int yPos); +static BOOL RenderWFCSettingsOption(MainMenuAppData *appData, enum MainMenuOption option, MainMenuWindow *param2, int yPos); +static BOOL RenderWiiMsgSettingsOption(MainMenuAppData *appData, enum MainMenuOption option, MainMenuWindow *param2, int yPos); MysteryGift *SaveData_GetMysteryGift(SaveData *saveData); int TrainerInfo_Size(void); @@ -341,10 +340,10 @@ static BOOL ShowWFCUserInfoErasedMsg(MainMenuAppData *appData) appData->wfcUserInfoErasedMsgPending[i] = FALSE; WFCUserInfoErasedAlertTemplate *alertTemplate = &sWFCUserInfoErasedMsgWindowTemplate[i]; - UnkStruct_ov97_02237808 v2; - ov97_02237808(&v2, &appData->wfcUserInfoErasedWindow, PLTT_0, alertTemplate->bankID, 1, PLTT_2); - ov97_02237858(&v2, alertTemplate->width, alertTemplate->height, ALERT_WINDOW_CONTENT_BASE_TILE); - ov97_0223795C(appData->bgConfig, &v2, alertTemplate->x, alertTemplate->y, alertTemplate->entryID); + MainMenuWindow v2; + MainMenuUtil_InitWindow(&v2, &appData->wfcUserInfoErasedWindow, PLTT_0, alertTemplate->bankID, 1, PLTT_2); + MainMenuWindow_SetDimensionsAndBasetile(&v2, alertTemplate->width, alertTemplate->height, ALERT_WINDOW_CONTENT_BASE_TILE); + MainMenuUtil_ShowWindowAtPos(appData->bgConfig, &v2, alertTemplate->x, alertTemplate->y, alertTemplate->entryID); return TRUE; } } @@ -403,7 +402,7 @@ static void DetectGBAGame(MainMenuAppData *appData) appData->agbGameType = GBACart_GetAGBGameType() + 1; - ov97_02238440(); + MainMenuUtil_UnsetGBACartIRQFunc(); } /* @@ -492,8 +491,8 @@ static BOOL ShowAlerts(MainMenuAppData *appData) appData->alertsState = MAIN_MANU_ALERTS_STATE_SHOW_NEXT_ALERT; break; case MAIN_MANU_ALERTS_STATE_SHOW_NEXT_ALERT: { - UnkStruct_ov97_02237808 v0; - ov97_02237808(&v0, &appData->alertWindow, PLTT_0, TEXT_BANK_MAIN_MENU_ALERTS, 1, PLTT_2); + MainMenuWindow v0; + MainMenuUtil_InitWindow(&v0, &appData->alertWindow, PLTT_0, TEXT_BANK_MAIN_MENU_ALERTS, 1, PLTT_2); int pendingAlerts = appData->pendingAlerts & ~appData->shownAlerts; @@ -517,12 +516,12 @@ static BOOL ShowAlerts(MainMenuAppData *appData) } appData->shownAlerts |= pendingAlerts; - ov97_02237858(&v0, alertTemplate->width, alertTemplate->height, ALERT_WINDOW_CONTENT_BASE_TILE); + MainMenuWindow_SetDimensionsAndBasetile(&v0, alertTemplate->width, alertTemplate->height, ALERT_WINDOW_CONTENT_BASE_TILE); - v0.unk_2C = 1; - ov97_0223795C(appData->bgConfig, &v0, alertTemplate->x, alertTemplate->y, alertTemplate->textEntryID); + v0.bgLayer = 1; + MainMenuUtil_ShowWindowAtPos(appData->bgConfig, &v0, alertTemplate->x, alertTemplate->y, alertTemplate->textEntryID); - Bg_ChangeTilemapRectPalette(appData->bgConfig, BG_LAYER_MAIN_1, Window_GetXPos(v0.unk_10), Window_GetYPos(v0.unk_10), Window_GetWidth(v0.unk_10), Window_GetHeight(v0.unk_10), PLTT_0); + Bg_ChangeTilemapRectPalette(appData->bgConfig, BG_LAYER_MAIN_1, Window_GetXPos(v0.window), Window_GetYPos(v0.window), Window_GetWidth(v0.window), Window_GetHeight(v0.window), PLTT_0); GXLayers_EngineAToggleLayers(GX_PLANEMASK_BG0, FALSE); GXLayers_EngineAToggleLayers(GX_PLANEMASK_BG2, FALSE); GXLayers_EngineAToggleLayers(GX_PLANEMASK_BG1, TRUE); @@ -604,15 +603,15 @@ static void InitMainMenuGraphics(MainMenuAppData *appData) GXLayers_SetBanks(&vramBanks); SetAllGraphicsModes(&graphicsModes); - ov97_022376FC(appData->bgConfig, 0, 2, 0xF000, 0x0); + MainMenuUtil_InitBG(appData->bgConfig, 0, 2, 0xF000, 0x0); G2_SetBG0Priority(2); Bg_ClearTilesRange(BG_LAYER_MAIN_0, 32, 0, HEAP_ID_MAIN_MENU); - ov97_022376FC(appData->bgConfig, 1, 1, 0xD800, 0x8000); + MainMenuUtil_InitBG(appData->bgConfig, 1, 1, 0xD800, 0x8000); G2_SetBG1Priority(1); Bg_ClearTilesRange(BG_LAYER_MAIN_1, 32, 0, HEAP_ID_MAIN_MENU); - ov97_022376FC(appData->bgConfig, 2, 2, 0xE000, 0x0); + MainMenuUtil_InitBG(appData->bgConfig, 2, 2, 0xE000, 0x0); G2_SetBG2Priority(0); Bg_ClearTilesRange(BG_LAYER_MAIN_2, 32, 0, HEAP_ID_MAIN_MENU); @@ -631,14 +630,14 @@ static void InitMainMenuGraphics(MainMenuAppData *appData) static void LoadScrollArrowsSprites(MainMenuAppData *appData) { - ov97_02237A20(); - ov97_02237A74(); - ov97_02237B0C(NARC_INDEX_GRAPHIC__MYSTERY, 43, 40, 42, 41, 0); + MainMenuUtil_InitCharPlttTransferBuffers(); + MainMenuUtil_InitSpriteLoader(); + MainMenuUtil_LoadSprite(NARC_INDEX_GRAPHIC__MYSTERY, 43, 40, 42, 41, 0); - appData->scrollUpArrowSprite = ov97_02237D14(0, appData->scrollUpArrowSprite, HW_LCD_WIDTH / 2, SCROLL_ARROWS_OFFSET, 0); + appData->scrollUpArrowSprite = MainMenuUtil_InitSprite(0, appData->scrollUpArrowSprite, HW_LCD_WIDTH / 2, SCROLL_ARROWS_OFFSET, 0); Sprite_SetDrawFlag(appData->scrollUpArrowSprite, FALSE); - appData->scrollDownArrowSprite = ov97_02237D14(0, appData->scrollDownArrowSprite, HW_LCD_WIDTH / 2, HW_LCD_HEIGHT - SCROLL_ARROWS_OFFSET, 1); + appData->scrollDownArrowSprite = MainMenuUtil_InitSprite(0, appData->scrollDownArrowSprite, HW_LCD_WIDTH / 2, HW_LCD_HEIGHT - SCROLL_ARROWS_OFFSET, 1); Sprite_SetDrawFlag(appData->scrollDownArrowSprite, FALSE); } @@ -719,7 +718,7 @@ static void SetTemplateNumberCustomFormatting(StringTemplate *strTemplate, int n StringTemplate_SetNumber(strTemplate, 0, number, maxDigits, paddingMode, CHARSET_MODE_EN); } -static BOOL RenderContinueOption(MainMenuAppData *appData, enum MainMenuOption option, UnkStruct_ov97_02237808 *param2, int yPos) +static BOOL RenderContinueOption(MainMenuAppData *appData, enum MainMenuOption option, MainMenuWindow *param2, int yPos) { StringTemplate *strTemplate; // Forward-declaration required to match. @@ -733,7 +732,7 @@ static BOOL RenderContinueOption(MainMenuAppData *appData, enum MainMenuOption o textColor = TEXT_COLOR(7, 8, 15); } - ov97_0223795C(appData->bgConfig, param2, 3, yPos, sOptions[option].textEntryID); + MainMenuUtil_ShowWindowAtPos(appData->bgConfig, param2, 3, yPos, sOptions[option].textEntryID); // Index 0 has the "Continue" string, which is printed separately for (int i = 1; i < NELEMS(sContinueOptionStringsIDs); i++) { @@ -742,26 +741,26 @@ static BOOL RenderContinueOption(MainMenuAppData *appData, enum MainMenuOption o } Strbuf *strBuf = MessageUtil_ExpandedStrbuf(strTemplate, msgLoader, sContinueOptionStringsIDs[i], HEAP_ID_MAIN_MENU); - Text_AddPrinterWithParamsAndColor(param2->unk_10, FONT_SYSTEM, strBuf, CONTINUE_WINDOW_MARGIN, TEXT_LINES(i), TEXT_SPEED_NO_TRANSFER, textColor, NULL); + Text_AddPrinterWithParamsAndColor(param2->window, FONT_SYSTEM, strBuf, CONTINUE_WINDOW_MARGIN, TEXT_LINES(i), TEXT_SPEED_NO_TRANSFER, textColor, NULL); Strbuf_Free(strBuf); } StringTemplate_SetPlayerName(strTemplate, 0, appData->trainerInfo); - PrintRightAlignedWithMargin(param2->unk_10, msgLoader, strTemplate, textColor, MainMenuOptions_Text_PlayerName, TEXT_LINES(1)); + PrintRightAlignedWithMargin(param2->window, msgLoader, strTemplate, textColor, MainMenuOptions_Text_PlayerName, TEXT_LINES(1)); SetTemplateNumberCustomFormatting(strTemplate, PlayTime_GetHours(appData->playTime)); StringTemplate_SetNumber(strTemplate, 1, PlayTime_GetMinutes(appData->playTime), 2, PADDING_MODE_ZEROES, CHARSET_MODE_EN); - PrintRightAlignedWithMargin(param2->unk_10, msgLoader, strTemplate, textColor, MainMenuOptions_Text_PlayTime, TEXT_LINES(2)); + PrintRightAlignedWithMargin(param2->window, msgLoader, strTemplate, textColor, MainMenuOptions_Text_PlayTime, TEXT_LINES(2)); StringTemplate_SetNumber(strTemplate, 0, appData->badgeCount, 1, PADDING_MODE_NONE, CHARSET_MODE_EN); - PrintRightAlignedWithMargin(param2->unk_10, msgLoader, strTemplate, textColor, MainMenuOptions_Text_BadgeCount, TEXT_LINES(3)); + PrintRightAlignedWithMargin(param2->window, msgLoader, strTemplate, textColor, MainMenuOptions_Text_BadgeCount, TEXT_LINES(3)); if (appData->pokedexObtained) { SetTemplateNumberCustomFormatting(strTemplate, Pokedex_CountSeen(appData->pokedex)); - PrintRightAlignedWithMargin(param2->unk_10, msgLoader, strTemplate, textColor, MainMenuOptions_Text_SeenSpeciesCount, TEXT_LINES(4)); + PrintRightAlignedWithMargin(param2->window, msgLoader, strTemplate, textColor, MainMenuOptions_Text_SeenSpeciesCount, TEXT_LINES(4)); } - Window_DrawStandardFrame(param2->unk_10, FALSE, param2->unk_38, param2->unk_3C); + Window_DrawStandardFrame(param2->window, FALSE, param2->frameBaseTile, param2->framePltt); appData->optionApps[option] = sOptions[option].appToLoad; @@ -771,7 +770,7 @@ static BOOL RenderContinueOption(MainMenuAppData *appData, enum MainMenuOption o return TRUE; } -static BOOL RenderGBAMigrationOption(MainMenuAppData *appData, enum MainMenuOption option, UnkStruct_ov97_02237808 *param2, int yPos) +static BOOL RenderGBAMigrationOption(MainMenuAppData *appData, enum MainMenuOption option, MainMenuWindow *param2, int yPos) { if (appData->agbGameType == 0) { return FALSE; @@ -796,7 +795,7 @@ static BOOL RenderGBAMigrationOption(MainMenuAppData *appData, enum MainMenuOpti break; } - ov97_0223795C(appData->bgConfig, param2, 3, yPos, optionTextID); + MainMenuUtil_ShowWindowAtPos(appData->bgConfig, param2, 3, yPos, optionTextID); ClearWirelessIcon(appData, OPTION_WINDOW_WIDTH, yPos); appData->optionApps[option] = sOptions[option].appToLoad; @@ -804,7 +803,7 @@ static BOOL RenderGBAMigrationOption(MainMenuAppData *appData, enum MainMenuOpti return TRUE; } -static BOOL RenderMysteryGiftOption(MainMenuAppData *appData, enum MainMenuOption option, UnkStruct_ov97_02237808 *param2, int yPos) +static BOOL RenderMysteryGiftOption(MainMenuAppData *appData, enum MainMenuOption option, MainMenuWindow *param2, int yPos) { if (appData->mysteryGiftUnlocked == FALSE) { if (MysteryGift_GetMysteryGiftUnlockedFlag(appData->mysteryGift) == TRUE) { @@ -819,7 +818,7 @@ static BOOL RenderMysteryGiftOption(MainMenuAppData *appData, enum MainMenuOptio if (DistributionCartridge_ReadLength()) { appData->mysteryGiftUnlocked = TRUE; - ov97_02238400(TRUE); + MainMenuUtil_ToggleTerminateOnGBACartRemoved(TRUE); } } @@ -830,7 +829,7 @@ static BOOL RenderMysteryGiftOption(MainMenuAppData *appData, enum MainMenuOptio } if (appData->mysteryGiftUnlocked == TRUE) { - ov97_0223795C(appData->bgConfig, param2, 3, yPos, sOptions[option].textEntryID); + MainMenuUtil_ShowWindowAtPos(appData->bgConfig, param2, 3, yPos, sOptions[option].textEntryID); ClearWirelessIcon(appData, OPTION_WINDOW_WIDTH, yPos); appData->optionApps[option] = sOptions[option].appToLoad; @@ -843,10 +842,10 @@ static BOOL RenderMysteryGiftOption(MainMenuAppData *appData, enum MainMenuOptio return FALSE; } -static BOOL RenderRangerLinkOption(MainMenuAppData *appData, enum MainMenuOption option, UnkStruct_ov97_02237808 *param2, int yPos) +static BOOL RenderRangerLinkOption(MainMenuAppData *appData, enum MainMenuOption option, MainMenuWindow *param2, int yPos) { if ((appData->rangerLinkAvailable == TRUE) && (appData->pokedexObtained == TRUE)) { - ov97_0223795C(appData->bgConfig, param2, 3, yPos, sOptions[option].textEntryID); + MainMenuUtil_ShowWindowAtPos(appData->bgConfig, param2, 3, yPos, sOptions[option].textEntryID); DrawWirelessIcon(appData, OPTION_WINDOW_WIDTH, yPos, WIRELESS_ICON_LOCAL); appData->optionWirelessIconTypes[option] = WIRELESS_ICON_LOCAL; @@ -859,10 +858,10 @@ static BOOL RenderRangerLinkOption(MainMenuAppData *appData, enum MainMenuOption return FALSE; } -static BOOL RenderWiiConnectionOption(MainMenuAppData *appData, enum MainMenuOption option, UnkStruct_ov97_02237808 *param2, int yPos) +static BOOL RenderWiiConnectionOption(MainMenuAppData *appData, enum MainMenuOption option, MainMenuWindow *param2, int yPos) { if (appData->wiiConnectionAvailable == TRUE) { - ov97_0223795C(appData->bgConfig, param2, 3, yPos, sOptions[option].textEntryID); + MainMenuUtil_ShowWindowAtPos(appData->bgConfig, param2, 3, yPos, sOptions[option].textEntryID); appData->optionWirelessIconTypes[option] = WIRELESS_ICON_LOCAL; DrawWirelessIcon(appData, OPTION_WINDOW_WIDTH, yPos, WIRELESS_ICON_LOCAL); @@ -873,9 +872,9 @@ static BOOL RenderWiiConnectionOption(MainMenuAppData *appData, enum MainMenuOpt return FALSE; } -static BOOL RenderWFCSettingsOption(MainMenuAppData *appData, enum MainMenuOption option, UnkStruct_ov97_02237808 *param2, int yPos) +static BOOL RenderWFCSettingsOption(MainMenuAppData *appData, enum MainMenuOption option, MainMenuWindow *param2, int yPos) { - ov97_0223795C(appData->bgConfig, param2, 3, yPos, sOptions[option].textEntryID); + MainMenuUtil_ShowWindowAtPos(appData->bgConfig, param2, 3, yPos, sOptions[option].textEntryID); appData->optionWirelessIconTypes[option] = WIRELESS_ICON_WIFI; DrawWirelessIcon(appData, OPTION_WINDOW_WIDTH, yPos, WIRELESS_ICON_WIFI); @@ -884,9 +883,9 @@ static BOOL RenderWFCSettingsOption(MainMenuAppData *appData, enum MainMenuOptio return TRUE; } -static BOOL RenderWiiMsgSettingsOption(MainMenuAppData *appData, enum MainMenuOption option, UnkStruct_ov97_02237808 *param2, int yPos) +static BOOL RenderWiiMsgSettingsOption(MainMenuAppData *appData, enum MainMenuOption option, MainMenuWindow *param2, int yPos) { - ov97_0223795C(appData->bgConfig, param2, 3, yPos, sOptions[option].textEntryID); + MainMenuUtil_ShowWindowAtPos(appData->bgConfig, param2, 3, yPos, sOptions[option].textEntryID); appData->optionWirelessIconTypes[option] = WIRELESS_ICON_NONE; ClearWirelessIcon(appData, OPTION_WINDOW_WIDTH, yPos); @@ -907,15 +906,15 @@ static BOOL RenderOptions(MainMenuAppData *appData) for (i = 0; i < (sizeof(sOptions) / sizeof(MainMenuOptionTemplate)); i++) { MainMenuOptionTemplate *option = &sOptions[i]; - UnkStruct_ov97_02237808 v1; - ov97_02237808(&v1, &appData->optionWindows[i], PLTT_1, TEXT_BANK_MAIN_MENU_OPTIONS, 1, PLTT_2); - ov97_02237858(&v1, OPTION_WINDOW_WIDTH, option->height, appData->nextOptionBasetile); + MainMenuWindow v1; + MainMenuUtil_InitWindow(&v1, &appData->optionWindows[i], PLTT_1, TEXT_BANK_MAIN_MENU_OPTIONS, 1, PLTT_2); + MainMenuWindow_SetDimensionsAndBasetile(&v1, OPTION_WINDOW_WIDTH, option->height, appData->nextOptionBasetile); if (option->renderFunc) { if (appData->optionApps[i]) { - Window_SetXPos(v1.unk_10, 3); - Window_SetYPos(v1.unk_10, nextOptionY); - Window_DrawStandardFrame(v1.unk_10, FALSE, v1.unk_38, v1.unk_3C); + Window_SetXPos(v1.window, 3); + Window_SetYPos(v1.window, nextOptionY); + Window_DrawStandardFrame(v1.window, FALSE, v1.frameBaseTile, v1.framePltt); if (appData->optionWirelessIconTypes[i]) { DrawWirelessIcon(appData, OPTION_WINDOW_WIDTH, nextOptionY, appData->optionWirelessIconTypes[i]); @@ -930,7 +929,7 @@ static BOOL RenderOptions(MainMenuAppData *appData) renderedCustomRenderedOption = TRUE; } } else { - ov97_0223795C(appData->bgConfig, &v1, 3, nextOptionY, option->textEntryID); + MainMenuUtil_ShowWindowAtPos(appData->bgConfig, &v1, 3, nextOptionY, option->textEntryID); appData->optionApps[i] = option->appToLoad; nextOptionY += option->height + 2; // Add 2 to account for the window border } @@ -1043,7 +1042,7 @@ static void FreeApplicationResources(ApplicationManager *appMan) if (appData->scrollUpArrowSprite || appData->scrollDownArrowSprite) { Sprite_Delete(appData->scrollUpArrowSprite); Sprite_Delete(appData->scrollDownArrowSprite); - ov97_02237DA0(); + MainMenuUtil_FreeSprites(); } for (int i = 0; i < NELEMS(sOptions); i++) { @@ -1138,7 +1137,7 @@ static int MainMenu_Init(ApplicationManager *appMan, int *unused) appData->badgeCount = TrainerInfo_BadgeCount(appData->trainerInfo); appData->alertsState = MAIN_MANU_ALERTS_STATE_WAIT; - ov97_02237694(HEAP_ID_MAIN_MENU); + MainMenuUtil_Init(HEAP_ID_MAIN_MENU); if (!SaveData_DataExists(appData->saveData)) { appData->isNewGame = TRUE; @@ -1174,13 +1173,13 @@ static int MainMenu_Main(ApplicationManager *appMan, int *state) if (CheckWFCUserInfoErased(appData) == FALSE) { *state = MAIN_MENU_STATE_CHECK_NEW_GAME_AND_GBA; } else { - ov97_02237790(FADE_TYPE_UNK_1, MAIN_MENU_STATE_WARM_WFC_USER_INFO_ERASED, state, MAIN_MENU_STATE_WAIT_SCREEN_TRANSITION); + MainMenuUtil_StartScreenFadeToState(FADE_TYPE_UNK_1, MAIN_MENU_STATE_WARM_WFC_USER_INFO_ERASED, state, MAIN_MENU_STATE_WAIT_SCREEN_TRANSITION); *HW_BG_A_PLTT_COLOR(PLTT_0, 0) = BACKGROUND_COLOR; } break; case MAIN_MENU_STATE_WARM_WFC_USER_INFO_ERASED: if (ShowWFCUserInfoErasedMsg(appData) == FALSE) { - ov97_02237790(FADE_TYPE_UNK_0, MAIN_MENU_STATE_CHECK_NEW_GAME_AND_GBA, state, MAIN_MENU_STATE_WAIT_SCREEN_TRANSITION); + MainMenuUtil_StartScreenFadeToState(FADE_TYPE_UNK_0, MAIN_MENU_STATE_CHECK_NEW_GAME_AND_GBA, state, MAIN_MENU_STATE_WAIT_SCREEN_TRANSITION); } break; case MAIN_MENU_STATE_CHECK_NEW_GAME_AND_GBA: @@ -1188,7 +1187,7 @@ static int MainMenu_Main(ApplicationManager *appMan, int *state) if (appData->isNewGame == TRUE) { appData->nextApplication = NEXT_APP_GAME_INTRO; - ov97_02237790(FADE_TYPE_UNK_0, MAIN_MENU_STATE_EXIT, state, MAIN_MENU_STATE_WAIT_SCREEN_TRANSITION); + MainMenuUtil_StartScreenFadeToState(FADE_TYPE_UNK_0, MAIN_MENU_STATE_EXIT, state, MAIN_MENU_STATE_WAIT_SCREEN_TRANSITION); } else { DetectGBAGame(appData); *state = MAIN_MENU_STATE_LOAD_GRAPHICS; @@ -1202,7 +1201,7 @@ static int MainMenu_Main(ApplicationManager *appMan, int *state) RenderOptions(appData); RenderOptionsFrames(appData, appData->focusedOption); - ov97_02237790(FADE_TYPE_UNK_1, MAIN_MENU_STATE_SELECT_OPTION, state, MAIN_MENU_STATE_WAIT_SCREEN_TRANSITION); + MainMenuUtil_StartScreenFadeToState(FADE_TYPE_UNK_1, MAIN_MENU_STATE_SELECT_OPTION, state, MAIN_MENU_STATE_WAIT_SCREEN_TRANSITION); *HW_BG_A_PLTT_COLOR(PLTT_0, 0) = BACKGROUND_COLOR; appData->wirelessCheckState = MAIN_MENU_WIRELESS_CHECK_START; @@ -1225,7 +1224,7 @@ static int MainMenu_Main(ApplicationManager *appMan, int *state) } else { Sound_PlayEffect(SEQ_SE_CONFIRM); appData->nextApplication = NEXT_APP_TITLE_SCREEN; - ov97_02237784(TRUE); + MainMenuUtil_SetFadeToWhite(TRUE); } if (appData->nextApplication == NEXT_APP_GAME_INTRO) { @@ -1234,10 +1233,10 @@ static int MainMenu_Main(ApplicationManager *appMan, int *state) *state = MAIN_MENU_STATE_CONFIRM_NEW_GAME; } else { if ((appData->nextApplication == NEXT_APP_WII_CONNECTION) || (appData->nextApplication == NEXT_APP_WFC_SETTINGS)) { - ov97_02237784(TRUE); + MainMenuUtil_SetFadeToWhite(TRUE); } - ov97_02237790(FADE_TYPE_UNK_0, MAIN_MENU_STATE_EXIT, state, MAIN_MENU_STATE_WAIT_SCREEN_TRANSITION); + MainMenuUtil_StartScreenFadeToState(FADE_TYPE_UNK_0, MAIN_MENU_STATE_EXIT, state, MAIN_MENU_STATE_WAIT_SCREEN_TRANSITION); } if (appData->wirelessCheckState == MAIN_MENU_WIRELESS_CHECK_CHECK_RESULT) { @@ -1274,7 +1273,7 @@ static int MainMenu_Main(ApplicationManager *appMan, int *state) if (appData->alertDismissKeys & PAD_BUTTON_B) { *state = MAIN_MENU_STATE_SELECT_OPTION; } else { - ov97_02237790(FADE_TYPE_UNK_0, MAIN_MENU_STATE_EXIT, state, MAIN_MENU_STATE_WAIT_SCREEN_TRANSITION); + MainMenuUtil_StartScreenFadeToState(FADE_TYPE_UNK_0, MAIN_MENU_STATE_EXIT, state, MAIN_MENU_STATE_WAIT_SCREEN_TRANSITION); } } break; @@ -1283,7 +1282,7 @@ static int MainMenu_Main(ApplicationManager *appMan, int *state) return TRUE; break; case MAIN_MENU_STATE_WAIT_SCREEN_TRANSITION: - ov97_022377F0(state); + MainMenuUtil_CheckScreenFadeDone(state); break; case MAIN_MENU_STATE_UNUSED_9: return TRUE; @@ -1292,7 +1291,7 @@ static int MainMenu_Main(ApplicationManager *appMan, int *state) DetectWirelessConnections(appData); DoScrollStep(appData); - ov97_02237CA0(); + MainMenuUtil_UpdateSpritesSkipGift(); return FALSE; } @@ -1347,7 +1346,7 @@ static BOOL MainMenu_Exit(ApplicationManager *appMan, int *unused) ApplicationManager_FreeData(appMan); Heap_Destroy(HEAP_ID_MAIN_MENU); - ov97_02238400(FALSE); + MainMenuUtil_ToggleTerminateOnGBACartRemoved(FALSE); return TRUE; } diff --git a/src/overlay097/mystery_gift_app.c b/src/overlay097/mystery_gift_app.c index 2f75dd1d2e..16c3934b4c 100644 --- a/src/overlay097/mystery_gift_app.c +++ b/src/overlay097/mystery_gift_app.c @@ -16,8 +16,6 @@ #include "overlay097/ov97_02237694.h" #include "overlay097/ov97_02238534.h" #include "overlay097/ov97_02238D74.h" -#include "overlay097/struct_ov97_02237808.h" -#include "overlay097/struct_ov97_02237AEC.h" #include "overlay097/wonder_cards_app.h" #include "savedata/save_table.h" @@ -216,7 +214,7 @@ typedef struct MysteryGiftAnimationManager { int animationStage; int unused_04; s8 blendBrightness; - UnkStruct_ov97_02237AEC *unk_0C; + MainMenuSpriteManager *unk_0C; SpriteResourcesHeader spriteResourcesHeaders[DS_SCREEN_MAX]; SpriteResource *spriteResources[DS_SCREEN_MAX][SPRITE_RESOURCE_MAX]; MysteryGiftParticle topScreenSmallParticles[NUM_MYSTERY_GIFT_PARTICLES]; @@ -299,7 +297,7 @@ StateChangeMenuOptionTemplate sConfirmReceiveGiftOptions_WirelessDistribution[] static ListMenuTemplate sMysteryGiftAppListMenuTemplate = { .choices = NULL, - .cursorCallback = ov97_022383C4, + .cursorCallback = MainMenuUtil_ListMenuCursorCB, .printCallback = NULL, .window = NULL, .count = 0, @@ -346,7 +344,7 @@ static void FreeApplicationResources(ApplicationManager *appMan) { MysteryGiftAppData *appData = ApplicationManager_Data(appMan); - ov97_02237DA0(); + MainMenuUtil_FreeSprites(); if (appData->listMenuOptions) { StringList_Free(appData->listMenuOptions); @@ -380,15 +378,15 @@ static void FreeApplicationResources(ApplicationManager *appMan) static void LoadDownloadArrowSpriteResources(MysteryGiftAppData *appData) { - ov97_02237A20(); - ov97_02237A74(); - ov97_02237B0C(NARC_INDEX_GRAPHIC__MYSTERY, 10, 7, 9, 8, 0); + MainMenuUtil_InitCharPlttTransferBuffers(); + MainMenuUtil_InitSpriteLoader(); + MainMenuUtil_LoadSprite(NARC_INDEX_GRAPHIC__MYSTERY, 10, 7, 9, 8, 0); } static void SetDownloadArrowAnim(MysteryGiftAppData *appData, int animID) { if (animID != HIDE_DOWNLOADING_ARROW) { - appData->dowloadArrowSprite = ov97_02237D14(0, appData->dowloadArrowSprite, HW_LCD_WIDTH / 2, 100, animID); + appData->dowloadArrowSprite = MainMenuUtil_InitSprite(0, appData->dowloadArrowSprite, HW_LCD_WIDTH / 2, 100, animID); } else { Sprite_SetDrawFlag(appData->dowloadArrowSprite, FALSE); } @@ -478,7 +476,7 @@ static WonderCard *GetReceivedWonderCard(ApplicationManager *appMan) switch (appData->receptionMethod) { case RECEIVE_FROM_FRIEND: memcpy(wonderCard, ov97_0222D2B8(0, NULL, 0), sizeof(WonderCard)); - ov97_02238324(&appData->eventData, &appData->eventData.wonderCard, HEAP_ID_MYSTERY_GIFT_APP); + MainMenuUtil_DecryptReceivedWonderCard(&appData->eventData, &appData->eventData.wonderCard, HEAP_ID_MYSTERY_GIFT_APP); break; case RECEIVE_FROM_LOCAL_WIRELESS: eventData = (MysteryGiftEventData *)appData->wirelessDistributionBuffer; @@ -521,7 +519,7 @@ static void MainCallbackSaveGame(MysteryGiftAppData *appData) appData->mainCallback = NULL; } - int saveStatus = ov97_0223847C(); + int saveStatus = MainMenuUtil_SaveState(); if (saveStatus == SAVE_RESULT_OK || saveStatus == SAVE_RESULT_CORRUPT) { if (ShouldPlayAnimation(&appData->eventData.wonderCard) != TRUE) { @@ -566,7 +564,7 @@ static void SaveReceivedGift(ApplicationManager *appMan) saved = MysteryGift_TrySaveWondercard(mysteryGift, wonderCard); } - ov97_0223846C(saveData); + MainMenuUtil_InitSaving(saveData); appData->cancelSave = FALSE; appData->mainCallback = MainCallbackSaveGame; @@ -800,7 +798,7 @@ static enum MysteryGiftAppState ExitToWonderCardsApp(ApplicationManager *appMan) ov97_02230224(appData); } - ov97_02237790(0, MG_APP_STATE_EXIT_TO_WONDER_CARDS_APP, (int *)appData->statePtr, MG_APP_STATE_WAIT_SCREEN_TRANSITION); + MainMenuUtil_StartScreenFadeToState(0, MG_APP_STATE_EXIT_TO_WONDER_CARDS_APP, (int *)appData->statePtr, MG_APP_STATE_WAIT_SCREEN_TRANSITION); return MG_APP_KEEP_PREVIOUS_STATE; } @@ -812,8 +810,8 @@ static enum MysteryGiftAppState ExitToTitleScreen(ApplicationManager *appMan) appData->unk_630 = 1; } - ov97_02237784(1); - ov97_02237790(0, MG_APP_STATE_EXIT_TO_TITLE_SCREEN, (int *)appData->statePtr, MG_APP_STATE_WAIT_SCREEN_TRANSITION); + MainMenuUtil_SetFadeToWhite(1); + MainMenuUtil_StartScreenFadeToState(0, MG_APP_STATE_EXIT_TO_TITLE_SCREEN, (int *)appData->statePtr, MG_APP_STATE_WAIT_SCREEN_TRANSITION); return MG_APP_KEEP_PREVIOUS_STATE; } @@ -1078,14 +1076,14 @@ void MysteryGiftApp_ShowWiFiCommError(MysteryGiftAppData *appData) StringTemplate *strTemplate = StringTemplate_Default(HEAP_ID_MYSTERY_GIFT_APP); StringTemplate_SetNumber(strTemplate, 0, appData->wifiCommErrorCode, 5, PADDING_MODE_ZEROES, CHARSET_MODE_EN); - UnkStruct_ov97_02237808 v1; - ov97_02237808(&v1, &appData->wifiCommErrorWindow, PLTT_1, TEXT_BANK_UNK_0695, BASE_TILE_STANDARD_WINDOW_FRAME, PLTT_3); - ov97_02237858(&v1, 24, 16, 100); - ov97_02237860(&v1, FALSE, FONT_MESSAGE); + MainMenuWindow v1; + MainMenuUtil_InitWindow(&v1, &appData->wifiCommErrorWindow, PLTT_1, TEXT_BANK_UNK_0695, BASE_TILE_STANDARD_WINDOW_FRAME, PLTT_3); + MainMenuWindow_SetDimensionsAndBasetile(&v1, 24, 16, 100); + MainMenuWindow_SetScrollableAndFont(&v1, FALSE, FONT_MESSAGE); - v1.unk_14 = strTemplate; + v1.strTemplate = strTemplate; - ov97_0223795C(appData->bgConfig, &v1, 4, 4, textEntryID); + MainMenuUtil_ShowWindowAtPos(appData->bgConfig, &v1, 4, 4, textEntryID); StringTemplate_Free(strTemplate); } @@ -1186,7 +1184,7 @@ static int MysteryGiftApp_Init(ApplicationManager *appMan, int *unused) if (DistributionCartridge_ReadLength()) { appData->receptionMethod = RECEIVE_FROM_GBA_CARTRIDGE; SetGBACartridgeVersion(gGameVersion); - ov97_02238400(TRUE); + MainMenuUtil_ToggleTerminateOnGBACartRemoved(TRUE); } appData->unk_62C = 29; @@ -1215,18 +1213,18 @@ static void LoadParticleSpriteResources(MysteryGiftAnimationManager *animMan) vramType = NNS_G2D_VRAM_TYPE_2DMAIN; resourceID = 20000 + vramType; - animMan->spriteResources[DS_SCREEN_MAIN][SPRITE_RESOURCE_CHAR] = SpriteResourceCollection_AddTiles(animMan->unk_0C->unk_190[SPRITE_RESOURCE_CHAR], narcID, tilesID, compressed, resourceID, vramType, heapID); - animMan->spriteResources[DS_SCREEN_MAIN][SPRITE_RESOURCE_PLTT] = SpriteResourceCollection_AddPalette(animMan->unk_0C->unk_190[SPRITE_RESOURCE_PLTT], narcID, paletteID, FALSE, resourceID, vramType, PLTT_1, heapID); - animMan->spriteResources[DS_SCREEN_MAIN][SPRITE_RESOURCE_CELL] = SpriteResourceCollection_Add(animMan->unk_0C->unk_190[SPRITE_RESOURCE_CELL], narcID, cellsID, compressed, resourceID, SPRITE_RESOURCE_CELL, heapID); - animMan->spriteResources[DS_SCREEN_MAIN][SPRITE_RESOURCE_ANIM] = SpriteResourceCollection_Add(animMan->unk_0C->unk_190[SPRITE_RESOURCE_ANIM], narcID, animationID, compressed, resourceID, SPRITE_RESOURCE_ANIM, heapID); + animMan->spriteResources[DS_SCREEN_MAIN][SPRITE_RESOURCE_CHAR] = SpriteResourceCollection_AddTiles(animMan->unk_0C->resourceCollections[SPRITE_RESOURCE_CHAR], narcID, tilesID, compressed, resourceID, vramType, heapID); + animMan->spriteResources[DS_SCREEN_MAIN][SPRITE_RESOURCE_PLTT] = SpriteResourceCollection_AddPalette(animMan->unk_0C->resourceCollections[SPRITE_RESOURCE_PLTT], narcID, paletteID, FALSE, resourceID, vramType, PLTT_1, heapID); + animMan->spriteResources[DS_SCREEN_MAIN][SPRITE_RESOURCE_CELL] = SpriteResourceCollection_Add(animMan->unk_0C->resourceCollections[SPRITE_RESOURCE_CELL], narcID, cellsID, compressed, resourceID, SPRITE_RESOURCE_CELL, heapID); + animMan->spriteResources[DS_SCREEN_MAIN][SPRITE_RESOURCE_ANIM] = SpriteResourceCollection_Add(animMan->unk_0C->resourceCollections[SPRITE_RESOURCE_ANIM], narcID, animationID, compressed, resourceID, SPRITE_RESOURCE_ANIM, heapID); vramType = NNS_G2D_VRAM_TYPE_2DSUB; resourceID = 20000 + vramType; - animMan->spriteResources[DS_SCREEN_SUB][SPRITE_RESOURCE_CHAR] = SpriteResourceCollection_AddTiles(animMan->unk_0C->unk_190[SPRITE_RESOURCE_CHAR], narcID, tilesID, compressed, resourceID, vramType, heapID); - animMan->spriteResources[DS_SCREEN_SUB][SPRITE_RESOURCE_PLTT] = SpriteResourceCollection_AddPalette(animMan->unk_0C->unk_190[SPRITE_RESOURCE_PLTT], narcID, paletteID, FALSE, resourceID, vramType, PLTT_1, heapID); - animMan->spriteResources[DS_SCREEN_SUB][SPRITE_RESOURCE_CELL] = SpriteResourceCollection_Add(animMan->unk_0C->unk_190[SPRITE_RESOURCE_CELL], narcID, cellsID, compressed, resourceID, SPRITE_RESOURCE_CELL, heapID); - animMan->spriteResources[DS_SCREEN_SUB][SPRITE_RESOURCE_ANIM] = SpriteResourceCollection_Add(animMan->unk_0C->unk_190[SPRITE_RESOURCE_ANIM], narcID, animationID, compressed, resourceID, SPRITE_RESOURCE_ANIM, heapID); + animMan->spriteResources[DS_SCREEN_SUB][SPRITE_RESOURCE_CHAR] = SpriteResourceCollection_AddTiles(animMan->unk_0C->resourceCollections[SPRITE_RESOURCE_CHAR], narcID, tilesID, compressed, resourceID, vramType, heapID); + animMan->spriteResources[DS_SCREEN_SUB][SPRITE_RESOURCE_PLTT] = SpriteResourceCollection_AddPalette(animMan->unk_0C->resourceCollections[SPRITE_RESOURCE_PLTT], narcID, paletteID, FALSE, resourceID, vramType, PLTT_1, heapID); + animMan->spriteResources[DS_SCREEN_SUB][SPRITE_RESOURCE_CELL] = SpriteResourceCollection_Add(animMan->unk_0C->resourceCollections[SPRITE_RESOURCE_CELL], narcID, cellsID, compressed, resourceID, SPRITE_RESOURCE_CELL, heapID); + animMan->spriteResources[DS_SCREEN_SUB][SPRITE_RESOURCE_ANIM] = SpriteResourceCollection_Add(animMan->unk_0C->resourceCollections[SPRITE_RESOURCE_ANIM], narcID, animationID, compressed, resourceID, SPRITE_RESOURCE_ANIM, heapID); SpriteTransfer_RequestChar(animMan->spriteResources[DS_SCREEN_MAIN][SPRITE_RESOURCE_CHAR]); SpriteTransfer_RequestChar(animMan->spriteResources[DS_SCREEN_SUB][SPRITE_RESOURCE_CHAR]); @@ -1237,13 +1235,13 @@ static void LoadParticleSpriteResources(MysteryGiftAnimationManager *animMan) vramType = NNS_G2D_VRAM_TYPE_2DMAIN; resourceID = 20000 + vramType; - SpriteResourcesHeader_Init(&animMan->spriteResourcesHeaders[DS_SCREEN_MAIN], resourceID, resourceID, resourceID, resourceID, 0xffffffff, 0xffffffff, FALSE, 0, animMan->unk_0C->unk_190[SPRITE_RESOURCE_CHAR], animMan->unk_0C->unk_190[SPRITE_RESOURCE_PLTT], animMan->unk_0C->unk_190[SPRITE_RESOURCE_CELL], animMan->unk_0C->unk_190[SPRITE_RESOURCE_ANIM], NULL, NULL); + SpriteResourcesHeader_Init(&animMan->spriteResourcesHeaders[DS_SCREEN_MAIN], resourceID, resourceID, resourceID, resourceID, 0xffffffff, 0xffffffff, FALSE, 0, animMan->unk_0C->resourceCollections[SPRITE_RESOURCE_CHAR], animMan->unk_0C->resourceCollections[SPRITE_RESOURCE_PLTT], animMan->unk_0C->resourceCollections[SPRITE_RESOURCE_CELL], animMan->unk_0C->resourceCollections[SPRITE_RESOURCE_ANIM], NULL, NULL); vramType = NNS_G2D_VRAM_TYPE_2DSUB; resourceID = 20000 + vramType; // Despite baseIndex always being 0, replacing `baseIndex + DS_SCREEN_SUB` with `DS_SCREEN_SUB` doesn't match here. - SpriteResourcesHeader_Init(&animMan->spriteResourcesHeaders[baseIndex + DS_SCREEN_SUB], resourceID, resourceID, resourceID, resourceID, 0xffffffff, 0xffffffff, FALSE, 0, animMan->unk_0C->unk_190[SPRITE_RESOURCE_CHAR], animMan->unk_0C->unk_190[SPRITE_RESOURCE_PLTT], animMan->unk_0C->unk_190[SPRITE_RESOURCE_CELL], animMan->unk_0C->unk_190[SPRITE_RESOURCE_ANIM], NULL, NULL); + SpriteResourcesHeader_Init(&animMan->spriteResourcesHeaders[baseIndex + DS_SCREEN_SUB], resourceID, resourceID, resourceID, resourceID, 0xffffffff, 0xffffffff, FALSE, 0, animMan->unk_0C->resourceCollections[SPRITE_RESOURCE_CHAR], animMan->unk_0C->resourceCollections[SPRITE_RESOURCE_PLTT], animMan->unk_0C->resourceCollections[SPRITE_RESOURCE_CELL], animMan->unk_0C->resourceCollections[SPRITE_RESOURCE_ANIM], NULL, NULL); } static Sprite *InitParticleSprite(MysteryGiftAnimationManager *animMan, int vramType) @@ -1256,7 +1254,7 @@ static Sprite *InitParticleSprite(MysteryGiftAnimationManager *animMan, int vram // 0 is the top screen, 1 is the bottom screen. Using enum variants doesn't match. enum DSScreen screen = (vramType == NNS_G2D_VRAM_TYPE_2DMAIN) ? 0 : 1; - template.list = animMan->unk_0C->unk_00; + template.list = animMan->unk_0C->spriteList; template.resourceData = &animMan->spriteResourcesHeaders[screen]; template.position.z = 0; template.affineScale.x = FX32_ONE; @@ -2004,7 +2002,7 @@ static BOOL MysteryGiftApp_Main(ApplicationManager *appMan, enum MysteryGiftAppS switch (*state) { case MG_APP_STATE_SETUP: - ov97_02237694(HEAP_ID_MYSTERY_GIFT_APP); + MainMenuUtil_Init(HEAP_ID_MYSTERY_GIFT_APP); appData->statePtr = state; *state = MG_APP_STATE_INIT_GRAPHICS; break; @@ -2012,10 +2010,10 @@ static BOOL MysteryGiftApp_Main(ApplicationManager *appMan, enum MysteryGiftAppS case MG_APP_STATE_INIT_GRAPHICS: ShowAppMainMenu(appMan, appData); LoadDownloadArrowSpriteResources(appData); - ov97_02237790(1, MG_APP_STATE_WAIT_MAIN_MENU_INPUT, (int *)state, MG_APP_STATE_WAIT_SCREEN_TRANSITION); + MainMenuUtil_StartScreenFadeToState(1, MG_APP_STATE_WAIT_MAIN_MENU_INPUT, (int *)state, MG_APP_STATE_WAIT_SCREEN_TRANSITION); break; case MG_APP_STATE_WAIT_SCREEN_TRANSITION: - ov97_022377F0((int *)state); + MainMenuUtil_CheckScreenFadeDone((int *)state); break; case MG_APP_STATE_WAIT_MAIN_MENU_INPUT: ProcessStateTransitionMenuInput(appMan, state, ExitToTitleScreen); @@ -2083,12 +2081,12 @@ static BOOL MysteryGiftApp_Main(ApplicationManager *appMan, enum MysteryGiftAppS memset(animMan, 0, sizeof(MysteryGiftAnimationManager)); animMan->animationStatusPtr = &appData->animationStatus; - animMan->unk_0C = ov97_02237AEC(); + animMan->unk_0C = MainMenuUtil_GetSpriteManager(); SysTask_Start((SysTaskFunc)RunMysteryGiftAnimationFrame, animMan, 5); } } else { - ov97_02238194(appData->bgConfig, wonderCard); + MainMenuUtil_LoadGiftSprite(appData->bgConfig, wonderCard); SaveReceivedGift(appMan); } @@ -2101,10 +2099,10 @@ static BOOL MysteryGiftApp_Main(ApplicationManager *appMan, enum MysteryGiftAppS } break; case MG_APP_STATE_WAIT_LOCAL_WIRELESS_GIFT_SAVED: { - int saveStatus = ov97_02238528(); + int saveStatus = MainMenuUtil_GetSavingStatus(); if (saveStatus == 4) { - ov97_022384F4(); + MainMenuUtil_ContinueSaving(); } if (saveStatus == SAVE_RESULT_OK) { @@ -2118,7 +2116,7 @@ static BOOL MysteryGiftApp_Main(ApplicationManager *appMan, enum MysteryGiftAppS WonderCard *wonderCard = &appData->eventData.wonderCard; if (ShouldPlayAnimation(wonderCard) == TRUE) { - ov97_02238194(appData->bgConfig, wonderCard); + MainMenuUtil_LoadGiftSprite(appData->bgConfig, wonderCard); appData->animationStatus = MG_ANIMATION_STATUS_PROCEED_IMPLOSION; } else { Sound_PlayEffect(SEQ_SE_DP_UG_020); @@ -2219,7 +2217,7 @@ static BOOL MysteryGiftApp_Main(ApplicationManager *appMan, enum MysteryGiftAppS } break; case MG_APP_STATE_SAVE_GIFT_FROM_FRIEND: - ov97_02238194(appData->bgConfig, GetReceivedWonderCard(appMan)); + MainMenuUtil_LoadGiftSprite(appData->bgConfig, GetReceivedWonderCard(appMan)); CommMan_SetErrorHandling(0, 0); SaveReceivedGift(appMan); *state = MG_APP_STATE_CHECK_FRIEND_CONNECTION_STILL_VALID; @@ -2230,7 +2228,7 @@ static BOOL MysteryGiftApp_Main(ApplicationManager *appMan, enum MysteryGiftAppS if (netID != 0 && CommSys_IsPlayerConnected(netID) == FALSE) { ov97_0222D2DC(); appData->cancelSave = TRUE; - ov97_0223850C(); + MainMenuUtil_CancelSave(); ToggleWaitDial(appData, FALSE); sub_02039794(); SetDownloadArrowAnim(appData, HIDE_DOWNLOADING_ARROW); @@ -2238,12 +2236,12 @@ static BOOL MysteryGiftApp_Main(ApplicationManager *appMan, enum MysteryGiftAppS break; } - if (ov97_02238528() == 4) { + if (MainMenuUtil_GetSavingStatus() == 4) { CommTiming_StartSync(0x93); *state = MG_APP_STATE_WAIT_FRIEND_READY_TO_DISCONNECT; appData->delay = 120; - } else if (ov97_02238528() == SAVE_RESULT_CORRUPT) { - ov97_0223850C(); + } else if (MainMenuUtil_GetSavingStatus() == SAVE_RESULT_CORRUPT) { + MainMenuUtil_CancelSave(); appData->eventData.header.hasWonderCard = FALSE; ToggleWaitDial(appData, FALSE); *state = ShowMessageBoxIntoStateTransition(appMan, &appData->messageBox, MysteryGiftMenu_Text_ProblemWithReceivingTheGift, MG_APP_STATE_EXIT_AFTER_RECEIVING_GIFT); @@ -2251,11 +2249,11 @@ static BOOL MysteryGiftApp_Main(ApplicationManager *appMan, enum MysteryGiftAppS } break; case MG_APP_STATE_WAIT_FRIEND_READY_TO_DISCONNECT: if (CommTiming_IsSyncState(0x93) == TRUE) { - ov97_022384F4(); + MainMenuUtil_ContinueSaving(); appData->delay = 10; *state = MG_APP_STATE_RECEIVE_FROM_FRIEND_SUCCESS; } else if (--appData->delay == 0) { - ov97_0223850C(); + MainMenuUtil_CancelSave(); appData->eventData.header.hasWonderCard = FALSE; ToggleWaitDial(appData, FALSE); *state = ShowMessageBoxIntoStateTransition(appMan, &appData->messageBox, MysteryGiftMenu_Text_ProblemWithReceivingTheGift, MG_APP_STATE_EXIT_AFTER_RECEIVING_GIFT); @@ -2336,7 +2334,7 @@ static BOOL MysteryGiftApp_Main(ApplicationManager *appMan, enum MysteryGiftAppS case MG_APP_STATE_SHOW_RECEIVING_GIFT_MSG: { WonderCard *wonderCard = GetReceivedWonderCard(appMan); - ov97_02238194(appData->bgConfig, wonderCard); + MainMenuUtil_LoadGiftSprite(appData->bgConfig, wonderCard); ShowMessageBox(appMan, &appData->messageBox, MysteryGiftMenu_Text_ReceivingGiftDontTurnOff); SetDownloadArrowAnim(appData, 1); ToggleWaitDial(appData, TRUE); @@ -2350,17 +2348,17 @@ static BOOL MysteryGiftApp_Main(ApplicationManager *appMan, enum MysteryGiftAppS } break; case MG_APP_STATE_WAIT_MYSTERY_GIFT_SAVED: - if (ov97_02238528() == 4) { - ov97_022384F4(); + if (MainMenuUtil_GetSavingStatus() == 4) { + MainMenuUtil_ContinueSaving(); } - if (ov97_02238528() == SAVE_RESULT_OK) { + if (MainMenuUtil_GetSavingStatus() == SAVE_RESULT_OK) { appData->delay = 1; ToggleWaitDial(appData, FALSE); SetDownloadArrowAnim(appData, HIDE_DOWNLOADING_ARROW); Sound_PlayEffect(SEQ_SE_DP_UG_020); *state = ShowMessageBoxIntoStateTransition(appMan, &appData->messageBox, MysteryGiftMenu_Text_GiftReceivedPickUpInPokeMart, MG_APP_STATE_WAIT_BEFORE_EXIT_AFTER_RECEIVING_GIFT); - } else if (ov97_02238528() == SAVE_RESULT_CORRUPT) { + } else if (MainMenuUtil_GetSavingStatus() == SAVE_RESULT_CORRUPT) { SetDownloadArrowAnim(appData, HIDE_DOWNLOADING_ARROW); appData->eventData.header.hasWonderCard = FALSE; *state = ShowMessageBoxIntoStateTransition(appMan, &appData->messageBox, MysteryGiftMenu_Text_ProblemWithReceivingTheGift, MG_APP_STATE_EXIT_AFTER_RECEIVING_GIFT); @@ -2409,10 +2407,10 @@ static BOOL MysteryGiftApp_Main(ApplicationManager *appMan, enum MysteryGiftAppS Sound_PlayEffect(SEQ_SE_CONFIRM); if (appData->eventData.header.hasWonderCard == TRUE) { - ov97_02237790(0, MG_APP_STATE_SHOW_RECEIVED_WONDERCARD, (int *)appData->statePtr, MG_APP_STATE_WAIT_SCREEN_TRANSITION); + MainMenuUtil_StartScreenFadeToState(0, MG_APP_STATE_SHOW_RECEIVED_WONDERCARD, (int *)appData->statePtr, MG_APP_STATE_WAIT_SCREEN_TRANSITION); } else { - ov97_02237784(1); - ov97_02237790(0, MG_APP_STATE_RESET_SYSTEM, (int *)appData->statePtr, MG_APP_STATE_WAIT_SCREEN_TRANSITION); + MainMenuUtil_SetFadeToWhite(1); + MainMenuUtil_StartScreenFadeToState(0, MG_APP_STATE_RESET_SYSTEM, (int *)appData->statePtr, MG_APP_STATE_WAIT_SCREEN_TRANSITION); } } break; @@ -2421,7 +2419,7 @@ static BOOL MysteryGiftApp_Main(ApplicationManager *appMan, enum MysteryGiftAppS GXLayers_EngineBToggleLayers(GX_PLANEMASK_BG0, FALSE); GXLayers_EngineBToggleLayers(GX_PLANEMASK_BG1, TRUE); WonderCardsApp_ShowWondercard(appData->bgConfig, &appData->eventData.wonderCard, HEAP_ID_MYSTERY_GIFT_APP); - ov97_02237790(1, MG_APP_STATE_EXIT_AFTER_RECEIVING_GIFT, (int *)appData->statePtr, MG_APP_STATE_WAIT_SCREEN_TRANSITION); + MainMenuUtil_StartScreenFadeToState(1, MG_APP_STATE_EXIT_AFTER_RECEIVING_GIFT, (int *)appData->statePtr, MG_APP_STATE_WAIT_SCREEN_TRANSITION); appData->eventData.header.hasWonderCard = FALSE; // Makes the game exit the application break; case MG_APP_STATE_RESET_SYSTEM: @@ -2433,7 +2431,7 @@ static BOOL MysteryGiftApp_Main(ApplicationManager *appMan, enum MysteryGiftAppS appData->mainCallback(appData); } - ov97_02237CAC(appData->animationStatus); + MainMenuUtil_UpdateSprites(appData->animationStatus); return FALSE; } @@ -2470,7 +2468,7 @@ static int MysteryGiftApp_Exit(ApplicationManager *appMan, int *unused) SetGBACartridgeVersion(VERSION_NONE); } - ov97_02238400(FALSE); + MainMenuUtil_ToggleTerminateOnGBACartRemoved(FALSE); return TRUE; } diff --git a/src/overlay097/ov97_0222C174.c b/src/overlay097/ov97_0222C174.c index 8709678191..74fffac3cd 100644 --- a/src/overlay097/ov97_0222C174.c +++ b/src/overlay097/ov97_0222C174.c @@ -10,7 +10,6 @@ #include "overlay097/ov97_02237694.h" #include "overlay097/struct_ov97_02232E38.h" #include "overlay097/struct_ov97_022335A8.h" -#include "overlay097/struct_ov97_02237808.h" #include "savedata/save_table.h" #include "bg_window.h" @@ -352,9 +351,9 @@ typedef struct { Window unk_18; Window unk_28; Window unk_38; - UnkStruct_ov97_02237808 unk_48; - UnkStruct_ov97_02237808 unk_9C; - UnkStruct_ov97_02237808 unk_F0; + MainMenuWindow unk_48; + MainMenuWindow unk_9C; + MainMenuWindow unk_F0; int unk_144; int unk_148; int unk_14C; @@ -529,10 +528,10 @@ static void ov97_0222C254(UnkStruct_ov97_0222C388 *param0) GXLayers_SetBanks(&v1); SetAllGraphicsModes(&v2); - ov97_022376FC(param0->unk_04, 0, 1, 0xF000, 0x0); - ov97_022376FC(param0->unk_04, 1, 1, 0xF800, 0x4000); - ov97_022376FC(param0->unk_04, 4, 1, 0x7800, 0x0); - ov97_022376FC(param0->unk_04, 5, 1, 0x7000, 0x4000); + MainMenuUtil_InitBG(param0->unk_04, 0, 1, 0xF000, 0x0); + MainMenuUtil_InitBG(param0->unk_04, 1, 1, 0xF800, 0x4000); + MainMenuUtil_InitBG(param0->unk_04, 4, 1, 0x7800, 0x0); + MainMenuUtil_InitBG(param0->unk_04, 5, 1, 0x7000, 0x4000); Text_ResetAllPrinters(); Font_LoadTextPalette(0, 0 * 32, param0->heapID); @@ -561,12 +560,12 @@ static void ov97_0222C388(UnkStruct_ov97_0222C388 *param0) static BOOL ov97_0222C404(UnkStruct_ov97_0222C388 *param0) { - UnkStruct_ov97_02237808 v0; + MainMenuWindow v0; if (Window_IsInUse(¶m0->unk_18) == 0) { - ov97_02237808(&v0, ¶m0->unk_18, 0, 14, 1, 1); - ov97_02237858(&v0, 22, 16, param0->unk_144); - ov97_0223795C(param0->unk_04, &v0, 5, 4, 2); + MainMenuUtil_InitWindow(&v0, ¶m0->unk_18, 0, 14, 1, 1); + MainMenuWindow_SetDimensionsAndBasetile(&v0, 22, 16, param0->unk_144); + MainMenuUtil_ShowWindowAtPos(param0->unk_04, &v0, 5, 4, 2); return 1; } else { if (gSystem.pressedKeys & (PAD_BUTTON_A | PAD_BUTTON_B)) { @@ -583,25 +582,25 @@ static void ov97_0222C578(UnkStruct_ov97_0222C388 *param0); static void ov97_0222C47C(UnkStruct_ov97_0222C388 *param0) { - ov97_02237808(¶m0->unk_48, ¶m0->unk_28, 0, 421, (1 + 9), 2); - ov97_02237858(¶m0->unk_48, 27, 4, param0->unk_144); - ov97_02237860(¶m0->unk_48, 1, 1); - ov97_0223795C(param0->unk_04, ¶m0->unk_48, 2, 19, 70); + MainMenuUtil_InitWindow(¶m0->unk_48, ¶m0->unk_28, 0, 421, (1 + 9), 2); + MainMenuWindow_SetDimensionsAndBasetile(¶m0->unk_48, 27, 4, param0->unk_144); + MainMenuWindow_SetScrollableAndFont(¶m0->unk_48, 1, 1); + MainMenuUtil_ShowWindowAtPos(param0->unk_04, ¶m0->unk_48, 2, 19, 70); - param0->unk_144 += ov97_02237A18(¶m0->unk_48); + param0->unk_144 += MainMenuWindow_GetSize(¶m0->unk_48); - ov97_02237808(¶m0->unk_9C, ¶m0->unk_18, 0, 421, 1, 1); - ov97_02237858(¶m0->unk_9C, 30, 4, param0->unk_144); - ov97_02237860(¶m0->unk_9C, 0, 1); - ov97_0223795C(param0->unk_04, ¶m0->unk_9C, 1, 1, 11); + MainMenuUtil_InitWindow(¶m0->unk_9C, ¶m0->unk_18, 0, 421, 1, 1); + MainMenuWindow_SetDimensionsAndBasetile(¶m0->unk_9C, 30, 4, param0->unk_144); + MainMenuWindow_SetScrollableAndFont(¶m0->unk_9C, 0, 1); + MainMenuUtil_ShowWindowAtPos(param0->unk_04, ¶m0->unk_9C, 1, 1, 11); - param0->unk_144 += ov97_02237A18(¶m0->unk_9C); + param0->unk_144 += MainMenuWindow_GetSize(¶m0->unk_9C); - ov97_02237A20(); - ov97_02237A74(); - ov97_02237B0C(116, 10, 7, 9, 8, 0); + MainMenuUtil_InitCharPlttTransferBuffers(); + MainMenuUtil_InitSpriteLoader(); + MainMenuUtil_LoadSprite(116, 10, 7, 9, 8, 0); - param0->unk_3170 = ov97_02237D14(0, param0->unk_3170, HW_LCD_WIDTH / 2, 76, 1); + param0->unk_3170 = MainMenuUtil_InitSprite(0, param0->unk_3170, HW_LCD_WIDTH / 2, 76, 1); ov97_0222C578(param0); } @@ -613,19 +612,19 @@ static void ov97_0222C578(UnkStruct_ov97_0222C388 *param0) UnkStruct_ov97_022335A8 v5; StringTemplate *v6 = StringTemplate_Default(param0->heapID); - ov97_02237808(¶m0->unk_F0, ¶m0->unk_38, 0, 421, 1, 1); - ov97_02237858(¶m0->unk_F0, 26, 4, param0->unk_144); - ov97_02237860(¶m0->unk_F0, 0, 1); + MainMenuUtil_InitWindow(¶m0->unk_F0, ¶m0->unk_38, 0, 421, 1, 1); + MainMenuWindow_SetDimensionsAndBasetile(¶m0->unk_F0, 26, 4, param0->unk_144); + MainMenuWindow_SetScrollableAndFont(¶m0->unk_F0, 0, 1); - param0->unk_F0.unk_14 = v6; + param0->unk_F0.strTemplate = v6; StringTemplate_SetPlayerName(v6, 0, param0->unk_10); StringTemplate_SetNumber(v6, 1, TrainerInfo_ID_LowHalf(param0->unk_10), 5, 2, 1); - ov97_0223795C(param0->unk_04, ¶m0->unk_F0, 3, 13, 66); - param0->unk_F0.unk_08 = 0; - ov97_02237868(¶m0->unk_F0, 0, Font_GetAttribute(FONT_SYSTEM, FONTATTR_MAX_LETTER_HEIGHT)); - ov97_0223795C(param0->unk_04, ¶m0->unk_F0, -1, -1, 68); + MainMenuUtil_ShowWindowAtPos(param0->unk_04, ¶m0->unk_F0, 3, 13, 66); + param0->unk_F0.clearBeforePrinting = 0; + MainMenuWindow_SetTextOffsets(¶m0->unk_F0, 0, Font_GetAttribute(FONT_SYSTEM, FONTATTR_MAX_LETTER_HEIGHT)); + MainMenuUtil_ShowWindowAtPos(param0->unk_04, ¶m0->unk_F0, -1, -1, 68); OS_GetMacAddress(v4); @@ -635,9 +634,9 @@ static void ov97_0222C578(UnkStruct_ov97_0222C388 *param0) StringTemplate_SetNumber(v6, 0, v0, 4, 2, 1); StringTemplate_SetNumber(v6, 1, v1, 4, 2, 1); - param0->unk_F0.unk_0C = 1; + param0->unk_F0.textRightAligned = 1; - ov97_0223795C(param0->unk_04, ¶m0->unk_F0, -1, -1, 69); + MainMenuUtil_ShowWindowAtPos(param0->unk_04, ¶m0->unk_F0, -1, -1, 69); StringTemplate_Free(v6); } @@ -646,7 +645,7 @@ static void ov97_0222C688(ApplicationManager *appMan) int v0; UnkStruct_ov97_0222C388 *v1 = ApplicationManager_Data(appMan); - ov97_02237DA0(); + MainMenuUtil_FreeSprites(); if (Window_IsInUse(&v1->unk_18) == 1) { Window_ClearAndCopyToVRAM(&v1->unk_18); @@ -666,7 +665,7 @@ static void ov97_0222C688(ApplicationManager *appMan) static int ov97_0222C6F8(ApplicationManager *appMan, int *param1) { - UnkStruct_ov97_0222C388 *v0 = ov97_022376C4(appMan, HEAP_ID_85, sizeof(UnkStruct_ov97_0222C388), 0x20000); + UnkStruct_ov97_0222C388 *v0 = MainMenuUtil_InitAppAndFadeToBlack(appMan, HEAP_ID_85, sizeof(UnkStruct_ov97_0222C388), 0x20000); v0->heapID = HEAP_ID_85; v0->unk_04 = BgConfig_New(v0->heapID); @@ -675,7 +674,7 @@ static int ov97_0222C6F8(ApplicationManager *appMan, int *param1) v0->unk_0C = SaveData_GetPokedex(v0->saveData); v0->options = SaveData_GetOptions(v0->saveData); - ov97_02237694(v0->heapID); + MainMenuUtil_Init(v0->heapID); v0->unk_3174 = SaveData_GetMysteryGift(v0->saveData); v0->unk_14C = UnkEnum_ov97_0222C78C_09; @@ -699,44 +698,44 @@ static int ov97_0222C78C(ApplicationManager *appMan, int *param1) ov97_0222C254(v0); if (Pokedex_IsObtained(v0->unk_0C) == FALSE) { - ov97_02237790(1, UnkEnum_ov97_0222C78C_01, param1, UnkEnum_ov97_0222C78C_13); + MainMenuUtil_StartScreenFadeToState(1, UnkEnum_ov97_0222C78C_01, param1, UnkEnum_ov97_0222C78C_13); } else { *param1 = UnkEnum_ov97_0222C78C_02; } break; case UnkEnum_ov97_0222C78C_01: if (ov97_0222C404(v0) == 0) { - ov97_02237784(1); - ov97_02237790(0, UnkEnum_ov97_0222C78C_12, param1, UnkEnum_ov97_0222C78C_13); + MainMenuUtil_SetFadeToWhite(1); + MainMenuUtil_StartScreenFadeToState(0, UnkEnum_ov97_0222C78C_12, param1, UnkEnum_ov97_0222C78C_13); } break; case UnkEnum_ov97_0222C78C_02: ov97_0222C47C(v0); if (MysteryGift_CheckFreePgtSlotExists(v0->unk_3174) == 0) { - v0->unk_48.unk_50 = 1; - v0->unk_317C = ov97_0223795C(v0->unk_04, &v0->unk_48, 2, 19, 21); - ov97_02237790(1, UnkEnum_ov97_0222C78C_03, param1, UnkEnum_ov97_0222C78C_13); + v0->unk_48.renderDelay = 1; + v0->unk_317C = MainMenuUtil_ShowWindowAtPos(v0->unk_04, &v0->unk_48, 2, 19, 21); + MainMenuUtil_StartScreenFadeToState(1, UnkEnum_ov97_0222C78C_03, param1, UnkEnum_ov97_0222C78C_13); } else { v0->unk_14C = UnkEnum_ov97_0222C78C_07; - ov97_02237790(1, UnkEnum_ov97_0222C78C_04, param1, UnkEnum_ov97_0222C78C_13); + MainMenuUtil_StartScreenFadeToState(1, UnkEnum_ov97_0222C78C_04, param1, UnkEnum_ov97_0222C78C_13); } break; case UnkEnum_ov97_0222C78C_03: if ((Text_IsPrinterActive(v0->unk_317C) == 0) && gSystem.pressedKeys & PAD_BUTTON_A) { - ov97_02237784(1); - ov97_02237790(0, UnkEnum_ov97_0222C78C_12, param1, UnkEnum_ov97_0222C78C_13); + MainMenuUtil_SetFadeToWhite(1); + MainMenuUtil_StartScreenFadeToState(0, UnkEnum_ov97_0222C78C_12, param1, UnkEnum_ov97_0222C78C_13); } break; case UnkEnum_ov97_0222C78C_04: v0->unk_150 = ov97_0222CB10(v0); if (v0->unk_150 == 5) { - ov97_02237784(1); - ov97_02237790(0, UnkEnum_ov97_0222C78C_12, param1, UnkEnum_ov97_0222C78C_13); + MainMenuUtil_SetFadeToWhite(1); + MainMenuUtil_StartScreenFadeToState(0, UnkEnum_ov97_0222C78C_12, param1, UnkEnum_ov97_0222C78C_13); } else if (v0->unk_150 == 4) { - ov97_02237784(1); - ov97_02237790(0, UnkEnum_ov97_0222C78C_12, param1, UnkEnum_ov97_0222C78C_13); + MainMenuUtil_SetFadeToWhite(1); + MainMenuUtil_StartScreenFadeToState(0, UnkEnum_ov97_0222C78C_12, param1, UnkEnum_ov97_0222C78C_13); } break; case UnkEnum_ov97_0222C78C_05: @@ -746,12 +745,12 @@ static int ov97_0222C78C(ApplicationManager *appMan, int *param1) GXLayers_EngineBToggleLayers(GX_PLANEMASK_BG1, 0); WonderCardsApp_ShowWondercard(v0->unk_04, &v0->unk_3180, HEAP_ID_85); - ov97_02237790(1, UnkEnum_ov97_0222C78C_06, param1, UnkEnum_ov97_0222C78C_13); + MainMenuUtil_StartScreenFadeToState(1, UnkEnum_ov97_0222C78C_06, param1, UnkEnum_ov97_0222C78C_13); v0->unk_3180.eventHeader.hasWonderCard = 0; break; case UnkEnum_ov97_0222C78C_06: if (gSystem.pressedKeys) { - ov97_02237790(0, UnkEnum_ov97_0222C78C_11, param1, UnkEnum_ov97_0222C78C_13); + MainMenuUtil_StartScreenFadeToState(0, UnkEnum_ov97_0222C78C_11, param1, UnkEnum_ov97_0222C78C_13); } break; case UnkEnum_ov97_0222C78C_11: @@ -762,11 +761,11 @@ static int ov97_0222C78C(ApplicationManager *appMan, int *param1) return 1; break; case UnkEnum_ov97_0222C78C_13: - ov97_022377F0(param1); + MainMenuUtil_CheckScreenFadeDone(param1); break; } - ov97_02237CA0(); + MainMenuUtil_UpdateSpritesSkipGift(); return 0; } @@ -800,7 +799,7 @@ static void ov97_0222C974(UnkStruct_ov97_0222C388 *param0) Strbuf_ToChars((const Strbuf *)v1, v4->eventHeader.title, 36); Strbuf_Free(v1); - v4->eventHeader.validGames = (ov97_02237E4C(10) | ov97_02237E4C(11) | ov97_02237E4C(12)); + v4->eventHeader.validGames = (MainMenuUtil_CalcMysteryGiftVersionBit(10) | MainMenuUtil_CalcMysteryGiftVersionBit(11) | MainMenuUtil_CalcMysteryGiftVersionBit(12)); v4->eventHeader.id = 1; v4->eventHeader.unique = 0; v4->eventHeader.unk_4E_1 = 0; @@ -826,7 +825,7 @@ static void ov97_0222C974(UnkStruct_ov97_0222C388 *param0) MysteryGift_TrySavePgt(param0->unk_3174, &v4->pgt, 3); GXLayers_EngineBToggleLayers(GX_PLANEMASK_BG0, 0); - ov97_02238194(param0->unk_04, v4); + MainMenuUtil_LoadGiftSprite(param0->unk_04, v4); } static void ov97_0222CAAC(UnkStruct_ov97_0222C388 *param0, int param1) @@ -921,7 +920,7 @@ int ov97_0222CB10(UnkStruct_ov97_0222C388 *param0) } break; case UnkEnum_ov97_0222C6F8_29: - ov97_0223795C(param0->unk_04, ¶m0->unk_48, 2, 19, 30); + MainMenuUtil_ShowWindowAtPos(param0->unk_04, ¶m0->unk_48, 2, 19, 30); Sprite_SetDrawFlag(param0->unk_3170, FALSE); DestroyWaitDial(param0->unk_34D8); param0->unk_34D8 = NULL; @@ -947,7 +946,7 @@ int ov97_0222CB10(UnkStruct_ov97_0222C388 *param0) ov97_0223329C(); *v3 = UnkEnum_ov97_0222C6F8_10; param0->unk_160 = 3200; - ov97_0223795C(param0->unk_04, ¶m0->unk_48, 2, 19, 34); + MainMenuUtil_ShowWindowAtPos(param0->unk_04, ¶m0->unk_48, 2, 19, 34); Sound_PlayEffect(SEQ_SE_CONFIRM); param0->unk_34D8 = NULL; @@ -958,7 +957,7 @@ int ov97_0222CB10(UnkStruct_ov97_0222C388 *param0) break; case UnkEnum_ov97_0222C6F8_10: if (ov97_022332F4()) { - ov97_0223795C(param0->unk_04, ¶m0->unk_48, 2, 19, 71); + MainMenuUtil_ShowWindowAtPos(param0->unk_04, ¶m0->unk_48, 2, 19, 71); Sprite_SetDrawFlag(param0->unk_3170, TRUE); ov97_0222C578(param0); *v3 = UnkEnum_ov97_0222C6F8_11; @@ -975,22 +974,22 @@ int ov97_0222CB10(UnkStruct_ov97_0222C388 *param0) if (ov97_02233320()) { *v3 = UnkEnum_ov97_0222C6F8_13; param0->unk_160 = 60; - ov97_0223795C(param0->unk_04, ¶m0->unk_48, 2, 19, 71); + MainMenuUtil_ShowWindowAtPos(param0->unk_04, ¶m0->unk_48, 2, 19, 71); } ov97_0222CAB4(param0, v3, 1, PAD_BUTTON_B); break; case UnkEnum_ov97_0222C6F8_13: if (--param0->unk_160 == 0) { - ov97_0223795C(param0->unk_04, ¶m0->unk_48, 2, 19, 72); + MainMenuUtil_ShowWindowAtPos(param0->unk_04, ¶m0->unk_48, 2, 19, 72); param0->unk_34D8 = Window_AddWaitDial(¶m0->unk_28, (1 + 9)); ov97_0222C974(param0); - ov97_0223846C(param0->saveData); + MainMenuUtil_InitSaving(param0->saveData); *v3 = UnkEnum_ov97_0222C6F8_14; } break; case UnkEnum_ov97_0222C6F8_14: - if (ov97_0223847C() == 1) { + if (MainMenuUtil_SaveState() == 1) { *v3 = UnkEnum_ov97_0222C6F8_15; param0->unk_160 = 6 + (OS_GetTickLo() % 54); } @@ -1007,7 +1006,7 @@ int ov97_0222CB10(UnkStruct_ov97_0222C388 *param0) break; case UnkEnum_ov97_0222C6F8_17: if (ov97_0223334C()) { - ov97_022384F4(); + MainMenuUtil_ContinueSaving(); *v3 = UnkEnum_ov97_0222C6F8_18; param0->unk_160 = 800; @@ -1027,12 +1026,12 @@ int ov97_0222CB10(UnkStruct_ov97_0222C388 *param0) } break; case UnkEnum_ov97_0222C6F8_18: - if (ov97_02238528() == 3) { + if (MainMenuUtil_GetSavingStatus() == 3) { ov97_022333BC(); *v3 = UnkEnum_ov97_0222C6F8_22; param0->unk_160 = 120; - } else if (ov97_02238528() != 2) { - ov97_0223847C(); + } else if (MainMenuUtil_GetSavingStatus() != 2) { + MainMenuUtil_SaveState(); } else { if (ov97_02233320() || (!ov97_02233388())) { *v3 = UnkEnum_ov97_0222C6F8_19; @@ -1051,7 +1050,7 @@ int ov97_0222CB10(UnkStruct_ov97_0222C388 *param0) if (--param0->unk_160 == 0) { *v3 = UnkEnum_ov97_0222C6F8_20; - ov97_0223795C(param0->unk_04, ¶m0->unk_48, 2, 19, 73); + MainMenuUtil_ShowWindowAtPos(param0->unk_04, ¶m0->unk_48, 2, 19, 73); Sprite_SetDrawFlag(param0->unk_3170, FALSE); DestroyWaitDial(param0->unk_34D8); @@ -1077,7 +1076,7 @@ int ov97_0222CB10(UnkStruct_ov97_0222C388 *param0) case UnkEnum_ov97_0222C6F8_22: *v3 = UnkEnum_ov97_0222C6F8_23; case UnkEnum_ov97_0222C6F8_23: - ov97_0223795C(param0->unk_04, ¶m0->unk_48, 2, 19, 74); + MainMenuUtil_ShowWindowAtPos(param0->unk_04, ¶m0->unk_48, 2, 19, 74); Sprite_SetDrawFlag(param0->unk_3170, FALSE); if (param0->unk_34D8) { diff --git a/src/overlay097/ov97_02237694.c b/src/overlay097/ov97_02237694.c index 6146fb3bf6..9bd3cea343 100644 --- a/src/overlay097/ov97_02237694.c +++ b/src/overlay097/ov97_02237694.c @@ -3,12 +3,13 @@ #include #include +#include "constants/forms.h" +#include "constants/graphics.h" +#include "constants/narc.h" #include "constants/species.h" #include "generated/items.h" #include "overlay097/mystery_gift_app.h" -#include "overlay097/struct_ov97_02237808.h" -#include "overlay097/struct_ov97_02237AEC.h" #include "assert.h" #include "bg_window.h" @@ -41,461 +42,461 @@ #include "text.h" #include "unk_020131EC.h" #include "unk_02033200.h" +#include "versions.h" #include "vram_transfer.h" -typedef struct { - BgConfig *unk_00; - BOOL unk_04; +#define WONDER_CARD_ENCRYPTION_MAGIC 0xD679 + +typedef struct MainMenuUtilManager MainMenuUtilManager; +typedef void (*MainMenuUtilVBlankFuncPtr)(MainMenuUtilManager *utilMan); + +struct MainMenuUtilManager { + BgConfig *bgConfig; + BOOL initialized; int heapID; - int unk_0C; - int unk_10; - int unk_14; + int screenFadeQueuedState; + BOOL fadeToWhite; + int savingStatus; SaveData *saveData; - void *unk_1C; - int unk_20; - BOOL unk_24[4]; - UnkStruct_ov97_02237AEC unk_34; - Sprite *unk_26C; - int unk_270; - fx32 unk_274; - u8 unk_278[3200]; - PokemonSpriteTemplate unk_EF8; - void (*unk_F08)(void *param0); -} UnkStruct_ov97_0223F550; + void *unused_1C; + int unused_20; + BOOL unused_24[4]; + MainMenuSpriteManager spriteManager; + Sprite *mysteryGiftSprite; + int giftSpriteDelay; + fx32 bottomScreenTopY; + u8 monSpriteBuffer[MON_SPRITE_FRAME_MAX_SIZE_BYTES]; + PokemonSpriteTemplate monSpriteTemplate; + MainMenuUtilVBlankFuncPtr onVBlank; +}; -static void ov97_02237E58(void *param0); +static void TransferGraphicsOnVBlank(void *unused); -static UnkStruct_ov97_0223F550 Unk_ov97_0223F550; +static MainMenuUtilManager sMainMenuUtilManager; -void ov97_02237694(int heapID) +void MainMenuUtil_Init(enum HeapId heapID) { - UnkStruct_ov97_0223F550 *v0 = &Unk_ov97_0223F550; + MainMenuUtilManager *utilMan = &sMainMenuUtilManager; - memset(v0, 0, sizeof(UnkStruct_ov97_0223F550)); + memset(utilMan, 0, sizeof(MainMenuUtilManager)); - v0->unk_04 = 1; - v0->heapID = heapID; + utilMan->initialized = TRUE; + utilMan->heapID = heapID; } -void *ov97_022376C4(ApplicationManager *appMan, int heapID, int param2, int param3) +void *MainMenuUtil_InitAppAndFadeToBlack(ApplicationManager *appMan, enum HeapId heapID, int appDataSize, enum HeapSize heapSize) { - void *v0; + void *newAppData; - Heap_Create(HEAP_ID_APPLICATION, heapID, param3); - v0 = ApplicationManager_NewData(appMan, param2, heapID); + Heap_Create(HEAP_ID_APPLICATION, heapID, heapSize); + newAppData = ApplicationManager_NewData(appMan, appDataSize, heapID); - memset(v0, 0, param2); + memset(newAppData, 0, appDataSize); SetScreenColorBrightness(DS_SCREEN_MAIN, FADE_TO_BLACK); SetScreenColorBrightness(DS_SCREEN_SUB, FADE_TO_BLACK); - return v0; + return newAppData; } -void ov97_022376FC(BgConfig *bgConfig, int bgLayer, u8 param2, u32 param3, u32 param4) +void MainMenuUtil_InitBG(BgConfig *bgConfig, enum BgLayer bgLayer, u8 screenSize, u32 screenBase, u32 charBase) { BgTemplate bgTemplate = { - 0, - 0, - 0x800, - 0, - 1, - GX_BG_COLORMODE_16, - GX_BG_SCRBASE_0x0000, - GX_BG_CHARBASE_0x00000, - GX_BG_EXTPLTT_01, - 0, - 0, - 0, - 0 + .x = 0, + .y = 0, + .bufferSize = 0x800, + .baseTile = 0, + .screenSize = BG_SCREEN_SIZE_256x256, + .colorMode = GX_BG_COLORMODE_16, + .screenBase = GX_BG_SCRBASE_0x0000, + .charBase = GX_BG_CHARBASE_0x00000, + .bgExtPltt = GX_BG_EXTPLTT_01, + .priority = 0, + .areaOver = 0, + .dummy = 0, + .mosaic = FALSE }; - bgTemplate.screenSize = param2; + bgTemplate.screenSize = screenSize; - switch (param2) { - case 1: + switch (screenSize) { + case BG_SCREEN_SIZE_256x256: bgTemplate.bufferSize = 0x800; break; - case 2: + case BG_SCREEN_SIZE_256x512: bgTemplate.bufferSize = 0x1000; break; - case 3: + case BG_SCREEN_SIZE_512x256: bgTemplate.bufferSize = 0x1000; break; - case 4: + case BG_SCREEN_SIZE_512x512: bgTemplate.bufferSize = 0x2000; break; } - bgTemplate.screenBase = param3 / 0x800; - bgTemplate.charBase = param4 / 0x4000; + bgTemplate.screenBase = screenBase / 0x800; + bgTemplate.charBase = charBase / 0x4000; - Bg_InitFromTemplate(bgConfig, bgLayer, &bgTemplate, 0); + Bg_InitFromTemplate(bgConfig, bgLayer, &bgTemplate, BG_TYPE_STATIC); Bg_ClearTilemap(bgConfig, bgLayer); } -void ov97_02237784(int param0) +void MainMenuUtil_SetFadeToWhite(BOOL enable) { - UnkStruct_ov97_0223F550 *v0 = &Unk_ov97_0223F550; - v0->unk_10 = param0; + MainMenuUtilManager *utilMan = &sMainMenuUtilManager; + utilMan->fadeToWhite = enable; } -void ov97_02237790(int param0, int param1, int *param2, int param3) +void MainMenuUtil_StartScreenFadeToState(enum FadeType fadeType, int destState, int *state, int waitState) { - UnkStruct_ov97_0223F550 *v0 = &Unk_ov97_0223F550; + MainMenuUtilManager *utilMan = &sMainMenuUtilManager; - if (v0->unk_10 == 0) { - StartScreenFade(FADE_BOTH_SCREENS, param0, param0, 0x0, 6, 1, v0->heapID); + if (utilMan->fadeToWhite == FALSE) { + StartScreenFade(FADE_BOTH_SCREENS, fadeType, fadeType, COLOR_BLACK, 6, 1, utilMan->heapID); } else { - StartScreenFade(FADE_BOTH_SCREENS, param0, param0, 0x7fff, 6, 1, v0->heapID); + StartScreenFade(FADE_BOTH_SCREENS, fadeType, fadeType, COLOR_WHITE, 6, 1, utilMan->heapID); } - if (param2) { - *param2 = param3; + if (state) { + *state = waitState; } - v0->unk_0C = param1; + utilMan->screenFadeQueuedState = destState; } -void ov97_022377F0(int *param0) +void MainMenuUtil_CheckScreenFadeDone(int *state) { - UnkStruct_ov97_0223F550 *v0 = &Unk_ov97_0223F550; + MainMenuUtilManager *utilMan = &sMainMenuUtilManager; if (IsScreenFadeDone()) { - *param0 = v0->unk_0C; + *state = utilMan->screenFadeQueuedState; } } -void ov97_02237808(UnkStruct_ov97_02237808 *param0, Window *param1, int param2, int param3, int param4, int param5) +void MainMenuUtil_InitWindow(MainMenuWindow *mainMenuWindow, Window *window, enum Palette textPalette, enum TextBank textBank, int baseTile, enum Palette framePalette) { - memset(param0, 0, sizeof(UnkStruct_ov97_02237808)); + memset(mainMenuWindow, 0, sizeof(MainMenuWindow)); - param0->unk_04 = 1; - param0->unk_08 = 1; - param0->unk_4C = -1; - param0->unk_10 = param1; - param0->unk_30 = param2; - param0->unk_34 = param3; - param0->unk_38 = param4; - param0->unk_3C = param5; - param0->unk_2C = 0; - param0->unk_40 = 0; - param0->unk_44 = TEXT_COLOR(1, 2, 15); - param0->unk_48 = 15; - param0->unk_00 = 0; - param0->unk_20 = param0->unk_24 = 0; - param0->unk_14 = NULL; - param0->unk_50 = 0xff; + mainMenuWindow->drawFrame = TRUE; + mainMenuWindow->clearBeforePrinting = TRUE; + mainMenuWindow->textEntryID = -1; + mainMenuWindow->window = window; + mainMenuWindow->textPltt = textPalette; + mainMenuWindow->textBank = textBank; + mainMenuWindow->frameBaseTile = baseTile; + mainMenuWindow->framePltt = framePalette; + mainMenuWindow->bgLayer = BG_LAYER_MAIN_0; + mainMenuWindow->font = FONT_SYSTEM; + mainMenuWindow->textColor = TEXT_COLOR(1, 2, 15); + mainMenuWindow->backgroundColorIdx = 15; + mainMenuWindow->scrollable = FALSE; + mainMenuWindow->textXOffset = mainMenuWindow->textYOffset = 0; + mainMenuWindow->strTemplate = NULL; + mainMenuWindow->renderDelay = 0xff; } -void ov97_02237858(UnkStruct_ov97_02237808 *param0, int param1, int param2, int param3) +void MainMenuWindow_SetDimensionsAndBasetile(MainMenuWindow *window, int width, int height, int baseTile) { - param0->unk_18 = param1; - param0->unk_1C = param2; - param0->unk_28 = param3; + window->width = width; + window->height = height; + window->baseTile = baseTile; } -void ov97_02237860(UnkStruct_ov97_02237808 *param0, int param1, int param2) +void MainMenuWindow_SetScrollableAndFont(MainMenuWindow *window, BOOL scrollable, enum Font font) { - param0->unk_00 = param1; - param0->unk_40 = param2; + window->scrollable = scrollable; + window->font = font; } -void ov97_02237868(UnkStruct_ov97_02237808 *param0, int param1, int param2) +void MainMenuWindow_SetTextOffsets(MainMenuWindow *window, int xOffset, int yOffset) { - param0->unk_20 = param1; - param0->unk_24 = param2; + window->textXOffset = xOffset; + window->textYOffset = yOffset; } -static int ov97_02237870(UnkStruct_ov97_02237808 *param0, int param1) +static int MainMenuWindow_PrintText(MainMenuWindow *window, int textEntryID) { - int v0; - Strbuf *v1; - StringTemplate *v2; - MessageLoader *v3; - UnkStruct_ov97_0223F550 *v4 = &Unk_ov97_0223F550; + MainMenuUtilManager *utilMan = &sMainMenuUtilManager; + int printerID; - if ((param1 != -1) && (param0->unk_4C != param1)) { - param0->unk_4C = param1; + if (textEntryID != -1 && window->textEntryID != textEntryID) { + window->textEntryID = textEntryID; - if (param0->unk_08 == 1) { - Window_FillTilemap(param0->unk_10, param0->unk_48); + if (window->clearBeforePrinting == TRUE) { + Window_FillTilemap(window->window, window->backgroundColorIdx); } - if (param0->unk_4C != -1) { - v3 = MessageLoader_Init(MESSAGE_LOADER_NARC_HANDLE, NARC_INDEX_MSGDATA__PL_MSG, param0->unk_34, v4->heapID); + if (window->textEntryID != -1) { + StringTemplate *strTemplate; + MessageLoader *msgLoader = MessageLoader_Init(MESSAGE_LOADER_NARC_HANDLE, NARC_INDEX_MSGDATA__PL_MSG, window->textBank, utilMan->heapID); - if (param0->unk_14 == NULL) { - v2 = StringTemplate_Default(v4->heapID); + if (window->strTemplate == NULL) { + strTemplate = StringTemplate_Default(utilMan->heapID); } else { - v2 = param0->unk_14; + strTemplate = window->strTemplate; } - v1 = MessageUtil_ExpandedStrbuf(v2, v3, param0->unk_4C, v4->heapID); + Strbuf *strBuf = MessageUtil_ExpandedStrbuf(strTemplate, msgLoader, window->textEntryID, utilMan->heapID); - if (param0->unk_0C == 0) { - v0 = Text_AddPrinterWithParamsAndColor(param0->unk_10, param0->unk_40, v1, param0->unk_20, param0->unk_24, param0->unk_50, param0->unk_44, NULL); + if (window->textRightAligned == FALSE) { + printerID = Text_AddPrinterWithParamsAndColor(window->window, window->font, strBuf, window->textXOffset, window->textYOffset, window->renderDelay, window->textColor, NULL); } else { - int v5, v6; + int textWidth = Font_CalcStrbufWidth(window->font, strBuf, Font_GetAttribute(window->font, FONTATTR_LETTER_SPACING)); + int windowWidth = Window_GetWidth(window->window) * 8 - textWidth; + printerID = Text_AddPrinterWithParamsAndColor(window->window, window->font, strBuf, windowWidth, window->textYOffset, window->renderDelay, window->textColor, NULL); - v5 = Font_CalcStrbufWidth(param0->unk_40, v1, Font_GetAttribute(param0->unk_40, 2)); - v6 = Window_GetWidth(param0->unk_10) * 8 - v5; - v0 = Text_AddPrinterWithParamsAndColor(param0->unk_10, param0->unk_40, v1, v6, param0->unk_24, param0->unk_50, param0->unk_44, NULL); - - param0->unk_0C = 0; + window->textRightAligned = FALSE; } - Strbuf_Free(v1); + Strbuf_Free(strBuf); - if (param0->unk_14 == NULL) { - StringTemplate_Free(v2); + if (window->strTemplate == NULL) { + StringTemplate_Free(strTemplate); } - MessageLoader_Free(v3); + MessageLoader_Free(msgLoader); } } - param0->unk_50 = 0xff; - return v0; + window->renderDelay = 0xff; + return printerID; } -int ov97_0223795C(BgConfig *param0, UnkStruct_ov97_02237808 *param1, int param2, int param3, int param4) +int MainMenuUtil_ShowWindowAtPos(BgConfig *param0, MainMenuWindow *window, int xPos, int yPos, int textEntryID) { - int v0; + int printerID; - if (param1->unk_10->bgConfig == NULL) { - Window_Add(param0, param1->unk_10, param1->unk_2C, param2, param3, param1->unk_18, param1->unk_1C, param1->unk_30, param1->unk_28); - v0 = ov97_02237870(param1, param4); + if (window->window->bgConfig == NULL) { + Window_Add(param0, window->window, window->bgLayer, xPos, yPos, window->width, window->height, window->textPltt, window->baseTile); + printerID = MainMenuWindow_PrintText(window, textEntryID); } else { - if (param2 != -1) { - Window_SetXPos(param1->unk_10, param2); + if (xPos != -1) { + Window_SetXPos(window->window, xPos); } - if (param3 != -1) { - Window_SetYPos(param1->unk_10, param3); + if (yPos != -1) { + Window_SetYPos(window->window, yPos); } - v0 = ov97_02237870(param1, param4); + printerID = MainMenuWindow_PrintText(window, textEntryID); } - if (param1->unk_04 == 1) { - if (param1->unk_00 == 0) { - Window_DrawStandardFrame(param1->unk_10, 0, param1->unk_38, param1->unk_3C); + if (window->drawFrame == TRUE) { + if (window->scrollable == FALSE) { + Window_DrawStandardFrame(window->window, FALSE, window->frameBaseTile, window->framePltt); } else { - Window_DrawMessageBoxWithScrollCursor(param1->unk_10, 0, param1->unk_38, param1->unk_3C); + Window_DrawMessageBoxWithScrollCursor(window->window, FALSE, window->frameBaseTile, window->framePltt); } } - return v0; + return printerID; } -int ov97_02237A18(UnkStruct_ov97_02237808 *param0) +int MainMenuWindow_GetSize(MainMenuWindow *window) { - return param0->unk_18 * param0->unk_1C; + return window->width * window->height; } -void ov97_02237A20(void) +void MainMenuUtil_InitCharPlttTransferBuffers(void) { - UnkStruct_ov97_0223F550 *v0 = &Unk_ov97_0223F550; - CharTransferTemplate v1 = { + MainMenuUtilManager *utilMan = &sMainMenuUtilManager; + CharTransferTemplate charTransTemplte = { 40, 4096, 4096, - NULL, + HEAP_ID_SYSTEM, }; - v1.heapID = v0->heapID; + charTransTemplte.heapID = utilMan->heapID; - CharTransfer_InitWithVramModes(&v1, GX_OBJVRAMMODE_CHAR_1D_32K, GX_OBJVRAMMODE_CHAR_1D_32K); - PlttTransfer_Init(30, v0->heapID); + CharTransfer_InitWithVramModes(&charTransTemplte, GX_OBJVRAMMODE_CHAR_1D_32K, GX_OBJVRAMMODE_CHAR_1D_32K); + PlttTransfer_Init(30, utilMan->heapID); CharTransfer_ClearBuffers(); PlttTransfer_Clear(); } -BOOL ov97_02237A60(void) +BOOL MainMenuUtil_CheckSpriteLoaderInit(void) { - UnkStruct_ov97_0223F550 *v0 = &Unk_ov97_0223F550; + MainMenuUtilManager *utilMan = &sMainMenuUtilManager; - return !!v0->unk_34.unk_00; + return !!utilMan->spriteManager.spriteList; } -void ov97_02237A74(void) +void MainMenuUtil_InitSpriteLoader(void) { - int v0; - UnkStruct_ov97_0223F550 *v1 = &Unk_ov97_0223F550; + MainMenuUtilManager *utilMan = &sMainMenuUtilManager; NNS_G2dInitOamManagerModule(); - RenderOam_Init(0, 126, 0, 32, 0, 126, 0, 32, v1->heapID); - v1->unk_34.unk_00 = SpriteList_InitRendering(128, &v1->unk_34.unk_04, v1->heapID); - SetSubScreenViewRect(&v1->unk_34.unk_04, 0, (256 * FX32_ONE)); + RenderOam_Init(0, 126, 0, 32, 0, 126, 0, 32, utilMan->heapID); + utilMan->spriteManager.spriteList = SpriteList_InitRendering(128, &utilMan->spriteManager.renderer, utilMan->heapID); + SetSubScreenViewRect(&utilMan->spriteManager.renderer, 0, 256 * FX32_ONE); - v1->unk_274 = (192 << FX32_SHIFT); + utilMan->bottomScreenTopY = 192 << FX32_SHIFT; - for (v0 = 0; v0 < 6; v0++) { - v1->unk_34.unk_190[v0] = SpriteResourceCollection_New(32, v0, v1->heapID); + for (int i = 0; i < SPRITE_RESOURCE_MAX; i++) { + utilMan->spriteManager.resourceCollections[i] = SpriteResourceCollection_New(32, i, utilMan->heapID); } } -UnkStruct_ov97_02237AEC *ov97_02237AEC(void) +MainMenuSpriteManager *MainMenuUtil_GetSpriteManager(void) { - UnkStruct_ov97_0223F550 *v0 = &Unk_ov97_0223F550; + MainMenuUtilManager *utilMan = &sMainMenuUtilManager; - GF_ASSERT(v0 != NULL); - GF_ASSERT(v0->unk_34.unk_00 != NULL); + GF_ASSERT(utilMan != NULL); + GF_ASSERT(utilMan->spriteManager.spriteList != NULL); - return &v0->unk_34; + return &utilMan->spriteManager; } -void ov97_02237B0C(int param0, int param1, int param2, int param3, int param4, int param5) +void MainMenuUtil_LoadSprite(enum NarcID narcID, int tilesID, int plttID, int cellID, int animID, enum DSScreen screen) { - UnkStruct_ov97_0223F550 *v0 = &Unk_ov97_0223F550; - int v1 = (param5 == 0) ? NNS_G2D_VRAM_TYPE_2DMAIN : NNS_G2D_VRAM_TYPE_2DSUB; - int v2 = 1; + MainMenuUtilManager *utilMan = &sMainMenuUtilManager; + int vramType = screen == DS_SCREEN_MAIN ? NNS_G2D_VRAM_TYPE_2DMAIN : NNS_G2D_VRAM_TYPE_2DSUB; + int compressed = TRUE; - if (param0 == 16) { - v2 = 0; + if (narcID == NARC_INDEX_ITEMTOOL__ITEMDATA__ITEM_ICON) { + compressed = FALSE; } - if (param1 != -1) { - v0->unk_34.unk_1A8[param5][0] = SpriteResourceCollection_AddTiles(v0->unk_34.unk_190[0], param0, param1, v2, param5, v1, v0->heapID); + if (tilesID != -1) { + utilMan->spriteManager.resources[screen][SPRITE_RESOURCE_CHAR] = SpriteResourceCollection_AddTiles(utilMan->spriteManager.resourceCollections[SPRITE_RESOURCE_CHAR], narcID, tilesID, compressed, screen, vramType, utilMan->heapID); } - if (param2 != -1) { - v0->unk_34.unk_1A8[param5][1] = SpriteResourceCollection_AddPalette(v0->unk_34.unk_190[1], param0, param2, 0, param5, v1, 3, v0->heapID); + if (plttID != -1) { + utilMan->spriteManager.resources[screen][SPRITE_RESOURCE_PLTT] = SpriteResourceCollection_AddPalette(utilMan->spriteManager.resourceCollections[SPRITE_RESOURCE_PLTT], narcID, plttID, FALSE, screen, vramType, PLTT_3, utilMan->heapID); } - if (param3 != -1) { - v0->unk_34.unk_1A8[param5][2] = SpriteResourceCollection_Add(v0->unk_34.unk_190[2], param0, param3, v2, param5, 2, v0->heapID); + if (cellID != -1) { + utilMan->spriteManager.resources[screen][SPRITE_RESOURCE_CELL] = SpriteResourceCollection_Add(utilMan->spriteManager.resourceCollections[SPRITE_RESOURCE_CELL], narcID, cellID, compressed, screen, SPRITE_RESOURCE_CELL, utilMan->heapID); } - if (param4 != -1) { - v0->unk_34.unk_1A8[param5][3] = SpriteResourceCollection_Add(v0->unk_34.unk_190[3], param0, param4, v2, param5, 3, v0->heapID); + if (animID != -1) { + utilMan->spriteManager.resources[screen][SPRITE_RESOURCE_ANIM] = SpriteResourceCollection_Add(utilMan->spriteManager.resourceCollections[SPRITE_RESOURCE_ANIM], narcID, animID, compressed, screen, SPRITE_RESOURCE_ANIM, utilMan->heapID); } - SpriteTransfer_RequestChar(v0->unk_34.unk_1A8[param5][0]); - SpriteTransfer_RequestPlttFreeSpace(v0->unk_34.unk_1A8[param5][1]); - SpriteResourcesHeader_Init(&v0->unk_34.unk_1D8[param5], param5, param5, param5, param5, 0xffffffff, 0xffffffff, 0, 0, v0->unk_34.unk_190[0], v0->unk_34.unk_190[1], v0->unk_34.unk_190[2], v0->unk_34.unk_190[3], NULL, NULL); + SpriteTransfer_RequestChar(utilMan->spriteManager.resources[screen][SPRITE_RESOURCE_CHAR]); + SpriteTransfer_RequestPlttFreeSpace(utilMan->spriteManager.resources[screen][SPRITE_RESOURCE_PLTT]); + SpriteResourcesHeader_Init(&utilMan->spriteManager.resourceHeaders[screen], screen, screen, screen, screen, 0xffffffff, 0xffffffff, FALSE, 0, utilMan->spriteManager.resourceCollections[SPRITE_RESOURCE_CHAR], utilMan->spriteManager.resourceCollections[SPRITE_RESOURCE_PLTT], utilMan->spriteManager.resourceCollections[SPRITE_RESOURCE_CELL], utilMan->spriteManager.resourceCollections[SPRITE_RESOURCE_ANIM], NULL, NULL); - if (param5 == 0) { - GXLayers_EngineAToggleLayers(GX_PLANEMASK_OBJ, 1); + if (screen == DS_SCREEN_MAIN) { + GXLayers_EngineAToggleLayers(GX_PLANEMASK_OBJ, TRUE); } else { - GXLayers_EngineBToggleLayers(GX_PLANEMASK_OBJ, 1); + GXLayers_EngineBToggleLayers(GX_PLANEMASK_OBJ, TRUE); } - SetVBlankCallback(ov97_02237E58, NULL); + SetVBlankCallback(TransferGraphicsOnVBlank, NULL); } -void ov97_02237C80(fx32 param0, fx32 param1) +void MainMenuUtil_SetSubScreenViewRect(fx32 x, fx32 y) { - UnkStruct_ov97_0223F550 *v0 = &Unk_ov97_0223F550; + MainMenuUtilManager *utilMan = &sMainMenuUtilManager; - SetSubScreenViewRect(&v0->unk_34.unk_04, param0, param1); - v0->unk_274 = param1; + SetSubScreenViewRect(&utilMan->spriteManager.renderer, x, y); + utilMan->bottomScreenTopY = y; } -void ov97_02237CA0(void) +void MainMenuUtil_UpdateSpritesSkipGift(void) { - ov97_02237CAC(0); + MainMenuUtil_UpdateSprites(FALSE); } -void ov97_02237CAC(int param0) +void MainMenuUtil_UpdateSprites(BOOL skipDrawGift) { - UnkStruct_ov97_0223F550 *v0 = &Unk_ov97_0223F550; + MainMenuUtilManager *utilMan = &sMainMenuUtilManager; - if (v0->unk_26C) { - VecFx32 *v1; + if (utilMan->mysteryGiftSprite) { + VecFx32 *spritePos; - if (v0->unk_270 == 0) { - if ((Sprite_GetDrawFlag(v0->unk_26C) == 0) && (param0 == 0)) { - Sprite_SetDrawFlag(v0->unk_26C, TRUE); + if (utilMan->giftSpriteDelay == 0) { + if (Sprite_GetDrawFlag(utilMan->mysteryGiftSprite) == FALSE && skipDrawGift == FALSE) { + Sprite_SetDrawFlag(utilMan->mysteryGiftSprite, TRUE); } - v1 = (VecFx32 *)Sprite_GetPosition(v0->unk_26C); + spritePos = (VecFx32 *)Sprite_GetPosition(utilMan->mysteryGiftSprite); - if (v1->y < 384 * FX32_ONE) { - v1->y += FX32_ONE * 3; + if (spritePos->y < 384 * FX32_ONE) { + spritePos->y += FX32_ONE * 3; } } else { - v0->unk_270--; + utilMan->giftSpriteDelay--; } } - if (v0->unk_34.unk_00 != NULL) { - SpriteList_Update(v0->unk_34.unk_00); + if (utilMan->spriteManager.spriteList != NULL) { + SpriteList_Update(utilMan->spriteManager.spriteList); } } -Sprite *ov97_02237D14(int param0, Sprite *param1, int param2, int param3, int param4) +Sprite *MainMenuUtil_InitSprite(enum DSScreen screen, Sprite *sprite, int x, int y, int animationIdx) { - UnkStruct_ov97_0223F550 *v0 = &Unk_ov97_0223F550; + MainMenuUtilManager *utilMan = &sMainMenuUtilManager; - if (param1 == NULL) { - AffineSpriteListTemplate v1; + if (sprite == NULL) { + AffineSpriteListTemplate template; - v1.list = v0->unk_34.unk_00; - v1.resourceData = &v0->unk_34.unk_1D8[param0]; - v1.position.z = 0; - v1.affineScale.x = FX32_ONE; - v1.affineScale.y = FX32_ONE; - v1.affineScale.z = FX32_ONE; - v1.affineZRotation = 0; - v1.position.x = FX32_ONE * param2; - v1.position.y = FX32_ONE * param3; - v1.priority = 10; - v1.vramType = (param0 == 0) ? NNS_G2D_VRAM_TYPE_2DMAIN : NNS_G2D_VRAM_TYPE_2DSUB; - v1.heapID = v0->heapID; + template.list = utilMan->spriteManager.spriteList; + template.resourceData = &utilMan->spriteManager.resourceHeaders[screen]; + template.position.z = 0; + template.affineScale.x = FX32_ONE; + template.affineScale.y = FX32_ONE; + template.affineScale.z = FX32_ONE; + template.affineZRotation = 0; + template.position.x = FX32_ONE *x; + template.position.y = FX32_ONE *y; + template.priority = 10; + template.vramType = screen == DS_SCREEN_MAIN ? NNS_G2D_VRAM_TYPE_2DMAIN : NNS_G2D_VRAM_TYPE_2DSUB; + template.heapID = utilMan->heapID; - if (v1.vramType == NNS_G2D_VRAM_TYPE_2DSUB) { - v1.position.y += v0->unk_274; + if (template.vramType == NNS_G2D_VRAM_TYPE_2DSUB) { + template.position.y += utilMan->bottomScreenTopY; } - param1 = SpriteList_AddAffine(&v1); + sprite = SpriteList_AddAffine(&template); } - Sprite_SetAnimateFlag(param1, 1); - Sprite_SetExplicitPriority(param1, 0); - Sprite_SetAnim(param1, param4); - Sprite_SetDrawFlag(param1, TRUE); + Sprite_SetAnimateFlag(sprite, TRUE); + Sprite_SetExplicitPriority(sprite, 0); + Sprite_SetAnim(sprite, animationIdx); + Sprite_SetDrawFlag(sprite, TRUE); - return param1; + return sprite; } -void ov97_02237DA0(void) +void MainMenuUtil_FreeSprites(void) { - UnkStruct_ov97_0223F550 *v0 = &Unk_ov97_0223F550; - UnkStruct_ov97_02237AEC *v1 = &v0->unk_34; - int v2; + MainMenuUtilManager *utilMan = &sMainMenuUtilManager; + MainMenuSpriteManager *spriteMan = &utilMan->spriteManager; - if (v0->unk_26C) { - Sprite_Delete(v0->unk_26C); - v0->unk_26C = NULL; + if (utilMan->mysteryGiftSprite) { + Sprite_Delete(utilMan->mysteryGiftSprite); + utilMan->mysteryGiftSprite = NULL; } - if (v1->unk_1A8[0][0]) { - SpriteTransfer_ResetCharTransfer(v1->unk_1A8[0][0]); + if (spriteMan->resources[DS_SCREEN_MAIN][SPRITE_RESOURCE_CHAR]) { + SpriteTransfer_ResetCharTransfer(spriteMan->resources[DS_SCREEN_MAIN][SPRITE_RESOURCE_CHAR]); } - if (v1->unk_1A8[1][0]) { - SpriteTransfer_ResetCharTransfer(v1->unk_1A8[1][0]); + if (spriteMan->resources[DS_SCREEN_SUB][SPRITE_RESOURCE_CHAR]) { + SpriteTransfer_ResetCharTransfer(spriteMan->resources[DS_SCREEN_SUB][SPRITE_RESOURCE_CHAR]); } - if (v1->unk_1A8[0][1]) { - SpriteTransfer_ResetPlttTransfer(v1->unk_1A8[0][1]); + if (spriteMan->resources[DS_SCREEN_MAIN][SPRITE_RESOURCE_PLTT]) { + SpriteTransfer_ResetPlttTransfer(spriteMan->resources[DS_SCREEN_MAIN][SPRITE_RESOURCE_PLTT]); } - if (v1->unk_1A8[1][1]) { - SpriteTransfer_ResetPlttTransfer(v1->unk_1A8[1][1]); + if (spriteMan->resources[DS_SCREEN_SUB][SPRITE_RESOURCE_PLTT]) { + SpriteTransfer_ResetPlttTransfer(spriteMan->resources[DS_SCREEN_SUB][SPRITE_RESOURCE_PLTT]); } - for (v2 = 0; v2 < 6; v2++) { - SpriteResourceCollection_Delete(v1->unk_190[v2]); - v1->unk_190[v2] = NULL; + for (int i = 0; i < SPRITE_RESOURCE_MAX; i++) { + SpriteResourceCollection_Delete(spriteMan->resourceCollections[i]); + spriteMan->resourceCollections[i] = NULL; } - SpriteList_Delete(v1->unk_00); - v1->unk_00 = NULL; + SpriteList_Delete(spriteMan->spriteList); + spriteMan->spriteList = NULL; RenderOam_Free(); CharTransfer_Free(); @@ -504,305 +505,285 @@ void ov97_02237DA0(void) SetVBlankCallback(NULL, NULL); } -u32 ov97_02237E4C(int param0) +/* + * This function is actually incorrect, since the games check against (1 << version) + * to know whether the mystery gift is valid for the current game. + * This is however only ever used to set the bitmask for the Ranger Manaphy egg, + * and since the wonder card is never saved (only the PGT), it doesn't matter. + */ +u32 MainMenuUtil_CalcMysteryGiftVersionBit(enum Version version) { - return (u32)1 << (param0 - 10); + return 1 << (version - VERSION_DIAMOND); } -static void ov97_02237E58(void *param0) +static void TransferGraphicsOnVBlank(void *unused) { - UnkStruct_ov97_0223F550 *v0 = &Unk_ov97_0223F550; + MainMenuUtilManager *utilMan = &sMainMenuUtilManager; - if (v0->unk_F08) { - v0->unk_F08(v0); - v0->unk_F08 = NULL; + if (utilMan->onVBlank) { + utilMan->onVBlank(utilMan); + utilMan->onVBlank = NULL; } VramTransfer_Process(); RenderOam_Transfer(); - if (v0->unk_00) { - Bg_RunScheduledUpdates(v0->unk_00); + if (utilMan->bgConfig) { + Bg_RunScheduledUpdates(utilMan->bgConfig); } OS_SetIrqCheckFlag(OS_IE_V_BLANK); } -static int ov97_02237EA8(int param0) +static int CalcPlttOffsetForGiftType(enum MysteryGiftType giftType) { - int v0; - struct { - u8 unk_00, unk_01; - } v1[] = { - { 0, 0 }, - { 1, 1 }, - { 2, 1 }, - { 3, 2 }, - { 4, 3 }, - { 5, 2 }, - { 6, 2 }, - { 7, 0 }, - { 8, 5 }, - { 9, 5 }, - { 10, 5 }, - { 11, 4 }, - { 12, 5 }, - { 13, 5 }, + u8 giftType; + u8 paletteOffset; + } giftTypeToPlttOffset[] = { + { MYST_GIFT_NONE, 0 }, + { MYST_GIFT_POKEMON, 1 }, + { MYST_GIFT_EGG, 1 }, + { MYST_GIFT_ITEM, 2 }, + { MYST_GIFT_BATTLE_REG, 3 }, + { MYST_GIFT_DECORATION_GOOD, 2 }, + { MYST_GIFT_COSMETICS, 2 }, + { MYST_GIFT_MANAPHY_EGG, 0 }, + { MYST_GIFT_MEMBER_CARD, 5 }, + { MYST_GIFT_OAKS_LETTER, 5 }, + { MYST_GIFT_AZURE_FLUTE, 5 }, + { MYST_GIFT_POKETCH_APP, 4 }, + { MYST_GIFT_SECRET_KEY, 5 }, + { MYST_GIFT_UNKNOWN, 5 }, { -1 }, }; - for (v0 = 0; v1[v0].unk_00 != -1; v0++) { - if (v1[v0].unk_00 == param0) { - return v1[v0].unk_01; + for (int i = 0; giftTypeToPlttOffset[i].giftType != -1; i++) { + if (giftTypeToPlttOffset[i].giftType == giftType) { + return giftTypeToPlttOffset[i].paletteOffset; } } return 0; } -static void ov97_02237EF8(Sprite *param0, Pokemon *param1, int param2, int param3, u8 *param4, PokemonSpriteTemplate *param5) +static void LoadPokemonSprite(Sprite *sprite, Pokemon *mon, enum Species species, int form, u8 *buffer, PokemonSpriteTemplate *monSpriteTemplate) { - int v0, v1; - u32 v2; - UnkStruct_ov97_0223F550 *v3 = &Unk_ov97_0223F550; + MainMenuUtilManager *utilMan = &sMainMenuUtilManager; - v0 = Pokemon_GetGender(param1); - v1 = Pokemon_IsShiny(param1); + enum Gender monGender = Pokemon_GetGender(mon); + BOOL shiny = Pokemon_IsShiny(mon); - BuildPokemonSpriteTemplate(param5, param2, v0, 2, v1, param3, 0); + BuildPokemonSpriteTemplate(monSpriteTemplate, species, monGender, FACE_FRONT, shiny, form, 0); - v2 = Pokemon_GetValue(param1, MON_DATA_PERSONALITY, NULL); - sub_020136A4(param5->narcID, param5->character, v3->heapID, 0, 0, 10, 10, param4, v2, 0, 2, param2); + u32 personality = Pokemon_GetValue(mon, MON_DATA_PERSONALITY, NULL); + sub_020136A4(monSpriteTemplate->narcID, monSpriteTemplate->character, utilMan->heapID, 0, 0, 10, 10, buffer, personality, 0, 2, species); - DC_FlushRange(param4, 0x20 * 10 * 10); + DC_FlushRange(buffer, MON_SPRITE_FRAME_MAX_SIZE_BYTES); - { - NNSG2dImageProxy *v4 = Sprite_GetImageProxy(param0); - u32 v5 = NNS_G2dGetImageLocation(v4, NNS_G2D_VRAM_TYPE_2DSUB); + NNSG2dImageProxy *imageProxy = Sprite_GetImageProxy(sprite); + u32 imageLocation = NNS_G2dGetImageLocation(imageProxy, NNS_G2D_VRAM_TYPE_2DSUB); - GXS_LoadOBJ(param4, v5 + 1 * (0x20 * 10 * 10), (0x20 * 10 * 10)); - } + GXS_LoadOBJ(buffer, imageLocation + MON_SPRITE_FRAME_MAX_SIZE_BYTES, MON_SPRITE_FRAME_MAX_SIZE_BYTES); + NNSG2dImagePaletteProxy *plttProxy = Sprite_GetPaletteProxy(sprite); + u32 plttLocation = NNS_G2dGetImagePaletteLocation(plttProxy, NNS_G2D_VRAM_TYPE_2DSUB); - { - NNSG2dImagePaletteProxy *v6 = Sprite_GetPaletteProxy(param0); - u32 v7 = NNS_G2dGetImagePaletteLocation(v6, NNS_G2D_VRAM_TYPE_2DSUB); - - Graphics_LoadPalette(param5->narcID, param5->palette, 5, 0x20 * (2 + 1) + v7, 32, v3->heapID); - } + Graphics_LoadPalette(monSpriteTemplate->narcID, monSpriteTemplate->palette, PAL_LOAD_SUB_OBJ, PLTT_OFFSET(3) + plttLocation, PALETTE_SIZE_BYTES, utilMan->heapID); } -static void ov97_02237FB4(UnkStruct_ov97_0223F550 *param0, int param1, WonderCard *param2) +static void LoadGiftBoxSprite(MainMenuUtilManager *utilMan, enum MysteryGiftType giftType, WonderCard *wonderCard) { - ov97_02237B0C(116, 35, 32, 34, 33, 1); - ov97_02237C80((0 * FX32_ONE), (256 * FX32_ONE)); + MainMenuUtil_LoadSprite(NARC_INDEX_GRAPHIC__MYSTERY, 35, 32, 34, 33, DS_SCREEN_SUB); + MainMenuUtil_SetSubScreenViewRect(0 * FX32_ONE, 256 * FX32_ONE); - param0->unk_26C = ov97_02237D14(1, param0->unk_26C, HW_LCD_WIDTH / 2, 0, 0); + utilMan->mysteryGiftSprite = MainMenuUtil_InitSprite(DS_SCREEN_SUB, utilMan->mysteryGiftSprite, HW_LCD_WIDTH / 2, 0, 0); } -static void ov97_02237FF4(UnkStruct_ov97_0223F550 *param0, int param1, WonderCard *param2) +static void LoadSpriteForMonGift(MainMenuUtilManager *param0, enum MysteryGiftType giftType, WonderCard *wonderCard) { - Pokemon *v0; + MainMenuUtil_LoadSprite(NARC_INDEX_DATA__TRADELIST, 10, 0, 11, 12, DS_SCREEN_SUB); + MainMenuUtil_SetSubScreenViewRect(0 * FX32_ONE, 256 * FX32_ONE); - ov97_02237B0C(54, 10, 0, 11, 12, 1); - ov97_02237C80((0 * FX32_ONE), (256 * FX32_ONE)); + param0->mysteryGiftSprite = MainMenuUtil_InitSprite(DS_SCREEN_SUB, param0->mysteryGiftSprite, HW_LCD_WIDTH / 2, 0, 1); + Pokemon *mon = &wonderCard->pgt.data.pokemonGiftData.pokemon; - param0->unk_26C = ov97_02237D14(1, param0->unk_26C, HW_LCD_WIDTH / 2, 0, 1); - v0 = ¶m2->pgt.data.pokemonGiftData.pokemon; - - switch (param1) { - case 1: - case 13: - ov97_02237EF8(param0->unk_26C, v0, Pokemon_GetValue(v0, MON_DATA_SPECIES, 0), Pokemon_GetValue(v0, MON_DATA_FORM, 0), param0->unk_278, ¶m0->unk_EF8); + switch (giftType) { + case MYST_GIFT_POKEMON: + case MYST_GIFT_UNKNOWN: + LoadPokemonSprite(param0->mysteryGiftSprite, mon, Pokemon_GetValue(mon, MON_DATA_SPECIES, NULL), Pokemon_GetValue(mon, MON_DATA_FORM, NULL), param0->monSpriteBuffer, ¶m0->monSpriteTemplate); break; - case 2: - ov97_02237EF8(param0->unk_26C, v0, SPECIES_EGG, 0, param0->unk_278, ¶m0->unk_EF8); + case MYST_GIFT_EGG: + LoadPokemonSprite(param0->mysteryGiftSprite, mon, SPECIES_EGG, EGG_FORM_BASE, param0->monSpriteBuffer, ¶m0->monSpriteTemplate); break; - case 7: - ov97_02237EF8(param0->unk_26C, v0, SPECIES_EGG, 1, param0->unk_278, ¶m0->unk_EF8); + case MYST_GIFT_MANAPHY_EGG: + LoadPokemonSprite(param0->mysteryGiftSprite, mon, SPECIES_EGG, EGG_FORM_MANAPHY, param0->monSpriteBuffer, ¶m0->monSpriteTemplate); break; } } -static void ov97_022380C8(UnkStruct_ov97_0223F550 *param0, int param1, WonderCard *param2) +static void LoadItemSprite(MainMenuUtilManager *utilMan, enum MysteryGiftType giftType, WonderCard *wonderCard) { int item; - switch (param1) { - case 3: - item = param2->pgt.data.itemGiftData.item; + switch (giftType) { + case MYST_GIFT_ITEM: + item = wonderCard->pgt.data.itemGiftData.item; break; - case 8: + case MYST_GIFT_MEMBER_CARD: item = ITEM_MEMBER_CARD; break; - case 9: + case MYST_GIFT_OAKS_LETTER: item = ITEM_OAKS_LETTER; break; - case 10: + case MYST_GIFT_AZURE_FLUTE: item = ITEM_AZURE_FLUTE; break; - case 12: + case MYST_GIFT_SECRET_KEY: item = ITEM_SECRET_KEY; break; } - ov97_02237B0C(16, Item_FileID(item, ITEM_FILE_TYPE_ICON), Item_FileID(item, ITEM_FILE_TYPE_PALETTE), Item_IconNCERFile(), Item_IconNANRFile(), 1); - ov97_02237C80((0 * FX32_ONE), (256 * FX32_ONE)); + MainMenuUtil_LoadSprite(NARC_INDEX_ITEMTOOL__ITEMDATA__ITEM_ICON, Item_FileID(item, ITEM_FILE_TYPE_ICON), Item_FileID(item, ITEM_FILE_TYPE_PALETTE), Item_IconNCERFile(), Item_IconNANRFile(), DS_SCREEN_SUB); + MainMenuUtil_SetSubScreenViewRect(0 * FX32_ONE, 256 * FX32_ONE); - param0->unk_26C = ov97_02237D14(1, param0->unk_26C, HW_LCD_WIDTH / 2, 0, 0); + utilMan->mysteryGiftSprite = MainMenuUtil_InitSprite(DS_SCREEN_SUB, utilMan->mysteryGiftSprite, HW_LCD_WIDTH / 2, 0, 0); } -static void ov97_02238174(void *param0) +static void LoadMysteryGiftPalettes(MainMenuUtilManager *utilMan) { - UnkStruct_ov97_0223F550 *v0 = (UnkStruct_ov97_0223F550 *)param0; - Graphics_LoadPalette(NARC_INDEX_GRAPHIC__MYSTERY, 29, 4, 16 * 2 * 8, 16 * 2 * 6, v0->heapID); + Graphics_LoadPalette(NARC_INDEX_GRAPHIC__MYSTERY, 29, PAL_LOAD_SUB_BG, PLTT_OFFSET(8), 6 * PALETTE_SIZE_BYTES, utilMan->heapID); } -void ov97_02238194(BgConfig *param0, WonderCard *param1) +void MainMenuUtil_LoadGiftSprite(BgConfig *bgConfig, WonderCard *wonderCard) { - int v0, v1; - UnkStruct_ov97_0223F550 *v2 = &Unk_ov97_0223F550; + MainMenuUtilManager *utilMan = &sMainMenuUtilManager; - v1 = param1->pgt.type; - v0 = ov97_02237EA8(v1); + enum MysteryGiftType giftType = wonderCard->pgt.type; + int plttOffset = CalcPlttOffsetForGiftType(giftType); - Graphics_LoadTilesToBgLayer(NARC_INDEX_GRAPHIC__MYSTERY, 30, param0, 5, 0, 10 * 16 * 0x20, 1, v2->heapID); + Graphics_LoadTilesToBgLayer(NARC_INDEX_GRAPHIC__MYSTERY, 30, bgConfig, BG_LAYER_SUB_1, 0, 10 * 16 * 0x20, TRUE, utilMan->heapID); - { - NNSG2dScreenData *v3; - void *v4 = LoadMemberFromNARC(NARC_INDEX_GRAPHIC__MYSTERY, 31, 1, v2->heapID, 1); + NNSG2dScreenData *screenData; + void *nscr = LoadMemberFromNARC(NARC_INDEX_GRAPHIC__MYSTERY, 31, TRUE, utilMan->heapID, TRUE); - NNS_G2dGetUnpackedScreenData(v4, &v3); + NNS_G2dGetUnpackedScreenData(nscr, &screenData); - Bg_LoadTilemapBuffer(param0, 5, v3->rawData, 32 * 24 * 2); - Heap_FreeToHeap(v4); - } + Bg_LoadTilemapBuffer(bgConfig, BG_LAYER_SUB_1, screenData->rawData, 32 * 24 * 2); + Heap_FreeToHeap(nscr); - Bg_ChangeTilemapRectPalette(param0, 5, 0, 0, 32, 24, 8 + v0); - Bg_ScheduleTilemapTransfer(param0, 5); + Bg_ChangeTilemapRectPalette(bgConfig, BG_LAYER_SUB_1, 0, 0, 32, 24, PLTT_8 + plttOffset); + Bg_ScheduleTilemapTransfer(bgConfig, BG_LAYER_SUB_1); - v2->unk_F08 = ov97_02238174; - v2->unk_00 = param0; + utilMan->onVBlank = LoadMysteryGiftPalettes; + utilMan->bgConfig = bgConfig; - switch (v1) { - case 4: - case 5: - case 6: - case 11: - ov97_02237FB4(v2, v1, param1); + switch (giftType) { + case MYST_GIFT_BATTLE_REG: + case MYST_GIFT_DECORATION_GOOD: + case MYST_GIFT_COSMETICS: + case MYST_GIFT_POKETCH_APP: + LoadGiftBoxSprite(utilMan, giftType, wonderCard); break; - case 7: - v2->unk_270 = 120; - case 1: - case 2: - case 13: - ov97_02237FF4(v2, v1, param1); + case MYST_GIFT_MANAPHY_EGG: + utilMan->giftSpriteDelay = 120; + case MYST_GIFT_POKEMON: + case MYST_GIFT_EGG: + case MYST_GIFT_UNKNOWN: + LoadSpriteForMonGift(utilMan, giftType, wonderCard); break; - case 3: - case 8: - case 9: - case 10: - case 12: - ov97_022380C8(v2, v1, param1); + case MYST_GIFT_ITEM: + case MYST_GIFT_MEMBER_CARD: + case MYST_GIFT_OAKS_LETTER: + case MYST_GIFT_AZURE_FLUTE: + case MYST_GIFT_SECRET_KEY: + LoadItemSprite(utilMan, giftType, wonderCard); break; } - Sprite_SetDrawFlag(v2->unk_26C, FALSE); + Sprite_SetDrawFlag(utilMan->mysteryGiftSprite, FALSE); } -void ov97_0223829C(MysteryGiftEventData *param0, WonderCard *param1, int heapID) +void MainMenuUtil_EncryptWonderCard(MysteryGiftEventData *eventData, WonderCard *wonderCard, enum HeapId heapID) { - MATHCRC16Table *v0; - CRYPTORC4Context *v1; - u16 v2[4]; - u16 v3, v4; - int v5; - v0 = Heap_AllocFromHeap(heapID, sizeof(MATHCRC16Table)); - MATH_CRC16InitTable(v0); + MATHCRC16Table *crcTable = Heap_AllocFromHeap(heapID, sizeof(MATHCRC16Table)); + MATH_CRC16InitTable(crcTable); - v3 = MATH_CalcCRC16(v0, ¶m0->header, sizeof(MysteryGiftEventHeader)); - Heap_FreeToHeap(v0); + u16 headerCRC = MATH_CalcCRC16(crcTable, &eventData->header, sizeof(MysteryGiftEventHeader)); + Heap_FreeToHeap(crcTable); - OS_GetMacAddress((u8 *)v2); + u16 key[4]; + OS_GetMacAddress((u8 *)key); - v2[3] = v2[1]; - v2[1] = v3; - v4 = 0xD679; + key[3] = key[1]; + key[1] = headerCRC; + u16 magic = WONDER_CARD_ENCRYPTION_MAGIC; - for (v5 = 0; v5 < 4; v5++) { - v2[v5] = v2[v5] ^ v4; - v4 = v2[v5]; + for (int i = 0; i < 4; i++) { + key[i] = key[i] ^ magic; + magic = key[i]; } - v1 = Heap_AllocFromHeap(heapID, sizeof(CRYPTORC4Context)); + CRYPTORC4Context *cryptoCtx = Heap_AllocFromHeap(heapID, sizeof(CRYPTORC4Context)); - CRYPTO_RC4Init(v1, v2, 8); - CRYPTO_RC4Encrypt(v1, ¶m0->wonderCard, sizeof(WonderCard), param1); + CRYPTO_RC4Init(cryptoCtx, key, sizeof(key)); + CRYPTO_RC4Encrypt(cryptoCtx, &eventData->wonderCard, sizeof(WonderCard), wonderCard); - Heap_FreeToHeap(v1); + Heap_FreeToHeap(cryptoCtx); } -void ov97_02238324(MysteryGiftEventData *param0, WonderCard *param1, int heapID) +void MainMenuUtil_DecryptReceivedWonderCard(MysteryGiftEventData *eventData, WonderCard *wonderCard, enum HeapId heapID) { - MATHCRC16Table *v0; - CRYPTORC4Context *v1; - const WMBssDesc *v2; - u16 v3[4]; - u16 v4, v5; - int v6; + MATHCRC16Table *crcTable = Heap_AllocFromHeap(heapID, sizeof(MATHCRC16Table)); + MATH_CRC16InitTable(crcTable); - v0 = Heap_AllocFromHeap(heapID, sizeof(MATHCRC16Table)); - MATH_CRC16InitTable(v0); + u16 headerCRC = MATH_CalcCRC16(crcTable, &eventData->header, sizeof(MysteryGiftEventHeader)); + Heap_FreeToHeap(crcTable); - v4 = MATH_CalcCRC16(v0, ¶m0->header, sizeof(MysteryGiftEventHeader)); - Heap_FreeToHeap(v0); + u16 key[4]; + const WMBssDesc *bssDesc = sub_02033F3C(0); // Network ID 0 is the sending console + memcpy(key, bssDesc->bssid, WM_SIZE_BSSID); // BSSID = MAC address of the sending console - v2 = sub_02033F3C(0); - memcpy(v3, v2->bssid, WM_SIZE_BSSID); + key[3] = key[1]; + key[1] = headerCRC; + u16 magic = WONDER_CARD_ENCRYPTION_MAGIC; - v3[3] = v3[1]; - v3[1] = v4; - v5 = 0xD679; - - for (v6 = 0; v6 < 4; v6++) { - v3[v6] = v3[v6] ^ v5; - v5 = v3[v6]; + for (int i = 0; i < 4; i++) { + key[i] = key[i] ^ magic; + magic = key[i]; } - v1 = Heap_AllocFromHeap(heapID, sizeof(CRYPTORC4Context)); + CRYPTORC4Context *cryptoCtx = Heap_AllocFromHeap(heapID, sizeof(CRYPTORC4Context)); - CRYPTO_RC4Init(v1, v3, 8); - CRYPTO_RC4Encrypt(v1, ¶m0->wonderCard, sizeof(WonderCard), param1); + CRYPTO_RC4Init(cryptoCtx, key, sizeof(key)); + CRYPTO_RC4Encrypt(cryptoCtx, &eventData->wonderCard, sizeof(WonderCard), wonderCard); - Heap_FreeToHeap(v1); + Heap_FreeToHeap(cryptoCtx); } -void ov97_022383C4(ListMenu *param0, u32 param1, u8 param2) +void MainMenuUtil_ListMenuCursorCB(ListMenu *listMenu, u32 index, u8 onInit) { - switch (param2) { - case 0: + switch (onInit) { + case FALSE: Sound_PlayEffect(SEQ_SE_CONFIRM); break; - case 1: + case TRUE: break; } } -static void ov97_022383DC(void) +static void TerminateOnGBACartRemoved(void) { - if (PAD_DetectFold() == 0) { - if (CTRDG_IsAgbCartridge() == 0) { - CTRDG_TerminateForPulledOut(); - } + if (PAD_DetectFold() == FALSE && CTRDG_IsAgbCartridge() == FALSE) { + CTRDG_TerminateForPulledOut(); } } -void ov97_02238400(BOOL param0) +void MainMenuUtil_ToggleTerminateOnGBACartRemoved(BOOL enable) { - if (param0 == 1) { + if (enable == TRUE) { OS_DisableIrq(); - OS_SetIrqFunction(OS_IE_CARTRIDGE, ov97_022383DC); + OS_SetIrqFunction(OS_IE_CARTRIDGE, TerminateOnGBACartRemoved); OS_EnableIrqMask(OS_IE_CARTRIDGE); OS_EnableIrq(); } else { @@ -810,86 +791,84 @@ void ov97_02238400(BOOL param0) } } -static void ov97_0223843C(void) +static void GBACartRemovedIrqStub(void) { return; } -void ov97_02238440(void) +void MainMenuUtil_UnsetGBACartIRQFunc(void) { OS_DisableIrq(); - OS_SetIrqFunction(OS_IE_CARTRIDGE, ov97_0223843C); + OS_SetIrqFunction(OS_IE_CARTRIDGE, GBACartRemovedIrqStub); OS_EnableIrqMask(OS_IE_CARTRIDGE); OS_EnableIrq(); } -void ov97_0223846C(SaveData *saveData) +void MainMenuUtil_InitSaving(SaveData *saveData) { - UnkStruct_ov97_0223F550 *v0 = &Unk_ov97_0223F550; + MainMenuUtilManager *utilMan = &sMainMenuUtilManager; - v0->saveData = saveData; - v0->unk_14 = 0; + utilMan->saveData = saveData; + utilMan->savingStatus = MAIN_MENU_UTIL_INIT_SAVING; } -int ov97_0223847C(void) +enum SaveResult MainMenuUtil_SaveState(void) { - int v0; - UnkStruct_ov97_0223F550 *v1 = &Unk_ov97_0223F550; + enum SaveResult saveResult; + MainMenuUtilManager *utilMan = &sMainMenuUtilManager; - switch (v1->unk_14) { - case 0: + switch (utilMan->savingStatus) { + case MAIN_MENU_UTIL_INIT_SAVING: ResetLock(RESET_LOCK_SOFT_RESET); - SaveData_SaveStateInit(v1->saveData, 2); - v1->unk_14++; + SaveData_SaveStateInit(utilMan->saveData, 2); + utilMan->savingStatus++; break; - case 1: - v0 = SaveData_SaveStateMain(v1->saveData); + case MAIN_MENU_UTIL_SAVING: + saveResult = SaveData_SaveStateMain(utilMan->saveData); - if (v0 == 3) { - v1->unk_14 = 3; - } else if (v0 == 2) { - v1->unk_14 = 2; - } else if (v0 == 1) { - v1->unk_14 = 4; + if (saveResult == SAVE_RESULT_CORRUPT) { + utilMan->savingStatus = MAIN_MENU_UTIL_SAVE_FAILURE; + } else if (saveResult == SAVE_RESULT_OK) { + utilMan->savingStatus = MAIN_MENU_UTIL_SAVE_SUCCESS; + } else if (saveResult == SAVE_RESULT_PROCEED_FINAL) { + utilMan->savingStatus = MAIN_MENU_UTIL_SAVING_IDLE; } - if ((v0 == 2) || (v0 == 3)) { + if (saveResult == SAVE_RESULT_OK || saveResult == SAVE_RESULT_CORRUPT) { ResetUnlock(RESET_LOCK_SOFT_RESET); } - return v0; + return saveResult; + case MAIN_MENU_UTIL_SAVING_IDLE: break; - case 4: + case MAIN_MENU_UTIL_SAVE_SUCCESS: break; - case 2: - break; - case 3: + case MAIN_MENU_UTIL_SAVE_FAILURE: break; } - return 0; + return SAVE_RESULT_PROCEED; } -void ov97_022384F4(void) +void MainMenuUtil_ContinueSaving(void) { - UnkStruct_ov97_0223F550 *v0 = &Unk_ov97_0223F550; + MainMenuUtilManager *utilMan = &sMainMenuUtilManager; - if (v0->unk_14 == 4) { - v0->unk_14 = 1; + if (utilMan->savingStatus == MAIN_MENU_UTIL_SAVING_IDLE) { + utilMan->savingStatus = MAIN_MENU_UTIL_SAVING; } } -void ov97_0223850C(void) +void MainMenuUtil_CancelSave(void) { - UnkStruct_ov97_0223F550 *v0 = &Unk_ov97_0223F550; + MainMenuUtilManager *utilMan = &sMainMenuUtilManager; - SaveData_SaveStateCancel(v0->saveData); - v0->unk_14 = 3; + SaveData_SaveStateCancel(utilMan->saveData); + utilMan->savingStatus = MAIN_MENU_UTIL_SAVE_FAILURE; ResetUnlock(RESET_LOCK_SOFT_RESET); } -int ov97_02238528(void) +int MainMenuUtil_GetSavingStatus(void) { - UnkStruct_ov97_0223F550 *v0 = &Unk_ov97_0223F550; - return v0->unk_14; + return sMainMenuUtilManager.savingStatus; } diff --git a/src/overlay097/wonder_cards_app.c b/src/overlay097/wonder_cards_app.c index 4a38ae4599..101f135283 100644 --- a/src/overlay097/wonder_cards_app.c +++ b/src/overlay097/wonder_cards_app.c @@ -596,7 +596,7 @@ static StateTransitionListMenuEntryTemplate sConfirmStartWirelessOptions[] = { static ListMenuTemplate sWonderCardsAppListMenuTemplate = { .choices = NULL, - .cursorCallback = ov97_022383C4, + .cursorCallback = MainMenuUtil_ListMenuCursorCB, .printCallback = NULL, .window = NULL, .count = 0, @@ -618,9 +618,9 @@ static ListMenuTemplate sWonderCardsAppListMenuTemplate = { static void LoadWcShareScreenButtonsGraphics(WonderCardsAppData *appData) { ResetAllSprites(appData); - ov97_02237A20(); - ov97_02237A74(); - ov97_02237B0C(NARC_INDEX_GRAPHIC__MYSTERY, 15, 12, 14, 13, 0); + MainMenuUtil_InitCharPlttTransferBuffers(); + MainMenuUtil_InitSpriteLoader(); + MainMenuUtil_LoadSprite(NARC_INDEX_GRAPHIC__MYSTERY, 15, 12, 14, 13, 0); } static void ResetAllSprites(WonderCardsAppData *appData) @@ -648,16 +648,16 @@ static void ResetAllSprites(WonderCardsAppData *appData) } appData->selectedWcSprites[0] = appData->selectedWcSprites[1] = appData->selectedWcSprites[2] = NULL; - ov97_02237DA0(); + MainMenuUtil_FreeSprites(); } static void ShowWcShareButtons(WonderCardsAppData *appData) { appData->shareScreenSelectedBtn = 0; - appData->shareScreenBtnSprites[WC_SHARE_BTN_SEND] = ov97_02237D14(0, appData->shareScreenBtnSprites[WC_SHARE_BTN_SEND], 72, WONDERCARD_HEIGHT, 1); + appData->shareScreenBtnSprites[WC_SHARE_BTN_SEND] = MainMenuUtil_InitSprite(0, appData->shareScreenBtnSprites[WC_SHARE_BTN_SEND], 72, WONDERCARD_HEIGHT, 1); Sprite_SetExplicitPriority(appData->shareScreenBtnSprites[WC_SHARE_BTN_SEND], 2); - appData->shareScreenBtnSprites[WC_SHARE_BTN_CANCEL] = ov97_02237D14(0, appData->shareScreenBtnSprites[WC_SHARE_BTN_CANCEL], 184, WONDERCARD_HEIGHT, 0); + appData->shareScreenBtnSprites[WC_SHARE_BTN_CANCEL] = MainMenuUtil_InitSprite(0, appData->shareScreenBtnSprites[WC_SHARE_BTN_CANCEL], 184, WONDERCARD_HEIGHT, 0); Sprite_SetExplicitPriority(appData->shareScreenBtnSprites[WC_SHARE_BTN_CANCEL], 2); } @@ -1154,13 +1154,13 @@ static void LoadPokemonSpritesForSelectedWc(WonderCardsAppData *appData) int spriteX, i; // forward declarations required to match if (appData->selectedWcSprites[0] == NULL && appData->selectedWcSprites[1] == NULL && appData->selectedWcSprites[2] == NULL) { - if (ov97_02237A60() == TRUE) { + if (MainMenuUtil_CheckSpriteLoaderInit() == TRUE) { ResetAllSprites(appData); } - ov97_02237A20(); - ov97_02237A74(); - ov97_02237B0C(NARC_INDEX_GRAPHIC__MYSTERY, 26, 23, 25, 24, 0); + MainMenuUtil_InitCharPlttTransferBuffers(); + MainMenuUtil_InitSpriteLoader(); + MainMenuUtil_LoadSprite(NARC_INDEX_GRAPHIC__MYSTERY, 26, 23, 25, 24, 0); Graphics_LoadPalette(NARC_INDEX_POKETOOL__ICONGRA__PL_POKE_ICON, PokeIconPalettesFileIndex(), PAL_LOAD_MAIN_OBJ, PLTT_OFFSET(3), 0, appData->heapID); } @@ -1181,7 +1181,7 @@ static void LoadPokemonSpritesForSelectedWc(WonderCardsAppData *appData) NNSG2dCharacterData *charData; - appData->selectedWcSprites[i] = ov97_02237D14(0, appData->selectedWcSprites[i], spriteX, 16, 10 + i); + appData->selectedWcSprites[i] = MainMenuUtil_InitSprite(0, appData->selectedWcSprites[i], spriteX, 16, 10 + i); u8 *ncgrBuffer = Graphics_GetCharData(NARC_INDEX_POKETOOL__ICONGRA__PL_POKE_ICON, PokeIconSpriteIndex(species, FALSE, HEAP_ID_SYSTEM), FALSE, &charData, appData->heapID); DC_FlushRange(charData->pRawData, (4 * 4 * 0x20)); @@ -1208,7 +1208,7 @@ static BOOL WonderCardsApp_Init(ApplicationManager *appMan, int *unused) appData->selectedWondercardSlot = NUM_WONDERCARD_SLOTS - 1; appData->numPlayerConnections = 1; - ov97_02237694(HEAP_ID_WONDER_CARDS_APP); + MainMenuUtil_Init(HEAP_ID_WONDER_CARDS_APP); Heap_Create(HEAP_ID_SYSTEM, HEAP_ID_91, 0x300); return TRUE; @@ -1317,7 +1317,7 @@ static BOOL RunFlipAnimFrame(WonderCardsAppData *appData) static void WonderCardsAppCallbackSaveGame(WonderCardsAppData *appData) { - int stage = ov97_0223847C(); + int stage = MainMenuUtil_SaveState(); if (stage == 2 || stage == 3) { Sound_PlayEffect(SEQ_SE_DP_SAVE); @@ -1339,7 +1339,7 @@ static void UpdateShareCount(WonderCardsAppData *appData) } SaveData_SetChecksum(SAVE_TABLE_ENTRY_MYSTERY_GIFT); - ov97_0223846C(appData->saveData); + MainMenuUtil_InitSaving(appData->saveData); appData->mainCallback = WonderCardsAppCallbackSaveGame; } @@ -1578,21 +1578,21 @@ static int WonderCardsApp_Main(ApplicationManager *appMan, enum WonderCardsAppSt break; case WC_APP_STATE_DISTRIBUTION_UNDERWAY: if (--appData->shouldSendWc == FALSE) { - ov97_0223829C(&appData->mysteryGiftAppData.eventData, &appData->currentWonderCard, appData->heapID); + MainMenuUtil_EncryptWonderCard(&appData->mysteryGiftAppData.eventData, &appData->currentWonderCard, appData->heapID); ov97_0222D1F0((const void *)&appData->currentWonderCard, sizeof(WonderCard)); UpdateShareCount(appData); *state = WC_APP_STATE_START_COMM_SYNC; } break; case WC_APP_STATE_START_COMM_SYNC: - if (ov97_02238528() == 4) { + if (MainMenuUtil_GetSavingStatus() == 4) { CommTiming_StartSync(0x93); *state = WC_APP_STATE_WAIT_FOR_COMM_SYNC; } break; case WC_APP_STATE_WAIT_FOR_COMM_SYNC: if (CountConnectedPlayers(appData) == 0 || CommTiming_IsSyncState(0x93) == TRUE) { - ov97_022384F4(); + MainMenuUtil_ContinueSaving(); ShowWindowFromTemplateIndex(appData, &appData->messageBox, MSG_BOX_DISTRIBUTION_SUCCESSFUL, 640); DestroyWaitDial(appData->waitDial); StopWirelessCommunication(appData, state, WC_APP_STATE_DISTRIBUTION_SUCCESSFUL); @@ -1624,7 +1624,7 @@ static int WonderCardsApp_Main(ApplicationManager *appMan, enum WonderCardsAppSt SpriteList_Update(appData->spriteList); } - ov97_02237CA0(); + MainMenuUtil_UpdateSpritesSkipGift(); if (appData->mainCallback) { appData->mainCallback(appData);