From 7e3d7e90768ea1098fc8e4d90d47e9f69c275902 Mon Sep 17 00:00:00 2001 From: DismissedLight <1686188646@qq.com> Date: Tue, 21 Mar 2023 13:16:09 +0800 Subject: [PATCH] remove MemoryExtension [skip ci] --- .../Service/Game/Unlocker/GameFpsUnlocker.cs | 4 ++- src/Snap.Hutao/Snap.Hutao/Snap.Hutao.csproj | 2 +- .../Achievement/AchievementImporter.cs | 6 ++--- .../Snap.Hutao/Win32/MemoryExtension.cs | 27 ------------------- 4 files changed, 7 insertions(+), 32 deletions(-) delete mode 100644 src/Snap.Hutao/Snap.Hutao/Win32/MemoryExtension.cs diff --git a/src/Snap.Hutao/Snap.Hutao/Service/Game/Unlocker/GameFpsUnlocker.cs b/src/Snap.Hutao/Snap.Hutao/Service/Game/Unlocker/GameFpsUnlocker.cs index 6172a5cf..bc2d962b 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/Game/Unlocker/GameFpsUnlocker.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/Game/Unlocker/GameFpsUnlocker.cs @@ -84,7 +84,9 @@ internal sealed class GameFpsUnlocker : IGameFpsUnlocker foreach (MODULEENTRY32 entry in StructMarshal.EnumerateModuleEntry32(snapshot)) { - if (entry.th32ProcessID == processId && entry.szModule.AsNullTerminatedReadOnlySpan().SequenceEqual(moduleName)) + __CHAR_256* pszModule = &entry.szModule; + ReadOnlySpan szModuleLocal = MemoryMarshal.CreateReadOnlySpanFromNullTerminated((byte*)pszModule); + if (entry.th32ProcessID == processId && szModuleLocal.SequenceEqual(moduleName)) { return entry; } diff --git a/src/Snap.Hutao/Snap.Hutao/Snap.Hutao.csproj b/src/Snap.Hutao/Snap.Hutao/Snap.Hutao.csproj index 05d81176..fa02c6b9 100644 --- a/src/Snap.Hutao/Snap.Hutao/Snap.Hutao.csproj +++ b/src/Snap.Hutao/Snap.Hutao/Snap.Hutao.csproj @@ -244,7 +244,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/Snap.Hutao/Snap.Hutao/ViewModel/Achievement/AchievementImporter.cs b/src/Snap.Hutao/Snap.Hutao/ViewModel/Achievement/AchievementImporter.cs index e2245e36..508c3e1d 100644 --- a/src/Snap.Hutao/Snap.Hutao/ViewModel/Achievement/AchievementImporter.cs +++ b/src/Snap.Hutao/Snap.Hutao/ViewModel/Achievement/AchievementImporter.cs @@ -50,7 +50,7 @@ internal sealed class AchievementImporter { if (await GetUIAFFromClipboardAsync().ConfigureAwait(false) is UIAF uiaf) { - return await ImportAsync(achievementService.CurrentArchive!, uiaf).ConfigureAwait(false); + return await TryImportAsync(achievementService.CurrentArchive!, uiaf).ConfigureAwait(false); } else { @@ -85,7 +85,7 @@ internal sealed class AchievementImporter if (isOk) { - return await ImportAsync(achievementService.CurrentArchive, uiaf!).ConfigureAwait(false); + return await TryImportAsync(achievementService.CurrentArchive, uiaf!).ConfigureAwait(false); } else { @@ -114,7 +114,7 @@ internal sealed class AchievementImporter } } - private async Task ImportAsync(EntityAchievementArchive archive, UIAF uiaf) + private async Task TryImportAsync(EntityAchievementArchive archive, UIAF uiaf) { if (uiaf.IsCurrentVersionSupported()) { diff --git a/src/Snap.Hutao/Snap.Hutao/Win32/MemoryExtension.cs b/src/Snap.Hutao/Snap.Hutao/Win32/MemoryExtension.cs deleted file mode 100644 index 95483176..00000000 --- a/src/Snap.Hutao/Snap.Hutao/Win32/MemoryExtension.cs +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) DGP Studio. All rights reserved. -// Licensed under the MIT license. - -using System.Runtime.InteropServices; -using Windows.Win32.Foundation; - -namespace Snap.Hutao.Win32; - -/// -/// 内存拓展 for and -/// -[HighQuality] -internal static class MemoryExtension -{ - /// - /// 将 __CHAR_256 转换到 字符串 - /// - /// 目标字符数组 - /// 结果字符串 - public static unsafe ReadOnlySpan AsNullTerminatedReadOnlySpan(this in __CHAR_256 char256) - { - fixed (CHAR* pszChar = &char256._0) - { - return MemoryMarshal.CreateReadOnlySpanFromNullTerminated((byte*)pszChar); - } - } -} \ No newline at end of file