From 50459923f99cc632dadf88818a4417fbc62cdcaa Mon Sep 17 00:00:00 2001 From: DismissedLight <1686188646@qq.com> Date: Fri, 23 Dec 2022 16:29:28 +0800 Subject: [PATCH] apply window-mode --- src/Snap.Hutao/Snap.Hutao/App.xaml | 2 + .../Snap.Hutao/Core/CommandLineBuilder.cs | 11 +++++ .../Metadata/Converter/AvatarCardConverter.cs | 37 +++++++++++++++ .../Metadata/Converter/ItemIconConverter.cs | 2 + .../Snap.Hutao/Service/Game/GameService.cs | 1 + .../Service/Game/LaunchConfiguration.cs | 11 +++++ .../Service/Game/Unlocker/GameFpsUnlocker.cs | 11 +++-- .../Snap.Hutao/View/Page/WikiAvatarPage.xaml | 47 +++++++++++++------ 8 files changed, 104 insertions(+), 18 deletions(-) create mode 100644 src/Snap.Hutao/Snap.Hutao/Model/Metadata/Converter/AvatarCardConverter.cs diff --git a/src/Snap.Hutao/Snap.Hutao/App.xaml b/src/Snap.Hutao/Snap.Hutao/App.xaml index 49f1b61a..2eca2557 100644 --- a/src/Snap.Hutao/Snap.Hutao/App.xaml +++ b/src/Snap.Hutao/Snap.Hutao/App.xaml @@ -43,8 +43,10 @@ 0,0,6,6 2 + + diff --git a/src/Snap.Hutao/Snap.Hutao/Core/CommandLineBuilder.cs b/src/Snap.Hutao/Snap.Hutao/Core/CommandLineBuilder.cs index 607eafe9..3eac4031 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/CommandLineBuilder.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/CommandLineBuilder.cs @@ -25,6 +25,17 @@ public class CommandLineBuilder return condition ? Append(name, value) : this; } + /// + /// 当参数不为 null 时添加参数 + /// + /// 参数名称 + /// 值 + /// 命令行建造器 + public CommandLineBuilder AppendIfNotNull(string name, object? value = null) + { + return AppendIf(name, value != null, value); + } + /// /// 添加参数 /// diff --git a/src/Snap.Hutao/Snap.Hutao/Model/Metadata/Converter/AvatarCardConverter.cs b/src/Snap.Hutao/Snap.Hutao/Model/Metadata/Converter/AvatarCardConverter.cs new file mode 100644 index 00000000..53b2638f --- /dev/null +++ b/src/Snap.Hutao/Snap.Hutao/Model/Metadata/Converter/AvatarCardConverter.cs @@ -0,0 +1,37 @@ +// Copyright (c) DGP Studio. All rights reserved. +// Licensed under the MIT license. + +using Snap.Hutao.Control; + +namespace Snap.Hutao.Model.Metadata.Converter; + +/// +/// 角色卡片转换器 +/// +internal class AvatarCardConverter : ValueConverterBase +{ + private const string BaseUrl = "https://static.snapgenshin.com/AvatarCard/{0}_Card.png"; + + private static readonly Uri UIAvatarIconCostumeCard = new("https://static.snapgenshin.com/AvatarCard/UI_AvatarIcon_Costume_Card.png"); + + /// + /// 名称转Uri + /// + /// 名称 + /// 链接 + public static Uri IconNameToUri(string name) + { + if (string.IsNullOrEmpty(name)) + { + return UIAvatarIconCostumeCard; + } + + return new Uri(string.Format(BaseUrl, name)); + } + + /// + public override Uri Convert(string from) + { + return IconNameToUri(from); + } +} \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Model/Metadata/Converter/ItemIconConverter.cs b/src/Snap.Hutao/Snap.Hutao/Model/Metadata/Converter/ItemIconConverter.cs index dd306fc7..643c4c03 100644 --- a/src/Snap.Hutao/Snap.Hutao/Model/Metadata/Converter/ItemIconConverter.cs +++ b/src/Snap.Hutao/Snap.Hutao/Model/Metadata/Converter/ItemIconConverter.cs @@ -12,6 +12,8 @@ internal class ItemIconConverter : ValueConverterBase { private const string BaseUrl = "https://static.snapgenshin.com/ItemIcon/{0}.png"; + private static readonly Uri UIItemIconNone = new("https://static.snapgenshin.com/Bg/UI_ItemIcon_None.png"); + /// /// 名称转Uri /// diff --git a/src/Snap.Hutao/Snap.Hutao/Service/Game/GameService.cs b/src/Snap.Hutao/Snap.Hutao/Service/Game/GameService.cs index 557afd31..a4167f77 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/Game/GameService.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/Game/GameService.cs @@ -244,6 +244,7 @@ internal class GameService : IGameService, IDisposable string commandLine = new CommandLineBuilder() .AppendIf("-popupwindow", configuration.IsBorderless) .Append("-screen-fullscreen", configuration.IsFullScreen ? 1 : 0) + .AppendIfNotNull("-window-mode", configuration.WindowMode) .Append("-screen-width", configuration.ScreenWidth) .Append("-screen-height", configuration.ScreenHeight) .ToString(); diff --git a/src/Snap.Hutao/Snap.Hutao/Service/Game/LaunchConfiguration.cs b/src/Snap.Hutao/Snap.Hutao/Service/Game/LaunchConfiguration.cs index 0bf32659..f203d0b9 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/Game/LaunchConfiguration.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/Game/LaunchConfiguration.cs @@ -57,4 +57,15 @@ internal readonly struct LaunchConfiguration UnlockFPS = unlockFps; TargetFPS = targetFps; } + + /// + /// 窗口模式字符串 + /// + public string? WindowMode + { + get + { + return IsFullScreen ? "exclusive" : IsBorderless ? "borderless" : null; + } + } } \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Service/Game/Unlocker/GameFpsUnlocker.cs b/src/Snap.Hutao/Snap.Hutao/Service/Game/Unlocker/GameFpsUnlocker.cs index 96b2314c..83b38deb 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/Game/Unlocker/GameFpsUnlocker.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/Game/Unlocker/GameFpsUnlocker.cs @@ -150,9 +150,12 @@ internal class GameFpsUnlocker : IGameFpsUnlocker Must.Range(adr >= 0, "未匹配到FPS字节"); - int rip = adr + 2; - int rel = image.Fixed(rip + 2); // Unsafe.ReadUnaligned(ref image[rip + 2]); - int ofs = rip + rel + 6; - fpsAddress = (nuint)((long)unityPlayer.modBaseAddr + ofs); + fixed (byte* pSpan = image) + { + int rip = adr + 2; + int rel = *(int*)(pSpan + rip + 2); // Unsafe.ReadUnaligned(ref image[rip + 2]); + int ofs = rip + rel + 6; + fpsAddress = (nuint)((long)unityPlayer.modBaseAddr + ofs); + } } } \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/View/Page/WikiAvatarPage.xaml b/src/Snap.Hutao/Snap.Hutao/View/Page/WikiAvatarPage.xaml index 2022a629..b77248aa 100644 --- a/src/Snap.Hutao/Snap.Hutao/View/Page/WikiAvatarPage.xaml +++ b/src/Snap.Hutao/Snap.Hutao/View/Page/WikiAvatarPage.xaml @@ -381,7 +381,11 @@ 0 - + @@ -389,11 +393,11 @@ 1 - - + Height="80" + Icon="{Binding Icons[0]}" + Quality="QUALITY_ORANGE"/> @@ -520,17 +524,32 @@ HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" Header="衣装"> - + - - - - - + + + + + + + + + + + +