StructReader.cs 1021 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using ChocolArm64.Memory;
  2. using System.Runtime.InteropServices;
  3. namespace Ryujinx.HLE.Utilities
  4. {
  5. class StructReader
  6. {
  7. private MemoryManager Memory;
  8. public long Position { get; private set; }
  9. public StructReader(MemoryManager Memory, long Position)
  10. {
  11. this.Memory = Memory;
  12. this.Position = Position;
  13. }
  14. public T Read<T>() where T : struct
  15. {
  16. T Value = MemoryHelper.Read<T>(Memory, Position);
  17. Position += Marshal.SizeOf<T>();
  18. return Value;
  19. }
  20. public T[] Read<T>(int Size) where T : struct
  21. {
  22. int StructSize = Marshal.SizeOf<T>();
  23. int Count = Size / StructSize;
  24. T[] Output = new T[Count];
  25. for (int Index = 0; Index < Count; Index++)
  26. {
  27. Output[Index] = MemoryHelper.Read<T>(Memory, Position);
  28. Position += StructSize;
  29. }
  30. return Output;
  31. }
  32. }
  33. }