From 034655dc263bb0acdc3581aedfe014d5f83dba6c Mon Sep 17 00:00:00 2001 From: qhy040404 Date: Tue, 25 Jun 2024 18:35:10 +0800 Subject: [PATCH] extract island to data folder --- .../Unlocker/Island/IslandGameFpsUnlocker.cs | 33 +++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/Snap.Hutao/Snap.Hutao/Service/Game/Unlocker/Island/IslandGameFpsUnlocker.cs b/src/Snap.Hutao/Snap.Hutao/Service/Game/Unlocker/Island/IslandGameFpsUnlocker.cs index 96046222..a2c9c2f0 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/Game/Unlocker/Island/IslandGameFpsUnlocker.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/Game/Unlocker/Island/IslandGameFpsUnlocker.cs @@ -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 progress) : base(serviceProvider, gameProcess, options, progress) { + RuntimeOptions runtimeOptions = serviceProvider.GetRequiredService(); + 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 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;