From 413e7f0169b4ff211cd617246ea6c3032654c1b6 Mon Sep 17 00:00:00 2001 From: SmileyAG <58108407+SmileyAG@users.noreply.github.com> Date: Fri, 5 Jul 2024 03:52:16 +0400 Subject: [PATCH] helper_functions: Disable V-Sync --- BunnymodXT/helper_functions.cpp | 20 ++++++++++++++++++++ BunnymodXT/helper_functions.hpp | 1 + BunnymodXT/modules/ClientDLL.cpp | 18 ++---------------- BunnymodXT/modules/HwDLL.cpp | 1 + BunnymodXT/modules/HwDLL.hpp | 2 ++ 5 files changed, 26 insertions(+), 16 deletions(-) diff --git a/BunnymodXT/helper_functions.cpp b/BunnymodXT/helper_functions.cpp index 34600c6b..dad8d969 100644 --- a/BunnymodXT/helper_functions.cpp +++ b/BunnymodXT/helper_functions.cpp @@ -40,4 +40,24 @@ namespace helper_functions std::exit(1); } + + void disable_vsync() + { + #ifdef _WIN32 + auto &hw = HwDLL::GetInstance(); + if (hw.check_vsync) + { + const bool bxtDisableVSync = getenv("BXT_DISABLE_VSYNC"); + if (bxtDisableVSync) + { + typedef BOOL(APIENTRY* PFNWGLSWAPINTERVALPROC)(int); + PFNWGLSWAPINTERVALPROC wglSwapIntervalEXT = 0; + wglSwapIntervalEXT = (PFNWGLSWAPINTERVALPROC)wglGetProcAddress("wglSwapIntervalEXT"); + if (wglSwapIntervalEXT) + wglSwapIntervalEXT(0); + } + hw.check_vsync = false; + } + #endif + } }; \ No newline at end of file diff --git a/BunnymodXT/helper_functions.hpp b/BunnymodXT/helper_functions.hpp index 44961a28..502798ae 100644 --- a/BunnymodXT/helper_functions.hpp +++ b/BunnymodXT/helper_functions.hpp @@ -13,4 +13,5 @@ namespace helper_functions void com_fixslashes(std::string &str); std::string swap_lib(const char* current_lib_path, std::string new_lib_path, const char *start); void crash_if_failed(std::string str); + void disable_vsync(); } \ No newline at end of file diff --git a/BunnymodXT/modules/ClientDLL.cpp b/BunnymodXT/modules/ClientDLL.cpp index 4d33a99a..8cfea5da 100644 --- a/BunnymodXT/modules/ClientDLL.cpp +++ b/BunnymodXT/modules/ClientDLL.cpp @@ -11,6 +11,7 @@ #include "../hud_custom.hpp" #include "../triangle_drawing.hpp" #include "../discord_integration.hpp" +#include "../helper_functions.hpp" #include // Linux hooks. @@ -1667,22 +1668,7 @@ HOOK_DEF_1(ClientDLL, void, __cdecl, HUD_Frame, double, time) orig_forcehltv_found = HwDLL::GetInstance().ORIG_Cmd_FindCmd("dem_forcehltv"); } - #ifdef _WIN32 - static bool check_vsync = true; - if (check_vsync) - { - bool bxtDisableVSync = getenv("BXT_DISABLE_VSYNC"); - if (bxtDisableVSync) - { - typedef BOOL(APIENTRY* PFNWGLSWAPINTERVALPROC)(int); - PFNWGLSWAPINTERVALPROC wglSwapIntervalEXT = 0; - wglSwapIntervalEXT = (PFNWGLSWAPINTERVALPROC)wglGetProcAddress("wglSwapIntervalEXT"); - if (wglSwapIntervalEXT) - wglSwapIntervalEXT(0); - } - check_vsync = false; - } - #endif + helper_functions::disable_vsync(); if (CVars::_bxt_taslog.GetBool() && pEngfuncs) pEngfuncs->Con_Printf(const_cast("HUD_Frame time: %f\n"), time); diff --git a/BunnymodXT/modules/HwDLL.cpp b/BunnymodXT/modules/HwDLL.cpp index 55d0377a..344a702b 100644 --- a/BunnymodXT/modules/HwDLL.cpp +++ b/BunnymodXT/modules/HwDLL.cpp @@ -764,6 +764,7 @@ void HwDLL::Clear() pcl = nullptr; cls = nullptr; psv = nullptr; + check_vsync = true; lastRecordedHealth = 0; offTime = 0; offWorldmodel = 0; diff --git a/BunnymodXT/modules/HwDLL.hpp b/BunnymodXT/modules/HwDLL.hpp index e759818a..9a4e91d4 100644 --- a/BunnymodXT/modules/HwDLL.hpp +++ b/BunnymodXT/modules/HwDLL.hpp @@ -370,6 +370,8 @@ class HwDLL : public IHookableNameFilterOrdered int tas_studio_norefresh_override = 0; + bool check_vsync = true; + private: // Make sure to have hl.exe last here, so that it is the lowest priority. HwDLL() : IHookableNameFilterOrdered({ L"hw.dll", L"hw.so", L"sw.dll", L"sw.so", L"hl.exe" }) {};