Skip to content

Commit

Permalink
- Trigger IGR on game crash.
Browse files Browse the repository at this point in the history
  • Loading branch information
Extrems committed Mar 11, 2020
1 parent 67b70a5 commit 4a99a1f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
4 changes: 2 additions & 2 deletions cube/patches/base/exi.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ typedef struct {
} queue[EXI_DEVICE_MAX];
} EXIControl;

s32 (*EXILock)(s32 chan, u32 dev, EXICallback unlockedCallback);
s32 (*EXIUnlock)(s32 chan);
extern s32 (*EXILock)(s32 chan, u32 dev, EXICallback unlockedCallback);
extern s32 (*EXIUnlock)(s32 chan);

#endif /* EXI_H */
8 changes: 4 additions & 4 deletions cube/patches/base/os.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ static OSExceptionHandler OSGetExceptionHandler(OSException exception)
return OSExceptionHandlerTable[exception];
}

void (*OSUnhandledException)(OSException exception, OSContext *context, u32 dsisr, u32 dar);
extern void (*OSUnhandledException)(OSException exception, OSContext *context, u32 dsisr, u32 dar);

typedef enum {
OS_INTERRUPT_MEM_0 = 0,
Expand Down Expand Up @@ -247,13 +247,13 @@ static OSInterruptHandler OSGetInterruptHandler(OSInterrupt interrupt)
return OSInterruptHandlerTable[interrupt];
}

OSInterruptMask (*OSMaskInterrupts)(OSInterruptMask mask);
OSInterruptMask (*OSUnmaskInterrupts)(OSInterruptMask mask);
extern OSInterruptMask (*OSMaskInterrupts)(OSInterruptMask mask);
extern OSInterruptMask (*OSUnmaskInterrupts)(OSInterruptMask mask);

#define OS_RESET_RESTART 0
#define OS_RESET_HOTRESET 1
#define OS_RESET_SHUTDOWN 2

void (*OSResetSystem)(s32 reset, u32 resetCode, s32 forceMenu);
extern void (*OSResetSystem)(s32 reset, u32 resetCode, s32 forceMenu);

#endif /* OS_H */
26 changes: 25 additions & 1 deletion cube/swiss/source/patcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,14 @@ int PatchDetectLowMemUsage( void *dst, u32 Length, int dataType )
return LowMemPatched;
}

u32 _ppchalt[] = {
0x7C0004AC, // sync
0x60000000, // nop
0x38600000, // li r3, 0
0x60000000, // nop
0x4BFFFFF4 // b -3
};

u32 _dvdgettransferredsize[] = {
0x8003000C, // lwz r0, 12 (r3)
0x2C000002, // cmpwi r0, 2
Expand Down Expand Up @@ -703,6 +711,8 @@ int Patch_DVDLowLevelReadAlt(u32 *data, u32 length, const char *gameID, int data
int patched = 0;
FuncPattern PrepareExecSig =
{ 60, 15, 3, 16, 13, 2, NULL, 0, "PrepareExec" };
FuncPattern PPCHaltSig =
{ 5, 1, 0, 0, 1, 1, NULL, 0, "PPCHalt" };
FuncPattern OSExceptionInitSigs[3] = {
{ 164, 61, 6, 18, 14, 14, NULL, 0, "OSExceptionInitD" },
{ 160, 39, 14, 14, 20, 7, NULL, 0, "OSExceptionInit" },
Expand Down Expand Up @@ -1218,7 +1228,9 @@ int Patch_DVDLowLevelReadAlt(u32 *data, u32 length, const char *gameID, int data
continue;
}
else if (data[i + 0] != 0x7C0802A6 && data[i + 1] != 0x7C0802A6) {
if (!memcmp(data + i, _dvdgettransferredsize, sizeof(_dvdgettransferredsize)))
if (!memcmp(data + i, _ppchalt, sizeof(_ppchalt)))
PPCHaltSig.offsetFoundAt = i;
else if (!memcmp(data + i, _dvdgettransferredsize, sizeof(_dvdgettransferredsize)))
DVDGetTransferredSizeSig.offsetFoundAt = i;
else if (!memcmp(data + i, _gxpeekz_a, sizeof(_gxpeekz_a)))
GXPeekZSigs[0].offsetFoundAt = i;
Expand Down Expand Up @@ -3099,6 +3111,18 @@ int Patch_DVDLowLevelReadAlt(u32 *data, u32 length, const char *gameID, int data
print_gecko("Found:[%s] @ %08X\n", __OSDoHotResetSigs[j].Name, __OSDoHotReset);
patched++;
}

if ((i = PPCHaltSig.offsetFoundAt)) {
u32 *PPCHalt = Calc_ProperAddress(data, dataType, i * sizeof(u32));

if (PPCHalt && __OSDoHotReset) {
if (swissSettings.igrType != IGR_OFF)
data[i + 4] = branch(__OSDoHotReset, PPCHalt + 4);

print_gecko("Found:[%s] @ %08X\n", PPCHaltSig.Name, PPCHalt);
patched++;
}
}
}

for (j = 0; j < sizeof(OSResetSystemSigs) / sizeof(FuncPattern); j++)
Expand Down

0 comments on commit 4a99a1f

Please sign in to comment.