Strings.Mngrp.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. namespace OpenVIII
  5. {
  6. /// <summary>
  7. /// Loads strings from FF8 files
  8. /// </summary>
  9. public partial class Strings
  10. {
  11. #region Classes
  12. public sealed class MenuGroup : StringsBase
  13. {
  14. #region Fields
  15. /// <summary>
  16. /// these files come in pairs. the bin has string offsets and 6 bytes of other data
  17. /// msg is where the strings are.
  18. /// </summary>
  19. private static readonly IReadOnlyDictionary<int, uint> BinMsg = new Dictionary<int, uint>
  20. {{106,111},{107,112},{108,113},{109,114},{110,115}};
  21. /// <summary>
  22. /// complex str has locations in first file, and they have 8 bytes of stuff at the start
  23. /// of each entry, 6 bytes UNK and ushort length? also can have multiple null ending
  24. /// strings per entry.
  25. /// </summary>
  26. private static readonly IReadOnlyDictionary<int, IReadOnlyList<int>> ComplexStr = new Dictionary<int, IReadOnlyList<int>> { { 74, new List<int> { 75, 76, 77, 78, 79, 80 } } };
  27. /// <summary>
  28. /// only location data before strings
  29. /// </summary>
  30. private static readonly int[] StringsLoc = { 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
  31. 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70,
  32. 71, 72, 73, 81, 82, 83, 84, 85, 86, 87, 88, 116};
  33. /// <summary>
  34. /// string contain padding values at start of file then location data before strings
  35. /// </summary>
  36. private static readonly int[] StringsPadLoc = { (int)SectionID.Tkmnmes1, (int)SectionID.Tkmnmes2, (int)SectionID.Tkmnmes3 };
  37. #endregion Fields
  38. #region Enums
  39. private enum SectionID
  40. {
  41. Tkmnmes1,
  42. Tkmnmes2,
  43. Tkmnmes3,
  44. }
  45. #endregion Enums
  46. #region Methods
  47. public static MenuGroup Load() => Load<MenuGroup>();
  48. protected override void DefaultValues() => SetValues(Memory.Archives.A_MENU, "mngrp.bin", "mngrphd.bin");
  49. protected override void LoadArchiveFiles()
  50. {
  51. StringFiles = new StringFile(118);
  52. GetFileLocations();
  53. var aw = ArchiveWorker.Load(Archive, true);
  54. var buffer = aw.GetBinaryFile(FileNames[0], true);
  55. if (buffer == null) return;
  56. using (var br = new BinaryReader(new MemoryStream(buffer)))
  57. {
  58. for (var key = 0; key < StringFiles.SubPositions.Count; key++)
  59. {
  60. var pad = (Array.IndexOf(StringsPadLoc, key) >= 0);
  61. if (pad || Array.IndexOf(StringsLoc, key) >= 0)
  62. Get_Strings_Offsets(br, FileNames[0], key, pad);
  63. else if (BinMsg.ContainsKey(key))
  64. {
  65. Get_Strings_BinMSG(br, FileNames[0], key, StringFiles.SubPositions[(int)BinMsg[key]].Seek, 1, 6);
  66. }
  67. else if (ComplexStr.ContainsKey(key))
  68. {
  69. Get_Strings_ComplexStr(br, FileNames[0], key, ComplexStr[key]);
  70. }
  71. }
  72. }
  73. }
  74. private void GetFileLocations()
  75. {
  76. var aw = ArchiveWorker.Load(Archive, true);
  77. var buffer = aw.GetBinaryFile(FileNames[1], true);
  78. if (buffer == null) return;
  79. using (var br = new BinaryReader(new MemoryStream(buffer)))
  80. {
  81. GetFileLocations(br);
  82. }
  83. }
  84. private void GetFileLocations(BinaryReader br)
  85. {
  86. while (br.BaseStream.Position + 8 < br.BaseStream.Length)
  87. {
  88. (var seek, var length) = ((br.ReadUInt32(), br.ReadUInt32()));
  89. if (seek == 0xFFFFFFFF || length == 0x00000000) continue;
  90. seek--;
  91. StringFiles.SubPositions.Add(Loc.CreateInstance(seek, length));
  92. }
  93. }
  94. #endregion Methods
  95. }
  96. #endregion Classes
  97. }
  98. }