Esempio n. 1
0
static void frontend_gx_init(void *data)
{
   (void)data;
#ifdef HW_RVL
   IOS_ReloadIOS(IOS_GetVersion());
   L2Enhance();
#ifndef IS_SALAMANDER
   gx_init_mem2();
#endif
#endif

#if defined(DEBUG) && defined(IS_SALAMANDER)
   VIDEO_Init();
   GXRModeObj *rmode = VIDEO_GetPreferredMode(NULL);
   void *xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
   console_init(xfb, 20, 20, rmode->fbWidth, rmode->xfbHeight, rmode->fbWidth * VI_DISPLAY_PIX_SZ);
   VIDEO_Configure(rmode);
   VIDEO_SetNextFramebuffer(xfb);
   VIDEO_SetBlack(FALSE);
   VIDEO_Flush();
   VIDEO_WaitVSync();
   VIDEO_WaitVSync();
#endif

#ifndef DEBUG
   __exception_setreload(8);
#endif

   fatInitDefault();

#ifdef HAVE_LOGGER
   devoptab_list[STD_OUT] = &dotab_stdout;
   devoptab_list[STD_ERR] = &dotab_stdout;
   dotab_stdout.write_r = gx_logger_net;
#elif defined(HAVE_FILE_LOGGER) && !defined(IS_SALAMANDER)
   devoptab_list[STD_OUT] = &dotab_stdout;
   devoptab_list[STD_ERR] = &dotab_stdout;
   dotab_stdout.write_r = gx_logger_file;
#endif

#if defined(HW_RVL) && !defined(IS_SALAMANDER)
   OSThread gx_device_thread;
   gx_devices[GX_DEVICE_SD].interface = &__io_wiisd;
   gx_devices[GX_DEVICE_SD].name = "sd";
   gx_devices[GX_DEVICE_SD].mounted = fatMountSimple(gx_devices[GX_DEVICE_SD].name, gx_devices[GX_DEVICE_SD].interface);
   gx_devices[GX_DEVICE_USB].interface = &__io_usbstorage;
   gx_devices[GX_DEVICE_USB].name = "usb";
   gx_devices[GX_DEVICE_USB].mounted = fatMountSimple(gx_devices[GX_DEVICE_USB].name, gx_devices[GX_DEVICE_USB].interface);

   OSInitMutex(&gx_device_cond_mutex);
   OSInitCond(&gx_device_cond);
   OSInitMutex(&gx_device_mutex);
   OSCreateThread(&gx_device_thread, gx_devthread, 0, NULL, NULL, 0, 66, 0);
#endif
}
Esempio n. 2
0
void WiiInit()
{
	extern const devoptab_t dotab_stdnull;
	devoptab_list[STD_OUT] = &dotab_stdnull;
	devoptab_list[STD_ERR] = &dotab_stdnull;
	//USBGeckoOutput(); // uncomment to enable USB gecko output
	__exception_setreload(8);
	fatInitDefault();
	ASND_Init();
	SetupPads();
	InitFreeType((u8*)font_ttf, font_ttf_size);
	LWP_CreateThread (&keythread, PressKeys, NULL, NULL, 0, 65);
	appPath[0] = 0;
}
Esempio n. 3
0
int main(int argc, char **argv)
{
	// Exit after 10 seconds if there is an error
	__exception_setreload(10);
	CheckForGecko();
	DCInvalidateRange(loader_stub, 0x1800);
	memcpy(loader_stub, (void*)0x80001800, 0x1800);
	DCFlushRange(loader_stub, 0x1800);

	if( !IsWiiU() )
	{
		gprintf("Nintendont Loader\r\n");
		gprintf("Built   : %s %s\r\n", __DATE__, __TIME__ );
		gprintf("Version : %d.%d\r\n", NIN_VERSION>>16, NIN_VERSION&0xFFFF );	
	}
Esempio n. 4
0
static void system_init(void)
{
#ifdef HW_RVL
   IOS_ReloadIOS(IOS_GetVersion());
   L2Enhance();
#ifndef IS_SALAMANDER
   gx_init_mem2();
#endif
#endif

#ifndef DEBUG
   __exception_setreload(8);
#endif

   fatInitDefault();

#ifdef HAVE_LOGGER
   inl_logger_init();
   devoptab_list[STD_OUT] = &dotab_stdout;
   devoptab_list[STD_ERR] = &dotab_stdout;
   dotab_stdout.write_r = gx_logger_net;
#elif defined(HAVE_FILE_LOGGER)
   inl_logger_init();
#ifndef IS_SALAMANDER
   devoptab_list[STD_OUT] = &dotab_stdout;
   devoptab_list[STD_ERR] = &dotab_stdout;
   dotab_stdout.write_r = gx_logger_file;
#endif
#endif

#if defined(HW_RVL) && !defined(IS_SALAMANDER)
   lwp_t gx_device_thread;
   gx_devices[GX_DEVICE_SD].interface = &__io_wiisd;
   gx_devices[GX_DEVICE_SD].name = "sd";
   gx_devices[GX_DEVICE_SD].mounted = fatMountSimple(gx_devices[GX_DEVICE_SD].name, gx_devices[GX_DEVICE_SD].interface);
   gx_devices[GX_DEVICE_USB].interface = &__io_usbstorage;
   gx_devices[GX_DEVICE_USB].name = "usb";
   gx_devices[GX_DEVICE_USB].mounted = fatMountSimple(gx_devices[GX_DEVICE_USB].name, gx_devices[GX_DEVICE_USB].interface);
   LWP_MutexInit(&gx_device_mutex, false);
   LWP_CreateThread(&gx_device_thread, gx_devthread, NULL, NULL, 0, 66);
#endif
}
Esempio n. 5
0
int main(int argc, char *argv[])
{
	__exception_setreload(20);
	
#ifdef GDB_DEBUG
	DEBUG_Init(GDBSTUB_DEVICE_USB, 1);
	_break();
#endif
	
	InitVideo();
	
	if(StartUpProcess::Run(argc, argv))
	{
		Application::Instance()->init();
		Application::Instance()->show();
		Application::Instance()->exec();
	}
	
	//! Return to the Wii system menu if not from HBC
	if(!IsFromHBC())
		SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);

	return 0;
}
Esempio n. 6
0
int main(int argc, char **argv)
{
	set_new_handler(no_memory);
	geckoinit = InitGecko();
	__exception_setreload(5);

	SYS_SetArena1Hi(APPLOADER_START);

	char *gameid = NULL;
	string dolLoc; //(argv[0] != NULL ? argv[0] : "");

	for (int 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 (int i=0; i < 5; i++)
				if (!isalnum(gameid[i]))
					gameid = NULL;
		}
	}
	gprintf("Loading cIOS: %d\n", mainIOS);

	ISFS_Initialize();

	// Load Custom IOS
	bool iosOK = loadIOS(mainIOS, false);
	MEM2_init(52);

	u8 mainIOSBase = 0;
	iosOK = iosOK && cIOSInfo::D2X(mainIOS, &mainIOSBase);
	gprintf("Loaded cIOS: %u has base %u\n", mainIOS, mainIOSBase);

	// Init video
	CVideo vid;
	vid.init();
	WIILIGHT_Init();
	vid.waitMessage(0.2f);

	// Init
	Sys_Init();
	Sys_ExitTo(EXIT_TO_HBC);

	int ret = 0;

	do
	{
		Open_Inputs();

		bool deviceAvailable = false;

		u8 timeout = 0;
		while(!deviceAvailable && timeout++ != 20)
		{
			DeviceHandler::Instance()->MountAll();
			sleep(1);

			for(u8 device = SD; device <= USB8; device++)
				if(DeviceHandler::Instance()->IsInserted(device))
					deviceAvailable = true;
		}

		bool dipOK = Disc_Init() >= 0;

		CMenu menu(vid);
		menu.init(dolLoc);
		mainMenu = &menu;
		if(!deviceAvailable)
		{
			menu.error(L"Could not find a device to save configuration files on!");
			break;
		}
		else if(!iosOK)
		{
			menu.error(sfmt("d2x cIOS %i rev6 or later is required", mainIOS));
			break;
		}
		else if(!dipOK)
		{
			menu.error(L"Could not initialize the DIP module!");
			break;
		}
		else
		{
			if (gameid != NULL && strlen(gameid) == 6)
				menu._directlaunch(gameid);
			else
				ret = menu.main();
		}
		vid.cleanup();
		if (bootHB)
		{
			IOS_ReloadIOS(58);
			BootHomebrew();
		}

	} while (ret == 1);

	WifiGecko_Close();

	Nand::Instance()->Disable_Emu();
	Nand::DestroyInstance();

	Sys_Exit();
	return 0;
};
int main(int argc, char* argv[])
{
	__exception_setreload(10);
	
	int i, ret;
	
	Init_Console();
	printf("\x1b[%u;%um", 37, false);
	
	PAD_Init();
	WPAD_Init();
	WPAD_SetDataFormat(WPAD_CHAN_0, WPAD_FMT_BTNS_ACC_IR);
	
	printheadline();
	
	ret = ahbprot_menu();
	if (ret < 0)
	{
		ret = ios_selectionmenu(236);
		if (ret > 0)
		{
			printf("\t- Reloading to IOS%d... ", ret);
			WPAD_Shutdown();
			IOS_ReloadIOS(ret);
			sleep(2);
			PAD_Init();
			WPAD_Init();
			WPAD_SetDataFormat(WPAD_CHAN_0, WPAD_FMT_BTNS_ACC_IR);
			printf("done.\n\n");
		} else
		if (ret == 0)
		{
			printf("\t- Proceeding without IOS reload...\n\n");
		} else {
			Reboot();
		}
	}
	
	resetscreen();
	printheadline();
	
	/* Initialize NAND FS */
	ISFS_Initialize();
	
	/* Do our stuff */
	char path[ISFS_MAXPATH];
	char *filenames[10] = { "misc.bin", "nwc24dl.bin", "nwc24fl.bin", "nwc24fls.bin", "nwc24msg.cbk", "nwc24msg.cfg", \
							"mbox/wc24recv.ctl", "mbox/wc24recv.mbx", "mbox/wc24send.ctl", "mbox/wc24send.mbx" };
	
	for (i = 0; i < 10; i++)
	{
		snprintf(path, MAX_CHARACTERS(path), "/shared2/wc24/%s", filenames[i]);
		
		printf("%u. Deleting \"%s\"... ", i + 1, path);
		ret = ISFS_Delete(path);
		if (ret < 0)
		{
			switch (ret)
			{
				case -1:
				case -102:
					printf("\n\t- Error: Permission denied!");
					break;
				case -2:
				case -105:
					printf("\n\t- Error: File exists!");
					break;
				case -4:
				case -101:
					printf("\n\t- Error: Invalid argument!");
					break;
				case -6:
				case -106:
					printf("\n\t- Error: File not found!");
					break;
				case -8:
				case -118:
					printf("\n\t- Error: Resource busy!");
					break;
				case -12:
				case -103:
				case -114:
					printf("\n\t- Error: NAND ECC failure!");
					break;
				case -22:
					printf("\n\t- Error: Memory allocation failed during request!");
					break;
				case -107:
				case -109:
					printf("\n\t- Error: Too many files open!");
					break;
				case -108:
					printf("\n\t- Error: Memory full!");
					break;
				case -110:
					printf("\n\t- Error: Path name is too long!");
					break;
				case -111:
					printf("\n\t- Error: File already open!");
					break;
				case -115:
					printf("\n\t- Error: Directory not empty!");
					break;
				case -116:
					printf("\n\t- Error: Max directory depth exceeded!");
					break;
				default:
					printf("\n\t- FATAL / UNKNOWN ERROR!!!");
			}
			
			printf(" (ret = %d)\n\n", ret);
			
			if (ret <= -119) break;
		} else {
			printf("OK!\n\n");
		}
		
		usleep(2000000); // 2 seconds
	}
	
	/* Unmount NAND FS and exit */
	ISFS_Deinitialize();
	Reboot();
	
	return 0;
}
Esempio n. 8
0
int main(int argc, char **argv)
{
	u32 cookie;
	FILE *exeFile = NULL;
	void *exeBuffer = (void *)EXECUTABLE_MEM_ADDR;
	u32 exeSize = 0;
	u32 exeEntryPointAddress = 0;
	entrypoint exeEntryPoint;
	__exception_setreload(0);

	IOS_ReloadIOS(58);

	/* int videomod */
	InitVideo();
	/* get imagedata */
	u8 * imgdata = GetImageData();
	fadein(imgdata);
	/* check devices */
	SDCard_Init();
	USBDevice_Init();

	char cfgpath[256];
	bool result = false;

	sprintf(cfgpath, "sd:/config/SaveGame_Manager_GX/SaveGame_Manager_GX.cfg");
	result = cfg_parsefile(cfgpath, &cfg_set);
	if(!result) //no cfg-File on SD: try USB:
	{
		sprintf(cfgpath, "usb:config/SaveGame_Manager_GX/SaveGame_Manager_GX.cfg");
		result = cfg_parsefile(cfgpath, &cfg_set);
	}

    if(result)
    {
        sprintf(cfgpath, "%sboot.dol", update_path);
		/* Open dol File and check exist */
        exeFile = fopen (cfgpath, "rb");
        if (exeFile==NULL)
        {
            sprintf(cfgpath, "%sboot.elf", update_path);
            exeFile = fopen (cfgpath,"rb");
        }
        if (exeFile==NULL)
			result = false;
        else
        result = true;
    }

	if(!result) // non cfg-File loaded or update_path not set
	{
		/* Open dol File and check exist */
		sprintf(cfgpath, "sd:/apps/SaveGame_Manager_GX/boot.dol");
		exeFile = fopen (cfgpath ,"rb");
		if (exeFile==NULL)
		{
			sprintf(cfgpath, "sd:/apps/SaveGame_Manager_GX/boot.elf");
			exeFile = fopen (cfgpath ,"rb");
		}
		if (exeFile==NULL)
		{
			sprintf(cfgpath, "usb:/apps/SaveGame_Manager_GX/boot.dol");
			exeFile = fopen (cfgpath ,"rb");
		}
		if (exeFile==NULL)
		{
			sprintf(cfgpath, "usb:/apps/SaveGame_Manager_GX/boot.elf");
			exeFile = fopen (cfgpath ,"rb");
		}
		if (exeFile==NULL)
		{
			sprintf(cfgpath, "sd:/apps/SaveGameManagerGX/boot.dol");
			exeFile = fopen (cfgpath ,"rb");
		}
		if (exeFile==NULL)
		{
			sprintf(cfgpath, "sd:/apps/SaveGameManagerGX/boot.elf");
			exeFile = fopen (cfgpath ,"rb");
		}
		if (exeFile==NULL)
		{
			sprintf(cfgpath, "usb:/apps/SaveGameManagerGX/boot.dol");
			exeFile = fopen (cfgpath ,"rb");
		}
		if (exeFile==NULL)
		{
			sprintf(cfgpath, "usb:/apps/SaveGameManagerGX/boot.elf");
			exeFile = fopen (cfgpath ,"rb");
		}
		// if nothing found exiting
		if (exeFile==NULL)
		{
            fadeout(imgdata);
            fclose (exeFile);
            SDCard_deInit();
            USBDevice_deInit();
            StopGX();
            free(imgdata);
			SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
		}
	}

	fseek (exeFile, 0, SEEK_END);
	exeSize = ftell(exeFile);
	rewind (exeFile);

	if(fread (exeBuffer, 1, exeSize, exeFile) != exeSize)
	{
		fadeout(imgdata);
        fclose (exeFile);
        SDCard_deInit();
        USBDevice_deInit();
        StopGX();
        free(imgdata);
		SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
	}
	fclose (exeFile);

	/* load entry point */
	struct __argv args;
	bzero(&args, sizeof(args));
	args.argvMagic = ARGV_MAGIC;
	args.length = strlen(cfgpath) + 2;
	args.commandLine = (char*)malloc(args.length);
	if (!args.commandLine) SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
	strcpy(args.commandLine, cfgpath);
	args.commandLine[args.length - 1] = '\0';
	args.argc = 1;
	args.argv = &args.commandLine;
	args.endARGV = args.argv + 1;

	u8 * appboot_buff = (u8 *) malloc(app_booter_dol_size);
	if(!appboot_buff)
	{
		fadeout(imgdata);
        SDCard_deInit();
        USBDevice_deInit();
        StopGX();
        free(imgdata);
		SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
	}

    memcpy(appboot_buff, app_booter_dol, app_booter_dol_size);

	exeEntryPointAddress = load_dol_image(appboot_buff, &args);

    if(appboot_buff)
        free(appboot_buff);

	fadeout(imgdata);
	SDCard_deInit();
	USBDevice_deInit();
	StopGX();
	free(imgdata);

	if (exeEntryPointAddress == 0)
	{
		SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
	}

	exeEntryPoint = (entrypoint) exeEntryPointAddress;
	/* cleaning up and load dol */
	SYS_ResetSystem(SYS_SHUTDOWN, 0, 0);
	_CPU_ISR_Disable (cookie);
	__exception_closeall ();
	exeEntryPoint ();
	_CPU_ISR_Restore (cookie);
	return 0;
}
Esempio n. 9
0
int main(int argc, char **argv)
{
	// Exit after 10 seconds if there is an error
	__exception_setreload(10);
//	u64 timeout = 0;
	CheckForGecko();
	DCInvalidateRange(loader_stub, 0x1800);
	memcpy(loader_stub, (void*)0x80001800, 0x1800);

	RAMInit();

	//Meh, doesnt do anything anymore anyways
	//STM_RegisterEventHandler(HandleSTMEvent);

	Initialise();

	// Checking for storage devices...
	ShowMessageScreen("Checking storage devices...");

	u32 u;
	//Disables MEMPROT for patches
	write16(MEM_PROT, 0);
	//Patches FS access
	for( u = 0x93A00000; u < 0x94000000; u+=2 )
	{
		if( memcmp( (void*)(u), FSAccessPattern, sizeof(FSAccessPattern) ) == 0 )
		{
		//	gprintf("FSAccessPatch:%08X\r\n", u );
			memcpy( (void*)u, FSAccessPatch, sizeof(FSAccessPatch) );
			DCFlushRange((void*)u, sizeof(FSAccessPatch));
			break;
		}
	}

	//for BT.c
	CONF_GetPadDevices((conf_pads*)0x932C0000);
	DCFlushRange((void*)0x932C0000, sizeof(conf_pads));
	*(vu32*)0x932C0490 = CONF_GetIRSensitivity();
	*(vu32*)0x932C0494 = CONF_GetSensorBarPosition();
	DCFlushRange((void*)0x932C0490, 8);

	if(LoadKernel() < 0)
	{
		ClearScreen();
		gprintf("Failed to load kernel from NAND!\r\n");
		ShowMessageScreenAndExit("Failed to load kernel from NAND!", 1);
	}
	InsertModule((char*)kernel_bin, kernel_bin_size);

	memset( (void*)0x92f00000, 0, 0x100000 );
	DCFlushRange( (void*)0x92f00000, 0x100000 );

	DCInvalidateRange( (void*)0x939F02F0, 0x20 );

	memcpy( (void*)0x939F02F0, Boot2Patch, sizeof(Boot2Patch) );

	DCFlushRange( (void*)0x939F02F0, 0x20 );

	//libogc still has that, lets close it
	__ES_Close();
	s32 fd = IOS_Open( "/dev/es", 0 );

	memset( STATUS, 0xFFFFFFFF, 0x20  );
	DCFlushRange( STATUS, 0x20 );

	memset( (void*)0x91000000, 0xFFFFFFFF, 0x20  );
	DCFlushRange( (void*)0x91000000, 0x20 );

	*(vu32*)0xD3003420 = 0; //make sure kernel doesnt reload

	raw_irq_handler_t irq_handler = BeforeIOSReload();
	IOS_IoctlvAsync( fd, 0x1F, 0, 0, &IOCTL_Buf, NULL, NULL );
	AfterIOSReload( irq_handler, FoundVersion );

	while(1)
	{
		DCInvalidateRange( STATUS, 0x20 );
		if((STATUS_LOADING > 0 || abs(STATUS_LOADING) > 1) && STATUS_LOADING < 20)
		{
			gprintf("Kernel sent signal\n");
			break;
		}
	}

	/* For slow USB HDDs */
	time_t timeout = time(NULL);
	while(time(NULL) - timeout < 10)
	{
		if(__io_custom_usbstorage.startup() && __io_custom_usbstorage.isInserted())
			break;
		usleep(50000);
	}
	fatInitDefault();

	gprintf("Nintendont at your service!\r\n%s\r\n", NIN_BUILD_STRING);
	KernelLoaded = 1;

	char* first_slash = strrchr(argv[0], '/');
	if (first_slash != NULL) strncpy(launch_dir, argv[0], first_slash-argv[0]+1);
	gprintf("launch_dir = %s\r\n", launch_dir);

	FPAD_Init();
	FPAD_Update();

	/* Read IPL Font before doing any patches */
	void *fontbuffer = memalign(32, 0x50000);
	__SYS_ReadROM((void*)fontbuffer,0x50000,0x1AFF00);
	memcpy((void*)0xD3100000, fontbuffer, 0x50000);
	DCInvalidateRange( (void*)0x93100000, 0x50000 );
	free(fontbuffer);
	//gprintf("Font: 0x1AFF00 starts with %.4s, 0x1FCF00 with %.4s\n", (char*)0x93100000, (char*)0x93100000 + 0x4D000);

	// Simple code to autoupdate the meta.xml in Nintendont's folder
	FILE *meta = fopen("meta.xml", "w");
	if(meta != NULL)
	{
		fprintf(meta, "%s\r\n<app version=\"1\">\r\n\t<name>%s</name>\r\n", META_XML, META_NAME);
		fprintf(meta, "\t<coder>%s</coder>\r\n\t<version>%d.%d</version>\r\n", META_AUTHOR, NIN_VERSION>>16, NIN_VERSION&0xFFFF);
		fprintf(meta, "\t<release_date>20150531000000</release_date>\r\n");
		fprintf(meta, "\t<short_description>%s</short_description>\r\n", META_SHORT);
		fprintf(meta, "\t<long_description>%s\r\n\r\n%s</long_description>\r\n", META_LONG1, META_LONG2);
		fprintf(meta, "\t<ahb_access/>\r\n</app>");
		fclose(meta);
	}
Esempio n. 10
0
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;
}
Esempio n. 11
0
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;
}