This commit is contained in:
Lightczx
2023-11-28 15:44:37 +08:00
parent 8e386c1457
commit 77217d2fc3
7 changed files with 44 additions and 27 deletions

View File

@@ -1,20 +1,20 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using System.Diagnostics.Contracts;
using System.Runtime.CompilerServices;
namespace Snap.Hutao.Core;
internal struct UnsafeDateTimeOffset
internal static class UnsafeDateTimeOffset
{
private DateTime dateTime;
private short offsetMinutes;
public DateTime DateTime { readonly get => dateTime; set => dateTime = value; }
[Pure]
[SuppressMessage("", "SH002")]
public static unsafe DateTimeOffset AdjustOffsetOnly(DateTimeOffset dateTimeOffset, in TimeSpan offset)
{
UnsafeDateTimeOffset* pUnsafe = (UnsafeDateTimeOffset*)&dateTimeOffset;
pUnsafe->offsetMinutes = (short)(offset.Ticks / TimeSpan.TicksPerMinute);
return dateTimeOffset;
return new(GetPrivateDateTime(ref dateTimeOffset), offset);
}
[UnsafeAccessor(UnsafeAccessorKind.Field, Name = "_dateTime")]
private static extern ref readonly DateTime GetPrivateDateTime(ref DateTimeOffset dateTimeOffset);
}

View File

@@ -12,17 +12,17 @@ internal static class WinRTExtension
{
IObjectReference objectReference = obj.NativeObject;
lock (GetDisposedLock(objectReference))
lock (GetPrivateDisposedLock(objectReference))
{
return GetDisposed(objectReference);
return GetProtectedDisposed(objectReference);
}
}
// protected bool disposed;
[UnsafeAccessor(UnsafeAccessorKind.Field, Name ="disposed")]
private static extern ref bool GetDisposed(IObjectReference objRef);
private static extern ref bool GetProtectedDisposed(IObjectReference objRef);
// private object _disposedLock
[UnsafeAccessor(UnsafeAccessorKind.Field, Name = "_disposedLock")]
private static extern ref object GetDisposedLock(IObjectReference objRef);
private static extern ref object GetPrivateDisposedLock(IObjectReference objRef);
}

View File

@@ -104,6 +104,6 @@ internal sealed class UIGF : IJsonOnSerializing, IJsonOnDeserialized
return new TimeSpan(offsetHours, 0, 0);
}
return PlayerUid.GetRegionTimeZoneUtcOffset(Info.Uid);
return PlayerUid.GetRegionTimeZoneUtcOffsetForUid(Info.Uid);
}
}

View File

@@ -75,7 +75,7 @@ internal sealed class UIGFInfo : IMappingFrom<UIGFInfo, RuntimeOptions, Metadata
ExportApp = SH.AppName,
ExportAppVersion = runtimeOptions.Version.ToString(),
UIGFVersion = UIGF.CurrentVersion,
RegionTimeZone = PlayerUid.GetRegionTimeZoneUtcOffset(uid).Hours,
RegionTimeZone = PlayerUid.GetRegionTimeZoneUtcOffsetForUid(uid).Hours,
};
}
}

View File

@@ -294,7 +294,7 @@
<PackageReference Include="Microsoft.VisualStudio.Validation" Version="17.8.8" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.2428" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.4.231115000" />
<PackageReference Include="Snap.Discord.GameSDK" Version="1.4.0" />
<PackageReference Include="Snap.Discord.GameSDK" Version="1.5.0" />
<PackageReference Include="StyleCop.Analyzers.Unstable" Version="1.2.0.507">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

View File

@@ -1,13 +1,15 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Snap.Hutao.Core;
namespace Snap.Hutao.Web.Hoyolab.Hk4e.Event.GachaInfo;
/// <summary>
/// 祈愿记录分页
/// </summary>
[HighQuality]
internal sealed class GachaLogPage
internal sealed class GachaLogPage : IJsonOnDeserialized
{
/// <summary>
/// 页码
@@ -40,4 +42,15 @@ internal sealed class GachaLogPage
/// </summary>
[JsonPropertyName("region")]
public string Region { get; set; } = default!;
public void OnDeserialized()
{
// Adjust items timezone
TimeSpan offset = PlayerUid.GetRegionTimeZoneUtcOffsetForRegion(Region);
foreach (GachaLogItem item in List)
{
item.Time = UnsafeDateTimeOffset.AdjustOffsetOnly(item.Time, offset);
}
}
}

View File

@@ -43,15 +43,8 @@ internal readonly partial struct PlayerUid
return new(uid);
}
/// <summary>
/// 判断是否为国际服
/// </summary>
/// <param name="uid">uid</param>
/// <returns>是否为国际服</returns>
public static bool IsOversea(string uid)
{
// We make this a static method rather than property,
// to avoid unnecessary memory allocation (Region field).
Must.Argument(UidRegex().IsMatch(uid), SH.WebHoyolabInvalidUid);
return uid.AsSpan()[0] switch
@@ -61,10 +54,8 @@ internal readonly partial struct PlayerUid
};
}
public static TimeSpan GetRegionTimeZoneUtcOffset(string uid)
public static TimeSpan GetRegionTimeZoneUtcOffsetForUid(string uid)
{
// We make this a static method rather than property,
// to avoid unnecessary memory allocation (Region field).
Must.Argument(UidRegex().IsMatch(uid), SH.WebHoyolabInvalidUid);
// 美服 UTC-05
@@ -78,6 +69,19 @@ internal readonly partial struct PlayerUid
};
}
public static TimeSpan GetRegionTimeZoneUtcOffsetForRegion(string region)
{
// 美服 UTC-05
// 欧服 UTC+01
// 其他 UTC+08
return region switch
{
"os_usa" => ServerRegionTimeZone.AmericaServerOffset,
"os_euro" => ServerRegionTimeZone.EuropeServerOffset,
_ => ServerRegionTimeZone.CommonOffset,
};
}
/// <inheritdoc/>
public override string ToString()
{