From 7ba27e184fbc66a63fccfc2bbe6330d22b82d2d5 Mon Sep 17 00:00:00 2001 From: DismissedLight <1686188646@qq.com> Date: Fri, 13 Oct 2023 23:17:08 +0800 Subject: [PATCH] ignore invalid launch schemes --- .../Snap.Hutao/Service/Game/ChannelOptions.cs | 12 +++++++++++ .../Game/IgnoredInvalidChannelOptions.cs | 20 +++++++++++++++++++ .../Snap.Hutao/View/Control/WebViewer.xaml.cs | 2 +- .../ViewModel/Game/LaunchGameViewModel.cs | 13 +++++++----- .../Web/Bridge/CoreWebView2Extension.cs | 11 +--------- 5 files changed, 42 insertions(+), 16 deletions(-) create mode 100644 src/Snap.Hutao/Snap.Hutao/Service/Game/IgnoredInvalidChannelOptions.cs diff --git a/src/Snap.Hutao/Snap.Hutao/Service/Game/ChannelOptions.cs b/src/Snap.Hutao/Snap.Hutao/Service/Game/ChannelOptions.cs index e8255f7f..8ebb4027 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/Game/ChannelOptions.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/Game/ChannelOptions.cs @@ -49,6 +49,13 @@ internal readonly struct ChannelOptions ConfigFilePath = configFilePath; } + public ChannelOptions(ChannelType channel, SubChannelType subChannel, bool isOversea) + { + Channel = channel; + SubChannel = subChannel; + IsOversea = isOversea; + } + /// /// 配置文件未找到 /// @@ -65,4 +72,9 @@ internal readonly struct ChannelOptions { return $"[ChannelType:{Channel}] [SubChannel:{SubChannel}] [IsOversea: {IsOversea}]"; } + + public override int GetHashCode() + { + return HashCode.Combine(Channel, SubChannel, IsOversea); + } } \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Service/Game/IgnoredInvalidChannelOptions.cs b/src/Snap.Hutao/Snap.Hutao/Service/Game/IgnoredInvalidChannelOptions.cs new file mode 100644 index 00000000..eac6d975 --- /dev/null +++ b/src/Snap.Hutao/Snap.Hutao/Service/Game/IgnoredInvalidChannelOptions.cs @@ -0,0 +1,20 @@ +// Copyright (c) DGP Studio. All rights reserved. +// Licensed under the MIT license. + +using Snap.Hutao.Model.Intrinsic; +using System.Collections.Immutable; + +namespace Snap.Hutao.Service.Game; + +internal static class IgnoredInvalidChannelOptions +{ + private static readonly ImmutableHashSet InvalidOptions = new HashSet() + { + new(ChannelType.Bili, SubChannelType.Official, true), + }.ToImmutableHashSet(); + + public static bool Contains(in ChannelOptions options) + { + return InvalidOptions.Contains(options); + } +} diff --git a/src/Snap.Hutao/Snap.Hutao/View/Control/WebViewer.xaml.cs b/src/Snap.Hutao/Snap.Hutao/View/Control/WebViewer.xaml.cs index e9326fa2..65a276af 100644 --- a/src/Snap.Hutao/Snap.Hutao/View/Control/WebViewer.xaml.cs +++ b/src/Snap.Hutao/Snap.Hutao/View/Control/WebViewer.xaml.cs @@ -91,7 +91,7 @@ internal partial class WebViewer : UserControl, IRecipient CoreWebView2Navigator navigator = new(coreWebView2); await navigator.NavigateAsync("about:blank").ConfigureAwait(true); - coreWebView2.SetCookie(user.CookieToken, user.LToken, user.SToken); + coreWebView2.SetCookie(user.CookieToken, user.LToken); _ = userAndUid.User.IsOversea ? coreWebView2.SetMobileOverseaUserAgent() : coreWebView2.SetMobileUserAgent(); jsInterface?.Detach(); jsInterface = SourceProvider.CreateJsInterface(serviceProvider, coreWebView2, userAndUid); diff --git a/src/Snap.Hutao/Snap.Hutao/ViewModel/Game/LaunchGameViewModel.cs b/src/Snap.Hutao/Snap.Hutao/ViewModel/Game/LaunchGameViewModel.cs index 4bc472b2..b82c1738 100644 --- a/src/Snap.Hutao/Snap.Hutao/ViewModel/Game/LaunchGameViewModel.cs +++ b/src/Snap.Hutao/Snap.Hutao/ViewModel/Game/LaunchGameViewModel.cs @@ -34,12 +34,12 @@ internal sealed partial class LaunchGameViewModel : Abstraction.ViewModel public const string DesiredUid = nameof(DesiredUid); private readonly IContentDialogFactory contentDialogFactory; + private readonly LaunchStatusOptions launchStatusOptions; private readonly INavigationService navigationService; private readonly IInfoBarService infoBarService; - private readonly LaunchOptions launchOptions; - private readonly LaunchStatusOptions launchStatusOptions; - private readonly RuntimeOptions hutaoOptions; private readonly ResourceClient resourceClient; + private readonly LaunchOptions launchOptions; + private readonly RuntimeOptions hutaoOptions; private readonly IUserService userService; private readonly ITaskContext taskContext; private readonly IGameService gameService; @@ -125,8 +125,11 @@ internal sealed partial class LaunchGameViewModel : Abstraction.ViewModel } catch (InvalidOperationException) { - // 后台收集 - throw new NotSupportedException($"不支持的 MultiChannel: {options}"); + if (!IgnoredInvalidChannelOptions.Contains(options)) + { + // 后台收集 + throw new NotSupportedException($"不支持的 MultiChannel: {options}"); + } } } else diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Bridge/CoreWebView2Extension.cs b/src/Snap.Hutao/Snap.Hutao/Web/Bridge/CoreWebView2Extension.cs index fd763312..d09b5013 100644 --- a/src/Snap.Hutao/Snap.Hutao/Web/Bridge/CoreWebView2Extension.cs +++ b/src/Snap.Hutao/Snap.Hutao/Web/Bridge/CoreWebView2Extension.cs @@ -67,10 +67,9 @@ internal static class CoreWebView2Extension /// webView2 /// CookieToken /// LToken - /// SToken /// 是否为国际服,用于改变 cookie domain /// 链式调用的WebView2 - public static CoreWebView2 SetCookie(this CoreWebView2 webView, Cookie? cookieToken = null, Cookie? lToken = null, Cookie? sToken = null, bool isOversea = false) + public static CoreWebView2 SetCookie(this CoreWebView2 webView, Cookie? cookieToken = null, Cookie? lToken = null, bool isOversea = false) { CoreWebView2CookieManager cookieManager = webView.CookieManager; @@ -88,14 +87,6 @@ internal static class CoreWebView2Extension .AddMihoyoCookie(Cookie.LTOKEN, lToken, isOversea); } - if (sToken is not null) - { - cookieManager - .AddMihoyoCookie(Cookie.MID, sToken, isOversea) - .AddMihoyoCookie(Cookie.STUID, sToken, isOversea) - .AddMihoyoCookie(Cookie.STOKEN, sToken, isOversea); - } - return webView; }