Skeleton.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using Microsoft.Xna.Framework;
  2. using System.Collections.Generic;
  3. using System.Diagnostics.CodeAnalysis;
  4. using System.IO;
  5. using System.Runtime.InteropServices;
  6. namespace OpenVIII.Battle.Dat
  7. {
  8. /// <summary>
  9. /// Section 1: Skeleton
  10. /// </summary>
  11. /// <see cref="http://wiki.ffrtt.ru/index.php?title=FF8/FileFormat_DAT#Section_1:_Skeleton"/>
  12. [StructLayout(LayoutKind.Explicit, Pack = 1)]
  13. [SuppressMessage("ReSharper", "UnusedMember.Global")]
  14. public class Skeleton
  15. {
  16. #region Fields
  17. [field: FieldOffset(16)]
  18. public readonly IReadOnlyList<Bone> Bones;
  19. /// <summary>
  20. /// Number of bones
  21. /// </summary>
  22. [field: FieldOffset(0)]
  23. public readonly ushort CBones;
  24. [field: FieldOffset(2)]
  25. public readonly ushort Scale;
  26. [field: FieldOffset(4)]
  27. public readonly ushort Unk2;
  28. [field: FieldOffset(6)]
  29. public readonly ushort Unk3;
  30. [field: FieldOffset(8)]
  31. public readonly ushort Unk4;
  32. [field: FieldOffset(10)]
  33. public readonly ushort Unk5;
  34. [field: FieldOffset(12)]
  35. public readonly ushort Unk6;
  36. [field: FieldOffset(14)]
  37. public readonly ushort Unk7;
  38. #endregion Fields
  39. #region Constructors
  40. private Skeleton(BinaryReader br)
  41. {
  42. if (br.BaseStream.Position + 16 >= br.BaseStream.Length) throw new InvalidDataException($"{nameof(Skeleton)} Stream to short to read");
  43. CBones = br.ReadUInt16();
  44. Scale = br.ReadUInt16();
  45. Unk2 = br.ReadUInt16();
  46. Unk3 = br.ReadUInt16();
  47. Unk4 = br.ReadUInt16();
  48. Unk5 = br.ReadUInt16();
  49. Unk6 = br.ReadUInt16();
  50. Unk7 = br.ReadUInt16();
  51. Bones = Bone.CreateInstances(br, CBones);
  52. }
  53. #endregion Constructors
  54. #region Properties
  55. public Vector3 GetScale => new Vector3(Scale / DatFile.ScaleHelper * 12, Scale / DatFile.ScaleHelper * 12, Scale / DatFile.ScaleHelper * 12);
  56. #endregion Properties
  57. #region Methods
  58. public static Skeleton CreateInstance(BinaryReader br, long startOffset)
  59. {
  60. br.BaseStream.Seek(startOffset, SeekOrigin.Begin);
  61. return new Skeleton(br);
  62. }
  63. public static Skeleton CreateInstance(BinaryReader br) => new Skeleton(br);
  64. #endregion Methods
  65. }
  66. }