2022-01-16 01:04:43 +01:00
|
|
|
#include <malloc.h>
|
|
|
|
|
2022-02-02 19:57:14 +01:00
|
|
|
#include "BootUtils.h"
|
2022-01-16 01:04:43 +01:00
|
|
|
#include "QuickStartUtils.h"
|
|
|
|
#include "logger.h"
|
|
|
|
|
|
|
|
#include <coreinit/exit.h>
|
|
|
|
#include <coreinit/foreground.h>
|
2022-02-02 19:57:14 +01:00
|
|
|
#include <coreinit/memdefaultheap.h>
|
|
|
|
#include <coreinit/thread.h>
|
2022-01-16 01:04:43 +01:00
|
|
|
#include <nn/acp/title.h>
|
|
|
|
#include <nn/act/client_cpp.h>
|
|
|
|
#include <nn/ccr/sys_caffeine.h>
|
|
|
|
#include <nn/sl.h>
|
|
|
|
#include <proc_ui/procui.h>
|
2022-02-02 19:57:14 +01:00
|
|
|
#include <sysapp/launch.h>
|
|
|
|
#include <sysapp/title.h>
|
2022-01-16 01:04:43 +01:00
|
|
|
|
|
|
|
extern "C" void __fini_wut();
|
|
|
|
|
|
|
|
static void StartAppletAndExit() {
|
|
|
|
DEBUG_FUNCTION_LINE("Wait for applet");
|
|
|
|
ProcUIInit(OSSavesDone_ReadyToRelease);
|
|
|
|
|
2022-02-03 14:01:11 +01:00
|
|
|
bool doProcUi = true;
|
2022-01-16 01:04:43 +01:00
|
|
|
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");
|
|
|
|
|
|
|
|
deinitLogging();
|
|
|
|
__fini_wut();
|
|
|
|
_Exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
|
|
|
nn::sl::Initialize(MEMAllocFromDefaultHeapEx, MEMFreeToDefaultHeap);
|
|
|
|
char path[0x80];
|
2022-02-03 13:03:38 +01:00
|
|
|
nn::sl::GetDefaultDatabasePath(path, 0x80, 0x0005001010066000); // ECO process
|
2022-01-16 01:04:43 +01:00
|
|
|
FSCmdBlock cmdBlock;
|
|
|
|
FSInitCmdBlock(&cmdBlock);
|
|
|
|
|
|
|
|
auto fileStream = new nn::sl::FileStream;
|
2022-02-03 14:01:11 +01:00
|
|
|
auto *fsClient = (FSClient *) memalign(0x40, sizeof(FSClient));
|
2022-02-04 21:42:53 +01:00
|
|
|
if (!fsClient) {
|
|
|
|
DEBUG_FUNCTION_LINE("Couldn't alloc memory for fsClient.");
|
|
|
|
return false;
|
|
|
|
}
|
2022-01-16 01:04:43 +01:00
|
|
|
memset(fsClient, 0, sizeof(*fsClient));
|
|
|
|
FSAddClient(fsClient, FS_ERROR_FLAG_NONE);
|
|
|
|
|
|
|
|
fileStream->Initialize(fsClient, &cmdBlock, path, "r");
|
|
|
|
|
|
|
|
auto database = new nn::sl::LaunchInfoDatabase;
|
|
|
|
database->Load(fileStream, nn::sl::REGION_EUR);
|
|
|
|
|
2022-02-03 13:03:38 +01:00
|
|
|
CCRAppLaunchParam data; // load sys caffeine data
|
2022-01-16 01:04:43 +01:00
|
|
|
// load app launch param
|
|
|
|
CCRSysCaffeineGetAppLaunchParam(&data);
|
|
|
|
|
|
|
|
// get launch info for id
|
|
|
|
nn::sl::LaunchInfo info;
|
|
|
|
auto result = database->GetLaunchInfoById(&info, data.titleId);
|
|
|
|
|
|
|
|
delete database;
|
|
|
|
delete fileStream;
|
|
|
|
|
|
|
|
FSDelClient(fsClient, FS_ERROR_FLAG_NONE);
|
2022-02-04 21:42:53 +01:00
|
|
|
free(fsClient);
|
2022-01-16 01:04:43 +01:00
|
|
|
|
|
|
|
nn::sl::Finalize();
|
|
|
|
|
|
|
|
if (!result.IsSuccess()) {
|
|
|
|
DEBUG_FUNCTION_LINE("GetLaunchInfoById failed.");
|
|
|
|
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 starting 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);
|
2022-07-25 11:52:33 +02:00
|
|
|
_SYSSwitchTo(SYSAPP_PFID_DOWNLOAD_MANAGEMENT);
|
2022-01-16 01:04:43 +01:00
|
|
|
|
|
|
|
StartAppletAndExit();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (info.titleId == 0x000500301001600AL ||
|
|
|
|
info.titleId == 0x000500301001610AL ||
|
|
|
|
info.titleId == 0x000500301001620AL) {
|
|
|
|
DEBUG_FUNCTION_LINE("Launching Miiverse");
|
|
|
|
loadConsoleAccount(data.uuid);
|
2022-07-25 11:52:33 +02:00
|
|
|
_SYSSwitchTo(SYSAPP_PFID_MIIVERSE);
|
2022-01-16 01:04:43 +01:00
|
|
|
|
|
|
|
StartAppletAndExit();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (info.titleId == 0x000500301001500AL ||
|
|
|
|
info.titleId == 0x000500301001510AL ||
|
|
|
|
info.titleId == 0x000500301001520AL) {
|
|
|
|
DEBUG_FUNCTION_LINE("Launching Friendlist");
|
|
|
|
loadConsoleAccount(data.uuid);
|
2022-07-25 11:52:33 +02:00
|
|
|
_SYSSwitchTo(SYSAPP_PFID_FRIENDLIST);
|
2022-01-16 01:04:43 +01:00
|
|
|
|
|
|
|
StartAppletAndExit();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (info.titleId == 0x000500301001300AL ||
|
|
|
|
info.titleId == 0x000500301001310AL ||
|
|
|
|
info.titleId == 0x000500301001320AL) {
|
|
|
|
DEBUG_FUNCTION_LINE("Launching TVii");
|
|
|
|
loadConsoleAccount(data.uuid);
|
2022-07-25 11:52:33 +02:00
|
|
|
_SYSSwitchTo(SYSAPP_PFID_TVII);
|
2022-01-16 01:04:43 +01:00
|
|
|
|
|
|
|
StartAppletAndExit();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-02-03 13:03:38 +01:00
|
|
|
if (info.titleId == 0x0005001010004000L) { // OSv0
|
2022-01-18 16:19:04 +01:00
|
|
|
DEBUG_FUNCTION_LINE("Launching vWii System Menu");
|
|
|
|
bootvWiiMenu();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-01-16 01:04:43 +01:00
|
|
|
if (!SYSCheckTitleExists(info.titleId)) {
|
|
|
|
DEBUG_FUNCTION_LINE("Title %016llX doesn't exist", info.titleId);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
MCPTitleListType titleInfo;
|
|
|
|
int32_t handle = MCP_Open();
|
2022-02-03 14:01:11 +01:00
|
|
|
auto err = MCP_GetTitleInfo(handle, info.titleId, &titleInfo);
|
2022-01-16 01:04:43 +01:00
|
|
|
MCP_Close(handle);
|
|
|
|
if (err == 0) {
|
|
|
|
loadConsoleAccount(data.uuid);
|
|
|
|
ACPAssignTitlePatch(&titleInfo);
|
|
|
|
_SYSLaunchTitleWithStdArgsInNoSplash(info.titleId, nullptr);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
DEBUG_FUNCTION_LINE("No quick start");
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|