diff --git a/Makefile b/Makefile index 42f7103..088f23a 100644 --- a/Makefile +++ b/Makefile @@ -26,7 +26,7 @@ INCLUDES := source include #------------------------------------------------------------------------------- # options for code generation #------------------------------------------------------------------------------- -CFLAGS := -g -Wall -O3 -ffunction-sections -fno-exceptions \ +CFLAGS := -g -Wall -O2 -ffunction-sections -fno-exceptions \ $(MACHDEP) CFLAGS += $(INCLUDE) -D__WIIU__ -D__WUT__ diff --git a/source/main.cpp b/source/main.cpp index a4cea3d..8db395f 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -2,6 +2,8 @@ #include #include #include +#include +#include #include #include #include @@ -10,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -34,6 +37,48 @@ #define COLOR_BORDER Color(204, 204, 204, 255) #define COLOR_BORDER_HIGHLIGHTED Color(0x3478e4ff) +void bootWiiUMenu(); + +void StartAppletAndExit() { + DEBUG_FUNCTION_LINE("Wait for applet"); + ProcUIInit(OSSavesDone_ReadyToRelease); + + bool doProcUi = true; + bool launchWiiUMenuOnNextForeground = false; + while (true) { + switch (ProcUIProcessMessages(true)) { + case PROCUI_STATUS_EXITING: { + doProcUi = false; + break; + } + case PROCUI_STATUS_RELEASE_FOREGROUND: { + ProcUIDrawDoneRelease(); + launchWiiUMenuOnNextForeground = true; + break; + } + case PROCUI_STATUS_IN_FOREGROUND: { + if (launchWiiUMenuOnNextForeground) { + bootWiiUMenu(); + launchWiiUMenuOnNextForeground = false; + } + break; + } + case PROCUI_STATUS_IN_BACKGROUND: { + break; + } + default: + break; + } + OSSleepTicks(OSMillisecondsToTicks(1)); + if (!doProcUi) { + break; + } + } + ProcUIShutdown(); + DEBUG_FUNCTION_LINE("Exit to Wii U Menu"); + _Exit(0); +} + enum { BOOT_OPTION_WII_U_MENU, BOOT_OPTION_HOMEBREW_LAUNCHER, @@ -86,6 +131,26 @@ void writeAutobootOption(int32_t autobootOption) { } } +extern "C" int32_t SYSSwitchToBrowser(void *); +extern "C" int32_t SYSSwitchToEShop(void *); +extern "C" int32_t _SYSSwitchTo(uint32_t pfid); + +void loadConsoleAccount(const char *data_uuid) { + nn::act::Initialize(); + for (int32_t i = 0; i < 13; i++) { + char uuid[16]; + auto result = nn::act::GetUuidEx(uuid, i); + if (result.IsSuccess()) { + if (memcmp(uuid, data_uuid, 8) == 0) { + DEBUG_FUNCTION_LINE("Load Console account %d", i); + nn::act::LoadConsoleAccount(i, 0, nullptr, false); + break; + } + } + } + nn::act::Finalize(); +} + bool getQuickBoot() { auto bootCheck = CCRSysCaffeineBootCheck(); if (bootCheck == 0) { @@ -125,12 +190,82 @@ bool getQuickBoot() { return false; } + DEBUG_FUNCTION_LINE("Trying to autoboot for titleId %016llX", info.titleId); + if (info.titleId == 0x0005001010040000L || info.titleId == 0x0005001010040100L || info.titleId == 0x0005001010040200L) { DEBUG_FUNCTION_LINE("Skip quick booting into the Wii U Menu"); return false; } + + if (info.titleId == 0x000500301001220AL || + info.titleId == 0x000500301001210AL || + info.titleId == 0x000500301001200AL) { + DEBUG_FUNCTION_LINE("Launching the browser"); + loadConsoleAccount(data.uuid); + SYSSwitchToBrowser(nullptr); + + StartAppletAndExit(); + + return true; + } + if (info.titleId == 0x000500301001400AL || + info.titleId == 0x000500301001410AL || + info.titleId == 0x000500301001420AL) { + DEBUG_FUNCTION_LINE("Launching the Eshop"); + loadConsoleAccount(data.uuid); + SYSSwitchToEShop(nullptr); + + StartAppletAndExit(); + + return true; + } + if (info.titleId == 0x000500301001800AL || + info.titleId == 0x000500301001810AL || + info.titleId == 0x000500301001820AL) { + DEBUG_FUNCTION_LINE("Launching the Download Management"); + loadConsoleAccount(data.uuid); + _SYSSwitchTo(12); + + StartAppletAndExit(); + + return true; + } + if (info.titleId == 0x000500301001600AL || + info.titleId == 0x000500301001610AL || + info.titleId == 0x000500301001620AL) { + DEBUG_FUNCTION_LINE("Launching Miiverse"); + loadConsoleAccount(data.uuid); + _SYSSwitchTo(9); + + StartAppletAndExit(); + + return true; + } + if (info.titleId == 0x000500301001500AL || + info.titleId == 0x000500301001510AL || + info.titleId == 0x000500301001520AL) { + DEBUG_FUNCTION_LINE("Launching Friendlist"); + loadConsoleAccount(data.uuid); + _SYSSwitchTo(11); + + StartAppletAndExit(); + + return true; + } + if (info.titleId == 0x000500301001300AL || + info.titleId == 0x000500301001310AL || + info.titleId == 0x000500301001320AL) { + DEBUG_FUNCTION_LINE("Launching TVii"); + loadConsoleAccount(data.uuid); + _SYSSwitchTo(3); + + StartAppletAndExit(); + + return true; + } + if (!SYSCheckTitleExists(info.titleId)) { DEBUG_FUNCTION_LINE("Title %016llX doesn't exist", info.titleId); return false; @@ -141,20 +276,7 @@ bool getQuickBoot() { auto err = MCP_GetTitleInfo(handle, info.titleId, &titleInfo); MCP_Close(handle); if (err == 0) { - nn::act::Initialize(); - for (int32_t i = 0; i < 13; i++) { - char uuid[16]; - result = nn::act::GetUuidEx(uuid, i); - if (result.IsSuccess()) { - if (memcmp(uuid, data.uuid, 8) == 0) { - DEBUG_FUNCTION_LINE("Load Console account %d", i); - nn::act::LoadConsoleAccount(i, 0, 0, 0); - break; - } - } - } - nn::act::Finalize(); - + loadConsoleAccount(data.uuid); ACPAssignTitlePatch(&titleInfo); _SYSLaunchTitleWithStdArgsInNoSplash(info.titleId, nullptr); return true;