2012-08-05 15:48:15 +02:00
|
|
|
|
2012-10-14 19:18:13 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <ogcsys.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <malloc.h>
|
2012-08-12 23:26:24 +02:00
|
|
|
#include "apploader.h"
|
2012-10-14 19:18:13 +02:00
|
|
|
#include "wdvd.h"
|
2012-01-21 21:57:41 +01:00
|
|
|
#include "patchcode.h"
|
2012-10-14 19:18:13 +02:00
|
|
|
#include "videopatch.h"
|
2012-07-16 16:05:57 +02:00
|
|
|
#include "cios.h"
|
2012-08-12 23:26:24 +02:00
|
|
|
#include "fst.h"
|
|
|
|
#include "wip.h"
|
2012-10-14 19:18:13 +02:00
|
|
|
#include "gecko.h"
|
2012-10-20 00:01:30 +02:00
|
|
|
#include "memory.h"
|
2012-10-14 19:18:13 +02:00
|
|
|
#include "video_tinyload.h"
|
2023-03-17 22:25:30 +01:00
|
|
|
#include "kirbypatch.h"
|
2012-08-12 23:26:24 +02:00
|
|
|
|
|
|
|
/* Apploader function pointers */
|
|
|
|
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)());
|
2012-05-16 00:34:57 +02:00
|
|
|
|
2012-12-27 18:01:04 +01:00
|
|
|
/* pointers */
|
|
|
|
static u8 *appldr = (u8*)0x81200000;
|
|
|
|
static const char *GameID = (const char*)0x80000000;
|
2012-08-12 23:26:24 +02:00
|
|
|
|
2012-10-14 19:18:13 +02:00
|
|
|
/* Constants */
|
2023-04-08 00:06:30 +02:00
|
|
|
#define APPLDR_OFFSET 0x910// usblgx uses 0x2440 -huh?
|
|
|
|
#define APPLDR_CODE 0x918// usblgx uses APPLDR_OFFSET + 0x20 - huh?
|
2012-10-14 19:18:13 +02:00
|
|
|
|
2021-09-27 13:46:51 +02:00
|
|
|
void maindolpatches(void *dst, int len, u8 vidMode, GXRModeObj *vmode, bool vipatch, bool countryString, u8 patchVidModes, int aspectRatio,
|
|
|
|
u32 returnTo, bool patchregion, u8 private_server, const char *server_addr, u8 deflicker, u8 bootType);
|
2012-07-16 16:05:57 +02:00
|
|
|
static void patch_NoDiscinDrive(void *buffer, u32 len);
|
|
|
|
static void Anti_002_fix(void *Address, int Size);
|
2012-10-14 19:18:13 +02:00
|
|
|
static bool Remove_001_Protection(void *Address, int Size);
|
2012-10-20 00:01:30 +02:00
|
|
|
static void PrinceOfPersiaPatch();
|
|
|
|
static void NewSuperMarioBrosPatch();
|
2021-01-05 21:01:03 +01:00
|
|
|
static void Patch_23400_and_MKWii_vulnerability();
|
2012-10-14 19:18:13 +02:00
|
|
|
bool hookpatched = false;
|
2012-08-12 23:26:24 +02:00
|
|
|
|
2023-04-08 00:06:30 +02:00
|
|
|
// wiiflow uses a struct to hold the appldr hdr and usblgx uses a u32 buffer[32] array to hold it.
|
2012-10-21 17:28:00 +02:00
|
|
|
/* Thanks Tinyload */
|
|
|
|
static struct
|
|
|
|
{
|
2023-04-08 00:06:30 +02:00
|
|
|
char revision[16];//[0-3] 16 divided by 4 bytes = 4
|
|
|
|
void *entry;// [4] 4 bytes
|
|
|
|
s32 size;//[5] 4 bytes
|
|
|
|
s32 trailersize;// [6] 4 bytes
|
|
|
|
s32 padding;// [7] 4 bytes
|
|
|
|
} apploader_hdr ATTRIBUTE_ALIGN(32);// 16+4+4+4+4=32 bytes
|
2012-10-21 17:28:00 +02:00
|
|
|
|
2019-09-23 16:20:22 +02:00
|
|
|
u32 Apploader_Run(u8 vidMode, GXRModeObj *vmode, bool vipatch, bool countryString, u8 patchVidModes, int aspectRatio, u32 returnTo,
|
2023-04-08 00:06:30 +02:00
|
|
|
bool patchregion , u8 private_server, const char *server_addr, u8 videoWidth, bool patchFix480p, u8 deflicker, u8 bootType)
|
2012-10-13 00:25:22 +02:00
|
|
|
{
|
2021-01-05 21:01:03 +01:00
|
|
|
//! Disable private server for games that still have official servers.
|
2021-11-29 18:36:30 +01:00
|
|
|
if(memcmp(GameID, "SC7", 3) == 0 || memcmp(GameID, "RJA", 3) == 0 ||
|
2021-01-05 21:01:03 +01:00
|
|
|
memcmp(GameID, "SM8", 3) == 0 || memcmp(GameID, "SZB", 3) == 0 || memcmp(GameID, "R9J", 3) == 0)
|
|
|
|
{
|
|
|
|
private_server = PRIVSERV_OFF; // Private server patching causes error 20100
|
|
|
|
}
|
|
|
|
|
2021-11-29 18:36:30 +01:00
|
|
|
// if either of these 2 games - adds internal wip codes before do_wip_code() is called in maindolpatches()
|
|
|
|
// note: using external .wip codes for these games will prevent their internal codes.
|
2012-10-14 19:18:13 +02:00
|
|
|
PrinceOfPersiaPatch();
|
|
|
|
NewSuperMarioBrosPatch();
|
2012-10-13 00:25:22 +02:00
|
|
|
|
2012-10-14 19:18:13 +02:00
|
|
|
void *dst = NULL;
|
|
|
|
int len = 0;
|
|
|
|
int offset = 0;
|
2012-10-13 18:57:03 +02:00
|
|
|
u32 appldr_len;
|
2012-10-14 19:18:13 +02:00
|
|
|
s32 ret;
|
2012-10-21 17:28:00 +02:00
|
|
|
|
|
|
|
app_entry appldr_entry;
|
2012-08-12 23:26:24 +02:00
|
|
|
app_init appldr_init;
|
|
|
|
app_main appldr_main;
|
2012-05-13 17:13:33 +02:00
|
|
|
app_final appldr_final;
|
2012-08-12 23:26:24 +02:00
|
|
|
|
2012-05-13 17:13:33 +02:00
|
|
|
/* Read apploader header */
|
2012-10-21 17:28:00 +02:00
|
|
|
ret = WDVD_Read(&apploader_hdr, 0x20, APPLDR_OFFSET);
|
2012-08-10 15:47:05 +02:00
|
|
|
if(ret < 0)
|
2012-10-21 17:28:00 +02:00
|
|
|
return 0;
|
2012-05-13 17:13:33 +02:00
|
|
|
|
|
|
|
/* Calculate apploader length */
|
2012-10-21 17:28:00 +02:00
|
|
|
appldr_len = apploader_hdr.size + apploader_hdr.trailersize;
|
2012-08-12 23:26:24 +02:00
|
|
|
|
2012-05-13 17:13:33 +02:00
|
|
|
/* Read apploader code */
|
2012-10-20 15:24:30 +02:00
|
|
|
ret = WDVD_Read(appldr, appldr_len, APPLDR_CODE);
|
2012-07-26 00:12:17 +02:00
|
|
|
if(ret < 0)
|
2012-10-21 17:28:00 +02:00
|
|
|
return 0;
|
2012-08-10 15:47:05 +02:00
|
|
|
|
2012-08-12 23:26:24 +02:00
|
|
|
/* Flush into memory */
|
2012-10-14 19:18:13 +02:00
|
|
|
DCFlushRange(appldr, appldr_len);
|
|
|
|
ICInvalidateRange(appldr, appldr_len);
|
2012-08-12 23:26:24 +02:00
|
|
|
|
|
|
|
/* Set apploader entry function */
|
2012-10-21 17:28:00 +02:00
|
|
|
appldr_entry = apploader_hdr.entry;
|
2012-08-12 23:26:24 +02:00
|
|
|
|
|
|
|
/* Call apploader entry */
|
|
|
|
appldr_entry(&appldr_init, &appldr_main, &appldr_final);
|
|
|
|
|
|
|
|
/* Initialize apploader */
|
2012-10-14 19:18:13 +02:00
|
|
|
appldr_init(gprintf);
|
2012-08-12 23:26:24 +02:00
|
|
|
|
|
|
|
while(appldr_main(&dst, &len, &offset))
|
2012-05-16 21:29:53 +02:00
|
|
|
{
|
|
|
|
/* Read data from DVD */
|
2012-10-20 15:24:30 +02:00
|
|
|
WDVD_Read(dst, len, offset);
|
2021-09-27 13:46:51 +02:00
|
|
|
// if server is wiimmfi and game is mario kart wii don't patch private server here, do_new_wiimfi() patches it below.
|
|
|
|
if(private_server == PRIVSERV_WIIMMFI && memcmp("RMC", GameID, 3) == 0)
|
|
|
|
maindolpatches(dst, len, vidMode, vmode, vipatch, countryString, patchVidModes, aspectRatio, returnTo, patchregion,
|
|
|
|
0, NULL, deflicker, bootType);
|
2020-11-29 01:20:39 +01:00
|
|
|
else
|
2021-09-27 13:46:51 +02:00
|
|
|
maindolpatches(dst, len, vidMode, vmode, vipatch, countryString, patchVidModes, aspectRatio, returnTo, patchregion,
|
|
|
|
private_server, server_addr, deflicker, bootType);
|
2020-11-29 01:20:39 +01:00
|
|
|
|
2012-10-14 19:18:13 +02:00
|
|
|
DCFlushRange(dst, len);
|
|
|
|
ICInvalidateRange(dst, len);
|
2012-10-20 15:24:30 +02:00
|
|
|
prog(20);
|
2012-05-16 21:29:53 +02:00
|
|
|
}
|
2012-10-14 19:18:13 +02:00
|
|
|
free_wip();
|
2023-04-08 00:06:30 +02:00
|
|
|
|
|
|
|
patch_kirby((u8 *)0x80000000);// can't be done during maindolpatches.
|
|
|
|
|
|
|
|
if(videoWidth == WIDTH_FRAMEBUFFER)
|
|
|
|
patch_width((void*)0x80000000, 0x900000);
|
|
|
|
|
2012-10-14 19:18:13 +02:00
|
|
|
if(hooktype != 0 && hookpatched)
|
2012-10-20 15:24:30 +02:00
|
|
|
ocarina_do_code();
|
2019-09-23 16:20:22 +02:00
|
|
|
|
2021-11-29 18:36:30 +01:00
|
|
|
//! Apply the 480p fix.
|
|
|
|
//! This needs to be done after the call to maindolpatches(), after loading any code handler.
|
|
|
|
//! Can (and should) be done before Wiimmfi patching, can't be done in maindolpatches() itself.
|
2021-12-01 22:18:14 +01:00
|
|
|
if(patchFix480p)
|
2019-09-23 16:20:22 +02:00
|
|
|
PatchFix480p();
|
|
|
|
|
2021-11-29 18:36:30 +01:00
|
|
|
//! If we're NOT on Wiimmfi, patch the known Remote Code Execution (RCE) vulnerability in MKWii.
|
2021-01-05 21:01:03 +01:00
|
|
|
//! Wiimmfi will handle that on its own through the update payload.
|
|
|
|
//! This will also patch error 23400 for a couple games that still have official servers.
|
|
|
|
if(private_server != PRIVSERV_WIIMMFI)
|
|
|
|
Patch_23400_and_MKWii_vulnerability();
|
|
|
|
|
2021-11-29 18:36:30 +01:00
|
|
|
else //PRIVSERV_WIIMMFI
|
2021-09-27 13:46:51 +02:00
|
|
|
{
|
|
|
|
if(memcmp("RMC", GameID, 3) != 0)// This isn't MKWii, perform the patch for other games.
|
2021-11-29 18:36:30 +01:00
|
|
|
do_new_wiimmfi_nonMKWii();// does not patch the server address - done in maindolpatches()
|
2021-09-27 13:46:51 +02:00
|
|
|
else // This is MKWii, perform the known patch from 2018.
|
2021-11-29 18:36:30 +01:00
|
|
|
do_new_wiimmfi();// includes patching the server address
|
2021-09-27 13:46:51 +02:00
|
|
|
}
|
2012-10-14 19:18:13 +02:00
|
|
|
|
2012-01-21 21:57:41 +01:00
|
|
|
/* Set entry point from apploader */
|
2012-10-21 17:28:00 +02:00
|
|
|
return (u32)appldr_final();
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
|
|
|
|
2021-09-27 13:46:51 +02:00
|
|
|
void maindolpatches(void *dst, int len, u8 vidMode, GXRModeObj *vmode, bool vipatch, bool countryString, u8 patchVidModes, int aspectRatio,
|
|
|
|
u32 returnTo, bool patchregion , u8 private_server, const char *serverAddr, u8 deflicker, u8 bootType)
|
2012-05-16 21:29:53 +02:00
|
|
|
{
|
2021-09-25 21:00:02 +02:00
|
|
|
u8 vfilter_off[7] = {0, 0, 21, 22, 21, 0, 0};
|
|
|
|
u8 vfilter_low[7] = {4, 4, 16, 16, 16, 4, 4};
|
|
|
|
u8 vfilter_medium[7] = {4, 8, 12, 16, 12, 8, 4};
|
|
|
|
u8 vfilter_high[7] = {8, 8, 10, 12, 10, 8, 8};
|
|
|
|
|
2020-05-04 22:31:00 +02:00
|
|
|
patchVideoModes(dst, len, vidMode, vmode, patchVidModes, bootType);
|
2012-10-14 19:18:13 +02:00
|
|
|
|
2013-05-21 14:43:14 +02:00
|
|
|
if(debuggerselect == 2)
|
|
|
|
Patch_fwrite(dst, len);
|
2012-10-20 00:01:30 +02:00
|
|
|
if(hooktype != 0 && hookpatched == false)
|
|
|
|
hookpatched = dogamehooks(dst, len, false);
|
2012-10-14 19:18:13 +02:00
|
|
|
if(vipatch)
|
2012-05-16 21:29:53 +02:00
|
|
|
vidolpatcher(dst, len);
|
2023-04-08 00:06:30 +02:00
|
|
|
if(patchVidModes > 0)
|
|
|
|
PatchVideoSneek(dst, len);
|
2012-05-16 21:29:53 +02:00
|
|
|
if(configbytes[0] != 0xCD)
|
|
|
|
langpatcher(dst, len);
|
2012-10-14 19:18:13 +02:00
|
|
|
if(countryString)
|
|
|
|
PatchCountryStrings(dst, len); // Country Patch by WiiPower
|
2023-04-08 00:06:30 +02:00
|
|
|
do_wip_code((u8 *)dst, len);
|
|
|
|
Remove_001_Protection(dst, len);
|
|
|
|
if(CurrentIOS.Type == IOS_TYPE_WANIN && CurrentIOS.Revision < 13)
|
|
|
|
Anti_002_fix(dst, len);
|
|
|
|
if((CurrentIOS.Type == IOS_TYPE_WANIN && CurrentIOS.Revision < 13) || CurrentIOS.Type == IOS_TYPE_HERMES)
|
|
|
|
patch_NoDiscinDrive(dst, len);
|
2014-02-16 21:12:35 +01:00
|
|
|
if(patchregion)
|
|
|
|
PatchRegion(dst, len);
|
2021-09-25 21:00:02 +02:00
|
|
|
if(deflicker == DEFLICKER_ON_LOW)
|
|
|
|
{
|
|
|
|
patch_vfilters(dst, len, vfilter_low);
|
|
|
|
patch_vfilters_rogue(dst, len, vfilter_low);
|
|
|
|
}
|
|
|
|
else if(deflicker == DEFLICKER_ON_MEDIUM)
|
|
|
|
{
|
|
|
|
patch_vfilters(dst, len, vfilter_medium);
|
|
|
|
patch_vfilters_rogue(dst, len, vfilter_medium);
|
|
|
|
}
|
|
|
|
else if(deflicker == DEFLICKER_ON_HIGH)
|
|
|
|
{
|
|
|
|
patch_vfilters(dst, len, vfilter_high);
|
|
|
|
patch_vfilters_rogue(dst, len, vfilter_high);
|
|
|
|
}
|
|
|
|
else if(deflicker != DEFLICKER_NORMAL) // Either safe or extended
|
|
|
|
{
|
|
|
|
patch_vfilters(dst, len, vfilter_off);
|
|
|
|
patch_vfilters_rogue(dst, len, vfilter_off);
|
|
|
|
// This might break fade and brightness effects
|
|
|
|
if (deflicker == DEFLICKER_OFF_EXTENDED)
|
|
|
|
deflicker_patch(dst, len);
|
|
|
|
}
|
2023-04-08 00:06:30 +02:00
|
|
|
if(returnTo)
|
|
|
|
PatchReturnTo(dst, len, returnTo);
|
|
|
|
if(aspectRatio != -1)
|
|
|
|
PatchAspectRatio(dst, len, aspectRatio);
|
|
|
|
if(private_server)
|
|
|
|
PrivateServerPatcher(dst, len, private_server, serverAddr);
|
2012-05-16 21:29:53 +02:00
|
|
|
}
|
|
|
|
|
2012-07-16 16:05:57 +02:00
|
|
|
static void patch_NoDiscinDrive(void *buffer, u32 len)
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
2012-07-16 16:05:57 +02:00
|
|
|
static const u8 oldcode[] = {0x54, 0x60, 0xF7, 0xFF, 0x40, 0x82, 0x00, 0x0C, 0x54, 0x60, 0x07, 0xFF, 0x41, 0x82, 0x00, 0x0C};
|
|
|
|
static const u8 newcode[] = {0x54, 0x60, 0xF7, 0xFF, 0x40, 0x82, 0x00, 0x0C, 0x54, 0x60, 0x07, 0xFF, 0x48, 0x00, 0x00, 0x0C};
|
|
|
|
u32 n;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-16 16:05:57 +02:00
|
|
|
/* Patch cover register */
|
|
|
|
for(n = 0; n < len - sizeof oldcode; n += 4) // n is not 4 aligned here, so you can get an out of buffer thing
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
2012-07-16 16:05:57 +02:00
|
|
|
if (memcmp(buffer + n, (void *)oldcode, sizeof oldcode) == 0)
|
|
|
|
memcpy(buffer + n, (void *)newcode, sizeof newcode);
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
2012-07-16 16:05:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void Anti_002_fix(void *Address, int Size)
|
|
|
|
{
|
|
|
|
static const u8 SearchPattern[] = {0x2C, 0x00, 0x00, 0x00, 0x48, 0x00, 0x02, 0x14, 0x3C, 0x60, 0x80, 0x00};
|
|
|
|
static const u8 PatchData[] = {0x2C, 0x00, 0x00, 0x00, 0x40, 0x82, 0x02, 0x14, 0x3C, 0x60, 0x80, 0x00};
|
|
|
|
void *Addr = Address;
|
|
|
|
void *Addr_end = Address + Size;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-07-16 16:05:57 +02:00
|
|
|
while(Addr <= Addr_end - sizeof SearchPattern)
|
|
|
|
{
|
|
|
|
if(memcmp(Addr, SearchPattern, sizeof SearchPattern) == 0)
|
|
|
|
memcpy(Addr, PatchData, sizeof PatchData);
|
|
|
|
Addr += 4;
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
|
|
|
}
|
2012-10-13 18:57:03 +02:00
|
|
|
|
2021-12-01 17:33:01 +01:00
|
|
|
static void PrinceOfPersiaPatch()// Prince of Persia: The Forgotten Sands
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
2012-12-27 18:01:04 +01:00
|
|
|
if(memcmp("SPX", GameID, 3) != 0 && memcmp("RPW", GameID, 3) != 0)
|
2012-10-20 00:01:30 +02:00
|
|
|
return;
|
2012-10-14 19:18:13 +02:00
|
|
|
|
2012-10-20 00:01:30 +02:00
|
|
|
WIP_Code CodeList[5];
|
2012-05-16 21:29:53 +02:00
|
|
|
CodeList[0].offset = 0x007AAC6A;
|
|
|
|
CodeList[0].srcaddress = 0x7A6B6F6A;
|
|
|
|
CodeList[0].dstaddress = 0x6F6A7A6B;
|
|
|
|
CodeList[1].offset = 0x007AAC75;
|
|
|
|
CodeList[1].srcaddress = 0x7C7A6939;
|
|
|
|
CodeList[1].dstaddress = 0x69397C7A;
|
|
|
|
CodeList[2].offset = 0x007AAC82;
|
|
|
|
CodeList[2].srcaddress = 0x7376686B;
|
|
|
|
CodeList[2].dstaddress = 0x686B7376;
|
|
|
|
CodeList[3].offset = 0x007AAC92;
|
|
|
|
CodeList[3].srcaddress = 0x80717570;
|
|
|
|
CodeList[3].dstaddress = 0x75708071;
|
|
|
|
CodeList[4].offset = 0x007AAC9D;
|
|
|
|
CodeList[4].srcaddress = 0x82806F3F;
|
|
|
|
CodeList[4].dstaddress = 0x6F3F8280;
|
2012-10-20 00:01:30 +02:00
|
|
|
set_wip_list(CodeList, 5);
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-10-20 00:01:30 +02:00
|
|
|
static void NewSuperMarioBrosPatch()
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
2012-10-20 00:01:30 +02:00
|
|
|
WIP_Code CodeList[3];
|
2012-12-27 18:01:04 +01:00
|
|
|
if(memcmp("SMNE01", GameID, 6) == 0)
|
2012-05-16 21:29:53 +02:00
|
|
|
{
|
|
|
|
CodeList[0].offset = 0x001AB610;
|
|
|
|
CodeList[0].srcaddress = 0x9421FFD0;
|
|
|
|
CodeList[0].dstaddress = 0x4E800020;
|
|
|
|
CodeList[1].offset = 0x001CED53;
|
|
|
|
CodeList[1].srcaddress = 0xDA000000;
|
|
|
|
CodeList[1].dstaddress = 0x71000000;
|
|
|
|
CodeList[2].offset = 0x001CED6B;
|
|
|
|
CodeList[2].srcaddress = 0xDA000000;
|
|
|
|
CodeList[2].dstaddress = 0x71000000;
|
2012-10-20 00:01:30 +02:00
|
|
|
set_wip_list(CodeList, 3);
|
2012-05-16 21:29:53 +02:00
|
|
|
}
|
2012-12-27 18:01:04 +01:00
|
|
|
else if(memcmp("SMNP01", GameID, 6) == 0)
|
2012-05-16 21:29:53 +02:00
|
|
|
{
|
|
|
|
CodeList[0].offset = 0x001AB750;
|
|
|
|
CodeList[0].srcaddress = 0x9421FFD0;
|
|
|
|
CodeList[0].dstaddress = 0x4E800020;
|
|
|
|
CodeList[1].offset = 0x001CEE90;
|
|
|
|
CodeList[1].srcaddress = 0x38A000DA;
|
|
|
|
CodeList[1].dstaddress = 0x38A00071;
|
|
|
|
CodeList[2].offset = 0x001CEEA8;
|
|
|
|
CodeList[2].srcaddress = 0x388000DA;
|
|
|
|
CodeList[2].dstaddress = 0x38800071;
|
2012-10-20 00:01:30 +02:00
|
|
|
set_wip_list(CodeList, 3);
|
2012-05-16 21:29:53 +02:00
|
|
|
}
|
2012-12-27 18:01:04 +01:00
|
|
|
else if(memcmp("SMNJ01", GameID, 6) == 0)
|
2012-05-16 21:29:53 +02:00
|
|
|
{
|
|
|
|
CodeList[0].offset = 0x001AB420;
|
|
|
|
CodeList[0].srcaddress = 0x9421FFD0;
|
|
|
|
CodeList[0].dstaddress = 0x4E800020;
|
|
|
|
CodeList[1].offset = 0x001CEB63;
|
|
|
|
CodeList[1].srcaddress = 0xDA000000;
|
|
|
|
CodeList[1].dstaddress = 0x71000000;
|
|
|
|
CodeList[2].offset = 0x001CEB7B;
|
|
|
|
CodeList[2].srcaddress = 0xDA000000;
|
|
|
|
CodeList[2].dstaddress = 0x71000000;
|
2012-10-20 00:01:30 +02:00
|
|
|
set_wip_list(CodeList, 3);
|
2012-05-16 21:29:53 +02:00
|
|
|
}
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
2012-10-13 18:57:03 +02:00
|
|
|
|
2012-10-14 19:18:13 +02:00
|
|
|
static bool Remove_001_Protection(void *Address, int Size)
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
|
|
|
static const u8 SearchPattern[] = {0x40, 0x82, 0x00, 0x0C, 0x38, 0x60, 0x00, 0x01, 0x48, 0x00, 0x02, 0x44, 0x38, 0x61, 0x00, 0x18};
|
|
|
|
static const u8 PatchData[] = {0x40, 0x82, 0x00, 0x04, 0x38, 0x60, 0x00, 0x01, 0x48, 0x00, 0x02, 0x44, 0x38, 0x61, 0x00, 0x18};
|
|
|
|
u8 *Addr_end = Address + Size;
|
|
|
|
u8 *Addr;
|
|
|
|
|
2012-10-20 00:01:30 +02:00
|
|
|
for(Addr = Address; Addr <= Addr_end - sizeof SearchPattern; Addr += 4)
|
2012-05-12 18:03:14 +02:00
|
|
|
{
|
2012-10-20 00:01:30 +02:00
|
|
|
if(memcmp(Addr, SearchPattern, sizeof SearchPattern) == 0)
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
|
|
|
memcpy(Addr, PatchData, sizeof PatchData);
|
2012-10-14 19:18:13 +02:00
|
|
|
return true;
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
2012-05-12 18:03:14 +02:00
|
|
|
}
|
2012-10-14 19:18:13 +02:00
|
|
|
return false;
|
2012-10-21 17:28:00 +02:00
|
|
|
}
|
2021-01-05 21:01:03 +01:00
|
|
|
|
|
|
|
static void Patch_23400_and_MKWii_vulnerability()
|
|
|
|
{
|
|
|
|
// Thanks to Seeky for the MKWii gecko codes
|
|
|
|
// Thanks to InvoxiPlayGames for the gecko codes for the 23400 fix.
|
|
|
|
// Reimplemented by Leseratte without the need for a code handler.
|
|
|
|
|
|
|
|
u32 * patch_addr = 0;
|
|
|
|
char * patched = 0;
|
|
|
|
|
|
|
|
// Patch error 23400 for CoD (Black Ops, Reflex, MW3) and Rock Band 3 / The Beatles
|
|
|
|
|
|
|
|
if (memcmp(GameID, "SC7", 3) == 0)
|
|
|
|
{
|
|
|
|
gprintf("Patching error 23400 for game %s\n", GameID);
|
|
|
|
*(u32 *)0x8023c954 = 0x41414141;
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (memcmp(GameID, "RJA", 3) == 0)
|
|
|
|
{
|
|
|
|
gprintf("Patching error 23400 for game %s\n", GameID);
|
|
|
|
*(u32 *)0x801b838c = 0x41414141;
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (memcmp(GameID, "SM8", 3) == 0)
|
|
|
|
{
|
|
|
|
gprintf("Patching error 23400 for game %s\n", GameID);
|
|
|
|
*(u32 *)0x80238c74 = 0x41414141;
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (memcmp(GameID, "SZB", 3) == 0)
|
|
|
|
{
|
|
|
|
gprintf("Patching error 23400 for game %s\n", GameID);
|
|
|
|
*(u32 *)0x808e3b20 = 0x41414141;
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (memcmp(GameID, "R9J", 3) == 0)
|
|
|
|
{
|
|
|
|
gprintf("Patching error 23400 for game %s\n", GameID);
|
|
|
|
*(u32 *)0x808d6934 = 0x41414141;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Patch RCE vulnerability in MKWii.
|
|
|
|
else if (memcmp(GameID, "RMC", 3) == 0)
|
|
|
|
{
|
|
|
|
switch (GameID[3]) {
|
|
|
|
|
|
|
|
case 'P':
|
|
|
|
patched = (char *)0x80276054;
|
|
|
|
patch_addr = (u32 *)0x8089a194;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'E':
|
|
|
|
patched = (char *)0x80271d14;
|
|
|
|
patch_addr = (u32 *)0x80895ac4;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'J':
|
|
|
|
patched = (char *)0x802759f4;
|
|
|
|
patch_addr = (u32 *)0x808992f4;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'K':
|
|
|
|
patched = (char *)0x80263E34;
|
|
|
|
patch_addr = (u32 *)0x808885cc;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
gprintf("NOT patching RCE vulnerability due to invalid game ID: %s\n", GameID);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*patched != '*')
|
|
|
|
{
|
|
|
|
gprintf("Game is already Wiimmfi-patched, don't apply the RCE fix\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gprintf("Patching RCE vulnerability for game ID %s\n", GameID);
|
|
|
|
|
|
|
|
for (int i = 0; i < 7; i++)
|
|
|
|
*patch_addr++ = 0xff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|