auto fix win11 bitblt

This commit is contained in:
辉鸭蛋 2024-11-02 12:57:58 +08:00
parent 4725af5491
commit dcd7831368
8 changed files with 88 additions and 8 deletions

View File

@ -55,6 +55,12 @@ public partial class AllConfig : ObservableObject
[ObservableProperty]
private bool _wgcUseBitmapCache = true;
/// <summary>
/// 自动修复Win11下BitBlt截图方式不可用的问题
/// </summary>
[ObservableProperty]
private bool _autoFixWin11BitBlt = true;
/// <summary>
/// 推理使用的设备
/// </summary>

View File

@ -143,7 +143,8 @@ namespace BetterGenshinImpact.GameTask
GameCapture.Start(hWnd,
new Dictionary<string, object>()
{
{ "useBitmapCache", TaskContext.Instance().Config.WgcUseBitmapCache }
{ "useBitmapCache", TaskContext.Instance().Config.WgcUseBitmapCache },
{ "autoFixWin11BitBlt", OsVersionHelper.IsWindows11_OrGreater && TaskContext.Instance().Config.AutoFixWin11BitBlt }
}
);

View File

@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.Windows;
using System.Windows.Media;
using BetterGenshinImpact.Helpers;
using Wpf.Ui.Violeta.Controls;
namespace BetterGenshinImpact.View;
@ -48,7 +49,8 @@ public partial class CaptureTestWindow : Window
_capture.Start(hWnd,
new Dictionary<string, object>()
{
{ "useBitmapCache", TaskContext.Instance().Config.WgcUseBitmapCache }
{ "useBitmapCache", TaskContext.Instance().Config.WgcUseBitmapCache },
{ "autoFixWin11BitBlt", OsVersionHelper.IsWindows11 && TaskContext.Instance().Config.AutoFixWin11BitBlt }
}
);

View File

@ -296,23 +296,29 @@
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<ui:TextBlock Grid.Row="0"
Grid.Column="0"
FontTypography="Body"
Text="系统图形设置"
Text="自动关闭 Windows11 窗口化优化以支持 BitBlt"
TextWrapping="Wrap" />
<ui:TextBlock Grid.Row="1"
Grid.Column="0"
Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}"
Text="可在此处关闭 Windows11 窗口化优化以支持 BitBlt"
Text="修改设置后重启游戏生效"
TextWrapping="Wrap" />
<ui:ToggleSwitch Grid.Row="0"
Grid.RowSpan="2"
Grid.Column="1"
Margin="0,0,10,0"
IsChecked="{Binding Config.AutoFixWin11BitBlt, Mode=TwoWay}" />
<ui:Button Grid.Row="0"
Grid.RowSpan="2"
Grid.Column="1"
Grid.Column="2"
Margin="0,0,36,0"
Command="{Binding OpenDisplayAdvancedGraphicsSettingsCommand}"
Content="开始设置" />
Content="手动设置" />
</Grid>
</StackPanel>
</ui:CardExpander>

View File

@ -13,8 +13,15 @@
d:DesignHeight="450"
d:DesignWidth="300"
mc:Ignorable="d">
<Window.Resources>
<SolidColorBrush x:Key="MultiSelectComboBox.Text.Foreground" Color="#ffffff" />
<SolidColorBrush x:Key="MultiSelectComboBox.DropDown.ListBoxItem.SelectedOrder.Foreground" Color="#000000" />
<SolidColorBrush x:Key="MultiSelectComboBox.DropDown.ListBoxItem.Selector.Background" Color="#000000" />
<SolidColorBrush x:Key="MultiSelectComboBox.DropDown.ListBoxItem.Selector.Border" Color="#000000" />
<SolidColorBrush x:Key="MultiSelectComboBox.DropDown.ListBoxItem.Selected.Background" Color="#000000" />
<SolidColorBrush x:Key="MultiSelectComboBox.DropDown.ListBoxItem.Selected.Border" Color="#000000" />
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
@ -47,14 +54,24 @@
<!-- 搜索输入框 -->
<sdl:MultiSelectComboBox Width="300"
MinWidth="300"
Background="{DynamicResource ApplicationBackgroundBrush}"
EnableAutoComplete="True"
EnableBatchSelection="True"
EnableFiltering="True"
Foreground="{DynamicResource TextFillColorPrimaryBrush}"
IsEditable="True"
ItemsSource="{Binding Definition.ObjectOptions, Mode=TwoWay}"
MaxDropDownHeight="300"
SelectedItems="{Binding Object, Mode=TwoWay}"
SelectionMode="Multiple" />
SelectionMode="Multiple">
<!--<sdl:MultiSelectComboBox.Resources>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Background" Value="{DynamicResource ApplicationBackgroundBrush}" />
<Setter Property="Foreground" Value="{DynamicResource TextFillColorPrimaryBrush}" />
</Style>
<SolidColorBrush x:Key="MultiSelectComboBox.Text.Foreground" Color="#ffffff" />
</sdl:MultiSelectComboBox.Resources>-->
</sdl:MultiSelectComboBox>
<ui:TextBlock Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}">则使用</ui:TextBlock>

View File

@ -1,11 +1,13 @@
using BetterGenshinImpact.Core.Config;
using BetterGenshinImpact.Core.Recognition.OCR;
using BetterGenshinImpact.Core.Script;
using BetterGenshinImpact.GameTask;
using BetterGenshinImpact.Helpers;
using BetterGenshinImpact.Model;
using BetterGenshinImpact.Service.Interface;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Fischless.GameCapture.BitBlt;
using Microsoft.Extensions.Logging;
using OpenCvSharp;
using System;
@ -108,6 +110,13 @@ public partial class MainWindowViewModel : ObservableObject, IViewModel
_logger.LogWarning("获取 BetterGI 最新版本信息失败");
}
// Win11下 BitBlt截图方式不可用需要关闭窗口优化功能
if (OsVersionHelper.IsWindows11_OrGreater && TaskContext.Instance().Config.AutoFixWin11BitBlt)
{
BitBltRegistryHelper.SetDirectXUserGlobalSettings();
}
// 更新仓库
ScriptRepoUpdater.Instance.AutoUpdate();
}

View File

@ -17,6 +17,13 @@ public class BitBltCapture : IGameCapture
{
_hWnd = hWnd;
IsCapturing = true;
if (settings != null && settings.TryGetValue("autoFixWin11BitBlt", out var value))
{
if (value is true)
{
BitBltRegistryHelper.SetDirectXUserGlobalSettings();
}
}
}
public Bitmap? Capture()

View File

@ -0,0 +1,32 @@
using System.Diagnostics;
using Microsoft.Win32;
namespace Fischless.GameCapture.BitBlt;
public class BitBltRegistryHelper
{
/// <summary>
/// https://github.com/babalae/better-genshin-impact/issues/92
/// Win11下 BitBlt截图方式不可用需要关闭窗口优化功能这是具体的注册表操作
/// \HKEY_CURRENT_USER\Software\Microsoft\DirectX\UserGpuPreferences
/// DirectXUserGlobalSettings = SwapEffectUpgradeEnable=0;
///
/// 要在游戏启动前设置才有效
/// </summary>
public static void SetDirectXUserGlobalSettings()
{
try
{
const string keyPath = @"Software\Microsoft\DirectX\UserGpuPreferences";
const string valueName = "DirectXUserGlobalSettings";
const string valueData = "SwapEffectUpgradeEnable=0;";
using var key = Registry.CurrentUser.CreateSubKey(keyPath);
key.SetValue(valueName, valueData, RegistryValueKind.String);
}
catch (Exception e)
{
Debug.WriteLine(e);
}
}
}