From 2382717600939e0e970f47f404cd62672c097ad4 Mon Sep 17 00:00:00 2001 From: Mary Date: Fri, 24 Jun 2022 21:11:56 +0200 Subject: [PATCH] timezone: Fix regression caused by #3361 (#3418) Because of that PR, TimeZoneRule was bigger than 0x4000 thanks to a misuse of a constant. This commit address this issue and add a new unit test to ensure the size of TimeZoneRule is 0x4000 bytes. Also address suggestions that were lost on the original PR. --- .../Time/TimeZone/Types/TimeTypeInfo.cs | 2 +- .../Time/TimeZone/Types/TimeZoneRule.cs | 12 ++++++------ Ryujinx.Tests/Ryujinx.Tests.csproj | 1 + Ryujinx.Tests/Time/TimeZoneRuleTests.cs | 18 ++++++++++++++++++ 4 files changed, 26 insertions(+), 7 deletions(-) create mode 100644 Ryujinx.Tests/Time/TimeZoneRuleTests.cs diff --git a/Ryujinx.HLE/HOS/Services/Time/TimeZone/Types/TimeTypeInfo.cs b/Ryujinx.HLE/HOS/Services/Time/TimeZone/Types/TimeTypeInfo.cs index 6a490bafcd..b8b3d9171f 100644 --- a/Ryujinx.HLE/HOS/Services/Time/TimeZone/Types/TimeTypeInfo.cs +++ b/Ryujinx.HLE/HOS/Services/Time/TimeZone/Types/TimeTypeInfo.cs @@ -4,7 +4,7 @@ using System.Runtime.InteropServices; namespace Ryujinx.HLE.HOS.Services.Time.TimeZone { [StructLayout(LayoutKind.Sequential, Size = Size, Pack = 4)] - struct TimeTypeInfo + public struct TimeTypeInfo { public const int Size = 0x10; diff --git a/Ryujinx.HLE/HOS/Services/Time/TimeZone/Types/TimeZoneRule.cs b/Ryujinx.HLE/HOS/Services/Time/TimeZone/Types/TimeZoneRule.cs index 705ff02599..67237f3d21 100644 --- a/Ryujinx.HLE/HOS/Services/Time/TimeZone/Types/TimeZoneRule.cs +++ b/Ryujinx.HLE/HOS/Services/Time/TimeZone/Types/TimeZoneRule.cs @@ -5,7 +5,7 @@ using System.Runtime.InteropServices; namespace Ryujinx.HLE.HOS.Services.Time.TimeZone { [StructLayout(LayoutKind.Sequential, Pack = 4, Size = 0x4000, CharSet = CharSet.Ansi)] - struct TimeZoneRule + public struct TimeZoneRule { public const int TzMaxTypes = 128; public const int TzMaxChars = 50; @@ -25,20 +25,20 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone public bool GoAhead; [StructLayout(LayoutKind.Sequential, Size = sizeof(long) * TzMaxTimes)] - private struct AtsStorageStruct {} + private struct AtsStorageStruct { } private AtsStorageStruct _ats; public Span Ats => SpanHelpers.AsSpan(ref _ats); [StructLayout(LayoutKind.Sequential, Size = sizeof(byte) * TzMaxTimes)] - private struct TypesStorageStruct {} + private struct TypesStorageStruct { } private TypesStorageStruct _types; - public Span Types => SpanHelpers.AsByteSpan(ref _types); + public Span Types => SpanHelpers.AsByteSpan(ref _types); - [StructLayout(LayoutKind.Sequential, Size = TimeTypeInfo.Size * TzMaxTimes)] + [StructLayout(LayoutKind.Sequential, Size = TimeTypeInfo.Size * TzMaxTypes)] private struct TimeTypeInfoStorageStruct { } private TimeTypeInfoStorageStruct _ttis; @@ -46,7 +46,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone public Span Ttis => SpanHelpers.AsSpan(ref _ttis); [StructLayout(LayoutKind.Sequential, Size = sizeof(byte) * TzCharsArraySize)] - private struct CharsStorageStruct {} + private struct CharsStorageStruct { } private CharsStorageStruct _chars; public Span Chars => SpanHelpers.AsByteSpan(ref _chars); diff --git a/Ryujinx.Tests/Ryujinx.Tests.csproj b/Ryujinx.Tests/Ryujinx.Tests.csproj index 96778486a8..ec191a8ee2 100644 --- a/Ryujinx.Tests/Ryujinx.Tests.csproj +++ b/Ryujinx.Tests/Ryujinx.Tests.csproj @@ -24,6 +24,7 @@ + diff --git a/Ryujinx.Tests/Time/TimeZoneRuleTests.cs b/Ryujinx.Tests/Time/TimeZoneRuleTests.cs new file mode 100644 index 0000000000..4d5c4eaa35 --- /dev/null +++ b/Ryujinx.Tests/Time/TimeZoneRuleTests.cs @@ -0,0 +1,18 @@ +using NUnit.Framework; +using Ryujinx.HLE.HOS.Services.Time.TimeZone; +using System.Runtime.CompilerServices; + +namespace Ryujinx.Tests.Time +{ + internal class TimeZoneRuleTests + { + class EffectInfoParameterTests + { + [Test] + public void EnsureTypeSize() + { + Assert.AreEqual(0x4000, Unsafe.SizeOf()); + } + } + } +}