aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.HLE/Utilities/StructReader.cs
blob: 19fd2674750e77754549f9a24a89b610b782e15a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using ChocolArm64.Memory;
using System.Runtime.InteropServices;

namespace Ryujinx.HLE.Utilities
{
    class StructReader
    {
        private MemoryManager Memory;

        public long Position { get; private set; }

        public StructReader(MemoryManager Memory, long Position)
        {
            this.Memory   = Memory;
            this.Position = Position;
        }

        public T Read<T>() where T : struct
        {
            T Value = MemoryHelper.Read<T>(Memory, Position);

            Position += Marshal.SizeOf<T>();

            return Value;
        }

        public T[] Read<T>(int Size) where T : struct
        {
            int StructSize = Marshal.SizeOf<T>();

            int Count = Size / StructSize;

            T[] Output = new T[Count];

            for (int Index = 0; Index < Count; Index++)
            {
                Output[Index] = MemoryHelper.Read<T>(Memory, Position);

                Position += StructSize;
            }

            return Output;
        }
    }
}