2022-01-16 01:04:43 +01:00
|
|
|
#include "BootUtils.h"
|
2022-07-25 11:52:33 +02:00
|
|
|
#include "ACTAccountInfo.h"
|
2022-01-18 14:17:15 +01:00
|
|
|
#include "DrawUtils.h"
|
|
|
|
#include "MenuUtils.h"
|
2022-02-02 19:57:14 +01:00
|
|
|
#include "logger.h"
|
2022-07-25 11:52:33 +02:00
|
|
|
#include <codecvt>
|
2022-08-25 19:49:00 +02:00
|
|
|
#include <coreinit/filesystem_fsa.h>
|
2022-07-25 11:52:33 +02:00
|
|
|
#include <locale>
|
|
|
|
#include <malloc.h>
|
|
|
|
#include <memory>
|
2022-08-25 19:49:00 +02:00
|
|
|
#include <mocha/mocha.h>
|
2022-01-16 01:04:43 +01:00
|
|
|
#include <nn/act.h>
|
2022-02-02 19:57:14 +01:00
|
|
|
#include <nn/cmpt/cmpt.h>
|
|
|
|
#include <padscore/kpad.h>
|
2022-07-25 11:52:33 +02:00
|
|
|
#include <string>
|
2022-01-16 01:04:43 +01:00
|
|
|
#include <sysapp/launch.h>
|
|
|
|
#include <sysapp/title.h>
|
2022-07-25 11:52:33 +02:00
|
|
|
#include <vector>
|
2022-01-18 14:17:15 +01:00
|
|
|
|
|
|
|
void handleAccountSelection();
|
2022-01-16 01:04:43 +01:00
|
|
|
|
|
|
|
void bootWiiUMenu() {
|
|
|
|
nn::act::Initialize();
|
2022-02-03 14:01:11 +01:00
|
|
|
nn::act::SlotNo slot = nn::act::GetSlotNo();
|
2022-01-16 01:04:43 +01:00
|
|
|
nn::act::SlotNo defaultSlot = nn::act::GetDefaultAccount();
|
|
|
|
nn::act::Finalize();
|
|
|
|
|
2022-02-03 13:03:38 +01:00
|
|
|
if (defaultSlot) { //normal menu boot
|
2022-01-16 01:04:43 +01:00
|
|
|
SYSLaunchMenu();
|
2022-02-03 13:03:38 +01:00
|
|
|
} else { //show mii select
|
2022-01-16 01:04:43 +01:00
|
|
|
_SYSLaunchMenuWithCheckingAccount(slot);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void bootHomebrewLauncher() {
|
2022-01-18 14:17:15 +01:00
|
|
|
handleAccountSelection();
|
|
|
|
|
2022-01-16 01:04:43 +01:00
|
|
|
uint64_t titleId = _SYSGetSystemApplicationTitleId(SYSTEM_APP_ID_MII_MAKER);
|
|
|
|
_SYSLaunchTitleWithStdArgsInNoSplash(titleId, nullptr);
|
|
|
|
}
|
|
|
|
|
2022-01-18 14:17:15 +01:00
|
|
|
void handleAccountSelection() {
|
|
|
|
nn::act::Initialize();
|
|
|
|
nn::act::SlotNo defaultSlot = nn::act::GetDefaultAccount();
|
|
|
|
|
2022-02-03 13:03:38 +01:00
|
|
|
if (!defaultSlot) { // No default account is set.
|
2022-01-18 14:17:15 +01:00
|
|
|
std::vector<std::shared_ptr<AccountInfo>> accountInfoList;
|
|
|
|
for (int32_t i = 0; i < 13; i++) {
|
|
|
|
if (!nn::act::IsSlotOccupied(i)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
char16_t nameOut[nn::act::MiiNameSize];
|
|
|
|
std::shared_ptr<AccountInfo> accountInfo = std::make_shared<AccountInfo>();
|
2022-02-03 14:01:11 +01:00
|
|
|
accountInfo->slot = i;
|
|
|
|
auto result = nn::act::GetMiiNameEx(reinterpret_cast<int16_t *>(nameOut), i);
|
2022-01-18 14:17:15 +01:00
|
|
|
if (result.IsSuccess()) {
|
|
|
|
std::u16string source;
|
|
|
|
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> convert;
|
|
|
|
accountInfo->name = convert.to_bytes((char16_t *) nameOut);
|
|
|
|
} else {
|
|
|
|
accountInfo->name = "[UNKNOWN]";
|
|
|
|
}
|
|
|
|
accountInfo->isNetworkAccount = nn::act::IsNetworkAccountEx(i);
|
|
|
|
if (accountInfo->isNetworkAccount) {
|
|
|
|
nn::act::GetAccountIdEx(accountInfo->accountId, i);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t imageSize = 0;
|
2022-02-03 14:01:11 +01:00
|
|
|
result = nn::act::GetMiiImageEx(&imageSize, accountInfo->miiImageBuffer, sizeof(accountInfo->miiImageBuffer), 0, i);
|
2022-01-18 14:17:15 +01:00
|
|
|
if (result.IsSuccess()) {
|
|
|
|
accountInfo->miiImageSize = imageSize;
|
|
|
|
}
|
|
|
|
accountInfoList.push_back(accountInfo);
|
|
|
|
}
|
|
|
|
|
2022-01-18 16:29:54 +01:00
|
|
|
if (accountInfoList.size() > 0) {
|
|
|
|
auto slot = handleAccountSelectScreen(accountInfoList);
|
|
|
|
|
|
|
|
DEBUG_FUNCTION_LINE("Load slot %d", slot);
|
|
|
|
nn::act::LoadConsoleAccount(slot, 0, nullptr, false);
|
|
|
|
}
|
2022-01-18 14:17:15 +01:00
|
|
|
}
|
|
|
|
nn::act::Finalize();
|
|
|
|
}
|
|
|
|
|
2022-07-25 11:52:33 +02:00
|
|
|
static void launchvWiiTitle(uint64_t titleId) {
|
2022-01-16 01:04:43 +01:00
|
|
|
// we need to init kpad for cmpt
|
|
|
|
KPADInit();
|
|
|
|
|
|
|
|
// Try to find a screen type that works
|
|
|
|
CMPTAcctSetScreenType(CMPT_SCREEN_TYPE_BOTH);
|
|
|
|
if (CMPTCheckScreenState() < 0) {
|
|
|
|
CMPTAcctSetScreenType(CMPT_SCREEN_TYPE_DRC);
|
|
|
|
if (CMPTCheckScreenState() < 0) {
|
|
|
|
CMPTAcctSetScreenType(CMPT_SCREEN_TYPE_TV);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t dataSize = 0;
|
|
|
|
CMPTGetDataSize(&dataSize);
|
|
|
|
|
|
|
|
void *dataBuffer = memalign(0x40, dataSize);
|
|
|
|
|
2022-07-25 11:52:33 +02:00
|
|
|
if (titleId == 0) {
|
2022-01-16 01:04:43 +01:00
|
|
|
CMPTLaunchMenu(dataBuffer, dataSize);
|
|
|
|
} else {
|
2022-07-25 11:52:33 +02:00
|
|
|
CMPTLaunchTitle(dataBuffer, dataSize, titleId);
|
2022-01-16 01:04:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
free(dataBuffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void bootvWiiMenu() {
|
2022-07-25 11:52:33 +02:00
|
|
|
launchvWiiTitle(0);
|
2022-01-16 01:04:43 +01:00
|
|
|
}
|
|
|
|
|
2022-08-25 19:49:00 +02:00
|
|
|
uint64_t getVWiiHBLTitleId() {
|
2022-01-18 16:21:15 +01:00
|
|
|
// fall back to booting the vWii system menu if anything fails
|
|
|
|
uint64_t titleId = 0;
|
|
|
|
|
2022-08-25 19:49:00 +02:00
|
|
|
FSAInit();
|
|
|
|
auto client = FSAAddClient(nullptr);
|
|
|
|
if (client > 0) {
|
|
|
|
if (Mocha_UnlockFSClientEx(client) == MOCHA_RESULT_SUCCESS) {
|
2022-01-18 16:21:15 +01:00
|
|
|
// mount the slccmpt
|
2022-08-25 19:49:00 +02:00
|
|
|
if (FSAMount(client, "/dev/slccmpt01", "/vol/storage_slccmpt01", FSA_MOUNT_FLAG_GLOBAL_MOUNT, nullptr, 0) >= 0) {
|
2022-07-25 11:52:33 +02:00
|
|
|
FSStat stat;
|
2022-01-18 16:21:15 +01:00
|
|
|
|
|
|
|
// test if the OHBC or HBC is installed
|
2022-08-25 19:49:00 +02:00
|
|
|
if (FSAGetStat(client, "/vol/storage_slccmpt01/title/00010001/4f484243/content/00000000.app", &stat) >= 0) {
|
2022-02-03 13:03:38 +01:00
|
|
|
titleId = 0x000100014F484243L; // 'OHBC'
|
2022-08-25 19:49:00 +02:00
|
|
|
} else if (FSAGetStat(client, "/vol/storage_slccmpt01/title/00010001/4c554c5a/content/00000000.app", &stat) >= 0) {
|
2022-02-03 13:03:38 +01:00
|
|
|
titleId = 0x000100014C554C5AL; // 'LULZ'
|
2022-01-18 16:21:15 +01:00
|
|
|
} else {
|
2022-08-25 19:49:00 +02:00
|
|
|
DEBUG_FUNCTION_LINE("Cannot find HBC");
|
2022-01-18 16:21:15 +01:00
|
|
|
}
|
2022-08-25 19:49:00 +02:00
|
|
|
FSAUnmount(client, "/vol/storage_slccmpt01", static_cast<FSAUnmountFlags>(2));
|
2022-01-18 16:21:15 +01:00
|
|
|
} else {
|
2022-08-25 19:49:00 +02:00
|
|
|
DEBUG_FUNCTION_LINE_ERR("Failed to mount slccmpt01");
|
2022-01-18 16:21:15 +01:00
|
|
|
}
|
|
|
|
} else {
|
2022-08-25 19:49:00 +02:00
|
|
|
DEBUG_FUNCTION_LINE_ERR("Failed to unlock FSClient");
|
2022-01-18 16:21:15 +01:00
|
|
|
}
|
2022-08-25 19:49:00 +02:00
|
|
|
FSADelClient(client);
|
2022-01-18 16:21:15 +01:00
|
|
|
} else {
|
2022-08-25 19:49:00 +02:00
|
|
|
DEBUG_FUNCTION_LINE_ERR("Failed to add FSAClient");
|
2022-01-18 16:21:15 +01:00
|
|
|
}
|
2022-08-25 19:49:00 +02:00
|
|
|
DEBUG_FUNCTION_LINE_ERR("%016llX", titleId);
|
|
|
|
return titleId;
|
|
|
|
}
|
2022-01-18 16:21:15 +01:00
|
|
|
|
2022-08-25 19:49:00 +02:00
|
|
|
void bootHomebrewChannel() {
|
|
|
|
uint64_t titleId = getVWiiHBLTitleId();
|
2022-01-18 16:21:15 +01:00
|
|
|
DEBUG_FUNCTION_LINE("Launching vWii title %016llx", titleId);
|
2022-07-25 11:52:33 +02:00
|
|
|
launchvWiiTitle(titleId);
|
2022-01-16 01:04:43 +01:00
|
|
|
}
|