diff --git a/lib/hooks.cpp b/lib/hooks.cpp index 235f88d..93eeb72 100644 --- a/lib/hooks.cpp +++ b/lib/hooks.cpp @@ -190,16 +190,8 @@ LONG WINAPI InterceptRegQueryValueExA(HKEY hKey, LPCSTR lpValueName, LPDWORD lpR void WINAPI InterceptSleep(DWORD dwMilliseconds) { - // Do nothing - std::string fps_behavior = config.GetString(_T("FPSLimit")); - - // If uncapped, do nothing - if (fps_behavior != "Uncapped") { - // If not default, pass through new FPS - if (fps_behavior == "Limited") { - dwMilliseconds = 1000.0f / config.GetFloat(_T("CustomFPS")); - } - + // If uncapped, do nothing. Otherwise pass through as normal. + if (config.GetString(_T("FPSLimit")) != "Uncapped") { Sleep(dwMilliseconds); } } @@ -216,6 +208,37 @@ HRESULT WINAPI InterceptD3DRMViewportSetField(LPDIRECT3DRMVIEWPORT viewport, D3D return d3drmViewportSetFieldOriginal(viewport, field); } +const SIZE_T max_frame_numbers = 60; +SIZE_T current_frame = 0; +DWORD frame_deltas[max_frame_numbers]; +DWORD last_time = 0; + +typedef HRESULT (WINAPI *d3drmDeviceUpdateFunction)(LPDIRECT3DRMDEVICE device); +d3drmDeviceUpdateFunction d3drmDeviceUpdateOriginal = NULL; +HRESULT WINAPI InterceptD3DRMDeviceUpdate(LPDIRECT3DRMDEVICE device) +{ + DWORD now = timeGetTime(); + + if (last_time != 0) { + DWORD diff = now - last_time; + frame_deltas[current_frame%max_frame_numbers] = diff; + current_frame++; + + if (current_frame >= max_frame_numbers) { + double avg_delta = 0; + for (size_t i=0; i