2009-07-15 19:20:45 +02:00
/****************************************************************************
* DiscBrowser
* USB Loader GX 2009
*
* DiscBrowser . h
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
# include "language/gettext.h"
# include "libwiigui/gui.h"
# include "libwiigui/gui_customoptionbrowser.h"
# include "prompts/PromptWindows.h"
# include "filelist.h"
# include "menu.h"
# include "usbloader/disc.h"
# include "usbloader/fstfile.h"
# include "usbloader/wdvd.h"
# include "main.h"
# include "sys.h"
# include "settings/cfg.h"
2009-08-03 20:55:55 +02:00
# include "memory.h"
2009-09-19 07:36:32 +02:00
# include "../wad/title.h"
2009-07-15 19:20:45 +02:00
/*** Extern functions ***/
extern void ResumeGui ( ) ;
extern void HaltGui ( ) ;
/*** Extern variables ***/
extern GuiWindow * mainWindow ;
extern u8 shutdown ;
extern u8 reset ;
/********************************************************************************
* Game specific settings
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-07-30 07:41:12 +02:00
int DiscBrowse ( struct discHdr * header ) {
bool exit = false ;
int ret , choice ;
u64 offset ;
2009-09-12 02:39:49 +02:00
//Halt Gui seems to fix that pain in the ass code dump. We'll see.
HaltGui ( ) ;
2009-07-30 07:41:12 +02:00
ret = Disc_SetUSB ( header - > id ) ;
if ( ret < 0 ) {
2009-09-12 02:39:49 +02:00
ResumeGui ( ) ;
2009-07-30 07:41:12 +02:00
WindowPrompt ( tr ( " ERROR: " ) , tr ( " Could not set USB. " ) , tr ( " OK " ) ) ;
2009-07-15 19:20:45 +02:00
return ret ;
2009-07-30 07:41:12 +02:00
}
2009-09-11 09:24:16 +02:00
2009-07-30 07:41:12 +02:00
ret = Disc_Open ( ) ;
if ( ret < 0 ) {
2009-09-12 02:39:49 +02:00
ResumeGui ( ) ;
2009-07-30 07:41:12 +02:00
WindowPrompt ( tr ( " ERROR: " ) , tr ( " Could not open disc. " ) , tr ( " OK " ) ) ;
2009-07-15 19:20:45 +02:00
return ret ;
2009-07-30 07:41:12 +02:00
}
ret = __Disc_FindPartition ( & offset ) ;
2009-07-15 19:20:45 +02:00
if ( ret < 0 ) {
2009-09-12 02:39:49 +02:00
ResumeGui ( ) ;
2009-07-30 07:41:12 +02:00
WindowPrompt ( tr ( " ERROR: " ) , tr ( " Could not find a WBFS partition. " ) , tr ( " OK " ) ) ;
return ret ;
}
ret = WDVD_OpenPartition ( offset ) ;
if ( ret < 0 ) {
2009-09-12 02:39:49 +02:00
ResumeGui ( ) ;
2009-07-30 07:41:12 +02:00
WindowPrompt ( tr ( " ERROR: " ) , tr ( " Could not open WBFS partition " ) , tr ( " OK " ) ) ;
return ret ;
2009-07-15 19:20:45 +02:00
}
2009-07-30 07:41:12 +02:00
2009-08-03 20:55:55 +02:00
int * buffer = ( int * ) allocate_memory ( 0x20 ) ;
2009-07-30 07:41:12 +02:00
if ( buffer = = NULL ) {
2009-09-12 02:39:49 +02:00
ResumeGui ( ) ;
2009-07-30 07:41:12 +02:00
WindowPrompt ( tr ( " ERROR: " ) , tr ( " Not enough free memory. " ) , tr ( " OK " ) ) ;
return - 1 ;
}
ret = WDVD_Read ( buffer , 0x20 , 0x420 ) ;
if ( ret < 0 ) {
2009-09-12 02:39:49 +02:00
ResumeGui ( ) ;
2009-07-30 07:41:12 +02:00
WindowPrompt ( tr ( " ERROR: " ) , tr ( " Could not read the disc. " ) , tr ( " OK " ) ) ;
return ret ;
}
2009-08-03 20:55:55 +02:00
void * fstbuffer = allocate_memory ( buffer [ 2 ] * 4 ) ;
2009-07-30 07:41:12 +02:00
FST_ENTRY * fst = ( FST_ENTRY * ) fstbuffer ;
if ( fst = = NULL ) {
2009-09-12 02:39:49 +02:00
ResumeGui ( ) ;
2009-07-30 07:41:12 +02:00
WindowPrompt ( tr ( " ERROR: " ) , tr ( " Not enough free memory. " ) , tr ( " OK " ) ) ;
free ( buffer ) ;
return - 1 ;
}
ret = WDVD_Read ( fstbuffer , buffer [ 2 ] * 4 , buffer [ 1 ] * 4 ) ;
if ( ret < 0 ) {
2009-09-12 02:39:49 +02:00
ResumeGui ( ) ;
2009-07-30 07:41:12 +02:00
WindowPrompt ( tr ( " ERROR: " ) , tr ( " Could not read the disc. " ) , tr ( " OK " ) ) ;
free ( buffer ) ;
free ( fstbuffer ) ;
return ret ;
}
2009-09-12 02:39:49 +02:00
ResumeGui ( ) ;
2009-07-30 07:41:12 +02:00
free ( buffer ) ;
WDVD_Reset ( ) ;
//Disc_SetUSB(NULL);
WDVD_ClosePartition ( ) ;
u32 discfilecount = fst [ 0 ] . filelen ;
u32 dolfilecount = 0 ;
//int offsetselect[20];
customOptionList options3 ( discfilecount ) ;
for ( u32 i = 0 ; i < discfilecount ; i + + ) {
//don't add files that aren't .dol to the list
int len = ( strlen ( fstfiles ( fst , i ) ) ) ;
if ( fstfiles ( fst , i ) [ len - 4 ] = = ' . ' & &
fstfiles ( fst , i ) [ len - 3 ] = = ' d ' & &
fstfiles ( fst , i ) [ len - 2 ] = = ' o ' & &
fstfiles ( fst , i ) [ len - 1 ] = = ' l ' ) {
options3 . SetName ( i , " %i " , i ) ;
options3 . SetValue ( i , fstfiles ( fst , i ) ) ;
//options3.SetName(i, fstfiles(fst, i));
dolfilecount + + ;
}
}
if ( dolfilecount < = 0 ) {
2009-07-15 19:20:45 +02:00
WindowPrompt ( tr ( " ERROR " ) , tr ( " No dol file found on disc. " ) , tr ( " OK " ) ) ;
free ( fstbuffer ) ;
return - 1 ;
}
2009-07-30 07:41:12 +02:00
GuiSound btnSoundOver ( button_over_pcm , button_over_pcm_size , SOUND_PCM , Settings . sfxvolume ) ;
GuiSound btnClick ( button_click2_pcm , button_click2_pcm_size , SOUND_PCM , Settings . sfxvolume ) ;
2009-07-15 19:20:45 +02:00
2009-07-30 07:41:12 +02:00
char imgPath [ 100 ] ;
2009-07-15 19:20:45 +02:00
2009-07-30 07:41:12 +02:00
snprintf ( imgPath , sizeof ( imgPath ) , " %sbutton_dialogue_box.png " , CFG . theme_path ) ;
GuiImageData btnOutline ( imgPath , button_dialogue_box_png ) ;
snprintf ( imgPath , sizeof ( imgPath ) , " %sgamesettings_background.png " , CFG . theme_path ) ;
GuiImageData settingsbg ( imgPath , settings_background_png ) ;
2009-07-15 19:20:45 +02:00
GuiTrigger trigA ;
2009-07-30 07:41:12 +02:00
trigA . SetSimpleTrigger ( - 1 , WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A , PAD_BUTTON_A ) ;
2009-07-15 19:20:45 +02:00
GuiTrigger trigHome ;
2009-07-30 07:41:12 +02:00
trigHome . SetButtonOnlyTrigger ( - 1 , WPAD_BUTTON_HOME | WPAD_CLASSIC_BUTTON_HOME , 0 ) ;
GuiTrigger trigB ;
trigB . SetButtonOnlyTrigger ( - 1 , WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B , PAD_BUTTON_B ) ;
2009-07-15 19:20:45 +02:00
2009-07-30 07:41:12 +02:00
GuiText titleTxt ( get_title ( header ) , 28 , ( GXColor ) { 0 , 0 , 0 , 255 } ) ;
titleTxt . SetAlignment ( ALIGN_CENTRE , ALIGN_TOP ) ;
titleTxt . SetPosition ( 12 , 40 ) ;
titleTxt . SetMaxWidth ( 356 , GuiText : : SCROLL ) ;
2009-07-15 19:20:45 +02:00
GuiImage settingsbackground ( & settingsbg ) ;
2009-07-30 07:41:12 +02:00
GuiButton settingsbackgroundbtn ( settingsbackground . GetWidth ( ) , settingsbackground . GetHeight ( ) ) ;
settingsbackgroundbtn . SetAlignment ( ALIGN_LEFT , ALIGN_TOP ) ;
settingsbackgroundbtn . SetPosition ( 0 , 0 ) ;
settingsbackgroundbtn . SetImage ( & settingsbackground ) ;
GuiText cancelBtnTxt ( tr ( " Back " ) , 22 , ( GXColor ) { THEME . prompttxt_r , THEME . prompttxt_g , THEME . prompttxt_b , 255 } ) ;
cancelBtnTxt . SetMaxWidth ( btnOutline . GetWidth ( ) - 30 ) ;
GuiImage cancelBtnImg ( & btnOutline ) ;
if ( Settings . wsprompt = = yes ) {
2009-07-15 19:20:45 +02:00
cancelBtnTxt . SetWidescreen ( CFG . widescreen ) ;
cancelBtnImg . SetWidescreen ( CFG . widescreen ) ;
}
2009-07-30 07:41:12 +02:00
GuiButton cancelBtn ( & cancelBtnImg , & cancelBtnImg , 2 , 3 , 180 , 400 , & trigA , & btnSoundOver , & btnClick , 1 ) ;
cancelBtn . SetScale ( 0.9 ) ;
cancelBtn . SetLabel ( & cancelBtnTxt ) ;
cancelBtn . SetTrigger ( & trigB ) ;
2009-07-15 19:20:45 +02:00
2009-07-30 07:41:12 +02:00
u8 scrollbaron = 0 ;
if ( dolfilecount > 9 )
2009-07-15 19:20:45 +02:00
scrollbaron = 1 ;
2009-07-30 07:41:12 +02:00
GuiCustomOptionBrowser optionBrowser3 ( 396 , 280 , & options3 , CFG . theme_path , " bg_options_gamesettings.png " , bg_options_settings_png , dolfilecount > 9 ? 1 : 0 , 200 ) ;
optionBrowser3 . SetPosition ( 0 , 90 ) ;
optionBrowser3 . SetAlignment ( ALIGN_CENTRE , ALIGN_TOP ) ;
HaltGui ( ) ;
GuiWindow w ( screenwidth , screenheight ) ;
w . Append ( & settingsbackgroundbtn ) ;
2009-07-15 19:20:45 +02:00
w . Append ( & titleTxt ) ;
2009-07-30 07:41:12 +02:00
w . Append ( & cancelBtn ) ;
2009-07-15 19:20:45 +02:00
w . Append ( & optionBrowser3 ) ;
2009-07-30 07:41:12 +02:00
mainWindow - > Append ( & w ) ;
ResumeGui ( ) ;
2009-07-15 19:20:45 +02:00
2009-07-30 07:41:12 +02:00
while ( ! exit ) {
VIDEO_WaitVSync ( ) ;
2009-07-15 19:20:45 +02:00
2009-07-30 07:41:12 +02:00
if ( shutdown = = 1 )
Sys_Shutdown ( ) ;
if ( reset = = 1 )
Sys_Reboot ( ) ;
2009-07-15 19:20:45 +02:00
2009-07-30 07:41:12 +02:00
ret = optionBrowser3 . GetClickedOption ( ) ;
2009-07-15 19:20:45 +02:00
2009-07-30 07:41:12 +02:00
if ( ret > 0 ) {
char temp [ 100 ] ;
2009-09-18 10:28:31 +02:00
strlcpy ( temp , fstfiles ( fst , ret ) , sizeof ( temp ) ) ;
2009-07-15 19:20:45 +02:00
choice = WindowPrompt ( temp , tr ( " Load this dol as alternate dol? " ) , tr ( " OK " ) , tr ( " Cancel " ) ) ;
2009-07-30 07:41:12 +02:00
if ( choice ) {
2009-07-15 19:20:45 +02:00
//ret = offsetselect[ret];
2009-09-18 10:28:31 +02:00
strlcpy ( alternatedname , temp , sizeof ( alternatedname ) ) ;
2009-09-11 09:24:16 +02:00
exit = true ;
2009-07-15 19:20:45 +02:00
}
2009-07-30 07:41:12 +02:00
}
2009-07-15 19:20:45 +02:00
2009-07-30 07:41:12 +02:00
if ( cancelBtn . GetState ( ) = = STATE_CLICKED ) {
2009-09-11 09:24:16 +02:00
ret = 696969 ;
exit = true ;
2009-07-30 07:41:12 +02:00
}
}
2009-07-15 19:20:45 +02:00
2009-07-30 07:41:12 +02:00
HaltGui ( ) ;
mainWindow - > Remove ( & w ) ;
ResumeGui ( ) ;
2009-07-15 19:20:45 +02:00
//free not needed list buffer anymore
2009-07-30 07:41:12 +02:00
free ( fstbuffer ) ;
2009-07-15 19:20:45 +02:00
2009-07-30 07:41:12 +02:00
return ret ;
2009-07-15 19:20:45 +02:00
}
2009-07-16 08:37:33 +02:00
2009-09-18 13:22:44 +02:00
int autoSelectDol ( const char * id , bool force ) {
2009-09-19 00:18:57 +02:00
// games that can be forced (always need alt dol)
2009-09-11 09:24:16 +02:00
//Boogie
if ( strcmp ( id , " RBOP69 " ) = = 0 ) return 657 ; //from isostar
if ( strcmp ( id , " RBOE69 " ) = = 0 ) return 675 ; //starstremr
//Fifa 08
2009-07-30 07:41:12 +02:00
if ( strcmp ( id , " RF8E69 " ) = = 0 ) return 439 ; //from isostar
if ( strcmp ( id , " RF8P69 " ) = = 0 ) return 463 ; //from isostar
if ( strcmp ( id , " RF8X69 " ) = = 0 ) return 464 ; //from isostar
2009-09-11 09:24:16 +02:00
//Grand Slam Tennis
if ( strcmp ( id , " R5TP69 " ) = = 0 ) return 1493 ; //from isostar
if ( strcmp ( id , " R5TE69 " ) = = 0 ) return 1493 ; //starstremr
//Madden NFL07
if ( strcmp ( id , " RMDP69 " ) = = 0 ) return 39 ; //from isostar
//Madden NFL08
if ( strcmp ( id , " RNFP69 " ) = = 0 ) return 1079 ; //from isostar
2009-09-19 00:18:57 +02:00
//Medal of Honor: Heroes 2
if ( strcmp ( id , " RM2X69 " ) = = 0 ) return 601 ; //dj_skual
if ( strcmp ( id , " RM2P69 " ) = = 0 ) return 517 ; //MZottel
if ( strcmp ( id , " RM2E69 " ) = = 0 ) return 492 ; //Old8oy
2009-09-11 09:24:16 +02:00
//Mortal Kombat
2009-07-30 07:41:12 +02:00
if ( strcmp ( id , " RKMP5D " ) = = 0 ) return 290 ; //from isostar
if ( strcmp ( id , " RKME5D " ) = = 0 ) return 290 ; //starstremr
2009-09-11 09:24:16 +02:00
//NBA 08
if ( strcmp ( id , " RNBX69 " ) = = 0 ) return 964 ; //from isostar
2009-07-30 07:41:12 +02:00
2009-09-11 09:24:16 +02:00
//Pangya! Golf with Style
if ( strcmp ( id , " RPYP9B " ) = = 0 ) return 12490 ; //from isostar
//Redsteel
if ( strcmp ( id , " REDP41 " ) = = 0 ) return 1957 ; //from isostar
if ( strcmp ( id , " REDE41 " ) = = 0 ) return 1957 ; //starstremr
//SSX
if ( strcmp ( id , " RSXP69 " ) = = 0 ) return 377 ; //previous value was 337
if ( strcmp ( id , " RSXE69 " ) = = 0 ) return 377 ; //previous value was 337
//Tiger Woods 10
2009-07-30 07:41:12 +02:00
if ( strcmp ( id , " R9OP69 " ) = = 0 ) return 1991 ; //from isostar
if ( strcmp ( id , " R9OE69 " ) = = 0 ) return 1973 ; //starstremr
2009-09-11 09:24:16 +02:00
//Virtual Tennis 2009
2009-07-30 07:41:12 +02:00
if ( strcmp ( id , " RVUP8P " ) = = 0 ) return 16426 ; //from isostar
if ( strcmp ( id , " RVUE8P " ) = = 0 ) return 16405 ; //from isostar
2009-09-11 09:24:16 +02:00
2009-09-18 13:22:44 +02:00
2009-09-19 00:18:57 +02:00
// games that can't be forced (alt dol is not always needed)
2009-09-18 13:22:44 +02:00
if ( ! force ) {
//Indiana Jones and the Staff of Kings (Fate of Atlantis)
if ( strcmp ( id , " RJ8P64 " ) = = 0 ) return 8 ; //from isostar
if ( strcmp ( id , " RJ8E64 " ) = = 0 ) return 8 ; //starstremr
//Medal of Honor Heroes
if ( strcmp ( id , " RMZX69 " ) = = 0 ) return 492 ; //from isostar
if ( strcmp ( id , " RMZP69 " ) = = 0 ) return 492 ; //from isostar
if ( strcmp ( id , " RMZE69 " ) = = 0 ) return 492 ; //starstremr
//Metal Slug Anthology
if ( strcmp ( id , " RMLP7U " ) = = 0 ) return 56 ; //from isostar
//The House Of The Dead 2 & 3 Return
if ( strcmp ( id , " RHDP8P " ) = = 0 ) return 149 ; //from isostar
if ( strcmp ( id , " RHDE8P " ) = = 0 ) return 149 ; //starstremr
//Wii Sports Resort
if ( strcmp ( id , " RZTP01 " ) = = 0 ) return 952 ; //from isostar
if ( strcmp ( id , " RZTE01 " ) = = 0 ) return 674 ; //from starstremr
}
2009-07-30 07:41:12 +02:00
return - 1 ;
2009-07-16 08:37:33 +02:00
}
2009-09-18 10:28:31 +02:00
int autoSelectDolMenu ( const char * id ) {
//Metroid Prime Trilogy
2009-09-19 07:36:32 +02:00
//don't let the game start without a save game in the nand
char id4 [ 10 ] ;
sprintf ( id4 , " %c%c%c%c " , id [ 0 ] , id [ 1 ] , id [ 2 ] , id [ 3 ] ) ;
if ( CheckForSave ( id4 ) = = 0 )
{
WindowPrompt ( 0 , " You need to play the game one time to create a save file. Then exit and start it again using the dol of the game you want to use. " , tr ( " Ok " ) ) ;
return - 1 ;
}
2009-09-18 10:28:31 +02:00
if ( strcmp ( id , " R3ME01 " ) = = 0 ) {
2009-09-19 00:18:57 +02:00
int choice = WindowPrompt ( tr ( " Select a DOL " ) , 0 , " Metroid Prime " , " Metroid Prime 2 " , " Metroid Prime 3 " , tr ( " Default " ) ) ;
2009-09-18 10:28:31 +02:00
switch ( choice ) {
case 1 :
choice = 780 ;
break ;
case 2 :
choice = 781 ;
break ;
case 3 :
choice = 782 ;
2009-09-19 00:18:57 +02:00
default : // no alt dol
choice = - 1 ;
2009-09-18 10:28:31 +02:00
break ;
}
return choice ;
}
if ( strcmp ( id , " R3MP01 " ) = = 0 ) {
2009-09-19 00:18:57 +02:00
int choice = WindowPrompt ( tr ( " Select a DOL " ) , 0 , " Metroid Prime " , " Metroid Prime 2 " , " Metroid Prime 3 " , tr ( " Default " ) ) ;
2009-09-18 10:28:31 +02:00
switch ( choice ) {
case 1 :
choice = 782 ;
break ;
case 2 :
choice = 783 ;
break ;
case 3 :
choice = 784 ;
2009-09-19 00:18:57 +02:00
default : // no alt dol
choice = - 1 ;
2009-09-18 10:28:31 +02:00
break ;
}
return choice ;
}
return - 1 ;
}