Patching real-time clock issues in old games?
I've been working to diagnose an issue with an old game (mid 90s) that does not run properly on modern hardware. The issue arises when using a CPU clocked above 4.2Ghz which causes unsigned integers to roll over. The function they use in their code to call the system's real-time clock DOES return a 64-bit integer but then elsewhere in the code they do brilliant things like this:
There are hundreds of calls to the clock function which use the wrong type so I don't see it being possible to patch these data types. But would it be possible instead to patch the code to divide the clock by some number so that it will fit into a signed 32-bit integer?
I've dealt with modifying code by altering or NOPing instructions but this here looks as though I'll need to add new instructions; something I've not done before. Is this possible?
This is what I have to work with:
Thanks.
Code:
int64 clock(); int old = clock(); .. (unsigned int)clock() - old <= something
I've dealt with modifying code by altering or NOPing instructions but this here looks as though I'll need to add new instructions; something I've not done before. Is this possible?
This is what I have to work with:
Code:
push ebp mov ebp,esp push ecx push ecx and dword ptr [ebp-08h],00000000h and dword ptr [ebp-04h],00000000h push esi rdtsc mov [ebp-08h],eax mov [ebp-04h],edx mov ecx,[ebp-08h] mov edx,[ebp-04h] xor eax,eax xor esi,esi or eax,ecx or edx,esi sub eax,[L00988C60] pop esi sbb edx,[L00988C64] leave retn