From d669a1a17e932372a394ea6258c637396de36785 Mon Sep 17 00:00:00 2001 From: yardape8000 Date: Sat, 12 May 2012 17:14:25 +0000 Subject: [PATCH] Fixed "Set USB failed: -6" dug. Fixed bug where user selected IOS is never actually used, because the configuration file was unloaded before it gets there. Fixed NAND paths being created with double "/"s. No real effect because they seem to be automatically reduced to a single "/" Minor wifi-gecko changes to keep it alive close to the game launch. --- source/channel/nand.cpp | 25 +++++++-- source/gecko/wifi_gecko.c | 5 +- source/loader/disc.c | 2 - source/loader/wdvd.c | 6 --- source/menu/menu.cpp | 21 +++++--- source/menu/menu.hpp | 4 +- source/menu/menu_game.cpp | 111 ++++++++++++++++++-------------------- 7 files changed, 94 insertions(+), 80 deletions(-) diff --git a/source/channel/nand.cpp b/source/channel/nand.cpp index b8445f21..5050fec3 100644 --- a/source/channel/nand.cpp +++ b/source/channel/nand.cpp @@ -181,14 +181,21 @@ s32 Nand::Disable_Emu() void Nand::Set_NandPath(string path) { - if(isalnum(*(path.begin()))) path.insert(path.begin(), '/'); - else *(path.begin()) = '/'; + if(isalnum(*(path.begin()))) + path.insert(path.begin(), '/'); + else + *(path.begin()) = '/'; - if(isalnum(*(path.end()))) path.push_back('/'); - else *(path.end()) = '/'; + if(isalnum(*(path.end()))) + path.push_back('/'); + else + path.replace(path.length() - 1, 1, "/"); if(path.size() <= 32) memcpy(NandPath, path.c_str(), path.size()); + else + memset(NandPath, 0, sizeof(NandPath)); +gprintf("NandPath = %s\n", NandPath); } void Nand::__Dec_Enc_TB(void) @@ -757,6 +764,16 @@ void Nand::CreatePath(const char *path, ...) if(folder[strlen(folder)-1] == '/') folder[strlen(folder)-1] = 0; + char *check = folder; + while (true) + { + check = strstr(folder, "//"); + if (check != NULL) + strcpy(check, check + 1); + else + break; + } + DIR *d; d = opendir(folder); diff --git a/source/gecko/wifi_gecko.c b/source/gecko/wifi_gecko.c index 51bfaf30..570c309e 100644 --- a/source/gecko/wifi_gecko.c +++ b/source/gecko/wifi_gecko.c @@ -29,6 +29,7 @@ #include #include #include +#include #include "wifi_gecko.h" // set to use TCP socket instead of UDP @@ -108,7 +109,9 @@ int WifiGecko_Send(const char * data, int datasize) while (done < datasize) { - if(blocksize > datasize-done) + while(net_get_status() == -EBUSY); + + if(blocksize > datasize-done) blocksize = datasize-done; ret = net_send(connection, data + done, blocksize, 0); diff --git a/source/loader/disc.c b/source/loader/disc.c index 4c793cc7..54ae450b 100644 --- a/source/loader/disc.c +++ b/source/loader/disc.c @@ -286,10 +286,8 @@ s32 Disc_Wait(void) s32 Disc_SetUSB(const u8 *id) { - //gprintf("Trying set_frag_list\n"); if (id) return set_frag_list((u8 *) id); - //gprintf("Trying WDVD_SetUSBMode\n"); return WDVD_SetUSBMode(wbfsDev, (u8 *) id, -1); } diff --git a/source/loader/wdvd.c b/source/loader/wdvd.c index 7384ab1e..e4f5f799 100644 --- a/source/loader/wdvd.c +++ b/source/loader/wdvd.c @@ -335,12 +335,6 @@ s32 WDVD_SetFragList(int device, void *fraglist, int size) inbuf[2] = (u32)fraglist; inbuf[3] = size; - //int i; - //for (i = 0; i < 8; i++) - // gprintf("inbuf[%d] = %X\n", i, inbuf[i]); - //ghexdump(fraglist, size); - //gprintf("\n"); - DCFlushRange(fraglist, size); s32 ret = IOS_Ioctl(di_fd, IOCTL_DI_SETFRAG, inbuf, sizeof(inbuf), outbuf, sizeof(outbuf)); if (ret < 0) return ret; diff --git a/source/menu/menu.cpp b/source/menu/menu.cpp index b740ce5e..dbbffa88 100644 --- a/source/menu/menu.cpp +++ b/source/menu/menu.cpp @@ -194,11 +194,9 @@ void CMenu::init(void) m_appDir = sfmt("%s:/%s", drive, APPDATA_DIR2); m_cfg.load(sfmt("%s/" CFG_FILENAME, m_appDir.c_str()).c_str()); - if (m_cfg.getBool("GENERAL", "async_network") || has_enabled_providers() || m_cfg.getBool("DEBUG", "wifi_gecko")) - { - _initAsyncNetwork(); - while(net_get_status() == -EBUSY); - } + m_use_wifi_gecko = m_cfg.getBool("DEBUG", "wifi_gecko"); + if (m_cfg.getBool("GENERAL", "async_network") || has_enabled_providers() || m_use_wifi_gecko) + _reload_wifi_gecko(); gprintf("Wiiflow boot.dol Location: %s\n", m_appDir.c_str()); @@ -496,7 +494,18 @@ void CMenu::cleanup(bool ios_reload) { _cleanupDefaultFont(); } - _deinitNetwork(); + if (!ios_reload || (!m_use_wifi_gecko && ios_reload)) + _deinitNetwork(); +} + +void CMenu::_reload_wifi_gecko(void) +{ + if (m_use_wifi_gecko) + { + _initAsyncNetwork(); + while(net_get_status() == -EBUSY); + usleep(1000); + } } void CMenu::_setAA(int aa) diff --git a/source/menu/menu.hpp b/source/menu/menu.hpp index 43c1ba79..b077ecd8 100644 --- a/source/menu/menu.hpp +++ b/source/menu/menu.hpp @@ -998,8 +998,10 @@ private: public: void _directlaunch(const string &id); private: + bool m_use_wifi_gecko; + void _reload_wifi_gecko(); bool _loadFile(SmartBuf &buffer, u32 &size, const char *path, const char *file); - int _loadIOS(u8 ios, string id); + int _loadIOS(u8 ios, int userIOS, string id); void _launch(dir_discHdr *hdr); void _launchGame(dir_discHdr *hdr, bool dvd); void _launchChannel(dir_discHdr *hdr); diff --git a/source/menu/menu_game.cpp b/source/menu/menu_game.cpp index ddfbe771..d84331ef 100644 --- a/source/menu/menu_game.cpp +++ b/source/menu/menu_game.cpp @@ -791,14 +791,11 @@ void CMenu::_launchHomebrew(const char *filepath, vector arguments) m_exit = true; } -int CMenu::_loadIOS(u8 ios, string id) +int CMenu::_loadIOS(u8 gameIOS, int userIOS, string id) { - int gameIOS = 0; - int userIOS = 0; + gprintf("Game ID# %s requested IOS %d. User selected %d\n", id.c_str(), gameIOS, userIOS); - gprintf("Game ID# %s requested IOS %d\n", id.c_str(), ios); - - if (m_gcfg2.getInt(id, "ios", &userIOS) && _installed_cios.size() > 0) + if (userIOS > 0 && _installed_cios.size() > 0) { for(CIOSItr itr = _installed_cios.begin(); itr != _installed_cios.end(); itr++) { @@ -807,59 +804,57 @@ int CMenu::_loadIOS(u8 ios, string id) gameIOS = itr->first; break; } - else gameIOS = 0; } } - // Reload IOS, if requested - if (gameIOS != mainIOS) + // remap IOS to CIOS + if(gameIOS < 0x64) { - if(gameIOS < 0x64) + if ( _installed_cios.size() <= 0) { - if ( _installed_cios.size() <= 0) + error(sfmt("No cios found!")); + Sys_LoadMenu(); + } + u8 IOS[3]; + IOS[0] = gameIOS; + IOS[1] = 56; + IOS[2] = 57; + bool found = false; + for(u8 num = 0; num < 3; num++) + { + if(found) + break; + if(IOS[num] == 0) + continue; + for(CIOSItr itr = _installed_cios.begin(); itr != _installed_cios.end(); itr++) { - error(sfmt("No cios found!")); - Sys_LoadMenu(); - } - u8 IOS[3]; - IOS[0] = gameIOS == 0 ? ios : gameIOS; - IOS[1] = 56; - IOS[2] = 57; - bool found = false; - for(u8 num = 0; num < 3; num++) - { - if(found) - break; - if(IOS[num] == 0) - continue; - for(CIOSItr itr = _installed_cios.begin(); itr != _installed_cios.end(); itr++) + if(itr->second == IOS[num] || itr->first == IOS[num]) { - if(itr->second == IOS[num] || itr->first == IOS[num]) - { - gameIOS = itr->first; - found = true; - break; - } + gameIOS = itr->first; + found = true; + break; } } - if(!found) - { - error(sfmt("Couldn't find a cIOS using base %i, or 56/57", IOS[0])); - return LOAD_IOS_FAILED; - } } - if (gameIOS != mainIOS) + if(!found) { - gprintf("Reloading IOS into %d\n", gameIOS); - cleanup(true); - if(!loadIOS(gameIOS, true)) - { - error(sfmt("Couldn't load IOS %i", gameIOS)); - return LOAD_IOS_FAILED; - } - return LOAD_IOS_SUCCEEDED; + error(sfmt("Couldn't find a cIOS using base %i, or 56/57", IOS[0])); + return LOAD_IOS_FAILED; } } + + if (gameIOS != mainIOS) + { + gprintf("Reloading IOS into %d\n", gameIOS); + cleanup(true); + if(!loadIOS(gameIOS, true)) + { + _reload_wifi_gecko(); + error(sfmt("Couldn't load IOS %i", gameIOS)); + return LOAD_IOS_FAILED; + } + return LOAD_IOS_SUCCEEDED; + } return LOAD_IOS_NOT_NEEDED; } @@ -926,6 +921,9 @@ void CMenu::_launchChannel(dir_discHdr *hdr) if (i==2) emulate_mode = true; + int userIOS = 0; + m_gcfg2.getInt(id, "ios", &userIOS); + m_gcfg1.save(true); m_gcfg2.save(true); m_cat.save(true); @@ -943,7 +941,7 @@ void CMenu::_launchChannel(dir_discHdr *hdr) _loadFile(cheatFile, cheatSize, m_cheatDir.c_str(), fmt("%s.gct", hdr->hdr.id)); ocarina_load_code(cheatFile.get(), cheatSize); - int result = _loadIOS(channel.GetRequestedIOS(hdr->hdr.chantitle), id); + int result = _loadIOS(channel.GetRequestedIOS(hdr->hdr.chantitle), userIOS, id); if (result == LOAD_IOS_FAILED) return; if (result == LOAD_IOS_SUCCEEDED) @@ -1001,7 +999,6 @@ void CMenu::_launchGame(dir_discHdr *hdr, bool dvd) { string id = string((const char *) hdr->hdr.id); Nand::Instance()->Disable_Emu(); - bool using_wifi_gecko = m_cfg.getBool("DEBUG", "wifi_gecko"); if (dvd) { @@ -1187,6 +1184,9 @@ void CMenu::_launchGame(dir_discHdr *hdr, bool dvd) if (has_enabled_providers() && _initNetwork() == 0) add_game_to_card(id.c_str()); + int userIOS = 0; + m_gcfg2.getInt(id, "ios", &userIOS); + m_gcfg1.save(true); m_gcfg2.save(true); m_cat.save(true); @@ -1203,31 +1203,22 @@ void CMenu::_launchGame(dir_discHdr *hdr, bool dvd) app_gameconfig_load((u8 *) &hdr->hdr.id, gameconfig.get(), gameconfigSize); ocarina_load_code(cheatFile.get(), cheatSize); - if (!using_wifi_gecko) + if (!m_use_wifi_gecko) net_wc24cleanup(); bool iosLoaded = false; if (!dvd) { - int result = _loadIOS(GetRequestedGameIOS(hdr), id); + int result = _loadIOS(GetRequestedGameIOS(hdr), userIOS, id); if (result == LOAD_IOS_FAILED) return; if (result == LOAD_IOS_SUCCEEDED) iosLoaded = true; } - - if (iosLoaded && using_wifi_gecko) - { - _initAsyncNetwork(); - while(net_get_status() == -EBUSY); - } - + if(emuSave) { - if(iosLoaded) ISFS_Deinitialize(); - ISFS_Initialize(); - Nand::Instance()->Init(emuPath.c_str(), emuPartition, false); DeviceHandler::Instance()->UnMount(emuPartition);