diff --git a/include/menu/MenuFunctions.h b/include/menu/MenuFunctions.h index d68db3d..a353cb4 100755 --- a/include/menu/MenuFunctions.h +++ b/include/menu/MenuFunctions.h @@ -92,6 +92,15 @@ void gen1MoveDeleterApply(void* context, const void* param); * @param param a nullpointer (dummy param) */ void gen2ReceiveGSBall(void* context, const void* param); + +/** + * This function will unlock the Egg Ticket event in a Pokémon Crystal save + * + * @param context a MenuScene* + * @param param a nullpointer (dummy param) + */ +void gen2ReceiveEggTicket(void* context, const void* param); + /** * This function will set a gen II event flag * diff --git a/libpokemegb b/libpokemegb index aedb588..bb3fbd6 160000 --- a/libpokemegb +++ b/libpokemegb @@ -1 +1 @@ -Subproject commit aedb58832c188d3c7ce28da6bc1c453c128ec1be +Subproject commit bb3fbd621b692cee07f978850507b0bf39cc65dc diff --git a/src/menu/MenuFunctions.cpp b/src/menu/MenuFunctions.cpp index 0b23125..e1dc2f4 100755 --- a/src/menu/MenuFunctions.cpp +++ b/src/menu/MenuFunctions.cpp @@ -712,6 +712,39 @@ void gen2ReceiveGSBall(void* context, const void* param) scene->showDialog(messageData); } +void gen2ReceiveEggTicket(void* context, const void* param) +{ + MenuScene* scene = static_cast(context); + TransferPakManager& tpakManager = scene->getDependencies().tpakManager; + TransferPakRomReader romReader(tpakManager); + TransferPakSaveManager saveManager(tpakManager); + const Gen2LocalizationLanguage language = static_cast(scene->getDependencies().localization); + Gen2GameReader gameReader(romReader, saveManager, Gen2GameType::CRYSTAL, language); + + DialogData* messageData = new DialogData{ + .shouldDeleteWhenDone = true + }; + + if(scene->getDependencies().localization != (uint8_t)Gen2LocalizationLanguage::JAPANESE) + { + setDialogDataText(*messageData, "Sorry! This can only be unlocked Japanese version!"); + scene->showDialog(messageData); + return; + } + + tpakManager.setRAMEnabled(true); + + // the unlockEggTicketEvent() function does all the work. + gameReader.unlockEggTicketEvent(); + gameReader.finishSave(); + tpakManager.finishWrites(); + tpakManager.setRAMEnabled(false); + + setDialogDataText(*messageData, "Egg Ticket unlocked! Please go talk to the day-care man on route 34!"); + + scene->showDialog(messageData); +} + void gen2SetEventFlag(void* context, const void* param) { MenuScene* scene = static_cast(context);