From f8c169280936a44c4a8f148b1b008f226e46ebac Mon Sep 17 00:00:00 2001 From: dimok321 <15055714+dimok789@users.noreply.github.com> Date: Fri, 24 Sep 2010 13:46:32 +0000 Subject: [PATCH] little optimization --- HBC/META.XML | 4 +- gui.pnproj | 2 +- gui.pnps | 2 +- source/fatmounter.h | 44 +++---- source/lstub.cpp | 2 +- source/main.cpp | 6 +- source/menu.cpp | 4 +- source/prompts/TitleBrowser.cpp | 60 ++++----- source/settings/Settings.cpp | 12 +- source/system/IosLoader.cpp | 215 +++++++++++++++----------------- source/system/IosLoader.h | 32 ++--- source/wad/nandtitle.cpp | 2 + source/wad/nandtitle.h | 3 +- source/wad/wad.cpp | 2 +- 14 files changed, 186 insertions(+), 204 deletions(-) diff --git a/HBC/META.XML b/HBC/META.XML index 59b450fe..0b2c1924 100644 --- a/HBC/META.XML +++ b/HBC/META.XML @@ -2,8 +2,8 @@ USB Loader GX USB Loader GX Team - 1.0 r966 - 201009241157 + 1.0 r967 + 201009241313 Loads games from USB-devices USB Loader GX is a libwiigui based USB iso loader with a wii-like GUI. You can install games to your HDDs and boot them with shorter loading times. The interactive GUI is completely controllable with WiiMote, Classic Controller or GC Controller. diff --git a/gui.pnproj b/gui.pnproj index 172a1b4d..6e426dc1 100644 --- a/gui.pnproj +++ b/gui.pnproj @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/gui.pnps b/gui.pnps index 37a2c6da..4814308e 100644 --- a/gui.pnps +++ b/gui.pnps @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/source/fatmounter.h b/source/fatmounter.h index 79a00034..15dd2368 100644 --- a/source/fatmounter.h +++ b/source/fatmounter.h @@ -6,30 +6,32 @@ extern "C" { #endif - extern int fat_sd_mount; - extern sec_t fat_sd_sec; - extern int fat_usb_mount; - extern sec_t fat_usb_sec; - extern int fat_wbfs_mount; - extern sec_t fat_wbfs_sec; +#include - int USBDevice_Init(); - void USBDevice_deInit(); - int WBFSDevice_Init(u32 sector); - void WBFSDevice_deInit(); - int isInserted(const char *path); - int SDCard_Init(); - void SDCard_deInit(); +extern int fat_sd_mount; +extern sec_t fat_sd_sec; +extern int fat_usb_mount; +extern sec_t fat_usb_sec; +extern int fat_wbfs_mount; +extern sec_t fat_wbfs_sec; - s32 MountNTFS(u32 sector); - s32 UnmountNTFS(void); +int USBDevice_Init(); +void USBDevice_deInit(); +int WBFSDevice_Init(u32 sector); +void WBFSDevice_deInit(); +int isInserted(const char *path); +int SDCard_Init(); +void SDCard_deInit(); - extern int fat_usb_mount; - extern sec_t fat_usb_sec; - extern int fat_wbfs_mount; - extern sec_t fat_wbfs_sec; - extern int fs_ntfs_mount; - extern sec_t fs_ntfs_sec; +s32 MountNTFS(u32 sector); +s32 UnmountNTFS(void); + +extern int fat_usb_mount; +extern sec_t fat_usb_sec; +extern int fat_wbfs_mount; +extern sec_t fat_wbfs_sec; +extern int fs_ntfs_mount; +extern sec_t fs_ntfs_sec; #ifdef __cplusplus } diff --git a/source/lstub.cpp b/source/lstub.cpp index fc78b35e..1b65b417 100644 --- a/source/lstub.cpp +++ b/source/lstub.cpp @@ -29,7 +29,7 @@ static char* determineStubTIDLocation() s32 Set_Stub(u64 reqID) { - if (titles.IndexOf(reqID) < 0) return WII_EINSTALL; + if (NandTitles.IndexOf(reqID) < 0) return WII_EINSTALL; char *stub = determineStubTIDLocation(); if (!stub) return -68; diff --git a/source/main.cpp b/source/main.cpp index 793f95b9..e37672a5 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -58,7 +58,6 @@ extern bool geckoinit; extern char headlessID[8]; char bootDevice[10]; -NandTitle titles; PartList partitions; int main(int argc, char *argv[]) @@ -70,7 +69,7 @@ int main(int argc, char *argv[]) __exception_setreload(20); printf("\tStarting up\n"); - titles.Get(); + NandTitles.Get(); bool bootDevice_found = false; if (argc >= 1) @@ -109,8 +108,7 @@ int main(int argc, char *argv[]) printf("done\n"); // Let's load the cIOS now - IosLoader loader(titles); - if (loader.LoadAppCios() < 0) + if (IosLoader::LoadAppCios() < 0) { printf("\n\tWARNING!\n"); printf("\tUSB Loader GX needs unstubbed cIOS 222 v4 or 249 v9+\n\n"); diff --git a/source/menu.cpp b/source/menu.cpp index 8d89358d..6ea8c491 100644 --- a/source/menu.cpp +++ b/source/menu.cpp @@ -612,8 +612,8 @@ int MainMenu(int menu) u32 channel = 0; if (returnToLoaderGV) { - int idx = titles.FindU32(Settings.returnTo); - if (idx >= 0) channel = TITLE_LOWER( titles.At( idx ) ); + int idx = NandTitles.FindU32(Settings.returnTo); + if (idx >= 0) channel = TITLE_LOWER( NandTitles.At( idx ) ); } //This is temporary diff --git a/source/prompts/TitleBrowser.cpp b/source/prompts/TitleBrowser.cpp index 13a1bbda..0fb8ea28 100644 --- a/source/prompts/TitleBrowser.cpp +++ b/source/prompts/TitleBrowser.cpp @@ -59,19 +59,19 @@ bool TitleSelector(char output[]) ISFS_Initialize();//initialize for "titles.Exists()" // Get count of titles of the good titles - num_titles = titles.SetType(0x10001); + num_titles = NandTitles.SetType(0x10001); u32 n = num_titles; //gprintf("num_titles: %u\n", num_titles ); for (u32 i = 0; i < n; i++) { - u64 tid = titles.Next(); + u64 tid = NandTitles.Next(); if (!tid) { break; } //remove ones not actually installed on the nand - if (!titles.Exists(tid)) + if (!NandTitles.Exists(tid)) { num_titles--; } @@ -89,29 +89,29 @@ bool TitleSelector(char output[]) //write the titles on the option browser s32 i = 0; - titles.SetType(0x10001); + NandTitles.SetType(0x10001); while (i < num_titles) { - u64 tid = titles.Next(); + u64 tid = NandTitles.Next(); if (!tid) { gprintf("shit happened\n"); break; } - if (!titles.Exists(tid)) + if (!NandTitles.Exists(tid)) { continue; } char id[5]; - titles.AsciiTID(tid, (char*) &id); + NandTitles.AsciiTID(tid, (char*) &id); - const char* name = titles.NameOf(tid); + const char* name = NandTitles.NameOf(tid); //gprintf("%016llx: %s: %s\n%p\t%p\n", tid, id, name, &id, name ); options4.SetName(i, "%s", id); - options4.SetValue(i, "%s", name ? titles.NameOf(tid) : tr( "Unknown" )); + options4.SetValue(i, "%s", name ? NandTitles.NameOf(tid) : tr( "Unknown" )); titleList[i] = tid; i++; } @@ -238,29 +238,29 @@ int TitleBrowser() ISFS_Initialize();//initialize for "titles.Exists()" // Get count of titles of the good titles - num_titles = titles.SetType(0x10001); + num_titles = NandTitles.SetType(0x10001); u32 n = num_titles; for (u32 i = 0; i < n; i++) { - u64 tid = titles.Next(); + u64 tid = NandTitles.Next(); if (!tid) { break; } //remove ones not actually installed on the nand - if (!titles.Exists(tid)) + if (!NandTitles.Exists(tid)) { num_titles--; } } // Get count of system titles - num_sys_titles = titles.SetType(0x10002); + num_sys_titles = NandTitles.SetType(0x10002); n = num_sys_titles; for (u32 i = 0; i < n; i++) { - u64 tid = titles.Next(); + u64 tid = NandTitles.Next(); if (!tid) { break; @@ -273,7 +273,7 @@ int TitleBrowser() } //these aren't installed on the nand - if (!titles.Exists(tid)) + if (!NandTitles.Exists(tid)) { num_sys_titles--; } @@ -290,55 +290,55 @@ int TitleBrowser() //write the titles on the option browser u32 i = 0; - titles.SetType(0x10001); + NandTitles.SetType(0x10001); //first add the good stuff while (i < num_titles) { - u64 tid = titles.Next(); + u64 tid = NandTitles.Next(); if (!tid) { gprintf("shit happened3\n"); break; } - gprintf("[ %u ] tid: %016llx\t%s\n", i, tid, titles.NameOf(tid)); + gprintf("[ %u ] tid: %016llx\t%s\n", i, tid, NandTitles.NameOf(tid)); - if (!titles.Exists(tid)) + if (!NandTitles.Exists(tid)) { continue; } char id[5]; - titles.AsciiTID(tid, (char*) &id); + NandTitles.AsciiTID(tid, (char*) &id); - const char* name = titles.NameOf(tid); + const char* name = NandTitles.NameOf(tid); options3.SetName(i, "%s", id); - options3.SetValue(i, "%s", name ? titles.NameOf(tid) : tr( "Unknown" )); + options3.SetValue(i, "%s", name ? NandTitles.NameOf(tid) : tr( "Unknown" )); titleList[i] = tid; i++; } - titles.SetType(0x10002); + NandTitles.SetType(0x10002); while (i < num_sys_titles + num_titles) { - u64 tid = titles.Next(); + u64 tid = NandTitles.Next(); if (!tid) { break; } if (TITLE_LOWER( tid ) == 0x48414741 || TITLE_LOWER( tid ) == 0x48414141 || TITLE_LOWER( tid ) == 0x48414641) continue; - if (!titles.Exists(tid)) + if (!NandTitles.Exists(tid)) { continue; } char id[5]; - titles.AsciiTID(tid, (char*) &id); - const char* name = titles.NameOf(tid); + NandTitles.AsciiTID(tid, (char*) &id); + const char* name = NandTitles.NameOf(tid); options3.SetName(i, "%s", id); - options3.SetValue(i, "%s", name ? titles.NameOf(tid) : tr( "Unknown" )); + options3.SetValue(i, "%s", name ? NandTitles.NameOf(tid) : tr( "Unknown" )); titleList[i] = tid; i++; } @@ -470,9 +470,9 @@ int TitleBrowser() //set the title's name, number, ID to text char text[0x100]; char id[5]; - titles.AsciiTID(titleList[ret], (char*) &id); + NandTitles.AsciiTID(titleList[ret], (char*) &id); - snprintf(text, sizeof(text), "%s : %s", id, titles.NameOf(titleList[ret])); + snprintf(text, sizeof(text), "%s : %s", id, NandTitles.NameOf(titleList[ret])); //prompt to boot selected title if (WindowPrompt(tr( "Boot?" ), text, tr( "OK" ), tr( "Cancel" ))) diff --git a/source/settings/Settings.cpp b/source/settings/Settings.cpp index 21254eeb..252810e5 100644 --- a/source/settings/Settings.cpp +++ b/source/settings/Settings.cpp @@ -1045,8 +1045,8 @@ int MenuSettings() Settings.cios = 222; break; } - if ((Settings.cios == 222 && titles.VersionOf(0x1000000deULL) != 4) - || (Settings.cios == 2 && titles.VersionOf(0x1000000dfULL) != 4)) + if ((Settings.cios == 222 && NandTitles.VersionOf(0x1000000deULL) != 4) + || (Settings.cios == 2 && NandTitles.VersionOf(0x1000000dfULL) != 4)) { WindowPrompt( tr( "Hermes CIOS" ), @@ -1135,10 +1135,10 @@ int MenuSettings() snprintf(Settings.returnTo, sizeof(Settings.returnTo), "%s", tidChar); } } - int haveTitle = titles.FindU32(Settings.returnTo); + int haveTitle = NandTitles.FindU32(Settings.returnTo); if (haveTitle >= 0) { - name = (char*) titles.NameFromIndex(haveTitle); + name = (char*) NandTitles.NameFromIndex(haveTitle); if (!strlen(name)) name = NULL; } options2.SetValue(Idx, "%s", name ? name : tr( opts_off_on[ 0 ] )); @@ -2719,12 +2719,12 @@ int GameSettings(struct discHdr * header) if (ret == Idx && ++returnToLoaderGV >= settings_off_on_max) returnToLoaderGV = 0; char text[IMET_MAX_NAME_LEN]; - int channel = titles.FindU32(Settings.returnTo);//is the channel set in the global settings actually installed? + int channel = NandTitles.FindU32(Settings.returnTo);//is the channel set in the global settings actually installed? if (!returnToLoaderGV || channel < 0)//channel is not installed or the uer wants to not use it sprintf(text, "%s", tr( opts_off_on[ 0 ] )); - else snprintf(text, sizeof(text), "%s", titles.NameFromIndex(channel)); + else snprintf(text, sizeof(text), "%s", NandTitles.NameFromIndex(channel)); options2.SetValue(Idx, "%s", text); } diff --git a/source/system/IosLoader.cpp b/source/system/IosLoader.cpp index dbfe97cc..a20d9969 100644 --- a/source/system/IosLoader.cpp +++ b/source/system/IosLoader.cpp @@ -1,115 +1,100 @@ -#include - -#include "IosLoader.h" -#include "../fatmounter.h" -#include "../usbloader/usbstorage2.h" -#include "../wad/nandtitle.h" -#include "../mload/mload_modules.h" -#include "../settings/CSettings.h" - -/****************************************************************************** - * Construction/Destruction: - ******************************************************************************/ - -/* Initializes a new instance of the IosLoader class. */ -IosLoader::IosLoader(NandTitle titles) -{ - nandTitles = titles; -} - -/* Finalizes an instance of the IosLoader class. */ -IosLoader::~IosLoader() -{ -} - -/****************************************************************************** - * Public Methods: - ******************************************************************************/ - -/* - * Loads CIOS (If possible the one from the settings file). - * @return 0 if a cios has been successfully loaded. Else a value below 0 is returned. - */ -s32 IosLoader::LoadAppCios() -{ - s32 ret = -1; - - // Unmount devices before reloading IOS. - SDCard_deInit(); - USBDevice_deInit(); - USBStorage2_Deinit(); - - u32 ciosLoadPriority[] = { 250, 249, 222, Settings.cios }; // Descending. - u32 activeCios = IOS_GetVersion(); - - - for (u8 i=(sizeof(ciosLoadPriority)/sizeof(ciosLoadPriority[0])); i>=0; i--) - { - u32 cios = ciosLoadPriority[i]; - - if (activeCios == cios) - { - ret = 0; - break; - } - - if ((ret = ReloadIosSafe(cios)) > -1) - { - // Remember working cios. - Settings.cios = cios; - break; - } - } - - // Remount devices after reloading IOS. - SDCard_Init(); - if (IOS_GetVersion() == 222) load_ehc_module(); - USBDevice_Init(); - - return ret; -} - -/****************************************************************************** - * Private/Protected Methods: - ******************************************************************************/ - -/* - * Reloads a certain IOS under the condition, that an appropriate version of the IOS is installed. - * @return a negative value if a safe reload of the ios was not possible. - */ -s32 IosLoader::ReloadIosSafe(s32 ios) -{ - switch (ios) - { - case 222: - { - s32 ios222rev = nandTitles.VersionOf(0x1000000deULL); - if (ios222rev == 4 || ios222rev == 5 || ios222rev == 65535) break; - return -2; - } - case 223: - { - s32 ios223rev = nandTitles.VersionOf(0x1000000dfULL); - if (ios223rev == 4 || ios223rev == 5 || ios223rev == 65535) break; - return -2; - } - case 249: - { - s32 ios249rev = nandTitles.VersionOf(0x1000000f9ULL); - if (ios249rev < 9 || ios249rev == 65280) return -2; - break; - } - case 250: - { - s32 ios250rev = nandTitles.VersionOf(0x1000000faULL); - if (ios250rev < 9 || ios250rev == 65280) return -2; - break; - } - default: - return -3; - } - - s32 r = IOS_ReloadIOS(ios); - if (r >= 0) WII_Initialize(); - return r; -} +#include + +#include "IosLoader.h" +#include "../fatmounter.h" +#include "../usbloader/usbstorage2.h" +#include "../wad/nandtitle.h" +#include "../mload/mload_modules.h" +#include "../settings/CSettings.h" +#include "wad/nandtitle.h" + +/****************************************************************************** + * Public Methods: + ******************************************************************************/ +/* + * Loads CIOS (If possible the one from the settings file). + * @return 0 if a cios has been successfully loaded. Else a value below 0 is returned. + */ +s32 IosLoader::LoadAppCios() +{ + s32 ret = -1; + + // Unmount devices before reloading IOS. + SDCard_deInit(); + USBDevice_deInit(); + USBStorage2_Deinit(); + + u32 ciosLoadPriority[] = { 250, 249, 222, Settings.cios }; // Descending. + u32 activeCios = IOS_GetVersion(); + + + for (u8 i=(sizeof(ciosLoadPriority)/sizeof(ciosLoadPriority[0])); i>=0; i--) + { + u32 cios = ciosLoadPriority[i]; + + if (activeCios == cios) + { + ret = 0; + break; + } + + if ((ret = ReloadIosSafe(cios)) > -1) + { + // Remember working cios. + Settings.cios = cios; + break; + } + } + + // Remount devices after reloading IOS. + SDCard_Init(); + if (IOS_GetVersion() == 222) load_ehc_module(); + USBDevice_Init(); + + return ret; +} + +/****************************************************************************** + * Private/Protected Methods: + ******************************************************************************/ + +/* + * Reloads a certain IOS under the condition, that an appropriate version of the IOS is installed. + * @return a negative value if a safe reload of the ios was not possible. + */ +s32 IosLoader::ReloadIosSafe(s32 ios) +{ + switch (ios) + { + case 222: + { + s32 ios222rev = NandTitles.VersionOf(0x1000000deULL); + if (ios222rev == 4 || ios222rev == 5 || ios222rev == 65535) break; + return -2; + } + case 223: + { + s32 ios223rev = NandTitles.VersionOf(0x1000000dfULL); + if (ios223rev == 4 || ios223rev == 5 || ios223rev == 65535) break; + return -2; + } + case 249: + { + s32 ios249rev = NandTitles.VersionOf(0x1000000f9ULL); + if (ios249rev < 9 || ios249rev == 65280) return -2; + break; + } + case 250: + { + s32 ios250rev = NandTitles.VersionOf(0x1000000faULL); + if (ios250rev < 9 || ios250rev == 65280) return -2; + break; + } + default: + return -3; + } + + s32 r = IOS_ReloadIOS(ios); + if (r >= 0) WII_Initialize(); + return r; +} diff --git a/source/system/IosLoader.h b/source/system/IosLoader.h index 5a59f8db..da9b47f5 100644 --- a/source/system/IosLoader.h +++ b/source/system/IosLoader.h @@ -1,19 +1,13 @@ -#ifndef _IOSLOADER_H_ -#define _IOSLOADER_H_ - -#include -#include "../wad/nandtitle.h" - -class IosLoader -{ - public: - IosLoader(NandTitle titles); - ~IosLoader(); - s32 CheckForCios(); - s32 LoadAppCios(); - private: - NandTitle nandTitles; - s32 ReloadIosSafe(s32 ios); -}; - -#endif +#ifndef _IOSLOADER_H_ +#define _IOSLOADER_H_ + +#include + +class IosLoader +{ + public: + static s32 LoadAppCios(); + static s32 ReloadIosSafe(s32 ios); +}; + +#endif diff --git a/source/wad/nandtitle.cpp b/source/wad/nandtitle.cpp index b4587757..9963fbfd 100644 --- a/source/wad/nandtitle.cpp +++ b/source/wad/nandtitle.cpp @@ -1,6 +1,8 @@ #include "nandtitle.h" #include "gecko.h" +NandTitle NandTitles; + extern "C" { extern s32 MagicPatches(s32); diff --git a/source/wad/nandtitle.h b/source/wad/nandtitle.h index be270115..27584314 100644 --- a/source/wad/nandtitle.h +++ b/source/wad/nandtitle.h @@ -108,5 +108,6 @@ class NandTitle u32 currentType; }; -extern NandTitle titles; +extern NandTitle NandTitles; + #endif // NANDTITLE_H diff --git a/source/wad/wad.cpp b/source/wad/wad.cpp index 9b1fb95c..9760ad13 100644 --- a/source/wad/wad.cpp +++ b/source/wad/wad.cpp @@ -560,7 +560,7 @@ s32 Wad_Uninstall(FILE *fp) msg2Txt.SetText(tr( ">> Deleting tickets..." )); // Get ticket views - ret = titles.GetTicketViews(tid, &viewData, &viewCnt); + ret = NandTitles.GetTicketViews(tid, &viewData, &viewCnt); if (ret < 0) { char errTxt[50];