unlocker kind switch

This commit is contained in:
DismissedLight
2024-07-05 19:31:10 +08:00
parent 7f6430fe80
commit 951ecd19d5
10 changed files with 90 additions and 17 deletions

View File

@@ -0,0 +1,20 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
namespace Snap.Hutao.Model;
internal sealed class NameDescriptionValue<T>
{
public NameDescriptionValue(string name, string description, T value)
{
Name = name;
Description = description;
Value = value;
}
public string Name { get; }
public string Description { get; }
public T Value { get; }
}

View File

@@ -13,7 +13,7 @@
<Identity
Name="60568DGPStudio.SnapHutao"
Publisher="CN=35C8E923-85DF-49A7-9172-B39DC6312C52"
Version="1.10.4.0" />
Version="1.10.5.0" />
<Properties>
<DisplayName>Snap Hutao</DisplayName>

View File

@@ -13,7 +13,7 @@
<Identity
Name="60568DGPStudio.SnapHutaoDev"
Publisher="CN=35C8E923-85DF-49A7-9172-B39DC6312C52"
Version="1.10.4.0" />
Version="1.10.5.0" />
<Properties>
<DisplayName>Snap Hutao Dev</DisplayName>

View File

@@ -147,6 +147,12 @@
<data name="ControlAutoSuggestBoxNotFoundValue" xml:space="preserve">
<value>未找到结果</value>
</data>
<data name="ControlAutoSuggestTokenBoxRemoveMenuItem" xml:space="preserve">
<value>删除</value>
</data>
<data name="ControlAutoSuggestTokenBoxSelectAllMenuItem" xml:space="preserve">
<value>选择全部</value>
</data>
<data name="ControlImageCachedImageInvalidResourceUri" xml:space="preserve">
<value>无效的 Uri</value>
</data>
@@ -162,12 +168,6 @@
<data name="ControlPanelPanelSelectorDropdownListName" xml:space="preserve">
<value>列表</value>
</data>
<data name="ControlAutoSuggestTokenBoxRemoveMenuItem" xml:space="preserve">
<value>删除</value>
</data>
<data name="ControlAutoSuggestTokenBoxSelectAllMenuItem" xml:space="preserve">
<value>选择全部</value>
</data>
<data name="CoreExceptionServiceDatabaseCorruptedMessage" xml:space="preserve">
<value>数据库已损坏:{0}</value>
</data>
@@ -2435,6 +2435,12 @@
<data name="ViewPageLaunchGameUnlockFpsHeader" xml:space="preserve">
<value>解锁帧率限制</value>
</data>
<data name="ViewPageLaunchGameUnlockFpsKindDescription" xml:space="preserve">
<value>更改解锁帧率的工作方式</value>
</data>
<data name="ViewPageLaunchGameUnlockFpsKindHeader" xml:space="preserve">
<value>解锁方式</value>
</data>
<data name="ViewPageLaunchGameUnlockFpsOff" xml:space="preserve">
<value>禁用</value>
</data>

View File

@@ -39,7 +39,7 @@ internal sealed class LaunchOptions : DbStoreOptions
private int? screenHeight;
private bool? isScreenHeightEnabled;
private bool? unlockFps;
private GameFpsUnlockerKind? unlockerKind;
private NameDescriptionValue<GameFpsUnlockerKind>? unlockerKind;
private int? targetFps;
private NameValue<int>? monitor;
private bool? isMonitorEnabled;
@@ -169,10 +169,32 @@ internal sealed class LaunchOptions : DbStoreOptions
set => SetOption(ref unlockFps, SettingEntry.LaunchUnlockFps, value);
}
public GameFpsUnlockerKind UnlockerKind
public List<NameDescriptionValue<GameFpsUnlockerKind>> UnlockerKinds { get; } =
[
new("经典", "经典的进程外内存操作,较为危险,但容易失败", GameFpsUnlockerKind.Legacy),
new("注入", "解锁模块注入游戏进程,非常危险,但容易成功", GameFpsUnlockerKind.Island),
];
public NameDescriptionValue<GameFpsUnlockerKind> UnlockerKind
{
get => GetOption(ref unlockerKind, SettingEntry.LaunchUnlockerKind, EnumParse<GameFpsUnlockerKind>, GameFpsUnlockerKind.Legacy).Value;
set => SetOption(ref unlockerKind, SettingEntry.LaunchUnlockerKind, value, EnumToStringOrEmpty);
get
{
return GetOption(ref unlockerKind, SettingEntry.LaunchUnlockerKind, name => GetKind(name, UnlockerKinds), UnlockerKinds[0]);
static NameDescriptionValue<GameFpsUnlockerKind> GetKind(string name, List<NameDescriptionValue<GameFpsUnlockerKind>> unlockerKinds)
{
GameFpsUnlockerKind kind = Enum.Parse<GameFpsUnlockerKind>(name);
return unlockerKinds.Single(entry => entry.Value == kind);
}
}
set
{
if (value is not null)
{
SetOption(ref unlockerKind, SettingEntry.LaunchUnlockerKind, value, selected => selected.Value.ToString());
}
}
}
public int TargetFps

