From 7d63690a44bfce3a2349aa928be7d8ca86d06cf2 Mon Sep 17 00:00:00 2001 From: duckymomo360 Date: Wed, 30 Mar 2022 01:14:17 -0700 Subject: [PATCH] Add vWii DRC Enabled Option This adds an option to disable the DRC (gamepad) when booting into vWii. --- source/BootUtils.cpp | 17 +++++++++------ source/BootUtils.h | 4 ++-- source/MenuUtils.cpp | 44 ++++++++++++++++++++++++++++++++++++-- source/MenuUtils.h | 6 +++++- source/QuickStartUtils.cpp | 2 +- source/main.cpp | 8 ++++--- 6 files changed, 66 insertions(+), 15 deletions(-) diff --git a/source/BootUtils.cpp b/source/BootUtils.cpp index 2e985a2..b1121bb 100644 --- a/source/BootUtils.cpp +++ b/source/BootUtils.cpp @@ -90,12 +90,17 @@ void handleAccountSelection() { nn::act::Finalize(); } -static void launchvWiiTitle(uint32_t titleId_low, uint32_t titleId_high) { +static void launchvWiiTitle(uint32_t titleId_low, uint32_t titleId_high, bool drcEnabled) { // we need to init kpad for cmpt KPADInit(); // Try to find a screen type that works - CMPTAcctSetScreenType(CMPT_SCREEN_TYPE_BOTH); + if (drcEnabled) { + CMPTAcctSetScreenType(CMPT_SCREEN_TYPE_BOTH); + } else { + CMPTAcctSetScreenType(CMPT_SCREEN_TYPE_TV); + } + if (CMPTCheckScreenState() < 0) { CMPTAcctSetScreenType(CMPT_SCREEN_TYPE_DRC); if (CMPTCheckScreenState() < 0) { @@ -117,11 +122,11 @@ static void launchvWiiTitle(uint32_t titleId_low, uint32_t titleId_high) { free(dataBuffer); } -void bootvWiiMenu() { - launchvWiiTitle(0, 0); +void bootvWiiMenu(bool drcEnabled) { + launchvWiiTitle(0, 0, drcEnabled); } -void bootHomebrewChannel() { +void bootHomebrewChannel(bool drcEnabled) { // fall back to booting the vWii system menu if anything fails uint64_t titleId = 0; @@ -157,5 +162,5 @@ void bootHomebrewChannel() { } DEBUG_FUNCTION_LINE("Launching vWii title %016llx", titleId); - launchvWiiTitle((uint32_t) (titleId >> 32), (uint32_t) (titleId & 0xffffffff)); + launchvWiiTitle((uint32_t) (titleId >> 32), (uint32_t) (titleId & 0xffffffff), drcEnabled); } diff --git a/source/BootUtils.h b/source/BootUtils.h index 4eeb473..1fd7047 100644 --- a/source/BootUtils.h +++ b/source/BootUtils.h @@ -6,6 +6,6 @@ void bootWiiUMenu(); void bootHomebrewLauncher(); -void bootvWiiMenu(); +void bootvWiiMenu(bool drcEnabled); -void bootHomebrewChannel(); \ No newline at end of file +void bootHomebrewChannel(bool drcEnabled); \ No newline at end of file diff --git a/source/MenuUtils.cpp b/source/MenuUtils.cpp index 84d2136..8b92574 100644 --- a/source/MenuUtils.cpp +++ b/source/MenuUtils.cpp @@ -69,7 +69,36 @@ void writeAutobootOption(std::string &configPath, int32_t autobootOption) { } } -int32_t handleMenuScreen(std::string &configPath, int32_t autobootOptionInput) { +bool readDrcEnabledOption(std::string &configPath) { + FILE *f = fopen(configPath.c_str(), "r"); + if (f) { + char buf[128]{}; + fgets(buf, sizeof(buf), f); + fclose(f); + + if (strncmp("0", buf, strlen("0")) == 0) { + return false; + } else { + return true; + } + } + return true; +} + +void writeDrcEnabledOption(std::string &configPath, bool drcEnabled) { + FILE *f = fopen(configPath.c_str(), "w"); + if (f) { + if (drcEnabled) { + fputs("1", f); + } else { + fputs("0", f); + } + + fclose(f); + } +} + +int32_t handleMenuScreen(std::string &configPath, std::string &drcSettingPath, int32_t autobootOptionInput, bool drcEnabledInput) { auto screenBuffer = DrawUtils::InitOSScreen(); if (!screenBuffer) { OSFatal("Failed to alloc memory for screen"); @@ -83,6 +112,7 @@ int32_t handleMenuScreen(std::string &configPath, int32_t autobootOptionInput) { uint32_t selected = autobootOptionInput > 0 ? autobootOptionInput : 0; int autoboot = autobootOptionInput; + bool drcEnabled = drcEnabledInput; bool redraw = true; while (true) { VPADStatus vpad{}; @@ -106,6 +136,9 @@ int32_t handleMenuScreen(std::string &configPath, int32_t autobootOptionInput) { } else if (vpad.trigger & VPAD_BUTTON_Y) { autoboot = selected; redraw = true; + } else if (vpad.trigger & VPAD_BUTTON_B) { + drcEnabled = !drcEnabled; + redraw = true; } if (redraw) { @@ -133,6 +166,9 @@ int32_t handleMenuScreen(std::string &configPath, int32_t autobootOptionInput) { DrawUtils::setFontSize(24); DrawUtils::drawPNG(16, 2, icon_png); DrawUtils::print(64 + 2, 6 + 24, "Tiramisu Boot Selector"); + DrawUtils::setFontSize(18); + const char *vWiiDrcStatus = drcEnabled ? "vWii DRC Enabled" : "vWii DRC Disabled"; + DrawUtils::print(SCREEN_WIDTH - DrawUtils::getTextWidth(vWiiDrcStatus) - 16, 6 + 24, vWiiDrcStatus); DrawUtils::drawRectFilled(8, 8 + 24 + 4, SCREEN_WIDTH - 8 * 2, 3, COLOR_WHITE); // draw bottom bar @@ -140,7 +176,7 @@ int32_t handleMenuScreen(std::string &configPath, int32_t autobootOptionInput) { DrawUtils::setFontSize(18); DrawUtils::print(16, SCREEN_HEIGHT - 8, "\ue07d Navigate "); DrawUtils::print(SCREEN_WIDTH - 16, SCREEN_HEIGHT - 8, "\ue000 Choose", true); - const char *autobootHints = "\ue002 Clear Autoboot / \ue003 Select Autoboot"; + const char *autobootHints = "\ue002 Clear Autoboot / \ue003 Select Autoboot / \ue001 Toggle vWii DRC"; DrawUtils::print(SCREEN_WIDTH / 2 + DrawUtils::getTextWidth(autobootHints) / 2, SCREEN_HEIGHT - 8, autobootHints, true); DrawUtils::endDraw(); @@ -164,6 +200,10 @@ int32_t handleMenuScreen(std::string &configPath, int32_t autobootOptionInput) { writeAutobootOption(configPath, autoboot); } + if (drcEnabled != drcEnabledInput) { + writeDrcEnabledOption(drcSettingPath, drcEnabled); + } + return selected; } diff --git a/source/MenuUtils.h b/source/MenuUtils.h index 8ee0ed3..3bbed7e 100644 --- a/source/MenuUtils.h +++ b/source/MenuUtils.h @@ -27,6 +27,10 @@ int32_t readAutobootOption(std::string &configPath); void writeAutobootOption(std::string &configPath, int32_t autobootOption); -int32_t handleMenuScreen(std::string &configPath, int32_t autobootOptionInput); +bool readDrcEnabledOption(std::string &configPath); + +void writeDrcEnabledOption(std::string &configPath, bool drcEnabled); + +int32_t handleMenuScreen(std::string &configPath, std::string &drcSettingPath, int32_t autobootOptionInput, bool drcEnabledInput); nn::act::SlotNo handleAccountSelectScreen(const std::vector> &data); \ No newline at end of file diff --git a/source/QuickStartUtils.cpp b/source/QuickStartUtils.cpp index a8e2df0..ccd1102 100644 --- a/source/QuickStartUtils.cpp +++ b/source/QuickStartUtils.cpp @@ -204,7 +204,7 @@ bool getQuickBoot() { if (info.titleId == 0x0005001010004000L) { // OSv0 DEBUG_FUNCTION_LINE("Launching vWii System Menu"); - bootvWiiMenu(); + bootvWiiMenu(true); return true; } diff --git a/source/main.cpp b/source/main.cpp index b476194..61f341f 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -39,8 +39,10 @@ int32_t main(int32_t argc, char **argv) { } std::string configPath = "fs:/vol/exernal01/wiiu/autoboot.cfg"; + std::string drcSettingPath = "fs:/vol/exernal01/wiiu/drcenabled.cfg"; if (argc >= 1) { configPath = std::string(argv[0]) + "/autoboot.cfg"; + drcSettingPath = std::string(argv[0]) + "/drcenabled.cfg"; } int32_t bootSelection = readAutobootOption(configPath); @@ -49,7 +51,7 @@ int32_t main(int32_t argc, char **argv) { VPADRead(VPAD_CHAN_0, &vpad, 1, nullptr); if ((bootSelection == -1) || (vpad.hold & VPAD_BUTTON_PLUS)) { - bootSelection = handleMenuScreen(configPath, bootSelection); + bootSelection = handleMenuScreen(configPath, drcSettingPath, bootSelection, readDrcEnabledOption(drcSettingPath)); } if (bootSelection >= 0) { @@ -61,10 +63,10 @@ int32_t main(int32_t argc, char **argv) { bootHomebrewLauncher(); break; case BOOT_OPTION_VWII_SYSTEM_MENU: - bootvWiiMenu(); + bootvWiiMenu(readDrcEnabledOption(drcSettingPath)); break; case BOOT_OPTION_VWII_HOMEBREW_CHANNEL: - bootHomebrewChannel(); + bootHomebrewChannel(readDrcEnabledOption(drcSettingPath)); break; default: bootWiiUMenu();