From c778748bd17690dc6f0951ea0de02d41bf7b604a Mon Sep 17 00:00:00 2001 From: "fix94.1" Date: Wed, 26 Jun 2013 21:35:38 +0000 Subject: [PATCH] -fixed 2 disc gc game installations -added the 2 disc game re4 (thanks etheboss) -made the gc game installation more safe --- source/loader/gc_disc_dump.cpp | 72 ++++++++--------- source/loader/gc_disc_dump.hpp | 9 +-- source/menu/menu.hpp | 7 +- source/menu/menu_wbfs.cpp | 136 +++++++++++++++++---------------- 4 files changed, 114 insertions(+), 110 deletions(-) diff --git a/source/loader/gc_disc_dump.cpp b/source/loader/gc_disc_dump.cpp index 413df0b5..78204247 100644 --- a/source/loader/gc_disc_dump.cpp +++ b/source/loader/gc_disc_dump.cpp @@ -39,8 +39,8 @@ #include "gui/Gekko.h" #include "gui/text.hpp" #include "memory/mem2.hpp" +#include "menu/menu.hpp" #include "defines.h" - using namespace std; static u8 *FSTable ATTRIBUTE_ALIGN(32); @@ -86,9 +86,9 @@ s32 GCDump::__DiscReadRaw(void *outbuf, u64 offset, u32 length) gc_retry = 0; waitonerror = false; if(FSTTotal > FSTSize) - message(4, Disc+1, minfo, u_data); + mainMenu.GC_Messenger(4, Disc+1, minfo); else - message(3, 0, minfo, u_data); + mainMenu.GC_Messenger(3, 0, minfo); } if(gc_retry >= gc_nbrretry) { @@ -109,9 +109,9 @@ s32 GCDump::__DiscReadRaw(void *outbuf, u64 offset, u32 length) { __WaitForDisc(Disc, 11); if(FSTTotal > FSTSize) - message(4, Disc+1, minfo, u_data); + mainMenu.GC_Messenger(4, Disc+1, minfo); else - message(3, 0, minfo, u_data); + mainMenu.GC_Messenger(3, 0, minfo); } else { @@ -161,8 +161,7 @@ s32 GCDump::__DiscWriteFile(FILE *f, u64 offset, u32 length, u8 *ReadBuffer) offset += toread; length -= toread; gc_done += toread; - if(spinner) - spinner(gc_done/1024, DiscSizeCalculated, u_data); + mainMenu.GC_Refresh(gc_done/1024, DiscSizeCalculated); } return wrote; } @@ -177,7 +176,7 @@ bool GCDump::__WaitForDisc(u8 dsc, u32 msg) bool done = false; while(!done) { - message(msg, dsc+1, minfo, u_data); + mainMenu.GC_Messenger(msg, dsc+1, minfo); while(1) { wiiLightSetLevel(255); @@ -225,26 +224,26 @@ bool GCDump::__WaitForDisc(u8 dsc, u32 msg) } else if(ID == ID2 && Disc2 != dsc) { - message( 7, Disc2+1, NULL, u_data); + mainMenu.GC_Messenger( 7, Disc2+1, NULL); usleep( 5000000 ); break; } else if(ID != ID2) { - message( 8, 0, NULL, u_data); + mainMenu.GC_Messenger( 8, 0, NULL); usleep( 5000000 ); break; } } else if(Disc_IsWii() == 0) { - message( 5, 0, NULL, u_data); + mainMenu.GC_Messenger( 5, 0, NULL); usleep( 5000000 ); break; } else { - message( 6, 0, NULL, u_data); + mainMenu.GC_Messenger( 6, 0, NULL); usleep( 5000000 ); break; @@ -268,6 +267,7 @@ bool GCDump::__CheckMDHack(u32 ID) case 0x474b42: /*** Baten Kaitos: Eternal Wings and the Lost Ocean ***/ case 0x473341: /*** The Lord of the Rings: The Third Age ***/ case 0x473554: /*** Tiger Woods PGA Tour 2005 ***/ + case 0x473442: /*** Resident Evil 4 ***/ return true; break; default: @@ -297,6 +297,9 @@ s32 GCDump::DumpGame() memset(folder, 0, MAX_FAT_PATH); char gamepath[MAX_FAT_PATH]; memset(gamepath, 0, MAX_FAT_PATH); + char basedir[MAX_FAT_PATH]; + memset(basedir, 0, MAX_FAT_PATH); + strncpy(basedir, fmt((strncmp(gamepartition, "sd", 2) != 0) ? usb_dml_game_dir : DML_DIR, gamepartition), MAX_FAT_PATH); while(!gamedone) { @@ -314,26 +317,23 @@ s32 GCDump::DumpGame() } Asciify2(gc_hdr.title); - if(!Disc) + snprintf(folder, sizeof(folder), basedir); + if(!fsop_DirExist(folder)) { - snprintf(folder, sizeof(folder), fmt((strncmp(gamepartition, "sd", 2) != 0) ? usb_dml_game_dir : DML_DIR, gamepartition)); - if(!fsop_DirExist(folder)) - { - gprintf("Creating directory: %s\n", folder); - fsop_MakeFolder(folder); - } - memset(folder, 0, sizeof(folder)); - snprintf(folder, sizeof(folder), "%s/%s [%.06s]", fmt((strncmp(gamepartition, "sd", 2) != 0) ? usb_dml_game_dir : DML_DIR, gamepartition), gc_hdr.title, gc_hdr.id); - if(!fsop_DirExist(folder)) - { - gprintf("Creating directory: %s\n", folder); - fsop_MakeFolder(folder); - } - else - { - gprintf("Skipping game: %s (Already installed)(%d)\n", gc_hdr.title, Gamesize[MultiGameDump]); - break; - } + gprintf("Creating directory: %s\n", folder); + fsop_MakeFolder(folder); + } + memset(folder, 0, sizeof(folder)); + snprintf(folder, sizeof(folder), "%s/%s [%.06s]", basedir, gc_hdr.title, gc_hdr.id); + if(!fsop_DirExist(folder)) + { + gprintf("Creating directory: %s\n", folder); + fsop_MakeFolder(folder); + } + else if(!Disc) + { + gprintf("Skipping game: %s (Already installed)(%d)\n", gc_hdr.title, Gamesize[MultiGameDump]); + break; } ret = __DiscReadRaw(ReadBuffer, NextOffset, 0x440); @@ -379,9 +379,9 @@ s32 GCDump::DumpGame() snprintf(minfo, sizeof(minfo), "[%.06s] %s", gc_hdr.id, gc_hdr.title); if(FSTTotal > FSTSize) - message(4, Disc+1, minfo, u_data); + mainMenu.GC_Messenger(4, Disc+1, minfo); else - message(3, 0, minfo, u_data); + mainMenu.GC_Messenger(3, 0, minfo); gprintf("Dumping: %s %s\n", gc_hdr.title, compressed ? "compressed" : "full"); @@ -397,7 +397,7 @@ s32 GCDump::DumpGame() if(writeexfiles && !Disc) { memset(folder, 0, sizeof(folder)); - snprintf(folder, sizeof(folder), "%s/%s [%.06s]/sys", fmt((strncmp(gamepartition, "sd", 2) != 0) ? usb_dml_game_dir : DML_DIR, gamepartition), gc_hdr.title, gc_hdr.id); + snprintf(folder, sizeof(folder), "%s/%s [%.06s]/sys", basedir, gc_hdr.title, gc_hdr.id); if(!fsop_DirExist(folder)) { gprintf("Creating directory: %s\n", folder); @@ -417,7 +417,7 @@ s32 GCDump::DumpGame() gc_done += __DiscWrite(gamepath, 0x2440+NextOffset, ApploaderSize, ReadBuffer); } - snprintf(gamepath, sizeof(gamepath), "%s/%s [%.06s]/game.iso", fmt((strncmp(gamepartition, "sd", 2) != 0) ? usb_dml_game_dir : DML_DIR, gamepartition), gc_hdr.title, gc_hdr.id); + snprintf(gamepath, sizeof(gamepath), "%s/%s [%.06s]/game.iso", basedir, gc_hdr.title, gc_hdr.id); if(Disc) { char *ptz = strstr(gamepath, "game.iso"); @@ -586,7 +586,7 @@ s32 GCDump::CheckSpace(u32 *needed, bool comp) snprintf(minfo, sizeof(minfo), "[%.06s] %s", gc_hdr.id, gc_hdr.title); - message( 2, 0, minfo, u_data); + mainMenu.GC_Messenger(2, 0, minfo); if(writeexfiles) { diff --git a/source/loader/gc_disc_dump.hpp b/source/loader/gc_disc_dump.hpp index 94f9d4d5..93aaee54 100644 --- a/source/loader/gc_disc_dump.hpp +++ b/source/loader/gc_disc_dump.hpp @@ -69,7 +69,7 @@ struct FST class GCDump { public: - void Init(bool skip, bool comp, bool wexf, bool align, u32 nretry, u32 rsize, const char* partition, const char* m_DMLgameDir, progress_callback_t i_spinner, message_callback_t i_message, void *i_udata) + void Init(bool skip, bool comp, bool wexf, bool align, u32 nretry, u32 rsize, const char* partition, const char* m_DMLgameDir) { skiponerror = skip; compressed = comp; @@ -80,17 +80,12 @@ public: gamepartition = partition; usb_dml_game_dir = m_DMLgameDir; gc_skipped = 0; - spinner = i_spinner; - message = i_message; - u_data = i_udata; - waitonerror = true; + waitonerror = true; } s32 DumpGame( ); s32 CheckSpace(u32 *needed, bool comp); u32 GetFreeSpace(char *path, u32 Value); private: - progress_callback_t spinner; - message_callback_t message; void *u_data; bool force_32k_align; bool skiponerror; diff --git a/source/menu/menu.hpp b/source/menu/menu.hpp index 56eb17ce..354fff45 100644 --- a/source/menu/menu.hpp +++ b/source/menu/menu.hpp @@ -1023,6 +1023,8 @@ private: public: void _hideWaitMessage(); bool m_Emulator_boot; + void GC_Refresh(int status, int total); + void GC_Messenger(int message, int info, char *cinfo); private: GuiSound *_sound(CMenu::SoundSet &soundSet, const char *domain, const char *key, const u8 * snd, u32 len, const char *name, bool isAllocated); GuiSound *_sound(CMenu::SoundSet &soundSet, const char *domain, const char *key, const char *name); @@ -1059,11 +1061,10 @@ private: void LoadView(void); void _getGrabStatus(void); static void _addDiscProgress(int status, int total, void *user_data); - static void _Messenger(int message, int info, char *cinfo, void *user_data); static void _ShowProgress(int dumpstat, int dumpprog, int filestat, int fileprog, int files, int folders, const char *tmess, void *user_data); - static int _gameInstaller(void *obj); - static int _GCgameInstaller(void *obj); + static int _gameInstaller(void *obj); static int _GCcopyGame(void *obj); + int _GCgameInstaller(); float m_progress; float m_fprogress; int m_fileprog; diff --git a/source/menu/menu_wbfs.cpp b/source/menu/menu_wbfs.cpp index 68a6724d..99c3984c 100644 --- a/source/menu/menu_wbfs.cpp +++ b/source/menu/menu_wbfs.cpp @@ -88,33 +88,34 @@ static inline bool _searchGamesByID(const char *gameId) return false; } -void CMenu::_Messenger(int message, int info, char *cinfo, void *user_data) +void CMenu::GC_Messenger(int message, int info, char *cinfo) { - CMenu &m = *(CMenu *)user_data; - LWP_MutexLock(m.m_mutex); if(message == 1) - m._setThrdMsg(wfmt(m._fmt("wbfsop23", L"Calculating space needed for %s...\n Please insert disc %d to continue"), cinfo, info), m.m_progress); - if(message == 2) - m._setThrdMsg(wfmt(m._fmt("wbfsop15", L"Calculating space needed for %s"), cinfo), m.m_progress); - if(message == 3) - m._setThrdMsg(wfmt(m._fmt("wbfsop16", L"Installing %s"), cinfo), m.m_progress); - if(message == 4) - m._setThrdMsg(wfmt(m._fmt("wbfsop17", L"Installing %s disc %d/2"), cinfo, info), m.m_progress); - if(message == 5) - m._setThrdMsg(m._t("wbfsop18", L"Don't try to trick me with a Wii disc!!"), m.m_progress); - if(message == 6) - m._setThrdMsg(m._t("wbfsop19", L"This is not a GC disc!!"), m.m_progress); - if(message == 7) - m._setThrdMsg(wfmt(m._fmt("wbfsop20", L"You inserted disc %d again!!"), info), m.m_progress); - if(message == 8) - m._setThrdMsg(m._t("wbfsop21", L"This is a disc of another game!!"), m.m_progress); - if(message == 9) - m._setThrdMsg(wfmt(m._fmt("wbfsop22", L"Installing %s...\n Please insert disc 2 to continue"), cinfo), m.m_progress); - if(message == 10) - m._setThrdMsg(m._t("wbfsop25", L"Disc read error!! Please clean the disc"), m.m_progress); - if(message == 11) - m._setThrdMsg(m._t("wbfsop26", L"Disc ejected!! Please insert disc again"), m.m_progress); - LWP_MutexUnlock(m.m_mutex); + m_thrdMessage = wfmt(_fmt("wbfsop23", L"Calculating space needed for %s...\n Please insert disc %d to continue"), cinfo, info); + else if(message == 2) + m_thrdMessage = wfmt(_fmt("wbfsop15", L"Calculating space needed for %s"), cinfo); + else if(message == 3) + m_thrdMessage = wfmt(_fmt("wbfsop16", L"Installing %s"), cinfo); + else if(message == 4) + m_thrdMessage = wfmt(_fmt("wbfsop17", L"Installing %s disc %d/2"), cinfo, info); + else if(message == 5) + m_thrdMessage = _t("wbfsop18", L"Don't try to trick me with a Wii disc!!"); + else if(message == 6) + m_thrdMessage = _t("wbfsop19", L"This is not a GC disc!!"); + else if(message == 7) + m_thrdMessage = wfmt(_fmt("wbfsop20", L"You inserted disc %d again!!"), info); + else if(message == 8) + m_thrdMessage = _t("wbfsop21", L"This is a disc of another game!!"); + else if(message == 9) + m_thrdMessage = wfmt(_fmt("wbfsop22", L"Installing %s...\n Please insert disc 2 to continue"), cinfo); + else if(message == 10) + m_thrdMessage = _t("wbfsop25", L"Disc read error!! Please clean the disc"); + else if(message == 11) + m_thrdMessage = _t("wbfsop26", L"Disc ejected!! Please insert disc again"); + + if(!m_thrdMessage.empty()) + m_btnMgr.setText(m_wbfsLblDialog, m_thrdMessage); + _mainLoopCommon(); } int CMenu::_gameInstaller(void *obj) @@ -159,29 +160,28 @@ int CMenu::_gameInstaller(void *obj) return ret; } -int CMenu::_GCgameInstaller(void *obj) +int CMenu::_GCgameInstaller() { - CMenu &m = *(CMenu *)obj; GCDump m_gcdump; - bool skip = m.m_cfg.getBool(GC_DOMAIN, "skip_on_error", false); - bool comp = m.m_cfg.getBool(GC_DOMAIN, "compressed_dump", false); - bool wexf = m.m_cfg.getBool(GC_DOMAIN, "write_ex_files", true); - bool alig = m.m_cfg.getBool(GC_DOMAIN, "force_32k_align_files", false); - u32 nretry = m.m_cfg.getUInt(GC_DOMAIN, "num_retries", 5); + bool skip = m_cfg.getBool(GC_DOMAIN, "skip_on_error", false); + bool comp = m_cfg.getBool(GC_DOMAIN, "compressed_dump", false); + bool wexf = m_cfg.getBool(GC_DOMAIN, "write_ex_files", true); + bool alig = m_cfg.getBool(GC_DOMAIN, "force_32k_align_files", false); + u32 nretry = m_cfg.getUInt(GC_DOMAIN, "num_retries", 5); u32 rsize = 1048576; //1MB if(skip) rsize = 8192; // Use small chunks when skip on error is enabled - m_gcdump.Init(skip, comp, wexf, alig, nretry, rsize,DeviceName[currentPartition],m.m_DMLgameDir.c_str(), _addDiscProgress, _Messenger, obj); + m_gcdump.Init(skip, comp, wexf, alig, nretry, rsize, DeviceName[currentPartition], m_DMLgameDir.c_str()); - int ret; - m.m_progress = 0.f; + int ret; + m_progress = 0.f; if(!DeviceHandle.IsInserted(currentPartition)) { - m.m_thrdWorking = false; + m_thrdWorking = false; return -1; } @@ -193,40 +193,34 @@ int CMenu::_GCgameInstaller(void *obj) ret = m_gcdump.CheckSpace(&needed, comp); if(ret != 0) { - m._setThrdMsg(m._t("wbfsop9", L"An error has occurred"), 1.f); - m.m_thrdWorking = false; + _setThrdMsg(_t("wbfsop9", L"An error has occurred"), 1.f); + m_thrdWorking = false; return ret; } if(m_gcdump.GetFreeSpace(partition, BL) <= needed) { gprintf("Free space available: %d Mb (%d blocks)\n", m_gcdump.GetFreeSpace(partition, MB), m_gcdump.GetFreeSpace(partition, BL)); - LWP_MutexLock(m.m_mutex); - m._setThrdMsg(wfmt(m._fmt("wbfsop24", L"Not enough space: %d blocks needed, %d available"), needed, m_gcdump.GetFreeSpace(partition, BL)), 0.f); - LWP_MutexUnlock(m.m_mutex); + _setThrdMsg(wfmt(_fmt("wbfsop24", L"Not enough space: %d blocks needed, %d available"), needed, m_gcdump.GetFreeSpace(partition, BL)), 0.f); ret = -1; } else { gprintf("Free space available: %d Mb (%d blocks)\n", m_gcdump.GetFreeSpace(partition, MB), m_gcdump.GetFreeSpace(partition, BL)); - LWP_MutexLock(m.m_mutex); - m._setThrdMsg(L"", 0); - LWP_MutexUnlock(m.m_mutex); + _setThrdMsg(L"", 0); ret = m_gcdump.DumpGame(); - LWP_MutexLock(m.m_mutex); if(ret == 0) - m._setThrdMsg(m._t("wbfsop8", L"Game installed"), 1.f); + _setThrdMsg(_t("wbfsop8", L"Game installed"), 1.f); else if( ret >= 0x30200) - m._setThrdMsg(wfmt(m._fmt("wbfsop12", L"DVDError(%d)"), ret), 1.f); + _setThrdMsg(wfmt(_fmt("wbfsop12", L"DVDError(%d)"), ret), 1.f); else if( ret > 0) - m._setThrdMsg(wfmt(m._fmt("wbfsop13", L"Game installed, but disc contains errors (%d)"), ret), 1.f); + _setThrdMsg(wfmt(_fmt("wbfsop13", L"Game installed, but disc contains errors (%d)"), ret), 1.f); else - m._setThrdMsg(m._t("wbfsop9", L"An error has occurred"), 1.f); - LWP_MutexUnlock(m.m_mutex); + _setThrdMsg(_t("wbfsop9", L"An error has occurred"), 1.f); slotLight(true); } - m.m_thrdWorking = false; + m_thrdWorking = false; return ret; } @@ -321,14 +315,14 @@ bool CMenu::_wbfsOp(CMenu::WBFS_OP op) case WO_ADD_GAME: MusicPlayer.Stop(); TempLoadIOS(); - m_btnMgr.hide(m_configLblPartitionName); - m_btnMgr.hide(m_configLblPartition); - m_btnMgr.hide(m_configBtnPartitionP); - m_btnMgr.hide(m_configBtnPartitionM); - m_btnMgr.show(m_wbfsPBar); - m_btnMgr.setProgress(m_wbfsPBar, 0.f); - m_btnMgr.hide(m_wbfsBtnGo); - m_btnMgr.show(m_wbfsLblMessage); + m_btnMgr.hide(m_configLblPartitionName, true); + m_btnMgr.hide(m_configLblPartition, true); + m_btnMgr.hide(m_configBtnPartitionP, true); + m_btnMgr.hide(m_configBtnPartitionM, true); + m_btnMgr.show(m_wbfsPBar, true); + m_btnMgr.setProgress(m_wbfsPBar, 0.f, true); + m_btnMgr.hide(m_wbfsBtnGo, true); + m_btnMgr.show(m_wbfsLblMessage, true); m_btnMgr.setText(m_wbfsLblMessage, L""); if (Disc_Wait() < 0) { @@ -378,7 +372,8 @@ bool CMenu::_wbfsOp(CMenu::WBFS_OP op) m_thrdWorking = true; m_thrdProgress = 0.f; m_thrdMessageAdded = false; - LWP_CreateThread(&thread, (void *(*)(void *))_GCgameInstaller, (void *)this, 0, 8 * 1024, 64); + //LWP_CreateThread(&thread, (void *(*)(void *))_GCgameInstaller, (void *)this, 0, 8 * 1024, 64); + _GCgameInstaller(); } else { @@ -447,10 +442,10 @@ bool CMenu::_wbfsOp(CMenu::WBFS_OP op) _setThrdMsg(wfmt(_fmt("wbfsop24", L"Not enough space: %d blocks needed, %d available"), fsop_GetFolderKb(GC_Path.c_str()), fsop_GetFreeSpaceKb("sd:/")), 0.f); break; } - m_btnMgr.show(m_wbfsPBar); - m_btnMgr.setProgress(m_wbfsPBar, 0.f); - m_btnMgr.hide(m_wbfsBtnGo); - m_btnMgr.show(m_wbfsLblMessage); + m_btnMgr.show(m_wbfsPBar, true); + m_btnMgr.setProgress(m_wbfsPBar, 0.f, true); + m_btnMgr.hide(m_wbfsBtnGo, true); + m_btnMgr.show(m_wbfsLblMessage, true); m_btnMgr.setText(m_wbfsLblMessage, L""); strncpy(cfPos, CF_Hdr->id, 6); m_btnMgr.setText(m_wbfsLblDialog, wfmt(_fmt("wbfsop10", L"Copying [%s] %s..."), CF_Hdr->id, CoverFlow.getTitle().toUTF8().c_str())); @@ -542,3 +537,16 @@ void CMenu::_textWBFS(void) { m_btnMgr.setText(m_wbfsBtnGo, _t("wbfsop5", L"Go")); } + +void CMenu::GC_Refresh(int status, int total) +{ + m_progress = (float)status / (float)total; + // Don't synchronize too often + if(m_progress - m_thrdProgress >= 0.01f) + { + m_thrdProgress = m_progress; + m_btnMgr.setProgress(m_wbfsPBar, m_thrdProgress); + m_btnMgr.setText(m_wbfsLblMessage, wfmt(L"%i%%", (int)(m_thrdProgress * 100.f))); + _mainLoopCommon(); + } +}