wm2field.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using Microsoft.Xna.Framework;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Runtime.InteropServices;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. namespace OpenVIII.Core.World
  10. {
  11. /// <summary>
  12. /// wm2field.tbl = World Map to Field table = helper class that determines the X Y and Z position and also fieldId to warp from field. This file
  13. /// does not contain the X Y and Z coordinates for world map!
  14. /// </summary>
  15. class wm2field
  16. {
  17. [StructLayout(LayoutKind.Sequential, Pack =1, Size =24)]
  18. public struct warpEntry
  19. {
  20. public short fieldX;
  21. public short fieldY;
  22. public ushort fieldZ;
  23. public ushort fieldId;
  24. public byte unk1;
  25. public byte unk2;
  26. public byte unk3;
  27. public byte unk4;
  28. [MarshalAs(UnmanagedType.ByValArray, SizeConst = 12)]
  29. public byte[] padd;
  30. }
  31. public warpEntry[] warpEntries;
  32. public wm2field(byte[] buffer)
  33. {
  34. int structSize = Marshal.SizeOf(typeof(warpEntry));
  35. warpEntries = new warpEntry[buffer.Length / structSize];
  36. for (int i = 0; i < warpEntries.Length; i++)
  37. warpEntries[i] = Extended.ByteArrayToStructure<warpEntry>(buffer.Skip(i * structSize).Take(structSize).ToArray());
  38. }
  39. public Vector3 GetFieldPosition(int entryId) => new Vector3(
  40. warpEntries[entryId].fieldX,
  41. warpEntries[entryId].fieldY,
  42. warpEntries[entryId].fieldZ);
  43. public int GetFieldId(int entryId) => warpEntries[entryId].fieldId;
  44. }
  45. }