More stable framelimiter - III

This commit is contained in:
Silent 2015-06-29 01:08:05 +02:00
parent 4d459e0ad4
commit 3b98e5abaf

View file

@ -234,6 +234,21 @@ char* GetMyDocumentsPath()
return cUserFilesPath;
}
static LARGE_INTEGER FrameTime;
DWORD GetTimeSinceLastFrame()
{
LARGE_INTEGER curTime;
QueryPerformanceCounter(&curTime);
return curTime.QuadPart - FrameTime.QuadPart;
}
static void (*RsEventHandler)(int, void*);
void NewFrameRender(int nEvent, void* pParam)
{
QueryPerformanceCounter(&FrameTime);
RsEventHandler(nEvent, pParam);
}
static char aNoDesktopMode[64];
void Patch_III_10(const RECT& desktop)
@ -350,6 +365,12 @@ void Patch_III_10(const RECT& desktop)
// BOOOOORING fixed
Patch<BYTE>(0x4925D7, 10);
// (Hopefully) more precise frame limiter
int pAddress = 0x582EFD;
RsEventHandler = (void(*)(int,void*))(*(int*)(pAddress+1) + pAddress + 5);
InjectHook(pAddress, NewFrameRender);
InjectHook(0x582EA4, GetTimeSinceLastFrame);
// Default to desktop res
Patch<DWORD>(0x581E5E, desktop.right);
Patch<DWORD>(0x581E68, desktop.bottom);
@ -475,6 +496,12 @@ void Patch_III_11(const RECT& desktop)
OldWndProc = *(LRESULT (CALLBACK***)(HWND, UINT, WPARAM, LPARAM))0x581FB4;
Patch(0x581FB4, &pCustomWndProc);
// (Hopefully) more precise frame limiter
int pAddress = 0x58323D;
RsEventHandler = (void(*)(int,void*))(*(int*)(pAddress+1) + pAddress + 5);
InjectHook(pAddress, NewFrameRender);
InjectHook(0x5831E4, GetTimeSinceLastFrame);
// Default to desktop res
Patch<DWORD>(0x58219E, desktop.right);
Patch<DWORD>(0x5821A8, desktop.bottom);
@ -596,6 +623,12 @@ void Patch_III_Steam(const RECT& desktop)
OldWndProc = *(LRESULT (CALLBACK***)(HWND, UINT, WPARAM, LPARAM))0x581EA4;
Patch(0x581EA4, &pCustomWndProc);
// (Hopefully) more precise frame limiter
int pAddress = 0x58312D;
RsEventHandler = (void(*)(int,void*))(*(int*)(pAddress+1) + pAddress + 5);
InjectHook(pAddress, NewFrameRender);
InjectHook(0x5830D4, GetTimeSinceLastFrame);
// Default to desktop res
Patch<DWORD>(0x58208E, desktop.right);
Patch<DWORD>(0x582098, desktop.bottom);