From 794fc9cca63ae5d10b7a766a379c496b8b7e11ec Mon Sep 17 00:00:00 2001 From: "fix94.1" Date: Wed, 5 Sep 2012 15:52:32 +0000 Subject: [PATCH] -added temporary reload to cIOS for game install and emu nand mode when in IOS58 mode -corrected a bug that the usb hdd does not get hooked up properly after IOS reload -small cleanup --- source/channel/nand.cpp | 1 + source/devicemounter/DeviceHandler.cpp | 15 ++++++++--- source/devicemounter/DeviceHandler.hpp | 3 ++- source/loader/alt_ios.cpp | 13 +++++----- source/loader/external_booter.cpp | 2 +- source/main.cpp | 21 +++++++++------- source/menu/menu.cpp | 35 ++++++++++++++++++++------ source/menu/menu.hpp | 3 ++- source/menu/menu_game.cpp | 24 +++++++----------- source/menu/menu_wbfs.cpp | 5 +++- 10 files changed, 77 insertions(+), 45 deletions(-) diff --git a/source/channel/nand.cpp b/source/channel/nand.cpp index 27c1ab64..6b59aa1f 100644 --- a/source/channel/nand.cpp +++ b/source/channel/nand.cpp @@ -188,6 +188,7 @@ s32 Nand::Disable_Emu() MountedDevice = 0; emu_enabled = false; + usleep(1000); return 0; } diff --git a/source/devicemounter/DeviceHandler.cpp b/source/devicemounter/DeviceHandler.cpp index b7d854a7..4ef4752c 100644 --- a/source/devicemounter/DeviceHandler.cpp +++ b/source/devicemounter/DeviceHandler.cpp @@ -67,7 +67,7 @@ void DeviceHandler::MountAll() #endif } -void DeviceHandler::UnMountAll(bool ShutdownUSB) +void DeviceHandler::UnMountAll() { for(u32 i = SD; i < MAXDEVICES; i++) UnMount(i); @@ -84,9 +84,8 @@ void DeviceHandler::UnMountAll(bool ShutdownUSB) usb1 = NULL; USBStorage2_Deinit(); + USB_Deinitialize(); SDHC_Close(); - if(ShutdownUSB) - USB_Deinitialize(); } bool DeviceHandler::Mount(int dev) @@ -420,3 +419,13 @@ void DeviceHandler::UnMountDevolution(int CurrentPartition) OGC_Device->UnMount(NewPartition); delete OGC_Device; } + +bool DeviceHandler::UsablePartitionMounted() +{ + for(u8 i = SD; i < MAXDEVICES; i++) + { + if(IsInserted(i) && !GetWbfsHandle(i)) //Everything besides WBFS for configuration + return true; + } + return false; +} diff --git a/source/devicemounter/DeviceHandler.hpp b/source/devicemounter/DeviceHandler.hpp index 6b28913d..c3cc2661 100644 --- a/source/devicemounter/DeviceHandler.hpp +++ b/source/devicemounter/DeviceHandler.hpp @@ -72,7 +72,7 @@ class DeviceHandler void SetModes(); void MountAll(); - void UnMountAll(bool ShutdownUSB = false); + void UnMountAll(); bool Mount(int dev); bool IsInserted(int dev); void UnMount(int dev); @@ -85,6 +85,7 @@ class DeviceHandler bool SD_Inserted() { if(sd) return sd->IsInserted(); return false; } bool USB0_Inserted() { if(usb0) return usb0->IsInserted(); return false; } bool USB1_Inserted() { if(usb1) return usb1->IsInserted(); return false; } + bool UsablePartitionMounted(); void WaitForDevice(const DISC_INTERFACE *Handle); void UnMountSD() { if(sd) delete sd; sd = NULL; } diff --git a/source/loader/alt_ios.cpp b/source/loader/alt_ios.cpp index d373a8a4..0a0d9940 100644 --- a/source/loader/alt_ios.cpp +++ b/source/loader/alt_ios.cpp @@ -8,6 +8,7 @@ #include "sys.h" #include "wbfs.h" #include "wdvd.h" +#include "external_booter.hpp" #include "channel/nand.hpp" #include "devicemounter/DeviceHandler.hpp" #include "devicemounter/sdhc.h" @@ -82,17 +83,17 @@ void load_dip_249() bool loadIOS(int ios, bool MountDevices) { + int CurIOS = IOS_GetVersion(); bool ret = true; - m_music.Stop(); - DeviceHandler::Instance()->UnMountAll(); #ifndef DOLPHIN - if(ios != IOS_GetVersion()) + if(ios != CurIOS) { WDVD_Close(); Close_Inputs(); - gprintf("Reloading into IOS %i from %i...\n", ios, IOS_GetVersion()); - Nand::Instance()->DeInit_ISFS(); + m_music.Stop(); + gprintf("Reloading into IOS %i from %i...\n", ios, CurIOS); + ShutdownBeforeExit(); ret = IOS_ReloadIOS(ios) == 0; Nand::Instance()->Init_ISFS(); gprintf("AHBPROT after IOS Reload: %u\n", AHBRPOT_Patched()); @@ -106,7 +107,7 @@ bool loadIOS(int ios, bool MountDevices) else if(CurrentIOS.Type == IOS_TYPE_WANIN && CurrentIOS.Revision >= 18) load_dip_249(); DeviceHandler::Instance()->SetModes(); - if(MountDevices) + if(MountDevices && ios != CurIOS) DeviceHandler::Instance()->MountAll(); return ret; diff --git a/source/loader/external_booter.cpp b/source/loader/external_booter.cpp index 4f318f68..f492bd42 100644 --- a/source/loader/external_booter.cpp +++ b/source/loader/external_booter.cpp @@ -111,7 +111,7 @@ void ExternalBooter_ChannelSetup(void *dolchunkoffset[18], u32 dolchunksize[18], void ShutdownBeforeExit(bool KeepPatches) { - DeviceHandler::Instance()->UnMountAll(true); //Shutdown USB as well + DeviceHandler::Instance()->UnMountAll(); Nand::Instance()->DeInit_ISFS(KeepPatches); WDVD_Close(); } diff --git a/source/main.cpp b/source/main.cpp index 8fe44233..8f2ca561 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -23,7 +23,7 @@ #include "memory/memory.h" CMenu *mainMenu; -bool useMainIOS; +bool useMainIOS = false; int main(int argc, char **argv) { @@ -96,33 +96,36 @@ int main(int argc, char **argv) DeviceHandler::Instance()->MountAll(); vid.waitMessage(0.15f); - bool dipOK = WDVD_Init() >= 0; mainMenu = new CMenu(vid); Open_Inputs(); mainMenu->init(); if(CurrentIOS.Version != mainIOS && !neek2o()) { - if(useMainIOS || (!DeviceHandler::Instance()->IsInserted(SD) && !DeviceHandler::Instance()->IsInserted(USB1))) + if(useMainIOS || !DeviceHandler::Instance()->UsablePartitionMounted()) { iosOK = loadIOS(mainIOS, true) && CustomIOS(CurrentIOS.Type); Open_Inputs(); mainMenu->init(); } } + if(CurrentIOS.Version == mainIOS) + useMainIOS = true; //Needed for later checks + if(!iosOK) mainMenu->terror("errboot1", L"No cIOS found!\ncIOS d2x 249 base 56 and 250 base 57 are enough for all your games."); - else if(!DeviceHandler::Instance()->IsInserted(SD) && !DeviceHandler::Instance()->IsInserted(USB1)) + else if(!DeviceHandler::Instance()->UsablePartitionMounted()) mainMenu->terror("errboot2", L"Could not find a device to save configuration files on!"); - else if(!dipOK) + else if(WDVD_Init() < 0) mainMenu->terror("errboot3", L"Could not initialize the DIP module!"); - else if(gameid != NULL && strlen(gameid) == 6) - mainMenu->directlaunch(gameid); - else + else { if(Emulator_boot) mainMenu->m_Emulator_boot = true; - mainMenu->main(); + if(gameid != NULL && strlen(gameid) == 6) + mainMenu->directlaunch(gameid); + else + mainMenu->main(); } //Exit WiiFlow, no game booted... mainMenu->cleanup(); diff --git a/source/menu/menu.cpp b/source/menu/menu.cpp index 04ff58bf..48064f20 100644 --- a/source/menu/menu.cpp +++ b/source/menu/menu.cpp @@ -2099,13 +2099,7 @@ bool CMenu::_loadChannelList(void) Nand::Instance()->Disable_Emu(); if(!disable_emu) { - if(CurrentIOS.Version != mainIOS) - { - loadIOS(mainIOS, true); - Open_Inputs(); - for(int chan = WPAD_MAX_WIIMOTES-2; chan >= 0; chan--) - WPAD_SetVRes(chan, m_vid.width() + m_cursor[chan].width(), m_vid.height() + m_cursor[chan].height()); - } + _TempLoadIOS(); if(!DeviceHandler::Instance()->IsInserted(lastPartition)) DeviceHandler::Instance()->Mount(lastPartition); @@ -2145,8 +2139,11 @@ bool CMenu::_loadList(void) if((m_current_view == COVERFLOW_CHANNEL && m_cfg.getBool("NAND", "disable", true)) || m_current_view != COVERFLOW_CHANNEL) Nand::Instance()->Disable_Emu(); - if(m_cfg.getBool(_domainFromView(), "update_cache")) m_gameList.Update(m_current_view); + if(m_cfg.getBool(_domainFromView(), "update_cache")) + m_gameList.Update(m_current_view); + /* Make sure if coming from Emu NAND the IOS is set back */ + _TempLoadIOS(IOS_TYPE_NORMAL_IOS); gprintf("Loading items of "); bool retval; @@ -2563,3 +2560,25 @@ void CMenu::RemoveCover( char * id ) remove(fmt("%s/%s.wfc", m_cacheDir.c_str(), id)); } } + +void CMenu::_TempLoadIOS(int IOS) +{ +#ifndef DOLPHIN + /* Only temp reload in IOS58 mode */ + if(useMainIOS || neek2o()) + return; + + if(IOS == IOS_TYPE_NORMAL_IOS) + IOS = 58; + else if(IOS == 0) + IOS = mainIOS; + + if(CurrentIOS.Version != IOS) + { + loadIOS(IOS, true); + Open_Inputs(); + for(int chan = WPAD_MAX_WIIMOTES-2; chan >= 0; chan--) + WPAD_SetVRes(chan, m_vid.width() + m_cursor[chan].width(), m_vid.height() + m_cursor[chan].height()); + } +#endif +} diff --git a/source/menu/menu.hpp b/source/menu/menu.hpp index a5a0b5e8..eb3224eb 100644 --- a/source/menu/menu.hpp +++ b/source/menu/menu.hpp @@ -1072,7 +1072,8 @@ private: static void _gameSoundThread(CMenu *m); static void _load_installed_cioses(); - // + void _TempLoadIOS(int IOS = 0); + struct SOption { const char id[10]; const wchar_t text[16]; }; static const string _translations[23]; static const SOption _languages[11]; diff --git a/source/menu/menu_game.cpp b/source/menu/menu_game.cpp index 460eb111..c08332ba 100644 --- a/source/menu/menu_game.cpp +++ b/source/menu/menu_game.cpp @@ -1083,8 +1083,6 @@ void CMenu::_launchChannel(dir_discHdr *hdr) ShutdownBeforeExit(); Launch_nk(gameTitle, emuPath.size() > 1 ? emuPath.c_str() : NULL); } - DeviceHandler::Instance()->UnMountAll(); - if(!forwarder || neek2o()) { if(!emu_disabled) @@ -1094,10 +1092,7 @@ void CMenu::_launchChannel(dir_discHdr *hdr) } gameIOS = channel.GetRequestedIOS(gameTitle); if(!emu_disabled) - { Nand::Instance()->Disable_Emu(); - usleep(1000); - } if(_loadIOS(gameIOS, userIOS, id) == LOAD_IOS_FAILED) return; } @@ -1165,7 +1160,7 @@ void CMenu::_launchGame(dir_discHdr *hdr, bool dvd) if(dvd) { u32 cover = 0; - #ifndef DOLPHIN +#ifndef DOLPHIN if(!neek2o()) { Disc_SetUSB(NULL, false); @@ -1184,23 +1179,24 @@ void CMenu::_launchGame(dir_discHdr *hdr, bool dvd) return; } while(!(cover & 0x2)); } - if(CurrentIOS.Version != mainIOS) - loadIOS(mainIOS, true); } - #endif +#endif + _TempLoadIOS(); /* Open Disc */ - if (Disc_Open(true) < 0) + if(Disc_Open(true) < 0) { error(_t("wbfsoperr2", L"Disc_Open failed")); - if (BTN_B_PRESSED) return; + if(BTN_B_PRESSED) + return; } /* Check disc */ - if (Disc_IsWii() < 0) + if(Disc_IsWii() < 0) { if (Disc_IsGC() < 0) { error(_t("errgame9", L"This is not a Wii or GC disc")); - if (BTN_B_PRESSED) return; + if(BTN_B_PRESSED) + return; } else { @@ -1355,8 +1351,6 @@ void CMenu::_launchGame(dir_discHdr *hdr, bool dvd) m_cat.save(true); m_cfg.save(true); cleanup(); // wifi and sd gecko doesnt work anymore after cleanup - DeviceHandler::Instance()->UnMountAll(); - if(CurrentIOS.Type == IOS_TYPE_D2X) { /* Open ES Module */ diff --git a/source/menu/menu_wbfs.cpp b/source/menu/menu_wbfs.cpp index 7b55c862..2854f1a9 100644 --- a/source/menu/menu_wbfs.cpp +++ b/source/menu/menu_wbfs.cpp @@ -306,6 +306,7 @@ bool CMenu::_wbfsOp(CMenu::WBFS_OP op) switch(op) { case CMenu::WO_ADD_GAME: + _TempLoadIOS(); m_btnMgr.show(m_wbfsPBar); m_btnMgr.setProgress(m_wbfsPBar, 0.f); m_btnMgr.hide(m_wbfsBtnGo); @@ -370,7 +371,6 @@ bool CMenu::_wbfsOp(CMenu::WBFS_OP op) { error(_t("wbfsoperr3", L"This is not a Wii or GC disc!")); out = true; - break; } break; case CMenu::WO_REMOVE_GAME: @@ -458,7 +458,10 @@ bool CMenu::_wbfsOp(CMenu::WBFS_OP op) if(!m_thrdWorking) { if(op == CMenu::WO_ADD_GAME) + { WDVD_StopMotor(); + _TempLoadIOS(IOS_TYPE_NORMAL_IOS); + } m_btnMgr.show(m_wbfsBtnBack); } }