aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Common/Extensions/BinaryReaderExtensions.cs
diff options
context:
space:
mode:
authorThomas Guillemard <thog@protonmail.com>2019-06-27 13:11:51 +0200
committerAc_K <Acoustik666@gmail.com>2019-06-27 13:11:51 +0200
commitdb21621bb681ee6d85f81fd04d7ea286b0742ca7 (patch)
tree074d7c89032cc7775d2ec04679a3cdc78a9d2735 /Ryujinx.Common/Extensions/BinaryReaderExtensions.cs
parent3db9daa3bda5053fdbda248263f0b8fa46bdba0d (diff)
PrntStub: Add a way to print arrays (#711)
* PrntStub: Add a way to print arrays This commit adds support for printing arrays in stubs (useful for IPC InBuffer/InPointer). This also add an util to parse an array of structure from a BinaryReader * Fix missing space Co-Authored-By: Ac_K <Acoustik666@gmail.com>
Diffstat (limited to 'Ryujinx.Common/Extensions/BinaryReaderExtensions.cs')
-rw-r--r--Ryujinx.Common/Extensions/BinaryReaderExtensions.cs20
1 files changed, 20 insertions, 0 deletions
diff --git a/Ryujinx.Common/Extensions/BinaryReaderExtensions.cs b/Ryujinx.Common/Extensions/BinaryReaderExtensions.cs
index 49af946f..05c77fe9 100644
--- a/Ryujinx.Common/Extensions/BinaryReaderExtensions.cs
+++ b/Ryujinx.Common/Extensions/BinaryReaderExtensions.cs
@@ -19,6 +19,26 @@ namespace Ryujinx.Common
}
}
+ public unsafe static T[] ReadStructArray<T>(this BinaryReader reader, int count)
+ where T : struct
+ {
+ int size = Marshal.SizeOf<T>();
+
+ T[] result = new T[count];
+
+ for (int i = 0; i < count; i++)
+ {
+ byte[] data = reader.ReadBytes(size);
+
+ fixed (byte* ptr = data)
+ {
+ result[i] = Marshal.PtrToStructure<T>((IntPtr)ptr);
+ }
+ }
+
+ return result;
+ }
+
public unsafe static void WriteStruct<T>(this BinaryWriter writer, T value)
where T : struct
{