Skip to content

Commit

Permalink
- PSO 1 & 2+ support
Browse files Browse the repository at this point in the history
  • Loading branch information
emukidid committed May 25, 2018
1 parent f185467 commit 0e07a6b
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 2 deletions.
5 changes: 3 additions & 2 deletions cube/swiss/source/gcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -348,12 +348,13 @@ int patch_gcm(file_handle *file, ExecutableFile *filesToPatch, int numToPatch, i

char patchDirName[256];
char patchBaseDirName[256];
char gameID[8];
memset(&gameID, 0, 8);
char gameID[16];
memset(&gameID, 0, 16);
memset(&patchDirName, 0, 256);
memset(&patchBaseDirName, 0, 256);
strncpy((char*)&gameID, (char*)&GCMDisk, 4);
sprintf(&patchDirName[0],"%sswiss_patches/%s",devices[DEVICE_PATCHES]->initial->name, &gameID[0]);
memcpy((char*)&gameID, (char*)&GCMDisk, 12);
sprintf(&patchBaseDirName[0],"%sswiss_patches",devices[DEVICE_PATCHES]->initial->name);
print_gecko("Patch dir will be: %s if required\r\n", patchDirName);
*(vu32*)VAR_EXECD_OFFSET = 0xFFFFFFFF;
Expand Down
67 changes: 67 additions & 0 deletions cube/swiss/source/patcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,56 @@ int PatchDetectLowMemUsage( u8 *dst, u32 Length, int dataType )
return LowMemPatched;
}

// HACK: PSO 0x80001800 move to 0x817F1800
u32 PatchPatchBuffer(char *dst)
{
int i;
int patched = 0;
u32 LISReg = -1;
u32 LISOff = -1;

for (i = 0;; i += 4)
{
u32 op = *(vu32*)(dst + i);

if ((op & 0xFC1FFFFF) == 0x3C008000) // lis rX, 0x8000
{
LISReg = (op & 0x3E00000) >> 21;
LISOff = (u32)dst + i;
}

if ((op & 0xFC000000) == 0x38000000) // li rX, x
{
u32 src = (op >> 16) & 0x1F;
u32 dst = (op >> 21) & 0x1F;
if ((src != LISReg) && (dst == LISReg))
{
LISReg = -1;
LISOff = (u32)dst + i;
}
}

if ((op & 0xFC00FFFF) == 0x38001800) // addi rX, rY, 0x1800 (patch buffer)
{
u32 src = (op >> 16) & 0x1F;
if (src == LISReg)
{
*(vu32*)(LISOff) = (LISReg << 21) | 0x3C00817F;
print_gecko("Patch:[%08X] %08X: lis r%u, 0x817F\r\n", (u32)LISOff, *(u32*)LISOff, LISReg );
LISReg = -1;
patched++;
}
u32 dst = (op >> 21) & 0x1F;
if (dst == LISReg)
LISReg = -1;
}
if (op == 0x4E800020) // blr
break;
}
return patched;
}



u32 Patch_DVDLowLevelReadForWKF(void *addr, u32 length, int dataType) {
int i = 0;
Expand Down Expand Up @@ -1842,6 +1892,23 @@ int Patch_GameSpecific(void *addr, u32 length, const char* gameID, int dataType)
addr_start += 4;
}
}
else if((*(u32*)&gameID[0] == 0x47504F45)
&& (*(u32*)&gameID[4] == 0x38500002)
&& (*(u32*)&gameID[8] == 0x01000000)) {
// Nasty PSO 1 & 2+ hack to redirect a lowmem buffer to highmem
void *addr_start = addr;
void *addr_end = addr+length;
while(addr_start<addr_end)
{
addr_start += 4;
if( *(vu32*)(addr_start) != 0x7C0802A6 )
continue;
if(PatchPatchBuffer(addr_start)) {
print_gecko("Patched: PSO 1 & 2 +\r\n");
patched=1;
}
}
}
else if(!strncmp(gameID, "GXX", 3) || !strncmp(gameID, "GC6", 3))
{
print_gecko("Patched:[Pokemon memset]\r\n");
Expand Down
7 changes: 7 additions & 0 deletions cube/swiss/source/swiss.c
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,13 @@ unsigned int load_app(int multiDol, ExecutableFile *filesToPatch)
if(swissSettings.wiirdDebug || getEnabledCheatsSize() > 0) {
top_of_main_ram = WIIRD_ENGINE;
}
if((*(u32*)0x80000000 == 0x47504F45)
&& (*(u32*)0x80000004 == 0x38500002)
&& (*(u32*)0x80000008 == 0x01000000)) {
// Nasty PSO 1 & 2+ hack to redirect a lowmem buffer to highmem
top_of_main_ram = 0x817F1800;
print_gecko("PSO 1 & 2+ hack enabled\r\n");
}

print_gecko("Top of RAM simulated as: 0x%08X\r\n", top_of_main_ram);

Expand Down

0 comments on commit 0e07a6b

Please sign in to comment.