StructReader.cs 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using Ryujinx.Cpu;
  2. using Ryujinx.Memory;
  3. using System.Runtime.InteropServices;
  4. namespace Ryujinx.HLE.Utilities
  5. {
  6. class StructReader
  7. {
  8. private IVirtualMemoryManager _memory;
  9. public long Position { get; private set; }
  10. public StructReader(IVirtualMemoryManager memory, long position)
  11. {
  12. _memory = memory;
  13. Position = position;
  14. }
  15. public T Read<T>() where T : struct
  16. {
  17. T value = MemoryHelper.Read<T>(_memory, Position);
  18. Position += Marshal.SizeOf<T>();
  19. return value;
  20. }
  21. public T[] Read<T>(int size) where T : struct
  22. {
  23. int structSize = Marshal.SizeOf<T>();
  24. int count = size / structSize;
  25. T[] output = new T[count];
  26. for (int index = 0; index < count; index++)
  27. {
  28. output[index] = MemoryHelper.Read<T>(_memory, Position);
  29. Position += structSize;
  30. }
  31. return output;
  32. }
  33. }
  34. }