diff --git a/src/Snap.Hutao/Snap.Hutao/Extension/EnumerableExtension.cs b/src/Snap.Hutao/Snap.Hutao/Extension/EnumerableExtension.cs index 4cbbad99..bfc83190 100644 --- a/src/Snap.Hutao/Snap.Hutao/Extension/EnumerableExtension.cs +++ b/src/Snap.Hutao/Snap.Hutao/Extension/EnumerableExtension.cs @@ -61,4 +61,46 @@ internal static partial class EnumerableExtension { return new ObservableCollection(source); } + + /// + /// Concatenates each element from the collection into single string. + /// + /// Type of array elements. + /// Collection to convert. Cannot be . + /// Delimiter between elements in the final string. + /// A string to be returned if collection has no elements. + /// Converted collection into string. + public static string ToString(this IEnumerable collection, string separator, string defaultValue = "") + { + string result = string.Join(separator, collection); + if (result.Length > 0) + { + return result; + } + else + { + return defaultValue; + } + } + + /// + /// Concatenates each element from the collection into single string. + /// + /// Type of array elements. + /// Collection to convert. Cannot be . + /// Delimiter between elements in the final string. + /// A string to be returned if collection has no elements. + /// Converted collection into string. + public static string ToString(this IEnumerable collection, char separator = ',', string defaultValue = "") + { + string result = string.Join(separator, collection); + if (result.Length > 0) + { + return result; + } + else + { + return defaultValue; + } + } } \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Model/Intrinsic/AchievementStatus.cs b/src/Snap.Hutao/Snap.Hutao/Model/Intrinsic/AchievementStatus.cs index 4b949fcc..3b5c4de0 100644 --- a/src/Snap.Hutao/Snap.Hutao/Model/Intrinsic/AchievementStatus.cs +++ b/src/Snap.Hutao/Snap.Hutao/Model/Intrinsic/AchievementStatus.cs @@ -15,7 +15,7 @@ internal enum AchievementStatus STATUS_UNRECOGNIZED = -1, /// - /// 非法值 + /// 不使用的成就 /// STATUS_INVALID = 0, diff --git a/src/Snap.Hutao/Snap.Hutao/Model/Intrinsic/ElementType.cs b/src/Snap.Hutao/Snap.Hutao/Model/Intrinsic/ElementType.cs index f2bde7f6..ff6b32bb 100644 --- a/src/Snap.Hutao/Snap.Hutao/Model/Intrinsic/ElementType.cs +++ b/src/Snap.Hutao/Snap.Hutao/Model/Intrinsic/ElementType.cs @@ -7,80 +7,22 @@ namespace Snap.Hutao.Model.Intrinsic; /// 元素类型 /// [HighQuality] +[SuppressMessage("", "SA1602")] internal enum ElementType { - /// - /// 无元素 - /// - None = 0, - - /// - /// 火元素 - /// - Fire = 1, - - /// - /// 水元素 - /// - Water = 2, - - /// - /// 草元素 - /// - Grass = 3, - - /// - /// 雷元素 - /// - Electric = 4, - - /// - /// 冰元素 - /// - Ice = 5, - - /// - /// 冻元素 - /// - Frozen = 6, - - /// - /// 风元素 - /// - Wind = 7, - - /// - /// 岩元素 - /// - Rock = 8, - - /// - /// 燃元素 - /// - AntiFire = 9, - - /// - /// 枫丹玩法 - /// - VehicleMuteIce = 10, - - /// - /// 弹弹菇 - /// - Mushroom = 11, - - /// - /// 激元素 - /// - Overdose = 12, - - /// - /// 木元素 - /// - Wood = 13, - - /// - /// 个数 - /// - Count = 14, + None = 0, // 无元素 + Fire = 1, // 火元素 + Water = 2, // 水元素 + Grass = 3, // 草元素 + Electric = 4, // 雷元素 + Ice = 5, // 冰元素 + Frozen = 6, // 冻元素 + Wind = 7, // 风元素 + Rock = 8, // 岩元素 + AntiFire = 9, // 燃元素 + VehicleMuteIce = 10, // 枫丹玩法 + Mushroom = 11, // 弹弹菇 + Overdose = 12, // 激元素 + Wood = 13, // 木元素 + Count = 14, // 个数 } \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Program.cs b/src/Snap.Hutao/Snap.Hutao/Program.cs index d470a014..575245c7 100644 --- a/src/Snap.Hutao/Snap.Hutao/Program.cs +++ b/src/Snap.Hutao/Snap.Hutao/Program.cs @@ -25,7 +25,7 @@ public static partial class Program [STAThread] private static void Main(string[] args) { - System.Diagnostics.Debug.WriteLine($"[Arguments]:{args}"); + System.Diagnostics.Debug.WriteLine($"[Arguments]:[{EnumerableExtension.ToString(args)}]"); XamlCheckProcessRequirements(); ComWrappersSupport.InitializeComWrappers(); 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 be3bdc0f..725883f6 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/Game/Unlocker/GameFpsUnlocker.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/Game/Unlocker/GameFpsUnlocker.cs @@ -3,6 +3,7 @@ using Snap.Hutao.Core.Diagnostics; using Snap.Hutao.Core.ExceptionService; +using Snap.Hutao.Win32.Memory; using System.Diagnostics; using System.Runtime.InteropServices; using Windows.Win32.Foundation; @@ -235,7 +236,7 @@ internal sealed class GameFpsUnlocker : IGameFpsUnlocker using (localMemory) { - int offset = IndexOfPattern(localMemory.GetBuffer()[(int)moduleEntryInfo.UnityPlayer.Size..]); + int offset = IndexOfPattern(localMemory.Span[(int)moduleEntryInfo.UnityPlayer.Size..]); Must.Range(offset >= 0, SH.ServiceGameUnlockerInterestedPatternNotFound); byte* pLocalMemory = (byte*)localMemory.Pointer; diff --git a/src/Snap.Hutao/Snap.Hutao/Service/Metadata/MetadataOptions.cs b/src/Snap.Hutao/Snap.Hutao/Service/Metadata/MetadataOptions.cs index 9e36b491..eb527a0a 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/Metadata/MetadataOptions.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/Metadata/MetadataOptions.cs @@ -84,7 +84,7 @@ internal sealed partial class MetadataOptions : IOptions /// 服务器上的本地化元数据文件 public string GetLocalizedRemoteFile(string fileNameWithExtension) { - return Web.HutaoEndpoints.RawGithubUserContentMetadataFile(LocaleName, fileNameWithExtension); + return Web.HutaoEndpoints.HutaoMetadata2File(LocaleName, fileNameWithExtension); } private string GetLocaleName() diff --git a/src/Snap.Hutao/Snap.Hutao/Win32/Memory/IUnmanagedMemory.cs b/src/Snap.Hutao/Snap.Hutao/Win32/Memory/IUnmanagedMemory.cs new file mode 100644 index 00000000..c9b090d7 --- /dev/null +++ b/src/Snap.Hutao/Snap.Hutao/Win32/Memory/IUnmanagedMemory.cs @@ -0,0 +1,25 @@ +// Copyright (c) DGP Studio. All rights reserved. +// Licensed under the MIT license. + +namespace Snap.Hutao.Win32.Memory; + +/// +/// 非托管内存 +/// +internal unsafe interface IUnmanagedMemory : IDisposable +{ + /// + /// Gets a pointer to the allocated unmanaged memory. + /// + void* Pointer { get; } + + /// + /// Gets size of referenced unmanaged memory, in bytes. + /// + uint Size { get; } + + /// + /// Gets a span of bytes from the current instance. + /// + Span Span { get; } +} \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Service/Game/Unlocker/VirtualMemory.cs b/src/Snap.Hutao/Snap.Hutao/Win32/Memory/VirtualMemory.cs similarity index 53% rename from src/Snap.Hutao/Snap.Hutao/Service/Game/Unlocker/VirtualMemory.cs rename to src/Snap.Hutao/Snap.Hutao/Win32/Memory/VirtualMemory.cs index 945364f3..4b629e12 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/Game/Unlocker/VirtualMemory.cs +++ b/src/Snap.Hutao/Snap.Hutao/Win32/Memory/VirtualMemory.cs @@ -4,22 +4,22 @@ using Windows.Win32.System.Memory; using static Windows.Win32.PInvoke; -namespace Snap.Hutao.Service.Game.Unlocker; +namespace Snap.Hutao.Win32.Memory; /// /// NativeMemory.AllocZeroed wrapper /// -internal readonly unsafe struct VirtualMemory : IDisposable +internal readonly unsafe struct VirtualMemory : IUnmanagedMemory { /// /// 缓冲区地址 /// - public readonly void* Pointer; + private readonly void* pointer; /// /// 长度 /// - public readonly uint Length; + private readonly uint size; /// /// 构造一个新的本地内存 @@ -27,28 +27,23 @@ internal readonly unsafe struct VirtualMemory : IDisposable /// 长度 public unsafe VirtualMemory(uint dwSize) { - Length = dwSize; + size = dwSize; VIRTUAL_ALLOCATION_TYPE commitAndReserve = VIRTUAL_ALLOCATION_TYPE.MEM_COMMIT | VIRTUAL_ALLOCATION_TYPE.MEM_RESERVE; - Pointer = VirtualAlloc(default, dwSize, commitAndReserve, PAGE_PROTECTION_FLAGS.PAGE_READWRITE); + pointer = VirtualAlloc(default, dwSize, commitAndReserve, PAGE_PROTECTION_FLAGS.PAGE_READWRITE); } - public static unsafe implicit operator Span(VirtualMemory memory) - { - return memory.GetBuffer(); - } + /// + public void* Pointer { get => pointer; } - /// - /// 获取缓冲区 - /// - /// 内存 - public unsafe Span GetBuffer() - { - return new Span(Pointer, (int)Length); - } + /// + public uint Size { get => size; } + + /// + public Span Span { get => new(pointer, (int)size); } /// public void Dispose() { - VirtualFree(Pointer, 0, VIRTUAL_FREE_TYPE.MEM_RELEASE); + VirtualFree(pointer, 0, VIRTUAL_FREE_TYPE.MEM_RELEASE); } } \ No newline at end of file