From ff785387dc4cae92aefd020e85f3b966fc306693 Mon Sep 17 00:00:00 2001 From: DismissedLight <1686188646@qq.com> Date: Fri, 28 Jun 2024 23:39:30 +0800 Subject: [PATCH] fix accessor unreachable issue --- .../Unlocker/Island/IslandGameFpsUnlocker.cs | 40 ++++++++++--------- 1 file changed, 21 insertions(+), 19 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 a2c9c2f0..d8d16799 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 @@ -41,28 +41,30 @@ internal sealed class IslandGameFpsUnlocker : GameFpsUnlocker { using (MemoryMappedFile file = MemoryMappedFile.CreateOrOpen(IslandEnvironmentName, 1024)) { - MemoryMappedViewAccessor accessor = file.CreateViewAccessor(); - nint handle = accessor.SafeMemoryMappedViewHandle.DangerousGetHandle(); - UpdateIslandEnvironment(handle, context, launchOptions); - InitializeIsland(context.GameProcess); - - using (PeriodicTimer timer = new(context.Options.AdjustFpsDelay)) + using (MemoryMappedViewAccessor accessor = file.CreateViewAccessor()) { - while (await timer.WaitForNextTickAsync(token).ConfigureAwait(false)) + nint handle = accessor.SafeMemoryMappedViewHandle.DangerousGetHandle(); + UpdateIslandEnvironment(handle, context, launchOptions); + InitializeIsland(context.GameProcess); + + using (PeriodicTimer timer = new(context.Options.AdjustFpsDelay)) { - context.Logger.LogInformation("context.GameProcess.HasExited: {Value}", context.GameProcess.HasExited); - if (!context.GameProcess.HasExited && context.FpsAddress != 0U) + while (await timer.WaitForNextTickAsync(token).ConfigureAwait(false)) { - IslandEnvironmentView view = UpdateIslandEnvironment(handle, context, launchOptions); - context.Logger.LogDebug("Island Environment|{State}|{Error}", view.State, view.LastError); - context.Report(); - } - else - { - context.IsUnlockerValid = false; - context.FpsAddress = 0; - context.Report(); - return; + context.Logger.LogInformation("context.GameProcess.HasExited: {Value}", context.GameProcess.HasExited); + if (!context.GameProcess.HasExited && context.FpsAddress != 0U) + { + IslandEnvironmentView view = UpdateIslandEnvironment(handle, context, launchOptions); + context.Logger.LogDebug("Island Environment|{State}|{Error}", view.State, view.LastError); + context.Report(); + } + else + { + context.IsUnlockerValid = false; + context.FpsAddress = 0; + context.Report(); + return; + } } } }