mirror of
https://github.com/wiidev/usbloadergx.git
synced 2024-11-16 00:15:08 +01:00
Update Wiimmfi patch (0.7.5)
This commit is contained in:
parent
8435e1f09f
commit
59f08ccd66
40
Dockerfile
Normal file
40
Dockerfile
Normal file
@ -0,0 +1,40 @@
|
||||
# Build:
|
||||
# DOCKER_BUILDKIT=1 docker build -o output .
|
||||
# for Windows, use
|
||||
# { "features": { "buildkit": true } }
|
||||
# instead of the environment variable
|
||||
|
||||
# Build a Debian base container
|
||||
FROM debian:buster as usbloader
|
||||
ENV DEBIAN_FRONTEND="noninteractive" TZ="Europe/London"
|
||||
RUN apt-get update -y && apt-get install -y \
|
||||
xz-utils make git && \
|
||||
apt-get -qq remove subversion
|
||||
|
||||
ADD https://wii.leseratte10.de/devkitPro/file.php/devkitPPC-r38-1-linux_x86_64.pkg.tar.xz /
|
||||
ADD https://wii.leseratte10.de/devkitPro/file.php/libogc-2.1.0-1-any.pkg.tar.xz /
|
||||
ADD https://wii.leseratte10.de/devkitPro/file.php/devkitppc-rules-1.1.0-1-any.pkg.tar.xz /
|
||||
ADD https://wii.leseratte10.de/devkitPro/file.php/general-tools-1.2.0-1-linux.pkg.tar.xz /
|
||||
ADD https://wii.leseratte10.de/devkitPro/file.php/gamecube-tools-1.0.2-1-linux.pkg.tar.xz /
|
||||
|
||||
|
||||
RUN tar -xf /devkitPPC-r38-1-linux_x86_64.pkg.tar.xz opt/devkitpro/devkitPPC --strip-components=1 && \
|
||||
tar -xf /libogc-2.1.0-1-any.pkg.tar.xz opt/devkitpro/libogc --strip-components=1 && \
|
||||
tar -xf /devkitppc-rules-1.1.0-1-any.pkg.tar.xz opt/devkitpro/devkitPPC --strip-components=1 && \
|
||||
tar -C /usr/local/bin -xf /general-tools-1.2.0-1-linux.pkg.tar.xz opt/devkitpro/tools/bin/bin2s --strip-components=4 && \
|
||||
tar -C /usr/local/bin -xf /gamecube-tools-1.0.2-1-linux.pkg.tar.xz opt/devkitpro/tools/bin/elf2dol --strip-components=4 && \
|
||||
mkdir /projectroot
|
||||
|
||||
ENV DEVKITPRO=/devkitpro
|
||||
ENV DEVKITPPC=/devkitpro/devkitPPC
|
||||
|
||||
|
||||
# Now we have a container that has the dev environment set up.
|
||||
# Copy current folder into container, then compile
|
||||
COPY . /projectroot/
|
||||
RUN cd /projectroot && make
|
||||
|
||||
|
||||
# Copy the DOL and ELF out of the container
|
||||
FROM scratch AS export-stage
|
||||
COPY --from=usbloader /projectroot/boot.* /
|
@ -55,7 +55,7 @@ void gamepatches(u8 videoSelected, u8 videoPatchDol, u8 aspectForce, u8 language
|
||||
{
|
||||
int i;
|
||||
|
||||
/* If a wip file is loaded for this game this does nothing - Dimok */
|
||||
// If a wip file is loaded for this game this does nothing - Dimok
|
||||
PoPPatch();
|
||||
NSMBPatch();
|
||||
|
||||
@ -74,10 +74,10 @@ void gamepatches(u8 videoSelected, u8 videoPatchDol, u8 aspectForce, u8 language
|
||||
if (sneekVideoPatch)
|
||||
sneek_video_patch(dst, len);
|
||||
|
||||
/*LANGUAGE PATCH - FISHEARS*/
|
||||
// LANGUAGE PATCH - FISHEARS
|
||||
langpatcher(dst, len, languageChoice);
|
||||
|
||||
/*Thanks to WiiPower*/
|
||||
// Thanks to WiiPower
|
||||
if (patchcountrystring == 1)
|
||||
PatchCountryStrings(dst, len);
|
||||
|
||||
@ -94,11 +94,18 @@ void gamepatches(u8 videoSelected, u8 videoPatchDol, u8 aspectForce, u8 language
|
||||
if (privateServer)
|
||||
PrivateServerPatcher(dst, len, privateServer, serverAddr);
|
||||
|
||||
if (privateServer == PRIVSERV_WIIMMFI)
|
||||
{
|
||||
// If we end up here, that means it's a NON-MKWii Wiimmfi patch
|
||||
// add the new patches.
|
||||
do_new_wiimmfi_nonMKWii(dst, len);
|
||||
}
|
||||
|
||||
DCFlushRange(dst, len);
|
||||
ICInvalidateRange(dst, len);
|
||||
}
|
||||
|
||||
/* ERROR 002 fix (thanks to WiiPower for sharing this)*/
|
||||
// ERROR 002 fix (thanks to WiiPower for sharing this)
|
||||
*(u32 *)0x80003140 = *(u32 *)0x80003188;
|
||||
|
||||
DCFlushRange((void *)0x80000000, 0x3f00);
|
||||
@ -115,8 +122,8 @@ bool Anti_002_fix(u8 * Address, int Size)
|
||||
return PatchDOL(Address, Size, (const u8 *)SearchPattern, sizeof(SearchPattern), (const u8 *)PatchData, sizeof(PatchData));
|
||||
}
|
||||
|
||||
|
||||
/** 480p Pixel Fix Patch by leseratte
|
||||
/**
|
||||
480p Pixel Fix Patch by leseratte
|
||||
fix for a Nintendo Revolution SDK bug found by Extrems affecting early Wii console when using 480p video mode.
|
||||
https://shmups.system11.org/viewtopic.php?p=1361158#p1361158
|
||||
https://github.com/ExtremsCorner/libogc-rice/commit/941d687e271fada68c359bbed98bed1fbb454448
|
||||
@ -130,7 +137,7 @@ void PatchFix480p()
|
||||
u32 patches_MKW[2] = {0x38600003, 0x98610019};
|
||||
/// Used by: MKWii, Wii Play, Need for Speed Nitro, Wii Sports, ...
|
||||
|
||||
/// Patch offset: ----------------------------------------------VVVVVVVV
|
||||
/// Patch offset: -----------------------------------------------VVVVVVVV
|
||||
u32 Pattern_NSMB[8] = {0x38000065, 0x9801001c, 0x3881001c, 0x386000e0, 0x9b81001d, 0x38a00002};
|
||||
u32 patches_NSMB[2] = {0x38a00003, 0x98a1001d};
|
||||
/// Used by: New Super Mario Bros, ...
|
||||
@ -167,11 +174,15 @@ void PatchFix480p()
|
||||
void *patch_ptr = 0;
|
||||
void *a = addr;
|
||||
|
||||
while ((char*)a < ((char*)addr + len)) {
|
||||
if (memcmp(a, &Pattern_MKW, 6 * 4) == 0) {
|
||||
while ((char *)a < ((char *)addr + len))
|
||||
{
|
||||
if (memcmp(a, &Pattern_MKW, 6 * 4) == 0)
|
||||
{
|
||||
// Found pattern?
|
||||
if (memcmp(a - 4, &prefix, 2) == 0) {
|
||||
if (memcmp(a + 8*4, &prefix, 2) == 0) {
|
||||
if (memcmp(a - 4, &prefix, 2) == 0)
|
||||
{
|
||||
if (memcmp(a + 8 * 4, &prefix, 2) == 0)
|
||||
{
|
||||
offset = a + 4;
|
||||
hexdump(a, 30);
|
||||
patch_ptr = &patches_MKW;
|
||||
@ -179,10 +190,13 @@ void PatchFix480p()
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (memcmp(a, &Pattern_NSMB, 6 * 4) == 0) {
|
||||
else if (memcmp(a, &Pattern_NSMB, 6 * 4) == 0)
|
||||
{
|
||||
// Found pattern?
|
||||
if (memcmp(a - 4, &prefix, 2) == 0) {
|
||||
if (memcmp(a + 8*4, &prefix, 2) == 0) {
|
||||
if (memcmp(a - 4, &prefix, 2) == 0)
|
||||
{
|
||||
if (memcmp(a + 8 * 4, &prefix, 2) == 0)
|
||||
{
|
||||
offset = a + 16;
|
||||
hexdump(a, 30);
|
||||
patch_ptr = &patches_NSMB;
|
||||
@ -193,9 +207,8 @@ void PatchFix480p()
|
||||
a += 4;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (offset == 0) {
|
||||
if (offset == 0)
|
||||
{
|
||||
// offset is still 0, we didn't find the pattern, return
|
||||
gprintf("Didn't find offset for 480p patch!\n");
|
||||
return;
|
||||
@ -243,11 +256,237 @@ void PrivateServerPatcher(void *addr, u32 len, u8 privateServer, const char *ser
|
||||
domainpatcher(addr, len, serverAddr);
|
||||
}
|
||||
|
||||
static inline int GetOpcode(unsigned int *instructionAddr)
|
||||
{
|
||||
return ((*instructionAddr >> 26) & 0x3f);
|
||||
}
|
||||
|
||||
static inline int GetImmediateDataVal(unsigned int *instructionAddr)
|
||||
{
|
||||
return (*instructionAddr & 0xffff);
|
||||
}
|
||||
|
||||
static inline int GetLoadTargetReg(unsigned int *instructionAddr)
|
||||
{
|
||||
return (int)((*instructionAddr >> 21) & 0x1f);
|
||||
}
|
||||
|
||||
static inline int GetComparisonTargetReg(unsigned int *instructionAddr)
|
||||
{
|
||||
return (int)((*instructionAddr >> 16) & 0x1f);
|
||||
}
|
||||
|
||||
s8 do_new_wiimmfi_nonMKWii(void *addr, u32 len)
|
||||
{
|
||||
// As of February 2021, Wiimmfi requires a special Wiimmfi patcher
|
||||
// update which does a bit more than just patch the server addresses.
|
||||
// This function is being called by apploader.c, right before
|
||||
// jumping to the entry point (only for non-MKWii games on Wiimmfi),
|
||||
// and applies all the necessary security fixes to the game.
|
||||
|
||||
// This function has been implemented by Leseratte. Please don't
|
||||
// try to modify it without speaking to the Wiimmfi team because
|
||||
// doing so could have unintended side effects.
|
||||
|
||||
// This function MUST not run for MKWii, that would break stuff.
|
||||
|
||||
int hasGT2Error = 0;
|
||||
char gt2locator[] = {0x38, 0x61, 0x00, 0x08, 0x38, 0xA0, 0x00, 0x14};
|
||||
// Opcode list for p2p:
|
||||
unsigned char opCodeChainP2P_v1[22] = {32, 32, 21, 21, 21, 21, 20, 20, 31, 40, 21, 20, 20, 31, 31, 10, 20, 36, 21, 44, 36, 16};
|
||||
unsigned char opCodeChainP2P_v2[22] = {32, 32, 21, 21, 20, 21, 20, 21, 31, 40, 21, 20, 20, 31, 31, 10, 20, 36, 21, 44, 36, 16};
|
||||
|
||||
// Opcode list for MASTER:
|
||||
unsigned char opCodeChainMASTER_v1[22] = {21, 21, 21, 21, 40, 20, 20, 20, 20, 31, 31, 14, 31, 20, 21, 44, 21, 36, 36, 18, 11, 16};
|
||||
unsigned char opCodeChainMASTER_v2[22] = {21, 21, 21, 21, 40, 20, 20, 20, 20, 31, 31, 14, 31, 20, 21, 36, 21, 44, 36, 18, 11, 16};
|
||||
|
||||
int MASTERopcodeChainOffset = 0;
|
||||
|
||||
char *cur = addr;
|
||||
const char *end = addr + len;
|
||||
|
||||
// Check if the game needs the new patch.
|
||||
do
|
||||
{
|
||||
if (memcmp(cur, "<GT2> RECV-0x%02x <- [--------:-----] [pid=%u]", 0x2e) == 0)
|
||||
{
|
||||
hasGT2Error++;
|
||||
}
|
||||
} while (++cur < end);
|
||||
|
||||
cur = addr;
|
||||
|
||||
if (hasGT2Error > 1)
|
||||
return 1; // error, this either doesn't exist, or exists once. Can't exist multiple times.
|
||||
|
||||
int successful_patch_p2p = 0;
|
||||
int successful_patch_master = 0;
|
||||
|
||||
do
|
||||
{
|
||||
// Patch the User-Agent so Wiimmfi knows this game has been patched.
|
||||
// This also identifies patcher (G=USB-Loader GX) and patch version (=3), please
|
||||
// do not change this without talking to Leseratte first.
|
||||
if (memcmp(cur, "User-Agent\x00\x00RVL SDK/", 20) == 0)
|
||||
{
|
||||
if (hasGT2Error)
|
||||
memcpy(cur + 12, "G-3-1\x00", 6);
|
||||
else
|
||||
memcpy(cur + 12, "G-3-0\x00", 6);
|
||||
}
|
||||
|
||||
if (hasGT2Error)
|
||||
{
|
||||
if (memcmp(cur, >2locator, 8) == 0)
|
||||
{
|
||||
int found_opcode_chain_P2P_v1 = 1;
|
||||
int found_opcode_chain_P2P_v2 = 1;
|
||||
|
||||
for (int i = 0; i < 22; i++)
|
||||
{
|
||||
int offset = (i * 4) + 12;
|
||||
if (opCodeChainP2P_v1[i] != (unsigned char)(GetOpcode((unsigned int *)(cur + offset))))
|
||||
found_opcode_chain_P2P_v1 = 0;
|
||||
|
||||
if (opCodeChainP2P_v2[i] != (unsigned char)(GetOpcode((unsigned int *)(cur + offset))))
|
||||
found_opcode_chain_P2P_v2 = 0;
|
||||
}
|
||||
int found_opcode_chain_MASTER;
|
||||
for (int dynamic = 0; dynamic < 40; dynamic += 4)
|
||||
{
|
||||
found_opcode_chain_MASTER = 1;
|
||||
int offset = 0;
|
||||
for (int i = 0; i < 22; i++)
|
||||
{
|
||||
offset = (i * 4) + 12 + dynamic;
|
||||
if (
|
||||
(opCodeChainMASTER_v1[i] != (unsigned char)(GetOpcode((unsigned int *)(cur + offset)))) &&
|
||||
(opCodeChainMASTER_v2[i] != (unsigned char)(GetOpcode((unsigned int *)(cur + offset))))
|
||||
)
|
||||
{
|
||||
found_opcode_chain_MASTER = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (found_opcode_chain_MASTER)
|
||||
{
|
||||
//gprintf("found master opcode chain\n");
|
||||
// We found the opcode chain, let's take a note of the offset.
|
||||
MASTERopcodeChainOffset = (int)(cur + 12 + dynamic);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found_opcode_chain_P2P_v1 || found_opcode_chain_P2P_v2)
|
||||
{
|
||||
// Match found
|
||||
// Now compare all the immediate values:
|
||||
if (
|
||||
GetImmediateDataVal((unsigned int *)(cur + 0x0c)) == 0x0c &&
|
||||
GetImmediateDataVal((unsigned int *)(cur + 0x10)) == 0x18 &&
|
||||
GetImmediateDataVal((unsigned int *)(cur + 0x30)) == 0x12 &&
|
||||
GetImmediateDataVal((unsigned int *)(cur + 0x48)) == 0x5a &&
|
||||
GetImmediateDataVal((unsigned int *)(cur + 0x50)) == 0x0c &&
|
||||
GetImmediateDataVal((unsigned int *)(cur + 0x58)) == 0x12 &&
|
||||
GetImmediateDataVal((unsigned int *)(cur + 0x5c)) == 0x18 &&
|
||||
GetImmediateDataVal((unsigned int *)(cur + 0x60)) == 0x18
|
||||
)
|
||||
{
|
||||
//gprintf("Patching P2P...\n");
|
||||
int loadedDataReg = GetLoadTargetReg((unsigned int *)(cur + 0x14));
|
||||
int comparisonDataReg = GetComparisonTargetReg((unsigned int *)(cur + 0x48));
|
||||
|
||||
if (found_opcode_chain_P2P_v1)
|
||||
{
|
||||
*(int *)(cur + 0x14) = (0x88010011 | (comparisonDataReg << 21));
|
||||
*(int *)(cur + 0x18) = (0x28000080 | (comparisonDataReg << 16));
|
||||
*(int *)(cur + 0x24) = 0x41810064;
|
||||
*(int *)(cur + 0x28) = 0x60000000;
|
||||
*(int *)(cur + 0x2c) = 0x60000000;
|
||||
*(int *)(cur + 0x34) = (0x3C005A00 | (comparisonDataReg << 21));
|
||||
*(int *)(cur + 0x48) = (0x7C000000 | (comparisonDataReg << 16) | (loadedDataReg << 11));
|
||||
successful_patch_p2p++;
|
||||
}
|
||||
if (found_opcode_chain_P2P_v2)
|
||||
{
|
||||
loadedDataReg = 12;
|
||||
|
||||
*(int *)(cur + 0x14) = (0x88010011 | (comparisonDataReg << 21));
|
||||
*(int *)(cur + 0x18) = (0x28000080 | (comparisonDataReg << 16));
|
||||
*(int *)(cur + 0x1c) = 0x41810070;
|
||||
*(int *)(cur + 0x24) = *(int *)(cur + 0x28);
|
||||
*(int *)(cur + 0x28) = (0x8001000c | (loadedDataReg << 21));
|
||||
*(int *)(cur + 0x2c) = (0x3C005A00 | (comparisonDataReg << 21));
|
||||
*(int *)(cur + 0x34) = (0x7c000000 | (comparisonDataReg << 16) | (loadedDataReg << 11));
|
||||
*(int *)(cur + 0x48) = 0x60000000;
|
||||
successful_patch_p2p++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (found_opcode_chain_MASTER)
|
||||
{
|
||||
if (
|
||||
GetImmediateDataVal((unsigned int *)(MASTERopcodeChainOffset + 0x10)) == 0x12 &&
|
||||
GetImmediateDataVal((unsigned int *)(MASTERopcodeChainOffset + 0x2c)) == 0x04 &&
|
||||
|
||||
GetImmediateDataVal((unsigned int *)(MASTERopcodeChainOffset + 0x48)) == 0x18 &&
|
||||
GetImmediateDataVal((unsigned int *)(MASTERopcodeChainOffset + 0x50)) == 0x00 &&
|
||||
GetImmediateDataVal((unsigned int *)(MASTERopcodeChainOffset + 0x54)) == 0x18
|
||||
)
|
||||
{
|
||||
int master_patch_version = 0;
|
||||
|
||||
// Check which version we have:
|
||||
if (
|
||||
GetImmediateDataVal((unsigned int *)(MASTERopcodeChainOffset + 0x3c)) == 0x12 &&
|
||||
GetImmediateDataVal((unsigned int *)(MASTERopcodeChainOffset + 0x44)) == 0x0c
|
||||
)
|
||||
master_patch_version = 1;
|
||||
|
||||
else if (
|
||||
GetImmediateDataVal((unsigned int *)(MASTERopcodeChainOffset + 0x3c)) == 0x0c &&
|
||||
GetImmediateDataVal((unsigned int *)(MASTERopcodeChainOffset + 0x44)) == 0x12
|
||||
)
|
||||
master_patch_version = 2;
|
||||
|
||||
if (master_patch_version == 2)
|
||||
{
|
||||
// Different opcode order...
|
||||
*(int *)(MASTERopcodeChainOffset + 0x3c) = *(int *)(MASTERopcodeChainOffset + 0x44);
|
||||
}
|
||||
|
||||
if (master_patch_version != 0)
|
||||
{
|
||||
int rY = GetComparisonTargetReg((unsigned int *)MASTERopcodeChainOffset);
|
||||
int rX = GetLoadTargetReg((unsigned int *)MASTERopcodeChainOffset);
|
||||
|
||||
*(int *)(MASTERopcodeChainOffset + 0x00) = 0x38000004 | (rX << 21);
|
||||
*(int *)(MASTERopcodeChainOffset + 0x04) = 0x7c00042c | (rY << 21) | (3 << 16) | (rX << 11);
|
||||
*(int *)(MASTERopcodeChainOffset + 0x14) = 0x9000000c | (rY << 21) | (1 << 16);
|
||||
*(int *)(MASTERopcodeChainOffset + 0x18) = 0x88000011 | (rY << 21) | (1 << 16);
|
||||
*(int *)(MASTERopcodeChainOffset + 0x28) = 0x28000080 | (rY << 16);
|
||||
*(int *)(MASTERopcodeChainOffset + 0x38) = 0x60000000;
|
||||
*(int *)(MASTERopcodeChainOffset + 0x44) = 0x41810014;
|
||||
successful_patch_master++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} while (++cur < end);
|
||||
|
||||
if (hasGT2Error)
|
||||
{
|
||||
if (successful_patch_master == 0 || successful_patch_p2p == 0)
|
||||
return 2;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
s8 do_new_wiimmfi()
|
||||
{
|
||||
|
||||
// As of November 2018, Wiimmfi requires a special Wiimmfi patcher
|
||||
// update which does a bit more than just patch the server adresses.
|
||||
// update which does a bit more than just patch the server addresses.
|
||||
// This function is being called by GameBooter.cpp, right before
|
||||
// jumping to the entry point (only for Mario Kart Wii & Wiimmfi),
|
||||
// and applies all the necessary new patches to the game.
|
||||
@ -258,42 +497,51 @@ s8 do_new_wiimmfi()
|
||||
// try to modify it without speaking to the Wiimmfi team because
|
||||
// doing so could have unintended side effects.
|
||||
|
||||
// Updated in 2021 to add the 51420 error fix.
|
||||
|
||||
// check region:
|
||||
char region = *((char *)(0x80000003));
|
||||
char *patched;
|
||||
void *patch1_offset, *patch2_offset, *patch3_offset;
|
||||
void *errorfix_offset;
|
||||
|
||||
// define some offsets and variables depending on the region:
|
||||
switch (region) {
|
||||
switch (region)
|
||||
{
|
||||
case 'P':
|
||||
patched = (char *)0x80276054;
|
||||
patch1_offset = (void *)0x800ee3a0;
|
||||
patch2_offset = (void *)0x801d4efc;
|
||||
patch3_offset = (void *)0x801A72E0;
|
||||
errorfix_offset = (void *)0x80658ce4;
|
||||
break;
|
||||
case 'E':
|
||||
patched = (char *)0x80271d14;
|
||||
patch1_offset = (void *)0x800ee300;
|
||||
patch2_offset = (void *)0x801d4e5c;
|
||||
patch3_offset = (void *)0x801A7240;
|
||||
errorfix_offset = (void *)0x8065485c;
|
||||
break;
|
||||
case 'J':
|
||||
patched = (char *)0x802759f4;
|
||||
patch1_offset = (void *)0x800ee2c0;
|
||||
patch2_offset = (void *)0x801d4e1c;
|
||||
patch3_offset = (void *)0x801A7200;
|
||||
errorfix_offset = (void *)0x80658360;
|
||||
break;
|
||||
case 'K':
|
||||
patched = (char *)0x80263E34;
|
||||
patch1_offset = (void *)0x800ee418;
|
||||
patch2_offset = (void *)0x801d5258;
|
||||
patch3_offset = (void *)0x801A763c;
|
||||
errorfix_offset = (void *)0x80646ffc;
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (*patched != '*') return -2; // ISO already patched
|
||||
if (*patched != '*')
|
||||
return -2; // ISO already patched
|
||||
|
||||
// This RAM address is set (no asterisk) by all officially
|
||||
// updated patchers, so if it is modified, the image is already
|
||||
@ -318,9 +566,9 @@ s8 do_new_wiimmfi()
|
||||
char newURL3J[] = "https://main.nas.wiimmfi.de/pj";
|
||||
char newURL3K[] = "https://main.nas.wiimmfi.de/pk";
|
||||
|
||||
|
||||
// Write the URLs to the proper place and do some other patching.
|
||||
switch (region) {
|
||||
switch (region)
|
||||
{
|
||||
case 'P':
|
||||
memcpy((void *)0x8027A400, newURL1, sizeof(newURL1));
|
||||
memcpy((void *)0x8027A400 + 0x28, newURL2, sizeof(newURL2));
|
||||
@ -351,16 +599,16 @@ s8 do_new_wiimmfi()
|
||||
break;
|
||||
}
|
||||
|
||||
// Make some space on heap (0x400) for our custom code.
|
||||
// Make some space on heap (0x500) for our custom code.
|
||||
u32 old_heap_ptr = *(u32 *)0x80003110;
|
||||
*((u32*)0x80003110) = (old_heap_ptr - 0x400);
|
||||
u32 heap_space = old_heap_ptr-0x400;
|
||||
memset((void*)old_heap_ptr-0x400, 0xed, 0x400);
|
||||
*((u32 *)0x80003110) = (old_heap_ptr - 0x500);
|
||||
u32 heap_space = old_heap_ptr - 0x500;
|
||||
memset((void *)old_heap_ptr - 0x500, 0xed, 0x500);
|
||||
|
||||
// Binary blobs with Wiimmfi patches. Do not modify.
|
||||
// Provided by Leseratte on 2018-12-14.
|
||||
|
||||
u32 binary[] = { 0x37C849A2, 0x8BC32FA4, 0xC9A34B71, 0x1BCB49A2,
|
||||
u32 binary[] = {
|
||||
0x37C849A2, 0x8BC32FA4, 0xC9A34B71, 0x1BCB49A2,
|
||||
0x2F119304, 0x5F402684, 0x3E4FDA29, 0x50849A21,
|
||||
0xB88B3452, 0x627FC9C1, 0xDC24D119, 0x5844350F,
|
||||
0xD893444F, 0x19A588DC, 0x16C91184, 0x0C3E237C,
|
||||
@ -413,18 +661,38 @@ s8 do_new_wiimmfi()
|
||||
0x92F26CF2, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000};
|
||||
|
||||
// Prepare patching process ....
|
||||
// Fix for error 51420:
|
||||
int patchCodeFix51420[] = {
|
||||
0x4800000d, 0x00000000,
|
||||
0x00000000, 0x7cc803a6,
|
||||
0x80860000, 0x7c041800,
|
||||
0x4182004c, 0x80a60004,
|
||||
0x38a50001, 0x2c050003,
|
||||
0x4182003c, 0x90a60004,
|
||||
0x90660000, 0x38610010,
|
||||
0x3ca08066, 0x38a58418,
|
||||
0x3c808066, 0x38848498,
|
||||
0x90a10010, 0x90810014,
|
||||
0x3ce08066, 0x38e78ce4,
|
||||
0x38e7fef0, 0x7ce903a6,
|
||||
0x4e800420, 0x3c80801d,
|
||||
0x388415f4, 0x7c8803a6,
|
||||
0x4e800021, 0x00000000};
|
||||
|
||||
// Prepare patching process...
|
||||
int i = 3;
|
||||
int idx = 0;
|
||||
for (; i < 202; i++) {
|
||||
if (i == 67 || i == 82) idx++;
|
||||
for (; i < 202; i++)
|
||||
{
|
||||
if (i == 67 || i == 82)
|
||||
idx++;
|
||||
binary[i] = binary[i] ^ binary[idx];
|
||||
binary[idx] = ((binary[idx] << 1) | ((binary[idx] >> (32 - 1)) & ~(0xfffffffe)));
|
||||
}
|
||||
|
||||
|
||||
// Binary blob needs some changes for regions other than PAL...
|
||||
switch (region) {
|
||||
switch (region)
|
||||
{
|
||||
case 'E':
|
||||
binary[29] = binary[67];
|
||||
binary[37] = binary[68];
|
||||
@ -432,6 +700,13 @@ s8 do_new_wiimmfi()
|
||||
binary[185] = 0x61295C74;
|
||||
binary[189] = 0x61295D40;
|
||||
binary[198] = 0x61086F5C;
|
||||
patchCodeFix51420[14] = 0x3ca08065;
|
||||
patchCodeFix51420[15] = 0x38a53f90;
|
||||
patchCodeFix51420[16] = 0x3c808065;
|
||||
patchCodeFix51420[17] = 0x38844010;
|
||||
patchCodeFix51420[20] = 0x3ce08065;
|
||||
patchCodeFix51420[21] = 0x38e7485c;
|
||||
patchCodeFix51420[26] = 0x38841554;
|
||||
break;
|
||||
case 'J':
|
||||
binary[29] = binary[70];
|
||||
@ -440,6 +715,13 @@ s8 do_new_wiimmfi()
|
||||
binary[185] = 0x612997CC;
|
||||
binary[189] = 0x61299898;
|
||||
binary[198] = 0x61086F1C;
|
||||
patchCodeFix51420[14] = 0x3ca08065;
|
||||
patchCodeFix51420[15] = 0x38a57a84;
|
||||
patchCodeFix51420[16] = 0x3c808065;
|
||||
patchCodeFix51420[17] = 0x38847b04;
|
||||
patchCodeFix51420[20] = 0x3ce08065;
|
||||
patchCodeFix51420[21] = 0x38e78350;
|
||||
patchCodeFix51420[26] = 0x38841514;
|
||||
break;
|
||||
case 'K':
|
||||
binary[6] = binary[73];
|
||||
@ -456,12 +738,17 @@ s8 do_new_wiimmfi()
|
||||
binary[188] = 0x3D208088;
|
||||
binary[189] = 0x61298B58;
|
||||
binary[198] = 0x61087358;
|
||||
patchCodeFix51420[14] = 0x3ca08064;
|
||||
patchCodeFix51420[15] = 0x38a56730;
|
||||
patchCodeFix51420[16] = 0x3c808064;
|
||||
patchCodeFix51420[17] = 0x388467b0;
|
||||
patchCodeFix51420[20] = 0x3ce08064;
|
||||
patchCodeFix51420[21] = 0x38e76ffc;
|
||||
patchCodeFix51420[26] = 0x38841950;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
// Installing all the patches.
|
||||
|
||||
memcpy((void *)heap_space, (void *)binary, 820);
|
||||
u32 code_offset_1 = heap_space + 12;
|
||||
u32 code_offset_2 = heap_space + 88;
|
||||
@ -469,13 +756,17 @@ s8 do_new_wiimmfi()
|
||||
u32 code_offset_4 = heap_space + 264;
|
||||
u32 code_offset_5 = heap_space + 328;
|
||||
|
||||
|
||||
*((u32 *)patch1_offset) = 0x48000000 + (((u32)(code_offset_1) - ((u32)(patch1_offset))) & 0x3ffffff);
|
||||
*((u32 *)code_offset_2) = 0x48000000 + (((u32)(patch1_offset + 4) - ((u32)(code_offset_2))) & 0x3ffffff);
|
||||
*((u32 *)patch2_offset) = 0x48000000 + (((u32)(code_offset_3) - ((u32)(patch2_offset))) & 0x3ffffff);
|
||||
*((u32 *)code_offset_4) = 0x48000000 + (((u32)(patch2_offset + 4) - ((u32)(code_offset_4))) & 0x3ffffff);
|
||||
*((u32 *)patch3_offset) = 0x48000000 + (((u32)(code_offset_5) - ((u32)(patch3_offset))) & 0x3ffffff);
|
||||
|
||||
// Add the 51420 fix:
|
||||
memcpy((void *)heap_space + 0x400, (void *)patchCodeFix51420, 0x78);
|
||||
*((u32 *)errorfix_offset) = 0x48000000 + (((u32)(heap_space + 0x400) - ((u32)(errorfix_offset))) & 0x3ffffff);
|
||||
*((u32 *)heap_space + 0x400 + 0x74) = 0x48000000 + (((u32)(errorfix_offset + 4) - ((u32)(heap_space + 0x400 + 0x74))) & 0x3ffffff);
|
||||
|
||||
// Patches successfully installed
|
||||
// returns 0 when all patching is done and game is ready to be booted.
|
||||
return 0;
|
||||
@ -523,7 +814,6 @@ bool NSMBPatch()
|
||||
CodeList[2].offset = 0x001CED6B;
|
||||
CodeList[2].srcaddress = 0xDA000000;
|
||||
CodeList[2].dstaddress = 0x71000000;
|
||||
|
||||
}
|
||||
else if (memcmp("SMNP01", (char *)0x80000000, 6) == 0)
|
||||
{
|
||||
@ -565,7 +855,6 @@ bool NSMBPatch()
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return CodeList != NULL;
|
||||
}
|
||||
|
||||
@ -670,7 +959,6 @@ static GXRModeObj TVPal528ProgSoft = {
|
||||
8, // line n+1
|
||||
8 // line n+1
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
static GXRModeObj TVPal524ProgAa = {
|
||||
@ -704,7 +992,6 @@ static GXRModeObj TVPal524ProgAa = {
|
||||
8, // line n+1
|
||||
4 // line n+1
|
||||
}
|
||||
|
||||
};
|
||||
#endif
|
||||
|
||||
@ -740,8 +1027,7 @@ static GXRModeObj* vmodes[] = {
|
||||
&TVEurgb60Hz480IntAa,
|
||||
&TVEurgb60Hz480Prog,
|
||||
&TVEurgb60Hz480ProgSoft,
|
||||
&TVEurgb60Hz480ProgAa
|
||||
};
|
||||
&TVEurgb60Hz480ProgAa};
|
||||
|
||||
static const char *vmodes_name[] = {
|
||||
"TVNtsc240Ds",
|
||||
@ -775,8 +1061,7 @@ static const char * vmodes_name[] = {
|
||||
"TVEurgb60Hz480IntAa",
|
||||
"TVEurgb60Hz480Prog",
|
||||
"TVEurgb60Hz480ProgSoft",
|
||||
"TVEurgb60Hz480ProgAa"
|
||||
};
|
||||
"TVEurgb60Hz480ProgAa"};
|
||||
|
||||
static GXRModeObj *PAL2NTSC[] = {
|
||||
&TVMpal480IntDf, &TVNtsc480IntDf,
|
||||
@ -799,8 +1084,7 @@ static GXRModeObj* PAL2NTSC[] = {
|
||||
&TVEurgb60Hz480Prog, &TVNtsc480Prog,
|
||||
&TVEurgb60Hz480ProgSoft, &TVNtsc480Prog,
|
||||
&TVEurgb60Hz480ProgAa, &TVNtsc480Prog,
|
||||
0, 0
|
||||
};
|
||||
0, 0};
|
||||
|
||||
static GXRModeObj *NTSC2PAL[] = {
|
||||
&TVNtsc240Ds, &TVPal264Ds,
|
||||
@ -811,8 +1095,7 @@ static GXRModeObj* NTSC2PAL[] = {
|
||||
&TVNtsc480IntDf, &TVPal528IntDf,
|
||||
&TVNtsc480IntAa, &TVPal524IntAa,
|
||||
&TVNtsc480Prog, &TVPal528Prog,
|
||||
0, 0
|
||||
};
|
||||
0, 0};
|
||||
|
||||
static GXRModeObj *NTSC2PAL60[] = {
|
||||
&TVNtsc240Ds, &TVEurgb60Hz240Ds,
|
||||
@ -823,8 +1106,7 @@ static GXRModeObj* NTSC2PAL60[] = {
|
||||
&TVNtsc480IntDf, &TVEurgb60Hz480IntDf,
|
||||
&TVNtsc480IntAa, &TVEurgb60Hz480IntAa,
|
||||
&TVNtsc480Prog, &TVEurgb60Hz480Prog,
|
||||
0, 0
|
||||
};
|
||||
0, 0};
|
||||
|
||||
static bool compare_videomodes(GXRModeObj *mode1, GXRModeObj *mode2)
|
||||
{
|
||||
@ -958,7 +1240,6 @@ static bool Search_and_patch_Video_To(void *Address, u32 Size, GXRModeObj* Table
|
||||
u8 *Addr = (u8 *)Address;
|
||||
bool found = 0;
|
||||
u32 i;
|
||||
|
||||
u8 target_vmode = 0;
|
||||
for (i = 0; i < sizeof(vmodes) / sizeof(vmodes[0]); i++)
|
||||
{
|
||||
@ -1001,7 +1282,6 @@ static bool Search_and_patch_Video_To(void *Address, u32 Size, GXRModeObj* Table
|
||||
Size -= (sizeof(GXRModeObj) - 4);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
if (patchAll && !found)
|
||||
{
|
||||
@ -1124,9 +1404,12 @@ bool PatchReturnTo( void *Address, int Size, u32 id )
|
||||
}
|
||||
else if (ad[0] && memcmp(Addr, SearchPattern, 8) == 0) // after the first match is found, only search the first 8 bytes for the other 2
|
||||
{
|
||||
if( !ad[ 1 ] ) ad[ found++ ] = (u32)Addr;
|
||||
else if( !ad[ 2 ] ) ad[ found++ ] = (u32)Addr;
|
||||
if( found >= 3 )break;
|
||||
if (!ad[1])
|
||||
ad[found++] = (u32)Addr;
|
||||
else if (!ad[2])
|
||||
ad[found++] = (u32)Addr;
|
||||
if (found >= 3)
|
||||
break;
|
||||
}
|
||||
Addr += 4;
|
||||
}
|
||||
@ -1149,9 +1432,12 @@ bool PatchReturnTo( void *Address, int Size, u32 id )
|
||||
}
|
||||
else if (ad[0] && memcmp(Addr, SearchPatternB, 8) == 0) // after the first match is found, only search the first 8 bytes for the other 2
|
||||
{
|
||||
if( !ad[ 1 ] ) ad[ found++ ] = (u32)Addr;
|
||||
else if( !ad[ 2 ] ) ad[ found++ ] = (u32)Addr;
|
||||
if( found >= 3 )break;
|
||||
if (!ad[1])
|
||||
ad[found++] = (u32)Addr;
|
||||
else if (!ad[2])
|
||||
ad[found++] = (u32)Addr;
|
||||
if (found >= 3)
|
||||
break;
|
||||
}
|
||||
Addr += 4;
|
||||
}
|
||||
@ -1164,12 +1450,12 @@ bool PatchReturnTo( void *Address, int Size, u32 id )
|
||||
u32 nop = 0x60000000;
|
||||
|
||||
// the magic that writes the TID to the registers
|
||||
u8 jump[ 20 ] = { 0x3C, 0x60, 0x00, 0x01, //lis r3,1
|
||||
u8 jump[20] = {
|
||||
0x3C, 0x60, 0x00, 0x01, // lis r3,1
|
||||
0x60, 0x63, 0x00, 0x01, // ori r3,r3,1
|
||||
0x3C, 0x80, (u8)(id >> 24), (u8)(id >> 16), // lis r4,(u16)(tid >> 16)
|
||||
0x60, 0x84, (u8)(id >> 8), (u8)id, // ori r4,r4,(u16)(tid)
|
||||
0x4E, 0x80, 0x00, 0x20
|
||||
}; //blr
|
||||
0x4E, 0x80, 0x00, 0x20}; // blr
|
||||
|
||||
if (oldSDK)
|
||||
{
|
||||
@ -1280,29 +1566,26 @@ int BlockIOSReload(int es_fd, u8 gameIOS)
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void PatchAspectRatio(void *addr, u32 len, u8 aspect)
|
||||
{
|
||||
if (aspect > 1)
|
||||
return;
|
||||
|
||||
static const u32 aspect_searchpattern1[5] = {
|
||||
0x9421FFF0, 0x7C0802A6, 0x38800001, 0x90010014, 0x38610008
|
||||
};
|
||||
0x9421FFF0, 0x7C0802A6, 0x38800001, 0x90010014, 0x38610008};
|
||||
|
||||
static const u32 aspect_searchpattern2[15] = {
|
||||
0x2C030000, 0x40820010, 0x38000000, 0x98010008, 0x48000018,
|
||||
0x88010008, 0x28000001, 0x4182000C, 0x38000000, 0x98010008,
|
||||
0x80010014, 0x88610008, 0x7C0803A6, 0x38210010, 0x4E800020
|
||||
};
|
||||
0x80010014, 0x88610008, 0x7C0803A6, 0x38210010, 0x4E800020};
|
||||
|
||||
u8 *addr_start = (u8 *)addr;
|
||||
u8 *addr_end = addr_start + len - sizeof(aspect_searchpattern1) - 4 - sizeof(aspect_searchpattern2);
|
||||
|
||||
while (addr_start < addr_end)
|
||||
{
|
||||
if( (memcmp(addr_start, aspect_searchpattern1, sizeof(aspect_searchpattern1)) == 0)
|
||||
&& (memcmp(addr_start + 4 + sizeof(aspect_searchpattern1), aspect_searchpattern2, sizeof(aspect_searchpattern2)) == 0))
|
||||
if ((memcmp(addr_start, aspect_searchpattern1, sizeof(aspect_searchpattern1)) == 0) &&
|
||||
(memcmp(addr_start + 4 + sizeof(aspect_searchpattern1), aspect_searchpattern2, sizeof(aspect_searchpattern2)) == 0))
|
||||
{
|
||||
*((u32 *)(addr_start + 0x44)) = (0x38600000 | aspect);
|
||||
gprintf("Aspect ratio patched to: %s\n", aspect ? "16:9" : "4:3");
|
||||
|
@ -15,6 +15,7 @@ bool Anti_002_fix(u8 * Address, int Size);
|
||||
void PrivateServerPatcher(void *addr, u32 len, u8 privateServer, const char *serverAddr);
|
||||
void PatchFix480p();
|
||||
s8 do_new_wiimmfi();
|
||||
s8 do_new_wiimmfi_nonMKWii(void *addr, u32 len);
|
||||
void domainpatcher(void *addr, u32 len, const char *domain);
|
||||
bool NSMBPatch();
|
||||
bool PoPPatch();
|
||||
|
Loading…
Reference in New Issue
Block a user