From 3b98e5abaf2d4794536cec1d2d041e52251d9317 Mon Sep 17 00:00:00 2001 From: Silent Date: Mon, 29 Jun 2015 01:08:05 +0200 Subject: [PATCH] More stable framelimiter - III --- SilentPatchIII/SilentPatchIII.cpp | 33 +++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/SilentPatchIII/SilentPatchIII.cpp b/SilentPatchIII/SilentPatchIII.cpp index d2c8aa4..11778b1 100644 --- a/SilentPatchIII/SilentPatchIII.cpp +++ b/SilentPatchIII/SilentPatchIII.cpp @@ -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(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(0x581E5E, desktop.right); Patch(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(0x58219E, desktop.right); Patch(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(0x58208E, desktop.right); Patch(0x582098, desktop.bottom);