From d89b004de80ce9fbe1d9ebd29cdbeaff8d34343c Mon Sep 17 00:00:00 2001
From: Gabriel A <gab.dark.100@gmail.com>
Date: Fri, 17 Nov 2023 20:38:30 -0300
Subject: [PATCH] Delete ByteArrayN and IArray

---
 src/Ryujinx.Common/Memory/ArrayPtr.cs         |  2 +-
 src/Ryujinx.Common/Memory/IArray.cs           | 21 -----
 .../Memory/StructByteArrayHelpers.cs          | 77 -------------------
 .../Applets/Browser/WebCommonReturnValue.cs   |  2 +-
 .../HOS/Applets/Error/ApplicationErrorArg.cs  |  4 +-
 .../HOS/Applets/Error/ErrorApplet.cs          |  4 +-
 .../HOS/Services/Ro/Types/NRRCertification.cs |  4 +-
 .../HOS/Services/Ro/Types/NrrHeader.cs        |  2 +-
 8 files changed, 9 insertions(+), 107 deletions(-)
 delete mode 100644 src/Ryujinx.Common/Memory/IArray.cs
 delete mode 100644 src/Ryujinx.Common/Memory/StructByteArrayHelpers.cs

diff --git a/src/Ryujinx.Common/Memory/ArrayPtr.cs b/src/Ryujinx.Common/Memory/ArrayPtr.cs
index 0365a5089..864fb61d3 100644
--- a/src/Ryujinx.Common/Memory/ArrayPtr.cs
+++ b/src/Ryujinx.Common/Memory/ArrayPtr.cs
@@ -9,7 +9,7 @@ namespace Ryujinx.Common.Memory
     /// Represents an array of unmanaged resources.
     /// </summary>
     /// <typeparam name="T">Array element type</typeparam>
-    public unsafe struct ArrayPtr<T> : IEquatable<ArrayPtr<T>>, IArray<T> where T : unmanaged
+    public unsafe struct ArrayPtr<T> : IEquatable<ArrayPtr<T>> where T : unmanaged
     {
         private IntPtr _ptr;
 
diff --git a/src/Ryujinx.Common/Memory/IArray.cs b/src/Ryujinx.Common/Memory/IArray.cs
deleted file mode 100644
index 8f17fade0..000000000
--- a/src/Ryujinx.Common/Memory/IArray.cs
+++ /dev/null
@@ -1,21 +0,0 @@
-namespace Ryujinx.Common.Memory
-{
-    /// <summary>
-    /// Array interface.
-    /// </summary>
-    /// <typeparam name="T">Element type</typeparam>
-    public interface IArray<T> where T : unmanaged
-    {
-        /// <summary>
-        /// Used to index the array.
-        /// </summary>
-        /// <param name="index">Element index</param>
-        /// <returns>Element at the specified index</returns>
-        ref T this[int index] { get; }
-
-        /// <summary>
-        /// Number of elements on the array.
-        /// </summary>
-        int Length { get; }
-    }
-}
diff --git a/src/Ryujinx.Common/Memory/StructByteArrayHelpers.cs b/src/Ryujinx.Common/Memory/StructByteArrayHelpers.cs
deleted file mode 100644
index f0f452730..000000000
--- a/src/Ryujinx.Common/Memory/StructByteArrayHelpers.cs
+++ /dev/null
@@ -1,77 +0,0 @@
-using System;
-using System.Runtime.InteropServices;
-
-namespace Ryujinx.Common.Memory
-{
-    [StructLayout(LayoutKind.Sequential, Size = Size, Pack = 1)]
-    public struct ByteArray128 : IArray<byte>
-    {
-        private const int Size = 128;
-
-        byte _element;
-
-        public readonly int Length => Size;
-        public ref byte this[int index] => ref AsSpan()[index];
-        public Span<byte> AsSpan() => MemoryMarshal.CreateSpan(ref _element, Size);
-    }
-
-    [StructLayout(LayoutKind.Sequential, Size = Size, Pack = 1)]
-    public struct ByteArray256 : IArray<byte>
-    {
-        private const int Size = 256;
-
-        byte _element;
-
-        public readonly int Length => Size;
-        public ref byte this[int index] => ref AsSpan()[index];
-        public Span<byte> AsSpan() => MemoryMarshal.CreateSpan(ref _element, Size);
-    }
-
-    [StructLayout(LayoutKind.Sequential, Size = Size, Pack = 1)]
-    public struct ByteArray512 : IArray<byte>
-    {
-        private const int Size = 512;
-
-        byte _element;
-
-        public readonly int Length => Size;
-        public ref byte this[int index] => ref AsSpan()[index];
-        public Span<byte> AsSpan() => MemoryMarshal.CreateSpan(ref _element, Size);
-    }
-
-    [StructLayout(LayoutKind.Sequential, Size = Size, Pack = 1)]
-    public struct ByteArray1024 : IArray<byte>
-    {
-        private const int Size = 1024;
-
-        byte _element;
-
-        public readonly int Length => Size;
-        public ref byte this[int index] => ref AsSpan()[index];
-        public Span<byte> AsSpan() => MemoryMarshal.CreateSpan(ref _element, Size);
-    }
-
-    [StructLayout(LayoutKind.Sequential, Size = Size, Pack = 1)]
-    public struct ByteArray2048 : IArray<byte>
-    {
-        private const int Size = 2048;
-
-        byte _element;
-
-        public readonly int Length => Size;
-        public ref byte this[int index] => ref AsSpan()[index];
-        public Span<byte> AsSpan() => MemoryMarshal.CreateSpan(ref _element, Size);
-    }
-
-    [StructLayout(LayoutKind.Sequential, Size = Size, Pack = 1)]
-    public struct ByteArray4096 : IArray<byte>
-    {
-        private const int Size = 4096;
-
-        byte _element;
-
-        public readonly int Length => Size;
-        public ref byte this[int index] => ref AsSpan()[index];
-        public Span<byte> AsSpan() => MemoryMarshal.CreateSpan(ref _element, Size);
-    }
-}
diff --git a/src/Ryujinx.HLE/HOS/Applets/Browser/WebCommonReturnValue.cs b/src/Ryujinx.HLE/HOS/Applets/Browser/WebCommonReturnValue.cs
index a1bdf0c76..9ea26079a 100644
--- a/src/Ryujinx.HLE/HOS/Applets/Browser/WebCommonReturnValue.cs
+++ b/src/Ryujinx.HLE/HOS/Applets/Browser/WebCommonReturnValue.cs
@@ -6,7 +6,7 @@ namespace Ryujinx.HLE.HOS.Applets.Browser
     {
         public WebExitReason ExitReason;
         public uint Padding;
-        public ByteArray4096 LastUrl;
+        public Array4096<byte> LastUrl;
         public ulong LastUrlSize;
     }
 }
