2022-08-25 18:39:06 +02:00
|
|
|
#include "BootUtils.h"
|
2022-02-02 19:57:14 +01:00
|
|
|
#include "DrawUtils.h"
|
2022-08-25 18:39:06 +02:00
|
|
|
#include "MenuUtils.h"
|
2022-02-02 19:57:14 +01:00
|
|
|
#include "QuickStartUtils.h"
|
|
|
|
#include "StorageUtils.h"
|
|
|
|
#include "logger.h"
|
|
|
|
#include <coreinit/debug.h>
|
2022-09-04 21:19:54 +02:00
|
|
|
#include <coreinit/filesystem_fsa.h>
|
2022-02-02 19:57:14 +01:00
|
|
|
#include <gx2/state.h>
|
2021-12-28 20:17:21 +01:00
|
|
|
#include <malloc.h>
|
2022-08-25 19:49:00 +02:00
|
|
|
#include <mocha/mocha.h>
|
2023-01-11 10:46:58 +01:00
|
|
|
#include <sndcore2/core.h>
|
2021-12-29 01:26:38 +01:00
|
|
|
#include <string>
|
2022-08-25 18:13:18 +02:00
|
|
|
#include <sys/stat.h>
|
2021-12-28 20:17:21 +01:00
|
|
|
#include <vpad/input.h>
|
2022-01-01 12:09:31 +01:00
|
|
|
|
2022-01-16 01:04:43 +01:00
|
|
|
void clearScreen() {
|
|
|
|
auto buffer = DrawUtils::InitOSScreen();
|
|
|
|
if (!buffer) {
|
|
|
|
OSFatal("Failed to alloc memory for screen");
|
2021-12-28 20:17:21 +01:00
|
|
|
}
|
2022-01-16 01:04:43 +01:00
|
|
|
DrawUtils::clear(COLOR_BACKGROUND);
|
2021-12-28 20:17:21 +01:00
|
|
|
|
2022-01-01 15:48:17 +01:00
|
|
|
// Call GX2Init to shut down OSScreen
|
|
|
|
GX2Init(nullptr);
|
2021-12-30 14:46:42 +01:00
|
|
|
|
2022-01-16 01:04:43 +01:00
|
|
|
free(buffer);
|
2021-12-28 20:17:21 +01:00
|
|
|
}
|
|
|
|
|
2021-12-29 17:02:08 +01:00
|
|
|
int32_t main(int32_t argc, char **argv) {
|
2022-01-16 01:04:43 +01:00
|
|
|
initLogging();
|
|
|
|
DEBUG_FUNCTION_LINE("Hello from Autoboot Module");
|
2023-01-11 10:46:58 +01:00
|
|
|
AXInit();
|
2023-03-31 14:39:15 +02:00
|
|
|
AXQuit();
|
2022-01-16 01:04:43 +01:00
|
|
|
|
|
|
|
// Clear screen to avoid screen corruptions when loading the Wii U Menu
|
|
|
|
clearScreen();
|
2021-12-28 20:17:21 +01:00
|
|
|
|
|
|
|
initExternalStorage();
|
|
|
|
|
|
|
|
if (getQuickBoot()) {
|
2023-03-31 14:39:15 +02:00
|
|
|
|
2022-01-16 01:04:43 +01:00
|
|
|
deinitLogging();
|
2021-12-28 20:17:21 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2022-08-25 19:49:00 +02:00
|
|
|
|
|
|
|
if (Mocha_InitLibrary() != MOCHA_RESULT_SUCCESS) {
|
|
|
|
OSFatal("AutobootModule: Mocha_InitLibrary failed");
|
|
|
|
}
|
|
|
|
|
2023-01-11 10:50:20 +01:00
|
|
|
VPADStatus vpad{};
|
|
|
|
// Buffer vpad read.
|
|
|
|
VPADRead(VPAD_CHAN_0, &vpad, 1, nullptr);
|
|
|
|
|
2022-09-04 21:19:54 +02:00
|
|
|
FSAInit();
|
|
|
|
auto client = FSAAddClient(nullptr);
|
|
|
|
if (client > 0) {
|
|
|
|
if (Mocha_UnlockFSClientEx(client) == MOCHA_RESULT_SUCCESS) {
|
|
|
|
// test if the update folder exists
|
2023-01-05 18:58:45 +01:00
|
|
|
FSADirectoryHandle dirHandle;
|
|
|
|
if (FSAOpenDir(client, "/vol/storage_mlc01/sys/update", &dirHandle) >= 0) {
|
|
|
|
FSACloseDir(client, dirHandle);
|
2022-09-04 21:19:54 +02:00
|
|
|
handleUpdateWarningScreen();
|
|
|
|
}
|
2023-01-11 10:50:29 +01:00
|
|
|
} else {
|
|
|
|
DEBUG_FUNCTION_LINE_ERR("Failed to unlock FSA Client");
|
2022-09-04 21:19:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
FSADelClient(client);
|
2023-01-11 10:50:29 +01:00
|
|
|
} else {
|
|
|
|
DEBUG_FUNCTION_LINE_ERR("Failed to create FSA Client");
|
2022-09-04 21:19:54 +02:00
|
|
|
}
|
|
|
|
|
2022-08-25 18:39:06 +02:00
|
|
|
bool showvHBL = getVWiiHBLTitleId() != 0;
|
2022-08-25 18:13:18 +02:00
|
|
|
bool showHBL = false;
|
2022-03-30 16:35:12 +02:00
|
|
|
std::string configPath = "fs:/vol/external01/wiiu/autoboot.cfg";
|
2021-12-29 01:26:38 +01:00
|
|
|
if (argc >= 1) {
|
|
|
|
configPath = std::string(argv[0]) + "/autoboot.cfg";
|
2022-08-25 18:13:18 +02:00
|
|
|
|
|
|
|
auto hblInstallerPath = std::string(argv[0]) + "/modules/setup/50_hbl_installer.rpx";
|
|
|
|
struct stat st {};
|
|
|
|
if (stat(hblInstallerPath.c_str(), &st) >= 0) {
|
|
|
|
showHBL = true;
|
|
|
|
}
|
2021-12-29 01:26:38 +01:00
|
|
|
}
|
|
|
|
|
2022-01-16 01:04:43 +01:00
|
|
|
int32_t bootSelection = readAutobootOption(configPath);
|
2021-12-28 23:16:34 +01:00
|
|
|
|
2022-08-25 19:54:10 +02:00
|
|
|
std::map<uint32_t, std::string> menu;
|
|
|
|
menu[BOOT_OPTION_WII_U_MENU] = "Wii U Menu";
|
|
|
|
if (showHBL) {
|
|
|
|
menu[BOOT_OPTION_HOMEBREW_LAUNCHER] = "Homebrew Launcher";
|
|
|
|
}
|
|
|
|
menu[BOOT_OPTION_VWII_SYSTEM_MENU] = "vWii System Menu";
|
|
|
|
if (showvHBL) {
|
|
|
|
menu[BOOT_OPTION_VWII_HOMEBREW_CHANNEL] = "vWii Homebrew Channel";
|
|
|
|
}
|
2022-08-25 18:39:06 +02:00
|
|
|
|
|
|
|
if ((bootSelection == -1) ||
|
|
|
|
(bootSelection == BOOT_OPTION_HOMEBREW_LAUNCHER && !showHBL) ||
|
|
|
|
(bootSelection == BOOT_OPTION_VWII_HOMEBREW_CHANNEL && !showvHBL) ||
|
|
|
|
(vpad.hold & VPAD_BUTTON_PLUS)) {
|
2022-08-25 19:54:10 +02:00
|
|
|
bootSelection = handleMenuScreen(configPath, bootSelection, menu);
|
2021-12-28 20:17:21 +01:00
|
|
|
}
|
|
|
|
|
2021-12-28 23:16:34 +01:00
|
|
|
if (bootSelection >= 0) {
|
|
|
|
switch (bootSelection) {
|
2021-12-29 17:02:08 +01:00
|
|
|
case BOOT_OPTION_WII_U_MENU:
|
|
|
|
bootWiiUMenu();
|
|
|
|
break;
|
|
|
|
case BOOT_OPTION_HOMEBREW_LAUNCHER:
|
2022-08-25 18:13:18 +02:00
|
|
|
if (!showHBL) {
|
|
|
|
bootWiiUMenu();
|
|
|
|
break;
|
|
|
|
}
|
2021-12-29 17:02:08 +01:00
|
|
|
bootHomebrewLauncher();
|
|
|
|
break;
|
|
|
|
case BOOT_OPTION_VWII_SYSTEM_MENU:
|
|
|
|
bootvWiiMenu();
|
|
|
|
break;
|
|
|
|
case BOOT_OPTION_VWII_HOMEBREW_CHANNEL:
|
2022-08-25 18:39:06 +02:00
|
|
|
if (!showvHBL) {
|
|
|
|
bootvWiiMenu();
|
|
|
|
break;
|
|
|
|
}
|
2021-12-29 17:02:08 +01:00
|
|
|
bootHomebrewChannel();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
bootWiiUMenu();
|
|
|
|
break;
|
2021-12-28 23:16:34 +01:00
|
|
|
}
|
2021-12-29 17:02:08 +01:00
|
|
|
} else {
|
|
|
|
bootWiiUMenu();
|
2021-12-28 23:16:34 +01:00
|
|
|
}
|
2021-12-28 20:17:21 +01:00
|
|
|
|
2022-09-04 00:08:31 +02:00
|
|
|
Mocha_DeInitLibrary();
|
2023-01-11 10:46:58 +01:00
|
|
|
deinitLogging();
|
|
|
|
|
2021-12-28 20:17:21 +01:00
|
|
|
return 0;
|
|
|
|
}
|