mirror of
https://jihulab.com/DGP-Studio/Snap.Hutao.git
synced 2025-11-19 21:02:53 +08:00
extract island to data folder
This commit is contained in:
@@ -1,11 +1,14 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Core;
|
||||
using Snap.Hutao.Win32.Foundation;
|
||||
using Snap.Hutao.Win32.UI.WindowsAndMessaging;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.IO.MemoryMappedFiles;
|
||||
using System.Runtime.InteropServices;
|
||||
using Windows.Storage;
|
||||
using static Snap.Hutao.Win32.ConstValues;
|
||||
using static Snap.Hutao.Win32.Kernel32;
|
||||
using static Snap.Hutao.Win32.Macros;
|
||||
@@ -17,13 +20,23 @@ internal sealed class IslandGameFpsUnlocker : GameFpsUnlocker
|
||||
{
|
||||
private const string IslandEnvironmentName = "4F3E8543-40F7-4808-82DC-21E48A6037A7";
|
||||
|
||||
private readonly string dataFolderIslandPath;
|
||||
|
||||
public IslandGameFpsUnlocker(IServiceProvider serviceProvider, Process gameProcess, in UnlockOptions options, IProgress<GameFpsUnlockerContext> progress)
|
||||
: base(serviceProvider, gameProcess, options, progress)
|
||||
{
|
||||
RuntimeOptions runtimeOptions = serviceProvider.GetRequiredService<RuntimeOptions>();
|
||||
dataFolderIslandPath = Path.Combine(runtimeOptions.DataFolder, "Snap.Hutao.UnlockerIsland.dll");
|
||||
}
|
||||
|
||||
protected override async ValueTask PostUnlockOverrideAsync(GameFpsUnlockerContext context, LaunchOptions launchOptions, ILogger logger, CancellationToken token = default(CancellationToken))
|
||||
{
|
||||
if (!await InitializeIslandFileAsync().ConfigureAwait(false))
|
||||
{
|
||||
context.Logger.LogError("Failed to copy island file.");
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
using (MemoryMappedFile file = MemoryMappedFile.CreateOrOpen(IslandEnvironmentName, 1024))
|
||||
@@ -61,12 +74,28 @@ internal sealed class IslandGameFpsUnlocker : GameFpsUnlocker
|
||||
}
|
||||
}
|
||||
|
||||
private static unsafe void InitializeIsland(Process gameProcess)
|
||||
private async ValueTask<bool> InitializeIslandFileAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
Uri islandUri = "ms-appx:///Snap.Hutao.UnlockerIsland.dll".ToUri();
|
||||
StorageFile islandFile = await StorageFile.GetFileFromApplicationUriAsync(islandUri);
|
||||
await islandFile.OverwriteCopyAsync(dataFolderIslandPath).ConfigureAwait(false);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private unsafe void InitializeIsland(Process gameProcess)
|
||||
{
|
||||
HANDLE hModule = default;
|
||||
try
|
||||
{
|
||||
hModule = NativeLibrary.Load("Snap.Hutao.UnlockerIsland.dll");
|
||||
hModule = NativeLibrary.Load(dataFolderIslandPath);
|
||||
nint pIslandGetWindowHook = NativeLibrary.GetExport((nint)(hModule & ~0x3L), "IslandGetWindowHook");
|
||||
|
||||
HOOKPROC hookProc = default;
|
||||
|
||||
Reference in New Issue
Block a user