mirror of
https://jihulab.com/DGP-Studio/Snap.Hutao.git
synced 2025-11-19 21:02:53 +08:00
fix #709
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Web.Hoyolab;
|
||||
using System.Net.Http;
|
||||
|
||||
namespace Snap.Hutao.Core.DependencyInjection;
|
||||
|
||||
@@ -6,6 +6,7 @@ using Microsoft.Web.WebView2.Core;
|
||||
using Microsoft.Win32;
|
||||
using Snap.Hutao.Core.Setting;
|
||||
using System.IO;
|
||||
using System.Security.Principal;
|
||||
using Windows.ApplicationModel;
|
||||
using Windows.Storage;
|
||||
|
||||
@@ -24,6 +25,8 @@ internal sealed class HutaoOptions : IOptions<HutaoOptions>
|
||||
private readonly bool isWebView2Supported;
|
||||
private readonly string webView2Version = SH.CoreWebView2HelperVersionUndetected;
|
||||
|
||||
private bool? isElevated;
|
||||
|
||||
/// <summary>
|
||||
/// 构造一个新的胡桃选项
|
||||
/// </summary>
|
||||
@@ -54,16 +57,16 @@ internal sealed class HutaoOptions : IOptions<HutaoOptions>
|
||||
/// </summary>
|
||||
public string UserAgent { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 数据文件夹路径
|
||||
/// </summary>
|
||||
public string DataFolder { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 安装位置
|
||||
/// </summary>
|
||||
public string InstalledLocation { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 数据文件夹路径
|
||||
/// </summary>
|
||||
public string DataFolder { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 本地缓存
|
||||
/// </summary>
|
||||
@@ -89,6 +92,11 @@ internal sealed class HutaoOptions : IOptions<HutaoOptions>
|
||||
/// </summary>
|
||||
public bool IsWebView2Supported { get => isWebView2Supported; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否为提升的权限
|
||||
/// </summary>
|
||||
public bool IsElevated { get => isElevated ??= GetElevated(); }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public HutaoOptions Value { get => this; }
|
||||
|
||||
@@ -121,6 +129,19 @@ internal sealed class HutaoOptions : IOptions<HutaoOptions>
|
||||
return Convert.ToMd5HexString($"{userName}{machineGuid}");
|
||||
}
|
||||
|
||||
private static bool GetElevated()
|
||||
{
|
||||
#if DEBUG_AS_FAKE_ELEVATED
|
||||
return true;
|
||||
#else
|
||||
using (WindowsIdentity identity = WindowsIdentity.GetCurrent())
|
||||
{
|
||||
WindowsPrincipal principal = new(identity);
|
||||
return principal.IsInRole(WindowsBuiltInRole.Administrator);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
private void DetectWebView2Environment(ref string webView2Version, ref bool isWebView2Supported)
|
||||
{
|
||||
try
|
||||
|
||||
@@ -54,30 +54,13 @@ internal static class Activation
|
||||
private static readonly WeakReference<MainWindow> MainWindowReference = new(default!);
|
||||
private static readonly SemaphoreSlim ActivateSemaphore = new(1);
|
||||
|
||||
/// <summary>
|
||||
/// 获取是否提升了权限
|
||||
/// </summary>
|
||||
/// <returns>是否提升了权限</returns>
|
||||
public static bool GetElevated()
|
||||
{
|
||||
#if DEBUG_AS_FAKE_ELEVATED
|
||||
return true;
|
||||
#else
|
||||
using (WindowsIdentity identity = WindowsIdentity.GetCurrent())
|
||||
{
|
||||
WindowsPrincipal principal = new(identity);
|
||||
return principal.IsInRole(WindowsBuiltInRole.Administrator);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 以管理员模式重启
|
||||
/// </summary>
|
||||
/// <returns>任务</returns>
|
||||
public static async ValueTask RestartAsElevatedAsync()
|
||||
{
|
||||
if (!GetElevated())
|
||||
// if (!GetElevated())
|
||||
{
|
||||
await FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync();
|
||||
Process.GetCurrentProcess().Kill();
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using Snap.Hutao.Core;
|
||||
using Snap.Hutao.Core.Database;
|
||||
using Snap.Hutao.Core.ExceptionService;
|
||||
using Snap.Hutao.Core.IO.Ini;
|
||||
@@ -33,6 +34,7 @@ internal sealed partial class GameService : IGameService
|
||||
private readonly PackageConverter packageConverter;
|
||||
private readonly IServiceProvider serviceProvider;
|
||||
private readonly LaunchOptions launchOptions;
|
||||
private readonly HutaoOptions hutaoOptions;
|
||||
private readonly ITaskContext taskContext;
|
||||
private readonly IMemoryCache memoryCache;
|
||||
private readonly AppOptions appOptions;
|
||||
@@ -289,7 +291,7 @@ internal sealed partial class GameService : IGameService
|
||||
|
||||
game.Start();
|
||||
|
||||
bool isAdvancedOptionsAllowed = Activation.GetElevated() && appOptions.IsAdvancedLaunchOptionsEnabled;
|
||||
bool isAdvancedOptionsAllowed = hutaoOptions.IsElevated && appOptions.IsAdvancedLaunchOptionsEnabled;
|
||||
if (isAdvancedOptionsAllowed && launchOptions.MultipleInstances && !isfirstInstance)
|
||||
{
|
||||
ProcessInterop.DisableProtection(game, gamePath);
|
||||
|
||||
@@ -508,6 +508,12 @@
|
||||
<Button.Flyout>
|
||||
<Flyout Placement="Left">
|
||||
<StackPanel MaxWidth="320">
|
||||
<StackPanel.Resources>
|
||||
<Thickness x:Key="SettingsCardPadding">16</Thickness>
|
||||
<x:Double x:Key="SettingsCardWrapThreshold">0</x:Double>
|
||||
<x:Double x:Key="SettingsCardWrapNoIconThreshold">0</x:Double>
|
||||
<x:Double x:Key="SettingsCardMinHeight">0</x:Double>
|
||||
</StackPanel.Resources>
|
||||
<shct:DescriptionTextBlock Description="{Binding Description}">
|
||||
<shct:DescriptionTextBlock.Resources>
|
||||
<Style BasedOn="{StaticResource BodyTextBlockStyle}" TargetType="TextBlock">
|
||||
@@ -522,7 +528,7 @@
|
||||
Margin="0,2,0,0"
|
||||
Padding="12,0"
|
||||
Header="{Binding Description}">
|
||||
<TextBlock Text="{Binding Parameter}"/>
|
||||
<TextBlock Margin="0,8" Text="{Binding Parameter}"/>
|
||||
</clw:SettingsCard>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
|
||||
@@ -63,7 +63,7 @@
|
||||
Description="{shcm:ResourceString Name=ViewPageLaunchGameSwitchSchemeDescription}"
|
||||
Header="{shcm:ResourceString Name=ViewPageLaunchGameSwitchSchemeHeader}"
|
||||
HeaderIcon="{shcm:FontIcon Glyph=}"
|
||||
IsEnabled="{Binding IsElevated}">
|
||||
IsEnabled="{Binding HutaoOptions.IsElevated}">
|
||||
<ComboBox
|
||||
DisplayMemberPath="DisplayName"
|
||||
ItemsSource="{Binding KnownSchemes}"
|
||||
@@ -183,13 +183,19 @@
|
||||
Description="{shcm:ResourceString Name=ViewPageLaunchGameAppearanceScreenWidthDescription}"
|
||||
Header="{shcm:ResourceString Name=ViewPageLaunchGameAppearanceScreenWidthHeader}"
|
||||
HeaderIcon="{shcm:FontIcon Glyph=}">
|
||||
<NumberBox Width="156" Value="{Binding Options.ScreenWidth, Mode=TwoWay}"/>
|
||||
<NumberBox
|
||||
Width="156"
|
||||
Padding="10,6,0,0"
|
||||
Value="{Binding Options.ScreenWidth, Mode=TwoWay}"/>
|
||||
</clw:SettingsCard>
|
||||
<clw:SettingsCard
|
||||
Description="{shcm:ResourceString Name=ViewPageLaunchGameAppearanceScreenHeightDescription}"
|
||||
Header="{shcm:ResourceString Name=ViewPageLaunchGameAppearanceScreenHeightHeader}"
|
||||
HeaderIcon="{shcm:FontIcon Glyph=}">
|
||||
<NumberBox Width="156" Value="{Binding Options.ScreenHeight, Mode=TwoWay}"/>
|
||||
<NumberBox
|
||||
Width="156"
|
||||
Padding="10,6,0,0"
|
||||
Value="{Binding Options.ScreenHeight, Mode=TwoWay}"/>
|
||||
</clw:SettingsCard>
|
||||
|
||||
<clw:SettingsCard
|
||||
@@ -208,31 +214,29 @@
|
||||
<clw:SettingsCard
|
||||
Description="{shcm:ResourceString Name=ViewPageLaunchGameMultipleInstancesDescription}"
|
||||
Header="{shcm:ResourceString Name=ViewPageLaunchGameMultipleInstancesHeader}"
|
||||
HeaderIcon="{shcm:FontIcon Glyph=}">
|
||||
HeaderIcon="{shcm:FontIcon Glyph=}"
|
||||
IsEnabled="{Binding HutaoOptions.IsElevated}">
|
||||
<ToggleSwitch Width="120" IsOn="{Binding Options.MultipleInstances, Mode=TwoWay}"/>
|
||||
</clw:SettingsCard>
|
||||
<clw:SettingsCard
|
||||
Description="{shcm:ResourceString Name=ViewPageLaunchGameUnlockFpsDescription}"
|
||||
Header="{shcm:ResourceString Name=ViewPageLaunchGameUnlockFpsHeader}"
|
||||
HeaderIcon="{shcm:FontIcon Glyph=}">
|
||||
<ToggleSwitch
|
||||
Width="120"
|
||||
IsOn="{Binding Options.UnlockFps, Mode=TwoWay}"
|
||||
OffContent="{shcm:ResourceString Name=ViewPageLaunchGameUnlockFpsOff}"
|
||||
OnContent="{shcm:ResourceString Name=ViewPageLaunchGameUnlockFpsOn}"/>
|
||||
</clw:SettingsCard>
|
||||
<clw:SettingsCard Header="{shcm:ResourceString Name=ViewPageLaunchGameSetFpsHeader}">
|
||||
<clw:SettingsCard.Description>
|
||||
<StackPanel>
|
||||
<TextBlock Text="{shcm:ResourceString Name=ViewPageLaunchGameSetFpsDescription}"/>
|
||||
<TextBlock Text="{Binding Options.TargetFps}"/>
|
||||
</StackPanel>
|
||||
</clw:SettingsCard.Description>
|
||||
<Slider
|
||||
Width="400"
|
||||
Maximum="360"
|
||||
Minimum="60"
|
||||
Value="{Binding Options.TargetFps, Mode=TwoWay}"/>
|
||||
HeaderIcon="{shcm:FontIcon Glyph=}"
|
||||
IsEnabled="{Binding HutaoOptions.IsElevated}">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<NumberBox
|
||||
MinWidth="156"
|
||||
Padding="10,8,0,0"
|
||||
Maximum="720"
|
||||
Minimum="60"
|
||||
SpinButtonPlacementMode="Inline"
|
||||
Value="{Binding Options.TargetFps, Mode=TwoWay}"/>
|
||||
<ToggleSwitch
|
||||
Width="120"
|
||||
IsOn="{Binding Options.UnlockFps, Mode=TwoWay}"
|
||||
OffContent="{shcm:ResourceString Name=ViewPageLaunchGameUnlockFpsOff}"
|
||||
OnContent="{shcm:ResourceString Name=ViewPageLaunchGameUnlockFpsOn}"/>
|
||||
</StackPanel>
|
||||
</clw:SettingsCard>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
|
||||
@@ -211,7 +211,7 @@
|
||||
Description="{shcm:ResourceString Name=ViewPageSettingIsAdvancedLaunchOptionsEnabledDescription}"
|
||||
Header="{shcm:ResourceString Name=ViewPageSettingIsAdvancedLaunchOptionsEnabledHeader}"
|
||||
HeaderIcon="{shcm:FontIcon Glyph=}"
|
||||
IsEnabled="{Binding IsElevated}">
|
||||
IsEnabled="{Binding HutaoOptions.IsElevated}">
|
||||
<ToggleSwitch Width="120" IsOn="{Binding Options.IsAdvancedLaunchOptionsEnabled, Mode=TwoWay}"/>
|
||||
</clw:SettingsCard>
|
||||
<InfoBar
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using Snap.Hutao.Control.Extension;
|
||||
using Snap.Hutao.Core;
|
||||
using Snap.Hutao.Core.ExceptionService;
|
||||
using Snap.Hutao.Core.LifeCycle;
|
||||
using Snap.Hutao.Model.Entity;
|
||||
@@ -34,6 +35,7 @@ internal sealed partial class LaunchGameViewModel : Abstraction.ViewModel
|
||||
|
||||
private readonly IServiceProvider serviceProvider;
|
||||
private readonly LaunchOptions launchOptions;
|
||||
private readonly HutaoOptions hutaoOptions;
|
||||
private readonly ITaskContext taskContext;
|
||||
private readonly IGameService gameService;
|
||||
private readonly IMemoryCache memoryCache;
|
||||
@@ -81,6 +83,11 @@ internal sealed partial class LaunchGameViewModel : Abstraction.ViewModel
|
||||
/// </summary>
|
||||
public LaunchOptions Options { get => launchOptions; }
|
||||
|
||||
/// <summary>
|
||||
/// 胡桃选项
|
||||
/// </summary>
|
||||
public HutaoOptions HutaoOptions { get => hutaoOptions; }
|
||||
|
||||
/// <summary>
|
||||
/// 应用选项
|
||||
/// </summary>
|
||||
@@ -91,12 +98,6 @@ internal sealed partial class LaunchGameViewModel : Abstraction.ViewModel
|
||||
/// </summary>
|
||||
public GameResource? GameResource { get => gameResource; set => SetProperty(ref gameResource, value); }
|
||||
|
||||
/// <summary>
|
||||
/// 是否提权
|
||||
/// </summary>
|
||||
[SuppressMessage("", "CA1822")]
|
||||
public bool IsElevated { get => Activation.GetElevated(); }
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override async Task OpenUIAsync()
|
||||
{
|
||||
|
||||
@@ -100,15 +100,6 @@ internal sealed partial class SettingViewModel : Abstraction.ViewModel
|
||||
/// </summary>
|
||||
public ExperimentalFeaturesViewModel Experimental { get => experimental; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否提权
|
||||
/// </summary>
|
||||
[SuppressMessage("", "CA1822")]
|
||||
public bool IsElevated
|
||||
{
|
||||
get => Activation.GetElevated();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override Task OpenUIAsync()
|
||||
{
|
||||
|
||||
@@ -18,24 +18,18 @@ internal sealed class SpiralAbyssView
|
||||
/// <param name="idAvatarMap">Id角色映射</param>
|
||||
public SpiralAbyssView(Web.Hoyolab.Takumi.GameRecord.SpiralAbyss.SpiralAbyss spiralAbyss, Dictionary<AvatarId, Model.Metadata.Avatar.Avatar> idAvatarMap)
|
||||
{
|
||||
Schedule = string.Format(SH.ModelEntitySpiralAbyssScheduleFormat, spiralAbyss.ScheduleId);
|
||||
TotalBattleTimes = spiralAbyss.TotalBattleTimes;
|
||||
TotalStar = spiralAbyss.TotalStar;
|
||||
MaxFloor = spiralAbyss.MaxFloor;
|
||||
Reveals = spiralAbyss.RevealRank.Select(r => new RankAvatar(r.Value, r.AvatarId, idAvatarMap)).ToList();
|
||||
Reveals = spiralAbyss.RevealRank.SelectList(r => new RankAvatar(r.Value, r.AvatarId, idAvatarMap));
|
||||
Defeat = spiralAbyss.DefeatRank.Select(r => new RankAvatar(r.Value, r.AvatarId, idAvatarMap)).SingleOrDefault();
|
||||
Damage = spiralAbyss.DamageRank.Select(r => new RankAvatar(r.Value, r.AvatarId, idAvatarMap)).SingleOrDefault();
|
||||
TakeDamage = spiralAbyss.TakeDamageRank.Select(r => new RankAvatar(r.Value, r.AvatarId, idAvatarMap)).SingleOrDefault();
|
||||
NormalSkill = spiralAbyss.NormalSkillRank.Select(r => new RankAvatar(r.Value, r.AvatarId, idAvatarMap)).SingleOrDefault();
|
||||
EnergySkill = spiralAbyss.EnergySkillRank.Select(r => new RankAvatar(r.Value, r.AvatarId, idAvatarMap)).SingleOrDefault();
|
||||
Floors = spiralAbyss.Floors.Select(f => new FloorView(f, idAvatarMap)).ToList();
|
||||
Floors = spiralAbyss.Floors.Select(f => new FloorView(f, idAvatarMap)).Reverse().ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 期
|
||||
/// </summary>
|
||||
public string Schedule { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 战斗次数
|
||||
/// </summary>
|
||||
|
||||
@@ -19,7 +19,7 @@ internal static class CoreWebView2Extension
|
||||
/// <returns>链式调用的WebView2</returns>
|
||||
public static CoreWebView2 SetMobileUserAgent(this CoreWebView2 webView)
|
||||
{
|
||||
webView.Settings.UserAgent = Core.HoyolabOptions.MobileUserAgent;
|
||||
webView.Settings.UserAgent = HoyolabOptions.MobileUserAgent;
|
||||
return webView;
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ internal static class CoreWebView2Extension
|
||||
/// <returns>链式调用的WebView2</returns>
|
||||
public static CoreWebView2 SetMobileOverseaUserAgent(this CoreWebView2 webView)
|
||||
{
|
||||
webView.Settings.UserAgent = Core.HoyolabOptions.MobileUserAgentOversea;
|
||||
webView.Settings.UserAgent = HoyolabOptions.MobileUserAgentOversea;
|
||||
return webView;
|
||||
}
|
||||
|
||||
|
||||
@@ -88,8 +88,8 @@ internal class MiHoYoJSInterface
|
||||
Data = new Dictionary<string, string>()
|
||||
{
|
||||
{ "x-rpc-client_type", "5" },
|
||||
{ "x-rpc-device_id", Core.HoyolabOptions.DeviceId },
|
||||
{ "x-rpc-app_version", Core.HoyolabOptions.XrpcVersion },
|
||||
{ "x-rpc-device_id", HoyolabOptions.DeviceId },
|
||||
{ "x-rpc-app_version", HoyolabOptions.XrpcVersion },
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -121,7 +121,7 @@ internal class MiHoYoJSInterface
|
||||
/// <returns>响应</returns>
|
||||
public virtual JsResult<Dictionary<string, string>> GetDynamicSecrectV1(JsParam param)
|
||||
{
|
||||
string salt = Core.HoyolabOptions.Salts[SaltType.LK2];
|
||||
string salt = HoyolabOptions.Salts[SaltType.LK2];
|
||||
long t = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
|
||||
string r = GetRandomString();
|
||||
string check = Core.Convert.ToMd5HexString($"salt={salt}&t={t}&r={r}").ToLowerInvariant();
|
||||
@@ -152,7 +152,7 @@ internal class MiHoYoJSInterface
|
||||
public virtual JsResult<Dictionary<string, string>> GetDynamicSecrectV2(JsParam<DynamicSecrect2Playload> param)
|
||||
{
|
||||
// TODO: Salt X4 for hoyolab user
|
||||
string salt = Core.HoyolabOptions.Salts[SaltType.X4];
|
||||
string salt = HoyolabOptions.Salts[SaltType.X4];
|
||||
long t = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
|
||||
int r = GetRandom();
|
||||
string b = param.Payload.Body;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
using Microsoft.Web.WebView2.Core;
|
||||
using Snap.Hutao.Web.Bridge.Model;
|
||||
using Snap.Hutao.Web.Hoyolab;
|
||||
|
||||
namespace Snap.Hutao.Web.Bridge;
|
||||
|
||||
@@ -35,8 +36,8 @@ internal sealed class SignInJSInterfaceOversea : MiHoYoJSInterface
|
||||
Data = new Dictionary<string, string>()
|
||||
{
|
||||
{ "x-rpc-client_type", "2" },
|
||||
{ "x-rpc-device_id", Core.HoyolabOptions.DeviceId },
|
||||
{ "x-rpc-app_version", Core.HoyolabOptions.XrpcVersionOversea },
|
||||
{ "x-rpc-device_id", HoyolabOptions.DeviceId },
|
||||
{ "x-rpc-app_version", HoyolabOptions.XrpcVersionOversea },
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
using Microsoft.Web.WebView2.Core;
|
||||
using Snap.Hutao.Web.Bridge.Model;
|
||||
using Snap.Hutao.Web.Hoyolab;
|
||||
|
||||
namespace Snap.Hutao.Web.Bridge;
|
||||
|
||||
@@ -26,8 +27,8 @@ internal sealed class SignInJsInterface : MiHoYoJSInterface
|
||||
Data = new Dictionary<string, string>()
|
||||
{
|
||||
{ "x-rpc-client_type", "2" },
|
||||
{ "x-rpc-device_id", Core.HoyolabOptions.DeviceId },
|
||||
{ "x-rpc-app_version", Core.HoyolabOptions.XrpcVersion },
|
||||
{ "x-rpc-device_id", HoyolabOptions.DeviceId },
|
||||
{ "x-rpc-app_version", HoyolabOptions.XrpcVersion },
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ internal sealed class DynamicSecretHandler : DelegatingHandler
|
||||
|
||||
private static async Task ProcessRequestWithOptionsAsync(HttpRequestMessage request, DynamicSecretCreationOptions options, CancellationToken token)
|
||||
{
|
||||
string salt = Core.HoyolabOptions.Salts[options.SaltType];
|
||||
string salt = HoyolabOptions.Salts[options.SaltType];
|
||||
|
||||
long t = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ using Microsoft.Extensions.Options;
|
||||
using Snap.Hutao.Web.Hoyolab.DynamicSecret;
|
||||
using System.Collections.Immutable;
|
||||
|
||||
namespace Snap.Hutao.Core;
|
||||
namespace Snap.Hutao.Web.Hoyolab;
|
||||
|
||||
/// <summary>
|
||||
/// 米游社选项
|
||||
Reference in New Issue
Block a user