From fabb15bbe4cd5ae3ccd8c6c0c19b418c0204e472 Mon Sep 17 00:00:00 2001 From: Pablo Curiel Date: Sat, 19 Feb 2022 06:03:06 +0100 Subject: [PATCH] Fix home button exit on all PoCs. --- code_templates/gc_dumper.c | 34 +++++++++++++++++++------- code_templates/nsp_dumper_stor.c | 10 ++++++-- code_templates/nsp_dumper_usb.c | 10 ++++++-- code_templates/sd_romfs_dumper.c | 28 +++++++++++++++++----- code_templates/system_title_dumper.c | 11 +++++++-- code_templates/usb_romfs_dumper.c | 36 ++++++++++++++++++++++------ code_templates/xml_generator.c | 14 ++++++++--- 7 files changed, 113 insertions(+), 30 deletions(-) diff --git a/code_templates/gc_dumper.c b/code_templates/gc_dumper.c index edd98b8..1877391 100644 --- a/code_templates/gc_dumper.c +++ b/code_templates/gc_dumper.c @@ -75,7 +75,7 @@ static void consolePrint(const char *text, ...); static u32 menuGetElementCount(const Menu *menu); static bool waitForGameCard(void); -static void waitForUsb(void); +static bool waitForUsb(void); static void generateDumpTxt(void); static bool saveDumpTxt(void); @@ -211,6 +211,8 @@ static CondVar g_readCondvar = 0, g_writeCondvar = 0; static char path[FS_MAX_PATH] = {0}, txt_info[FS_MAX_PATH] = {0}; +static bool g_appletStatus = true; + static void utilsScanPads(void) { padUpdate(&g_padState); @@ -295,13 +297,16 @@ int main(int argc, char *argv[]) consoleUpdate(NULL); u64 btn_down = 0, btn_held = 0; - while(!btn_down && !btn_held) + while((g_appletStatus = appletMainLoop())) { utilsScanPads(); btn_down = utilsGetButtonsDown(); btn_held = utilsGetButtonsHeld(); + if (btn_down || btn_held) break; } + if (!g_appletStatus) break; + if (btn_down & HidNpadButton_A) { Menu *child_menu = (Menu*)selected_element->child_menu; @@ -315,10 +320,14 @@ int main(int argc, char *argv[]) if (selected_element->task_func) { /* Wait for gamecard. */ - if (!waitForGameCard()) continue; + if (!waitForGameCard()) + { + if (g_appletStatus) continue; + break; + } /* Wait for USB session. */ - if (g_useUsbHost) waitForUsb(); + if (g_useUsbHost && !waitForUsb()) break; /* Generate dump text. */ generateDumpTxt(); @@ -426,7 +435,14 @@ static bool waitForGameCard(void) consolePrint("waiting for gamecard...\n"); u8 status = GameCardStatus_NotInserted; - while(status <= GameCardStatus_Processing) status = gamecardGetStatus(); + + while((g_appletStatus = appletMainLoop())) + { + status = gamecardGetStatus(); + if (status <= GameCardStatus_Processing) break; + } + + if (!g_appletStatus) return false; switch(status) { @@ -453,16 +469,18 @@ static bool waitForGameCard(void) return true; } -static void waitForUsb(void) +static bool waitForUsb(void) { - if (usbIsReady()) return; + if (usbIsReady()) return true; consolePrint("waiting for usb session...\n"); - while(true) + while((g_appletStatus = appletMainLoop())) { if (usbIsReady()) break; } + + return g_appletStatus; } static void generateDumpTxt(void) diff --git a/code_templates/nsp_dumper_stor.c b/code_templates/nsp_dumper_stor.c index 3db2031..c38959a 100644 --- a/code_templates/nsp_dumper_stor.c +++ b/code_templates/nsp_dumper_stor.c @@ -847,6 +847,8 @@ int main(int argc, char *argv[]) char device_total_fs_size_str[36] = {0}, device_free_fs_size_str[32] = {0}, device_info[0x300] = {0}; bool device_retrieved_size = false, device_retrieved_info = false; + bool applet_status = true; + app_metadata = titleGetApplicationMetadataEntries(false, &app_count); if (!app_metadata || !app_count) { @@ -860,7 +862,7 @@ int main(int argc, char *argv[]) utilsSleep(1); - while(true) + while((applet_status = appletMainLoop())) { consoleClear(); @@ -971,7 +973,7 @@ int main(int argc, char *argv[]) bool data_update = false; u64 btn_down = 0, btn_held = 0; - while(true) + while((applet_status = appletMainLoop())) { utilsScanPads(); btn_down = utilsGetButtonsDown(); @@ -1015,6 +1017,8 @@ int main(int argc, char *argv[]) } } + if (!applet_status) break; + if (data_update) continue; if (btn_down & HidNpadButton_A) @@ -1173,6 +1177,8 @@ int main(int argc, char *argv[]) if (btn_held & (HidNpadButton_StickLDown | HidNpadButton_StickRDown | HidNpadButton_StickLUp | HidNpadButton_StickRUp)) svcSleepThread(50000000); // 50 ms } + if (!applet_status) menu = UINT32_MAX; + out2: if (menu != UINT32_MAX) { diff --git a/code_templates/nsp_dumper_usb.c b/code_templates/nsp_dumper_usb.c index 448e568..6b27923 100644 --- a/code_templates/nsp_dumper_usb.c +++ b/code_templates/nsp_dumper_usb.c @@ -1000,6 +1000,8 @@ int main(int argc, char *argv[]) u32 type_idx = 0, type_scroll = 0; u32 list_count = 0, list_idx = 0; + bool applet_status = true; + app_metadata = titleGetApplicationMetadataEntries(false, &app_count); if (!app_metadata || !app_count) { @@ -1012,7 +1014,7 @@ int main(int argc, char *argv[]) utilsSleep(1); - while(true) + while((applet_status = appletMainLoop())) { consoleClear(); @@ -1086,7 +1088,7 @@ int main(int argc, char *argv[]) bool gc_update = false; u64 btn_down = 0, btn_held = 0; - while(true) + while((applet_status = appletMainLoop())) { utilsScanPads(); btn_down = utilsGetButtonsDown(); @@ -1116,6 +1118,8 @@ int main(int argc, char *argv[]) } } + if (!applet_status) break; + if (gc_update) continue; if (btn_down & HidNpadButton_A) @@ -1246,6 +1250,8 @@ int main(int argc, char *argv[]) if (btn_held & (HidNpadButton_StickLDown | HidNpadButton_StickRDown | HidNpadButton_StickLUp | HidNpadButton_StickRUp)) svcSleepThread(50000000); // 50 ms } + if (!applet_status) menu = UINT32_MAX; + out2: consoleRefresh(); diff --git a/code_templates/sd_romfs_dumper.c b/code_templates/sd_romfs_dumper.c index c350f93..a0af8f5 100644 --- a/code_templates/sd_romfs_dumper.c +++ b/code_templates/sd_romfs_dumper.c @@ -268,6 +268,7 @@ u8 get_program_id_offset(TitleInfo *info, u32 program_count) u8 id_offset = 0; u32 selected_idx = 0, page_size = 30, scroll = 0; char nca_id_str[0x21] = {0}; + bool applet_status = true; NcmContentInfo **content_infos = calloc(program_count, sizeof(NcmContentInfo*)); if (!content_infos) return 0; @@ -278,7 +279,7 @@ u8 get_program_id_offset(TitleInfo *info, u32 program_count) content_infos[j++] = &(info->content_infos[i]); } - while(true) + while((applet_status = appletMainLoop())) { consoleClear(); printf("select a program nca to dump the romfs from.\n\n"); @@ -295,7 +296,7 @@ u8 get_program_id_offset(TitleInfo *info, u32 program_count) consoleUpdate(NULL); u64 btn_down = 0, btn_held = 0; - while(true) + while((applet_status = appletMainLoop())) { utilsScanPads(); btn_down = utilsGetButtonsDown(); @@ -303,6 +304,8 @@ u8 get_program_id_offset(TitleInfo *info, u32 program_count) if (btn_down || btn_held) break; } + if (!applet_status) break; + if (btn_down & HidNpadButton_A) { id_offset = content_infos[selected_idx]->id_offset; @@ -351,7 +354,7 @@ u8 get_program_id_offset(TitleInfo *info, u32 program_count) free(content_infos); - return id_offset; + return (applet_status ? id_offset : (u8)program_count); } int main(int argc, char *argv[]) @@ -377,7 +380,7 @@ int main(int argc, char *argv[]) TitleUserApplicationData user_app_data = {0}; u32 selected_idx = 0, page_size = 30, scroll = 0; - bool exit_prompt = true; + bool applet_status = true, exit_prompt = true; u8 *buf = NULL; @@ -427,7 +430,7 @@ int main(int argc, char *argv[]) utilsSleep(1); - while(true) + while((applet_status = appletMainLoop())) { consoleClear(); printf("select a user application to dump its romfs.\nif an update is available, patch romfs data will be dumped instead.\ndata will be saved to \"sdmc:/romfs\".\npress b to exit.\n\n"); @@ -447,7 +450,7 @@ int main(int argc, char *argv[]) bool gc_update = false; u64 btn_down = 0, btn_held = 0; - while(true) + while((applet_status = appletMainLoop())) { utilsScanPads(); btn_down = utilsGetButtonsDown(); @@ -472,6 +475,8 @@ int main(int argc, char *argv[]) } } + if (!applet_status) break; + if (gc_update) continue; if (btn_down & HidNpadButton_A) @@ -532,6 +537,12 @@ int main(int argc, char *argv[]) if (btn_held & (HidNpadButton_StickLDown | HidNpadButton_StickRDown | HidNpadButton_StickLUp | HidNpadButton_StickRUp)) svcSleepThread(50000000); // 50 ms } + if (!applet_status) + { + exit_prompt = false; + goto out2; + } + u32 program_count = titleGetContentCountByType(user_app_data.app_info, NcmContentType_Program); if (!program_count) { @@ -540,6 +551,11 @@ int main(int argc, char *argv[]) } u8 program_id_offset = get_program_id_offset(user_app_data.app_info, program_count); + if (program_id_offset >= program_count) + { + exit_prompt = false; + goto out2; + } consoleClear(); consolePrint("selected title:\n%s (%016lX)\n\n", app_metadata[selected_idx]->lang_entry.name, app_metadata[selected_idx]->title_id + program_id_offset); diff --git a/code_templates/system_title_dumper.c b/code_templates/system_title_dumper.c index f3231cc..eb08b9b 100644 --- a/code_templates/system_title_dumper.c +++ b/code_templates/system_title_dumper.c @@ -279,6 +279,8 @@ int main(int argc, char *argv[]) NcaContext *nca_ctx = NULL; + bool applet_status = true; + app_metadata = titleGetApplicationMetadataEntries(true, &app_count); if (!app_metadata || !app_count) { @@ -308,7 +310,7 @@ int main(int argc, char *argv[]) utilsSleep(1); - while(true) + while((applet_status = appletMainLoop())) { consoleClear(); @@ -352,13 +354,16 @@ int main(int argc, char *argv[]) consoleUpdate(NULL); u64 btn_down = 0, btn_held = 0; - while(!btn_down && !btn_held) + while((applet_status = appletMainLoop())) { utilsScanPads(); btn_down = utilsGetButtonsDown(); btn_held = utilsGetButtonsHeld(); + if (btn_down || btn_held) break; } + if (!applet_status) break; + if (btn_down & HidNpadButton_A) { bool error = false; @@ -464,6 +469,8 @@ int main(int argc, char *argv[]) if (btn_held & (HidNpadButton_StickLDown | HidNpadButton_StickRDown | HidNpadButton_StickLUp | HidNpadButton_StickRUp)) svcSleepThread(50000000); // 50 ms } + if (!applet_status) menu = UINT32_MAX; + out2: if (menu != UINT32_MAX) { diff --git a/code_templates/usb_romfs_dumper.c b/code_templates/usb_romfs_dumper.c index c9b281a..105fc7a 100644 --- a/code_templates/usb_romfs_dumper.c +++ b/code_templates/usb_romfs_dumper.c @@ -247,6 +247,7 @@ u8 get_program_id_offset(TitleInfo *info, u32 program_count) u8 id_offset = 0; u32 selected_idx = 0, page_size = 30, scroll = 0; char nca_id_str[0x21] = {0}; + bool applet_status = true; NcmContentInfo **content_infos = calloc(program_count, sizeof(NcmContentInfo*)); if (!content_infos) return 0; @@ -257,7 +258,7 @@ u8 get_program_id_offset(TitleInfo *info, u32 program_count) content_infos[j++] = &(info->content_infos[i]); } - while(true) + while((applet_status = appletMainLoop())) { consoleClear(); printf("select a program nca to dump the romfs from.\n\n"); @@ -274,7 +275,7 @@ u8 get_program_id_offset(TitleInfo *info, u32 program_count) consoleUpdate(NULL); u64 btn_down = 0, btn_held = 0; - while(true) + while((applet_status = appletMainLoop())) { utilsScanPads(); btn_down = utilsGetButtonsDown(); @@ -282,6 +283,8 @@ u8 get_program_id_offset(TitleInfo *info, u32 program_count) if (btn_down || btn_held) break; } + if (!applet_status) break; + if (btn_down & HidNpadButton_A) { id_offset = content_infos[selected_idx]->id_offset; @@ -330,7 +333,7 @@ u8 get_program_id_offset(TitleInfo *info, u32 program_count) free(content_infos); - return id_offset; + return (applet_status ? id_offset : (u8)program_count); } int main(int argc, char *argv[]) @@ -356,7 +359,7 @@ int main(int argc, char *argv[]) TitleUserApplicationData user_app_data = {0}; u32 selected_idx = 0, page_size = 30, scroll = 0; - bool exit_prompt = true; + bool applet_status = true, exit_prompt = true; u8 *buf = NULL; @@ -406,7 +409,7 @@ int main(int argc, char *argv[]) utilsSleep(1); - while(true) + while((applet_status = appletMainLoop())) { consoleClear(); printf("select a user application to dump its romfs.\nif an update is available, patch romfs data will be dumped instead.\ndata will be transferred via usb.\npress b to exit.\n\n"); @@ -424,7 +427,7 @@ int main(int argc, char *argv[]) consoleUpdate(NULL); u64 btn_down = 0, btn_held = 0; - while(true) + while((applet_status = appletMainLoop())) { utilsScanPads(); btn_down = utilsGetButtonsDown(); @@ -447,6 +450,8 @@ int main(int argc, char *argv[]) } } + if (!applet_status) break; + if (btn_down & HidNpadButton_A) { if (!titleGetUserApplicationData(app_metadata[selected_idx]->title_id, &user_app_data) || !user_app_data.app_info) @@ -505,6 +510,12 @@ int main(int argc, char *argv[]) if (btn_held & (HidNpadButton_StickLDown | HidNpadButton_StickRDown | HidNpadButton_StickLUp | HidNpadButton_StickRUp)) svcSleepThread(50000000); // 50 ms } + if (!applet_status) + { + exit_prompt = false; + goto out2; + } + u32 program_count = titleGetContentCountByType(user_app_data.app_info, NcmContentType_Program); if (!program_count) { @@ -513,6 +524,11 @@ int main(int argc, char *argv[]) } u8 program_id_offset = get_program_id_offset(user_app_data.app_info, program_count); + if (program_id_offset >= program_count) + { + exit_prompt = false; + goto out2; + } consoleClear(); consolePrint("selected title:\n%s (%016lX)\n\n", app_metadata[selected_idx]->lang_entry.name, app_metadata[selected_idx]->title_id + program_id_offset); @@ -565,7 +581,7 @@ int main(int argc, char *argv[]) time_t start = time(NULL); u8 usb_host_speed = UsbHostSpeed_None; - while(true) + while((applet_status = appletMainLoop())) { time_t now = time(NULL); if ((now - start) >= 10) break; @@ -575,6 +591,12 @@ int main(int argc, char *argv[]) utilsSleep(1); } + if (!applet_status) + { + exit_prompt = false; + goto out2; + } + consolePrint("\n"); if (!usb_host_speed) diff --git a/code_templates/xml_generator.c b/code_templates/xml_generator.c index 99effc9..e9f99c1 100644 --- a/code_templates/xml_generator.c +++ b/code_templates/xml_generator.c @@ -102,7 +102,7 @@ int main(int argc, char *argv[]) TitleUserApplicationData user_app_data = {0}; u32 selected_idx = 0, page_size = 30, scroll = 0; - bool exit_prompt = true; + bool applet_status = true, exit_prompt = true; NcaContext *nca_ctx = NULL; Ticket tik = {0}; @@ -132,7 +132,7 @@ int main(int argc, char *argv[]) utilsSleep(1); - while(true) + while((applet_status = appletMainLoop())) { consoleClear(); printf("select a user application to generate xmls for.\npress b to exit.\n\n"); @@ -150,7 +150,7 @@ int main(int argc, char *argv[]) consoleUpdate(NULL); u64 btn_down = 0, btn_held = 0; - while(true) + while((applet_status = appletMainLoop())) { utilsScanPads(); btn_down = utilsGetButtonsDown(); @@ -173,6 +173,8 @@ int main(int argc, char *argv[]) } } + if (!applet_status) break; + if (btn_down & HidNpadButton_A) { if (!titleGetUserApplicationData(app_metadata[selected_idx]->title_id, &user_app_data) || !user_app_data.app_info) @@ -231,6 +233,12 @@ int main(int argc, char *argv[]) if (btn_held & (HidNpadButton_StickLDown | HidNpadButton_StickRDown | HidNpadButton_StickLUp | HidNpadButton_StickRUp)) svcSleepThread(50000000); // 50 ms } + if (!applet_status) + { + exit_prompt = false; + goto out2; + } + consoleClear(); consolePrint("selected title:\n%s (%016lX)\n\n", app_metadata[selected_idx]->lang_entry.name, app_metadata[selected_idx]->title_id);