2009-05-03 20:53:31 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ogcsys.h>
|
2009-07-30 07:41:12 +02:00
|
|
|
#include <ogc/lwp_watchdog.h>
|
|
|
|
#include <wiiuse/wpad.h>
|
|
|
|
|
2009-06-13 02:24:36 +02:00
|
|
|
#include "patches/fst.h"
|
2010-05-30 16:18:25 +02:00
|
|
|
#include "patches/gamepatches.h"
|
2010-05-29 17:43:19 +02:00
|
|
|
#include "patches/wip.h"
|
2009-05-03 20:53:31 +02:00
|
|
|
#include "apploader.h"
|
|
|
|
#include "disc.h"
|
2010-05-29 09:38:54 +02:00
|
|
|
#include "video.h"
|
2009-07-30 07:41:12 +02:00
|
|
|
#include "wdvd.h"
|
2009-10-21 01:00:19 +02:00
|
|
|
#include "alternatedol.h"
|
2009-08-03 20:55:55 +02:00
|
|
|
#include "memory.h"
|
2009-12-19 15:05:31 +01:00
|
|
|
#include "wbfs.h"
|
2010-05-29 09:38:54 +02:00
|
|
|
#include "../gecko.h"
|
|
|
|
#include "../fatmounter.h"
|
2010-02-27 19:18:01 +01:00
|
|
|
|
2009-05-03 20:53:31 +02:00
|
|
|
/* Constants */
|
2010-09-19 01:16:05 +02:00
|
|
|
#define PTABLE_OFFSET 0x40000
|
|
|
|
#define WII_MAGIC 0x5D1C9EA3
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2010-02-27 19:18:01 +01:00
|
|
|
//appentrypoint
|
|
|
|
u32 appentrypoint;
|
|
|
|
|
2009-05-03 20:53:31 +02:00
|
|
|
/* Disc pointers */
|
2010-09-24 02:48:03 +02:00
|
|
|
static u32 *buffer = (u32 *) 0x93000000;
|
|
|
|
static u8 *diskid = (u8 *) Disc_ID;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
void __Disc_SetLowMem(void)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-12-20 05:26:30 +01:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
*Sys_Magic = 0x0D15EA5E; // Standard Boot Code
|
|
|
|
*Version = 0x00000001; // Version
|
|
|
|
*Arena_L = 0x00000000; // Arena Low
|
|
|
|
*BI2 = 0x817E5480; // BI2
|
|
|
|
*Bus_Speed = 0x0E7BE2C0; // Console Bus Speed
|
|
|
|
*CPU_Speed = 0x2B73A840; // Console CPU Speed
|
2009-07-30 07:41:12 +02:00
|
|
|
|
|
|
|
/* Setup low memory */
|
2010-09-24 02:48:03 +02:00
|
|
|
*Assembler = 0x38A00040; // Assembler
|
|
|
|
*(u32 *) 0x800000E4 = 0x80431A80;
|
|
|
|
*Dev_Debugger = 0x81800000; // Dev Debugger Monitor Address
|
|
|
|
*Simulated_Mem = 0x01800000; // Simulated Memory Size
|
|
|
|
*(vu32 *) 0xCD00643C = 0x00000000; // 32Mhz on Bus
|
2009-07-15 19:20:45 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
//If the game is sam & max: season 1 put this shit in
|
2009-12-20 05:26:30 +01:00
|
|
|
char gameid[8];
|
2010-09-24 02:48:03 +02:00
|
|
|
memset(gameid, 0, 8);
|
|
|
|
memcpy(gameid, (char*) Disc_ID, 6);
|
2009-12-20 05:26:30 +01:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if ((strcmp(gameid, "R3XE6U") == 0) || (strcmp(gameid, "R3XP6V") == 0))
|
2010-02-09 11:59:55 +01:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
*GameID_Address = 0x80000000; // Game ID Address
|
2009-07-30 07:41:12 +02:00
|
|
|
}
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Copy disc ID */
|
2010-09-24 02:48:03 +02:00
|
|
|
memcpy((void *) Online_Check, (void *) Disc_ID, 4);
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Flush cache */
|
2010-09-24 02:48:03 +02:00
|
|
|
DCFlushRange((void *) Disc_ID, 0x3F00);
|
2009-05-03 20:53:31 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
void __Disc_SetVMode(u8 videoselected)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-07-30 07:41:12 +02:00
|
|
|
GXRModeObj *vmode = NULL;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
u32 progressive, tvmode, vmode_reg = 0;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Get video mode configuration */
|
2010-09-24 02:48:03 +02:00
|
|
|
progressive = (CONF_GetProgressiveScan() > 0) && VIDEO_HaveComponentCable();
|
|
|
|
tvmode = CONF_GetVideo();
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Select video mode register */
|
2010-09-24 02:48:03 +02:00
|
|
|
switch (tvmode)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
case CONF_VIDEO_PAL:
|
2010-09-24 02:48:03 +02:00
|
|
|
vmode_reg = (CONF_GetEuRGB60() > 0) ? 5 : 1;
|
2010-09-19 01:16:05 +02:00
|
|
|
break;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
case CONF_VIDEO_MPAL:
|
|
|
|
vmode_reg = 4;
|
|
|
|
break;
|
2009-07-30 07:41:12 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
case CONF_VIDEO_NTSC:
|
|
|
|
vmode_reg = 0;
|
2009-07-30 07:41:12 +02:00
|
|
|
break;
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
2009-07-30 07:41:12 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
switch (videoselected)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
|
|
|
|
/* Select video mode */
|
2010-09-24 02:48:03 +02:00
|
|
|
switch (diskid[3])
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
/* PAL */
|
2010-09-19 01:16:05 +02:00
|
|
|
case 'P':
|
|
|
|
case 'D':
|
|
|
|
case 'F':
|
|
|
|
case 'I':
|
|
|
|
case 'S':
|
|
|
|
case 'H':
|
|
|
|
case 'X':
|
|
|
|
case 'Y':
|
|
|
|
case 'Z':
|
2010-09-24 02:48:03 +02:00
|
|
|
if (tvmode != CONF_VIDEO_PAL)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
vmode_reg = 5;
|
2010-09-24 02:48:03 +02:00
|
|
|
vmode = (progressive) ? &TVNtsc480Prog : &TVEurgb60Hz480IntDf;
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* NTSC or unknown */
|
|
|
|
case 'E':
|
|
|
|
case 'J':
|
|
|
|
case 'K':
|
|
|
|
case 'W':
|
2010-09-24 02:48:03 +02:00
|
|
|
if (tvmode != CONF_VIDEO_NTSC)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
vmode_reg = 0;
|
2010-09-24 02:48:03 +02:00
|
|
|
vmode = (progressive) ? &TVNtsc480Prog : &TVNtsc480IntDf;
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2009-07-30 07:41:12 +02:00
|
|
|
}
|
2010-09-19 01:16:05 +02:00
|
|
|
break;
|
2009-07-30 07:41:12 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
case 1:
|
2010-09-24 02:48:03 +02:00
|
|
|
vmode = &TVPal528IntDf;
|
|
|
|
vmode_reg = (vmode->viTVMode) >> 2;
|
2009-07-30 07:41:12 +02:00
|
|
|
break;
|
2010-09-19 01:16:05 +02:00
|
|
|
case 2:
|
2010-09-24 02:48:03 +02:00
|
|
|
progressive = (CONF_GetProgressiveScan() > 0) && VIDEO_HaveComponentCable();
|
|
|
|
vmode = (progressive) ? &TVNtsc480Prog : &TVEurgb60Hz480IntDf;
|
|
|
|
vmode_reg = (vmode->viTVMode) >> 2;
|
2010-09-19 01:16:05 +02:00
|
|
|
break;
|
|
|
|
case 3:
|
2010-09-24 02:48:03 +02:00
|
|
|
progressive = (CONF_GetProgressiveScan() > 0) && VIDEO_HaveComponentCable();
|
|
|
|
vmode = (progressive) ? &TVNtsc480Prog : &TVNtsc480IntDf;
|
|
|
|
vmode_reg = (vmode->viTVMode) >> 2;
|
2010-09-19 01:16:05 +02:00
|
|
|
break;
|
|
|
|
case 4:
|
2010-09-24 02:48:03 +02:00
|
|
|
// vmode = VIDEO_GetPreferredMode(NULL);
|
2010-09-19 01:16:05 +02:00
|
|
|
break;
|
2009-05-03 20:53:31 +02:00
|
|
|
}
|
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Set video mode register */
|
2009-08-03 20:55:55 +02:00
|
|
|
*Video_Mode = vmode_reg;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Set video mode */
|
2010-09-24 02:48:03 +02:00
|
|
|
if (vmode)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
VIDEO_Configure(vmode);
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Setup video */
|
2010-09-24 02:48:03 +02:00
|
|
|
VIDEO_SetBlack(FALSE);
|
2009-07-30 07:41:12 +02:00
|
|
|
VIDEO_Flush();
|
|
|
|
VIDEO_WaitVSync();
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (vmode->viTVMode & VI_NON_INTERLACE) VIDEO_WaitVSync();
|
2009-07-30 07:41:12 +02:00
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
gprintf("\nVideo mode - %s", ((progressive) ? "progressive" : "interlaced"));
|
2010-02-27 19:18:01 +01:00
|
|
|
|
2009-05-03 20:53:31 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
void __Disc_SetTime(void)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Extern */
|
2010-09-24 02:48:03 +02:00
|
|
|
extern void settime(u64);
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Set proper time */
|
2010-09-24 02:48:03 +02:00
|
|
|
settime(secs_to_ticks( time( NULL ) - 946684800 ));
|
2009-05-03 20:53:31 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
s32 __Disc_FindPartition(u64 *outbuf)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-07-30 07:41:12 +02:00
|
|
|
u64 offset = 0, table_offset = 0;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
u32 cnt, nb_partitions;
|
|
|
|
s32 ret;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Read partition info */
|
2010-09-24 02:48:03 +02:00
|
|
|
ret = WDVD_UnencryptedRead(buffer, 0x20, PTABLE_OFFSET);
|
|
|
|
if (ret < 0) return ret;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Get data */
|
|
|
|
nb_partitions = buffer[0];
|
2010-09-24 02:48:03 +02:00
|
|
|
table_offset = buffer[1] << 2;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Read partition table */
|
2010-09-24 02:48:03 +02:00
|
|
|
ret = WDVD_UnencryptedRead(buffer, 0x20, table_offset);
|
|
|
|
if (ret < 0) return ret;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Find game partition */
|
2010-09-24 02:48:03 +02:00
|
|
|
for (cnt = 0; cnt < nb_partitions; cnt++)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-07-30 07:41:12 +02:00
|
|
|
u32 type = buffer[cnt * 2 + 1];
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Game partition */
|
2010-09-24 02:48:03 +02:00
|
|
|
if (!type) offset = buffer[cnt * 2] << 2;
|
2009-07-30 07:41:12 +02:00
|
|
|
}
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* No game partition found */
|
2010-09-24 02:48:03 +02:00
|
|
|
if (!offset) return -1;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Set output buffer */
|
|
|
|
*outbuf = offset;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
return 0;
|
2009-05-03 20:53:31 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
s32 Disc_Init(void)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Init DVD subsystem */
|
|
|
|
return WDVD_Init();
|
2009-05-03 20:53:31 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
s32 Disc_Open(void)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-07-30 07:41:12 +02:00
|
|
|
s32 ret;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Reset drive */
|
|
|
|
ret = WDVD_Reset();
|
2010-09-24 02:48:03 +02:00
|
|
|
if (ret < 0) return ret;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Read disc ID */
|
2010-09-24 02:48:03 +02:00
|
|
|
return WDVD_ReadDiskId(diskid);
|
2009-05-03 20:53:31 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
s32 Disc_Wait(void)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-07-30 07:41:12 +02:00
|
|
|
u32 cover = 0;
|
|
|
|
s32 ret;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Wait for disc */
|
2010-09-24 02:48:03 +02:00
|
|
|
while (!(cover & 0x2))
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Get cover status */
|
2010-09-24 02:48:03 +02:00
|
|
|
ret = WDVD_GetCoverStatus(&cover);
|
|
|
|
if (ret < 0) return ret;
|
2009-07-30 07:41:12 +02:00
|
|
|
}
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
return 0;
|
2009-05-03 20:53:31 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
s32 Disc_SetUSB(const u8 *id)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
u32 part = 0;
|
2010-09-24 02:48:03 +02:00
|
|
|
if (wbfs_part_fs)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
part = wbfs_part_lba;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
part = wbfs_part_idx ? wbfs_part_idx - 1 : 0;
|
|
|
|
}
|
2009-11-15 20:52:58 +01:00
|
|
|
|
2010-05-29 09:38:54 +02:00
|
|
|
/* Set USB mode */
|
2010-09-24 02:48:03 +02:00
|
|
|
return WDVD_SetUSBMode(id, part);
|
2009-05-03 20:53:31 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
s32 Disc_ReadHeader(void *outbuf)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Read disc header */
|
2010-09-24 02:48:03 +02:00
|
|
|
return WDVD_UnencryptedRead(outbuf, sizeof(struct discHdr), 0);
|
2009-05-03 20:53:31 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
s32 Disc_IsWii(void)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
struct discHdr *header = (struct discHdr *) buffer;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
s32 ret;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Read disc header */
|
2010-09-24 02:48:03 +02:00
|
|
|
ret = Disc_ReadHeader(header);
|
|
|
|
if (ret < 0) return ret;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Check magic word */
|
2010-09-24 02:48:03 +02:00
|
|
|
if (header->magic != WII_MAGIC) return -1;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
return 0;
|
2009-05-03 20:53:31 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
s32 Disc_BootPartition(u64 offset, char * dolpath, u8 videoselected, u8 cheat, u8 vipatch, u8 patchcountrystring,
|
|
|
|
u8 error002fix, u8 alternatedol, u32 alternatedoloffset, u32 returnTo)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
gprintf("booting partition IOS %u v%u\n", IOS_GetVersion(), IOS_GetRevision());
|
2009-07-30 07:41:12 +02:00
|
|
|
entry_point p_entry;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
s32 ret;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Open specified partition */
|
2010-09-24 02:48:03 +02:00
|
|
|
ret = WDVD_OpenPartition(offset);
|
|
|
|
if (ret < 0) return ret;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2010-05-30 16:18:25 +02:00
|
|
|
/* Setup low memory */
|
|
|
|
__Disc_SetLowMem();
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
char gameid[8];
|
2010-09-24 02:48:03 +02:00
|
|
|
memset(gameid, 0, 8);
|
|
|
|
memcpy(gameid, (char*) Disc_ID, 6);
|
2009-12-15 07:04:14 +01:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
load_wip_code((u8 *) &gameid);
|
2010-05-29 17:43:19 +02:00
|
|
|
|
2010-05-30 16:18:25 +02:00
|
|
|
/* If a wip file is loaded for this game this does nothing - Dimok */
|
|
|
|
PoPPatch();
|
2009-12-15 07:04:14 +01:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Run apploader */
|
2010-09-24 02:48:03 +02:00
|
|
|
ret = Apploader_Run(&p_entry, dolpath, cheat, videoselected, vipatch, patchcountrystring, error002fix,
|
|
|
|
alternatedol, alternatedoloffset, returnTo);
|
|
|
|
if (ret < 0) return ret;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2010-05-29 17:43:19 +02:00
|
|
|
free_wip();
|
|
|
|
|
2010-02-27 19:54:42 +01:00
|
|
|
bool cheatloaded = false;
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (cheat)
|
2010-05-29 17:43:19 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
// OCARINA STUFF - FISHEARS
|
|
|
|
if (ocarina_load_code((u8 *) gameid) > 0)
|
2010-02-27 19:18:01 +01:00
|
|
|
{
|
|
|
|
ocarina_do_code();
|
2010-02-27 19:54:42 +01:00
|
|
|
cheatloaded = true;
|
2010-02-27 19:18:01 +01:00
|
|
|
}
|
2009-12-20 21:28:30 +01:00
|
|
|
}
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
//kill the USB and SD
|
|
|
|
USBDevice_deInit();
|
2009-12-15 07:04:14 +01:00
|
|
|
SDCard_deInit();
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Set an appropiate video mode */
|
2010-09-24 02:48:03 +02:00
|
|
|
__Disc_SetVMode(videoselected);
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Set time */
|
|
|
|
__Disc_SetTime();
|
|
|
|
|
|
|
|
/* Disconnect Wiimote */
|
2010-09-24 02:48:03 +02:00
|
|
|
WPAD_Flush(0);
|
|
|
|
WPAD_Disconnect(0);
|
2009-07-30 07:41:12 +02:00
|
|
|
WPAD_Shutdown();
|
2009-12-15 07:04:14 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
// Anti-green screen fix
|
2010-09-24 02:48:03 +02:00
|
|
|
VIDEO_SetBlack(TRUE);
|
2010-09-19 01:16:05 +02:00
|
|
|
VIDEO_Flush();
|
|
|
|
VIDEO_WaitVSync();
|
2010-09-24 02:48:03 +02:00
|
|
|
gprintf("USB Loader GX is done.\n");
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Shutdown IOS subsystems */
|
2010-09-19 01:16:05 +02:00
|
|
|
// fix for PeppaPig (from NeoGamma)
|
|
|
|
extern void __exception_closeall();
|
|
|
|
IRQ_Disable();
|
|
|
|
__IOS_ShutdownSubsystems();
|
|
|
|
__exception_closeall();
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
appentrypoint = (u32) p_entry;
|
2010-09-19 01:16:05 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (cheat == 1 && cheatloaded)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
__asm__(
|
2010-09-24 02:48:03 +02:00
|
|
|
"lis %r3, appentrypoint@h\n"
|
|
|
|
"ori %r3, %r3, appentrypoint@l\n"
|
|
|
|
"lwz %r3, 0(%r3)\n"
|
|
|
|
"mtlr %r3\n"
|
|
|
|
"lis %r3, 0x8000\n"
|
|
|
|
"ori %r3, %r3, 0x18A8\n"
|
|
|
|
"mtctr %r3\n"
|
|
|
|
"bctr\n"
|
2010-09-19 01:16:05 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
__asm__(
|
2010-09-24 02:48:03 +02:00
|
|
|
"lis %r3, appentrypoint@h\n"
|
|
|
|
"ori %r3, %r3, appentrypoint@l\n"
|
|
|
|
"lwz %r3, 0(%r3)\n"
|
|
|
|
"mtlr %r3\n"
|
|
|
|
"blr\n"
|
2010-09-19 01:16:05 +02:00
|
|
|
);
|
|
|
|
}
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
return 0;
|
2009-05-03 20:53:31 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
s32 Disc_WiiBoot(char * dolpath, u8 videoselected, u8 cheat, u8 vipatch, u8 patchcountrystring, u8 error002fix,
|
|
|
|
u8 alternatedol, u32 alternatedoloffset, u32 returnTo)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-07-30 07:41:12 +02:00
|
|
|
u64 offset;
|
|
|
|
s32 ret;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Find game partition offset */
|
2010-09-24 02:48:03 +02:00
|
|
|
ret = __Disc_FindPartition(&offset);
|
|
|
|
if (ret < 0) return ret;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Boot partition */
|
2010-09-24 02:48:03 +02:00
|
|
|
return Disc_BootPartition(offset, dolpath, videoselected, cheat, vipatch, patchcountrystring, error002fix,
|
|
|
|
alternatedol, alternatedoloffset, returnTo);
|
2009-07-30 07:41:12 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
void PatchCountryStrings(void *Address, int Size)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
u8 SearchPattern[4] = { 0x00, 0x00, 0x00, 0x00 };
|
|
|
|
u8 PatchData[4] = { 0x00, 0x00, 0x00, 0x00 };
|
|
|
|
u8 *Addr = (u8*) Address;
|
2009-07-30 07:41:12 +02:00
|
|
|
|
|
|
|
int wiiregion = CONF_GetRegion();
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
switch (wiiregion)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
case CONF_REGION_JP:
|
|
|
|
SearchPattern[0] = 0x00;
|
|
|
|
SearchPattern[1] = 0x4A; // J
|
|
|
|
SearchPattern[2] = 0x50; // P
|
|
|
|
break;
|
|
|
|
case CONF_REGION_EU:
|
|
|
|
SearchPattern[0] = 0x02;
|
|
|
|
SearchPattern[1] = 0x45; // E
|
|
|
|
SearchPattern[2] = 0x55; // U
|
|
|
|
break;
|
|
|
|
case CONF_REGION_KR:
|
|
|
|
SearchPattern[0] = 0x04;
|
|
|
|
SearchPattern[1] = 0x4B; // K
|
|
|
|
SearchPattern[2] = 0x52; // R
|
|
|
|
break;
|
|
|
|
case CONF_REGION_CN:
|
|
|
|
SearchPattern[0] = 0x05;
|
|
|
|
SearchPattern[1] = 0x43; // C
|
|
|
|
SearchPattern[2] = 0x4E; // N
|
|
|
|
break;
|
|
|
|
case CONF_REGION_US:
|
|
|
|
default:
|
|
|
|
SearchPattern[0] = 0x01;
|
|
|
|
SearchPattern[1] = 0x55; // U
|
|
|
|
SearchPattern[2] = 0x53; // S
|
2009-07-30 07:41:12 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
switch (diskid[3])
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
case 'J':
|
|
|
|
PatchData[1] = 0x4A; // J
|
|
|
|
PatchData[2] = 0x50; // P
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'D':
|
|
|
|
case 'F':
|
|
|
|
case 'P':
|
|
|
|
case 'X':
|
|
|
|
case 'Y':
|
|
|
|
PatchData[1] = 0x45; // E
|
|
|
|
PatchData[2] = 0x55; // U
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'E':
|
|
|
|
default:
|
|
|
|
PatchData[1] = 0x55; // U
|
|
|
|
PatchData[2] = 0x53; // S
|
2009-07-30 07:41:12 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
while (Size >= 4)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (Addr[0] == SearchPattern[0] && Addr[1] == SearchPattern[1] && Addr[2] == SearchPattern[2] && Addr[3]
|
|
|
|
== SearchPattern[3])
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-07-30 07:41:12 +02:00
|
|
|
//*Addr = PatchData[0];
|
|
|
|
Addr += 1;
|
|
|
|
*Addr = PatchData[1];
|
|
|
|
Addr += 1;
|
|
|
|
*Addr = PatchData[2];
|
|
|
|
Addr += 1;
|
|
|
|
//*Addr = PatchData[3];
|
|
|
|
Addr += 1;
|
|
|
|
Size -= 4;
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-07-30 07:41:12 +02:00
|
|
|
Addr += 4;
|
|
|
|
Size -= 4;
|
|
|
|
}
|
|
|
|
}
|
2009-05-03 20:53:31 +02:00
|
|
|
}
|