diff --git a/asm/include/overlay_95.inc b/asm/include/overlay_95.inc index 63c6bb6d5f..ceaed27544 100644 --- a/asm/include/overlay_95.inc +++ b/asm/include/overlay_95.inc @@ -168,6 +168,6 @@ .public NNS_GfdDefaultFuncAllocTexVram .public NNS_GfdDefaultFuncAllocPlttVram .public gSystem -.public ov95_021E6D70 -.public ov95_021E6E88 -.public ov95_021E6F0C +.public HatchEggApp_Init +.public HatchEggApp_Main +.public HatchEggApp_Exit diff --git a/asm/include/unk_020910D8.inc b/asm/include/unk_020910D8.inc deleted file mode 100644 index 4869867a16..0000000000 --- a/asm/include/unk_020910D8.inc +++ /dev/null @@ -1,27 +0,0 @@ -#include -#pragma once -.public AllocFromHeapAtEnd -.public FreeToHeap -.public Save_PlayerData_GetProfileAddr -.public Save_PlayerData_GetOptionsAddr -.public UpdatePokedexWithReceivedSpecies -.public MapHeader_GetMapSec -.public FieldSystem_GetSaveData -.public TaskManager_Call -.public CallApplicationAsTask -.public TaskManager_GetFieldSystem -.public TaskManager_GetEnvironment -.public CallTask_LeaveOverworld -.public CallTask_RestoreOverworld -.public sub_0206D328 -.public GetMonData -.public SetMonData -.public NamingScreen_CreateArgs -.public NamingScreen_DeleteArgs -.public MonSetTrainerMemo -.public CallTask_HatchEggInParty -.public sub_02093134 -.public gOverlayTemplate_NamingScreen -.public ov95_021E6D70 -.public ov95_021E6E88 -.public ov95_021E6F0C diff --git a/asm/overlay_95.s b/asm/overlay_95.s index 029ec9e054..96a165761d 100644 --- a/asm/overlay_95.s +++ b/asm/overlay_95.s @@ -2587,8 +2587,8 @@ _021E6D68: .word 0x00000815 _021E6D6C: .word 0x0000FFFF thumb_func_end ov95_021E6B74 - thumb_func_start ov95_021E6D70 -ov95_021E6D70: ; 0x021E6D70 + thumb_func_start HatchEggApp_Init +HatchEggApp_Init: ; 0x021E6D70 push {r4, r5, lr} sub sp, #0xc add r5, r0, #0 @@ -2699,10 +2699,10 @@ ov95_021E6D70: ; 0x021E6D70 pop {r4, r5, pc} .balign 4, 0 _021E6E84: .word ov95_021E5B24 - thumb_func_end ov95_021E6D70 + thumb_func_end HatchEggApp_Init - thumb_func_start ov95_021E6E88 -ov95_021E6E88: ; 0x021E6E88 + thumb_func_start HatchEggApp_Main +HatchEggApp_Main: ; 0x021E6E88 push {r3, r4, r5, lr} add r4, r1, #0 bl OverlayManager_GetData @@ -2768,10 +2768,10 @@ _021E6F04: pop {r3, r4, r5, pc} .balign 4, 0 _021E6F08: .word 0x000001EA - thumb_func_end ov95_021E6E88 + thumb_func_end HatchEggApp_Main - thumb_func_start ov95_021E6F0C -ov95_021E6F0C: ; 0x021E6F0C + thumb_func_start HatchEggApp_Exit +HatchEggApp_Exit: ; 0x021E6F0C push {r3, r4, r5, lr} add r5, r0, #0 bl OverlayManager_GetData @@ -2838,7 +2838,7 @@ ov95_021E6F0C: ; 0x021E6F0C mov r0, #1 pop {r3, r4, r5, pc} .balign 4, 0 - thumb_func_end ov95_021E6F0C + thumb_func_end HatchEggApp_Exit thumb_func_start ov95_021E6FC4 ov95_021E6FC4: ; 0x021E6FC4 diff --git a/asm/unk_020910D8.s b/asm/unk_020910D8.s deleted file mode 100644 index e895697797..0000000000 --- a/asm/unk_020910D8.s +++ /dev/null @@ -1,218 +0,0 @@ -#include "constants/easy_chat.h" -#include "constants/items.h" -#include "constants/maps.h" -#include "constants/moves.h" -#include "constants/pokemon.h" -#include "constants/species.h" - .include "asm/macros.inc" - .include "unk_020910D8.inc" - .include "global.inc" - - .public gOverlayTemplate_NamingScreen - - .text - - thumb_func_start Task_HatchEggInParty -Task_HatchEggInParty: ; 0x020910D8 - push {r3, r4, r5, r6, r7, lr} - sub sp, #0x10 - add r5, r0, #0 - bl TaskManager_GetEnvironment - add r4, r0, #0 - ldr r1, [r4] - cmp r1, #6 - bls _020910EC - b _02091232 -_020910EC: - add r1, r1, r1 - add r1, pc - ldrh r1, [r1, #6] - lsl r1, r1, #0x10 - asr r1, r1, #0x10 - add pc, r1 -_020910F8: ; jump table - .short _02091106 - _020910F8 - 2 ; case 0 - .short _0209111C - _020910F8 - 2 ; case 1 - .short _0209112E - _020910F8 - 2 ; case 2 - .short _0209119A - _020910F8 - 2 ; case 3 - .short _020911FA - _020910F8 - 2 ; case 4 - .short _0209121A - _020910F8 - 2 ; case 5 - .short _02091228 - _020910F8 - 2 ; case 6 -_02091106: - ldr r0, [r4, #0xc] - mov r1, #0xb - bl sub_0206D328 - add r0, r5, #0 - bl CallTask_LeaveOverworld - ldr r0, [r4] - add r0, r0, #1 - str r0, [r4] - b _02091232 -_0209111C: - ldr r1, _02091238 ; =_02106048 - add r0, r5, #0 - add r2, r4, #0 - bl CallApplicationAsTask - ldr r0, [r4] - add r0, r0, #1 - str r0, [r4] - b _02091232 -_0209112E: - add r0, r5, #0 - bl TaskManager_GetFieldSystem - add r6, r0, #0 - ldr r5, [r4, #0xc] - bl FieldSystem_GetSaveData - bl Save_PlayerData_GetProfileAddr - add r7, r0, #0 - ldr r0, [r6, #0x20] - ldr r0, [r0] - bl MapHeader_GetMapSec - str r0, [sp, #8] - mov r0, #0 - str r0, [sp, #0xc] - add r0, r5, #0 - mov r1, #0x4c - add r2, sp, #0xc - bl SetMonData - mov r0, #0xb - str r0, [sp] - ldr r3, [sp, #8] - add r0, r5, #0 - add r1, r7, #0 - mov r2, #6 - bl MonSetTrainerMemo - add r0, r5, #0 - mov r1, #0xb3 - mov r2, #0 - bl SetMonData - add r0, r6, #0 - add r1, r5, #0 - bl sub_02093134 - add r0, r6, #0 - bl FieldSystem_GetSaveData - ldr r1, [r4, #0xc] - bl UpdatePokedexWithReceivedSpecies - ldr r0, [r4, #4] - cmp r0, #1 - bne _02091194 - mov r0, #3 - str r0, [r4] - b _02091232 -_02091194: - mov r0, #5 - str r0, [r4] - b _02091232 -_0209119A: - add r0, r5, #0 - bl TaskManager_GetFieldSystem - add r6, r0, #0 - ldr r0, [r4, #0xc] - mov r1, #MON_DATA_SPECIES - mov r2, #0 - bl GetMonData - add r7, r0, #0 - add r0, r6, #0 - bl FieldSystem_GetSaveData - bl Save_PlayerData_GetOptionsAddr - str r0, [sp] - mov r0, #0 - str r0, [sp, #4] - mov r0, #0xb - mov r1, #1 - add r2, r7, #0 - mov r3, #0xa - bl NamingScreen_CreateArgs - str r0, [r4, #8] - ldr r0, [r4, #0xc] - mov r1, #MON_DATA_GENDER - mov r2, #0 - bl GetMonData - ldr r1, [r4, #8] - mov r2, #0 - str r0, [r1, #0x10] - ldr r0, [r4, #0xc] - mov r1, #MON_DATA_FORM - bl GetMonData - ldr r1, [r4, #8] - str r0, [r1, #8] - ldr r1, _0209123C ; =gOverlayTemplate_NamingScreen - ldr r2, [r4, #8] - add r0, r5, #0 - bl CallApplicationAsTask - ldr r0, [r4] - add r0, r0, #1 - str r0, [r4] - b _02091232 -_020911FA: - ldr r2, [r4, #8] - ldr r0, [r2, #0x14] - cmp r0, #0 - bne _0209120C - ldr r0, [r4, #0xc] - ldr r2, [r2, #0x18] - mov r1, #0x78 - bl SetMonData -_0209120C: - ldr r0, [r4, #8] - bl NamingScreen_DeleteArgs - ldr r0, [r4] - add r0, r0, #1 - str r0, [r4] - b _02091232 -_0209121A: - add r0, r5, #0 - bl CallTask_RestoreOverworld - ldr r0, [r4] - add r0, r0, #1 - str r0, [r4] - b _02091232 -_02091228: - bl FreeToHeap - add sp, #0x10 - mov r0, #1 - pop {r3, r4, r5, r6, r7, pc} -_02091232: - mov r0, #0 - add sp, #0x10 - pop {r3, r4, r5, r6, r7, pc} - .balign 4, 0 -_02091238: .word _02106048 -_0209123C: .word gOverlayTemplate_NamingScreen - thumb_func_end Task_HatchEggInParty - - thumb_func_start CallTask_HatchEggInParty -CallTask_HatchEggInParty: ; 0x02091240 - push {r3, r4, r5, lr} - add r5, r0, #0 - add r4, r1, #0 - mov r0, #0xb - mov r1, #0x1c - bl AllocFromHeapAtEnd - add r2, r0, #0 - add r3, r2, #0 - mov r1, #0x1c - mov r0, #0 -_02091256: - strb r0, [r3] - add r3, r3, #1 - sub r1, r1, #1 - bne _02091256 - add r3, r2, #0 - add r3, #0xc - ldmia r4!, {r0, r1} - stmia r3!, {r0, r1} - ldmia r4!, {r0, r1} - stmia r3!, {r0, r1} - ldr r1, _02091274 ; =Task_HatchEggInParty - add r0, r5, #0 - bl TaskManager_Call - pop {r3, r4, r5, pc} - .balign 4, 0 -_02091274: .word Task_HatchEggInParty - thumb_func_end CallTask_HatchEggInParty - - .rodata - -_02106048: - .word ov95_021E6D70, ov95_021E6E88, ov95_021E6F0C, FS_OVERLAY_ID(OVY_95) diff --git a/include/unk_020910D8.h b/include/hatch_egg_task.h similarity index 72% rename from include/unk_020910D8.h rename to include/hatch_egg_task.h index ce919536be..21d1048a1e 100644 --- a/include/unk_020910D8.h +++ b/include/hatch_egg_task.h @@ -1,5 +1,5 @@ -#ifndef POKEHEARTGOLD_UNK_020910D8_H -#define POKEHEARTGOLD_UNK_020910D8_H +#ifndef POKEHEARTGOLD_HATCH_EGG_TASK_H +#define POKEHEARTGOLD_HATCH_EGG_TASK_H #include "options.h" #include "player_data.h" @@ -15,4 +15,4 @@ typedef struct UnkStruct_02091240 { void CallTask_HatchEggInParty(TaskManager *taskman, UnkStruct_02091240 *a1); -#endif // POKEHEARTGOLD_UNK_020910D8_H +#endif // POKEHEARTGOLD_HATCH_EGG_TASK_H diff --git a/include/overlay_95.h b/include/overlay_95.h new file mode 100644 index 0000000000..2936fea95f --- /dev/null +++ b/include/overlay_95.h @@ -0,0 +1,10 @@ +#ifndef POKEHEARTGOLD_OVERLAY_95_H +#define POKEHEARTGOLD_OVERLAY_95_H + +#include "overlay_manager.h" + +BOOL HatchEggApp_Init(OVY_MANAGER *manager, int *state); +BOOL HatchEggApp_Main(OVY_MANAGER *manager, int *state); +BOOL HatchEggApp_Exit(OVY_MANAGER *manager, int *state); + +#endif diff --git a/main.lsf b/main.lsf index b4132cbd02..bd53fee527 100644 --- a/main.lsf +++ b/main.lsf @@ -295,7 +295,7 @@ Static main Object src/use_item_on_mon.o Object src/mail_misc.o Object src/unk_02091054.o - Object asm/unk_020910D8.o + Object src/hatch_egg_task.o Object asm/unk_02091278.o Object asm/unk_020912AC.o Object src/dex_mon_measures.o diff --git a/src/hatch_egg_task.c b/src/hatch_egg_task.c new file mode 100644 index 0000000000..5a5427143d --- /dev/null +++ b/src/hatch_egg_task.c @@ -0,0 +1,107 @@ +#include "hatch_egg_task.h" + +#include "get_egg.h" +#include "naming_screen.h" +#include "overlay_95.h" +#include "trainer_memo.h" +#include "unk_02055244.h" +#include "unk_020552A4.h" + +typedef enum HatchEggTaskState { + HATCHEGGTASKSTATE_LEAVE_OVERWORLD, + HATCHEGGTASKSTATE_OPEN_HATCH_APP, + HATCHEGGTASKSTATE_UPDATE_MON_INFO, + HATCHEGGTASKSTATE_OPEN_NAMING_SCREEN, + HATCHEGGTASKSTATE_SET_MON_NAME, + HATCHEGGTASKSTATE_LOAD_OVERWORLD, + HATCHEGGTASKSTATE_EXIT, +} HatchEggTaskState; + +typedef struct HatchEggTaskData { + HatchEggTaskState state; + BOOL wantToNameNewMon; + NamingScreenArgs *namingScreenArgs; + UnkStruct_02091240 unkC; +} HatchEggTaskData; + +FS_EXTERN_OVERLAY(OVY_95); +static const OVY_MGR_TEMPLATE sApplication_HatchEgg = { + .init = HatchEggApp_Init, + .exec = HatchEggApp_Main, + .exit = HatchEggApp_Exit, + .ovy_id = FS_OVERLAY_ID(OVY_95), +}; + +static BOOL Task_HatchEggInParty(TaskManager *taskManager) { + HatchEggTaskData *data = TaskManager_GetEnvironment(taskManager); + + switch (data->state) { + case HATCHEGGTASKSTATE_LEAVE_OVERWORLD: + sub_0206D328(data->unkC.mon, HEAP_ID_FIELD); + CallTask_LeaveOverworld(taskManager); + data->state++; + break; + case HATCHEGGTASKSTATE_OPEN_HATCH_APP: + CallApplicationAsTask(taskManager, &sApplication_HatchEgg, data); + data->state++; + break; + case HATCHEGGTASKSTATE_UPDATE_MON_INFO: { + FieldSystem *fieldSystem = TaskManager_GetFieldSystem(taskManager); + Pokemon *pokemon = data->unkC.mon; + PlayerProfile *profile = Save_PlayerData_GetProfileAddr(FieldSystem_GetSaveData(fieldSystem)); + + u32 mapsec = MapHeader_GetMapSec(fieldSystem->location->mapId); + BOOL isEgg = FALSE; + SetMonData(pokemon, MON_DATA_IS_EGG, &isEgg); + MonSetTrainerMemo(pokemon, profile, 6, mapsec, HEAP_ID_FIELD); + SetMonData(pokemon, MON_DATA_SPECIES_NAME, NULL); + sub_02093134(fieldSystem, pokemon); + UpdatePokedexWithReceivedSpecies(FieldSystem_GetSaveData(fieldSystem), data->unkC.mon); + + if (data->wantToNameNewMon == TRUE) { + data->state = HATCHEGGTASKSTATE_OPEN_NAMING_SCREEN; + } else { + data->state = HATCHEGGTASKSTATE_LOAD_OVERWORLD; + } + + break; + } + case HATCHEGGTASKSTATE_OPEN_NAMING_SCREEN: { + FieldSystem *fieldSystem = TaskManager_GetFieldSystem(taskManager); + + u32 species = GetMonData(data->unkC.mon, MON_DATA_SPECIES, NULL); + Options *options = Save_PlayerData_GetOptionsAddr(FieldSystem_GetSaveData(fieldSystem)); + data->namingScreenArgs = NamingScreen_CreateArgs(HEAP_ID_FIELD, NAME_SCREEN_POKEMON, species, POKEMON_NAME_LENGTH, options, NULL); + data->namingScreenArgs->monGender = GetMonData(data->unkC.mon, MON_DATA_GENDER, NULL); + data->namingScreenArgs->monForm = GetMonData(data->unkC.mon, MON_DATA_FORM, NULL); + + CallApplicationAsTask(taskManager, &gOverlayTemplate_NamingScreen, data->namingScreenArgs); + data->state++; + break; + } + case HATCHEGGTASKSTATE_SET_MON_NAME: + if (!data->namingScreenArgs->noInput) { + SetMonData(data->unkC.mon, MON_DATA_NICKNAME_STRING_COMPARE, data->namingScreenArgs->nameInputString); + } + NamingScreen_DeleteArgs(data->namingScreenArgs); + data->state++; + break; + case HATCHEGGTASKSTATE_LOAD_OVERWORLD: + CallTask_RestoreOverworld(taskManager); + data->state++; + break; + case HATCHEGGTASKSTATE_EXIT: + FreeToHeap(data); + return TRUE; + } + + return FALSE; +} + +void CallTask_HatchEggInParty(TaskManager *taskManager, UnkStruct_02091240 *a1) { + HatchEggTaskData *data = AllocFromHeapAtEnd(HEAP_ID_FIELD, sizeof(HatchEggTaskData)); + memset(data, 0, sizeof(HatchEggTaskData)); + data->unkC = *a1; + + TaskManager_Call(taskManager, Task_HatchEggInParty, data); +} diff --git a/src/launch_application.c b/src/launch_application.c index 89fdc1445e..5686032418 100644 --- a/src/launch_application.c +++ b/src/launch_application.c @@ -17,6 +17,7 @@ #include "frontier_data.h" #include "game_stats.h" #include "get_egg.h" +#include "hatch_egg_task.h" #include "launch_application_internal.h" #include "mail_misc.h" #include "naming_screen.h" @@ -83,7 +84,6 @@ #include "unk_020755E8.h" #include "unk_02087A78.h" #include "unk_02088288.h" -#include "unk_020910D8.h" #include "unk_02092BE8.h" #include "unk_02097B78.h"