From 0129039d76ccbe9d0be16df27db98b013ebbdb6a Mon Sep 17 00:00:00 2001 From: suchmememanyskill Date: Thu, 21 Jan 2021 17:59:49 +0100 Subject: [PATCH] Add reboot normally option, hide reboot to rcm on mariko On mariko, rebooting normally will bypass fuses --- source/gfx/menu.c | 20 ++++---------------- source/gfx/menu.h | 3 +-- source/tegraexplorer/mainmenu.c | 21 +++++++++++++++++++-- source/utils/utils.c | 9 ++++++++- source/utils/utils.h | 3 ++- 5 files changed, 34 insertions(+), 22 deletions(-) diff --git a/source/gfx/menu.c b/source/gfx/menu.c index 4514cea..13634a0 100644 --- a/source/gfx/menu.c +++ b/source/gfx/menu.c @@ -41,21 +41,15 @@ void _printEntry(MenuEntry_t entry, u32 maxLen, u8 highlighted, u32 bg){ gfx_putc('\n'); } -void FunctionMenuHandler(MenuEntry_t *entries, int entryCount, menuPaths *paths, u8 options){ - Vector_t ent = vecFromArray(entries, entryCount, sizeof(MenuEntry_t)); - gfx_clearscreen(); - gfx_putc('\n'); - int res = newMenu(&ent, 0, 79, 30, options, entryCount); - if (paths[res] != NULL) - paths[res](); -} - int newMenu(Vector_t* vec, int startIndex, int screenLenX, int screenLenY, u8 options, int entryCount) { vecPDefArray(MenuEntry_t*, entries, vec); u32 selected = startIndex; - while (entries[selected].skip || entries[selected].hide) + while (entries[selected].skip || entries[selected].hide){ selected++; + if (selected >= vec->count) + selected = 0; + } u32 lastIndex = selected; u32 startX = 0, startY = 0; @@ -63,12 +57,6 @@ int newMenu(Vector_t* vec, int startIndex, int screenLenX, int screenLenY, u8 op u32 bgColor = (options & USELIGHTGREY) ? COLOR_DARKGREY : COLOR_DEFAULT; - /* - if (options & ENABLEPAGECOUNT){ - screenLenY -= 2; - startY += 32; - } - */ bool redrawScreen = true; Input_t *input = hidRead(); diff --git a/source/gfx/menu.h b/source/gfx/menu.h index 8133549..a4763c8 100644 --- a/source/gfx/menu.h +++ b/source/gfx/menu.h @@ -44,5 +44,4 @@ typedef struct _menuEntry { #define ARR_LEN(x) (sizeof(x) / sizeof(*x)) -int newMenu(Vector_t* vec, int startIndex, int screenLenX, int screenLenY, u8 options, int entryCount); -void FunctionMenuHandler(MenuEntry_t *entries, int entryCount, menuPaths *paths, u8 options); \ No newline at end of file +int newMenu(Vector_t* vec, int startIndex, int screenLenX, int screenLenY, u8 options, int entryCount); \ No newline at end of file diff --git a/source/tegraexplorer/mainmenu.c b/source/tegraexplorer/mainmenu.c index 6c8f030..0011369 100644 --- a/source/tegraexplorer/mainmenu.c +++ b/source/tegraexplorer/mainmenu.c @@ -16,6 +16,9 @@ #include "../fs/fsutils.h" #include #include "../utils/utils.h" +#include "../config.h" + +extern hekate_config h_cfg; enum { MainExplore = 0, @@ -31,6 +34,7 @@ enum { MainExit, MainPowerOff, MainRebootRCM, + MainRebootNormal, MainRebootHekate, MainRebootAMS }; @@ -49,6 +53,7 @@ MenuEntry_t mainMenuEntries[] = { [MainExit] = {.optionUnion = COLORTORGB(COLOR_WHITE) | SKIPBIT, .name = "\n-- Exit --"}, [MainPowerOff] = {.optionUnion = COLORTORGB(COLOR_VIOLET), .name = "Power off"}, [MainRebootRCM] = {.optionUnion = COLORTORGB(COLOR_VIOLET), .name = "Reboot to RCM"}, + [MainRebootNormal] = {.optionUnion = COLORTORGB(COLOR_VIOLET), .name = "Reboot normally"}, [MainRebootHekate] = {.optionUnion = COLORTORGB(COLOR_VIOLET), .name = "Reboot to bootloader/update.bin"}, [MainRebootAMS] = {.optionUnion = COLORTORGB(COLOR_VIOLET), .name = "Reboot to atmosphere/reboot_payload.bin"} }; @@ -99,7 +104,10 @@ void ViewKeys(){ void ViewCredits(){ gfx_clearscreen(); - gfx_printf("\nTegraexplorer v%d.%d.%d\nBy SuchMemeManySkill\n\nBased on Lockpick_RCM & Hekate, from shchmue & CTCaer", LP_VER_MJ, LP_VER_MN, LP_VER_BF); + gfx_printf("\nTegraexplorer v%d.%d.%d\nBy SuchMemeManySkill\n\nBased on Lockpick_RCM & Hekate, from shchmue & CTCaer\n\n\n", LP_VER_MJ, LP_VER_MN, LP_VER_BF); + + if (hidRead()->r) + gfx_printf("%k\"I'm not even sure if it works\" - meme", COLOR_ORANGE); hidWait(); } @@ -132,9 +140,11 @@ menuPaths mainMenuPaths[] = { [MainRebootRCM] = reboot_rcm, [MainPowerOff] = power_off, [MainViewCredits] = ViewCredits, + [MainRebootNormal] = reboot_normal, }; void EnterMainMenu(){ + int res = 0; while (1){ if (sd_get_card_removed()) sd_unmount(); @@ -152,8 +162,15 @@ void EnterMainMenu(){ // -- Exit -- mainMenuEntries[MainRebootAMS].hide = (!sd_mounted || !FileExists("sd:/atmosphere/reboot_payload.bin")); mainMenuEntries[MainRebootHekate].hide = (!sd_mounted || !FileExists("sd:/bootloader/update.bin")); + mainMenuEntries[MainRebootRCM].hide = h_cfg.t210b01; - FunctionMenuHandler(mainMenuEntries, ARR_LEN(mainMenuEntries), mainMenuPaths, ALWAYSREDRAW); + gfx_clearscreen(); + gfx_putc('\n'); + + Vector_t ent = vecFromArray(mainMenuEntries, ARR_LEN(mainMenuEntries), sizeof(MenuEntry_t)); + res = newMenu(&ent, res, 79, 30, ALWAYSREDRAW, 0); + if (mainMenuPaths[res] != NULL) + mainMenuPaths[res](); } } diff --git a/source/utils/utils.c b/source/utils/utils.c index c0fc2f8..89335af 100644 --- a/source/utils/utils.c +++ b/source/utils/utils.c @@ -9,17 +9,24 @@ #include "../gfx/menu.h" #include "../hid/hid.h" #include "../fs/fsutils.h" +#include "../config.h" + +extern hekate_config h_cfg; extern int launch_payload(char *path); void ALWAYS_INLINE power_off(){ - power_set_state(POWER_OFF); + power_set_state(POWER_OFF_RESET); } void ALWAYS_INLINE reboot_rcm(){ power_set_state(REBOOT_RCM); } +void ALWAYS_INLINE reboot_normal(){ + power_set_state((h_cfg.t210b01) ? REBOOT_BYPASS_FUSES : POWER_OFF_REBOOT); +} + void RebootToPayloadOrRcm(){ if (FileExists("sd:/atmosphere/reboot_payload.bin")) launch_payload("sd:/atmosphere/reboot_payload.bin"); diff --git a/source/utils/utils.h b/source/utils/utils.h index dbf5f58..d62bf72 100644 --- a/source/utils/utils.h +++ b/source/utils/utils.h @@ -11,4 +11,5 @@ void RebootToPayloadOrRcm(); char *ShowKeyboard(const char *toEdit, u8 alwaysRet); void power_off(); -void reboot_rcm(); \ No newline at end of file +void reboot_rcm(); +void reboot_normal(); \ No newline at end of file