From 81228858bdfb056b1883e567dabd5fc8aff92118 Mon Sep 17 00:00:00 2001 From: jdfr228 Date: Sat, 15 Apr 2023 17:24:38 -0400 Subject: [PATCH] Add options to autoboot from disc --- source/StartUpProcess.cpp | 76 +++++++++++++++++++++++ source/StartUpProcess.h | 4 ++ source/menu/menu_install.cpp | 6 ++ source/settings/CSettings.cpp | 12 ++++ source/settings/CSettings.h | 2 + source/settings/menus/GUISettingsMenu.cpp | 20 ++++++ source/usbloader/disc.c | 6 -- 7 files changed, 120 insertions(+), 6 deletions(-) diff --git a/source/StartUpProcess.cpp b/source/StartUpProcess.cpp index 42a7054c..a17b97e9 100644 --- a/source/StartUpProcess.cpp +++ b/source/StartUpProcess.cpp @@ -22,12 +22,15 @@ #include "usbloader/MountGamePartition.h" #include "usbloader/GameBooter.hpp" #include "usbloader/GameList.h" +#include "usbloader/wdvd.h" #include "utils/tools.h" +#include "utils/ShowError.h" #include "sys.h" #include "svnrev.h" #include "gitver.h" #include "usbloader/sdhc.h" #include "settings/meta.h" +#include "language/gettext.h" extern bool isWiiVC; // in sys.cpp extern u8 sdhc_mode_sd; @@ -69,6 +72,10 @@ StartUpProcess::StartUpProcess() cancelTxt->SetAlignment(ALIGN_CENTER, ALIGN_MIDDLE); cancelTxt->SetPosition(screenwidth / 2, screenheight / 2 + 90); + discCancelTxt = new GuiText("Press B to cancel", 22, (GXColor){255, 255, 255, 255}); + discCancelTxt->SetAlignment(ALIGN_CENTER, ALIGN_MIDDLE); + discCancelTxt->SetPosition(screenwidth / 2, screenheight / 2 + 90); + trigB = new GuiTrigger; trigB->SetButtonOnlyTrigger(-1, WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B, PAD_BUTTON_B); @@ -83,6 +90,7 @@ StartUpProcess::StartUpProcess() sdmodeBtn->SetTrigger(trigA); drawCancel = false; + drawDiscCancel = false; } StartUpProcess::~StartUpProcess() @@ -94,6 +102,7 @@ StartUpProcess::~StartUpProcess() delete messageTxt; delete versionTxt; delete cancelTxt; + delete discCancelTxt; delete cancelBtn; delete sdmodeBtn; delete trigB; @@ -427,6 +436,41 @@ int StartUpProcess::Execute(bool quickGameBoot) SetTextf("Checking installed MIOS\n"); IosLoader::GetMIOSInfo(); + if (Settings.AutobootDiscs == ON) { + drawDiscCancel = true; + Timer countDown; + bool skipDiscAutoboot = false; + + do + { + UpdatePads(); + for (int i = 0; i < 4; ++i) + { + cancelBtn->Update(&userInput[i]); + } + if (cancelBtn->GetState() == STATE_CLICKED) { + skipDiscAutoboot = true; + break; + } + + messageTxt->SetTextf("Autobooting from Disc in: %i sec\n", Settings.AutobootDiscsDelay - (int)countDown.elapsed()); + Draw(); + usleep(50000); + } while (countDown.elapsed() < (float)Settings.AutobootDiscsDelay); + + drawDiscCancel = false; + if (skipDiscAutoboot == false) { + messageTxt->SetTextf("Autobooting from Disc\n"); + Draw(); + return this->AutobootDisc(); + } + } + + return FinalizeExecute(); +} + +int StartUpProcess::FinalizeExecute() +{ SetTextf("Loading resources\n"); // Do not allow banner grid mode without AHBPROT // this function does nothing if it was already initiated before @@ -459,6 +503,8 @@ void StartUpProcess::Draw() versionTxt->Draw(); if (drawCancel) cancelTxt->Draw(); + if (drawDiscCancel) + discCancelTxt->Draw(); Menu_Render(); } @@ -481,3 +527,33 @@ int StartUpProcess::QuickGameBoot(const char *gameID) return GameBooter::BootGame(header); } + +int StartUpProcess::AutobootDisc() +{ + Disc_Init(); + + u32 DiscDriveCover = 0; + WDVD_GetCoverStatus(&DiscDriveCover); + + if (DiscDriveCover & 0x02) { + struct discHdr* header = new struct discHdr; + if (Disc_Mount(header) < 0) + { + delete header; + header = NULL; + SetTextf("Error Mounting Disc\n"); + usleep(3000000); //~3 seconds in Dolphin + return FinalizeExecute(); + } + else + { + GameStatistics.SetPlayCount(header->id, GameStatistics.GetPlayCount(header->id) + 1); + GameStatistics.Save(); + + return GameBooter::BootGame(header); + } + } + else { + return FinalizeExecute(); + } +} \ No newline at end of file diff --git a/source/StartUpProcess.h b/source/StartUpProcess.h index dca9366c..19e51981 100644 --- a/source/StartUpProcess.h +++ b/source/StartUpProcess.h @@ -13,14 +13,17 @@ private: ~StartUpProcess(); void LoadIOS(u8 ios, bool boot); int Execute(bool quickGameBoot); + int FinalizeExecute(); bool USBSpinUp(); void TextFade(int direction); void SetTextf(const char *format, ...); void Draw(); static int ParseArguments(int argc, char *argv[]); static int QuickGameBoot(const char *gameID); + int AutobootDisc(); bool drawCancel; + bool drawDiscCancel; GuiImageData *GXImageData; GuiImage *background; @@ -29,6 +32,7 @@ private: GuiText *messageTxt; GuiText *versionTxt; GuiText *cancelTxt; + GuiText *discCancelTxt; GuiButton *cancelBtn; GuiButton *sdmodeBtn; GuiTrigger *trigB; diff --git a/source/menu/menu_install.cpp b/source/menu/menu_install.cpp index e8738eb6..c695c510 100644 --- a/source/menu/menu_install.cpp +++ b/source/menu/menu_install.cpp @@ -6,6 +6,7 @@ #include "usbloader/wbfs.h" #include "usbloader/disc.h" #include "usbloader/GameList.h" +#include "usbloader/wdvd.h" #include "prompts/ProgressWindow.h" #include "prompts/GCMultiDiscMenu.h" #include "themes/CTheme.h" @@ -218,6 +219,11 @@ int MenuInstall() WindowPrompt(tr( "Error reading Disc" ), 0, tr( "Back" )); return MENU_DISCLIST; } + ret = WDVD_Reset(); + if (ret < 0) { + WindowPrompt(tr( "Error resetting disc drive" ), 0, tr( "Back" )); + return MENU_DISCLIST; + } ret = Disc_Open(); if (ret < 0) { diff --git a/source/settings/CSettings.cpp b/source/settings/CSettings.cpp index cde66efe..4678265b 100644 --- a/source/settings/CSettings.cpp +++ b/source/settings/CSettings.cpp @@ -169,6 +169,8 @@ void CSettings::SetDefault() NandEmuMode = OFF; NandEmuChanMode = 2; UseSystemFont = ON; + AutobootDiscs = OFF; + AutobootDiscsDelay = 3; Hooktype = 0; WiirdDebugger = OFF; WiirdDebuggerPause = OFF; @@ -439,6 +441,8 @@ bool CSettings::Save() fprintf(file, "NandEmuPath = %s\n", NandEmuPath); fprintf(file, "NandEmuChanPath = %s\n", NandEmuChanPath); fprintf(file, "UseSystemFont = %d\n", UseSystemFont); + fprintf(file, "AutobootDiscs = %d\n", AutobootDiscs); + fprintf(file, "AutobootDiscsDelay = %d\n", AutobootDiscsDelay); fprintf(file, "Hooktype = %d\n", Hooktype); fprintf(file, "WiirdDebugger = %d\n", WiirdDebugger); fprintf(file, "WiirdDebuggerPause = %d\n", WiirdDebuggerPause); @@ -867,6 +871,14 @@ bool CSettings::SetSetting(char *name, char *value) { UseSystemFont = atoi(value); } + else if (strcmp(name, "AutobootDiscs") == 0) + { + AutobootDiscs = atoi(value); + } + else if (strcmp(name, "AutobootDiscsDelay") == 0) + { + AutobootDiscsDelay = atoi(value); + } else if(strcmp(name, "Hooktype") == 0) { Hooktype = atoi(value); diff --git a/source/settings/CSettings.h b/source/settings/CSettings.h index 7fa61a72..aa2d2ed5 100644 --- a/source/settings/CSettings.h +++ b/source/settings/CSettings.h @@ -175,6 +175,8 @@ class CSettings short NandEmuMode; short NandEmuChanMode; short UseSystemFont; + short AutobootDiscs; + short AutobootDiscsDelay; short Hooktype; short WiirdDebugger; short WiirdDebuggerPause; diff --git a/source/settings/menus/GUISettingsMenu.cpp b/source/settings/menus/GUISettingsMenu.cpp index 16dddde2..11428762 100644 --- a/source/settings/menus/GUISettingsMenu.cpp +++ b/source/settings/menus/GUISettingsMenu.cpp @@ -159,6 +159,8 @@ GuiSettingsMenu::GuiSettingsMenu() Options->SetName(Idx++, "%s", tr( "Show Game Count" )); Options->SetName(Idx++, "%s", tr( "HOME Menu" )); Options->SetName(Idx++, "%s", tr( "Use System Font" )); + Options->SetName(Idx++, "%s", tr( "Autoboot Discs" )); + Options->SetName(Idx++, "%s", tr( "Autoboot Discs Delay" )); Options->SetName(Idx++, "%s", tr( "Virtual Pointer Speed" )); Options->SetName(Idx++, "%s", tr( "Adjust Overscan X" )); Options->SetName(Idx++, "%s", tr( "Adjust Overscan Y" )); @@ -254,6 +256,12 @@ void GuiSettingsMenu::SetOptionValues() //! Settings: Use System Font Options->SetValue(Idx++, "%s", tr( OnOffText[Settings.UseSystemFont] )); + //! Settings: Autoboot Discs + Options->SetValue(Idx++, "%s", tr( OnOffText[Settings.AutobootDiscs] )); + + //! Settings: Autoboot Discs Delay + Options->SetValue(Idx++, "%i", Settings.AutobootDiscsDelay); + //! Settings: Virtual Pointer Speed Options->SetValue(Idx++, "%g", Settings.PointerSpeed); @@ -484,6 +492,18 @@ int GuiSettingsMenu::GetMenuInternal() Settings.FontScaleFactor = 1.0f; } + //! Settings: Autoboot Discs + else if (ret == ++Idx) + { + if (++Settings.AutobootDiscs >= MAX_ON_OFF) Settings.AutobootDiscs = 0; + } + + //! Settings: Autoboot Discs Delay + else if (ret == ++Idx) + { + if (++Settings.AutobootDiscsDelay >= 6) Settings.AutobootDiscsDelay = 0; + } + //! Settings: Virtual Pointer Speed else if (ret == ++Idx) { diff --git a/source/usbloader/disc.c b/source/usbloader/disc.c index e863ca07..566c3e46 100644 --- a/source/usbloader/disc.c +++ b/source/usbloader/disc.c @@ -263,12 +263,6 @@ s32 Disc_Init(void) s32 Disc_Open(void) { - s32 ret; - - /* Reset drive */ - ret = WDVD_Reset(); - if (ret < 0) return ret; - /* Read disc ID */ return WDVD_ReadDiskId(diskid); }