diff --git a/src/Ryujinx.HLE/HOS/Applets/Error/ApplicationErrorArg.cs b/src/Ryujinx.HLE/HOS/Applets/Error/ApplicationErrorArg.cs
index 4263c84b8..93c2abb3d 100644
--- a/src/Ryujinx.HLE/HOS/Applets/Error/ApplicationErrorArg.cs
+++ b/src/Ryujinx.HLE/HOS/Applets/Error/ApplicationErrorArg.cs
@@ -8,7 +8,7 @@ namespace Ryujinx.HLE.HOS.Applets.Error
     {
         public uint ErrorNumber;
         public ulong LanguageCode;
-        public ByteArray2048 MessageText;
-        public ByteArray2048 DetailsText;
+        public Array2048<byte> MessageText;
+        public Array2048<byte> DetailsText;
     }
 }
diff --git a/src/Ryujinx.HLE/HOS/Applets/Error/ErrorApplet.cs b/src/Ryujinx.HLE/HOS/Applets/Error/ErrorApplet.cs
index fa415b396..30f3dd989 100644
--- a/src/Ryujinx.HLE/HOS/Applets/Error/ErrorApplet.cs
+++ b/src/Ryujinx.HLE/HOS/Applets/Error/ErrorApplet.cs
@@ -183,8 +183,8 @@ namespace Ryujinx.HLE.HOS.Applets.Error
             byte[] messageTextBuffer = new byte[0x800];
             byte[] detailsTextBuffer = new byte[0x800];
 
-            applicationErrorArg.MessageText.AsSpan().CopyTo(messageTextBuffer);
-            applicationErrorArg.DetailsText.AsSpan().CopyTo(detailsTextBuffer);
+            ((Span<byte>)applicationErrorArg.MessageText).CopyTo(messageTextBuffer);
+            ((Span<byte>)applicationErrorArg.DetailsText).CopyTo(detailsTextBuffer);
 
             string messageText = Encoding.ASCII.GetString(messageTextBuffer.TakeWhile(b => !b.Equals(0)).ToArray());
             string detailsText = Encoding.ASCII.GetString(detailsTextBuffer.TakeWhile(b => !b.Equals(0)).ToArray());
diff --git a/src/Ryujinx.HLE/HOS/Services/Ro/Types/NRRCertification.cs b/src/Ryujinx.HLE/HOS/Services/Ro/Types/NRRCertification.cs
index 8c56adb9f..d1b626913 100644
--- a/src/Ryujinx.HLE/HOS/Services/Ro/Types/NRRCertification.cs
+++ b/src/Ryujinx.HLE/HOS/Services/Ro/Types/NRRCertification.cs
@@ -9,7 +9,7 @@ namespace Ryujinx.HLE.HOS.Services.Ro
         public ulong ApplicationIdMask;
         public ulong ApplicationIdPattern;
         private Array16<byte> _reserved;
-        public ByteArray256 Modulus;
-        public ByteArray256 Signature;
+        public Array256<byte> Modulus;
+        public Array256<byte> Signature;
     }
 }
diff --git a/src/Ryujinx.HLE/HOS/Services/Ro/Types/NrrHeader.cs b/src/Ryujinx.HLE/HOS/Services/Ro/Types/NrrHeader.cs
index dbbcb1511..c6c8aaa7b 100644
--- a/src/Ryujinx.HLE/HOS/Services/Ro/Types/NrrHeader.cs
+++ b/src/Ryujinx.HLE/HOS/Services/Ro/Types/NrrHeader.cs
@@ -10,7 +10,7 @@ namespace Ryujinx.HLE.HOS.Services.Ro
         public uint KeyGeneration; // 9.0.0+
         private Array8<byte> _reserved;
         public NRRCertification Certification;
-        public ByteArray256 Signature;
+        public Array256<byte> Signature;
         public ulong TitleId;
         public uint Size;
         public byte Kind; // 7.0.0+