Skip to content

Commit

Permalink
Merge branch 'develop' into feat/qr
Browse files Browse the repository at this point in the history
  • Loading branch information
BTMuli authored Nov 5, 2024
2 parents cde201a + 1bf5c30 commit 91938a5
Show file tree
Hide file tree
Showing 213 changed files with 4,822 additions and 2,120 deletions.
3 changes: 2 additions & 1 deletion .github/ISSUE_TEMPLATE/CHS-bug-report.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
name: 问题反馈
description: 通过这个议题向开发团队反馈你发现的程序中的问题
title: "[Bug]: 在这里填写一个合适的标题"
labels: ["BUG", "priority:none"]
type: "Bug"
labels: ["priority:none"]
body:
- type: markdown
attributes:
Expand Down
3 changes: 2 additions & 1 deletion .github/ISSUE_TEMPLATE/CHS-feature-request.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
name: 功能请求
description: 通过这个议题来向开发团队分享你的想法
title: "[Feat]: 在这里填写一个合适的标题"
labels: ["feature request", "needs-triage", "priority:none"]
type: "Feature"
labels: ["needs-triage", "priority:none"]
body:
- type: markdown
attributes:
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/CHS-network-issue.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: 网络问题
description: 通过这个议题来反馈网络问题
title: "[Network]: 在这里填写一个合适的标题"
type: "Bug"
labels: ["area-Network"]
assignees:
- Lightczx
Expand Down
3 changes: 2 additions & 1 deletion .github/ISSUE_TEMPLATE/ENG-bug-report.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
name: BUG Report [English Form]
description: Tell us what issue you get
title: "[ENG][Bug]: Place your Issue Title Here"
labels: ["BUG", "priority:none"]
type: "Bug"
labels: ["priority:none"]
body:
- type: markdown
attributes:
Expand Down
3 changes: 2 additions & 1 deletion .github/ISSUE_TEMPLATE/ENG-feature-request.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
name: Feature Request [English Form]
description: Tell us about your thought
title: "[Feat]: Place your title here"
labels: ["feature request", "needs-triage", "priority:none"]
type: "Feature"
labels: ["needs-triage", "priority:none"]
body:
- type: markdown
attributes:
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/ENG-network-issue.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: Network Issue [English Form]
description: Submit this issue form when network issue affect your client experience
title: "[Network]: Place your title here"
type: "Bug"
labels: ["area-Network"]
assignees:
- Lightczx
Expand Down
10 changes: 10 additions & 0 deletions .github/workflows/alpha.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,13 @@ jobs:
"
echo $summary >> $Env:GITHUB_STEP_SUMMARY
- name: Clean up
run: |
Write-Host "Cleaning up NuGet cache..."
Remove-Item -Recurse -Force "$env:USERPROFILE\.nuget\packages"
Write-Host "NuGet cache cleaned."
Write-Host "Cleaning up .NET install folder..."
Remove-Item -Recurse -Force "C:\Users\Public\Documents\dotnet_install"
Write-Host ".NET install folder cleaned."
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ Snap Hutao uses [Crowdin](https://translate.hut.ao/) as a client text translatio

Snap Hutao is currently using sponsored software from the following service providers.

| [![](https://www.netlify.com/v3/img/components/netlify-light.svg)](https://www.netlify.com/) | [![](https://support.crowdin.com/images/logos/core-logo/svg/crowdin-core-logo-cDark.svg)](https://crowdin.com/) | [![](https://github.com/user-attachments/assets/1fe09f87-3f56-4341-8a34-5ed8151f5f10)](https://navicat.com) |
| :----------------------------------------------------------: | :----------------------------------------------------------: | :----------------------------------------------------------: |
| [![](https://github.com/DGP-Studio/Snap.Hutao/assets/10614984/73ae8b90-f3c7-4033-b2b7-f4126331ce66)](https://about.signpath.io) | [![](https://github.com/DGP-Studio/Snap.Hutao/assets/10614984/49aed8ee-9f19-4a8a-998c-7b93ee286d65)](https://1password.com/) | [![](https://github.com/DGP-Studio/Snap.Hutao/assets/10614984/ad121220-d2d3-4f49-b215-b6d063dc229d)](https://www.digitalocean.com) |
| [![ducalis](https://raw.githubusercontent.com/DGP-Studio/Snap.Hutao.Docs/main/docs/.vuepress/public/svg/ducalis.svg)](https://hi.ducalis.io/) | [![jetbrains](https://github.com/DGP-Studio/Snap.Hutao/assets/36357191/4105772a-728a-4a84-9c6e-d713a5698a20)](https://www.jetbrains.com/opensource/) | |
| [![](https://raw.githubusercontent.com/DGP-Studio/Snap.Hutao.Docs/main/docs/.vuepress/public/svg/netlify.svg)](https://www.netlify.com/) | [![](https://raw.githubusercontent.com/DGP-Studio/Snap.Hutao.Docs/main/docs/.vuepress/public/svg/crowdin-core-logo-cDark.svg)](https://crowdin.com/) | [![](https://raw.githubusercontent.com/DGP-Studio/Snap.Hutao.Docs/main/docs/.vuepress/public/svg/navicat.svg)](https://navicat.com/) |
| :----------------------------------------------------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------------------------------------------------------: | :-----------------------------------------------------------------------------------------------------------------------------------------------: |
| [![](https://raw.githubusercontent.com/DGP-Studio/Snap.Hutao.Docs/main/docs/.vuepress/public/svg/signpath.svg)](https://about.signpath.io) | [![](https://raw.githubusercontent.com/DGP-Studio/Snap.Hutao.Docs/main/docs/.vuepress/public/svg/1Password.svg)](https://1password.com/) | [![](https://raw.githubusercontent.com/DGP-Studio/Snap.Hutao.Docs/main/docs/.vuepress/public/svg/digitalocean.svg)](https://www.digitalocean.com) |
| [![](https://raw.githubusercontent.com/DGP-Studio/Snap.Hutao.Docs/main/docs/.vuepress/public/svg/ducalis.svg)](https://hi.ducalis.io/) | [![](https://raw.githubusercontent.com/DGP-Studio/Snap.Hutao.Docs/main/docs/.vuepress/public/svg/jetbrains.svg)](https://www.jetbrains.com/) | [![](https://raw.githubusercontent.com/DGP-Studio/Snap.Hutao.Docs/main/docs/.vuepress/public/svg/termius-logo.svg)](https://termius.com) |

- Netlify provides document and home page hosting service for Snap Hutao

Expand Down
11 changes: 11 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ branches:
- "release"
build_cloud: HUTAO-ACTIONS
image: Visual Studio 2022
cache:
- 'C:\Users\Public\Documents\dotnet_install\.nuget\packages'
clone_depth: 3
clone_folder: C:\Users\Public\appveyor\Snap.Hutao
install:
Expand All @@ -18,3 +20,12 @@ deploy:
url: https://app.signpath.io/API/v1/7a941fa3-64d8-4c45-bd03-92a02bcd4964/Integrations/AppVeyor?ProjectSlug=Snap.Hutao&SigningPolicySlug=release-signing&ArtifactConfigurationSlug=msix
authorization:
secure: j8srQ5/UYWhI+jlm3Vo3D3QfXoRyQ9hOn3ynJGtwusKui4+uDi4gykdUFYCITZxK+C/fOCAZNJ+YaKSm/OaiXw==
on_finish:
- pwsh: |
Write-Host "Cleaning up NuGet cache..."
Remove-Item -Recurse -Force "$env:LOCALAPPDATA\NuGet\v3-cache"
Write-Host "NuGet cache cleaned."
Write-Host "Cleaning up .NET install folder..."
Remove-Item -Recurse -Force "C:\Users\Public\Documents\dotnet_install"
Write-Host ".NET install folder cleaned."
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Text.Json;
using System.Text.Json.Serialization;
Expand Down Expand Up @@ -110,6 +111,13 @@ public void NewEmptyObjectSerializeAsEmptyObject()
Assert.AreEqual(result, "{}");
}

[TestMethod]
public void StructCanDeserialize()
{
SampleStruct sample = JsonSerializer.Deserialize<SampleStruct>(SampleObjectJson);
Assert.AreEqual(sample.A, 1);
}

private sealed class SampleDelegatePropertyClass
{
public int A { get => B; set => B = value; }
Expand Down Expand Up @@ -161,4 +169,10 @@ string ToJson()
return JsonSerializer.Serialize(this);
}
}

private struct SampleStruct
{
[JsonInclude]
public int A;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ private static void GetRegistryContentCore(string subkey)
{
RegistryValueKind.DWord => (int)gameKey.GetValue(valueName)!,
RegistryValueKind.Binary => GetStringOrObject((byte[])gameKey.GetValue(valueName)!),
_ => throw new NotImplementedException()
RegistryValueKind.String => (string)gameKey.GetValue(valueName)!,
_ => throw new ArgumentException($"Unsupported type: {gameKey.GetValueKind(valueName)}"),
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,45 @@ public class UnlockerIslandFunctionOffsetTest
[TestMethod]
public void GenerateJson()
{
// FunctionOffsetMickeyWonderMethod:
// public static byte[] AnonymousMethod43(int nType) -> jmp xxxxxxxx -> another xref to xxxxxxxx
// FunctionOffsetMickeyWonderMethodPartner:
// public static string get_unityVersion() -> jmp
// FunctionOffsetMickeyWonderMethodPartner2:
// "4C 8B 05 ?? ?? ?? ?? 4C 89 F1 48 89 FA E8 ?? ?? ?? ?? 90 48 83 C4 28 5B 5F 5E 41 5E C3"
// FunctionOffsetSetFieldOfView:
// public void set_fieldOfView(float value) -> jmp xxxxxxxx
// FunctionOffsetSetTargetFrameRate:
// public static void set_targetFrameRate(int value) -> jmp xxxxxxxxx (to the end)
// FunctionOffsetSetEnableFogRendering:
// public static void set_enableFogRendering(bool value) -> jmp xxxxxxxxx (to the end)

// FunctionOffsetOpenTeam:
// public static void AJODMEAHOGI()
// FunctionOffsetOpenTeamPageAccordingly:
// public static void OEEFGJDOCJJ(bool KCBOKOCOGEI = true)
UnlockerIslandConfigurationWrapper wrapper = new()
{
Chinese = new()
{
FunctionOffsetMickeyWonderMethod = 0x099D1D80,
FunctionOffsetMickeyWonderMethodPartner = 0x0092D5F0,
FunctionOffsetMickeyWonderMethodPartner2 = 0x054AEF80,
FunctionOffsetSetFieldOfView = 0x01136D30,
FunctionOffsetSetTargetFrameRate = 0x0131E600,
FunctionOffsetSetEnableFogRendering = 0x015DC790,
FunctionOffsetOpenTeam = 0x07806530,
FunctionOffsetOpenTeamPageAccordingly = 0x0781D3F0,
},
Oversea = new()
{
FunctionOffsetMickeyWonderMethod = 0x09B37E60,
FunctionOffsetMickeyWonderMethodPartner = 0x0092D7D0,
FunctionOffsetMickeyWonderMethodPartner2 = 0x054AEE50,
FunctionOffsetSetFieldOfView = 0x01136F30,
FunctionOffsetSetTargetFrameRate = 0x0131E800,
FunctionOffsetSetEnableFogRendering = 0x015DC990,
FunctionOffsetOpenTeam = 0x0777E4F0,
FunctionOffsetOpenTeamPageAccordingly = 0x07779870,
},
};

Expand All @@ -39,17 +61,27 @@ public void GenerateJson()

private sealed class UnlockerIslandConfigurationWrapper
{
public required UnlockerIslandConfiguration Oversea { get; set; }

public required UnlockerIslandConfiguration Chinese { get; set; }

public required UnlockerIslandConfiguration Oversea { get; set; }
}

private sealed class UnlockerIslandConfiguration
{
public required uint FunctionOffsetMickeyWonderMethod { get; set; }

public required uint FunctionOffsetMickeyWonderMethodPartner { get; set; }

public required uint FunctionOffsetMickeyWonderMethodPartner2 { get; set; }

public required uint FunctionOffsetSetFieldOfView { get; set; }

public required uint FunctionOffsetSetTargetFrameRate { get; set; }

public required uint FunctionOffsetSetEnableFogRendering { get; set; }

public required uint FunctionOffsetOpenTeam { get; set; }

public required uint FunctionOffsetOpenTeamPageAccordingly { get; set; }
}
}
4 changes: 2 additions & 2 deletions src/Snap.Hutao/Snap.Hutao.Test/Snap.Hutao.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="MSTest.TestAdapter" Version="3.6.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.6.1" />
<PackageReference Include="MSTest.TestAdapter" Version="3.6.2" />
<PackageReference Include="MSTest.TestFramework" Version="3.6.2" />
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
2 changes: 2 additions & 0 deletions src/Snap.Hutao/Snap.Hutao/BannedSymbols.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.BannedApiAnalyzers/BannedApiAnalyzers.Help.md
M:System.Collections.Generic.List`1.ForEach(System.Action{`0})
8 changes: 4 additions & 4 deletions src/Snap.Hutao/Snap.Hutao/Core/Caching/ImageCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public async ValueTask<ValueFile> GetFileFromCacheAsync(Uri uri, ElementTheme th
// If the file already exists, we don't need to download it again
if (!IsFileInvalid(defaultFilePath))
{
await ConvertToMonoChromeAndSaveFileAsync(defaultFilePath, themeOrDefaultFilePath, theme).ConfigureAwait(false);
await TryConvertToMonoChromeAndSaveFileAsync(defaultFilePath, themeOrDefaultFilePath, theme).ConfigureAwait(false);
return themeOrDefaultFilePath;
}

Expand All @@ -86,7 +86,7 @@ public async ValueTask<ValueFile> GetFileFromCacheAsync(Uri uri, ElementTheme th
// File may be downloaded by another thread
if (!IsFileInvalid(defaultFilePath))
{
await ConvertToMonoChromeAndSaveFileAsync(defaultFilePath, themeOrDefaultFilePath, theme).ConfigureAwait(false);
await TryConvertToMonoChromeAndSaveFileAsync(defaultFilePath, themeOrDefaultFilePath, theme).ConfigureAwait(false);
return themeOrDefaultFilePath;
}

Expand Down Expand Up @@ -122,9 +122,9 @@ private static bool IsFileInvalid(string file, bool treatNullFileAsInvalid = tru
return new FileInfo(file).Length == 0;
}

private static async ValueTask ConvertToMonoChromeAndSaveFileAsync(string sourceFile, string themeFile, ElementTheme theme)
private static async ValueTask TryConvertToMonoChromeAndSaveFileAsync(string sourceFile, string themeFile, ElementTheme theme)
{
if (string.Equals(sourceFile, themeFile, StringComparison.OrdinalIgnoreCase))
if (theme is ElementTheme.Default || string.Equals(sourceFile, themeFile, StringComparison.OrdinalIgnoreCase))
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,18 @@ private async ValueTask CopyShardAsync(IHttpShard shard, IProgress<PrivateShardS

using (request)
{
using (HttpResponseMessage response = await options.HttpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, token).ConfigureAwait(false))
using (HttpResponseMessage response = await options.HttpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, token).ConfigureAwait(true))
{
response.EnsureSuccessStatusCode();
using (IMemoryOwner<byte> memoryOwner = MemoryPool<byte>.Shared.Rent(options.BufferSize))
{
Memory<byte> buffer = memoryOwner.Memory;
using (Stream stream = await response.Content.ReadAsStreamAsync(token).ConfigureAwait(false))
using (Stream stream = await response.Content.ReadAsStreamAsync(token).ConfigureAwait(true))
{
int bytesReadSinceLastReport = 0;
do
{
using (await shard.ReaderWriterLock.ReaderLockAsync().ConfigureAwait(false))
using (await shard.ReaderWriterLock.ReaderLockAsync().ConfigureAwait(true))
{
if (shard.BytesRead >= shard.End - shard.Start)
{
Expand All @@ -81,13 +81,13 @@ private async ValueTask CopyShardAsync(IHttpShard shard, IProgress<PrivateShardS
bool report = true;
try
{
int bytesRead = await stream.ReadAsync(buffer, token).ConfigureAwait(false);
int bytesRead = await stream.ReadAsync(buffer, token).ConfigureAwait(true);
if (bytesRead <= 0)
{
break;
}

await RandomAccess.WriteAsync(options.DestinationFileHandle, buffer[..bytesRead], shard.Start + shard.BytesRead, token).ConfigureAwait(false);
await RandomAccess.WriteAsync(options.DestinationFileHandle, buffer[..bytesRead], shard.Start + shard.BytesRead, token).ConfigureAwait(true);

shard.BytesRead += bytesRead;
bytesReadSinceLastReport += bytesRead;
Expand Down
37 changes: 34 additions & 3 deletions src/Snap.Hutao/Snap.Hutao/Core/IO/PhysicalDriver.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.

using Snap.Hutao.Core.ExceptionService;
using Snap.Hutao.Core.Setting;
using Snap.Hutao.Win32.Foundation;
using Snap.Hutao.Win32.Storage.FileSystem;
Expand Down Expand Up @@ -41,12 +42,42 @@ private static unsafe void GetDeviceNumber(string fileName, out uint deviceNumbe
{
hLogicalDriver = CreateDirectAccessStorageDeviceHandle(fileName);
STORAGE_DEVICE_NUMBER number = default;
if (!DeviceIoControl(hLogicalDriver, IOCTL_STORAGE_GET_DEVICE_NUMBER, default, default, &number, (uint)sizeof(STORAGE_DEVICE_NUMBER), default, default))
if (DeviceIoControl(hLogicalDriver, IOCTL_STORAGE_GET_DEVICE_NUMBER, default, default, &number, (uint)sizeof(STORAGE_DEVICE_NUMBER), default, default))
{
Marshal.ThrowExceptionForHR(HRESULT_FROM_WIN32(GetLastError()));
deviceNumber = number.DeviceNumber;
return;
}

WIN32_ERROR error = GetLastError();
if (error is not WIN32_ERROR.ERROR_INVALID_FUNCTION)
{
Marshal.ThrowExceptionForHR(HRESULT_FROM_WIN32(error));
}

// This logical driver belongs to a partitionable device.
Span<byte> buffer = stackalloc byte[sizeof(VOLUME_DISK_EXTENTS) + (sizeof(DISK_EXTENT) * 1)];
if (DeviceIoControl(hLogicalDriver, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, default, default, buffer, default, default))
{
deviceNumber = MemoryMarshal.AsRef<VOLUME_DISK_EXTENTS>(buffer).Extents[0].DiskNumber;
return;
}

WIN32_ERROR error2 = GetLastError();
if (error2 is not WIN32_ERROR.ERROR_MORE_DATA)
{
Marshal.ThrowExceptionForHR(HRESULT_FROM_WIN32(error2));
}

// The volume has multiple extents.
buffer = stackalloc byte[sizeof(VOLUME_DISK_EXTENTS) + (sizeof(DISK_EXTENT) * (int)MemoryMarshal.AsRef<VOLUME_DISK_EXTENTS>(buffer).NumberOfDiskExtents)];
if (DeviceIoControl(hLogicalDriver, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, default, default, buffer, default, default))
{
deviceNumber = MemoryMarshal.AsRef<VOLUME_DISK_EXTENTS>(buffer).Extents[0].DiskNumber;
return;
}

deviceNumber = number.DeviceNumber;
Marshal.ThrowExceptionForHR(HRESULT_FROM_WIN32(GetLastError()));
throw HutaoException.Throw("Failed to get the device number.");
}
finally
{
Expand Down
14 changes: 13 additions & 1 deletion src/Snap.Hutao/Snap.Hutao/Core/IO/TempFileStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@ internal sealed partial class TempFileStream : Stream
private readonly FileStream stream;

public TempFileStream(FileMode mode, FileAccess access)
: this(Path.GetTempFileName(), mode, access)
{
path = Path.GetTempFileName();
}

private TempFileStream(string path, FileMode mode, FileAccess access)
{
this.path = path;
stream = File.Open(path, mode, access);
}

Expand All @@ -26,6 +31,13 @@ public TempFileStream(FileMode mode, FileAccess access)

public override long Position { get => stream.Position; set => stream.Position = value; }

public static TempFileStream CopyFrom(string file, FileMode mode, FileAccess access)
{
string path = Path.GetTempFileName();
File.Copy(file, path, true);
return new TempFileStream(path, mode, access);
}

public override void Flush()
{
stream.Flush();
Expand Down
Loading

0 comments on commit 91938a5

Please sign in to comment.