// Returns 1 if patch added, 2 if already present, and 0 if code cannot be found (unsupported firmware) int FixTimerAPI() { dword *fw = (dword*)0x80000000; if(PatchIsInstalled(fw, "Ta")) return 2; else { // TAP_Timer_Modify @ 80002560, copy @+0 to @+5, @+12 ($gp restore), copy @+12 to @+1 (3c0ffffe) dword* codeSeg = (void*)FindInstructionSequence( "02a0e025 33deffff 3418fffe 53d80005 97999fd4 33deffff 3c19ffff 10000023 03d91021 97989fd6 0019ca00 0338c821 3c0ffffe 1000001d 032f1021", "00000000 ffffffff ffffffff ffffffff ffff0000 00000000 ffffffff ffffff00 ffffffff ffff0000 ffffffff ffffffff 00000000 ffffff00 ffffffff", 0x80170000, 0x80230000, 0, FALSE); dword setT7 = 0x3c0ffffe; if(!codeSeg) // Not found, unsupported firmware return 0; else if(codeSeg[0] == setT7 && codeSeg[5] == codeSeg[12]) // Already patched (no ID?) return 2; else if(codeSeg[12] == setT7) // Not patched, so do patching { codeSeg[5] = codeSeg[0]; codeSeg[12] = codeSeg[0]; codeSeg[0] = setT7; PatchInstallID(fw, "Ta"); return 1; } else return 0; // Unknown state } }