View File

@@ -26,7 +26,7 @@ internal sealed class LaunchExecutionUnlockFpsHandler : ILaunchExecutionDelegate
}
UnlockOptions unlockOptions = new(gameFileSystem, 100, 20000, 2000);
IGameFpsUnlocker unlocker = context.Options.UnlockerKind switch
IGameFpsUnlocker unlocker = context.Options.UnlockerKind.Value switch
{
GameFpsUnlockerKind.Island => new IslandGameFpsUnlocker(context.ServiceProvider, context.Process, unlockOptions, progress),
_ => new DefaultGameFpsUnlocker(context.ServiceProvider, context.Process, unlockOptions, progress),

View File

@@ -181,7 +181,6 @@ internal sealed partial class CachedImage : Microsoft.UI.Xaml.Controls.Control,
ElementTheme theme = ShowAsMonoChrome ? ThemeHelper.ApplicationToElement(ThemeHelper.ElementToApplication(ActualTheme)) : ElementTheme.Default;
string file = await imageCache.GetFileFromCacheAsync(imageUri, theme).ConfigureAwait(true); // BitmapImage need to be created by main thread.
CachedName = Path.GetFileName(file);
token.ThrowIfCancellationRequested(); // check token state to determine whether the operation should be canceled.
return file.ToUri();
}
catch (COMException)

View File

@@ -306,7 +306,6 @@
<DataTemplate x:Key="AvatarPropertyTemplate">
<Grid
Padding="16,8"
Background="{Binding Background, Mode=OneWay}"
BorderBrush="{ThemeResource CardStrokeColorDefaultBrush}"
BorderThickness="0,1,0,0">
<Grid.ColumnDefinitions>

View File

@@ -343,12 +343,13 @@
</cwc:SettingsCard>
</cwc:SettingsExpander.Items>
</cwc:SettingsExpander>
<cwc:SettingsCard
<cwc:SettingsExpander
Padding="{ThemeResource SettingsCardAlignSettingsExpanderPadding}"
Description="{shuxm:ResourceString Name=ViewPageLaunchGameUnlockFpsDescription}"
Header="{shuxm:ResourceString Name=ViewPageLaunchGameUnlockFpsHeader}"
HeaderIcon="{shuxm:FontIcon Glyph=&#xE785;}"
IsEnabled="{Binding RuntimeOptions.IsElevated}"
IsExpanded="True"
Visibility="{Binding LaunchOptions.IsAdvancedLaunchOptionsEnabled, Converter={StaticResource BoolToVisibilityConverter}}">
<StackPanel Orientation="Horizontal" Spacing="10">
<shuxc:Elevation Visibility="{Binding RuntimeOptions.IsElevated, Converter={StaticResource BoolToVisibilityRevertConverter}}"/>
@@ -365,7 +366,28 @@
OffContent="{shuxm:ResourceString Name=ViewPageLaunchGameUnlockFpsOff}"
OnContent="{shuxm:ResourceString Name=ViewPageLaunchGameUnlockFpsOn}"/>
</StackPanel>
</cwc:SettingsCard>
<cwc:SettingsExpander.Items>
<cwc:SettingsCard Description="{shuxm:ResourceString Name=ViewPageLaunchGameUnlockFpsKindDescription}" Header="{shuxm:ResourceString Name=ViewPageLaunchGameUnlockFpsKindHeader}">
<StackPanel VerticalAlignment="Center" Spacing="3">
<TextBlock
HorizontalAlignment="Right"
Foreground="{ThemeResource SystemControlErrorTextForegroundBrush}"
Opacity="0.8"
Style="{StaticResource CaptionTextBlockStyle}"
Text="{Binding LaunchOptions.UnlockerKind.Description, Mode=OneWay}"/>
<shuxc:SizeRestrictedContentControl HorizontalAlignment="Right">
<ComboBox
DisplayMemberPath="Name"
ItemsSource="{Binding LaunchOptions.UnlockerKinds, Mode=OneWay}"
SelectedItem="{Binding LaunchOptions.UnlockerKind, Mode=TwoWay}"/>
</shuxc:SizeRestrictedContentControl>
</StackPanel>
</cwc:SettingsCard>
</cwc:SettingsExpander.Items>
</cwc:SettingsExpander>
</StackPanel>
</Border>
</Border>

View File

@@ -53,6 +53,11 @@ internal sealed partial class UserViewModel : ObservableObject
{
case UserOptionResult.Added:
ArgumentNullException.ThrowIfNull(Users);
if (Users.CurrentItem is null)
{
taskContext.InvokeOnMainThread(Users.MoveCurrentToFirst);
}
infoBarService.Success(SH.FormatViewModelUserAdded(uid));
break;
case UserOptionResult.CookieIncomplete: