From 04dda07620a65e8e2e892593debb8912864ad4e7 Mon Sep 17 00:00:00 2001 From: pizzaboxer Date: Tue, 1 Aug 2023 19:29:10 +0100 Subject: [PATCH] Set default FPS limit as main display refresh rate https: //cdn.discordapp.com/attachments/377894067712950275/1136002569660014653/image.png Co-Authored-By: $wag Messiah <135360571+sahelantrophus@users.noreply.github.com> --- Bloxstrap/FastFlagManager.cs | 30 +++++++++++++++++++++--------- Bloxstrap/NativeMethods.txt | 1 + 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/Bloxstrap/FastFlagManager.cs b/Bloxstrap/FastFlagManager.cs index 42335a33..0a3e36a8 100644 --- a/Bloxstrap/FastFlagManager.cs +++ b/Bloxstrap/FastFlagManager.cs @@ -1,5 +1,7 @@ -using System.Windows.Input; -using System.Windows.Media.Animation; +using System.Windows.Forms; + +using Windows.Win32; +using Windows.Win32.Graphics.Gdi; namespace Bloxstrap { @@ -152,12 +154,6 @@ public void SetPreset(string prefix, object? value) SetValue(pair.Value, value); } - public void SetPresetOnce(string key, object? value) - { - if (GetPreset(key) is null) - SetPreset(key, value); - } - public void SetPresetEnum(string prefix, string target, object? value) { foreach (var pair in PresetFlags.Where(x => x.Key.StartsWith(prefix))) @@ -207,8 +203,24 @@ public override void Load() { base.Load(); - SetPresetOnce("Rendering.Framerate", 9999); CheckManualFullscreenPreset(); + + if (GetPreset("Rendering.Framerate") is not null) + return; + + // set it to be the framerate of the primary display by default + + var screen = Screen.AllScreens.Where(x => x.Primary).Single(); + var devmode = new DEVMODEW(); + + PInvoke.EnumDisplaySettings(screen.DeviceName, ENUM_DISPLAY_SETTINGS_MODE.ENUM_CURRENT_SETTINGS, ref devmode); + + uint framerate = devmode.dmDisplayFrequency; + + if (framerate <= 100) + framerate *= 2; + + SetPreset("Rendering.Framerate", framerate); } } } diff --git a/Bloxstrap/NativeMethods.txt b/Bloxstrap/NativeMethods.txt index a66c6fad..aaa0b6a7 100644 --- a/Bloxstrap/NativeMethods.txt +++ b/Bloxstrap/NativeMethods.txt @@ -2,3 +2,4 @@ FlashWindow GetWindowLong SetWindowLong +EnumDisplaySettings