diff --git a/BetterGenshinImpact/Core/Config/GenshinStartConfig.cs b/BetterGenshinImpact/Core/Config/GenshinStartConfig.cs
index 4ac99dba..a857918c 100644
--- a/BetterGenshinImpact/Core/Config/GenshinStartConfig.cs
+++ b/BetterGenshinImpact/Core/Config/GenshinStartConfig.cs
@@ -47,4 +47,10 @@ public partial class GenshinStartConfig : ObservableObject
[ObservableProperty]
private bool _startGameWithCmd = false;
+
+ ///
+ /// 启动前自动关闭原神 HDR(删除原神 HDR 对应注册表键)
+ ///
+ [ObservableProperty]
+ private bool _autoDisableGenshinHdrEnabled = true;
}
diff --git a/BetterGenshinImpact/GameTask/GenshinHdrRegistryHelper.cs b/BetterGenshinImpact/GameTask/GenshinHdrRegistryHelper.cs
new file mode 100644
index 00000000..f378790d
--- /dev/null
+++ b/BetterGenshinImpact/GameTask/GenshinHdrRegistryHelper.cs
@@ -0,0 +1,61 @@
+using Microsoft.Win32;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+
+namespace BetterGenshinImpact.GameTask;
+
+public static class GenshinHdrRegistryHelper
+{
+ public const string HdrRegistryEntryName = "WINDOWS_HDR_ON_h3132281285";
+ public const string CnHdrRegistrySubKeyPath = @"Software\miHoYo\原神\WINDOWS_HDR_ON_h3132281285";
+ public const string GlobalHdrRegistrySubKeyPath = @"Software\miHoYo\Genshin Impact\WINDOWS_HDR_ON_h3132281285";
+ public const string CnHdrRegistryParentKeyPath = @"Software\miHoYo\原神";
+ public const string GlobalHdrRegistryParentKeyPath = @"Software\miHoYo\Genshin Impact";
+
+ public static readonly IReadOnlyList HdrRegistrySubKeyPaths =
+ [
+ CnHdrRegistrySubKeyPath,
+ GlobalHdrRegistrySubKeyPath
+ ];
+
+ public static readonly IReadOnlyList HdrRegistryParentKeyPaths =
+ [
+ CnHdrRegistryParentKeyPath,
+ GlobalHdrRegistryParentKeyPath
+ ];
+
+ public static IReadOnlyList HdrRegistryFullKeyPaths =>
+ HdrRegistrySubKeyPaths.Select(static path => $@"HKEY_CURRENT_USER\{path}").ToArray();
+
+ public static bool TryDisableHdr(out IReadOnlyList deletedFullKeyPaths)
+ {
+ var deletedPaths = new List();
+ foreach (var parentKeyPath in HdrRegistryParentKeyPaths)
+ {
+ try
+ {
+ using var key = Registry.CurrentUser.OpenSubKey(parentKeyPath, writable: true);
+ if (key == null)
+ {
+ continue;
+ }
+
+ if (key.GetValue(HdrRegistryEntryName) == null)
+ {
+ continue;
+ }
+
+ key.DeleteValue(HdrRegistryEntryName, throwOnMissingValue: false);
+ deletedPaths.Add($@"HKEY_CURRENT_USER\{parentKeyPath}\{HdrRegistryEntryName}");
+ }
+ catch
+ {
+ // 忽略删除失败,避免影响启动流程
+ }
+ }
+
+ deletedFullKeyPaths = deletedPaths.Distinct(StringComparer.OrdinalIgnoreCase).ToArray();
+ return deletedFullKeyPaths.Count > 0;
+ }
+}
diff --git a/BetterGenshinImpact/View/Pages/HomePage.xaml b/BetterGenshinImpact/View/Pages/HomePage.xaml
index fb31c5a2..4e9821b5 100644
--- a/BetterGenshinImpact/View/Pages/HomePage.xaml
+++ b/BetterGenshinImpact/View/Pages/HomePage.xaml
@@ -436,6 +436,32 @@
AcceptsReturn="True" />
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/BetterGenshinImpact/ViewModel/Pages/HomePageViewModel.cs b/BetterGenshinImpact/ViewModel/Pages/HomePageViewModel.cs
index d3ab15b4..cafd2e07 100644
--- a/BetterGenshinImpact/ViewModel/Pages/HomePageViewModel.cs
+++ b/BetterGenshinImpact/ViewModel/Pages/HomePageViewModel.cs
@@ -217,6 +217,8 @@ public partial class HomePageViewModel : ViewModel
[RelayCommand(CanExecute = nameof(CanStartTrigger))]
public async Task OnStartTriggerAsync()
{
+ await DisableGenshinHdrIfNeededAsync();
+
var hWnd = SystemControl.FindGenshinImpactHandle();
if (hWnd == IntPtr.Zero)
{
@@ -249,6 +251,24 @@ public partial class HomePageViewModel : ViewModel
Start(hWnd);
}
+ private Task DisableGenshinHdrIfNeededAsync()
+ {
+ if (!Config.GenshinStartConfig.AutoDisableGenshinHdrEnabled)
+ {
+ return Task.CompletedTask;
+ }
+
+ if (!GenshinHdrRegistryHelper.TryDisableHdr(out _))
+ {
+ return Task.CompletedTask;
+ }
+
+ // 这行日志可能看不到
+ _logger.LogWarning(
+ "检测到原神 HDR 已开启并已自动关闭。如游戏已在运行,请重启游戏后生效。");
+ return Task.CompletedTask;
+ }
+
private void Start(IntPtr hWnd)
{
Debug.WriteLine($"原神启动句柄{hWnd}");
@@ -634,4 +654,4 @@ public partial class HomePageViewModel : ViewModel
}
#endregion
-}
\ No newline at end of file
+}