s32 DeviceHandler::OpenWBFS(int dev) { u32 part_lba, part_idx = 1; u32 part_fs = GetFSType(dev); const char *partition = DeviceName[dev]; if(dev == SD && IsInserted(dev)) part_lba = sd.GetLBAStart(dev); else if(dev >= USB1 && dev <= USB8 && IsInserted(dev)) { part_idx = dev; part_lba = usb.GetLBAStart(dev - USB1); } else return -1; return WBFS_Init(GetWbfsHandle(dev), part_fs, part_idx, part_lba, partition); }
int Sys_IosReload(int IOS) { s32 ret = -1; //shutdown SD and USB before IOS Reload in DiscWait SDCard_deInit(); USBDevice_deInit(); WPAD_Flush(0); WPAD_Disconnect(0); WPAD_Shutdown(); WDVD_Close(); USBStorage_Deinit(); if (IOS == 249 || IOS == 222 || IOS == 223) { int i; for (i = 0; i < 10; i++) { ret = IOS_ReloadIOS(IOS); if (ret < 0) return ret; if (IOS == 222 || IOS == 223) load_ehc_module(); ret = WBFS_Init(WBFS_DEVICE_USB); if (!(ret < 0)) break; sleep(1); USBStorage_Deinit(); } if (ret>=0) { ret = Disc_Init(); if (ret>=0) { ret = WBFS_Open(); } } else Sys_BackToLoader(); } PAD_Init(); Wpad_Init(); WPAD_SetDataFormat(WPAD_CHAN_ALL,WPAD_FMT_BTNS_ACC_IR); // WPAD_SetVRes(WPAD_CHAN_ALL, screenwidth, screenheight); //reinitialize SD and USB SDCard_Init(); USBDevice_Init(); return ret; }
int Sys_ChangeIos(int ios) { s32 prevIos = IOS_GetVersion(); SDCard_deInit(); USBDevice_deInit(); WPAD_Flush(0); WPAD_Disconnect(0); WPAD_Shutdown(); WDVD_Close(); USBStorage2_Deinit(); s32 ret = IOS_ReloadIOSsafe(ios); if (ret < 0) { ios = prevIos; } SDCard_Init(); if (ios == 222 || ios == 223) { load_ehc_module(); } USBDevice_Init(); PAD_Init(); Wpad_Init(); WPAD_SetDataFormat(WPAD_CHAN_ALL,WPAD_FMT_BTNS_ACC_IR); WPAD_SetVRes(WPAD_CHAN_ALL, screenwidth, screenheight); WBFS_Init(WBFS_DEVICE_USB); Disc_Init(); if (Sys_IsHermes()) { WBFS_OpenNamed((char *) &game_partition); } else { WBFS_Open(); } return ret; }
void Menu_Boot() { struct discHdr *header; bool gc = false; header = &gameList[gameSelected]; s32 ret; struct Game_CFG_2 *game_cfg = NULL; /* Clear console */ if (!CFG.direct_launch) { Con_Clear(); } FgColor(CFG.color_header); printf_x(gt("Start this game?")); printf("\n\n"); DefaultColor(); game_cfg = CFG_find_game(header->id); // Get game size gc = header->magic == GC_MAGIC; bool do_skip = !CFG.confirm_start; /* SoundInfo snd; u8 banner_title[84]; memset(banner_title, 0, 84); memset(&snd, 0, sizeof(snd)); WBFS_Banner(header->id, &snd, banner_title, !do_skip, CFG_read_active_game_setting(header->id).write_playlog); */ if (do_skip) { goto skip_confirm; } printf("\n"); /* Show game info */ printf_("%s\n", get_title(header)); printf_("(%.6s)\n\n", header->id); __Menu_ShowGameInfo(true, header->id); /* load game info from XML */ printf("\n"); //Does DL warning apply to launching discs too? Not sure printf_h(gt("Press %s button to continue."), (button_names[CFG.button_confirm.num])); printf("\n"); printf_h(gt("Press %s button to go back."), (button_names[CFG.button_cancel.num])); if (!gc) { printf("\n"); printf_h(gt("Press %s button for options."), (button_names[CFG.button_other.num])); } printf("\n\n"); __console_flush(0); // play banner sound /* if (snd.dsp_data) { SND_PauseVoice(0, 1); // pause mp3 int fmt = (snd.channels == 2) ? VOICE_STEREO_16BIT : VOICE_MONO_16BIT; SND_SetVoice(1, fmt, snd.rate, 0, snd.dsp_data, snd.size, 255,255, //volume,volume, NULL); //DataTransferCallback } */ /* Wait for user answer */ u32 buttons; for (;;) { buttons = Wpad_WaitButtons(); if (buttons & CFG.button_confirm.mask) break; if (buttons & CFG.button_cancel.mask) break; if (!gc && (buttons & CFG.button_other.mask)) break; if (buttons & CFG.button_exit.mask) break; } /* // stop banner sound, resume mp3 if (snd.dsp_data) { SND_StopVoice(1); SAFE_FREE(snd.dsp_data); if (buttons & CFG.button_confirm.mask) { SND_ChangeVolumeVoice(0, 0, 0); } SND_PauseVoice(0, 0); } */ if (buttons & CFG.button_cancel.mask) goto close; if (buttons & CFG.button_exit.mask) { Handle_Home(0); return; } if (!gc && (buttons & CFG.button_other.mask)) { Menu_Boot_Options(header); return; } // A button: continue to boot skip_confirm: if (game_cfg) { CFG.game = game_cfg->curr; } if (CFG.game.write_playlog && set_playrec(header->id, (u8 *) header->title) < 0) { // banner_title) < 0) { printf_(gt("Error storing playlog file.\nStart from the Wii Menu to fix.")); printf("\n"); printf_h(gt("Press %s button to exit."), (button_names[CFG.button_exit.num])); printf("\n"); if (!Menu_Confirm(0)) return; } WBFS_OpenDisc(header->id, header->game_idx); printf("\n"); printf_x(gt("Booting Wii game, please wait...")); printf("\n\n"); // load stuff before ios reloads & services close ocarina_load_code(header->id); load_wip_patches(header->id); // Close the wode stuff WBFS_Close(); use_dvdx = 0; Disc_Init(); ret = Disc_Wait(); if (ret < 0) { printf("Cannot mount newly selected image: %d\n", ret); } Disc_Open(); // stop services (music, gui) Services_Close(); setPlayStat(header->id); //I'd rather do this after the check, but now you unmount fat before that ;) Fat_UnmountAll(); if (gc) { WII_Initialize(); ret = WII_LaunchTitle(0x0000000100000100ULL); } else { switch(CFG.game.language) { // 0 = CFG_LANG_CONSOLE case 0: configbytes[0] = 0xCD; break; case 1: configbytes[0] = 0x00; break; case 2: configbytes[0] = 0x01; break; case 3: configbytes[0] = 0x02; break; case 4: configbytes[0] = 0x03; break; case 5: configbytes[0] = 0x04; break; case 6: configbytes[0] = 0x05; break; case 7: configbytes[0] = 0x06; break; case 8: configbytes[0] = 0x07; break; case 9: configbytes[0] = 0x08; break; case 10: configbytes[0] = 0x09; break; } /* Boot Wii disc */ ret = Disc_WiiBoot(); } printf_(gt("Returned! (ret = %d)"), ret); printf("\n"); printf("\n"); printf_(gt("Press any button to exit...")); printf("\n"); /* Wait for button */ Wpad_WaitButtonsCommon(); exit(0); close: WDVD_StopMotor(); header = &gameList[gameSelected]; Gui_DrawCover(header->id); // Reopen the wode WBFS_Init(); return; }
int old_main() { geckoinit = InitGecko(); use_dvdx = 1; InitDVD(); SYS_SetArena1Hi((void *)0x81200000); // See loader/apploader.c CVideo vid; gprintf("WodeFlow started, running with ios %d\n", IOS_GetVersion()); bool dipOK = false; int ret = 0; bool hbc; bool wodeOK = false; // MEM2 usage : // 36 MB for general purpose allocations // 12 MB for covers (and temporary buffers) // adds 15 MB from MEM1 to obtain 27 MB for covers (about 150 HQ covers on screen) MEM2_init(36, 12); // Max ~48 // Launched through the HBC? hbc = *((u32 *) 0x80001804) == 0x53545542 && *((u32 *) 0x80001808) == 0x48415858; // Init video vid.init(); // Init STexture texWait; texWait.fromPNG(wait_png, GX_TF_RGB565, ALLOC_MALLOC); vid.waitMessage(texWait); Sys_Init(); Sys_ExitToWiiMenu(true); Fat_Mount(); WPAD_Init(); WPAD_SetDataFormat(0, WPAD_FMT_BTNS_ACC_IR); dipOK = Disc_Init() >= 0; if (dipOK) { u32 status = 0; if (WDVD_GetCoverStatus(&status) != 0 || (status & 2) == 0) { // WDVD_WaitForDisc(); STexture texWaitForDisc; texWaitForDisc.fromPNG(wait_disc_png, GX_TF_RGB565, ALLOC_MALLOC); vid.waitMessage(texWaitForDisc); texWaitForDisc.data.release(); do { WPAD_ScanPads(); s32 padsState = WPAD_ButtonsDown(0); if ((padsState & WPAD_BUTTON_B) != 0) break; usleep(100 * 1000); } while (WDVD_GetCoverStatus(&status) != 0 || (status & 2) == 0); if ((status & 2) == 0) return -2; InitDVD(); } } wodeOK = WBFS_Init() >= 0; vid.waitMessage(texWait); texWait.data.release(); MEM2_takeBigOnes(true); do { CMenu menu(vid); menu.init(hbc); if (!dipOK) menu.error(L"Could not initialize DIP module!"); else if (!wodeOK) menu.error(L"Wode not found."); else { ret = menu.main(); } vid.cleanup(); } while (ret == 1); LaunchISO(0, 0); CloseWode(); Fat_Unmount(); return ret; };
void Menu_Device(void) { u32 timeout = 30; s32 ret; /* Ask user for device */ for (;;) { char *devname = "Unknown!"; /* Set device name */ switch (wbfsDev) { case WBFS_DEVICE_USB: devname = "USB Mass Storage Device"; break; case WBFS_DEVICE_SDHC: devname = "SD/SDHC Card"; break; } /* Clear console */ Con_Clear(); printf("[+] Select WBFS device:\n"); printf(" < %s >\n\n", devname); printf(" Press LEFT/RIGHT to select device.\n"); printf(" Press A button to continue.\n\n"); u32 buttons = Wpad_WaitButtons(); /* LEFT/RIGHT buttons */ if (buttons & WPAD_BUTTON_LEFT) { if ((--wbfsDev) < WBFS_MIN_DEVICE) wbfsDev = WBFS_MAX_DEVICE; } if (buttons & WPAD_BUTTON_RIGHT) { if ((++wbfsDev) > WBFS_MAX_DEVICE) wbfsDev = WBFS_MIN_DEVICE; } /* A button */ if (buttons & WPAD_BUTTON_A) break; } printf("[+] Mounting device, please wait...\n"); printf(" (%d seconds timeout)\n\n", timeout); fflush(stdout); /* Initialize WBFS */ ret = WBFS_Init(wbfsDev, timeout); if (ret < 0) { printf(" ERROR! (ret = %d)\n", ret); /* Restart wait */ Restart_Wait(); } /* Try to open device */ while (WBFS_Open() < 0) { /* Clear console */ Con_Clear(); printf("[+] WARNING:\n\n"); printf(" No WBFS partition found!\n"); printf(" You need to format a partition.\n\n"); printf(" Press A button to format a partition.\n"); printf(" Press B button to restart.\n\n"); /* Wait for user answer */ for (;;) { u32 buttons = Wpad_WaitButtons(); /* A button */ if (buttons & WPAD_BUTTON_A) break; /* B button */ if (buttons & WPAD_BUTTON_B) Restart(); } /* Format device */ Menu_Format(); } /* Get game list */ __Menu_GetEntries(); }
static void BootUpProblems() { s32 ret2; // load main font from file, or default to built-in font fontSystem = new FreeTypeGX(); fontSystem->loadFont(NULL, font_ttf, font_ttf_size, 0); fontSystem->setCompatibilityMode(FTGX_COMPATIBILITY_DEFAULT_TEVOP_GX_PASSCLR | FTGX_COMPATIBILITY_DEFAULT_VTXDESC_GX_NONE); GuiImageData bootimageData(gxlogo_png); GuiImage bootimage(&bootimageData); GuiText boottext(NULL, 20, (GXColor) {255, 255, 255, 255} ); boottext.SetPosition(200, 240-1.2*bootimage.GetHeight()/2+250); bootimage.SetPosition(320-1.2*bootimage.GetWidth()/2, 240-1.2*bootimage.GetHeight()/2); bootimage.SetScale(1.2); GuiImageData usbimageData(usbport_png); GuiImage usbimage(&usbimageData); usbimage.SetPosition(400,300); usbimage.SetScale(.7); usbimage.SetAlpha(200); time_t curtime; time_t endtime = time(0) + 30; do { /*ret2 = IOS_ReloadIOSsafe(249); if (ret2 < 0) { ret2 = IOS_ReloadIOSsafe(222); SDCard_Init(); load_ehc_module(); SDCard_deInit(); if(ret2 <0) { boottext.SetText("ERROR: cIOS could not be loaded!"); bootimage.Draw(); boottext.Draw(); Menu_Render(); sleep(5); SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0); } }*/ USBDevice_deInit(); USBDevice_Init(); ret2 = WBFS_Init(WBFS_DEVICE_USB); if (ret2 >= 0) { boottext.SetText("Loading..."); bootimage.Draw(); boottext.Draw(); Menu_Render(); break; } curtime = time(0); boottext.SetTextf("Waiting for your slow USB Device: %i secs...", int(endtime-curtime)); while(curtime == time(0)) { boottext.Draw(); bootimage.Draw(); if (endtime-curtime<15)usbimage.Draw(); Menu_Render(); } } while((endtime-time(0)) > 0); /*if(ret2 < 0) { boottext.SetText("ERROR: USB device could not be loaded!"); usbimage.Draw(); bootimage.Draw(); boottext.Draw(); Menu_Render(); SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0); }*/ ///delete font to load up custom if set if(fontSystem) { delete fontSystem; fontSystem = NULL; } }
int main(int argc, char *argv[]) { setlocale(LC_ALL, "en.UTF-8"); geckoinit = InitGecko(); if (hbcStubAvailable() || geckoinit) { InitTextVideo(); } // DEBUG_Init(GDBSTUB_DEVICE_USB, 1); //_break(); __exception_setreload(5); //auto reset code dump nobody gives us codedump info anyways. gprintf("\n\n------------------"); gprintf("\nUSB Loader GX rev%s",GetRev()); gprintf("\nmain(%d", argc); for (int i=0;i<argc;i++) gprintf(", %s",argv[i]?argv[i]:"<NULL>"); gprintf(")"); // This part is added, because we need a identify patched ios // printf("\n\tReloading into ios 236"); if (IOS_ReloadIOSsafe(236) < 0) { // printf("\n\tIOS 236 not found, reloading into 36"); IOS_ReloadIOSsafe(36); } printf("\n\tStarting up"); MEM2_init(36); // Initialize 36 MB MEM2_takeBigOnes(true); s32 ret; bool startupproblem = false; bool bootDevice_found=false; if (argc >= 1) { if (!strncasecmp(argv[0], "usb:/", 5)) { strcpy(bootDevice, "USB:"); bootDevice_found = true; } else if (!strncasecmp(argv[0], "sd:/", 4)) bootDevice_found = true; } printf("\n\tInitializing controllers"); /** PAD_Init has to be before InitVideo don't move that **/ PAD_Init(); // initialize PAD/WPAD printf("\n\tInitialize USB (wake up)"); USBDevice_Init(); // seems enough to wake up some HDDs if they are in sleep mode when the loader starts (tested with WD MyPassport Essential 2.5") gprintf("\n\tChecking for stub IOS"); ios222rev = getIOSrev(0x00000001000000dell); ios249rev = getIOSrev(0x00000001000000f9ll); //if we don't like either of the cIOS then scram if (!(ios222rev==4 || ios222rev==5 || (ios249rev>=9 && ios249rev<65280))) { InitTextVideo(); printf("\x1b[2J"); if ((ios222rev < 0 && ios222rev != WII_EINSTALL) && (ios249rev < 0 && ios249rev != WII_EINSTALL)) { printf("\n\n\n\tWARNING!"); printf("\n\tUSB Loader GX needs unstubbed cIOS 222 v4 or 249 v9+"); printf("\n\n\tWe cannot determine the versions on your system,\n\tsince you have no patched ios 36 or 236 installed."); printf("\n\tTherefor, if loading of USB Loader GX fails, you\n\tprobably have installed the 4.2 update,"); printf("\n\tand you should go figure out how to get some cios action going on\n\tin your Wii."); printf("\n\n\tThis message will show every time."); sleep(5); } else { printf("\n\n\n\tERROR!"); printf("\n\tUSB Loader GX needs unstubbed cIOS 222 v4 or 249 v9+"); printf("\n\n\tI found \n\t\t222 = %d%s",ios222rev,ios222rev==65280?" (Stubbed by 4.2 update)":""); printf("\n\t\t249 = %d%s",ios249rev,ios249rev==65280?" (Stubbed by 4.2 update)":""); printf("\n\n\tGo figure out how to get some cIOS action going on\n\tin your Wii and come back and see me."); sleep(15); printf("\n\n\tBye"); USBDevice_deInit(); exit(0); } } printf("\n\tReloading ios 249..."); ret = IOS_ReloadIOSsafe(249); printf("%d", ret); if (ret < 0) { printf("\n\tIOS 249 failed, reloading ios 222..."); ret = IOS_ReloadIOSsafe(222); printf("%d", ret); if (ret < 0) { printf("\n\tIOS 222 failed, reloading ios 250..."); ret = IOS_ReloadIOSsafe(250); printf("%d", ret); if(ret < 0) { printf("\n\tIOS 250 failed, reloading ios 223..."); ret = IOS_ReloadIOSsafe(223); printf("%d", ret); if (ret < 0) { printf("\n\tERROR: cIOS could not be loaded!\n"); sleep(5); SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0); } } } printf("\n\tInitialize sd card"); SDCard_Init(); printf("\n\tLoad ehc module"); load_ehc_module(); printf("\n\tdeinit sd card"); SDCard_deInit(); } printf("\n\tInit wbfs..."); ret = WBFS_Init(WBFS_DEVICE_USB); printf("%d", ret); if (ret < 0) { printf("\n\tYou have issues with a slow disc, or a difficult disc\n\tReloading 222..."); ret = IOS_ReloadIOSsafe(222); printf("%d", ret); /*if(ret < 0) { // printf("\n\tSleeping for 4 seconds"); // sleep(4); InitVideo(); // Initialise video Menu_Render(); BootUpProblems(); startupproblem = true; ret = 1; }*/ printf("\n\tInitialize sd card"); SDCard_Init(); printf("\n\tLoad ehc module"); load_ehc_module(); printf("\n\tdeinit sd card"); SDCard_deInit(); printf("\n\tInitialize wbfs..."); USBDevice_deInit(); USBDevice_Init(); ret = WBFS_Init(WBFS_DEVICE_USB); printf("%d", ret); if(ret < 0) { // printf("\n\tSleeping for 4 seconds"); // sleep(4); InitVideo(); // Initialise video Menu_Render(); BootUpProblems(); startupproblem = true; ret = 1; } } printf("\n\tInitialize sd card"); SDCard_Init(); // mount SD for loading cfg's //this should have already been done by now in order to WBFS_Init(). printf("\n\tInitialize usb device"); USBDevice_Init(); // and mount USB:/ if (!bootDevice_found) { printf("\n\tSearch for configuration file"); //try USB //left in all the dol and elf files in this check in case this is the first time running the app and they dont have the config if (checkfile((char*) "USB:/config/GXglobal.cfg") || (checkfile((char*) "USB:/apps/usbloader_gx/boot.elf")) || checkfile((char*) "USB:/apps/usbloadergx/boot.dol") || (checkfile((char*) "USB:/apps/usbloadergx/boot.elf")) || checkfile((char*) "USB:/apps/usbloader_gx/boot.dol")) strcpy(bootDevice, "USB:"); printf("\n\tConfiguration file is on %s", bootDevice); } // Try opening and closing the configuration file here // to prevent a crash dump later on - giantpune char GXGlobal_cfg[26]; sprintf(GXGlobal_cfg, "%s/config/GXGlobal.cfg", bootDevice); FILE *fp = fopen(GXGlobal_cfg, "r"); if (fp) { fclose(fp); } gettextCleanUp(); printf("\n\tLoading configuration..."); CFG_Load(); printf("done"); // gprintf("\n\tbootDevice = %s",bootDevice); /* Load Custom IOS */ if ((Settings.cios == ios222 && IOS_GetVersion() != 222) || (Settings.cios == ios223 && IOS_GetVersion() != 223)) { printf("\n\tReloading IOS to config setting (%d)...", Settings.cios == ios222 ? 222 : 223); SDCard_deInit(); // unmount SD for reloading IOS USBDevice_deInit(); // unmount USB for reloading IOS USBStorage2_Deinit(); ret = IOS_ReloadIOSsafe(Settings.cios == ios222 ? 222 : 223); printf("%d", ret); SDCard_Init(); load_ehc_module(); if (ret < 0) { SDCard_deInit(); Settings.cios = ios249; ret = IOS_ReloadIOSsafe(249); // now mount SD:/ //no need to keep mindlessly mounting and unmounting SD card SDCard_Init(); } USBDevice_Init(); // and mount USB:/ WBFS_Init(WBFS_DEVICE_USB); } else if ((Settings.cios == ios249 && IOS_GetVersion() != 249) || (Settings.cios == ios250 && IOS_GetVersion() != 250)) { printf("\n\tReloading IOS to config setting (%d)...", ios249 ? 249 : 250); SDCard_deInit(); // unmount SD for reloading IOS USBDevice_deInit(); // unmount USB for reloading IOS USBStorage2_Deinit(); ret = IOS_ReloadIOSsafe(ios249 ? 249 : 250); printf("%d", ret); if (ret < 0) { Settings.cios = ios222; ret = IOS_ReloadIOSsafe(222); SDCard_Init(); load_ehc_module(); } else SDCard_Init(); // now mount SD:/ //no need to keep mindlessly mounting and unmounting SD card USBDevice_Init(); // and mount USB:/ WBFS_Init(WBFS_DEVICE_USB); } // Partition_GetList(&partitions); if (ret < 0) { printf("\nERROR: cIOS could not be loaded!"); sleep(5); exit(0); //SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0); } //gprintf("\n\tcIOS = %u (Rev %u)",IOS_GetVersion(), IOS_GetRevision());//don't need gprintf if sending console shit to gecko, too printf("\n\tcIOS = %u (Rev %u)",IOS_GetVersion(), IOS_GetRevision()); // printf("Sleeping for 5 seconds\n"); // sleep(5); //if a ID was passed via args copy it and try to boot it after the partition is mounted //its not really a headless mode. more like hairless. if (argc > 1 && argv[1]) { if (strlen(argv[1])==6) strncpy(headlessID, argv[1], sizeof(headlessID)); } //! Init the rest of the System Sys_Init(); Wpad_Init(); if(!startupproblem) InitVideo(); InitAudio(); // Initialize audio WPAD_SetDataFormat(WPAD_CHAN_ALL,WPAD_FMT_BTNS_ACC_IR); WPAD_SetVRes(WPAD_CHAN_ALL, screenwidth, screenheight); // load main font from file, or default to built-in font fontSystem = new FreeTypeGX(); char *fontPath = NULL; asprintf(&fontPath, "%sfont.ttf", CFG.theme_path); fontSystem->loadFont(fontPath, font_ttf, font_ttf_size, 0); fontSystem->setCompatibilityMode(FTGX_COMPATIBILITY_DEFAULT_TEVOP_GX_PASSCLR | FTGX_COMPATIBILITY_DEFAULT_VTXDESC_GX_NONE); free(fontPath); fontClock = new FreeTypeGX(); fontClock->loadFont(NULL, clock_ttf, clock_ttf_size, 0); fontClock->setCompatibilityMode(FTGX_COMPATIBILITY_DEFAULT_TEVOP_GX_PASSCLR | FTGX_COMPATIBILITY_DEFAULT_VTXDESC_GX_NONE); gprintf("\n\tEnd of Main()"); InitGUIThreads(); MainMenu(MENU_CHECK); return 0; }