Skip to content

Commit 3b0d771

Browse files
committed
fix: VRR monitor reads HKLM\...\GraphicsDrivers\VRROptimizeEnable, not the DirectX HKCU string
1 parent f41fbd5 commit 3b0d771

3 files changed

Lines changed: 19 additions & 49 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ GamerGuardian doesn't ask you to take its word for it.
220220
| Game DVR | `(Get-ItemProperty 'HKCU:\System\GameConfigStore' -Name GameDVR_Enabled).GameDVR_Enabled` |
221221
| Mouse precision | `(Get-ItemProperty 'HKCU:\Control Panel\Mouse' -Name MouseSpeed).MouseSpeed` |
222222
| Fullscreen optimizations | `(Get-ItemProperty 'HKCU:\System\GameConfigStore' -Name GameDVR_FSEBehaviorMode).GameDVR_FSEBehaviorMode` |
223-
| VRR | `(Get-ItemProperty 'HKCU:\Software\Microsoft\DirectX\UserGpuPreferences' -Name DirectXUserGlobalSettings).DirectXUserGlobalSettings` |
223+
| VRR | `(Get-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\GraphicsDrivers' -Name VRROptimizeEnable).VRROptimizeEnable` |
224224
| System Responsiveness | `(Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Multimedia\SystemProfile' -Name SystemResponsiveness).SystemResponsiveness` |
225225
| Network Throttling | `(Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Multimedia\SystemProfile' -Name NetworkThrottlingIndex).NetworkThrottlingIndex` |
226226
| USB Selective Suspend | `(Get-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Services\USB' -Name DisableSelectiveSuspend).DisableSelectiveSuspend` |
Lines changed: 16 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,44 @@
11
using GamerGuardian.Models;
2+
using GamerGuardian.Services;
23
using Microsoft.Win32;
34

45
namespace GamerGuardian.Monitors;
56

67
public sealed class VrrMonitor : IMonitoredSetting
78
{
89
public string Id => "vrr";
9-
private const string SubKey = @"Software\Microsoft\DirectX\UserGpuPreferences";
10-
private const string ValueName = "DirectXUserGlobalSettings";
11-
private const string Key = "VRROptimizeEnable";
10+
private const string SubKey = @"SYSTEM\CurrentControlSet\Control\GraphicsDrivers";
11+
private const string ValueName = "VRROptimizeEnable";
1212

1313
public IEnumerable<DriftItem> CheckDrift(AppConfig config)
1414
{
1515
var pref = config.Global.Vrr;
1616

17-
var current = ReadCurrent();
18-
if (current is null) yield break;
19-
if (current.Value == pref.DesiredOn) yield break;
17+
using var k = Registry.LocalMachine.OpenSubKey(SubKey, writable: false);
18+
if (k?.GetValue(ValueName) is not int rawValue) yield break;
19+
var current = rawValue != 0;
20+
if (current == pref.DesiredOn) yield break;
2021

2122
bool desired = pref.DesiredOn;
23+
uint desiredRaw = desired ? 1u : 0u;
2224
yield return new DriftItem(
2325
SettingId: Id,
2426
DisplayKey: "global",
2527
DisplayLabel: "Global",
26-
Description: "Variable Refresh Rate (Windows)",
27-
CurrentValue: current.Value ? "On" : "Off",
28+
Description: "Variable Refresh Rate (DirectX)",
29+
CurrentValue: current ? "On" : "Off",
2830
DesiredValue: desired ? "On" : "Off",
2931
AutoApply: pref.AutoApply,
30-
Apply: () => Task.Run(() => Apply(desired)),
32+
Apply: () => Task.Run(() => ElevatedRegistry.SetHklmDword(SubKey, ValueName, desiredRaw)),
3133
IsMonitored: pref.Monitor,
32-
RawBefore: $"VRROptimizeEnable={(current.Value ? "1" : "0")}",
33-
RawDesired: $"VRROptimizeEnable={(desired ? "1" : "0")}");
34+
RawBefore: rawValue.ToString(),
35+
RawDesired: desiredRaw.ToString());
3436
}
3537

