mirror of
https://jihulab.com/DGP-Studio/Snap.Hutao.git
synced 2025-11-19 21:02:53 +08:00
Compare commits
10 Commits
ref/disabl
...
opt/launch
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
031cf77c27 | ||
|
|
3200c5e60b | ||
|
|
b392a6f8e5 | ||
|
|
3e8e109123 | ||
|
|
91c886befb | ||
|
|
32bdfe12af | ||
|
|
eac67b6f44 | ||
|
|
0dcba220c5 | ||
|
|
db15b6a30c | ||
|
|
1b0356b5ef |
@@ -5,6 +5,7 @@ using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Markup;
|
||||
using Microsoft.UI.Xaml.Navigation;
|
||||
using Snap.Hutao.Core.Abstraction;
|
||||
using Snap.Hutao.Service.Navigation;
|
||||
using Snap.Hutao.View.Helper;
|
||||
using Snap.Hutao.ViewModel.Abstraction;
|
||||
@@ -53,9 +54,14 @@ internal class ScopedPage : Page
|
||||
{
|
||||
try
|
||||
{
|
||||
IViewModel viewModel = pageScope.ServiceProvider.GetRequiredService<TViewModel>();
|
||||
viewModel.CancellationToken = viewCancellationTokenSource.Token;
|
||||
viewModel.DeferContentLoader = new DeferContentLoader(this);
|
||||
TViewModel viewModel = pageScope.ServiceProvider.GetRequiredService<TViewModel>();
|
||||
using (viewModel.DisposeLock.Enter())
|
||||
{
|
||||
viewModel.IsViewDisposed = false;
|
||||
viewModel.CancellationToken = viewCancellationTokenSource.Token;
|
||||
viewModel.DeferContentLoader = new DeferContentLoader(this);
|
||||
}
|
||||
|
||||
DataContext = viewModel;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -104,13 +110,15 @@ internal class ScopedPage : Page
|
||||
viewCancellationTokenSource.Cancel();
|
||||
IViewModel viewModel = (IViewModel)DataContext;
|
||||
|
||||
// Wait to ensure viewmodel operation is completed
|
||||
viewModel.DisposeLock.Wait();
|
||||
viewModel.IsViewDisposed = true;
|
||||
using (viewModel.DisposeLock.Enter())
|
||||
{
|
||||
// Wait to ensure viewmodel operation is completed
|
||||
viewModel.IsViewDisposed = true;
|
||||
|
||||
// Dispose the scope
|
||||
pageScope.Dispose();
|
||||
GC.Collect(GC.MaxGeneration, GCCollectionMode.Aggressive, true);
|
||||
// Dispose the scope
|
||||
pageScope.Dispose();
|
||||
GC.Collect(GC.MaxGeneration, GCCollectionMode.Aggressive, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,5 +5,5 @@ namespace Snap.Hutao.Core.Abstraction;
|
||||
|
||||
internal interface IPinnable<TData>
|
||||
{
|
||||
ref readonly TData GetPinnableReference();
|
||||
ref TData GetPinnableReference();
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
namespace Snap.Hutao.Core.Abstraction;
|
||||
|
||||
internal interface IResurrectable
|
||||
{
|
||||
void Resurrect();
|
||||
}
|
||||
@@ -96,25 +96,31 @@ internal sealed partial class AppActivation : IAppActivation, IAppActivationActi
|
||||
|
||||
await taskContext.SwitchToMainThreadAsync();
|
||||
|
||||
if (currentWindowReference.Window is null)
|
||||
switch (currentWindowReference.Window)
|
||||
{
|
||||
currentWindowReference.Window = serviceProvider.GetRequiredService<LaunchGameWindow>();
|
||||
return;
|
||||
}
|
||||
case null:
|
||||
LaunchGameWindow launchGameWindow = serviceProvider.GetRequiredService<LaunchGameWindow>();
|
||||
currentWindowReference.Window = launchGameWindow;
|
||||
|
||||
if (currentWindowReference.Window is MainWindow)
|
||||
{
|
||||
await serviceProvider
|
||||
.GetRequiredService<INavigationService>()
|
||||
.NavigateAsync<View.Page.LaunchGamePage>(INavigationAwaiter.Default, true)
|
||||
.ConfigureAwait(false);
|
||||
launchGameWindow.SwitchTo();
|
||||
launchGameWindow.BringToForeground();
|
||||
return;
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
// We have a non-Main Window, just exit current process anyway
|
||||
Process.GetCurrentProcess().Kill();
|
||||
case MainWindow:
|
||||
await serviceProvider
|
||||
.GetRequiredService<INavigationService>()
|
||||
.NavigateAsync<View.Page.LaunchGamePage>(INavigationAwaiter.Default, true)
|
||||
.ConfigureAwait(false);
|
||||
return;
|
||||
|
||||
case LaunchGameWindow currentLaunchGameWindow:
|
||||
currentLaunchGameWindow.SwitchTo();
|
||||
currentLaunchGameWindow.BringToForeground();
|
||||
return;
|
||||
|
||||
default:
|
||||
Process.GetCurrentProcess().Kill();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -63,7 +63,8 @@ internal static class WindowExtension
|
||||
{
|
||||
ShowWindow(hwnd, SHOW_WINDOW_CMD.SW_SHOW);
|
||||
}
|
||||
else if (IsIconic(hwnd))
|
||||
|
||||
if (IsIconic(hwnd))
|
||||
{
|
||||
ShowWindow(hwnd, SHOW_WINDOW_CMD.SW_RESTORE);
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ internal sealed class Material : DisplayItem
|
||||
DayOfWeek.Monday or DayOfWeek.Thursday => Materials.MondayThursdayItems.Contains(Id),
|
||||
DayOfWeek.Tuesday or DayOfWeek.Friday => Materials.TuesdayFridayItems.Contains(Id),
|
||||
DayOfWeek.Wednesday or DayOfWeek.Saturday => Materials.WednesdaySaturdayItems.Contains(Id),
|
||||
_ => treatSundayAsTrue,
|
||||
_ => treatSundayAsTrue && (Materials.MondayThursdayItems.Contains(Id) || Materials.TuesdayFridayItems.Contains(Id) || Materials.WednesdaySaturdayItems.Contains(Id)),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Service.Game.Scheme;
|
||||
using System.IO;
|
||||
|
||||
namespace Snap.Hutao.Service.Game;
|
||||
@@ -38,4 +39,6 @@ internal sealed class GameFileSystem
|
||||
public string PCGameSDKFilePath { get => pcGameSDKFilePath ??= Path.Combine(GameDirectory, GameConstants.PCGameSDKFilePath); }
|
||||
|
||||
public string ScreenShotDirectory { get => Path.Combine(GameDirectory, "ScreenShot"); }
|
||||
|
||||
public string DataDirectory { get => Path.Combine(GameDirectory, LaunchScheme.ExecutableIsOversea(GameFileName) ? GameConstants.GenshinImpactData : GameConstants.YuanShenData); }
|
||||
}
|
||||
@@ -19,7 +19,12 @@ internal sealed class LaunchExecutionUnlockFpsHandler : ILaunchExecutionDelegate
|
||||
|
||||
IProgressFactory progressFactory = context.ServiceProvider.GetRequiredService<IProgressFactory>();
|
||||
IProgress<GameFpsUnlockerContext> progress = progressFactory.CreateForMainThread<GameFpsUnlockerContext>(c => context.Progress.Report(LaunchStatus.FromUnlockerContext(c)));
|
||||
GameFpsUnlocker unlocker = new(context.ServiceProvider, context.Process, new(100, 20000, 3000), progress);
|
||||
if (!context.TryGetGameFileSystem(out GameFileSystem? gameFileSystem))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
GameFpsUnlocker unlocker = new(context.ServiceProvider, context.Process, new(gameFileSystem, 100, 20000, 3000), progress);
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
@@ -16,43 +16,30 @@ internal static class GameFpsAddress
|
||||
private const byte ASM_JMP = 0xE9;
|
||||
#pragma warning restore SA1310
|
||||
|
||||
public static unsafe void UnsafeFindFpsAddress(GameFpsUnlockerContext state, in RequiredGameModule requiredGameModule)
|
||||
public static unsafe void UnsafeFindFpsAddress(GameFpsUnlockerContext context, in RequiredRemoteModule remoteModule, in RequiredLocalModule localModule)
|
||||
{
|
||||
bool readOk = UnsafeReadModulesMemory(state.GameProcess, requiredGameModule, out VirtualMemory localMemory);
|
||||
HutaoException.ThrowIfNot(readOk, SH.ServiceGameUnlockerReadModuleMemoryCopyVirtualMemoryFailed);
|
||||
int offsetToUserAssembly = IndexOfPattern(localModule.UserAssembly.AsSpan());
|
||||
HutaoException.ThrowIfNot(offsetToUserAssembly >= 0, SH.ServiceGameUnlockerInterestedPatternNotFound);
|
||||
|
||||
using (localMemory)
|
||||
nuint rip = localModule.UserAssembly.Address + (uint)offsetToUserAssembly;
|
||||
rip += 5U;
|
||||
rip += (nuint)(*(int*)(rip + 2U) + 6);
|
||||
|
||||
nuint remoteVirtualAddress = remoteModule.UserAssembly.Address + (rip - localModule.UserAssembly.Address);
|
||||
|
||||
nuint ptr = 0;
|
||||
SpinWait.SpinUntil(() => UnsafeReadProcessMemory(context.GameProcess, remoteVirtualAddress, out ptr) && ptr != 0);
|
||||
|
||||
nuint localVirtualAddress = ptr - remoteModule.UnityPlayer.Address + localModule.UnityPlayer.Address;
|
||||
|
||||
while (*(byte*)localVirtualAddress is ASM_CALL or ASM_JMP)
|
||||
{
|
||||
int offset = IndexOfPattern(localMemory.AsSpan()[(int)requiredGameModule.UnityPlayer.Size..]);
|
||||
HutaoException.ThrowIfNot(offset >= 0, SH.ServiceGameUnlockerInterestedPatternNotFound);
|
||||
|
||||
byte* pLocalMemory = (byte*)localMemory.Pointer;
|
||||
ref readonly Module unityPlayer = ref requiredGameModule.UnityPlayer;
|
||||
ref readonly Module userAssembly = ref requiredGameModule.UserAssembly;
|
||||
|
||||
nuint localMemoryUnityPlayerAddress = (nuint)pLocalMemory;
|
||||
nuint localMemoryUserAssemblyAddress = localMemoryUnityPlayerAddress + unityPlayer.Size;
|
||||
|
||||
nuint rip = localMemoryUserAssemblyAddress + (uint)offset;
|
||||
rip += 5U;
|
||||
rip += (nuint)(*(int*)(rip + 2U) + 6);
|
||||
|
||||
nuint address = userAssembly.Address + (rip - localMemoryUserAssemblyAddress);
|
||||
|
||||
nuint ptr = 0;
|
||||
SpinWait.SpinUntil(() => UnsafeReadProcessMemory(state.GameProcess, address, out ptr) && ptr != 0);
|
||||
|
||||
rip = ptr - unityPlayer.Address + localMemoryUnityPlayerAddress;
|
||||
|
||||
while (*(byte*)rip is ASM_CALL or ASM_JMP)
|
||||
{
|
||||
rip += (nuint)(*(int*)(rip + 1) + 5);
|
||||
}
|
||||
|
||||
nuint localMemoryActualAddress = rip + *(uint*)(rip + 2) + 6;
|
||||
nuint actualOffset = localMemoryActualAddress - localMemoryUnityPlayerAddress;
|
||||
state.FpsAddress = unityPlayer.Address + actualOffset;
|
||||
localVirtualAddress += (nuint)(*(int*)(localVirtualAddress + 1) + 5);
|
||||
}
|
||||
|
||||
localVirtualAddress += *(uint*)(localVirtualAddress + 2) + 6;
|
||||
nuint relativeVirtualAddress = localVirtualAddress - localModule.UnityPlayer.Address;
|
||||
context.FpsAddress = remoteModule.UnityPlayer.Address + relativeVirtualAddress;
|
||||
}
|
||||
|
||||
private static int IndexOfPattern(in ReadOnlySpan<byte> memory)
|
||||
@@ -62,16 +49,6 @@ internal static class GameFpsAddress
|
||||
return memory.IndexOf(part);
|
||||
}
|
||||
|
||||
private static unsafe bool UnsafeReadModulesMemory(Process process, in RequiredGameModule moduleEntryInfo, out VirtualMemory memory)
|
||||
{
|
||||
ref readonly Module unityPlayer = ref moduleEntryInfo.UnityPlayer;
|
||||
ref readonly Module userAssembly = ref moduleEntryInfo.UserAssembly;
|
||||
|
||||
memory = new VirtualMemory(unityPlayer.Size + userAssembly.Size);
|
||||
return ReadProcessMemory(process.Handle, (void*)unityPlayer.Address, memory.AsSpan()[..(int)unityPlayer.Size], out _)
|
||||
&& ReadProcessMemory(process.Handle, (void*)userAssembly.Address, memory.AsSpan()[(int)unityPlayer.Size..], out _);
|
||||
}
|
||||
|
||||
private static unsafe bool UnsafeReadProcessMemory(Process process, nuint baseAddress, out nuint value)
|
||||
{
|
||||
value = 0;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
using Snap.Hutao.Core.ExceptionService;
|
||||
using Snap.Hutao.Win32.Foundation;
|
||||
using Snap.Hutao.Win32.System.LibraryLoader;
|
||||
using System.Diagnostics;
|
||||
using static Snap.Hutao.Win32.Kernel32;
|
||||
|
||||
@@ -18,12 +19,12 @@ internal sealed class GameFpsUnlocker : IGameFpsUnlocker
|
||||
private readonly LaunchOptions launchOptions;
|
||||
private readonly GameFpsUnlockerContext context = new();
|
||||
|
||||
public GameFpsUnlocker(IServiceProvider serviceProvider, Process gameProcess, in UnlockTimingOptions options, IProgress<GameFpsUnlockerContext> progress)
|
||||
public GameFpsUnlocker(IServiceProvider serviceProvider, Process gameProcess, in UnlockOptions options, IProgress<GameFpsUnlockerContext> progress)
|
||||
{
|
||||
launchOptions = serviceProvider.GetRequiredService<LaunchOptions>();
|
||||
|
||||
context.GameProcess = gameProcess;
|
||||
context.TimingOptions = options;
|
||||
context.Options = options;
|
||||
context.Progress = progress;
|
||||
}
|
||||
|
||||
@@ -31,18 +32,22 @@ internal sealed class GameFpsUnlocker : IGameFpsUnlocker
|
||||
public async ValueTask<bool> UnlockAsync(CancellationToken token = default)
|
||||
{
|
||||
HutaoException.ThrowIfNot(context.IsUnlockerValid, "This Unlocker is invalid");
|
||||
(FindModuleResult result, RequiredGameModule gameModule) = await GameProcessModule.FindModuleAsync(context).ConfigureAwait(false);
|
||||
(FindModuleResult result, RequiredRemoteModule remoteModule) = await GameProcessModule.FindModuleAsync(context).ConfigureAwait(false);
|
||||
HutaoException.ThrowIfNot(result != FindModuleResult.TimeLimitExeeded, SH.ServiceGameUnlockerFindModuleTimeLimitExeeded);
|
||||
HutaoException.ThrowIfNot(result != FindModuleResult.NoModuleFound, SH.ServiceGameUnlockerFindModuleNoModuleFound);
|
||||
|
||||
GameFpsAddress.UnsafeFindFpsAddress(context, gameModule);
|
||||
using (RequiredLocalModule localModule = LoadRequiredLocalModule(context.Options.GameFileSystem))
|
||||
{
|
||||
GameFpsAddress.UnsafeFindFpsAddress(context, remoteModule, localModule);
|
||||
}
|
||||
|
||||
context.Report();
|
||||
return context.FpsAddress != 0U;
|
||||
}
|
||||
|
||||
public async ValueTask PostUnlockAsync(CancellationToken token = default)
|
||||
{
|
||||
using (PeriodicTimer timer = new(context.TimingOptions.AdjustFpsDelay))
|
||||
using (PeriodicTimer timer = new(context.Options.AdjustFpsDelay))
|
||||
{
|
||||
while (await timer.WaitForNextTickAsync(token).ConfigureAwait(false))
|
||||
{
|
||||
@@ -66,4 +71,15 @@ internal sealed class GameFpsUnlocker : IGameFpsUnlocker
|
||||
{
|
||||
return WriteProcessMemory((HANDLE)process.Handle, (void*)baseAddress, ref value, out _);
|
||||
}
|
||||
|
||||
private static RequiredLocalModule LoadRequiredLocalModule(GameFileSystem gameFileSystem)
|
||||
{
|
||||
string gameFoler = gameFileSystem.GameDirectory;
|
||||
string dataFoler = gameFileSystem.DataDirectory;
|
||||
LOAD_LIBRARY_FLAGS flags = LOAD_LIBRARY_FLAGS.LOAD_LIBRARY_AS_IMAGE_RESOURCE;
|
||||
HMODULE unityPlayerAddress = LoadLibraryExW(System.IO.Path.Combine(gameFoler, "UnityPlayer.dll"), default, flags);
|
||||
HMODULE userAssemblyAddress = LoadLibraryExW(System.IO.Path.Combine(dataFoler, "Native", "UserAssembly.dll"), default, flags);
|
||||
|
||||
return new(unityPlayerAddress, userAssemblyAddress);
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ internal sealed class GameFpsUnlockerContext
|
||||
|
||||
public nuint FpsAddress { get; set; }
|
||||
|
||||
public UnlockTimingOptions TimingOptions { get; set; }
|
||||
public UnlockOptions Options { get; set; }
|
||||
|
||||
public Process GameProcess { get; set; } = default!;
|
||||
|
||||
|
||||
@@ -12,14 +12,14 @@ namespace Snap.Hutao.Service.Game.Unlocker;
|
||||
|
||||
internal static class GameProcessModule
|
||||
{
|
||||
public static async ValueTask<ValueResult<FindModuleResult, RequiredGameModule>> FindModuleAsync(GameFpsUnlockerContext state)
|
||||
public static async ValueTask<ValueResult<FindModuleResult, RequiredRemoteModule>> FindModuleAsync(GameFpsUnlockerContext state)
|
||||
{
|
||||
ValueStopwatch watch = ValueStopwatch.StartNew();
|
||||
using (PeriodicTimer timer = new(state.TimingOptions.FindModuleDelay))
|
||||
using (PeriodicTimer timer = new(state.Options.FindModuleDelay))
|
||||
{
|
||||
while (await timer.WaitForNextTickAsync().ConfigureAwait(false))
|
||||
{
|
||||
FindModuleResult result = UnsafeGetGameModuleInfo((HANDLE)state.GameProcess.Handle, out RequiredGameModule gameModule);
|
||||
FindModuleResult result = UnsafeGetGameModuleInfo((HANDLE)state.GameProcess.Handle, out RequiredRemoteModule gameModule);
|
||||
if (result == FindModuleResult.Ok)
|
||||
{
|
||||
return new(FindModuleResult.Ok, gameModule);
|
||||
@@ -30,7 +30,7 @@ internal static class GameProcessModule
|
||||
return new(FindModuleResult.NoModuleFound, default);
|
||||
}
|
||||
|
||||
if (watch.GetElapsedTime() > state.TimingOptions.FindModuleLimit)
|
||||
if (watch.GetElapsedTime() > state.Options.FindModuleLimit)
|
||||
{
|
||||
break;
|
||||
}
|
||||
@@ -40,7 +40,7 @@ internal static class GameProcessModule
|
||||
return new(FindModuleResult.TimeLimitExeeded, default);
|
||||
}
|
||||
|
||||
private static FindModuleResult UnsafeGetGameModuleInfo(in HANDLE hProcess, out RequiredGameModule info)
|
||||
private static FindModuleResult UnsafeGetGameModuleInfo(in HANDLE hProcess, out RequiredRemoteModule info)
|
||||
{
|
||||
FindModuleResult unityPlayerResult = UnsafeFindModule(hProcess, "UnityPlayer.dll", out Module unityPlayer);
|
||||
FindModuleResult userAssemblyResult = UnsafeFindModule(hProcess, "UserAssembly.dll", out Module userAssembly);
|
||||
|
||||
@@ -15,4 +15,9 @@ internal readonly struct Module
|
||||
Address = address;
|
||||
Size = size;
|
||||
}
|
||||
|
||||
public unsafe Span<byte> AsSpan()
|
||||
{
|
||||
return new((void*)Address, (int)Size);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Win32.Foundation;
|
||||
using Snap.Hutao.Win32.System.Diagnostics.Debug;
|
||||
using Snap.Hutao.Win32.System.SystemService;
|
||||
using System.Runtime.CompilerServices;
|
||||
using static Snap.Hutao.Win32.Kernel32;
|
||||
|
||||
namespace Snap.Hutao.Service.Game.Unlocker;
|
||||
|
||||
internal readonly struct RequiredLocalModule : IDisposable
|
||||
{
|
||||
public readonly bool HasValue = false;
|
||||
public readonly Module UnityPlayer;
|
||||
public readonly Module UserAssembly;
|
||||
|
||||
[SuppressMessage("", "SH002")]
|
||||
public RequiredLocalModule(HMODULE unityPlayer, HMODULE userAssembly)
|
||||
{
|
||||
// Align the pointer
|
||||
unityPlayer = (nint)(unityPlayer & ~0x3L);
|
||||
userAssembly = (nint)(userAssembly & ~0x3L);
|
||||
|
||||
HasValue = true;
|
||||
UnityPlayer = new((nuint)(nint)unityPlayer, GetImageSize(unityPlayer));
|
||||
UserAssembly = new((nuint)(nint)userAssembly, GetImageSize(userAssembly));
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
FreeLibrary((nint)UnityPlayer.Address);
|
||||
FreeLibrary((nint)UserAssembly.Address);
|
||||
}
|
||||
|
||||
[SuppressMessage("", "SH002")]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private unsafe uint GetImageSize(HMODULE hModule)
|
||||
{
|
||||
IMAGE_DOS_HEADER* pImageDosHeader = (IMAGE_DOS_HEADER*)(nint)hModule;
|
||||
IMAGE_NT_HEADERS64* pImageNtHeader = (IMAGE_NT_HEADERS64*)(pImageDosHeader->e_lfanew + hModule);
|
||||
return pImageNtHeader->OptionalHeader.SizeOfImage;
|
||||
}
|
||||
}
|
||||
@@ -3,13 +3,13 @@
|
||||
|
||||
namespace Snap.Hutao.Service.Game.Unlocker;
|
||||
|
||||
internal readonly struct RequiredGameModule
|
||||
internal readonly struct RequiredRemoteModule
|
||||
{
|
||||
public readonly bool HasValue = false;
|
||||
public readonly Module UnityPlayer;
|
||||
public readonly Module UserAssembly;
|
||||
|
||||
public RequiredGameModule(in Module unityPlayer, in Module userAssembly)
|
||||
public RequiredRemoteModule(in Module unityPlayer, in Module userAssembly)
|
||||
{
|
||||
HasValue = true;
|
||||
UnityPlayer = unityPlayer;
|
||||
@@ -0,0 +1,20 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
namespace Snap.Hutao.Service.Game.Unlocker;
|
||||
|
||||
internal readonly struct UnlockOptions
|
||||
{
|
||||
public readonly GameFileSystem GameFileSystem;
|
||||
public readonly TimeSpan FindModuleDelay;
|
||||
public readonly TimeSpan FindModuleLimit;
|
||||
public readonly TimeSpan AdjustFpsDelay;
|
||||
|
||||
public UnlockOptions(GameFileSystem gameFileSystem, int findModuleDelayMilliseconds, int findModuleLimitMilliseconds, int adjustFpsDelayMilliseconds)
|
||||
{
|
||||
GameFileSystem = gameFileSystem;
|
||||
FindModuleDelay = TimeSpan.FromMilliseconds(findModuleDelayMilliseconds);
|
||||
FindModuleLimit = TimeSpan.FromMilliseconds(findModuleLimitMilliseconds);
|
||||
AdjustFpsDelay = TimeSpan.FromMilliseconds(adjustFpsDelayMilliseconds);
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
namespace Snap.Hutao.Service.Game.Unlocker;
|
||||
|
||||
/// <summary>
|
||||
/// 解锁时机选项
|
||||
/// </summary>
|
||||
internal readonly struct UnlockTimingOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// 每次查找 Module 的延时
|
||||
/// </summary>
|
||||
public readonly TimeSpan FindModuleDelay;
|
||||
|
||||
/// <summary>
|
||||
/// 查找 Module 的最大时间阈值
|
||||
/// </summary>
|
||||
public readonly TimeSpan FindModuleLimit;
|
||||
|
||||
/// <summary>
|
||||
/// 每次循环调整的间隔时间
|
||||
/// </summary>
|
||||
public readonly TimeSpan AdjustFpsDelay;
|
||||
|
||||
/// <summary>
|
||||
/// 构造一个新的解锁器选项
|
||||
/// </summary>
|
||||
/// <param name="findModuleDelayMilliseconds">每次查找UnityPlayer的延时,推荐100毫秒</param>
|
||||
/// <param name="findModuleLimitMilliseconds">查找UnityPlayer的最大阈值,推荐10000毫秒</param>
|
||||
/// <param name="adjustFpsDelayMilliseconds">每次循环调整的间隔时间,推荐2000毫秒</param>
|
||||
public UnlockTimingOptions(int findModuleDelayMilliseconds, int findModuleLimitMilliseconds, int adjustFpsDelayMilliseconds)
|
||||
{
|
||||
FindModuleDelay = TimeSpan.FromMilliseconds(findModuleDelayMilliseconds);
|
||||
FindModuleLimit = TimeSpan.FromMilliseconds(findModuleLimitMilliseconds);
|
||||
AdjustFpsDelay = TimeSpan.FromMilliseconds(adjustFpsDelayMilliseconds);
|
||||
}
|
||||
}
|
||||
@@ -100,6 +100,6 @@ internal sealed partial class LaunchGameShared
|
||||
[Command("HandleGamePathNullOrEmptyCommand")]
|
||||
private void HandleGamePathNullOrEmpty()
|
||||
{
|
||||
navigationService.Navigate<LaunchGamePage>(INavigationAwaiter.Default);
|
||||
navigationService.Navigate<LaunchGamePage>(INavigationAwaiter.Default, true);
|
||||
}
|
||||
}
|
||||
@@ -8,4 +8,8 @@ namespace Snap.Hutao.Win32.Foundation;
|
||||
internal readonly struct HMODULE
|
||||
{
|
||||
public readonly nint Value;
|
||||
|
||||
public static unsafe implicit operator HMODULE(nint value) => *(HMODULE*)&value;
|
||||
|
||||
public static unsafe implicit operator nint(HMODULE module) => *(nint*)&module;
|
||||
}
|
||||
@@ -4,6 +4,7 @@
|
||||
using Snap.Hutao.Win32.Foundation;
|
||||
using Snap.Hutao.Win32.Security;
|
||||
using Snap.Hutao.Win32.System.Console;
|
||||
using Snap.Hutao.Win32.System.LibraryLoader;
|
||||
using Snap.Hutao.Win32.System.ProcessStatus;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
@@ -41,6 +42,10 @@ internal static class Kernel32
|
||||
[DllImport("KERNEL32.dll", CallingConvention = CallingConvention.Winapi, ExactSpelling = true)]
|
||||
public static extern BOOL FreeConsole();
|
||||
|
||||
[DllImport("KERNEL32.dll", CallingConvention = CallingConvention.Winapi, ExactSpelling = true)]
|
||||
[SupportedOSPlatform("windows5.1.2600")]
|
||||
public static extern BOOL FreeLibrary(HMODULE hLibModule);
|
||||
|
||||
[DllImport("KERNEL32.dll", CallingConvention = CallingConvention.Winapi, ExactSpelling = true)]
|
||||
public static unsafe extern BOOL GetConsoleMode(HANDLE hConsoleHandle, CONSOLE_MODE* lpMode);
|
||||
|
||||
@@ -96,6 +101,19 @@ internal static class Kernel32
|
||||
}
|
||||
}
|
||||
|
||||
[DllImport("KERNEL32.dll", CallingConvention = CallingConvention.Winapi, ExactSpelling = true)]
|
||||
[SupportedOSPlatform("windows5.1.2600")]
|
||||
public static extern HMODULE LoadLibraryExW(PCWSTR lpLibFileName, [AllowNull] HANDLE hFile, LOAD_LIBRARY_FLAGS dwFlags);
|
||||
|
||||
[DebuggerStepThrough]
|
||||
public static unsafe HMODULE LoadLibraryExW(ReadOnlySpan<char> libFileName, [AllowNull] HANDLE hFile, LOAD_LIBRARY_FLAGS dwFlags)
|
||||
{
|
||||
fixed (char* lpLibFileName = libFileName)
|
||||
{
|
||||
return LoadLibraryExW(lpLibFileName, hFile, dwFlags);
|
||||
}
|
||||
}
|
||||
|
||||
[DllImport("KERNEL32.dll", CallingConvention = CallingConvention.Winapi, ExactSpelling = true)]
|
||||
[SupportedOSPlatform("windows5.1.2600")]
|
||||
public static unsafe extern BOOL ReadProcessMemory(HANDLE hProcess, void* lpBaseAddress, void* lpBuffer, nuint nSize, [MaybeNull] nuint* lpNumberOfBytesRead);
|
||||
|
||||
@@ -159,4 +159,4 @@ internal enum FACILITY_CODE : uint
|
||||
FACILITY_GAME = 2340u,
|
||||
FACILITY_PIX = 2748u,
|
||||
FACILITY_NT_BIT = 268435456u,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
namespace Snap.Hutao.Win32.System.Diagnostics.Debug;
|
||||
|
||||
internal struct IMAGE_DATA_DIRECTORY
|
||||
{
|
||||
public uint VirtualAddress;
|
||||
public uint Size;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
namespace Snap.Hutao.Win32.System.Diagnostics.Debug;
|
||||
|
||||
[Flags]
|
||||
internal enum IMAGE_DLL_CHARACTERISTICS : ushort
|
||||
{
|
||||
IMAGE_DLLCHARACTERISTICS_HIGH_ENTROPY_VA = 0x20,
|
||||
IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE = 0x40,
|
||||
IMAGE_DLLCHARACTERISTICS_FORCE_INTEGRITY = 0x80,
|
||||
IMAGE_DLLCHARACTERISTICS_NX_COMPAT = 0x100,
|
||||
IMAGE_DLLCHARACTERISTICS_NO_ISOLATION = 0x200,
|
||||
IMAGE_DLLCHARACTERISTICS_NO_SEH = 0x400,
|
||||
IMAGE_DLLCHARACTERISTICS_NO_BIND = 0x800,
|
||||
IMAGE_DLLCHARACTERISTICS_APPCONTAINER = 0x1000,
|
||||
IMAGE_DLLCHARACTERISTICS_WDM_DRIVER = 0x2000,
|
||||
IMAGE_DLLCHARACTERISTICS_GUARD_CF = 0x4000,
|
||||
IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE = 0x8000,
|
||||
IMAGE_DLLCHARACTERISTICS_EX_CET_COMPAT = 1,
|
||||
IMAGE_DLLCHARACTERISTICS_EX_CET_COMPAT_STRICT_MODE = 2,
|
||||
IMAGE_DLLCHARACTERISTICS_EX_CET_SET_CONTEXT_IP_VALIDATION_RELAXED_MODE = 4,
|
||||
IMAGE_DLLCHARACTERISTICS_EX_CET_DYNAMIC_APIS_ALLOW_IN_PROC = 8,
|
||||
IMAGE_DLLCHARACTERISTICS_EX_CET_RESERVED_1 = 0x10,
|
||||
IMAGE_DLLCHARACTERISTICS_EX_CET_RESERVED_2 = 0x20,
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
namespace Snap.Hutao.Win32.System.Diagnostics.Debug;
|
||||
|
||||
[Flags]
|
||||
internal enum IMAGE_FILE_CHARACTERISTICS : ushort
|
||||
{
|
||||
IMAGE_FILE_RELOCS_STRIPPED = 0x1,
|
||||
IMAGE_FILE_EXECUTABLE_IMAGE = 0x2,
|
||||
IMAGE_FILE_LINE_NUMS_STRIPPED = 0x4,
|
||||
IMAGE_FILE_LOCAL_SYMS_STRIPPED = 0x8,
|
||||
IMAGE_FILE_AGGRESIVE_WS_TRIM = 0x10,
|
||||
IMAGE_FILE_LARGE_ADDRESS_AWARE = 0x20,
|
||||
IMAGE_FILE_BYTES_REVERSED_LO = 0x80,
|
||||
IMAGE_FILE_32BIT_MACHINE = 0x100,
|
||||
IMAGE_FILE_DEBUG_STRIPPED = 0x200,
|
||||
IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP = 0x400,
|
||||
IMAGE_FILE_NET_RUN_FROM_SWAP = 0x800,
|
||||
IMAGE_FILE_SYSTEM = 0x1000,
|
||||
IMAGE_FILE_DLL = 0x2000,
|
||||
IMAGE_FILE_UP_SYSTEM_ONLY = 0x4000,
|
||||
IMAGE_FILE_BYTES_REVERSED_HI = 0x8000,
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Win32.System.SystemInformation;
|
||||
|
||||
namespace Snap.Hutao.Win32.System.Diagnostics.Debug;
|
||||
|
||||
internal struct IMAGE_FILE_HEADER
|
||||
{
|
||||
public IMAGE_FILE_MACHINE Machine;
|
||||
public ushort NumberOfSections;
|
||||
public uint TimeDateStamp;
|
||||
public uint PointerToSymbolTable;
|
||||
public uint NumberOfSymbols;
|
||||
public ushort SizeOfOptionalHeader;
|
||||
public IMAGE_FILE_CHARACTERISTICS Characteristics;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
namespace Snap.Hutao.Win32.System.Diagnostics.Debug;
|
||||
|
||||
internal struct IMAGE_NT_HEADERS64
|
||||
{
|
||||
public uint Signature;
|
||||
public IMAGE_FILE_HEADER FileHeader;
|
||||
public IMAGE_OPTIONAL_HEADER64 OptionalHeader;
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Snap.Hutao.Win32.System.Diagnostics.Debug;
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 4)]
|
||||
internal struct IMAGE_OPTIONAL_HEADER64
|
||||
{
|
||||
public IMAGE_OPTIONAL_HEADER_MAGIC Magic;
|
||||
public byte MajorLinkerVersion;
|
||||
public byte MinorLinkerVersion;
|
||||
public uint SizeOfCode;
|
||||
public uint SizeOfInitializedData;
|
||||
public uint SizeOfUninitializedData;
|
||||
public uint AddressOfEntryPoint;
|
||||
public uint BaseOfCode;
|
||||
public ulong ImageBase;
|
||||
public uint SectionAlignment;
|
||||
public uint FileAlignment;
|
||||
public ushort MajorOperatingSystemVersion;
|
||||
public ushort MinorOperatingSystemVersion;
|
||||
public ushort MajorImageVersion;
|
||||
public ushort MinorImageVersion;
|
||||
public ushort MajorSubsystemVersion;
|
||||
public ushort MinorSubsystemVersion;
|
||||
public uint Win32VersionValue;
|
||||
public uint SizeOfImage;
|
||||
public uint SizeOfHeaders;
|
||||
public uint CheckSum;
|
||||
public IMAGE_SUBSYSTEM Subsystem;
|
||||
public IMAGE_DLL_CHARACTERISTICS DllCharacteristics;
|
||||
public ulong SizeOfStackReserve;
|
||||
public ulong SizeOfStackCommit;
|
||||
public ulong SizeOfHeapReserve;
|
||||
public ulong SizeOfHeapCommit;
|
||||
|
||||
[Obsolete]
|
||||
public uint LoaderFlags;
|
||||
public uint NumberOfRvaAndSizes;
|
||||
public IMAGE_DATA_DIRECTORY_16 DataDirectory;
|
||||
|
||||
[InlineArray(16)]
|
||||
internal struct IMAGE_DATA_DIRECTORY_16
|
||||
{
|
||||
public IMAGE_DATA_DIRECTORY Value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
namespace Snap.Hutao.Win32.System.Diagnostics.Debug;
|
||||
|
||||
internal enum IMAGE_OPTIONAL_HEADER_MAGIC : ushort
|
||||
{
|
||||
IMAGE_NT_OPTIONAL_HDR_MAGIC = 523,
|
||||
IMAGE_NT_OPTIONAL_HDR32_MAGIC = 267,
|
||||
IMAGE_NT_OPTIONAL_HDR64_MAGIC = 523,
|
||||
IMAGE_ROM_OPTIONAL_HDR_MAGIC = 263,
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
namespace Snap.Hutao.Win32.System.Diagnostics.Debug;
|
||||
|
||||
internal enum IMAGE_SUBSYSTEM : ushort
|
||||
{
|
||||
IMAGE_SUBSYSTEM_UNKNOWN = 0,
|
||||
IMAGE_SUBSYSTEM_NATIVE = 1,
|
||||
IMAGE_SUBSYSTEM_WINDOWS_GUI = 2,
|
||||
IMAGE_SUBSYSTEM_WINDOWS_CUI = 3,
|
||||
IMAGE_SUBSYSTEM_OS2_CUI = 5,
|
||||
IMAGE_SUBSYSTEM_POSIX_CUI = 7,
|
||||
IMAGE_SUBSYSTEM_NATIVE_WINDOWS = 8,
|
||||
IMAGE_SUBSYSTEM_WINDOWS_CE_GUI = 9,
|
||||
IMAGE_SUBSYSTEM_EFI_APPLICATION = 10,
|
||||
IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER = 11,
|
||||
IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER = 12,
|
||||
IMAGE_SUBSYSTEM_EFI_ROM = 13,
|
||||
IMAGE_SUBSYSTEM_XBOX = 14,
|
||||
IMAGE_SUBSYSTEM_WINDOWS_BOOT_APPLICATION = 16,
|
||||
IMAGE_SUBSYSTEM_XBOX_CODE_CATALOG = 17,
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
namespace Snap.Hutao.Win32.System.LibraryLoader;
|
||||
|
||||
[Flags]
|
||||
internal enum LOAD_LIBRARY_FLAGS : uint
|
||||
{
|
||||
DONT_RESOLVE_DLL_REFERENCES = 1U,
|
||||
LOAD_LIBRARY_AS_DATAFILE = 2U,
|
||||
LOAD_WITH_ALTERED_SEARCH_PATH = 8U,
|
||||
LOAD_IGNORE_CODE_AUTHZ_LEVEL = 0x10U,
|
||||
LOAD_LIBRARY_AS_IMAGE_RESOURCE = 0x20U,
|
||||
LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE = 0x40U,
|
||||
LOAD_LIBRARY_REQUIRE_SIGNED_TARGET = 0x80U,
|
||||
LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR = 0x100U,
|
||||
LOAD_LIBRARY_SEARCH_APPLICATION_DIR = 0x200U,
|
||||
LOAD_LIBRARY_SEARCH_USER_DIRS = 0x400U,
|
||||
LOAD_LIBRARY_SEARCH_SYSTEM32 = 0x800U,
|
||||
LOAD_LIBRARY_SEARCH_DEFAULT_DIRS = 0x1000U,
|
||||
LOAD_LIBRARY_SAFE_CURRENT_DIRS = 0x2000U,
|
||||
LOAD_LIBRARY_SEARCH_SYSTEM32_NO_FORWARDER = 0x4000U,
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Snap.Hutao.Win32.System.SystemInformation;
|
||||
|
||||
internal enum IMAGE_FILE_MACHINE : ushort
|
||||
{
|
||||
IMAGE_FILE_MACHINE_AXP64 = 644,
|
||||
IMAGE_FILE_MACHINE_I386 = 332,
|
||||
IMAGE_FILE_MACHINE_IA64 = 512,
|
||||
IMAGE_FILE_MACHINE_AMD64 = 34404,
|
||||
IMAGE_FILE_MACHINE_UNKNOWN = 0,
|
||||
IMAGE_FILE_MACHINE_TARGET_HOST = 1,
|
||||
IMAGE_FILE_MACHINE_R3000 = 354,
|
||||
IMAGE_FILE_MACHINE_R4000 = 358,
|
||||
IMAGE_FILE_MACHINE_R10000 = 360,
|
||||
IMAGE_FILE_MACHINE_WCEMIPSV2 = 361,
|
||||
IMAGE_FILE_MACHINE_ALPHA = 388,
|
||||
IMAGE_FILE_MACHINE_SH3 = 418,
|
||||
IMAGE_FILE_MACHINE_SH3DSP = 419,
|
||||
IMAGE_FILE_MACHINE_SH3E = 420,
|
||||
IMAGE_FILE_MACHINE_SH4 = 422,
|
||||
IMAGE_FILE_MACHINE_SH5 = 424,
|
||||
IMAGE_FILE_MACHINE_ARM = 448,
|
||||
IMAGE_FILE_MACHINE_THUMB = 450,
|
||||
IMAGE_FILE_MACHINE_ARMNT = 452,
|
||||
IMAGE_FILE_MACHINE_AM33 = 467,
|
||||
IMAGE_FILE_MACHINE_POWERPC = 496,
|
||||
IMAGE_FILE_MACHINE_POWERPCFP = 497,
|
||||
IMAGE_FILE_MACHINE_MIPS16 = 614,
|
||||
IMAGE_FILE_MACHINE_ALPHA64 = 644,
|
||||
IMAGE_FILE_MACHINE_MIPSFPU = 870,
|
||||
IMAGE_FILE_MACHINE_MIPSFPU16 = 1126,
|
||||
IMAGE_FILE_MACHINE_TRICORE = 1312,
|
||||
IMAGE_FILE_MACHINE_CEF = 3311,
|
||||
IMAGE_FILE_MACHINE_EBC = 3772,
|
||||
IMAGE_FILE_MACHINE_M32R = 36929,
|
||||
IMAGE_FILE_MACHINE_ARM64 = 43620,
|
||||
IMAGE_FILE_MACHINE_CEE = 49390,
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Snap.Hutao.Win32.System.SystemService;
|
||||
|
||||
[SuppressMessage("", "SA1307")]
|
||||
[SuppressMessage("", "SA1310")]
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 2)]
|
||||
internal struct IMAGE_DOS_HEADER
|
||||
{
|
||||
public ushort e_magic;
|
||||
public ushort e_cblp;
|
||||
public ushort e_cp;
|
||||
public ushort e_crlc;
|
||||
public ushort e_cparhdr;
|
||||
public ushort e_minalloc;
|
||||
public ushort e_maxalloc;
|
||||
public ushort e_ss;
|
||||
public ushort e_sp;
|
||||
public ushort e_csum;
|
||||
public ushort e_ip;
|
||||
public ushort e_cs;
|
||||
public ushort e_lfarlc;
|
||||
public ushort e_ovno;
|
||||
public unsafe fixed ushort e_res[4];
|
||||
public ushort e_oemid;
|
||||
public ushort e_oeminfo;
|
||||
public unsafe fixed ushort e_res2[10];
|
||||
public int e_lfanew;
|
||||
}
|
||||
Reference in New Issue
Block a user