2010-05-29 09:38:54 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <ogcsys.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "usbloader/wdvd.h"
|
|
|
|
#include "usbloader/usbstorage2.h"
|
|
|
|
#include "usbloader/disc.h"
|
|
|
|
#include "usbloader/wbfs.h"
|
|
|
|
#include "usbloader/partition_usbloader.h"
|
|
|
|
#include "mload/mload_modules.h"
|
|
|
|
#include "video.h"
|
|
|
|
#include "audio.h"
|
|
|
|
#include "menu.h"
|
|
|
|
#include "fatmounter.h"
|
2010-09-16 21:59:41 +02:00
|
|
|
#include "gecko.h"
|
2010-05-29 09:38:54 +02:00
|
|
|
#include "sys.h"
|
|
|
|
#include "wpad.h"
|
2010-09-16 21:59:41 +02:00
|
|
|
#include "lstub.h"
|
2010-09-19 01:04:39 +02:00
|
|
|
#include "wad/nandtitle.h"
|
2010-05-29 09:38:54 +02:00
|
|
|
|
|
|
|
extern char game_partition[6];
|
|
|
|
extern u8 load_from_fs;
|
|
|
|
|
|
|
|
//Wiilight stuff
|
2010-09-19 01:16:05 +02:00
|
|
|
static vu32 *_wiilight_reg = ( u32* )0xCD0000C0;
|
|
|
|
void wiilight( int enable ) // Toggle wiilight (thanks Bool for wiilight source)
|
|
|
|
{
|
|
|
|
u32 val = ( *_wiilight_reg&~0x20 );
|
|
|
|
if ( enable && Settings.wiilight ) val |= 0x20;
|
|
|
|
*_wiilight_reg = val;
|
2010-05-29 09:38:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Variables */
|
|
|
|
u8 shutdown = 0;
|
|
|
|
u8 reset = 0;
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
void __Sys_ResetCallback( void )
|
|
|
|
{
|
2010-05-29 09:38:54 +02:00
|
|
|
/* Reboot console */
|
|
|
|
reset = 1;
|
|
|
|
}
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
void __Sys_PowerCallback( void )
|
|
|
|
{
|
2010-05-29 09:38:54 +02:00
|
|
|
/* Poweroff console */
|
|
|
|
shutdown = 1;
|
|
|
|
}
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
void Sys_Init( void )
|
|
|
|
{
|
2010-05-29 09:38:54 +02:00
|
|
|
/* Initialize video subsytem */
|
|
|
|
//VIDEO_Init();
|
|
|
|
|
|
|
|
/* Set RESET/POWER button callback */
|
2010-09-19 01:16:05 +02:00
|
|
|
SYS_SetResetCallback( __Sys_ResetCallback );
|
|
|
|
SYS_SetPowerCallback( __Sys_PowerCallback );
|
2010-05-29 09:38:54 +02:00
|
|
|
}
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
static void _ExitApp()
|
|
|
|
{
|
2010-05-29 09:38:54 +02:00
|
|
|
ExitGUIThreads();
|
|
|
|
StopGX();
|
|
|
|
ShutdownAudio();
|
|
|
|
|
|
|
|
UnmountNTFS();
|
|
|
|
SDCard_deInit();
|
|
|
|
USBDevice_deInit();
|
2010-09-19 01:16:05 +02:00
|
|
|
mload_set_ES_ioctlv_vector( NULL );
|
2010-05-29 09:38:54 +02:00
|
|
|
mload_close();
|
|
|
|
}
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
void Sys_Reboot( void )
|
|
|
|
{
|
2010-05-29 09:38:54 +02:00
|
|
|
/* Restart console */
|
|
|
|
_ExitApp();
|
|
|
|
STM_RebootSystem();
|
|
|
|
}
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
int Sys_ChangeIos( int ios )
|
|
|
|
{
|
|
|
|
s32 prevIos = IOS_GetVersion();
|
2010-05-29 09:38:54 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
SDCard_deInit();
|
|
|
|
USBDevice_deInit();
|
2010-05-29 09:38:54 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
WPAD_Flush( 0 );
|
|
|
|
WPAD_Disconnect( 0 );
|
|
|
|
WPAD_Shutdown();
|
2010-05-29 09:38:54 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
WDVD_Close();
|
2010-05-29 09:38:54 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
USBStorage2_Deinit();
|
2010-05-29 09:38:54 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
s32 ret = IOS_ReloadIOSsafe( ios );
|
|
|
|
if ( ret < 0 )
|
|
|
|
{
|
|
|
|
ios = prevIos;
|
|
|
|
}
|
2010-05-29 09:38:54 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
SDCard_Init();
|
2010-05-29 09:38:54 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
if ( ios == 222 || ios == 223 )
|
|
|
|
{
|
|
|
|
load_ehc_module();
|
|
|
|
}
|
|
|
|
USBDevice_Init();
|
2010-05-29 09:38:54 +02:00
|
|
|
|
|
|
|
PAD_Init();
|
|
|
|
Wpad_Init();
|
2010-09-19 01:16:05 +02:00
|
|
|
WPAD_SetDataFormat( WPAD_CHAN_ALL, WPAD_FMT_BTNS_ACC_IR );
|
|
|
|
WPAD_SetVRes( WPAD_CHAN_ALL, screenwidth, screenheight );
|
2010-05-29 09:38:54 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
WBFS_Init( WBFS_DEVICE_USB );
|
|
|
|
Disc_Init();
|
2010-05-29 09:38:54 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
if ( Sys_IsHermes() )
|
|
|
|
{
|
|
|
|
WBFS_OpenNamed( ( char * ) &game_partition );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WBFS_Open();
|
|
|
|
}
|
2010-05-29 09:38:54 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
return ret;
|
2010-05-29 09:38:54 +02:00
|
|
|
}
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
int Sys_IosReload( int IOS )
|
|
|
|
{
|
2010-05-29 09:38:54 +02:00
|
|
|
s32 ret = -1;
|
|
|
|
|
|
|
|
//shutdown SD and USB before IOS Reload in DiscWait
|
|
|
|
SDCard_deInit();
|
|
|
|
USBDevice_deInit();
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
WPAD_Flush( 0 );
|
|
|
|
WPAD_Disconnect( 0 );
|
2010-05-29 09:38:54 +02:00
|
|
|
WPAD_Shutdown();
|
|
|
|
|
|
|
|
WDVD_Close();
|
|
|
|
|
|
|
|
USBStorage2_Deinit();
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
if ( IOS == 249 || IOS == 222 || IOS == 223 )
|
|
|
|
{
|
|
|
|
for ( int i = 0; i < 10; i++ )
|
|
|
|
{
|
|
|
|
ret = IOS_ReloadIOSsafe( 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 );
|
2010-05-29 09:38:54 +02:00
|
|
|
USBStorage2_Deinit();
|
|
|
|
}
|
2010-09-19 01:16:05 +02:00
|
|
|
if ( ret >= 0 )
|
|
|
|
{
|
2010-05-29 09:38:54 +02:00
|
|
|
ret = Disc_Init();
|
2010-09-19 01:16:05 +02:00
|
|
|
if ( ret >= 0 )
|
|
|
|
{
|
2010-05-29 09:38:54 +02:00
|
|
|
ret = WBFS_Open();
|
|
|
|
}
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
|
|
|
else Sys_BackToLoader();
|
2010-05-29 09:38:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
PAD_Init();
|
|
|
|
Wpad_Init();
|
2010-09-19 01:16:05 +02:00
|
|
|
WPAD_SetDataFormat( WPAD_CHAN_ALL, WPAD_FMT_BTNS_ACC_IR );
|
|
|
|
WPAD_SetVRes( WPAD_CHAN_ALL, screenwidth, screenheight );
|
2010-05-29 09:38:54 +02:00
|
|
|
//reinitialize SD and USB
|
|
|
|
SDCard_Init();
|
|
|
|
USBDevice_Init();
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
#define ShutdownToDefault 0
|
|
|
|
#define ShutdownToIdle 1
|
|
|
|
#define ShutdownToStandby 2
|
2010-05-29 09:38:54 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
static void _Sys_Shutdown( int SHUTDOWN_MODE )
|
|
|
|
{
|
2010-05-29 09:38:54 +02:00
|
|
|
_ExitApp();
|
2010-09-19 01:16:05 +02:00
|
|
|
WPAD_Flush( 0 );
|
|
|
|
WPAD_Disconnect( 0 );
|
2010-05-29 09:38:54 +02:00
|
|
|
WPAD_Shutdown();
|
|
|
|
|
|
|
|
/* Poweroff console */
|
2010-09-19 01:16:05 +02:00
|
|
|
if ( ( CONF_GetShutdownMode() == CONF_SHUTDOWN_IDLE && SHUTDOWN_MODE != ShutdownToStandby ) || SHUTDOWN_MODE == ShutdownToIdle )
|
|
|
|
{
|
2010-05-29 09:38:54 +02:00
|
|
|
s32 ret;
|
|
|
|
|
|
|
|
/* Set LED mode */
|
|
|
|
ret = CONF_GetIdleLedMode();
|
2010-09-19 01:16:05 +02:00
|
|
|
if ( ret >= 0 && ret <= 2 )
|
|
|
|
STM_SetLedMode( ret );
|
2010-05-29 09:38:54 +02:00
|
|
|
|
|
|
|
/* Shutdown to idle */
|
|
|
|
STM_ShutdownToIdle();
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-05-29 09:38:54 +02:00
|
|
|
/* Shutdown to standby */
|
|
|
|
STM_ShutdownToStandby();
|
|
|
|
}
|
|
|
|
}
|
2010-09-19 01:16:05 +02:00
|
|
|
void Sys_Shutdown( void )
|
|
|
|
{
|
|
|
|
_Sys_Shutdown( ShutdownToDefault );
|
2010-05-29 09:38:54 +02:00
|
|
|
}
|
2010-09-19 01:16:05 +02:00
|
|
|
void Sys_ShutdownToIdel( void )
|
|
|
|
{
|
|
|
|
_Sys_Shutdown( ShutdownToIdle );
|
2010-05-29 09:38:54 +02:00
|
|
|
}
|
2010-09-19 01:16:05 +02:00
|
|
|
void Sys_ShutdownToStandby( void )
|
|
|
|
{
|
|
|
|
_Sys_Shutdown( ShutdownToStandby );
|
2010-05-29 09:38:54 +02:00
|
|
|
}
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
void Sys_LoadMenu( void )
|
|
|
|
{
|
2010-05-29 09:38:54 +02:00
|
|
|
_ExitApp();
|
|
|
|
/* Return to the Wii system menu */
|
2010-09-19 01:16:05 +02:00
|
|
|
SYS_ResetSystem( SYS_RETURNTOMENU, 0, 0 );
|
2010-05-29 09:38:54 +02:00
|
|
|
}
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
void Sys_BackToLoader( void )
|
|
|
|
{
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
if ( hbcStubAvailable() )
|
|
|
|
{
|
2010-05-29 09:38:54 +02:00
|
|
|
_ExitApp();
|
2010-09-19 01:16:05 +02:00
|
|
|
exit( 0 );
|
2010-05-29 09:38:54 +02:00
|
|
|
}
|
|
|
|
// Channel Version
|
|
|
|
Sys_LoadMenu();
|
|
|
|
}
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
bool Sys_IsHermes()
|
|
|
|
{
|
|
|
|
return IOS_GetVersion() == 222 || IOS_GetVersion() == 223;
|
2010-05-29 09:38:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#include "prompts/PromptWindows.h"
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
void ShowMemInfo()
|
|
|
|
{
|
|
|
|
char buf[255];
|
2010-05-29 09:38:54 +02:00
|
|
|
struct mallinfo mymallinfo = mallinfo();
|
2010-09-19 01:16:05 +02:00
|
|
|
sprintf( ( char * ) &buf, "Total: %d, Used: %d, Can be freed: %d", mymallinfo.arena / 1024, mymallinfo.uordblks / 1024, mymallinfo.keepcost / 1024 );
|
|
|
|
WindowPrompt( "Mem info", ( char * ) &buf, "OK" );
|
2010-05-29 09:38:54 +02:00
|
|
|
}
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
s32 IOS_ReloadIOSsafe( int ios )
|
2010-05-29 09:38:54 +02:00
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
if ( ios == 222 )
|
|
|
|
{
|
|
|
|
s32 ios222rev = titles.VersionOf( 0x1000000deULL );
|
|
|
|
if ( !ios222rev )
|
|
|
|
return -2;
|
|
|
|
if ( ios222rev != 4 && ios222rev != 5 && ios222rev != 65535 )
|
|
|
|
return -2;
|
|
|
|
}
|
|
|
|
else if ( ios == 223 )
|
|
|
|
{
|
|
|
|
s32 ios223rev = titles.VersionOf( 0x1000000dfULL );
|
|
|
|
if ( !ios223rev )
|
|
|
|
return -2;
|
|
|
|
if ( ios223rev != 4 && ios223rev != 5 && ios223rev != 65535 )
|
|
|
|
return -2;
|
|
|
|
}
|
|
|
|
else if ( ios == 249 )
|
|
|
|
{
|
|
|
|
s32 ios249rev = titles.VersionOf( 0x1000000f9ULL );
|
|
|
|
if ( !ios249rev )
|
|
|
|
return -2;
|
|
|
|
if ( ios249rev < 9 || ios249rev == 65280 )
|
|
|
|
return -2;
|
|
|
|
}
|
|
|
|
else if ( ios == 250 )
|
|
|
|
{
|
|
|
|
s32 ios250rev = titles.VersionOf( 0x1000000faULL );
|
|
|
|
if ( !ios250rev )
|
|
|
|
return -2;
|
|
|
|
if ( ios250rev < 9 || ios250rev == 65280 )
|
|
|
|
return -2;
|
|
|
|
}
|
|
|
|
|
|
|
|
s32 r = IOS_ReloadIOS( ios );
|
|
|
|
if ( r >= 0 )
|
|
|
|
{
|
|
|
|
WII_Initialize();
|
|
|
|
}
|
|
|
|
return r;
|
2010-05-29 09:38:54 +02:00
|
|
|
}
|
|
|
|
|
2010-09-16 21:59:41 +02:00
|
|
|
s32 CheckForCIOS()
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
gprintf( "\tChecking for stub IOS\n" );
|
2010-09-16 21:59:41 +02:00
|
|
|
s32 ret = 1;
|
2010-09-19 01:16:05 +02:00
|
|
|
s32 ios222rev = titles.VersionOf( 0x00000001000000deULL );
|
|
|
|
s32 ios249rev = titles.VersionOf( 0x00000001000000f9ULL );
|
|
|
|
|
|
|
|
u8 ios222OK = !( ios222rev < 4 || ios222rev == 65280 );
|
|
|
|
u8 ios249OK = !( ios249rev < 9 || ios249rev == 65280 );
|
|
|
|
|
|
|
|
gprintf( "222ok: %u\t 249ok: %u\n", ios222OK, ios249OK );
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
//if we don't like either of the cIOS then scram
|
|
|
|
//if( !((ios222rev >= 4 && ios222rev < 65280) || (ios249rev >=9 && ios249rev < 65280)))
|
|
|
|
if ( ios222rev < 4 || ios222rev == 65280 || ios249rev < 9 || ios249rev == 65280 )
|
|
|
|
{
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
}
|
2010-09-16 21:59:41 +02:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int LoadAppCIOS()
|
|
|
|
{
|
|
|
|
s32 ret = 1;
|
|
|
|
/* Load Custom IOS */
|
|
|
|
SDCard_deInit();// unmount SD for reloading IOS
|
|
|
|
USBDevice_deInit();// unmount USB for reloading IOS
|
|
|
|
USBStorage2_Deinit();
|
|
|
|
|
2010-09-19 22:25:12 +02:00
|
|
|
if ( Settings.cios == 222 && IOS_GetVersion() != 222 )
|
2010-09-16 21:59:41 +02:00
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
printf( "\n\tReloading IOS to config setting (222)..." );
|
|
|
|
ret = IOS_ReloadIOSsafe( 222 );
|
|
|
|
printf( "%d", ret );
|
|
|
|
if ( ret < 0 )
|
2010-09-16 21:59:41 +02:00
|
|
|
{
|
2010-09-19 22:25:12 +02:00
|
|
|
Settings.cios = 249;
|
|
|
|
IOS_ReloadIOSsafe( Settings.cios );
|
2010-09-16 21:59:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-19 22:25:12 +02:00
|
|
|
if ( ( Settings.cios == 249 && IOS_GetVersion() != 249 )
|
|
|
|
|| ( Settings.cios == 250 && IOS_GetVersion() != 250 ) )
|
2010-09-16 21:59:41 +02:00
|
|
|
{
|
2010-09-19 22:25:12 +02:00
|
|
|
printf( "\n\tReloading IOS to config setting (%d)...", ( Settings.cios == 249 ) ? 249 : 250 );
|
|
|
|
ret = IOS_ReloadIOSsafe( ( Settings.cios == 249 ) ? 249 : 250 );
|
2010-09-19 01:16:05 +02:00
|
|
|
printf( "%d", ret );
|
|
|
|
if ( ret < 0 )
|
|
|
|
{
|
2010-09-19 22:25:12 +02:00
|
|
|
Settings.cios = 222;
|
|
|
|
ret = IOS_ReloadIOSsafe( Settings.cios );
|
2010-09-16 21:59:41 +02:00
|
|
|
}
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
2010-09-16 21:59:41 +02:00
|
|
|
|
|
|
|
SDCard_Init();
|
2010-09-19 01:16:05 +02:00
|
|
|
if ( IOS_GetVersion() == 222 )
|
2010-09-16 21:59:41 +02:00
|
|
|
load_ehc_module();
|
|
|
|
|
|
|
|
USBDevice_Init();
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
return ret;
|
2010-09-16 21:59:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-29 09:38:54 +02:00
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
void ScreenShot()
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
time_t rawtime;
|
|
|
|
struct tm * timeinfo;
|
|
|
|
char buffer [80];
|
|
|
|
char buffer2 [80];
|
|
|
|
|
|
|
|
time ( &rawtime );
|
|
|
|
timeinfo = localtime ( &rawtime );
|
|
|
|
//USBLoader_GX_ScreenShot-Month_Day_Hour_Minute_Second_Year.png
|
|
|
|
strftime ( buffer, 80, "USBLoader_GX_ScreenShot-%b%d%H%M%S%y.png", timeinfo );
|
|
|
|
sprintf( buffer2, "%s/config/%s", bootDevice, buffer );
|
|
|
|
|
|
|
|
TakeScreenshot( buffer2 );
|
2010-05-29 09:38:54 +02:00
|
|
|
}
|