usbloadergx/source/usbloader/apploader.c

144 lines
3.8 KiB
C
Raw Normal View History

2009-07-31 14:45:14 +02:00
#include <stdio.h>
#include <ogcsys.h>
#include <string.h>
#include <malloc.h>
2009-07-31 14:45:14 +02:00
#include "patches/patchcode.h"
#include "apploader.h"
#include "wdvd.h"
#include "wpad.h"
#include "disc.h"
#include "alternatedol.h"
#include "fstfile.h"
#include "gecko.h"
#include "patches/wip.h"
#include "patches/dolpatcher.h"
#include "patches/gamepatches.h"
2009-07-31 14:45:14 +02:00
extern bool geckoinit;
2009-07-31 14:45:14 +02:00
/* Apploader function pointers */
2010-09-24 02:48:03 +02:00
typedef int (*app_main)(void **dst, int *size, int *offset);
typedef void (*app_init)(void(*report)(const char *fmt, ...));
typedef void *(*app_final)();
typedef void (*app_entry)(void(**init)(void(*report)(const char *fmt, ...)), int(**main)(), void *(**final)());
2009-07-31 14:45:14 +02:00
/* Apploader pointers */
2010-09-24 02:48:03 +02:00
static u8 *appldr = (u8 *) 0x81200000;
/* Constants */
#define APPLDR_OFFSET 0x2440
/* Variables */
static u32 buffer[0x20] ATTRIBUTE_ALIGN( 32 );
void gamepatches( u8 * dst, int len, u8 videoSelected, u8 languageChoice, u8 patchcountrystring, u8 vipatch, u8 cheat, u32 returnTo, u8 fix002 )
{
VideoModePatcher( dst, len, videoSelected );
2009-07-31 14:45:14 +02:00
if ( cheat )
dogamehooks( dst, len );
2009-07-31 14:45:14 +02:00
if ( vipatch )
vidolpatcher( dst, len );
2009-07-31 14:45:14 +02:00
/*LANGUAGE PATCH - FISHEARS*/
langpatcher( dst, len, languageChoice );
2009-07-31 14:45:14 +02:00
/*Thanks to WiiPower*/
if ( patchcountrystring == 1 )
PatchCountryStrings( dst, len );
2009-07-31 14:45:14 +02:00
do_wip_code( ( u8 * ) dst, len );
if ( fix002 == 2 )
Anti_002_fix( dst, len );
PatchReturnTo( dst, len, returnTo );
2009-07-31 14:45:14 +02:00
}
s32 Apploader_Run(entry_point *entry, char * dolpath, u8 cheat, u8 videoSelected, u8 languageChoice, u8 vipatch, u8 patchcountrystring,
u8 alternatedol, u32 alternatedoloffset, u32 returnTo, u8 fix002)
{
2009-07-31 14:45:14 +02:00
app_entry appldr_entry;
2010-09-24 02:48:03 +02:00
app_init appldr_init;
app_main appldr_main;
2009-07-31 14:45:14 +02:00
app_final appldr_final;
u32 appldr_len;
s32 ret;
2010-09-24 02:48:03 +02:00
gprintf("\nApploader_Run() started\n");
2009-07-31 14:45:14 +02:00
/* Read apploader header */
2010-09-24 02:48:03 +02:00
ret = WDVD_Read(buffer, 0x20, APPLDR_OFFSET);
if (ret < 0) return ret;
2009-07-31 14:45:14 +02:00
/* Calculate apploader length */
appldr_len = buffer[5] + buffer[6];
/* Read apploader code */
2010-09-24 02:48:03 +02:00
ret = WDVD_Read(appldr, appldr_len, APPLDR_OFFSET + 0x20);
if (ret < 0) return ret;
/* Set apploader entry function */
2010-09-24 02:48:03 +02:00
appldr_entry = (app_entry) buffer[4];
2009-07-31 14:45:14 +02:00
/* Call apploader entry */
2010-09-24 02:48:03 +02:00
appldr_entry(&appldr_init, &appldr_main, &appldr_final);
2009-07-31 14:45:14 +02:00
/* Initialize apploader */
2010-09-24 02:48:03 +02:00
appldr_init(gprintf);
if (fix002 != 0)
{
2009-07-31 14:45:14 +02:00
/* ERROR 002 fix (thanks to WiiPower for sharing this)*/
2010-09-24 02:48:03 +02:00
*(u32 *) 0x80003188 = *(u32 *) 0x80003140;
2009-07-31 14:45:14 +02:00
}
2010-09-24 02:48:03 +02:00
for (;;)
{
2009-07-31 14:45:14 +02:00
void *dst = NULL;
int len = 0, offset = 0;
/* Run apploader main function */
2010-09-24 02:48:03 +02:00
ret = appldr_main(&dst, &len, &offset);
if (!ret) break;
2009-07-31 14:45:14 +02:00
/* Read data from DVD */
2010-09-24 02:48:03 +02:00
WDVD_Read(dst, len, (u64) (offset << 2));
2009-07-31 14:45:14 +02:00
if( !alternatedol )
gamepatches(dst, len, videoSelected, languageChoice, patchcountrystring, vipatch, cheat, returnTo, fix002 );
DCFlushRange(dst, len);
2009-07-31 14:45:14 +02:00
}
*entry = appldr_final();
/** Load alternate dol if set **/
if (alternatedol == 2)
{
wip_reset_counter();
void *dolbuffer = NULL;
int dollen = 0;
2009-07-31 14:45:14 +02:00
bool dolloaded = Load_Dol(&dolbuffer, &dollen, dolpath, videoSelected, languageChoice, patchcountrystring, vipatch, cheat, returnTo);
2010-09-24 02:48:03 +02:00
if (dolloaded)
{
2010-09-24 02:48:03 +02:00
*entry = (entry_point) load_dol_image(dolbuffer);
}
2010-09-24 02:48:03 +02:00
if (dolbuffer) free(dolbuffer);
}
*Fixed display of partition size on WBFS partitions with a different wbfs sector size than 512bytes. *Made the ProgressWindow for game installation more accurate *Added displaying newly installed games (marked as new) on favorite list, so you don't have to change to full list when installing new games. (Thanks Cyan for the patch) *Lot's a small fixes *Added WDM Menu on game start. You can set it in the alternative DOL option (one new option there). The menu lists all DOLs on the disc and if a wdm file is provided in the WDM path (configurable in the settings) than the dol parameter and dol replacement name will be taken from the wdm. The DOLs that are not listed in the WDM but exist on the DISC will be listed at the end of the list. *Added avoid of multiple app cleanup when game fails to boot *Changed libfat to use FS info sector on FAT32 partitions. This speeds up the free space information getting to instant. For that the FS info sector has to have correct values. The values of all partitions where homebrews were writing to are currently incorrect because the official libfat does not support FS info sector (i submited a patch) (Windows does write it correct though). That is why there needs to be a synchronization of the FS info sector for partitions used with homebrews. For this purpose a new setting was added in the Loader Settings. You can synchronize all your FAT32 partitions on the USB with it once and you are done (if you don't write to that partition with current homebrews). After that you can enable free space display and it will be instant like on WBFS/NTFS/EXT partitions.
2011-01-16 14:12:07 +01:00
else if ((alternatedol == 1 || alternatedol == 3) && alternatedoloffset != 0)
{
wip_reset_counter();
2010-09-24 02:48:03 +02:00
FST_ENTRY *fst = (FST_ENTRY *) *(u32 *) 0x80000038;
2009-07-31 14:45:14 +02:00
*entry = (entry_point) Load_Dol_from_disc(fst[alternatedoloffset].fileoffset, videoSelected, languageChoice,
patchcountrystring, vipatch, cheat, returnTo);
2009-07-31 14:45:14 +02:00
}
return 0;
}