bool loadIOS(int ios, bool MountDevices) { int CurIOS = IOS_GetVersion(); bool ret = true; if(ios != CurIOS && IOS_GetType(ios) != IOS_TYPE_STUB) { WDVD_Close(); gprintf("Reloading into IOS %i from %i...\n", ios, CurIOS); ShutdownBeforeExit(); NandHandle.Patch_AHB(); //No AHBPROT for the next IOS ret = IOS_ReloadIOS(ios) == 0; gprintf("AHBPROT after IOS Reload: %u\n", AHBRPOT_Patched()); NandHandle.Init_ISFS(); WDVD_Init(); } IOS_GetCurrentIOSInfo(); if(CurrentIOS.Type == IOS_TYPE_HERMES) load_ehc_module_ex(); else if(CurrentIOS.Type == IOS_TYPE_WANIN && CurrentIOS.Revision >= 18) load_dip_249(); DeviceHandle.SetModes(); if(MountDevices && ios != CurIOS) DeviceHandle.MountAll(); return ret; }
void WiiFlow_ExternalBooter(u8 vidMode, bool vipatch, bool countryString, u8 patchVidMode, int aspectRatio, u32 returnTo, u8 BootType, bool use_led) { normalCFG.vidMode = vidMode; normalCFG.vipatch = vipatch; normalCFG.countryString = countryString; normalCFG.patchVidMode = patchVidMode; normalCFG.aspectRatio = aspectRatio; normalCFG.returnTo = returnTo; normalCFG.configbytes[0] = configbytes[0]; normalCFG.configbytes[1] = configbytes[1]; normalCFG.IOS = CurrentIOS; normalCFG.codelist = codelist; normalCFG.codelistend = codelistend; normalCFG.cheats = code_buf; normalCFG.cheatSize = code_size; normalCFG.hooktype = hooktype; normalCFG.debugger = debuggerselect; normalCFG.gameconf = gameconf; normalCFG.gameconfsize = gameconfsize; normalCFG.BootType = BootType; normalCFG.use_led = use_led; normalCFG.wip_list = get_wip_list(); normalCFG.wip_count = get_wip_count(); /* Copy CFG Into lower MEM1 so it doesnt get destroyed */ DCFlushRange(&normalCFG, sizeof(the_CFG)); the_CFG *lowCFG = (the_CFG*)MEM1_lo_alloc(sizeof(the_CFG)); memcpy(lowCFG, &normalCFG, sizeof(the_CFG)); DCFlushRange(&lowCFG, sizeof(the_CFG)); *EXT_ADDR_CFG = ((u32)lowCFG); /* Unmount devices etc */ ShutdownBeforeExit(); /* Wii Games will need it */ net_wc24cleanup(); /* Set proper time */ settime(secs_to_ticks(time(NULL) - 946684800)); /* Copy in booter */ memcpy(EXT_ADDR, booter_ptr, booter_size); DCFlushRange(EXT_ADDR, booter_size); /* Loader just for the booter */ memcpy(LDR_ADDR, extldr_ptr, extldr_size); DCFlushRange(LDR_ADDR, extldr_size); /* Boot it */ JumpToEntry(LDR_ENTRY); }
int main(int argc, char **argv) { MEM_init(); //Inits both mem1lo and mem2 mainIOS = DOL_MAIN_IOS; __exception_setreload(10); Gecko_Init(); //USB Gecko and SD/WiFi buffer gprintf(" \nWelcome to %s!\nThis is the debug output.\n", VERSION_STRING.c_str()); m_vid.init(); // Init video DeviceHandle.Init(); NandHandle.Init(); char *gameid = NULL; bool Emulator_boot = false; bool iosOK = true; for(u8 i = 0; i < argc; i++) { if(argv[i] != NULL && strcasestr(argv[i], "ios=") != NULL && strlen(argv[i]) > 4) { while(argv[i][0] && !isdigit(argv[i][0])) argv[i]++; if (atoi(argv[i]) < 254 && atoi(argv[i]) > 0) mainIOS = atoi(argv[i]); } else if(strlen(argv[i]) == 6) { gameid = argv[i]; for(u8 i = 0; i < 5; i++) { if(!isalnum(gameid[i])) gameid = NULL; } } else if(argv[i] != NULL && strcasestr(argv[i], "EMULATOR_MAGIC") != NULL) Emulator_boot = true; } check_neek2o(); /* Init ISFS */ if(neek2o() || Sys_DolphinMode()) NandHandle.Init_ISFS(); else NandHandle.LoadDefaultIOS(); /* safe reload to preferred IOS */ /* Maybe new IOS and Port settings */ if(InternalSave.CheckSave()) InternalSave.LoadSettings(); /* Handle (c)IOS Loading */ if(neek2o() || Sys_DolphinMode()) /* wont reload anythin */ iosOK = loadIOS(IOS_GetVersion(), false); else if(useMainIOS && CustomIOS(IOS_GetType(mainIOS))) /* Requested */ iosOK = loadIOS(mainIOS, false) && CustomIOS(CurrentIOS.Type); // Init Sys_Init(); Sys_ExitTo(EXIT_TO_HBC); DeviceHandle.MountAll(); m_vid.waitMessage(0.15f); Open_Inputs(); mainMenu.init(); if(CurrentIOS.Version != mainIOS && !neek2o() && !Sys_DolphinMode()) { if(useMainIOS || !DeviceHandle.UsablePartitionMounted()) { useMainIOS = false; mainMenu.TempLoadIOS(); iosOK = CustomIOS(CurrentIOS.Type); } } if(CurrentIOS.Version == mainIOS) useMainIOS = true; //Needed for later checks if(!iosOK) mainMenu.terror("errboot1", L"No cIOS found!\ncIOS d2x 249 base 56 and 250 base 57 are enough for all your games."); else if(!DeviceHandle.UsablePartitionMounted()) mainMenu.terror("errboot2", L"Could not find a device to save configuration files on!"); else if(WDVD_Init() < 0) mainMenu.terror("errboot3", L"Could not initialize the DIP module!"); else { writeStub(); if(Emulator_boot) mainMenu.m_Emulator_boot = true; if(gameid != NULL && strlen(gameid) == 6) mainMenu.directlaunch(gameid); else mainMenu.main(); } //Exit WiiFlow, no game booted... mainMenu.cleanup(); ShutdownBeforeExit(); Sys_Exit(); return 0; }