2009-10-01 01:10:58 +02:00
/****************************************************************************
* USB Loader GX Team
*
* libwiigui Template
* by Tantric 2009
*
* menu . cpp
* Menu flow routines - handles all menu logic
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
# include <unistd.h>
# include "libwiigui/gui.h"
# include "homebrewboot/BootHomebrew.h"
2009-11-15 20:52:58 +01:00
# include "homebrewboot/HomebrewBrowse.h"
2009-10-01 01:10:58 +02:00
# include "prompts/ProgressWindow.h"
2009-11-15 20:52:58 +01:00
# include "menu/menus.h"
2009-10-01 01:10:58 +02:00
# include "mload/mload.h"
2010-02-15 00:22:52 +01:00
# include "mload/mload_modules.h"
2009-10-01 01:10:58 +02:00
# include "network/networkops.h"
2009-11-15 20:52:58 +01:00
# include "patches/patchcode.h"
# include "settings/Settings.h"
# include "settings/cfg.h"
# include "themes/Theme_Downloader.h"
# include "usbloader/disc.h"
2010-09-18 13:46:25 +02:00
# include "usbloader/GameList.h"
2009-11-15 20:52:58 +01:00
# include "xml/xml.h"
2010-05-29 09:38:54 +02:00
# include "audio.h"
2009-11-15 20:52:58 +01:00
# include "gecko.h"
# include "menu.h"
2009-10-01 01:10:58 +02:00
# include "sys.h"
# include "wpad.h"
2009-11-21 23:59:57 +01:00
# include "settings/newtitles.h"
2009-12-04 16:05:20 +01:00
# include "patches/fst.h"
2009-12-19 15:05:31 +01:00
# include "usbloader/frag.h"
# include "usbloader/wbfs.h"
2010-09-19 01:04:39 +02:00
# include "wad/nandtitle.h"
2009-10-01 01:10:58 +02:00
/*** Variables that are also used extern ***/
GuiWindow * mainWindow = NULL ;
GuiImageData * pointer [ 4 ] ;
GuiImage * bgImg = NULL ;
GuiImageData * background = NULL ;
2010-02-15 00:22:52 +01:00
GuiBGM * bgMusic = NULL ;
2009-11-10 00:03:13 +01:00
GuiSound * btnClick2 = NULL ;
2009-11-15 20:52:58 +01:00
struct discHdr * dvdheader = NULL ;
2009-10-01 01:10:58 +02:00
int currentMenu ;
2010-09-19 01:16:05 +02:00
u8 mountMethod = 0 ;
2009-10-01 01:10:58 +02:00
2009-11-15 20:52:58 +01:00
char game_partition [ 6 ] ;
2009-12-19 15:05:31 +01:00
int load_from_fs ;
2009-11-15 20:52:58 +01:00
/*** Variables used only in the menus ***/
GuiText * GameIDTxt = NULL ;
GuiText * GameRegionTxt = NULL ;
GuiImage * coverImg = NULL ;
GuiImageData * cover = NULL ;
bool altdoldefault = true ;
2010-09-24 02:48:03 +02:00
char headlessID [ 8 ] = { 0 } ;
2009-10-01 01:10:58 +02:00
static lwp_t guithread = LWP_THREAD_NULL ;
static bool guiHalt = true ;
static int ExitRequested = 0 ;
/*** Extern variables ***/
2010-01-19 11:48:50 +01:00
extern u8 shutdown ;
extern u8 reset ;
2009-10-01 01:10:58 +02:00
extern s32 gameSelected , gameStart ;
extern u8 boothomebrew ;
2009-12-24 09:33:53 +01:00
2009-10-01 01:10:58 +02:00
/****************************************************************************
* ResumeGui
*
* Signals the GUI thread to start , and resumes the thread . This is called
* after finishing the removal / insertion of new elements , and after initial
* GUI setup .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2010-09-19 01:16:05 +02:00
void ResumeGui ( )
{
2009-10-01 01:10:58 +02:00
guiHalt = false ;
2010-09-24 02:48:03 +02:00
LWP_ResumeThread ( guithread ) ;
2009-10-01 01:10:58 +02:00
}
/****************************************************************************
* HaltGui
*
* Signals the GUI thread to stop , and waits for GUI thread to stop
* This is necessary whenever removing / inserting new elements into the GUI .
* This eliminates the possibility that the GUI is in the middle of accessing
* an element that is being changed .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2010-09-19 01:16:05 +02:00
void HaltGui ( )
{
2010-09-24 02:48:03 +02:00
if ( guiHalt ) return ;
2009-10-01 01:10:58 +02:00
guiHalt = true ;
// wait for thread to finish
2010-09-24 02:48:03 +02:00
while ( ! LWP_ThreadIsSuspended ( guithread ) )
usleep ( 50 ) ;
2009-10-01 01:10:58 +02:00
}
/****************************************************************************
* UpdateGUI
*
* Primary thread to allow GUI to respond to state changes , and draws GUI
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2010-09-24 02:48:03 +02:00
static void * UpdateGUI ( void * arg )
2010-09-17 19:48:16 +02:00
{
int i ;
2010-09-24 02:48:03 +02:00
while ( ! ExitRequested )
2010-09-17 19:48:16 +02:00
{
2010-09-24 02:48:03 +02:00
if ( guiHalt )
2010-09-17 19:48:16 +02:00
{
2010-09-24 02:48:03 +02:00
LWP_SuspendThread ( guithread ) ;
2010-09-17 19:48:16 +02:00
continue ;
2009-10-01 01:10:58 +02:00
}
2010-09-17 19:48:16 +02:00
mainWindow - > Draw ( ) ;
2010-09-24 02:48:03 +02:00
if ( Settings . tooltips = = TooltipsOn & & THEME . show_tooltip ! = 0 & & mainWindow - > GetState ( ) ! = STATE_DISABLED ) mainWindow - > DrawTooltip ( ) ;
2009-10-01 01:10:58 +02:00
2010-09-24 02:48:03 +02:00
for ( i = 3 ; i > = 0 ; i - - )
2010-09-17 19:48:16 +02:00
{
2010-09-24 02:48:03 +02:00
if ( userInput [ i ] . wpad . ir . valid )
2010-09-17 19:48:16 +02:00
{
2010-09-24 02:48:03 +02:00
Menu_DrawImg ( userInput [ i ] . wpad . ir . x - 48 , userInput [ i ] . wpad . ir . y - 48 , 200.0 , 96 , 96 ,
pointer [ i ] - > GetImage ( ) , userInput [ i ] . wpad . ir . angle , Settings . widescreen ? 0.8 : 1 , 1 , 255 , 0 ,
0 , 0 , 0 , 0 , 0 , 0 , 0 ) ;
2010-09-17 19:48:16 +02:00
}
2009-10-01 01:10:58 +02:00
}
2010-01-19 11:48:50 +01:00
2010-09-17 19:48:16 +02:00
Menu_Render ( ) ;
UpdatePads ( ) ;
2010-09-24 02:48:03 +02:00
for ( i = 0 ; i < 4 ; i + + )
mainWindow - > Update ( & userInput [ i ] ) ;
2010-09-17 19:48:16 +02:00
2010-09-24 02:48:03 +02:00
if ( bgMusic ) bgMusic - > UpdateState ( ) ;
2010-09-17 19:48:16 +02:00
2010-09-24 02:48:03 +02:00
switch ( Settings . screensaver )
2010-09-17 19:48:16 +02:00
{
case 1 :
2010-09-24 02:48:03 +02:00
WPad_SetIdleTime ( 180 ) ;
2010-09-17 19:48:16 +02:00
break ;
case 2 :
2010-09-24 02:48:03 +02:00
WPad_SetIdleTime ( 300 ) ;
2010-09-17 19:48:16 +02:00
break ;
case 3 :
2010-09-24 02:48:03 +02:00
WPad_SetIdleTime ( 600 ) ;
2010-09-17 19:48:16 +02:00
break ;
case 4 :
2010-09-24 02:48:03 +02:00
WPad_SetIdleTime ( 1200 ) ;
2010-09-17 19:48:16 +02:00
break ;
case 5 :
2010-09-24 02:48:03 +02:00
WPad_SetIdleTime ( 1800 ) ;
2010-09-17 19:48:16 +02:00
break ;
case 6 :
2010-09-24 02:48:03 +02:00
WPad_SetIdleTime ( 3600 ) ;
2010-09-17 19:48:16 +02:00
break ;
}
}
2010-01-19 11:48:50 +01:00
2010-09-24 02:48:03 +02:00
for ( i = 5 ; i < 255 ; i + = 10 )
2010-09-17 19:48:16 +02:00
{
2010-09-24 02:48:03 +02:00
if ( strcmp ( headlessID , " " ) = = 0 ) mainWindow - > Draw ( ) ;
Menu_DrawRectangle ( 0 , 0 , screenwidth , screenheight , ( GXColor )
{ 0 , 0 , 0 , i } , 1 ) ;
2010-09-17 19:48:16 +02:00
Menu_Render ( ) ;
2009-10-01 01:10:58 +02:00
}
2010-09-17 19:48:16 +02:00
mainWindow - > RemoveAll ( ) ;
ShutoffRumble ( ) ;
2009-10-01 01:10:58 +02:00
return NULL ;
}
/****************************************************************************
* InitGUIThread
*
* Startup GUI threads
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2010-09-19 01:16:05 +02:00
void InitGUIThreads ( )
{
2010-09-24 02:48:03 +02:00
LWP_CreateThread ( & guithread , UpdateGUI , NULL , NULL , 65536 , LWP_PRIO_HIGHEST ) ;
2009-10-01 01:10:58 +02:00
InitProgressThread ( ) ;
InitNetworkThread ( ) ;
2010-09-24 02:48:03 +02:00
if ( Settings . autonetwork ) ResumeNetworkThread ( ) ;
2009-10-01 01:10:58 +02:00
}
2010-09-19 01:16:05 +02:00
void ExitGUIThreads ( )
{
2009-10-01 01:10:58 +02:00
ExitRequested = 1 ;
2010-09-24 02:48:03 +02:00
LWP_JoinThread ( guithread , NULL ) ;
2009-10-01 01:10:58 +02:00
guithread = LWP_THREAD_NULL ;
}
/****************************************************************************
* LoadCoverImage
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2010-09-24 02:48:03 +02:00
GuiImageData * LoadCoverImage ( struct discHdr * header , bool Prefere3D , bool noCover )
2010-02-09 11:59:55 +01:00
{
2010-09-24 02:48:03 +02:00
if ( ! header ) return NULL ;
2010-09-19 01:16:05 +02:00
GuiImageData * Cover = NULL ;
char ID [ 4 ] ;
char IDfull [ 7 ] ;
char Path [ 100 ] ;
bool flag = Prefere3D ;
2010-09-24 02:48:03 +02:00
snprintf ( ID , sizeof ( ID ) , " %c%c%c " , header - > id [ 0 ] , header - > id [ 1 ] , header - > id [ 2 ] ) ;
snprintf ( IDfull , sizeof ( IDfull ) , " %s%c%c%c " , ID , header - > id [ 3 ] , header - > id [ 4 ] , header - > id [ 5 ] ) ;
2010-09-19 01:16:05 +02:00
2010-09-24 02:48:03 +02:00
for ( int i = 0 ; i < 2 ; + + i )
2010-09-19 01:16:05 +02:00
{
2010-09-24 02:48:03 +02:00
char * coverPath = flag ? Settings . covers_path : Settings . covers2d_path ;
flag = ! flag ;
2010-09-19 01:16:05 +02:00
//Load full id image
2010-09-24 02:48:03 +02:00
snprintf ( Path , sizeof ( Path ) , " %s%s.png " , coverPath , IDfull ) ;
delete Cover ;
Cover = new ( std : : nothrow ) GuiImageData ( Path , NULL ) ;
2010-09-19 01:16:05 +02:00
//Load short id image
2010-09-24 02:48:03 +02:00
if ( ! Cover | | ! Cover - > GetImage ( ) )
2010-09-19 01:16:05 +02:00
{
2010-09-24 02:48:03 +02:00
snprintf ( Path , sizeof ( Path ) , " %s%s.png " , coverPath , ID ) ;
delete Cover ;
Cover = new ( std : : nothrow ) GuiImageData ( Path , NULL ) ;
2010-09-19 01:16:05 +02:00
}
2010-09-24 02:48:03 +02:00
if ( Cover & & Cover - > GetImage ( ) ) break ;
2010-09-19 01:16:05 +02:00
}
//Load no image
2010-09-24 02:48:03 +02:00
if ( noCover & & ( ! Cover | | ! Cover - > GetImage ( ) ) )
2010-09-19 01:16:05 +02:00
{
flag = Prefere3D ;
2010-09-24 02:48:03 +02:00
for ( int i = 0 ; i < 2 ; + + i )
2010-09-19 01:16:05 +02:00
{
2010-09-24 02:48:03 +02:00
const char * nocoverPath = ( flag ? " %snoimage.png " : " %snoimage2d.png " ) ;
flag = ! flag ;
snprintf ( Path , sizeof ( Path ) , nocoverPath , Settings . theme_path ) ;
delete Cover ;
Cover = new ( std : : nothrow ) GuiImageData ( Path , ( Prefere3D ? nocover_png : nocoverFlat_png ) ) ;
if ( Cover & & Cover - > GetImage ( ) ) break ;
2010-09-19 01:16:05 +02:00
}
}
2010-09-24 02:48:03 +02:00
if ( Cover & & ! Cover - > GetImage ( ) )
2010-09-19 01:16:05 +02:00
{
delete Cover ;
Cover = NULL ;
}
return Cover ;
2009-10-01 01:10:58 +02:00
}
/****************************************************************************
* MainMenu
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2010-09-24 02:48:03 +02:00
int MainMenu ( int menu )
2010-09-19 01:16:05 +02:00
{
2009-10-01 01:10:58 +02:00
currentMenu = menu ;
char imgPath [ 100 ] ;
2009-12-28 17:05:16 +01:00
2010-09-19 01:16:05 +02:00
//if (strcmp(headlessID,"")!=0)HaltGui();
//WindowPrompt("Can you see me now",0,"ok");
2010-01-19 11:48:50 +01:00
2010-09-24 02:48:03 +02:00
snprintf ( imgPath , sizeof ( imgPath ) , " %splayer1_point.png " , Settings . theme_path ) ;
pointer [ 0 ] = new GuiImageData ( imgPath , player1_point_png ) ;
snprintf ( imgPath , sizeof ( imgPath ) , " %splayer2_point.png " , Settings . theme_path ) ;
pointer [ 1 ] = new GuiImageData ( imgPath , player2_point_png ) ;
snprintf ( imgPath , sizeof ( imgPath ) , " %splayer3_point.png " , Settings . theme_path ) ;
pointer [ 2 ] = new GuiImageData ( imgPath , player3_point_png ) ;
snprintf ( imgPath , sizeof ( imgPath ) , " %splayer4_point.png " , Settings . theme_path ) ;
pointer [ 3 ] = new GuiImageData ( imgPath , player4_point_png ) ;
2009-10-01 01:10:58 +02:00
2010-09-24 02:48:03 +02:00
mainWindow = new GuiWindow ( screenwidth , screenheight ) ;
2009-10-01 01:10:58 +02:00
2010-09-24 02:48:03 +02:00
if ( Settings . widescreen )
snprintf ( imgPath , sizeof ( imgPath ) , " %swbackground.png " , Settings . theme_path ) ;
else snprintf ( imgPath , sizeof ( imgPath ) , " %sbackground.png " , Settings . theme_path ) ;
2009-10-01 01:10:58 +02:00
2010-09-24 02:48:03 +02:00
background = new GuiImageData ( imgPath , Settings . widescreen ? wbackground_png : background_png ) ;
2009-10-01 01:10:58 +02:00
2010-09-24 02:48:03 +02:00
bgImg = new GuiImage ( background ) ;
mainWindow - > Append ( bgImg ) ;
2009-10-01 01:10:58 +02:00
2010-09-24 02:48:03 +02:00
if ( strcmp ( headlessID , " " ) = = 0 ) ResumeGui ( ) ;
2009-10-01 01:10:58 +02:00
2010-09-24 02:48:03 +02:00
bgMusic = new GuiBGM ( bg_music_ogg , bg_music_ogg_size , Settings . volume ) ;
bgMusic - > SetLoop ( Settings . musicloopmode ) ; //loop music
bgMusic - > Load ( Settings . ogg_path ) ;
2010-09-19 01:16:05 +02:00
bgMusic - > Play ( ) ;
2009-12-28 17:05:16 +01:00
2010-09-24 02:48:03 +02:00
while ( currentMenu ! = MENU_EXIT )
2010-09-19 01:16:05 +02:00
{
2010-09-24 02:48:03 +02:00
bgMusic - > SetVolume ( Settings . volume ) ;
// gprintf("Current menu: %d\n", currentMenu);
2009-10-01 01:10:58 +02:00
2010-09-24 02:48:03 +02:00
switch ( currentMenu )
2010-09-19 01:16:05 +02:00
{
case MENU_CHECK :
currentMenu = MenuCheck ( ) ;
break ;
case MENU_FORMAT :
currentMenu = MenuFormat ( ) ;
break ;
case MENU_INSTALL :
currentMenu = MenuInstall ( ) ;
break ;
case MENU_SETTINGS :
currentMenu = MenuSettings ( ) ;
break ;
case MENU_THEMEDOWNLOADER :
currentMenu = Theme_Downloader ( ) ;
break ;
case MENU_HOMEBREWBROWSE :
currentMenu = MenuHomebrewBrowse ( ) ;
break ;
case MENU_DISCLIST :
currentMenu = MenuDiscList ( ) ;
break ;
default : // unrecognized menu
currentMenu = MenuCheck ( ) ;
break ;
2009-10-01 01:10:58 +02:00
}
}
2009-10-21 21:32:46 +02:00
2010-09-19 01:16:05 +02:00
// MemInfoPrompt();
2010-09-24 02:48:03 +02:00
gprintf ( " Exiting main GUI. mountMethod = %d \n " , mountMethod ) ;
2009-11-15 20:52:58 +01:00
2010-09-19 01:16:05 +02:00
CloseXMLDatabase ( ) ;
2009-12-03 02:06:09 +01:00
NewTitles : : DestroyInstance ( ) ;
2010-09-19 01:16:05 +02:00
CFG_Cleanup ( ) ;
2010-01-20 19:33:30 +01:00
2010-09-24 02:48:03 +02:00
if ( strcmp ( headlessID , " " ) ! = 0 ) //the GUIthread was never started, so it cant be ended and joined properly if headless mode was used. so we resume it and close it.
ResumeGui ( ) ;
2010-09-19 01:16:05 +02:00
ExitGUIThreads ( ) ;
2009-12-03 02:06:09 +01:00
2009-10-01 01:10:58 +02:00
bgMusic - > Stop ( ) ;
delete bgMusic ;
delete background ;
delete bgImg ;
delete mainWindow ;
2010-09-24 02:48:03 +02:00
for ( int i = 0 ; i < 4 ; i + + )
2009-10-01 01:10:58 +02:00
delete pointer [ i ] ;
delete GameRegionTxt ;
delete GameIDTxt ;
delete cover ;
delete coverImg ;
2010-09-19 01:16:05 +02:00
delete fontSystem ;
ShutdownAudio ( ) ;
2009-10-01 01:10:58 +02:00
StopGX ( ) ;
2010-09-19 01:16:05 +02:00
gettextCleanUp ( ) ;
2009-11-15 20:52:58 +01:00
2010-09-24 02:48:03 +02:00
if ( mountMethod = = 3 )
2010-09-19 01:16:05 +02:00
{
struct discHdr * header = gameList [ gameSelected ] ;
char tmp [ 20 ] ;
u32 tid ;
2010-09-24 02:48:03 +02:00
sprintf ( tmp , " %c%c%c%c " , header - > id [ 0 ] , header - > id [ 1 ] , header - > id [ 2 ] , header - > id [ 3 ] ) ;
memcpy ( & tid , tmp , 4 ) ;
gprintf ( " \n Booting title %016llx " , TITLE_ID ( ( header - > id [ 5 ] = = ' 1 ' ? 0x00010001 : 0x00010002 ) , tid ) ) ;
2010-09-19 01:16:05 +02:00
WII_Initialize ( ) ;
2010-09-24 02:48:03 +02:00
WII_LaunchTitle ( TITLE_ID ( ( header - > id [ 5 ] = = ' 1 ' ? 0x00010001 : 0x00010002 ) , tid ) ) ;
2010-02-09 11:59:55 +01:00
}
2010-09-24 02:48:03 +02:00
if ( mountMethod = = 2 )
2010-09-19 01:16:05 +02:00
{
2010-09-24 02:48:03 +02:00
gprintf ( " \n Loading BC for GameCube " ) ;
2010-09-19 01:16:05 +02:00
WII_Initialize ( ) ;
2010-09-24 02:48:03 +02:00
WII_LaunchTitle ( 0x0000000100000100ULL ) ;
2010-02-09 11:59:55 +01:00
}
2010-09-19 01:16:05 +02:00
2010-09-24 02:48:03 +02:00
if ( boothomebrew = = 1 )
2010-09-19 01:16:05 +02:00
{
2010-09-24 02:48:03 +02:00
gprintf ( " \n BootHomebrew " ) ;
BootHomebrew ( Settings . selected_homebrew ) ;
2010-09-19 01:16:05 +02:00
}
2010-09-24 02:48:03 +02:00
else if ( boothomebrew = = 2 )
2010-09-19 01:16:05 +02:00
{
2010-09-24 02:48:03 +02:00
gprintf ( " \n BootHomebrew from Menu " ) ;
2010-09-19 01:16:05 +02:00
//BootHomebrew();
BootHomebrewFromMem ( ) ;
}
else
{
2010-09-24 02:48:03 +02:00
gprintf ( " \t Settings.partition: %d \n " , Settings . partition ) ;
2010-09-19 01:16:05 +02:00
struct discHdr * header = NULL ;
//if the GUI was "skipped" to boot a game from main(argv[1])
2010-09-24 02:48:03 +02:00
if ( strcmp ( headlessID , " " ) ! = 0 )
2010-09-19 01:16:05 +02:00
{
2010-09-24 02:48:03 +02:00
gprintf ( " \t Headless mode (%s) \n " , headlessID ) ;
2010-09-19 01:16:05 +02:00
gameList . LoadUnfiltered ( ) ;
2010-09-24 02:48:03 +02:00
if ( ! gameList . size ( ) )
2010-09-19 01:16:05 +02:00
{
2010-09-24 02:48:03 +02:00
gprintf ( " ERROR : !gameCnt " ) ;
exit ( 0 ) ;
2010-09-19 01:16:05 +02:00
}
//gprintf("\n\tgameCnt:%d",gameCnt);
2010-09-24 02:48:03 +02:00
for ( int i = 0 ; i < gameList . size ( ) ; i + + )
2010-09-19 01:16:05 +02:00
{
header = gameList [ i ] ;
char tmp [ 8 ] ;
2010-09-24 02:48:03 +02:00
sprintf ( tmp , " %c%c%c%c%c%c " , header - > id [ 0 ] , header - > id [ 1 ] , header - > id [ 2 ] , header - > id [ 3 ] , header - > id [ 4 ] ,
header - > id [ 5 ] ) ;
if ( strcmp ( tmp , headlessID ) = = 0 )
2010-09-19 01:16:05 +02:00
{
gameSelected = i ;
2010-09-24 02:48:03 +02:00
gprintf ( " found (%d) \n " , i ) ;
2010-09-19 01:16:05 +02:00
break ;
}
//if the game was not found
2010-09-24 02:48:03 +02:00
if ( i = = gameList . GameCount ( ) - 1 )
2010-09-19 01:16:05 +02:00
{
2010-09-24 02:48:03 +02:00
gprintf ( " not found (%d IDs checked) \n " , i ) ;
exit ( 0 ) ;
2010-09-19 01:16:05 +02:00
}
}
}
2009-12-28 17:05:16 +01:00
2009-10-01 01:10:58 +02:00
int ret = 0 ;
2010-09-24 02:48:03 +02:00
header = ( mountMethod ? dvdheader : gameList [ gameSelected ] ) ;
2009-10-01 01:10:58 +02:00
2010-09-24 02:48:03 +02:00
struct Game_CFG * game_cfg = CFG_get_game_opt ( header - > id ) ;
2009-11-22 15:09:08 +01:00
2010-09-24 02:48:03 +02:00
if ( game_cfg )
2010-09-19 01:16:05 +02:00
{
2010-05-29 09:38:54 +02:00
videoChoice = game_cfg - > video ;
2009-10-01 01:10:58 +02:00
languageChoice = game_cfg - > language ;
ocarinaChoice = game_cfg - > ocarina ;
viChoice = game_cfg - > vipatch ;
fix002 = game_cfg - > errorfix002 ;
iosChoice = game_cfg - > ios ;
countrystrings = game_cfg - > patchcountrystrings ;
2010-09-24 02:48:03 +02:00
if ( ! altdoldefault )
2010-09-19 01:16:05 +02:00
{
alternatedol = game_cfg - > loadalternatedol ;
alternatedoloffset = game_cfg - > alternatedolstart ;
}
2009-10-01 01:10:58 +02:00
reloadblock = game_cfg - > iosreloadblock ;
2010-09-24 02:48:03 +02:00
returnToLoaderGV = game_cfg - > returnTo ;
2010-09-19 01:16:05 +02:00
}
else
{
2010-09-19 22:25:12 +02:00
videoChoice = Settings . videomode ;
2010-05-29 09:38:54 +02:00
languageChoice = Settings . language ;
ocarinaChoice = Settings . ocarina ;
2010-09-19 22:25:12 +02:00
viChoice = Settings . videopatch ;
iosChoice = Settings . cios ;
2010-05-29 09:38:54 +02:00
fix002 = Settings . error002 ;
countrystrings = Settings . patchcountrystrings ;
2010-09-24 02:48:03 +02:00
if ( ! altdoldefault )
2010-09-19 01:16:05 +02:00
{
alternatedol = off ;
alternatedoloffset = 0 ;
}
2010-05-29 09:38:54 +02:00
reloadblock = off ;
2010-09-24 01:47:51 +02:00
returnToLoaderGV = 1 ;
2009-10-01 01:10:58 +02:00
}
2010-09-19 01:16:05 +02:00
2010-09-24 02:48:03 +02:00
if ( ! mountMethod )
2010-09-19 01:16:05 +02:00
{
2010-09-24 02:48:03 +02:00
gprintf ( " Loading fragment list... " ) ;
ret = get_frag_list ( header - > id ) ;
gprintf ( " %d \n " , ret ) ;
2010-09-19 01:16:05 +02:00
2010-09-24 02:48:03 +02:00
gprintf ( " Setting fragment list... " ) ;
ret = set_frag_list ( header - > id ) ;
gprintf ( " %d \n " , ret ) ;
2010-09-19 01:16:05 +02:00
2010-09-24 02:48:03 +02:00
ret = Disc_SetUSB ( header - > id ) ;
if ( ret < 0 ) Sys_BackToLoader ( ) ;
gprintf ( " \t USB set to game \n " ) ;
2010-09-19 01:16:05 +02:00
}
else
{
2010-09-24 02:48:03 +02:00
gprintf ( " \t USB not set, loading DVD \n " ) ;
2010-09-19 01:16:05 +02:00
}
2009-10-01 01:10:58 +02:00
ret = Disc_Open ( ) ;
2010-09-24 02:48:03 +02:00
if ( ret < 0 ) Sys_BackToLoader ( ) ;
2009-10-01 01:10:58 +02:00
2010-09-24 02:48:03 +02:00
if ( dvdheader ) delete dvdheader ;
2009-10-21 21:32:46 +02:00
2010-09-24 02:48:03 +02:00
gprintf ( " Loading BCA data... " ) ;
ret = do_bca_code ( header - > id ) ;
gprintf ( " %d \n " , ret ) ;
2009-12-04 16:05:20 +01:00
2010-09-24 02:48:03 +02:00
if ( reloadblock = = on & & Sys_IsHermes ( ) )
2010-09-19 01:16:05 +02:00
{
2010-02-15 00:22:52 +01:00
enable_ES_ioctlv_vector ( ) ;
2010-09-24 02:48:03 +02:00
if ( load_from_fs = = PART_FS_WBFS )
2010-09-19 01:16:05 +02:00
{
mload_close ( ) ;
}
2009-10-01 01:10:58 +02:00
}
2009-12-28 17:05:16 +01:00
2010-09-19 22:25:12 +02:00
u8 errorfixer002 = fix002 ;
2009-10-01 01:10:58 +02:00
2010-09-24 02:48:03 +02:00
switch ( languageChoice )
2010-09-19 01:16:05 +02:00
{
case ConsoleLangDefault :
configbytes [ 0 ] = 0xCD ;
break ;
2009-10-01 01:10:58 +02:00
2010-09-19 01:16:05 +02:00
case jap :
configbytes [ 0 ] = 0x00 ;
break ;
2009-10-01 01:10:58 +02:00
2010-09-19 01:16:05 +02:00
case eng :
configbytes [ 0 ] = 0x01 ;
break ;
2009-10-01 01:10:58 +02:00
2010-09-19 01:16:05 +02:00
case ger :
configbytes [ 0 ] = 0x02 ;
break ;
2009-10-01 01:10:58 +02:00
2010-09-19 01:16:05 +02:00
case fren :
configbytes [ 0 ] = 0x03 ;
break ;
2009-10-01 01:10:58 +02:00
2010-09-19 01:16:05 +02:00
case esp :
configbytes [ 0 ] = 0x04 ;
break ;
2009-10-01 01:10:58 +02:00
2010-09-19 01:16:05 +02:00
case it :
configbytes [ 0 ] = 0x05 ;
break ;
2009-10-01 01:10:58 +02:00
2010-09-19 01:16:05 +02:00
case dut :
configbytes [ 0 ] = 0x06 ;
break ;
2009-10-01 01:10:58 +02:00
2010-09-19 01:16:05 +02:00
case schin :
configbytes [ 0 ] = 0x07 ;
break ;
2009-10-01 01:10:58 +02:00
2010-09-19 01:16:05 +02:00
case tchin :
configbytes [ 0 ] = 0x08 ;
break ;
2009-10-01 01:10:58 +02:00
2010-09-19 01:16:05 +02:00
case kor :
configbytes [ 0 ] = 0x09 ;
break ;
//wenn nicht genau klar ist welches
default :
configbytes [ 0 ] = 0xCD ;
break ;
2009-10-01 01:10:58 +02:00
}
u8 videoselected = 0 ;
2010-09-24 02:48:03 +02:00
switch ( videoChoice )
2010-09-19 01:16:05 +02:00
{
case discdefault :
videoselected = 0 ;
break ;
2009-10-01 01:10:58 +02:00
2010-09-19 01:16:05 +02:00
case pal50 :
videoselected = 1 ;
break ;
2009-10-01 01:10:58 +02:00
2010-09-19 01:16:05 +02:00
case pal60 :
videoselected = 2 ;
break ;
2009-10-01 01:10:58 +02:00
2010-09-19 01:16:05 +02:00
case ntsc :
videoselected = 3 ;
break ;
2009-10-01 01:10:58 +02:00
2010-09-19 01:16:05 +02:00
case systemdefault :
videoselected = 4 ;
break ;
2009-10-01 01:10:58 +02:00
2010-09-19 01:16:05 +02:00
case patch :
videoselected = 5 ;
break ;
2009-10-01 01:10:58 +02:00
2010-09-19 01:16:05 +02:00
default :
videoselected = 0 ;
break ;
2009-10-01 01:10:58 +02:00
}
u32 cheat = 0 ;
2010-09-24 02:48:03 +02:00
switch ( ocarinaChoice )
2010-09-19 01:16:05 +02:00
{
case on :
cheat = 1 ;
break ;
2009-10-01 01:10:58 +02:00
2010-09-19 01:16:05 +02:00
case off :
cheat = 0 ;
break ;
2009-10-01 01:10:58 +02:00
2010-09-19 01:16:05 +02:00
default :
cheat = 1 ;
break ;
2009-10-01 01:10:58 +02:00
}
u8 vipatch = 0 ;
2010-09-24 02:48:03 +02:00
switch ( viChoice )
2010-09-19 01:16:05 +02:00
{
case on :
vipatch = 1 ;
break ;
2009-10-01 01:10:58 +02:00
2010-09-19 01:16:05 +02:00
case off :
vipatch = 0 ;
break ;
2009-10-01 01:10:58 +02:00
2010-09-19 01:16:05 +02:00
default :
vipatch = 0 ;
break ;
2009-10-01 01:10:58 +02:00
}
2010-09-19 12:53:24 +02:00
2010-09-24 02:48:03 +02:00
u32 channel = 0 ;
if ( returnToLoaderGV )
{
2010-09-24 15:46:32 +02:00
int idx = NandTitles . FindU32 ( Settings . returnTo ) ;
if ( idx > = 0 ) channel = TITLE_LOWER ( NandTitles . At ( idx ) ) ;
2010-09-24 02:48:03 +02:00
}
2010-09-19 22:25:12 +02:00
2010-09-24 02:48:03 +02:00
//This is temporary
SetCheatFilepath ( Settings . Cheatcodespath ) ;
SetBCAFilepath ( Settings . BcaCodepath ) ;
2010-09-19 22:25:12 +02:00
2010-09-24 02:48:03 +02:00
gprintf ( " \t Disc_wiiBoot \n " ) ;
2009-11-15 20:52:58 +01:00
2010-09-24 02:48:03 +02:00
ret = Disc_WiiBoot ( Settings . dolpath , videoselected , cheat , vipatch , countrystrings , errorfixer002 ,
alternatedol , alternatedoloffset , channel ) ;
if ( ret < 0 )
2010-09-19 01:16:05 +02:00
{
2009-10-01 01:10:58 +02:00
Sys_LoadMenu ( ) ;
}
2010-05-29 09:38:54 +02:00
2010-09-19 01:16:05 +02:00
//should never get here
2010-09-24 02:48:03 +02:00
printf ( " Returning entry point: 0x%0x \n " , ret ) ;
2009-10-01 01:10:58 +02:00
}
2010-09-19 01:16:05 +02:00
return 0 ;
2009-10-01 01:10:58 +02:00
}