diff --git a/source/main.cpp b/source/main.cpp index ec60fafc..07aa41bd 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -129,8 +129,8 @@ int main(int argc, char **argv) ret = mainMenu->main(); } } + delete mainMenu; - ISFS_Deinitialize(); Sys_Exit(); exit(1); return 0; diff --git a/source/memory/mem2alloc.cpp b/source/memory/mem2alloc.cpp index cc8ef62c..56b7f103 100644 --- a/source/memory/mem2alloc.cpp +++ b/source/memory/mem2alloc.cpp @@ -70,7 +70,7 @@ void *CMEM2Alloc::allocate(unsigned int s) } // Search for a free block SBlock *i; - SBlock *j; + SBlock *j = m_first; for (i = m_first; i != 0; i = i->next) { if (i->f && i->s >= s) diff --git a/source/menu/menu.cpp b/source/menu/menu.cpp index 2cee3a3c..159eece2 100644 --- a/source/menu/menu.cpp +++ b/source/menu/menu.cpp @@ -481,45 +481,40 @@ void CMenu::init(void) bool cleaned_up = false; -void CMenu::cleanup(bool ios_reload) +void CMenu::cleanup() { if(cleaned_up) return; m_cf.stopCoverLoader(); + _cleanupDefaultFont(); m_cf.clear(); - ClearGameSoundThreadStack(); + m_banner->DeleteBanner(); m_plugin.Cleanup(); _stopSounds(); - - if (!ios_reload) - m_cameraSound.release(); - - m_music->cleanup(); + delete m_music; + m_cameraSound.release(); + ClearGameSoundThreadStack(); SoundHandler::DestroyInstance(); soundDeinit(); if(!m_reload) { + ISFS_Deinitialize(); DeviceHandler::DestroyInstance(); + m_vid.CheckWaitThread(true); m_vid.cleanup(); - wiiLightOff(); } + wiiLightOff(); + _deinitNetwork(); - if (!ios_reload) - { - LWP_MutexDestroy(m_mutex); - m_mutex = 0; - } + LWP_MutexDestroy(m_mutex); + m_mutex = 0; - if (!ios_reload) - _cleanupDefaultFont(); - - if (!ios_reload || (!m_use_wifi_gecko && ios_reload)) - _deinitNetwork(); ClearLogBuffer(); + Close_Inputs(); cleaned_up = true; gprintf(" \nMemory cleaned up\n"); @@ -527,11 +522,11 @@ void CMenu::cleanup(bool ios_reload) void CMenu::_reload_wifi_gecko(void) { - if (m_use_wifi_gecko) + if(m_use_wifi_gecko) { _initAsyncNetwork(); - while(net_get_status() == -EBUSY); - usleep(1000); + while(net_get_status() == -EBUSY) + usleep(100); } } diff --git a/source/menu/menu.hpp b/source/menu/menu.hpp index 65b954c5..b67e30cd 100644 --- a/source/menu/menu.hpp +++ b/source/menu/menu.hpp @@ -47,7 +47,7 @@ public: void terror(const char *key, const wchar_t *msg) { error(_fmt(key, msg)); } void exitHandler(int ExitTo); int main(void); - void cleanup(bool ios_reload = false); + void cleanup(); u8 m_current_view; private: struct SZone diff --git a/source/menu/menu_download.cpp b/source/menu/menu_download.cpp index 4e49cb3d..8e3c0ed2 100644 --- a/source/menu/menu_download.cpp +++ b/source/menu/menu_download.cpp @@ -451,6 +451,8 @@ int CMenu::_initNetwork() void CMenu::_deinitNetwork() { + while(net_get_status() == -EBUSY) + usleep(100); net_wc24cleanup(); net_deinit(); m_networkInit = false; diff --git a/source/menu/menu_game.cpp b/source/menu/menu_game.cpp index 5841371c..586d1b8b 100644 --- a/source/menu/menu_game.cpp +++ b/source/menu/menu_game.cpp @@ -17,6 +17,7 @@ #include "wip.h" #include "channel_launcher.h" #include "devicemounter/sdhc.h" +#include "devicemounter/usbstorage.h" #include "BannerWindow.hpp" #include @@ -772,11 +773,13 @@ void CMenu::_launch(dir_discHdr *hdr) } } -extern "C" {extern void USBStorage_Deinit(void);} - void CMenu::_launchGC(dir_discHdr *hdr, bool DML) { - char* id = (char *)hdr->id; + char id[7]; + strncpy(id, hdr->id, sizeof(id)); + + char path[256]; + strncpy(path, hdr->path, sizeof(path)); Nand::Instance()->Disable_Emu(); @@ -812,23 +815,21 @@ void CMenu::_launchGC(dir_discHdr *hdr, bool DML) if(cheats) { snprintf(CheatPath, sizeof(CheatPath), "%s/%s", m_cheatDir.c_str(), fmt("%s.gct", id)); - snprintf(NewCheatPath, sizeof(NewCheatPath), "%s/%s/%s", fmt(DML_DIR, "sd"), hdr->path, fmt("%s.gct", id)); + snprintf(NewCheatPath, sizeof(NewCheatPath), "%s/%s/%s", fmt(DML_DIR, "sd"), path, fmt("%s.gct", id)); } - if(m_new_dml) + string newPath; + if(strcasestr(path, "boot.bin") != NULL) { - string path; - if(strcasestr(hdr->path, "boot.bin") != NULL) - { - path = &hdr->path[string(hdr->path).find_first_of(":/")+1]; - path.erase(path.end() - 12, path.end()); - } - else - path = &hdr->path[string(hdr->path).find_first_of(":/")+1]; - DML_New_SetOptions(path.c_str(), CheatPath, NewCheatPath, cheats, DML_debug, NMM, nodisc, DMLvideoMode); + newPath = &path[string(path).find_first_of(":/")+1]; + newPath.erase(newPath.end() - 12, newPath.end()); } else - DML_Old_SetOptions(hdr->path, CheatPath, NewCheatPath, cheats); + newPath = &path[string(path).find_first_of(":/")+1]; + if(m_new_dml) + DML_New_SetOptions(newPath.c_str(), CheatPath, NewCheatPath, cheats, DML_debug, NMM, nodisc, DMLvideoMode); + else + DML_Old_SetOptions(path, CheatPath, NewCheatPath, cheats); if(!nodisc || !m_new_dml) { @@ -844,9 +845,8 @@ void CMenu::_launchGC(dir_discHdr *hdr, bool DML) m_gcfg2.save(true); m_cat.save(true); m_cfg.save(true); - cleanup(); - Close_Inputs(); + USBStorage_Deinit(); SDHC_Init(); @@ -876,19 +876,10 @@ void CMenu::_launchHomebrew(const char *filepath, vector arguments) m_cat.save(true); m_cfg.save(true); - while(net_get_status() == -EBUSY) - usleep(100); - - m_vid.CheckWaitThread(true); Playlog_Delete(); - cleanup(); - // wifi and sd gecko doesnt work anymore after cleanup - Close_Inputs(); - m_vid.cleanup(); - wiiLightOff(); + cleanup(); // wifi and sd gecko doesnt work anymore after cleanup LoadHomebrew(filepath); - DeviceHandler::DestroyInstance(); USBStorage_Deinit(); AddBootArgument(filepath); for(u32 i = 0; i < arguments.size(); ++i) @@ -978,7 +969,7 @@ void CMenu::_launchChannel(dir_discHdr *hdr) u32 entry = 0; Nand::Instance()->Disable_Emu(); - string id = string((const char *)hdr->id); + string id = string(hdr->id); bool forwarder = true; for (u8 num = 0; num < ARRAY_SIZE(systems); num++) @@ -1032,18 +1023,14 @@ void CMenu::_launchChannel(dir_discHdr *hdr) int emulate_mode = min(max(0, m_cfg.getInt("NAND", "emulation", 1)), (int)ARRAY_SIZE(CMenu::_NandEmu) - 1); int userIOS = m_gcfg2.getInt(id, "ios", 0); + u64 gameTitle = TITLE_ID(hdr->settings[0],hdr->settings[1]); m_gcfg1.save(true); m_gcfg2.save(true); m_cat.save(true); m_cfg.save(true); - - CheckGameSoundThread(); - m_vid.CheckWaitThread(true); cleanup(); - USBStorage_Deinit(); - Close_Inputs(); - + if(!emu_disabled) { Nand::Instance()->Init(emuPath.c_str(), emuPartition, false); @@ -1065,13 +1052,13 @@ void CMenu::_launchChannel(dir_discHdr *hdr) if(!forwarder) { - entry = channel.Load(TITLE_ID(hdr->settings[0],hdr->settings[1]), &ios); + entry = channel.Load(gameTitle, &ios); setLanguage(language); SmartBuf cheatFile; u32 cheatSize = 0; if (cheat) - _loadFile(cheatFile, cheatSize, m_cheatDir.c_str(), fmt("%s.gct", hdr->id)); + _loadFile(cheatFile, cheatSize, m_cheatDir.c_str(), fmt("%s.gct", id.c_str())); ocarina_load_code(cheatFile.get(), cheatSize); @@ -1157,17 +1144,22 @@ void CMenu::_launchChannel(dir_discHdr *hdr) if(forwarder) { WII_Initialize(); - if(WII_LaunchTitle(TITLE_ID(hdr->settings[0],hdr->settings[1])) < 0) + if(WII_LaunchTitle(gameTitle) < 0) Sys_LoadMenu(); } - if(!BootChannel(entry, TITLE_ID(hdr->settings[0],hdr->settings[1]), ios, videoMode, vipatch, countryPatch, patchVidMode, aspectRatio)) + if(!BootChannel(entry, gameTitle, ios, videoMode, vipatch, countryPatch, patchVidMode, aspectRatio)) Sys_LoadMenu(); } void CMenu::_launchGame(dir_discHdr *hdr, bool dvd) { - string id = string((const char *) hdr->id); + char id[7]; + strncpy(id, hdr->id, sizeof(id)); + + char path[256]; + strncpy(path, hdr->path, sizeof(path)); + Nand::Instance()->Disable_Emu(); if (dvd) @@ -1208,7 +1200,7 @@ void CMenu::_launchGame(dir_discHdr *hdr, bool dvd) /* Read GC disc header */ struct gc_discHdr *gcHeader = (struct gc_discHdr *)MEM2_alloc(sizeof(struct gc_discHdr)); Disc_ReadGCHeader(gcHeader); - memcpy(hdr->id, gcHeader->id, 6); + memcpy(id, gcHeader->id, 6); MEM2_free(gcHeader); /* Launching GC Game */ _launchGC(hdr, false); @@ -1299,8 +1291,8 @@ void CMenu::_launchGame(dir_discHdr *hdr, bool dvd) Nand::Instance()->Do_Region_Change(id); } } - - if (!dvd && get_frag_list((u8 *)hdr->id, (char *) hdr->path, currentPartition == 0 ? 0x200 : sector_size) < 0) + + if(!dvd && get_frag_list((u8 *)id, path, currentPartition == 0 ? 0x200 : sector_size) < 0) return; u8 patchVidMode = min((u32)m_gcfg2.getInt(id, "patch_video_modes", 0), ARRAY_SIZE(CMenu::_vidModePatch) - 1u); @@ -1310,7 +1302,7 @@ void CMenu::_launchGame(dir_discHdr *hdr, bool dvd) if ((debuggerselect || cheat) && hooktype == 0) hooktype = 1; if (!debuggerselect && !cheat) hooktype = 0; - if (id == "RPWE41" || id == "RPWZ41" || id == "SPXP41") // Prince of Persia, Rival Swords + if(strstr(id, "RPWE41") || strstr(id, "RPWZ41") || strstr(id, "SPXP41")) // Prince of Persia, Rival Swords debuggerselect = false; SmartBuf cheatFile, gameconfig; @@ -1322,38 +1314,36 @@ void CMenu::_launchGame(dir_discHdr *hdr, bool dvd) m_gcfg1.setUInt("LASTPLAYED", id, time(NULL)); if(has_enabled_providers() && _initNetwork() == 0) - add_game_to_card(id.c_str()); + add_game_to_card(id); int userIOS = 0; m_gcfg2.getInt(id, "ios", &userIOS); + setLanguage(language); + + if(cheat) + _loadFile(cheatFile, cheatSize, m_cheatDir.c_str(), fmt("%s.gct", id)); + _loadFile(gameconfig, gameconfigSize, m_txtCheatDir.c_str(), "gameconfig.txt"); + + load_wip_patches((u8 *)m_wipDir.c_str(), (u8 *) &id); + app_gameconfig_load((u8 *) &id, gameconfig.get(), gameconfigSize); + ocarina_load_code(cheatFile.get(), cheatSize); + u8 gameIOS = GetRequestedGameIOS(hdr); + m_gcfg1.save(true); m_gcfg2.save(true); m_cat.save(true); m_cfg.save(true); - - setLanguage(language); - - if(cheat) - _loadFile(cheatFile, cheatSize, m_cheatDir.c_str(), fmt("%s.gct", hdr->id)); - - _loadFile(gameconfig, gameconfigSize, m_txtCheatDir.c_str(), "gameconfig.txt"); - - load_wip_patches((u8 *)m_wipDir.c_str(), (u8 *) &hdr->id); - app_gameconfig_load((u8 *) &hdr->id, gameconfig.get(), gameconfigSize); - ocarina_load_code(cheatFile.get(), cheatSize); - - if (!m_use_wifi_gecko) - net_wc24cleanup(); + cleanup(); // wifi and sd gecko doesnt work anymore after cleanup bool iosLoaded = false; - if (!dvd) + if(!dvd) { - int result = _loadIOS(GetRequestedGameIOS(hdr), userIOS, id); - if (result == LOAD_IOS_FAILED) + int result = _loadIOS(gameIOS, userIOS, id); + if(result == LOAD_IOS_FAILED) return; - if (result == LOAD_IOS_SUCCEEDED) + if(result == LOAD_IOS_SUCCEEDED) iosLoaded = true; } @@ -1373,7 +1363,7 @@ void CMenu::_launchGame(dir_discHdr *hdr, bool dvd) { Nand::Instance()->Disable_Emu(); error(_t("errgame6", L"Enabling emu after reload failed!")); - if (iosLoaded) Sys_LoadMenu(); + Sys_LoadMenu(); return; } if(!DeviceHandler::Instance()->IsInserted(currentPartition)) @@ -1402,7 +1392,7 @@ void CMenu::_launchGame(dir_discHdr *hdr, bool dvd) if (!dvd) { - s32 ret = Disc_SetUSB((u8 *)hdr->id); + s32 ret = Disc_SetUSB((u8 *)id); if (ret < 0) { gprintf("Set USB failed: %d\n", ret); @@ -1420,13 +1410,6 @@ void CMenu::_launchGame(dir_discHdr *hdr, bool dvd) } IOSReloadBlock(IOS_GetVersion(), true); - while(net_get_status() == -EBUSY) - usleep(100); - - m_vid.CheckWaitThread(true); - cleanup(); - // wifi and sd gecko doesnt work anymore after cleanup - Close_Inputs(); USBStorage_Deinit(); if(currentPartition == 0) SDHC_Init(); diff --git a/source/menu/menu_main.cpp b/source/menu/menu_main.cpp index 0273d571..c6c91107 100644 --- a/source/menu/menu_main.cpp +++ b/source/menu/menu_main.cpp @@ -836,8 +836,10 @@ int CMenu::main(void) coverStatus = LWP_THREAD_NULL; if(coverstatus_stack.get()) coverstatus_stack.release(); + if(!m_reload) + return 0; cleanup(); - return m_reload ? 1 : 0; + return 1; } void CMenu::_initMainMenu(CMenu::SThemeData &theme) diff --git a/source/music/musicplayer.h b/source/music/musicplayer.h index 79af80df..3bae338a 100644 --- a/source/music/musicplayer.h +++ b/source/music/musicplayer.h @@ -19,6 +19,8 @@ class MusicPlayer { public: MusicPlayer(); + ~MusicPlayer(); + void cleanup(); void Init(Config &cfg, std::string musicDir, std::string themeMusicDir); void Tick(bool attenuate); @@ -36,8 +38,6 @@ public: bool IsStopped() { return m_stopped; }; private: - ~MusicPlayer(); - void LoadCurrentFile(); CachedList m_music_files;