/WII/uLoader/source/uloader.c
C | 2767 lines | 1818 code | 775 blank | 174 comment | 406 complexity | 21254956e8291bf0f67782ad7e049a8d MD5 | raw file
Possible License(s): GPL-3.0, GPL-2.0, BSD-3-Clause
- /* uLoader- Project based in YAL and usbloader by Hermes */
-
- /*
- Copyright (C) 2009-2010 Hermes
- Copyright (C) 2009 Kwiirk (YAL)
- Copyright (C) 2009 Waninkoko (usbloader)
-
- Yet Another Loader. The barely minimum usb loader
-
- Based on SoftChip, which should be based on GeckoOS...
-
- no video, no input, try to load the wbfs passed as argument or return to menu.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
- // ALTERNATIVE_VERSION
-
- #include <gccore.h>
- #include <string.h>
- #include <malloc.h>
- #include "defs.h"
- #include "utils.h"
- #include <stdlib.h>
- #include <unistd.h>
-
- #include "libpng/pngu/pngu.h"
- #include "libwbfs/libwbfs.h"
- #include "libwbfs/wiiscrubber.h"
- #include "wbfs.h"
- #include "usbstorage2.h"
-
- #include <wiiuse/wpad.h>
- #include <sdcard/wiisd_io.h>
-
-
- #include "wdvd.h"
- #include "disc.h"
-
- #include <network.h>
- #include "remote.h"
-
- #include "global.h"
- #include "cheats.h"
-
- #include "sys/dir.h"
- #include "fatffs_util.h"
- #include "diario.h"
- #include "sonido.h"
- #include "fatffs_util.h"
-
- #include "dolmenu.h"
-
-
-
-
- char uloader_version[5]="5.1E"; // yes, you can change here the current version of the application
-
- char *str_trace=NULL;
-
- test_t *dolmenubuffer=NULL;
- extern u32 dolparameter;
-
- int skip_alternative_dol=0;
-
- u32 INK0= 0xf0000000;
- u32 INK1= 0xfff0f0f0;
- int in_black=0;
-
- int shadow_mload=0;
-
- // WBFS game configuration datas
- // field1: In Use (32 bits), field2: Unused (32 bits)
-
- // NOTE: Remember you field1 is saved in little endian format (the struct use big endian format, so you must reverse bytes)
-
- typedef struct
- {
-
- // byte 0
-
- u32 skip_boot :1; // skip boot content in Wiiwares. Old skip ios option
- u32 game_locked :1; // parental control
- u32 bca_mode :1; // bca mode 0:-> from disc 1-> from data base
- u32 pad3 :2;
- u32 hook_selected :3; // hooktype option for cheats
-
- // byte 1
-
- u32 pad2 :8;
- //u32 shadow_mload :1;
- // byte 2
-
- u32 dont_use_diary :1; // if one don't register the game in the diary
- u32 pad1 :2;
- u32 nand_mode :5; // nand_mode -> bit 0-> use SD, bit 1-> use USB, bit 2-3 -> nand folder , bit 4 -> DLC from x:/nand
-
- // byte 3
-
- u32 language :4; // language: 0-> default 1->japanese...
- u32 modevideo :2; // modevideo 0-> auto 1-> PAL 60 2-> NTSC 3-> PAL 50
- u32 ios_selected :2; // bit 0-> Use cIOS 224 (old cIOS 249), if bit 0==0 bit 1-> 0= use cIOS 222, 1= use cIOS 223
-
- } cfg_field1;
-
- cfg_field1 *game_cfg_field1=NULL;
-
- /*
-
- uhack_settings0
-
- bit 0 -> 'back in black'
- bit 1 -> force IOS 224 instead 222
-
- */
-
- extern u8 uhack_settings0;
-
- extern u8 launch_short;
-
- extern int bootTitle(u64 titleid);
-
- int cios_list[3]={222,223,224};
-
- int global_mount=0;
- u32 nand_mode=0;
-
- int frames2=0;
-
- int use_port1=0;
-
- extern float angle_icon; // angle for pointer
-
- int use_icon2=0;
-
- #define MEM_PRINT
-
- int test_mode=0;
-
- int is_fat=0; // working in FAT .ciso Mode
- int dvd_only=0; // no WBFS HDD (FAT .ciso, DVD USB, DVD)
-
- int dont_use_diary=0;
-
- u32 load_wip_code(u8 *gameid);
-
- #define CIOS 222
-
- #include <stdarg.h>
- #include <stdio.h>
-
- #include "screen.h"
- #include "fat.h"
- #include <math.h>
-
-
- #include "gfx.h"
-
- #ifndef ALTERNATIVE_VERSION
-
- #include "resources/defpng.h"
- #include "resources/defpng2.h"
- #include "resources/button1.h"
- #include "resources/button2.h"
- #include "resources/button3.h"
-
- #include "resources/icon.h"
-
- #include "resources/sound.h"
-
- #else
-
- #include "resources_alt/defpng.h"
- #include "resources_alt/defpng2.h"
- #include "resources_alt/button1.h"
- #include "resources_alt/button2.h"
- #include "resources_alt/button3.h"
-
- #include "resources_alt/icon.h"
-
- #include "resources_alt/sound.h"
-
- #endif
-
- #include "files.h"
-
- #include "mload_modules.h"
-
- extern int home_menu(struct discHdr *header);
-
- extern int call_home_menu(struct discHdr *header, int function);
-
- extern unsigned hiscore;
- extern int pintor();
-
- static syswd_t scr_poweroff;
-
- int time_sleep=0;
-
-
- static void scr_poweroff_handler(syswd_t alarm, void * arg)
- {
- if(time_sleep>1) time_sleep--;
- if(time_sleep==1) SetVideoSleep(1);
-
- }
-
- #define ticks_to_msecs(ticks) ((u32)((ticks)/(TB_TIMER_CLOCK)))
-
- u32 gettick();
-
-
- int is_16_9=0;
-
- //#include "logmodule.h"
-
- extern void* SYS_AllocArena2MemLo(u32 size,u32 align);
-
- u8 BCA_Data[64] ATTRIBUTE_ALIGN(32);
- int BCA_ret=-1;
-
- int show_bca=0;
-
-
- int force_reload_ios222=0;
- int forcevideo=0;
-
- int sd_ok=0;
- int ud_ok=0;
-
-
- #define USE_MODPLAYER 1
-
- #ifdef USE_MODPLAYER
-
- #include "asndlib.h"
-
- #ifdef ALTERNATIVE_VERSION
-
- #include "oggplayer.h"
- #include "resources_alt/bg_music.h"
-
- #else
-
- // MOD Player
- #include "gcmodplay.h"
-
- MODPlay mod_track;
-
- #include "resources/lotus3_2.h"
- #endif
-
- #endif
-
- // parental control flag
- int parental_control_on=1;
-
- /*LANGUAGE PATCH - FISHEARS*/
- u32 langsel = 0;
- char languages[11][22] =
- {
- {" Default "},
- {" Japanese "},
- {" English "},
- {" German "},
- {" French "},
- {" Spanish "},
- {" Italian "},
- {" Dutch "},
- {"S. Chinese"},
- {"T. Chinese"},
- {" Korean "}
- };
-
- u32 hook_selected=1;
-
- char hook_type_name[8][16]={
- " VBI ",
- " KPAD ",
- " Joypad ",
- " GXDraw ",
- " GXFlush ",
- "OSSleepThread",
- " AXNextFrame ",
- " VBI OLD "
- };
-
-
- //---------------------------------------------------------------------------------
- /* Global definitions */
- //---------------------------------------------------------------------------------
-
- int force_ios249=0;
-
- unsigned char *buff_cheats=NULL;
- int len_cheats=0;
-
- extern int cheats_for_wiiware;
-
- int load_cheats(u8 *discid);
-
- int load_disc(u8 *discid);
-
- // to use temporary
- u8 *temp_data= NULL;
- // to read the game conf datas
- u8 *disc_conf= NULL;
-
- // texture of white-noise animation generated here
- u32 *game_empty= NULL;
-
- s8 sound_effects[2][2048] ATTRIBUTE_ALIGN(32);
-
- //---------------------------------------------------------------------------------
- /* language GUI */
- //---------------------------------------------------------------------------------
-
- int idioma=0;
-
-
- char letrero[2][70][64]=
- {
- {"Return", "Configure", "Delete Favorite", "Add Favorite", "Load Game", "Add to Favorites", "Favorites", "Page", "Ok" ,"Discard",
- " Cheats Codes found !!! ", "Apply Codes ", "Skip Codes ", "Format WBFS", "Selected", "You have one WBFS partition", "Are You Sure You Can Format?",
- " Yes ", " No ", "Formatting...","Formatting Disc Successfull","Formatting Disc Failed",
- //22
- "Return", "Add New Game", "Add PNG Bitmap", "Delete PNG Bitmap", "Fix Parental Control","Return to Wii Menu", "Rename Game", "Delete Game", "Format Disc",
- "Alternative .dol","uLoader Update","uLoader Hacks","","",
- //36
- "Are you sure you want delete this?", "Press A to accept or B to cancel",
- // 38
- "Insert the game DVD disc...", "ERROR! Aborted", "Press B to Abort","Opening DVD disc...", "ERROR: Not a Wii disc!!",
- "ERROR: Game already installed!!!", "Installing game, please wait... ", "Done", "Change the password", "Use this password?","Restore Name",
- //49
- "Delete Alternative .dol", ".dol Search", "Searching for .dol...","Alternative .dol Selected","Alternative .dol Deleted", "Edit CFG #1", "Edit CFG #2",
- // 56
- "ehcmodule - Use USB Port 1", "ehcmodule - Use Bulk Reset","ehcmodule - Force GetMaxLun", "ehcmodule - Force SetConfiguration", "ehcmodule - Alternative Timeout",
- "No More Snow, Please!!!", "Automatic DVD/SD Mode", "Short Direct Launch (from Channel)", "Back in Black", "Force IOS 224 instead IOS 222", "???"
- },
- // spanish
- {"Retorna", "Configurar", "Borra Favorito", "A?ade Favorito", "Carga juego", "A?ade a Favoritos", "Favoritos", "Página", "Hecho", "Descartar",
- " Códigos de Trucos encontrados !!! ","Usa Códigos", "Salta Códigos", "Formatear WBFS", "Seleccionado", "Ya tienes una partición WBFS",
- "?Estas seguro que quieres formatear?", " Si ", " No ", "Formateando...", "Exito Formateando el Disco", "Error al Formatear el Disco",
- //22
- "Retornar", "A?adir Nuevo Juego", "A?adir Bitmap PNG", "Borrar Bitmap PNG", "Fijar Control Parental", "Retorna al Menu de Wii", "Renombrar Juego", "Borrar Juego", "Formatear Disco",
- ".dol Alternativo","Actualización de uLoader","uLoader Hacks","","",
-
- //36
- "?Estás seguro de que quieres borrar éste?", "Pulsa A para aceptar o B para cancelar",
- // 38
- "Inserta el DVD del juego ...", "ERROR! Abortado", "Pulsa B para Abortar","Abriendo el disco DVD...", "ERROR: No es un disco de Wii!!",
- "ERROR: Juego ya instalado!!!", "Instalando el juego, espera... ", "Terminado", "Cambia la contrase?a", "?Usar esta contrase?a?", "Restaurar Nombre",
- //49
- "Borrar .dol Alternativo", "Buscar .dol", "Buscando ficheros .dol...","Alternativo .dol Seleccionado","Alternativo .dol Borrado", "Editar CFG #1", "Editar CFG #2",
- // 56
- "ehcmodule - Usa Puerto USB 1", "ehcmodule - Usa Reset Bulk", "ehcmodule - Fuerza GetMaxLun", "ehcmodule - Fuerza SetConfiguration", "ehcmodule - Timeout Alternativo",
- "No Mas Nieve, Por Favor!!!", "Modo DVD/SD Automático", "Lanzamiento Directo Corto (Desde Canal)", "Back in Black", "Fuerza IOS 224 en lugar de IOS 222", "???",
- },
- };
-
-
- _config_file config_file ATTRIBUTE_ALIGN(32);
-
- //---------------------------------------------------------------------------------
- /* Reset and Power Off */
- //---------------------------------------------------------------------------------
-
- int exit_by_reset=0;
-
- int return_reset=2;
-
- void reset_call() {exit_by_reset=return_reset;}
- void power_call() {exit_by_reset=3;}
-
-
- int cios = CIOS;
-
- //---------------------------------------------------------------------------------
- /* from Waninkoko usbloader */
- //---------------------------------------------------------------------------------
-
-
- /* Gamelist variables */
- struct discHdr *gameList = NULL;
-
- u32 gameCnt = 0;
-
-
- s32 __Menu_EntryCmp(const void *a, const void *b)
- {
- struct discHdr *hdr1 = (struct discHdr *)a;
- struct discHdr *hdr2 = (struct discHdr *)b;
-
- /* Compare strings */
- return strcmp(hdr1->title, hdr2->title);
- }
- //---------------------------------------------------------------------------------
- /* Wiimote's routines */
- //---------------------------------------------------------------------------------
-
- unsigned temp_pad=0,new_pad=0,old_pad=0;
-
- WPADData * wmote_datas=NULL;
-
- // wiimote position (temp)
- int px=-100,py=-100;
-
- // wiimote position emulated for Guitar
- int guitar_pos_x,guitar_pos_y;
-
- static int w_index=-1;
-
- int rumble=0;
-
- void wiimote_rumble(int status)
- {
-
-
- if(config_file.rumble_off) status=0;
- //if(status==0) rumble=0;
-
- if(w_index<0)
- {
- if(status==0)
- {
- WPAD_Rumble(0, status);
- WPAD_Rumble(1, status);
- WPAD_Rumble(2, status);
- WPAD_Rumble(3, status);
- }
- return;
- }
- WPAD_Rumble(w_index, status);
-
- }
-
- void make_rumble_off()
- {
- int n;
- rumble=0;
-
- for(n=0;n<3;n++)
- {
- usleep(30*1000);
- wiimote_rumble(0);
- WPAD_Flush(w_index);
- WPAD_ScanPads();
- }
-
- }
-
- unsigned wiimote_read()
- {
- int n;
-
- int ret=-1;
-
- unsigned type=0;
-
- unsigned butt=0;
-
- wmote_datas=NULL;
-
- w_index=-1;
-
- for(n=0;n<4;n++) // busca el primer wiimote encendido y usa ese
- {
- ret=WPAD_Probe(n, &type);
-
- if(ret>=0)
- {
-
- butt=WPAD_ButtonsHeld(n);
-
- wmote_datas=WPAD_Data(n);
-
- w_index=n;
-
- break;
- }
- }
-
- if(n==4) butt=0;
-
- temp_pad=butt;
-
- new_pad=temp_pad & (~old_pad);old_pad=temp_pad;
-
- if(new_pad)
- {
- time_sleep=TIME_SLEEP_SCR;
- SetVideoSleep(0);
- }
-
- return butt;
- }
-
-
- void wiimote_ir()
- {
- px=wmote_datas->ir.x-104*is_16_9;py=wmote_datas->ir.y;
- angle_icon=wmote_datas->orient.roll;
-
- time_sleep=TIME_SLEEP_SCR;
- SetVideoSleep(0);
-
- SetTexture(NULL);
- DrawIcon(px,py,frames2);
- }
-
- void wiimote_guitar()
- {
- angle_icon=0.0f;
-
-
- if(wmote_datas->exp.gh3.js.pos.x>=wmote_datas->exp.gh3.js.center.x+8)
- {guitar_pos_x+=8;if(guitar_pos_x>(SCR_WIDTH+104*is_16_9-16)) guitar_pos_x=(SCR_WIDTH+104*is_16_9-16);}
- if(wmote_datas->exp.gh3.js.pos.x<=wmote_datas->exp.gh3.js.center.x-8)
- {guitar_pos_x-=8;if(guitar_pos_x<16-104*is_16_9) guitar_pos_x=16-104*is_16_9;}
-
-
- if(wmote_datas->exp.gh3.js.pos.y>=wmote_datas->exp.gh3.js.center.y+8)
- {guitar_pos_y-=8;if(guitar_pos_y<16) guitar_pos_y=16;}
- if(wmote_datas->exp.gh3.js.pos.y<=wmote_datas->exp.gh3.js.center.y-8)
- {guitar_pos_y+=8;if(guitar_pos_y>(SCR_HEIGHT-16)) guitar_pos_y=(SCR_HEIGHT-16);}
-
- if(guitar_pos_x<-104*is_16_9) guitar_pos_x=104*is_16_9;
- if(guitar_pos_x>(SCR_WIDTH-16+104*is_16_9)) guitar_pos_x=(SCR_WIDTH-16+104*is_16_9);
- if(guitar_pos_y<0) guitar_pos_y=0;
- if(guitar_pos_y>(SCR_HEIGHT-16)) guitar_pos_y=(SCR_HEIGHT-16);
-
- if(px!=guitar_pos_x || py!=guitar_pos_y)
- {
- time_sleep=TIME_SLEEP_SCR;
- SetVideoSleep(0);
- }
-
- px=guitar_pos_x; py=guitar_pos_y;
-
-
- SetTexture(NULL);
- DrawIcon(px,py,frames2);
-
- if(new_pad & WPAD_GUITAR_HERO_3_BUTTON_GREEN) new_pad|=WPAD_BUTTON_A;
- if(old_pad & WPAD_GUITAR_HERO_3_BUTTON_GREEN) old_pad|=WPAD_BUTTON_A;
-
- if(new_pad & WPAD_GUITAR_HERO_3_BUTTON_RED) new_pad|=WPAD_BUTTON_B;
- if(old_pad & WPAD_GUITAR_HERO_3_BUTTON_RED) old_pad|=WPAD_BUTTON_B;
-
- if(new_pad & WPAD_GUITAR_HERO_3_BUTTON_YELLOW) new_pad|=WPAD_BUTTON_1;
- if(old_pad & WPAD_GUITAR_HERO_3_BUTTON_YELLOW) old_pad|=WPAD_BUTTON_1;
-
- if(new_pad & WPAD_GUITAR_HERO_3_BUTTON_MINUS) new_pad|=WPAD_BUTTON_MINUS;
- if(old_pad & WPAD_GUITAR_HERO_3_BUTTON_MINUS) old_pad|=WPAD_BUTTON_MINUS;
-
- if(new_pad & WPAD_GUITAR_HERO_3_BUTTON_PLUS) new_pad|=WPAD_BUTTON_PLUS;
- if(old_pad & WPAD_GUITAR_HERO_3_BUTTON_PLUS) old_pad|=WPAD_BUTTON_PLUS;
-
- }
-
-
- void wiimote_classic()
- {
- angle_icon=0.0f;
-
-
- if(wmote_datas->exp.classic.ljs.pos.x>=wmote_datas->exp.classic.ljs.center.x+8)
- {guitar_pos_x+=8;if(guitar_pos_x>(SCR_WIDTH+104*is_16_9-16)) guitar_pos_x=(SCR_WIDTH+104*is_16_9-16);}
- if(wmote_datas->exp.classic.ljs.pos.x<=wmote_datas->exp.classic.ljs.center.x-8)
- {guitar_pos_x-=8;if(guitar_pos_x<16-104*is_16_9) guitar_pos_x=16-104*is_16_9;}
-
-
- if(wmote_datas->exp.classic.ljs.pos.y>=wmote_datas->exp.classic.ljs.center.y+8)
- {guitar_pos_y-=8;if(guitar_pos_y<16) guitar_pos_y=16;}
- if(wmote_datas->exp.classic.ljs.pos.y<=wmote_datas->exp.classic.ljs.center.y-8)
- {guitar_pos_y+=8;if(guitar_pos_y>(SCR_HEIGHT-16)) guitar_pos_y=(SCR_HEIGHT-16);}
-
- if(guitar_pos_x<-104*is_16_9) guitar_pos_x=104*is_16_9;
- if(guitar_pos_x>(SCR_WIDTH-16+104*is_16_9)) guitar_pos_x=(SCR_WIDTH-16+104*is_16_9);
- if(guitar_pos_y<0) guitar_pos_y=0;
- if(guitar_pos_y>(SCR_HEIGHT-16)) guitar_pos_y=(SCR_HEIGHT-16);
-
- if(px!=guitar_pos_x || py!=guitar_pos_y)
- {
- time_sleep=TIME_SLEEP_SCR;
- SetVideoSleep(0);
- }
-
- px=guitar_pos_x; py=guitar_pos_y;
-
-
- SetTexture(NULL);
- DrawIcon(px,py,frames2);
-
- if(new_pad & WPAD_CLASSIC_BUTTON_UP) new_pad|=WPAD_BUTTON_UP;
- if(old_pad & WPAD_CLASSIC_BUTTON_UP) old_pad|=WPAD_BUTTON_UP;
-
- if(new_pad & WPAD_CLASSIC_BUTTON_DOWN) new_pad|=WPAD_BUTTON_DOWN;
- if(old_pad & WPAD_CLASSIC_BUTTON_DOWN) old_pad|=WPAD_BUTTON_DOWN;
-
- if(new_pad & WPAD_CLASSIC_BUTTON_LEFT) new_pad|=WPAD_BUTTON_LEFT;
- if(old_pad & WPAD_CLASSIC_BUTTON_LEFT) old_pad|=WPAD_BUTTON_LEFT;
-
- if(new_pad & WPAD_CLASSIC_BUTTON_RIGHT) new_pad|=WPAD_BUTTON_RIGHT;
- if(old_pad & WPAD_CLASSIC_BUTTON_RIGHT) old_pad|=WPAD_BUTTON_RIGHT;
-
- if(new_pad & WPAD_CLASSIC_BUTTON_A) new_pad|=WPAD_BUTTON_A;
- if(old_pad & WPAD_CLASSIC_BUTTON_A) old_pad|=WPAD_BUTTON_A;
-
- if(new_pad & WPAD_CLASSIC_BUTTON_B) new_pad|=WPAD_BUTTON_B;
- if(old_pad & WPAD_CLASSIC_BUTTON_B) old_pad|=WPAD_BUTTON_B;
-
- if(new_pad & WPAD_CLASSIC_BUTTON_X) new_pad|=WPAD_BUTTON_1;
- if(old_pad & WPAD_CLASSIC_BUTTON_X) old_pad|=WPAD_BUTTON_1;
-
- if(new_pad & WPAD_CLASSIC_BUTTON_Y) new_pad|=WPAD_BUTTON_2;
- if(old_pad & WPAD_CLASSIC_BUTTON_Y) old_pad|=WPAD_BUTTON_2;
-
- if(new_pad & WPAD_CLASSIC_BUTTON_HOME) new_pad|=WPAD_BUTTON_HOME;
- if(old_pad & WPAD_CLASSIC_BUTTON_HOME) old_pad|=WPAD_BUTTON_HOME;
-
- if(new_pad & WPAD_CLASSIC_BUTTON_PLUS) new_pad|=WPAD_BUTTON_PLUS;
- if(old_pad & WPAD_CLASSIC_BUTTON_PLUS) old_pad|=WPAD_BUTTON_PLUS;
-
- if(new_pad & WPAD_CLASSIC_BUTTON_MINUS) new_pad|=WPAD_BUTTON_MINUS;
- if(old_pad & WPAD_CLASSIC_BUTTON_MINUS) old_pad|=WPAD_BUTTON_MINUS;
-
- }
-
- //---------------------------------------------------------------------------------
- /* Sound effects */
- //---------------------------------------------------------------------------------
-
- void snd_fx_tick()
- {
- #ifdef USE_MODPLAYER
- ASND_SetVoice(2, VOICE_MONO_8BIT, 4096*6*2,0, &sound_effects[0][0], 2048/128, 64, 64, NULL);
- #endif
- }
- void snd_fx_yes()
- {
- #ifdef USE_MODPLAYER
- ASND_SetVoice(1, VOICE_MONO_8BIT, 12000,0, &sound_effects[1][0], 2048/4, 63, 63, NULL);
- #endif
- }
-
- void snd_fx_no()
- {
- #ifdef USE_MODPLAYER
- ASND_SetVoice(1, VOICE_MONO_8BIT, 4096,0, &sound_effects[0][0], 2048/16, 96, 96, NULL);
- #endif
- }
-
- void snd_fx_scroll()
- {
- #ifdef USE_MODPLAYER
- ASND_SetVoice(2, VOICE_MONO_8BIT, 1024,0, &sound_effects[0][0], 64, 64, 64, NULL);
- #endif
- }
-
- void snd_fx_fx(int percent)
- {
- #ifdef USE_MODPLAYER
- ASND_SetVoice(2, VOICE_MONO_8BIT, 5000+percent*250,0, &sound_effects[0][0], 128, 64, 64, NULL);
- #endif
- }
-
-
-
- //---------------------------------------------------------------------------------
- /* GUI routines and datas*/
- //---------------------------------------------------------------------------------
-
-
-
- struct _game_datas
- {
- int ind;
- void * png_bmp;
- GXTexObj texture;
- u32 config;
- int is_png;
- int pad[3];
- } game_datas[32];
-
-
- struct discHdr png_header;
-
-
- void create_game_png_texture(int n)
- {
-
-
- PNGUPROP imgProp;
- IMGCTX ctx;
- char *texture_buff;
-
-
- s32 ret;
-
- game_datas[n].is_png=0;
- game_datas[n].png_bmp=NULL;
-
- if(!(disc_conf[0]=='H' && disc_conf[1]=='D' && disc_conf[2]=='R'))
- {game_datas[n].png_bmp=NULL;game_datas[n].config=0;
-
- /*if(is_fat && (png_header.version & 2))
- goto is_vc_title;*/
- return;
- }
-
-
- game_datas[n].config=disc_conf[4]+(disc_conf[5]<<8)+(disc_conf[6]<<16)+(disc_conf[7]<<24);
-
- if(disc_conf[8]==0 && disc_conf[9]=='C' && disc_conf[10]=='1' && disc_conf[11]=='6')
- {
- u16 temp_w,temp_h;
- game_datas[n].png_bmp=NULL;
- memcpy(&temp_w, (void *)&disc_conf[12], 2);
- memcpy(&temp_h, (void *)&disc_conf[14], 2);
-
- if(temp_w==0 || temp_w>256) return ;
- if(temp_h==0 || temp_h>128) return ;
-
- texture_buff=memalign(32, temp_w * temp_h *2+2048);
- if(!texture_buff) {return;}
-
- memcpy(texture_buff, (void *)&disc_conf[16], temp_w * temp_h * 2);
- game_datas[n].png_bmp=texture_buff;
- game_datas[n].is_png=0;
-
- CreateTexture(&game_datas[n].texture, TILE_RGB5A1, game_datas[n].png_bmp, temp_w, temp_h, 0);
- return;
-
- }
-
- if(!(disc_conf[9]=='P' && disc_conf[10]=='N' && disc_conf[11]=='G'))
- {game_datas[n].png_bmp=NULL;
-
- // if(is_fat && (png_header.version & 2))
- // goto is_vc_title;
- return;
- }
-
-
-
- /* Select PNG data */
- ctx = PNGU_SelectImageFromBuffer(disc_conf+8);
- if (!ctx)
- {game_datas[n].is_png=0;game_datas[n].png_bmp=NULL;return;}
-
- /* Get image properties */
- ret = PNGU_GetImageProperties(ctx, &imgProp);
- if (ret != PNGU_OK)
- {game_datas[n].is_png=0;game_datas[n].png_bmp=NULL;return;}
-
- texture_buff=memalign(32, imgProp.imgWidth * imgProp.imgHeight *4+2048);
- if(!texture_buff) {game_datas[n].png_bmp=NULL;game_datas[n].is_png=0;return;}
-
-
-
- PNGU_DecodeTo4x4RGBA8 (ctx, imgProp.imgWidth, imgProp.imgHeight, texture_buff, 255);
- PNGU_ReleaseImageContext(ctx);
-
- game_datas[n].png_bmp=texture_buff;
- game_datas[n].is_png=1;
-
- DCFlushRange( texture_buff, imgProp.imgWidth * imgProp.imgHeight *4);
-
- GX_InitTexObj(&game_datas[n].texture,texture_buff, imgProp.imgWidth, imgProp.imgHeight, GX_TF_RGBA8, GX_CLAMP , GX_CLAMP , GX_FALSE);
- GX_InitTexObjLOD(&game_datas[n].texture, // objeto de textura
- GX_LINEAR, // filtro Linear para cerca
- GX_LINEAR, // filtro Linear para lejos
- 0, 0, 0, 0, 0, GX_ANISO_1);
-
- return;
-
- #if 0
-
- is_vc_title:
-
- {
-
- char filename[256];
- void *app;
- int size_app;
- void *tpl_1;
-
- game_datas[n].png_bmp=NULL;
-
- sprintf(filename, "%s/nand/title/00010001/%02x%02x%02x%02x/content/%08x.app", (png_header.version & 1) ? "sd:" : "ud:",
- png_header.id[0], png_header.id[1], png_header.id[2], png_header.id[3], *((u32 *)&png_header.unused2[0]));
-
-
-
- void parse_banner_tpl(void *banner, void *tpl_1);
- void * tpl_2_rgba(void *tpl);
- if(FAT_read_file(filename, &app, &size_app)<0) {return;}
- parse_banner_tpl(app, &tpl_1);free(app);
- //WBFS_GetBannerTPL(png_header.id, &tpl_1);
-
-
- if(tpl_1)
- {
- game_datas[n].png_bmp=tpl_2_rgba(tpl_1);
- free(tpl_1);
- }
-
-
-
- extern u16 tpl_w, tpl_h;
-
- // save fake PNG
- if(game_datas[n].png_bmp)
- {
- /*
- disc_conf[0]='H'; disc_conf[1]='D'; disc_conf[2]='R';disc_conf[3]=((tpl_w * tpl_h *2+16+1023)/1024)-1;
- // fake PNG
- disc_conf[8]=0;
- disc_conf[9]= 'C';
- disc_conf[10]='1';
- disc_conf[11]='6';
- memcpy((void *)&disc_conf[12], &tpl_w, 2);
- memcpy((void *)&disc_conf[14], &tpl_h, 2);
-
- memcpy((void *)&disc_conf[16], game_datas[n].png_bmp, tpl_w * tpl_h * 2);
-
- global_SetProfileDatas(png_header.id, disc_conf);
- */
- CreateTexture(&game_datas[n].texture, TILE_RGB5A1, game_datas[n].png_bmp, tpl_w, tpl_h, 0);
- }
- }
- #endif
- }
-
- void display_loader_error(int ret)
- {
- switch(ret)
- {
- case 1:
- s_printf("Error: WDVD_SetUSBMode isn't supported");
- break;
- case 2:
- s_printf("Error: Bad disc ID");
- break;
- case 3:
- s_printf("Error: Bad Partition");
- break;
- case 4:
- s_printf("Fail Opening Partition");
- break;
-
- case -10001:
- s_printf("Error: Fail reading TMD");
- break;
- case -10002:
- s_printf("Error Creating Shared Content");
- break;
- case -10003:
- s_printf("Error: %08x.app don't exist", ERR_FATFSS_APP);
- break;
- case -10004:
- s_printf("Error: Creating Clone TMD");
- break;
- case -10005:
- s_printf("Error Saving Modified TMD");
- break;
- case -10006:
- s_printf("Error: .dol Not Found");
- break;
-
- case 888:
- s_printf("Error in ES_Identify()");
- break;
- case 889:
- s_printf("Error: fail loading .dol");
- break;
- case 890:
- s_printf("Error in ES_SetUID()");
- break;
- case -999:
- s_printf("Error: Bad .dol Entry Address");
- break;
- case 17:
- s_printf("Fail Loading FAT FFS Module\n");
- break;
- case 101:
- s_printf("You can't use cIOS 249 with multiple partitions!!!\n");
- break;
- case -7777:
- s_printf("ERROR: You need cIOS 223/ 224 v4-v5 to work!!!\n");
- break;
- case 666:
- s_printf("ERROR FROM THE LOADER: Disc ID is not equal!\n");
- break;
- default:
- s_printf("ERROR FROM THE LOADER: %i\n", ret);
-
- }
-
- }
-
- void usb_test()
- {
- static int n_sectors=0,errores=0;
- static u32 sector=0, sector_size;
-
- static u32 err_time=0,ok_time=0;
- static u32 first_time=0, curr_time=0,start_time=0;
- static int err=2;
- static u32 addr=0,dat,dat2=0,dat3=0,bytes_readed=0,dat4=0, flag=0;
-
-
-
- if(err==2)
- {
- err=0;
- start_time=first_time=time(NULL);
- }
-
-
- if(addr==0)
- {
- // get EHCI base registers
- mload_getw((void *) 0x0D040000, &addr);
-
- addr&=0xff;
- addr+=0x0D040000;
- }
-
-
- if(n_sectors==0)
- n_sectors = USBStorage2_GetCapacity(§or_size);
-
- dat=0;
-
- mload_getw((void *) (addr+0x44), &dat);
- if(dat!=0x1005) dat2=dat;
- if(dat2!=0x1805) dat3=dat2;
-
- PY+=32;
- s_printf("port: %x %x %x\n", dat,dat2,dat3);
- PY-=32;
-
- if(USBStorage2_ReadSectors(sector, 64*512/sector_size, disc_conf)<=0)
- {sprintf(cabecera2_str,"ERROR! %i", errores);
- errores++;err_time=gettick();if(err==0) curr_time= time(NULL)-first_time;err=1;
-
- }
- else
- {
- if(err)
- {first_time=time(NULL);ok_time=gettick();err=0;}
- sprintf(cabecera2_str,"OK %i %u Last T: %u Time %u", errores, ticks_to_msecs(ok_time-err_time), curr_time, (u32) (time(NULL)-start_time));
- bytes_readed+=64*512;
- }
-
- switch((((u32) (time(NULL)-start_time)) % 10))
- {
- case 0:
- if(flag==0)
- {dat4=bytes_readed/(10);bytes_readed=0;flag=1;}
- break;
- default:
- flag=0;
- break;
- }
-
- PY=480-64;
- s_printf("sector: %u / %u\n", sector, n_sectors);
-
- PY=480-32;
- s_printf("speed: %i bytes/sec\n", dat4);
-
-
- sector+=64*512/sector_size;
- if(sector>(n_sectors-(64*512/sector_size))) sector=0;
-
- if(err) signal_draw_cabecera2=1;
- draw_cabecera2();
- signal_draw_cabecera2=0;
- }
-
-
- int load_game_routine(u8 *discid, int game_mode);
-
- int load_file_dol(char *name);
-
-
- #ifdef MEM_PRINT
- void save_log()
- {
- FILE *fp;
- int len;
- if(!sd_ok) return;
-
- mload_init();
- len=mload_get_log();
- // mload_seek(0x13750000, SEEK_SET);
- if(len>0)
- mload_read(temp_data, len);
- mload_close();
-
- if(len<=0) return;
-
- if(sd_ok )
- {
- for(len=0;len<4096;len++)
- {
- if(temp_data[len]==0) break;
- }
-
- fp=fopen("sd:/log_ehc.txt","wb");
-
- if(fp!=0)
- {
- fwrite(temp_data,1, len ,fp);
-
- fclose(fp);
- }
- }
- }
- #endif
-
- int remote_DVD_disc_status=0;
- static struct discHdr mydisc_header ATTRIBUTE_ALIGN(32);
-
- int mode_disc=0; // bits 0-1 : 0 -> HDD, 1-> DVD Wii, 2-> USB DVD
-
- int bca_status_read=0;
-
- struct _multi_ciso multi_ciso[8];
-
- int ciso_sel=0;
-
- static u8 disc_buffer[65536] ATTRIBUTE_ALIGN(32);
-
-
- void remote_DVD_disc()
- {
- int r;
- int ciso=0;
-
- if(remote_DVD_disc_status==3)
- {
- if(mode_disc & 2)
- WDVD_SetUSBMode((u8 *) "_DVD", multi_ciso[ciso_sel].lba);
- else
- WDVD_SetUSBMode(NULL, multi_ciso[ciso_sel].lba);
-
- bca_status_read=0;BCA_ret=-1;
-
- remote_DVD_disc_status=1;
-
- WDVD_Reset();
-
- r=Disc_Open();
- if(r>=0) r=Disc_IsWii();
- if(r>=0)
- {
- if(Disc_ReadHeader(&mydisc_header)==0)
- {
- memset(BCA_Data,0,64);
- bca_status_read=0;BCA_ret=-1;
- show_bca=0;
- remote_DVD_disc_status=2;
- }
- else r=-1;
- }
- }
-
-
- /*if(mode_disc & 2) WDVD_SetUSBMode((u8 *) "_DVD", 0);
- else
- WDVD_SetUSBMode(NULL, 0);*/
-
- if(mode_disc & 2) r=Disc_USB_DVD_Wait();
- else r=Disc_Wait();
-
- if(r==0)
- {
-
- if(remote_DVD_disc_status==0)
- {
- remote_DVD_disc_status=1;
-
- if(mode_disc & 2) WDVD_SetUSBMode((u8 *) "_DVD", 0);
- else
- WDVD_SetUSBMode(NULL, 0);
-
- WDVD_Reset();
-
- r=Disc_Open();
-
- if(r>=0)
- {
- r=Disc_IsWii();
- ciso_sel=0;multi_ciso[0].len=multi_ciso[0].lba=0;
-
- // TEST for CISO Disc
-
- if(r==-1 && mode_disc && !(mode_disc & 2))
- {
- r=WDVD_UnencryptedRead(disc_buffer, 2048, 0);
- if(r>=0 && !memcmp((void *) disc_buffer, "CISO",4))
- {
- int m;
- ciso_sel=0;
- for(m=0;m<8;m++)
- {
- multi_ciso[m].len=0;
- multi_ciso[m].lba=(m==0); // add one for DVD Wii
- }
-
- WDVD_SetUSBMode(NULL, multi_ciso[ciso_sel].lba);
-
- ciso=1;
-
- r=Disc_Open();
- if(r>=0) r=Disc_IsWii();
- }
- else r=-1;
- }
-
- // TEST for UDF Disc
- if(r==-1 && (mode_disc /*& 2*/))
- {
- if(mode_disc & 2)
- r = USBStorage2_ReadSectors(16, 1, disc_buffer);
- else
- r=WDVD_UnencryptedRead(disc_buffer, 2048, 16<<11);
-
- if(r>=0 && !memcmp((void *) disc_buffer, "\0BEA01\1\0",8))
- {
- ciso=1;
-
- if(mode_disc & 2)
- r = USBStorage2_ReadSectors(256, 32, disc_buffer);
- else
- r=WDVD_UnencryptedRead(disc_buffer, 2048*32, 256<<11);
-
- if(r>=0 && !memcmp(disc_buffer, "\2\0\2\0",4))
- {
- int n,m,p, last_lba=0, curr_lba;;
- for(n=1;n<16;n++) if(!memcmp((void *) &disc_buffer[2048*n], "\1\1\2\0",4)) break;
- if(n==16) r=-1;
- else
- {
- n*=2048;
- p=0;
-
- for(m=0;m<8;m++)
- {
- if(!memcmp((void *) &disc_buffer[n+p], "\1\1\2\0",4))
- {
- u8 *punt=&disc_buffer[n+p+0x18];
-
- curr_lba=(punt[0]+(punt[1]<<8)+(punt[2]<<16)+(punt[3]<<24))+1;
-
- if(last_lba<curr_lba) last_lba=curr_lba;
-
- if(!disc_buffer[n+p+0x13] || disc_buffer[n+p+0x12]==0xa) m--;
- else
- if(disc_buffer[n+p+0x12] & 0x2)
- {
- // sorry don´t support directories (files must be in root)
- break;
- }
-
- else
- if(curr_lba>32)
- {
- // sorry LBA is out of the buffer
- break;
- }
- else
- {
- punt=&disc_buffer[curr_lba*2048+0x40];
- multi_ciso[m].len=(punt[0]+(punt[1]<<8)+(punt[2]<<16)+(punt[3]<<24));
-
- memset((void *) multi_ciso[m].name,0,64);
-
- if(disc_buffer[n+p+0x26]==16)
- {
- int s;
- for(s=0;s<63 && s< (disc_buffer[n+p+0x13]/2);s++) multi_ciso[m].name[s]=disc_buffer[n+p+0x28+s*2];
- }
- else
- {
- int s;
- for(s=0;s<63 && s< (disc_buffer[n+p+0x13]-1);s++) multi_ciso[m].name[s]=disc_buffer[n+p+0x27+s];
- }
-
- multi_ciso[m].name[63]=0;
-
- // SKIP if not .ciso file
- if(!(strstr((void *) multi_ciso[m].name, ".ciso") || strstr((void *) multi_ciso[m].name, ".CISO")))
- {
- multi_ciso[m].len=0;
- m--;
- }
-
- }
-
-
- p+=(0x26+disc_buffer[n+p+0x13]+3) & ~3;
- }
- else multi_ciso[m].len=0;
-
- }
-
- if(m<8) // bad UDF format
- r=-1;
- else
- {
-
- last_lba+=257;
-
- for(m=0;m<8;m++)
- {
- if(!multi_ciso[m].len) break;
- multi_ciso[m].lba=last_lba+1*(!(mode_disc & 2)); // add one for DVD Wii
- last_lba+=multi_ciso[m].len;
- }
- ciso_sel=0;
- //exit(0);
- if(mode_disc & 2)
- WDVD_SetUSBMode((u8 *) "_DVD", multi_ciso[ciso_sel].lba);
- else
- WDVD_SetUSBMode(NULL, multi_ciso[ciso_sel].lba);
-
- WDVD_Reset();
-
- r=Disc_Open();
- if(r>=0) r=Disc_IsWii();
- }
- }
- }
- else r=-1;
- }
- else r=-1;
- }
- // end of TEST for UDF Disc
- if(r>=0)
- {
- if(Disc_ReadHeader(&mydisc_header)==0)
- {
- memset(BCA_Data,0,64);
- if(ciso) bca_status_read=0; else bca_status_read=1;BCA_ret=-1;
- show_bca=0;
- remote_DVD_disc_status=2;
- }
- }
- else {bca_status_read=0;remote_DVD_disc_status=r;BCA_ret=-1;ciso_sel=0;multi_ciso[0].len=multi_ciso[0].lba=0;}
- }
- else {remote_DVD_disc_status=r;BCA_ret=-1;bca_status_read=0;ciso_sel=0;multi_ciso[0].len=multi_ciso[0].lba=0;}
- }
- }
- else {remote_DVD_disc_status=0;bca_status_read=0;ciso_sel=0;multi_ciso[0].len=multi_ciso[0].lba=0;}
-
- if(bca_status_read==2)
- {
- memset(BCA_Data,0,64);
- BCA_ret=WDVD_Read_Disc_BCA(BCA_Data);
- if(BCA_ret<0) memset(BCA_Data,0,64);
- bca_status_read=3;
- }
-
-
- usleep(50*1024);
- }
-
-
- void update_bca(u8 *id, u8 *bca_datas);
-
- int bca_mode=0;
-
- int get_bca(u8 *id, u8 *bca_datas);
-
- /////////////////////////////////////////////////
-
- // main() variables
- u8 discid[7];
- int direct_launch=0;
-
- int temp_game_cnt;
- struct discHdr *temp_buffer = NULL;
- /////////////////////////////////////////////////
-
-
- int menu_main();
-
- char name_button[64];
-
- //---------------------------------------------------------------------------------
- int main(int argc, char **argv) {
- //---------------------------------------------------------------------------------
- int n;
- int ret,ret2;
- struct timespec tb;
- int rel_time;
-
- if (*((u32*)0x80001800) && strncmp("STUBHAXX", (char *)0x80001804, 8) == 0) return_reset=1;
- else return_reset=2;
- /*
- if(argc<1) return_reset=2;
-
- else
- if(*((char *) argv[0])=='s') return_reset=2;
- */
-
- current_partition=0;
-
- if(argc>1)
- if(argv[1])
- {
- char *t=argv[1];
- if(t[0]=='#')
- {
- t++;
- direct_launch=1;
- memcpy(discid,t,6);
- t+=6;
- if(t[0]=='-') current_partition=t[1]-48;
- current_partition&=3;
- }
- }
-
-
- SYS_SetResetCallback(reset_call); // esto es para que puedas salir al pulsar boton de RESET
- SYS_SetPowerCallback(power_call); // esto para apagar con power
- LWP_SetThreadPriority(LWP_GetSelf(),40);
-
- SYS_CreateAlarm(&scr_poweroff);
- tb.tv_sec = 1;tb.tv_nsec = 0;
- SYS_SetPeriodicAlarm(scr_poweroff, &tb, &tb, scr_poweroff_handler, NULL);
-
- discid[6]=0;
-
- ret2=-1;
-
- cios=cios_list[0];
-
-
- if(uhack_settings0 & 2)
- {
-
- n=cios_list[0]; cios_list[0]=cios_list[2]; cios_list[2]=n;
-
- cios=cios_list[0];
-
- ret=IOS_ReloadIOS(cios);
-
- if(ret!=0)
- {
- uhack_settings0&=~2;
- cios=cios_list[2];
- ret=IOS_ReloadIOS(cios);
- }
-
- }
- else
- ret=IOS_ReloadIOS(cios);
-
- if(ret!=0)
- {
- cios=cios_list[1];
- ret=IOS_ReloadIOS(cios);
- }
-
- if(ret==0)
- {
- sleep(1);
- if((*(volatile u32 *)0x80003140 & 0xffff)<4) ret=-7777;
- }
- else
- {
- #ifndef DONT_USE_IOS249
- force_ios249=1;
- cios=249;
- ret=IOS_ReloadIOS(cios);
- #else
- ret=-1;
- #endif
- sleep(1);
- }
-
- if(CONF_Init()==0)
- {
- is_16_9=CONF_GetAspectRatio()!=0;
-
- switch(CONF_GetLanguage())
- {
- case CONF_LANG_SPANISH:
- idioma=1;break;
- default:
- idioma=0;break;
- }
-
- }
-
- InitScreen(); // Inicialización del Video
- time_sleep=TIME_SLEEP_SCR;
-
- remote_init();
-
-
- time_t my_time=(time(NULL));
- struct tm *l_time=localtime(&my_time);
-
- if(l_time)
- {
- l_time->tm_mon++;
- if(!no_more_snow)
- if((l_time->tm_mday>=12 && l_time->tm_mon==12) || l_time->tm_mon<3 || (l_time->tm_mday<=6 && l_time->tm_mon==3)) flag_snow=1;
- }
-
-
- //create_png_texture(&text_background, background, 1);
- if(1) // new background
- {
- u32 *t=(void *) SYS_AllocArena2MemLo(128*128*4*3,32);//memalign(32,128*128*4*3);
-
- memset(t, 0, 128*128*4*3);
- create_background_text(670, 128, 128, t);
- CreateTexture(&text_background[0], TILE_SRGBA8 , t, 128, 128, 1);
- create_background_text(663, 128, 128, t+128*128*1);
- CreateTexture(&text_background[1], TILE_SRGBA8 , t+128*128*1, 128, 128, 1);
- create_background_text(663*2, 128, 128, t+128*128*2);
- CreateTexture(&text_background[2], TILE_SRGBA8 , t+128*128*2, 128, 128, 1);
-
-
- GX_InitTexObj(&text_background2, t, 128, 128, GX_TF_RGBA8, GX_CLAMP, GX_CLAMP, GX_FALSE);
-
- GX_InitTexObjLOD(&text_background2, // objeto de textura
- GX_LINEAR, // filtro Linear para cerca
- GX_LINEAR, // filtro Linear para lejos
- 0, 0, 0, 0, 0, GX_ANISO_1);
- }
-
- bkcolor=0;
- remote_call(splash_scr_send);
-
- WPAD_Init();
- WPAD_SetIdleTimeout(60*5); // 5 minutes
-
- WPAD_SetDataFormat(WPAD_CHAN_ALL, WPAD_FMT_BTNS_ACC_IR); // ajusta el formato para acelerometros en todos los wiimotes
- WPAD_SetVRes(WPAD_CHAN_ALL, SCR_WIDTH+is_16_9*208, SCR_HEIGHT);
-
-
- sd_ok=0;
- for(n=0;n<5;n++)
- {
- if(__io_wiisd.startup())
- {
- sd_ok = fatMountSimple("sd", &__io_wiisd);
- if(!sd_ok) __io_wiisd.shutdown();
- }
- if(sd_ok) break;
- usleep(50000);
- }
-
-
- if(sd_ok) global_mount|=64;
-
-
- if(ret!=0)
- {
- remote_call_abort();while(remote_ret()==REMOTE_BUSY) usleep(1000*50);
- splash_scr();
- SelectFontTexture(1); // selecciona la fuente de letra extra
-
- letter_size(8,32);
-
- PX=0; PY= SCR_HEIGHT/2+32; color= INK0;
-
- bkcolor=0;
- autocenter=1;
- SetTexture(NULL);
- DrawRoundFillBox((SCR_WIDTH-540)/2, SCR_HEIGHT/2-16+32, 540, 64, 999, 0xa00000ff);
- DrawRoundBox((SCR_WIDTH-540)/2, SCR_HEIGHT/2-16+32, 540, 64, 999, 4, 0xa0000000);
- if(ret==-7777)
- s_printf("ERROR: You need cIOS222 from uLoader 3.0 v4 to work!!!\n");
- else
- #ifndef DONT_USE_IOS249
- s_printf("ERROR: You need cIOS222 and/or cIOS249 to work!!!\n");
- #else
- s_printf("ERROR: You need cIOS222 and/or cIOS223 to work!!!\n");
- #endif
- Screen_flip();
- sleep(2);
- goto error;
- }
-
- temp_data=memalign(32,256*1024);
- disc_conf=memalign(32,256*1024);
- // texture of white-noise animation generated here
- game_empty=memalign(32,128*64*3*4);
-
-
- test_and_patch_for_port1();
-
- load_ehc_module();
-
- if(external_ehcmodule)
- {remote_call_abort();while(remote_ret()==REMOTE_BUSY) usleep(1000*50);
- for(n=0;n<20;n++)
- {
-
- splash_scr();
- SelectFontTexture(1); // selecciona la fuente de letra extra
-
- letter_size(8,32);
-
- PX=0; PY= SCR_HEIGHT/2+32; color= INK0;
-
- bkcolor=0;
- autocenter=1;
- SetTexture(NULL);
- DrawRoundFillBox((SCR_WIDTH-540)/2, SCR_HEIGHT/2-16+32, 540, 64, 999, 0xa000ff00);
- DrawRoundBox((SCR_WIDTH-540)/2, SCR_HEIGHT/2-16+32, 540, 64, 999, 4, 0xa0000000);
-
- s_printf("External ehcmodule.elf loaded\n");
- Screen_flip();
- }
-
-
- }
-
- if(exit_by_reset) {test_mode=1; SYS_SetResetCallback(reset_call);exit_by_reset=0;}
-
-
-
-
- // sound pattern generator
- for(n=0;n<2;n++)
- {
- int m,l;
- switch(n)
- {
- case 0:
- l=64;
- for(m=0;m<2048;m++)
- {
- sound_effects[0][m]=((m) & l) ? 127 : -128;
- if((m & 255)==0) l>>=1; if(l<16) l=16;
- }
- break;
-
- case 1:
- l=127;
- for(m=0;m<2048;m++)
- {
- sound_effects[1][m]=((m) & 8) ? l : -l;
- if((m & 7)==0) l--; if(l<0) l=0;
- }
- break;
-
- }
- }
-
- remote_call_abort();while(remote_ret()==REMOTE_BUSY) usleep(1000*50);
- ret2=REMOTE_BUSY;
-
- num_fat_games=0;
-
- if(sd_ok)
- {
- down_frame=-1;
-
- down_mess="";//Installing SD Content";
- remote_call(wait_splash_scr);
-
- FAT_Install(1);
- down_mess="Reading .CISO and WiiWare From SD";
- down_frame=0;
- list_fat("sd:/ciso/");
-
- if(sd_ok)
- {
- load_cfg(1);
- }
-
- remote_call_abort();while(remote_ret()==REMOTE_BUSY) usleep(1000*50);
- }
-
- int ret_flag=0;
-
- rel_time= time(NULL);
-
- if(automatic_dvd_mode)
- {
- Disc_Init();
- }
-
- for(n=0;n<10;n++)
- {
- int r,mod=0;
- while(1)
- {
- WPAD_ScanPads();
-
- splash_scr();
- SelectFontTexture(1); // selecciona la fuente de letra extra
-
- letter_size(8,32);
-
- PX=0; PY= SCR_HEIGHT/2+32; color= INK0;
-
- bkcolor=0;
- autocenter=1;
- SetTexture(NULL);
-
- if(mod==0)
- {
- ret_flag=0;
- r=remote_USBStorage2_Init();
- if(r!=REMOTE_BUSY) mod=1;
-
- }
- if(mod==1)
- {
-
- r=remote_ret();
- if(r!=REMOTE_BUSY) {mod=0;ret2=r;ret_flag=1;}
-
- }
-
- if(ret2==REMOTE_BUSY) ;
- else
- if(ret2==-20001 || ret2==-20002)
- {n=0;
- DrawRoundFillBox((SCR_WIDTH-540)/2, SCR_HEIGHT/2-16+32, 540, 64, 999, 0xa00000ff);
- DrawRoundBox((SCR_WIDTH-540)/2, SCR_HEIGHT/2-16+32, 540, 64, 999, 4, 0xa0000000);
-
- if(ret2==-20001)
- s_printf("ERROR: USB Device Sector Size must be 512 bytes");
- else
- s_printf("ERROR: DVD Device Sector Size must be 2048 bytes");
-
- DrawRoundFillBox((SCR_WIDTH-540)/2, SCR_HEIGHT/2-16+32+80, 540, 64, 999, 0xa00000ff);
- DrawRoundBox((SCR_WIDTH-540)/2, SCR_HEIGHT/2-16+32+80, 540, 64, 999, 4, 0xa0000000);
-
- PY+=80;
-
- exit_by_reset=return_reset;
-
-
- }
- else
- if(ret2==-20000)
- {n=0;
- DrawRoundFillBox((SCR_WIDTH-540)/2, SCR_HEIGHT/2-16+32, 540, 64, 999, 0xa00000ff);
- DrawRoundBox((SCR_WIDTH-540)/2, SCR_HEIGHT/2-16+32, 540, 64, 999, 4, 0xa0000000);
-
- s_printf("ERROR: USB Device is detected as HUB!!!");
-
- DrawRoundFillBox((SCR_WIDTH-540)/2, SCR_HEIGHT/2-16+32+80, 540, 64, 999, 0xa00000ff);
- DrawRoundBox((SCR_WIDTH-540)/2, SCR_HEIGHT/2-16+32+80, 540, 64, 999, 4, 0xa0000000);
-
- PY+=80;
-
- if(!use_port1)
- s_printf("You need plug one device on USB port 0...");
- else
- s_printf("You need plug one device on USB port 1...");
-
- }
- else
- if(ret2==-100)
- {
- static int conta=0;
- n=0;
- DrawRoundFillBox((SCR_WIDTH-540)/2, SCR_HEIGHT/2-16+32, 540, 64, 999, 0xa00000ff);
- DrawRoundBox((SCR_WIDTH-540)/2, SCR_HEIGHT/2-16+32, 540, 64, 999, 4, 0xa0000000);
-
- s_printf("ERROR: USB Device Disconnected (try unplug/plug)");
-
- DrawRoundFillBox((SCR_WIDTH-540)/2, SCR_HEIGHT/2-16+32+80, 540, 64, 999, 0xa00000ff);
- DrawRoundBox((SCR_WIDTH-540)/2, SCR_HEIGHT/2-16+32+80, 540, 64, 999, 4, 0xa0000000);
-
- if(automatic_dvd_mode && (time(NULL)-rel_time)>5)
- {
-
- if(num_fat_games!=0) {dvd_only=1;mode_disc=0;is_fat=1;ret2=0;}
- else
- if(Disc_Wait()==0)
- {
- dvd_only=1;
- mode_disc=1;
- ret2=0;
- }
- }
-
- PY+=80;
- if(!(conta & 64))
- {
- if(!use_port1)
- s_printf("Maybe you need plug the device on USB port 0...");
- else
- s_printf("Maybe you need plug the device on USB port 1...");
- }
- else
- s_printf("Press < 2 > for DVD Mode");
-
- conta++;
-
- if((new_pad & (WPAD_BUTTON_2 | WPAD_CLASSIC_BUTTON_Y | WPAD_GUITAR_HERO_3_BUTTON_RED)) && ret2!=0)
- {
- dvd_only=1;
- if(num_fat_games==0) mode_disc=1; else {mode_disc=0;is_fat=1;}
- ret2=0;
- }
-
- //if(mode_disc) ret2=0; // mode disc
-
- }
- else
- if(ret2==-101)
- {n=0;
- DrawRoundFillBox((SCR_WIDTH-540)/2, SCR_HEIGHT/2-16+32, 540, 64, 999, 0xa00000ff);
- DrawRoundBox((SCR_WIDTH-540)/2, SCR_HEIGHT/2-16+32, 540, 64, 999, 4, 0xa0000000);
-
- s_printf("%s","ERROR: USB Device don´t work as USB 2.0 (try unplug/plug)");
-
- DrawRoundFillBox((SCR_WIDTH-540)/2, SCR_HEIGHT/2-16+32+80, 540, 64, 999, 0xa00000ff);
- DrawRoundBox((SCR_WIDTH-540)/2, SCR_HEIGHT/2-16+32+80, 540, 64, 999, 4, 0xa0000000);
-
- PY+=80;
-
- if(!use_port1)
- s_printf("Maybe you need plug the device on USB port 0...");
- else
- s_printf("Maybe you need plug the device on USB port 1...");
-
- }
- else
- if(ret2==-122)
- {
- DrawRoundFillBox((SCR_WIDTH-540)/2, SCR_HEIGHT/2-16+32, 540, 64, 999, 0xa00000ff);
- DrawRoundBox((SCR_WIDTH-540)/2, SCR_HEIGHT/2-16+32, 540, 64, 999, 4, 0xa0000000);
-
- s_printf("ERROR: Can't Mount Device");
-
- DrawRoundFillBox((SCR_WIDTH-540)/2, SCR_HEIGHT/2-16+32+80, 540, 64, 999, 0xa00000ff);
- DrawRoundBox((SCR_WIDTH-540)/2, SCR_HEIGHT/2-16+32+80, 540, 64, 999, 4, 0xa0000000);
-
- PY+=80;
- s_printf("... waiting for Storage or DVD media ...");
-
- }
- else
- if(ret2<0)
- {
- DrawRoundFillBox((SCR_WIDTH-540)/2, SCR_HEIGHT/2-16+32, 540, 64, 999, 0xa00000ff);
- DrawRoundBox((SCR_WIDTH-540)/2, SCR_HEIGHT/2-16+32, 540, 64, 999, 4, 0xa0000000);
-
- s_printf("ERROR: Could not initialize USB subsystem! (ret = %d)", ret2);
-
- DrawRoundFillBox((SCR_WIDTH-540)/2, SCR_HEIGHT/2-16+32+80, 540, 64, 999, 0xa00000ff);
- DrawRoundBox((SCR_WIDTH-540)/2, SCR_HEIGHT/2-16+32+80, 540, 64, 999, 4, 0xa0000000);
-
- PY+=80;
- s_printf("Retries: %i",n);
-
-
- }
-
- if((exit_by_reset || (new_pad & WPAD_BUTTON_HOME)))
- {
- DrawRoundFillBox((SCR_WIDTH-540)/2, SCR_HEIGHT/2-16+32+80, 540, 64, 0, 0xff0000ff);
- DrawRoundBox((SCR_WIDTH-540)/2, SCR_HEIGHT/2-16+32+80, 540, 64, 0, 4, 0xa0000000);
-
- letter_size(16,32);PY= SCR_HEIGHT/2+32+80;
- s_printf("Exiting...");
- Screen_flip();
- ret2=-1;n=100;
- break;
- }
-
- Screen_flip();
- if(ret2<0 && ret2!=-122 && ret2!=-100 && ret2!=-101 && mod<2 && ret2!=REMOTE_BUSY && ret_flag) {ret_flag=0;mod=2;}
-
-
- if(!ret2 || ret2==1) break;
-
-
- wiimote_read();
-
- if(mod>1)
- {
- mod++;if(mod>30) {mod=0;break;}
- }
-
- }
-
- //if(ret_flag==0) n--;
- if(!ret2 || ret2==1) break;
-
- }
-
- if(ret2==1)
- {
- ret2=0;
- dvd_only=1;
- mode_disc=1024+2; // USB DVD MODE
- if(num_fat_games!=0) {is_fat=1;}
- }
-
- CreatePalette(&palette_icon, TLUT_RGB5A3, 0, icon_palette, icon_palette_colors); // crea paleta 0
- CreateTexture(&text_icon[0], TILE_CI8, icon_sprite_1, icon_sprite_1_sx, icon_sprite_1_sy, 0);
- CreateTexture(&text_icon[1], TILE_CI8, icon_sprite_2, icon_sprite_2_sx, icon_sprite_2_sy, 0);
- CreateTexture(&text_icon[2], TILE_CI8, icon_sprite_3, icon_sprite_3_sx, icon_sprite_3_sy, 0);
- CreateTexture(&text_icon[3], TILE_CI8, icon_sprite_4, icon_sprite_4_sx, icon_sprite_4_sy, 0);
- CreateTexture(&text_icon[4], TILE_CI8, icon_sprite_5, icon_sprite_5_sx, icon_sprite_5_sy, 0);
-
-
- CreateTexture(&text_icon[5], TILE_CI8, icon_sprite_6, icon_sprite_6_sx, icon_sprite_6_sy, 0);
- CreateTexture(&text_icon[6], TILE_CI8, icon_sprite_7, icon_sprite_7_sx, icon_sprite_7_sy, 0);
- CreateTexture(&text_icon[7], TILE_CI8, icon_sprite_8, icon_sprite_8_sx, icon_sprite_8_sy, 0);
- CreateTexture(&text_icon[8], TILE_CI8, icon_sprite_9, icon_sprite_9_sx, icon_sprite_9_sy, 0);
-
-
- #ifdef MEM_PRINT
-
- if(test_mode && (mode_disc & 1)==0)
- {
- if(ret2>=0)
- {
- USBStorage2_TestMode(1);
-
- remote_call(usb_test);
- while(1)
- {
- WPAD_ScanPads();
- wiimote_read();
-
- if(exit_by_reset || (new_pad & WPAD_BUTTON_HOME)) break;
- usleep(1000*50);
-
- }
- }
- remote_call_abort();while(remote_ret()==REMOTE_BUSY) usleep(1000*50);
-
- splash_scr();
-
- SelectFontTexture(1); // selecciona la fuente de letra extra
-
- letter_size(8,32);
-
- PX=0; PY= SCR_HEIGHT/2+32; color= INK0;
-
- bkcolor=0;
- autocenter=1;
- SetTexture(NULL);
-
- s_printf("save log");
- Screen_flip();
-
-
- save_log();
-
- splash_scr();
-
- Screen_flip();
-
-
- if(sd_ok)
- {
- fatUnmount("sd");
- __io_wiisd.shutdown();sd_ok=0;
- }
- sleep(2);
- goto error;
-
- } // end test mode
- #endif
-
- if(ret2<0) {sleep(2);goto error;}
-
-
- remote_call(splash_scr_send);
-
- if(ret2>=0)
- {
- ret2=WBFS_Init();
- if(mode_disc && ret2<0) {mode_disc|=1024;ret2=0;} // mode disc
- if(ret2>=0) ret2=Disc_Init();
- }
-
-
- if(ret2>=0 && (mode_disc & 1026)==0)
- {
- __io_usbstorage2.startup();
- ud_ok = fatMountSimple("ud", &__io_usbstorage2);
- if(ud_ok) global_mount|=128;
- }
- else ud_ok=0;
-
- if(num_fat_games!=0) ret2=Disc_Init();;
-
- if(ud_ok)
- {
- remote_call_abort();while(remote_ret()==REMOTE_BUSY) usleep(1000*50);
-
- down_frame=-1;
- //down_mess="Installing USB Content";
- down_mess="";
- remote_call(wait_splash_scr);
-
- FAT_Install(0);
-
- down_mess="Reading .CISO and WiiWare From USB";
- down_frame=0;
- list_fat("ud:/ciso/");
- remote_call_abort();while(remote_ret()==REMOTE_BUSY) usleep(1000*50);
- remote_call(splash_scr_send);
- }
-
- /*
- // test warning
- if(usb_clusters) usb_clusters=4;
- if(sd_clusters) sd_clusters=4;
- */
-
- if((sd_clusters && sd_clusters<32) || (usb_clusters && usb_clusters<32))
- {
- remote_call_abort();while(remote_ret()==REMOTE_BUSY) usleep(1000*50);
- cluster_warning();
- remote_call_abort();while(remote_ret()==REMOTE_BUSY) usleep(1000*50);
- remote_call(splash_scr_send);
- }
-
-
- if(!direct_launch) sleep(2); //for(n=0;n<120;n++) {splash_scr();Screen_flip();}
-
- //
-
-
- screen_fx=memalign(32, 128*128*4);
-
- create_png_texture(&text_button[0], button1, 32);
- create_png_texture(&text_button[1], button2, 32);
- create_png_texture(&text_button[2], button3, 32);
- text_button[3]=text_button[1];
-
- create_png_texture(& default_game_texture, defpng, 32);
- create_png_texture(& default_game_texture2, defpng2, 32);
-
-
- if(sd_ok && (uhack_settings0 & 1))
- {
- int len;
-
- if(FAT_read_file("sd:/background.png", &background_png, &len)<0)
- FAT_read_file("sd:/apps/uloader/background.png", &background_png, &len);
-
- if(background_png)
- {
-
- create_png_texture(&text_background[3], background_png, 32);
- free(background_png);background_png= (void *) 0xffffffff; // fake pointer
- }
-
- }
-
- if(ud_ok && (uhack_settings0 & 1) && !background_png)
- {
- int len;
-
- if(FAT_read_file("ud:/background.png", &background_png, &len)<0)
- FAT_read_file("ud:/apps/uloader/background.png", &background_png, &len);
-
- if(background_png)
- {
- create_png_texture(&text_background[3], background_png, 32);
- free(background_png);background_png= (void *) 0xffffffff; // fake pointer
- }
- }
-
- for(n=0;n<128*64*3;n++)
- {
- switch((rand()>>3) & 7)
- {
- case 0:
- game_empty[n]=0xfff0f0f0;break;
- case 1:
- game_empty[n]=0xff404040;break;
- case 2:
- game_empty[n]=0xffd0d0d0;break;
- case 3:
- game_empty[n]=0xffc0c0c0;break;
- case 4:
- game_empty[n]=0xffc0a000;break;
- case 5:
- game_empty[n]=0xff404040;break;
- case 6:
- game_empty[n]=0xffd0d0d0;break;
- case 7:
- game_empty[n]=0xffc0c0c0;break;
- }
- }
-
-
- CreateTexture(&text_game_empty[0], TILE_SRGBA8, &game_empty[0], 128, 64, 0);
- CreateTexture(&text_game_empty[1], TILE_SRGBA8, &game_empty[128*64], 128, 64, 0);
- CreateTexture(&text_game_empty[2], TILE_SRGBA8, &game_empty[128*64*2], 128, 64, 0);
- text_game_empty[3]=text_game_empty[1];
-
- remote_call_abort();while(remote_ret()==REMOTE_BUSY) usleep(1000*50);
- splash_scr();
-
- SelectFontTexture(1); // selecciona la fuente de letra extra
-
- letter_size(8,32);
-
- PX=0; PY= SCR_HEIGHT/2+32; color= INK0;
-
- bkcolor=0;
- autocenter=1;
- SetTexture(NULL);
-
- if (ret2 < 0) {
- DrawRoundFillBox((SCR_WIDTH-540)/2, SCR_HEIGHT/2-16+32, 540, 64, 999, 0xa00000ff);
- DrawRoundBox((SCR_WIDTH-540)/2, SCR_HEIGHT/2-16+32, 540, 64, 999, 4, 0xa0000000);
-
- s_printf("ERROR: Could not initialize WBFS subsystem! (ret = %d)", ret2);
-
- DrawRoundFillBox((SCR_WIDTH-540)/2, SCR_HEIGHT/2-16+32+80, 540, 64, 999, 0xa00000ff);
- DrawRoundBox((SCR_WIDTH-540)/2, SCR_HEIGHT/2-16+32+80, 540, 64, 999, 4, 0xa0000000);
-
- PY+=80;
-
- if(!use_port1)
- s_printf("Maybe you need plug the device on USB port 0...");
- else
- s_printf("Maybe you need plug the device on USB port 1...");
-
- Screen_flip();
- sleep(2);
- goto error;
- }
- Screen_flip();
-
-
-
-
- #if 1
-
- #ifdef USE_MODPLAYER
- ASND_Init();
- ASND_Pause(0);
-
- if(l_time)
- {
-
- if(l_time->tm_mday>=1 && l_time->tm_mday<=6 && l_time->tm_mon==1 && l_time->tm_year>109) happy_new_year(l_time->tm_year);
-
- }
-
-
- remote_call(splash_scr_send);
- // inicializa el modplayer en modo loop infinito
-
- #ifndef ALTERNATIVE_VERSION
- MODPlay_Init(&mod_track);
-
- n=-1;
- if(sd_ok)
- {
- FILE *fp;
- fp=fopen("sd:/apps/uloader/music.mod","rb");
-
- if(fp!=0)
- {
- int size;
- char *p;
-
- fseek(fp, 0, SEEK_END);
- size = ftell(fp);
- p= malloc(size);
- if(p)
- {
- fseek(fp, 0, SEEK_SET);
-
- if(fread(p,1, size ,fp)==size)
- {
- n=MODPlay_SetMOD (&mod_track, p);
- }
- else free(p);
- }
-
- fclose(fp);
- }
- }
- if(n<0) n=MODPlay_SetMOD (&mod_track, lotus3_2 );
- if (n < 0 ) // set the MOD song
- {
- MODPlay_Unload (&mod_track);
- }
- else
- {
-
- MODPlay_SetVolume( &mod_track, 16, 16); // fix the volume to 16 (max 64)
- MODPlay_Start (&mod_track); // Play the MOD
-
- }
-
- #else
-
- // Ogg
-
- if(sd_ok)
- {
- FILE *fp;
- int ogg_size;
- void *ogg_file;
-
- fp=fopen("sd:/apps/uloader/music.ogg","rb"); // abre fichero
-
- if(fp!=0)
- {
- fseek(fp, 0, SEEK_END); // situa el puntero de lectura al final del fichero
- ogg_size = ftell(fp); // obtiene la posicion del puntero (al estar al final, obtiene el tama?o del fichero ;)
-
- fseek(fp, 0, SEEK_SET); // situa el puntero de lectura al principio del fichero
-
- ogg_file=malloc(ogg_size+128); /* asigna memoria suficiente para leer el fichero ogg al completo mas 128 bytes extras de proteccion (seguramente no haga falta, pero por si alguna lectura rebasa un poco) */
-
- if(ogg_file) // si tenemos memoria asignada, procede
- {
- if(fread(ogg_file,1, ogg_size ,fp)==ogg_size) // lee el fichero al completo, si no falla procede
- {
- PlayOgg(mem_open(ogg_file, ogg_size),0,OGG_INFINITE_TIME); // tocala otra vez, Sam
- }
- }
-
- fclose(fp); // cierra el fichero
- }
- else PlayOgg(mem_open((void *) bg_music, size_bg_music),0,OGG_INFINITE_TIME);
- }
- else PlayOgg(mem_open((void *) bg_music, size_bg_music),0,OGG_INFINITE_TIME);
-
- #endif
-
- #endif
-
- remote_call_abort();while(remote_ret()==REMOTE_BUSY) usleep(1000*50);
- splash_scr();
-
- SelectFontTexture(1); // selecciona la fuente de letra extra
-
- letter_size(16,32);
- PX=0; PY= SCR_HEIGHT/2+32; color= INK0;
-
- bkcolor=0;
- autocenter=1;
- SetTexture(NULL);
-
- Screen_flip();
-
- n=menu_main();
- if(n==1) goto exit_ok;
- if(n==2) goto error_w;
-
-
- VIDEO_SetBlack(TRUE);
- VIDEO_Flush();
- VIDEO_WaitVSync();
-
- exit_ok:
-
- mload_set_ES_ioctlv_vector(NULL);
- mload_close();
- #ifdef USE_MODPLAYER
-
- #ifdef ALTERNATIVE_VERSION
- StopOgg();
- #endif
- ASND_End(); // finaliza el sonido
- #endif
- make_rumble_off();
- wiimote_read();
- WPAD_Shutdown();
- USBStorage2_Umount();
- SYS_RemoveAlarm(scr_poweroff);
-
- Diario_InvalidarDiario();
-
- sleep(1);
-
- if(exit_by_reset<2 && !(*((u32*)0x80001800) && strncmp("STUBHAXX", (char *)0x80001804, 8) == 0)) exit_by_reset=2;
-
- if(exit_by_reset==2)
- SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
- if(exit_by_reset==3)
- SYS_ResetSystem(SYS_POWEROFF_STANDBY, 0, 0);
- return 0;
-
- error_w:
-
- mload_set_ES_ioctlv_vector(NULL);
- mload_close();
- #ifdef USE_MODPLAYER
- #ifdef ALTERNATIVE_VERSION
- StopOgg();
- #endif
- ASND_End(); // finaliza el sonido
- #endif
-
-
- error:
- make_rumble_off();
- wiimote_read();
-
- WPAD_Shutdown();
-
- remote_call_abort();while(remote_ret()==REMOTE_BUSY) usleep(1000*50);
- remote_end();
- SYS_RemoveAlarm(scr_poweroff);
- Diario_InvalidarDiario();
-
- VIDEO_SetBlack(TRUE);
- VIDEO_Flush();
- VIDEO_WaitVSync();
-
- sleep(2);
- if(sd_ok)
- {
- fatUnmount("sd");
- __io_wiisd.shutdown();sd_ok=0;
- }
- if(ud_ok)
- {
- fatUnmount("ud");
- __io_usbstorage2.shutdown();ud_ok=0;
- }
-
- if(exit_by_reset<2 && !(*((u32*)0x80001800) && strncmp("STUBHAXX", (char *)0x80001804, 8) == 0)) exit_by_reset=2;
-
- if(exit_by_reset==2)
- SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
- if(exit_by_reset==3)
- SYS_ResetSystem(SYS_POWEROFF_STANDBY, 0, 0);
-
- return 0;
- // return ret;
- }
-
-
- static u32 lba_start=0;
-
- static int init_ciso_table=1;
-
- int fun_fat_read(void*fp,u32 offset,u32 count,void*iobuf)
- {
-
- int ret,l;
-
- static u32 table_lba[2048];
- static u8 mem_index[2048];
- static u8 buff[32768] ATTRIBUTE_ALIGN(32);
- static int ciso_size;
-
-
- if(!fp)
- {
- void *temp_ptr;
- int size2;
-
- size2=(count+31) & ~31;
-
- temp_ptr=memalign(32, size2);
-
- if(!temp_ptr) return 0;
-
-
- if(WDVD_UnencryptedRead(temp_ptr, size2, ((u64)offset)<<2)<0) count=0;
-
-
- if(count)
- {
- memcpy(iobuf, temp_ptr, count);
- }
-
- free(temp_ptr);
-
- return (count==0);
- }
-
- if(init_ciso_table)
- {
- u32 lba_glob=(lba_start<<9)+(16<<9);
-
-
- fseek(fp,(lba_start<<11), SEEK_SET);
-
- ret=fread(buff,1, 32768 ,fp);
- if(ret<=0) {return 1;}
- else
- if(!(buff[0]=='C' && buff[1]=='I' && buff[2]=='S' && buff[3]=='O')) return 1;
- ciso_size=(((u32)buff[4])+(((u32)buff[5])<<8)+(((u32)buff[6])<<16)+(((u32)buff[7])<<24))/4;
-
- memset(mem_index,0,2048);
-
-
- for(l=0;l<16384;l++)
- {
-
- if((l & 7)==0) table_lba[l>>3]=lba_glob;
-
- if(buff[(8+l)])
- {
- mem_index[l>>3]|=1<<(l & 7);
- lba_glob+=ciso_size;
- }
- }
-
- init_ciso_table=0;
- }
-
- if(!init_ciso_table)
- {
- u32 temp=((u32) offset)/ciso_size;
-
-
- u32 read_lba=table_lba[temp>>3];
-
- for(l=0;l<(temp & 7);l++) if((mem_index[temp>>3]>>l) & 1) read_lba+=ciso_size;
-
- read_lba<<=2;
-
- read_lba+=((offset) & (ciso_size-1))<<2;
-
-
- fseek(fp, read_lba, SEEK_SET);
- //ret=fread(ptr,1, size ,fp_disc);
- return !(fread(iobuf, 1, count, fp)==count);
-
- }
-
- return 1;
- }
-
-
- char bannerTitle[84];
-
- // adapted from Mark R. (USB Loader mrc v9)
- char* FAT_BannerTitle(char *path, SoundInfo *snd ){
- void *banner = NULL;
- int size;
- FILE *fp;
- int indx=0;
-
- fp=fopen(path, "r");
- if(!fp) goto error;
-
- init_ciso_table=1;
- lba_start=0;
-
- size = wbfs_extract_file2(fp, "opening.bnr", &banner, fun_fat_read);
-
- fclose(fp);
-
- if (!banner || size <= 0) goto error;
-
- if(memcmp(((char *) banner)+0x40+indx, "IMET", 4))
- {
- indx+=0x40;
- if(memcmp(((char *) banner)+0x40+indx, "IMET", 4)) goto error;
- }
-
- int i;
- for(i=0;i<84;i++)
- bannerTitle[i]=((char*)banner)[0xB0+i+indx];
-
- parse_banner_snd(banner, snd);
-
- //SAFE_FREE(banner);
- if(banner){
- free(banner);
- banner=NULL;
- }
-
- return bannerTitle;
- error:
- return NULL;
- }
-
- s32 __WBFS_ReadDVD(void *fp, u32 lba, u32 len, void *iobuf);
-
- char* disc_BannerTitle(u32 lba, SoundInfo *snd ){
- void *banner = NULL;
- int size;
- FILE *fp=NULL;
- int indx=0;
-
- init_ciso_table=1;
- lba_start=lba;
-
- size = wbfs_extract_file2(fp, "opening.bnr", &banner, __WBFS_ReadDVD/*fun_fat_read*/);
-
-
- if (!banner || size <= 0) goto error;
-
-
- if(memcmp(((char *) banner)+0x40+indx, "IMET", 4))
- {
- indx+=0x40;
- if(memcmp(((char *) banner)+0x40+indx, "IMET", 4)) goto error;
- }
-
- int i;
- for(i=0;i<84;i++)
- bannerTitle[i]=((char*)banner)[0xB0+i+indx];
-
- parse_banner_snd(banner, snd);
-
- //SAFE_FREE(banner);
- if(banner){
- free(banner);
- banner=NULL;
- }
-
-
- return bannerTitle;
- error:
-
- return NULL;
- }
- char* banner_title=NULL;
-
- extern void * title_dol;
- extern void * title_banner;
-
-
- int load_game_routine(u8 *discid, int game_mode)
- {
- int n, ret,ret2;
- int force_ingame_ios=0;
-
- int flag_disc=game_mode & 0xa00000;
-
- static u64 titleid=0;
-
- make_rumble_off();
-
- wiimote_read();
-
- static SoundInfo snd;
- memset(&snd, 0, sizeof(snd));
-
-
- titleid=0ULL;
-
- if(game_mode & 0x400000) // load title
- {
- static u8 str_id[8];
-
- titleid=0x0001000100000000ULL;
- memcpy(((char *) &titleid)+4, discid, 4);
-
- game_mode^=0x400000;
-
- game_cfg_field1= (void *) &game_datas[game_mode-1].config;
-
- force_ingame_ios= game_cfg_field1->skip_boot;
-
- cabecera2("Reading The Title ...");
-
- ret=FAT_get_title(titleid, &title_dol, str_id, force_ingame_ios);
-
- if(ret<0) return ret;
-
- //discid=(void *) str_id;
-
- }
-
- #if 1
- if(!titleid)
- {
-
- thread_in_second_plane=1;
-
- cabecera2("Reading The Banner...");
-
- if(flag_disc)
- {
- banner_title=disc_BannerTitle(0, &snd);
-
- }
- else
- if(is_fat)
- {
- char *path;
-
- get_fat_name_pass=1;
-
- path=get_fat_name(discid);
-
- get_fat_name_pass=0;
-
-
- if(path)
- banner_title=FAT_BannerTitle(path, &snd);
- else banner_title=NULL;
-
-
- }
- else
- {
- banner_title=WBFS_BannerTitle(discid, &snd);
-
- }
- }
- else
- {
-
- if(title_banner)
- {
- int indx=0,i;
-
- banner_title=NULL;
-
- if(memcmp(((char *) title_banner)+0x40+indx, "IMET", 4))
- {
- indx+=0x40;
- if(memcmp(((char *) title_banner)+0x40+indx, "IMET", 4)) goto title_error;
- }
-
- for(i=0;i<84;i++)
- bannerTitle[i]=((char*)title_banner)[0xB0+i+indx];
-
- banner_title=bannerTitle;
-
- parse_banner_snd(title_banner, &snd);
-
- title_error:
- if(title_banner){free(title_banner);title_banner=NULL;}
- }
- }
- ASND_StopVoice(0);
- #ifdef USE_MODPLAYER
- #ifdef ALTERNATIVE_VERSION
- StopOgg();
- #else
-
- //MODPlay_Stop(&mod_track);
- MODPlay_Unload (&mod_track);
- #endif
- //ASND_End(); // finaliza el sonido
- #endif
- if (snd.dsp_data)
- {
-
-
- ASND_StopVoice(4);
-
- int fmt = (snd.channels == 2) ? VOICE_STEREO_16BIT : VOICE_MONO_16BIT;
-
- if(snd.loop) ASND_SetInfiniteVoice(4, fmt, snd.rate, 0, snd.dsp_data, snd.size, 160,160);
- else ASND_SetVoice(4, fmt, snd.rate, 0, snd.dsp_data, snd.size, 96,96, NULL);
- }
-
-
- thread_in_second_plane=0;
- #endif
-
- //WPAD_Shutdown();
-
- game_mode &= ~0xa00000;
-
- add_game_log(discid);
-
- if(!flag_disc)
- save_cfg(0);
- else
- save_cfg(1);
-
- game_cfg_field1= (void *) &game_datas[game_mode-1].config;
-
- #ifndef DONT_USE_IOS249
- if((game_cfg_field1->ios_selected & 1) || force_ios249) cios=249;
- else { if(game_cfg_field1->ios_selected & 2) cios=cios_list[1]; else cios=cios_list[0];}
- #else
- if((game_cfg_field1->ios_selected & 1)) cios=cios_list[2];
- else {if(game_cfg_field1->ios_selected & 2) cios=cios_list[1]; else cios=cios_list[0];}
- // game_datas[game_mode-1].config &=~1;
- #endif
-
- dont_use_diary= game_cfg_field1->dont_use_diary;
- //shadow_mload= game_cfg_field1->shadow_mload;
-
- forcevideo= game_cfg_field1->modevideo;//if(forcevideo==3) forcevideo=0;
-
- langsel= game_cfg_field1->language; if(langsel>10) langsel=0;
-
- if(!titleid)
- nand_mode= game_cfg_field1->nand_mode;
-
- force_ingame_ios=0; // unused for disc games now //1*((game_datas[game_mode-1].config>>31)!=0);
-
- //bca_mode=(game_datas[game_mode-1].config>>29) & 1;
-
- hook_selected= (game_cfg_field1->hook_selected)+1;
- //game_locked_cfg=1*((game_datas[game_mode-1].config & (1<<30))!=0);
-
- if(!((bca_mode & 1) && get_bca(discid, BCA_Data))) bca_mode=0;
-
- // alternative dol when it don't use WDM files
- if(!skip_alternative_dol)
- Get_AlternativeDol(discid);
-
- load_wip_code(discid);
-
-
- if(sd_ok)
- {
- fatUnmount("sd");
- __io_wiisd.shutdown();
- sd_ok=0;
- }
- __io_wiisd.shutdown();
- __io_wiisd.shutdown();
-
-
- if(ud_ok)
- {
- fatUnmount("ud");
- __io_usbstorage2.shutdown();ud_ok=0;
- }
-
- USBStorage2_Watchdog(0); // disable watchdog
- USBStorage2_Deinit();
-
- // WARNING: this disable ehcmodule for USB 2.0 operations (only to work in DVD Mode without NAND emulation)
- //if(!(flag_disc & 0x200000) && flag_disc && (nand_mode & 2)==0) USBStorage2_EHC_Off();
-
- WDVD_Close();
-
- /*
- #ifdef USE_MODPLAYER
- #ifdef ALTERNATIVE_VERSION
- StopOgg();
- #else
- MODPlay_Stop(&mod_track);
- #endif
- //ASND_End(); // finaliza el sonido
- #endif
- */
-
- if((cios!=cios_list[0] && force_ios249==0) || force_reload_ios222)
- {
- cabecera2("Loading...");
-
- WPAD_Shutdown();
- usleep(500*1000);
-
- ret2=IOS_ReloadIOS(cios);
- if((cios==cios_list[1] || cios==cios_list[2]) && ret2==0)
- {
- if((*(volatile u32 *)0x80003140 & 0xffff)<4) return -7777;
- }
- if(ret2<0)
- {
- cios=cios_list[0];
- IOS_ReloadIOS(cios);
- }
- sleep(1);
-
- cabecera2( "Loading...");
-
- test_and_patch_for_port1();
-
- load_ehc_module();
-
- WPAD_Init();
- WPAD_SetIdleTimeout(60*5); // 5 minutes
-
- WPAD_SetDataFormat(WPAD_CHAN_ALL, WPAD_FMT_BTNS_ACC_IR); // ajusta el formato para acelerometros en todos los wiimotes
- WPAD_SetVRes(WPAD_CHAN_ALL, SCR_WIDTH+is_16_9*208, SCR_HEIGHT);
-
- // WARNING: this disable ehcmodule for USB 2.0 operations (only to work in DVD Mode)
-
- if(!(flag_disc & 0x200000) && flag_disc && (nand_mode & 2)==0) {USBStorage2_EHC_Off();free_usb_ports();}
- else
- {
- if(!dvd_only)
- {
- for(n=0;n<50;n++)
- {
- cabecera2("Loading...");
-
- ret2 = USBStorage2_Init();
- if(!ret2) break;
- usleep(500*1000);
- }
-
- USBStorage2_Deinit();
- }
- }
-
-
- }
-
- // enables fake ES_ioctlv (to skip IOS_ReloadIOS(ios))
- if(force_ingame_ios)
- {
- enable_ES_ioctlv_vector();
- }
-
- mload_close();
-
- if(flag_disc & 0x200000) discid[6]=2; // mode DVD USB
- else if(flag_disc) discid[6]=1; // mode DVD
-
-
- if(banner_title && !dont_use_diary)
- {
-
- if(Diario_ActualizarDiario(banner_title,(char*) discid)<0) ;//exit(0);
-
- }
- else Diario_InvalidarDiario();
-
- if(titleid)
- {
- memcpy((void*)0x80000000, discid, 6);
- DCFlushRange((void*)0x80000000, 0x6);
-
- ret=bootTitle(titleid);
- }
- else
- ret = load_disc(discid);
-
- ASND_StopVoice(4);
- sleep(1);
- ASND_End(); // finaliza el sonido
-
- return ret;
- }
-
-
-
-
- void snd_explo(int voice, int pos)
- {
- #ifdef USE_MODPLAYER
-
- if(ASND_StatusVoice(2+voice)!=SND_WORKING)
- {
- int l,r;
-
- l=((pos-SCR_WIDTH/2)<100) ? 127 : 64;
- r=((pos-SCR_WIDTH/2)>-100) ? 12