mirror of
https://github.com/babalae/better-genshin-impact.git
synced 2026-05-07 00:15:53 +08:00
原神HDR自动关闭
This commit is contained in:
@@ -47,4 +47,10 @@ public partial class GenshinStartConfig : ObservableObject
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _startGameWithCmd = false;
|
||||
|
||||
/// <summary>
|
||||
/// 启动前自动关闭原神 HDR(删除原神 HDR 对应注册表键)
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private bool _autoDisableGenshinHdrEnabled = true;
|
||||
}
|
||||
|
||||
61
BetterGenshinImpact/GameTask/GenshinHdrRegistryHelper.cs
Normal file
61
BetterGenshinImpact/GameTask/GenshinHdrRegistryHelper.cs
Normal file
@@ -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<string> HdrRegistrySubKeyPaths =
|
||||
[
|
||||
CnHdrRegistrySubKeyPath,
|
||||
GlobalHdrRegistrySubKeyPath
|
||||
];
|
||||
|
||||
public static readonly IReadOnlyList<string> HdrRegistryParentKeyPaths =
|
||||
[
|
||||
CnHdrRegistryParentKeyPath,
|
||||
GlobalHdrRegistryParentKeyPath
|
||||
];
|
||||
|
||||
public static IReadOnlyList<string> HdrRegistryFullKeyPaths =>
|
||||
HdrRegistrySubKeyPaths.Select(static path => $@"HKEY_CURRENT_USER\{path}").ToArray();
|
||||
|
||||
public static bool TryDisableHdr(out IReadOnlyList<string> deletedFullKeyPaths)
|
||||
{
|
||||
var deletedPaths = new List<string>();
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -436,6 +436,32 @@
|
||||
AcceptsReturn="True" />
|
||||
</Grid>
|
||||
<Separator Margin="-18,0" BorderThickness="0,1,0,0" />
|
||||
<Grid Margin="16">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<ui:TextBlock Grid.Row="0"
|
||||
Grid.Column="0"
|
||||
FontTypography="Body"
|
||||
Text="启动前自动关闭原神 HDR"
|
||||
TextWrapping="Wrap" />
|
||||
<ui:TextBlock Grid.Row="1"
|
||||
Grid.Column="0"
|
||||
Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}"
|
||||
Text="检测到开启时会自动关闭原神 HDR 注册表设置"
|
||||
TextWrapping="Wrap" />
|
||||
<ui:ToggleSwitch Grid.Row="0"
|
||||
Grid.RowSpan="2"
|
||||
Grid.Column="1"
|
||||
Margin="0,0,36,0"
|
||||
IsChecked="{Binding Config.GenshinStartConfig.AutoDisableGenshinHdrEnabled, Mode=TwoWay}" />
|
||||
</Grid>
|
||||
<Separator Margin="-18,0" BorderThickness="0,1,0,0" />
|
||||
<Grid Margin="16">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user