Kernel_bin.Menu_abilities.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. using System.Collections.Generic;
  2. using System.IO;
  3. using System.Linq;
  4. namespace OpenVIII
  5. {
  6. namespace Kernel
  7. {
  8. #region Classes
  9. /// <summary>
  10. /// Menu Abilities Data
  11. /// </summary>
  12. /// <see cref="https://github.com/alexfilth/doomtrain/wiki/Menu-abilities"/>
  13. public class MenuAbilities : Ability
  14. {
  15. #region Fields
  16. /// <summary>
  17. /// Section Count
  18. /// </summary>
  19. public const int Count = 24;
  20. /// <summary>
  21. /// Section ID
  22. /// </summary>
  23. public const int ID = 17;
  24. /// <summary>
  25. /// Icon for this type.
  26. /// </summary>
  27. private new const Icons.ID Icon = Icons.ID.Ability_Menu;
  28. #endregion Fields
  29. #region Constructors
  30. private MenuAbilities(FF8String name, FF8String description, byte ap, byte index, byte start, byte end)
  31. : base(name, description, ap, Icon)
  32. => (Index, Start, End) = (index, start, end);
  33. #endregion Constructors
  34. #region Properties
  35. /// <summary>
  36. /// End offset
  37. /// </summary>
  38. public byte End { get; }
  39. /// <summary>
  40. /// <para>Index to m00X files in menu.fs</para>
  41. /// <para>first 3 sections are treated as special cases</para>
  42. /// </summary>
  43. public byte Index { get; }
  44. /// <summary>
  45. /// Start offset
  46. /// </summary>
  47. public byte Start { get; }
  48. #endregion Properties
  49. #region Methods
  50. public static Dictionary<Abilities, MenuAbilities> Read(BinaryReader br)
  51. => Enumerable.Range(0, Count)
  52. .ToDictionary(i => (Abilities)(i + (int)Abilities.Haggle), i => CreateInstance(br, i));
  53. private static MenuAbilities CreateInstance(BinaryReader br, int i)
  54. {
  55. //0x0000 2 bytes Offset
  56. FF8StringReference name = Memory.Strings.Read(Strings.FileID.KERNEL, ID, i * 2);
  57. //0x0002 2 bytes Offset
  58. FF8StringReference description = Memory.Strings.Read(Strings.FileID.KERNEL, ID, i * 2 + 1);
  59. br.BaseStream.Seek(4, SeekOrigin.Current);
  60. //0x0004 1 byte
  61. byte ap = br.ReadByte();
  62. //0x0005 1 byte
  63. byte index = br.ReadByte();
  64. //0x0006 1 byte
  65. byte start = br.ReadByte();
  66. //0x0007 1 byte
  67. byte end = br.ReadByte();
  68. return new MenuAbilities(name, description, ap, index, start, end);
  69. }
  70. #endregion Methods
  71. }
  72. #endregion Classes
  73. }
  74. }