2009-10-01 01:10:58 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* USB Loader GX Team
|
|
|
|
*
|
|
|
|
* Main loadup of the application
|
|
|
|
*
|
|
|
|
* libwiigui
|
|
|
|
* Tantric 2009
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#include <gccore.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/dir.h>
|
|
|
|
#include <ogcsys.h>
|
|
|
|
#include <unistd.h>
|
2009-10-15 16:13:13 +02:00
|
|
|
#include <locale.h>
|
2010-01-07 00:07:35 +01:00
|
|
|
#include <ogc/libversion.h>
|
2009-10-01 01:10:58 +02:00
|
|
|
#include <wiiuse/wpad.h>
|
2009-12-15 09:39:45 +01:00
|
|
|
//#include <debug.h>
|
2010-01-07 00:07:35 +01:00
|
|
|
extern "C" {
|
|
|
|
extern void __exception_setreload(int t);
|
2009-12-10 21:27:36 +01:00
|
|
|
}
|
2009-12-03 02:06:09 +01:00
|
|
|
|
|
|
|
#include <di/di.h>
|
|
|
|
#include <sys/iosupport.h>
|
2009-10-01 01:10:58 +02:00
|
|
|
|
|
|
|
#include "libwiigui/gui.h"
|
|
|
|
#include "usbloader/wbfs.h"
|
|
|
|
#include "settings/cfg.h"
|
|
|
|
#include "language/gettext.h"
|
|
|
|
#include "mload/mload.h"
|
|
|
|
#include "FreeTypeGX.h"
|
|
|
|
#include "video.h"
|
|
|
|
#include "audio.h"
|
|
|
|
#include "menu.h"
|
|
|
|
#include "input.h"
|
|
|
|
#include "filelist.h"
|
|
|
|
#include "listfiles.h"
|
|
|
|
#include "main.h"
|
|
|
|
#include "fatmounter.h"
|
|
|
|
#include "sys.h"
|
|
|
|
#include "wpad.h"
|
|
|
|
#include "fat.h"
|
2009-10-20 13:46:55 +02:00
|
|
|
#include "gecko.h"
|
2009-10-21 01:00:19 +02:00
|
|
|
#include "svnrev.h"
|
2009-12-03 02:06:09 +01:00
|
|
|
#include "wad/title.h"
|
2009-11-15 22:30:44 +01:00
|
|
|
#include "usbloader/partition_usbloader.h"
|
2009-11-15 20:52:58 +01:00
|
|
|
#include "usbloader/usbstorage.h"
|
2009-12-04 16:05:20 +01:00
|
|
|
#include "memory/mem2.h"
|
2009-12-10 21:27:36 +01:00
|
|
|
#include "lstub.h"
|
2010-01-07 00:07:35 +01:00
|
|
|
#include "xml/xml.h"
|
|
|
|
#include "settings/newtitles.h"
|
|
|
|
#include "menu/menus.h"
|
2009-10-20 13:46:55 +02:00
|
|
|
|
|
|
|
extern bool geckoinit;
|
2009-12-03 02:06:09 +01:00
|
|
|
extern bool textVideoInit;
|
|
|
|
extern char headlessID[8];
|
2010-01-07 00:07:35 +01:00
|
|
|
PartList partitions;
|
2009-10-01 01:10:58 +02:00
|
|
|
|
|
|
|
/* Constants */
|
2010-01-07 00:07:35 +01:00
|
|
|
#define CONSOLE_XCOORD 260
|
|
|
|
#define CONSOLE_YCOORD 115
|
|
|
|
#define CONSOLE_WIDTH 340
|
|
|
|
#define CONSOLE_HEIGHT 218
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2009-10-19 22:34:54 +02:00
|
|
|
FreeTypeGX *fontSystem=0;
|
|
|
|
FreeTypeGX *fontClock=0;
|
2009-12-24 09:33:53 +01:00
|
|
|
|
2010-01-07 00:07:35 +01:00
|
|
|
void LoadHeadlessID(const char * ID)
|
2009-10-01 01:10:58 +02:00
|
|
|
{
|
2010-01-07 00:07:35 +01:00
|
|
|
InitTextVideo();
|
|
|
|
strncpy(headlessID, ID, sizeof(headlessID));
|
|
|
|
InitCheckThread();
|
2009-12-30 10:52:24 +01:00
|
|
|
time_t endtime = time(0) + 30;
|
2010-01-07 00:07:35 +01:00
|
|
|
time_t curtime;
|
|
|
|
printf("\tWaiting for USB-Device:\n");
|
|
|
|
while(checkthreadState != 1)
|
2009-12-30 10:52:24 +01:00
|
|
|
{
|
2010-01-07 00:07:35 +01:00
|
|
|
usleep(100);
|
2009-12-30 10:52:24 +01:00
|
|
|
curtime = time(0);
|
2010-01-07 00:07:35 +01:00
|
|
|
printf("\t\t%d\n", int(endtime-curtime));
|
|
|
|
if(endtime == curtime)
|
2009-12-30 10:52:24 +01:00
|
|
|
{
|
2010-01-07 00:07:35 +01:00
|
|
|
printf("\n\tDevice could not be loaded.\n\tExiting...\n");
|
|
|
|
sleep(5);
|
|
|
|
SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
|
2009-12-30 10:52:24 +01:00
|
|
|
}
|
2009-10-19 22:34:54 +02:00
|
|
|
}
|
2010-01-07 00:07:35 +01:00
|
|
|
mountMethod = 0;
|
|
|
|
checkthreadState = 0;
|
|
|
|
ExitCheckThread();
|
|
|
|
CloseXMLDatabase();
|
|
|
|
NewTitles::DestroyInstance();
|
|
|
|
ShutdownAudio();
|
|
|
|
StopGX();
|
|
|
|
gettextCleanUp();
|
|
|
|
menuBootgame(headlessID);
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
2010-01-07 00:07:35 +01:00
|
|
|
int main(int argc, char *argv[])
|
2009-12-30 10:52:24 +01:00
|
|
|
{
|
2010-01-07 00:07:35 +01:00
|
|
|
setlocale(LC_ALL, "en.UTF-8");
|
|
|
|
geckoinit = InitGecko();
|
2009-11-17 23:57:41 +01:00
|
|
|
|
2010-01-07 00:07:35 +01:00
|
|
|
if (hbcStubAvailable() || geckoinit)
|
|
|
|
InitTextVideo();
|
2009-11-17 23:57:41 +01:00
|
|
|
|
2010-01-07 00:07:35 +01:00
|
|
|
__exception_setreload(5);//auto reset code dump nobody gives us codedump info anyways.
|
2009-11-17 23:57:41 +01:00
|
|
|
|
2010-01-07 00:07:35 +01:00
|
|
|
gprintf("\n\n------------------");
|
|
|
|
gprintf("\nUSB Loader GX rev%s linked with %s",GetRev(), _V_STRING);
|
|
|
|
gprintf("\nmain(%d", argc);
|
|
|
|
for (int i=0;i<argc;i++)
|
|
|
|
gprintf(", %s",argv[i]?argv[i]:"<NULL>");
|
2009-12-30 10:52:24 +01:00
|
|
|
gprintf(")");
|
|
|
|
|
|
|
|
// This part is added, because we need a identify patched ios
|
2010-01-07 00:07:35 +01:00
|
|
|
//printf("\n\tReloading into ios 236");
|
|
|
|
if (IOS_ReloadIOSsafe(236) < 0)
|
|
|
|
IOS_ReloadIOSsafe(36);
|
2009-12-30 10:52:24 +01:00
|
|
|
|
2010-01-07 00:07:35 +01:00
|
|
|
printf("\n\tStarting up");
|
2009-12-30 10:52:24 +01:00
|
|
|
|
2010-01-07 00:07:35 +01:00
|
|
|
MEM2_init(36); // Initialize 36 MB
|
|
|
|
MEM2_takeBigOnes(true);
|
2009-10-15 16:13:13 +02:00
|
|
|
|
2009-10-01 01:10:58 +02:00
|
|
|
s32 ret;
|
|
|
|
|
|
|
|
bool bootDevice_found=false;
|
2010-01-07 00:07:35 +01:00
|
|
|
if (argc >= 1) {
|
|
|
|
if (!strncasecmp(argv[0], "usb:/", 5)) {
|
2009-10-01 01:10:58 +02:00
|
|
|
strcpy(bootDevice, "USB:");
|
|
|
|
bootDevice_found = true;
|
|
|
|
} else if (!strncasecmp(argv[0], "sd:/", 4))
|
2010-01-07 00:07:35 +01:00
|
|
|
bootDevice_found = true;
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
2009-12-30 10:52:24 +01:00
|
|
|
|
2010-01-07 00:07:35 +01:00
|
|
|
printf("\n\tInitializing controllers");
|
2009-12-30 10:52:24 +01:00
|
|
|
|
2009-10-01 01:10:58 +02:00
|
|
|
/** PAD_Init has to be before InitVideo don't move that **/
|
2010-01-07 00:07:35 +01:00
|
|
|
PAD_Init(); // initialize PAD/WPAD
|
2009-12-30 10:52:24 +01:00
|
|
|
|
2010-01-07 00:07:35 +01:00
|
|
|
printf("\n\tInitialize USB (wake up)");
|
2009-12-30 10:52:24 +01:00
|
|
|
|
2010-01-07 00:07:35 +01:00
|
|
|
USBDevice_Init();// seems enough to wake up some HDDs if they are in sleep mode when the loader starts (tested with WD MyPassport Essential 2.5")
|
2010-01-07 09:35:11 +01:00
|
|
|
USBDevice_deInit();// seems enough to wake up some HDDs if they are in sleep mode when the loader starts (tested with WD MyPassport Essential 2.5")
|
2009-12-30 10:52:24 +01:00
|
|
|
|
2010-01-07 00:07:35 +01:00
|
|
|
ret = CheckForCIOS();
|
2009-12-30 10:52:24 +01:00
|
|
|
|
2010-01-07 00:07:35 +01:00
|
|
|
printf("\n\tInitialize sd card");
|
|
|
|
SDCard_Init(); // mount SD for loading cfg's
|
|
|
|
printf("\n\tInitialize usb device");
|
|
|
|
USBDevice_Init(); // and mount USB:/
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2009-12-30 10:52:24 +01:00
|
|
|
if (!bootDevice_found)
|
|
|
|
{
|
2010-01-07 00:07:35 +01:00
|
|
|
printf("\n\tSearch for configuration file");
|
2009-10-01 01:10:58 +02:00
|
|
|
//try USB
|
|
|
|
//left in all the dol and elf files in this check in case this is the first time running the app and they dont have the config
|
|
|
|
if (checkfile((char*) "USB:/config/GXglobal.cfg") || (checkfile((char*) "USB:/apps/usbloader_gx/boot.elf"))
|
2010-01-07 00:07:35 +01:00
|
|
|
|| checkfile((char*) "USB:/apps/usbloadergx/boot.dol") || (checkfile((char*) "USB:/apps/usbloadergx/boot.elf"))
|
|
|
|
|| checkfile((char*) "USB:/apps/usbloader_gx/boot.dol"))
|
2009-10-01 01:10:58 +02:00
|
|
|
strcpy(bootDevice, "USB:");
|
2009-11-17 23:57:41 +01:00
|
|
|
|
2010-01-07 00:07:35 +01:00
|
|
|
printf("\n\tConfiguration file is on %s", bootDevice);
|
2009-12-30 10:52:24 +01:00
|
|
|
}
|
2009-12-19 15:05:31 +01:00
|
|
|
|
2010-01-07 09:35:11 +01:00
|
|
|
// Try opening and closing the configuration file here
|
|
|
|
// to prevent a crash dump later on - giantpune
|
|
|
|
// how the fuck is this supposed to help? - dimok
|
|
|
|
char GXGlobal_cfg[26];
|
|
|
|
sprintf(GXGlobal_cfg, "%s/config/GXGlobal.cfg", bootDevice);
|
|
|
|
FILE *fp = fopen(GXGlobal_cfg, "r");
|
|
|
|
if (fp)
|
|
|
|
{
|
|
|
|
fclose(fp);
|
|
|
|
printf("\n\tConfiguration file is on %s", bootDevice);
|
|
|
|
}
|
|
|
|
|
2009-10-01 01:10:58 +02:00
|
|
|
gettextCleanUp();
|
2010-01-07 00:07:35 +01:00
|
|
|
printf("\n\tLoading configuration...");
|
2009-10-01 01:10:58 +02:00
|
|
|
CFG_Load();
|
2010-01-07 00:07:35 +01:00
|
|
|
printf("done");
|
2009-11-15 20:52:58 +01:00
|
|
|
|
2010-01-07 00:07:35 +01:00
|
|
|
LoadAppCIOS();
|
|
|
|
printf("\n\tcIOS = %u (Rev %u)",IOS_GetVersion(), IOS_GetRevision());
|
2009-12-30 10:52:24 +01:00
|
|
|
|
2010-01-07 00:07:35 +01:00
|
|
|
//if a ID was passed via args copy it and try to boot it after the partition is mounted
|
|
|
|
//its not really a headless mode. more like hairless.
|
|
|
|
if (argc > 1 && argv[1])
|
|
|
|
{
|
|
|
|
if (strlen(argv[1]) == 6)
|
|
|
|
LoadHeadlessID(argv[1]);
|
|
|
|
}
|
2009-12-03 02:06:09 +01:00
|
|
|
|
2009-10-01 01:10:58 +02:00
|
|
|
//! Init the rest of the System
|
|
|
|
Sys_Init();
|
|
|
|
Wpad_Init();
|
2010-01-07 00:07:35 +01:00
|
|
|
InitVideo();
|
|
|
|
InitAudio(); // Initialize audio
|
2009-10-01 01:10:58 +02:00
|
|
|
|
|
|
|
WPAD_SetDataFormat(WPAD_CHAN_ALL,WPAD_FMT_BTNS_ACC_IR);
|
|
|
|
WPAD_SetVRes(WPAD_CHAN_ALL, screenwidth, screenheight);
|
|
|
|
|
2009-10-19 22:34:54 +02:00
|
|
|
// load main font from file, or default to built-in font
|
|
|
|
fontSystem = new FreeTypeGX();
|
2009-10-01 01:10:58 +02:00
|
|
|
char *fontPath = NULL;
|
|
|
|
asprintf(&fontPath, "%sfont.ttf", CFG.theme_path);
|
2009-10-19 22:34:54 +02:00
|
|
|
fontSystem->loadFont(fontPath, font_ttf, font_ttf_size, 0);
|
|
|
|
fontSystem->setCompatibilityMode(FTGX_COMPATIBILITY_DEFAULT_TEVOP_GX_PASSCLR | FTGX_COMPATIBILITY_DEFAULT_VTXDESC_GX_NONE);
|
2009-10-01 01:10:58 +02:00
|
|
|
free(fontPath);
|
|
|
|
|
2009-10-19 22:34:54 +02:00
|
|
|
fontClock = new FreeTypeGX();
|
|
|
|
fontClock->loadFont(NULL, clock_ttf, clock_ttf_size, 0);
|
|
|
|
fontClock->setCompatibilityMode(FTGX_COMPATIBILITY_DEFAULT_TEVOP_GX_PASSCLR | FTGX_COMPATIBILITY_DEFAULT_VTXDESC_GX_NONE);
|
|
|
|
|
2010-01-07 00:07:35 +01:00
|
|
|
gprintf("\n\tEnd of Main()");
|
2009-10-01 01:10:58 +02:00
|
|
|
InitGUIThreads();
|
2010-01-07 00:07:35 +01:00
|
|
|
MainMenu(MENU_DISCLIST);
|
|
|
|
|
2009-10-01 01:10:58 +02:00
|
|
|
return 0;
|
|
|
|
}
|