AbsoluteGamer

OpenGL FPS Limiter

Jul 2nd, 2017
1,005
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Windows.h>
  2. #include <detours.h>
  3. #pragma comment (lib, "detours.lib")
  4.  
  5. typedef BOOL(__stdcall * f_wglSwapBuffers) (_In_ HDC hDc);
  6. f_wglSwapBuffers original_wglSwapBuffers;
  7.  
  8. DWORD frames = 0xDEADBEEF; // delay goes here
  9.  
  10. BOOL _stdcall hooked_wglSwapBuffers(_In_ HDC hDc) {
  11.     Sleep(frames);
  12.     return original_wglSwapBuffers(hDc);
  13. }
  14.  
  15. DWORD WINAPI Main_Thread(LPVOID lpParam) {
  16.  
  17.     HMODULE hMod = GetModuleHandleW(L"opengl32.dll");
  18.     if (!hMod)
  19.         return S_OK;
  20.     original_wglSwapBuffers = (f_wglSwapBuffers)(DWORD)GetProcAddress(hMod, "wglSwapBuffers");
  21.     DetourTransactionBegin();
  22.     DetourUpdateThread(GetCurrentThread());
  23.     DetourAttach(&(PVOID&)original_wglSwapBuffers, hooked_wglSwapBuffers);
  24.     DetourTransactionCommit();
  25.    
  26.     MessageBoxA(0, "DLL injected,\nFPS should now be limited", "Success", MB_OK | MB_APPLMODAL);
  27.  
  28.     return S_OK;
  29. }
  30.  
  31. BOOL APIENTRY DllMain(HMODULE hModule, DWORD _reason, LPVOID lpReserved) {
  32.  
  33.     if (_reason == DLL_PROCESS_ATTACH) {
  34.         CreateThread(0, 0x1000, &Main_Thread, 0, 0, NULL);
  35.     }
  36.     return TRUE;
  37. }
Add Comment
Please, Sign In to add comment