3638
public static bool? ReadCurrent()
3739
{
38-
using var k = Registry.CurrentUser.OpenSubKey(SubKey, writable: false);
39-
var raw = k?.GetValue(ValueName) as string;
40-
if (string.IsNullOrEmpty(raw)) return null;
41-
var pairs = ParsePairs(raw);
42-
if (!pairs.TryGetValue(Key, out var v)) return null;
43-
return v == "1";
44-
}
45-
46-
public static void Apply(bool on)
47-
{
48-
using var k = Registry.CurrentUser.CreateSubKey(SubKey, writable: true)!;
49-
var raw = (k.GetValue(ValueName) as string) ?? string.Empty;
50-
var pairs = ParsePairs(raw);
51-
pairs[Key] = on ? "1" : "0";
52-
k.SetValue(ValueName, BuildPairs(pairs), RegistryValueKind.String);
53-
}
54-
55-
private static Dictionary<string, string> ParsePairs(string raw)
56-
{
57-
var d = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
58-
foreach (var part in raw.Split(';', StringSplitOptions.RemoveEmptyEntries))
59-
{
60-
var idx = part.IndexOf('=');
61-
if (idx <= 0) continue;
62-
d[part[..idx]] = part[(idx + 1)..];
63-
}
64-
return d;
65-
}
66-
67-
private static string BuildPairs(Dictionary<string, string> pairs)
68-
{
69-
var sb = new System.Text.StringBuilder();
70-
foreach (var kv in pairs)
71-
sb.Append(kv.Key).Append('=').Append(kv.Value).Append(';');
72-
return sb.ToString();
40+
using var k = Registry.LocalMachine.OpenSubKey(SubKey, writable: false);
41+
if (k?.GetValue(ValueName) is int v) return v != 0;
42+
return null;
7343
}
7444
}

src/GamerGuardian/Services/SettingDocs.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public static string MechanismFor(string settingId)
2020
"gamedvr" => @"HKCU\System\GameConfigStore\GameDVR_Enabled + HKCU\...\GameDVR\AppCaptureEnabled",
2121
"mouseaccel" => @"user32.SystemParametersInfo SPI_SETMOUSE + HKCU\Control Panel\Mouse",
2222
"fso" => @"HKCU\System\GameConfigStore (GameDVR_FSEBehaviorMode + 3 related DWORDs)",
23-
"vrr" => @"HKCU\Software\Microsoft\DirectX\UserGpuPreferences\DirectXUserGlobalSettings (REG_SZ, VRROptimizeEnable=)",
23+
"vrr" => @"HKLM\SYSTEM\CurrentControlSet\Control\GraphicsDrivers\VRROptimizeEnable (DWORD)",
2424
"sysresponse" => @"HKLM\SOFTWARE\...\Multimedia\SystemProfile\SystemResponsiveness (DWORD)",
2525
"netthrottle" => @"HKLM\SOFTWARE\...\Multimedia\SystemProfile\NetworkThrottlingIndex (DWORD)",
2626
"usbsuspend" => @"HKLM\SYSTEM\CurrentControlSet\Services\USB\DisableSelectiveSuspend (DWORD)",
@@ -42,7 +42,7 @@ public static string VerifyCommandFor(string settingId)
4242
"gamedvr" => @"(Get-ItemProperty 'HKCU:\System\GameConfigStore' -Name GameDVR_Enabled).GameDVR_Enabled",
4343
"mouseaccel" => @"(Get-ItemProperty 'HKCU:\Control Panel\Mouse' -Name MouseSpeed).MouseSpeed",
4444
"fso" => @"(Get-ItemProperty 'HKCU:\System\GameConfigStore' -Name GameDVR_FSEBehaviorMode).GameDVR_FSEBehaviorMode",
45-
"vrr" => @"(Get-ItemProperty 'HKCU:\Software\Microsoft\DirectX\UserGpuPreferences' -Name DirectXUserGlobalSettings).DirectXUserGlobalSettings",
45+
"vrr" => @"(Get-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\GraphicsDrivers' -Name VRROptimizeEnable).VRROptimizeEnable",
4646
"sysresponse" => @"(Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Multimedia\SystemProfile' -Name SystemResponsiveness).SystemResponsiveness",
4747
"netthrottle" => @"(Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Multimedia\SystemProfile' -Name NetworkThrottlingIndex).NetworkThrottlingIndex",
4848
"usbsuspend" => @"(Get-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Services\USB' -Name DisableSelectiveSuspend).DisableSelectiveSuspend",

0 commit comments

Comments
 (0)