Strings.Mngrp.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 class Mngrp : StringsBase
  13. {
  14. #region Fields
  15. private Dictionary<uint, uint> BinMSG;
  16. private Dictionary<uint, List<uint>> ComplexStr;
  17. private uint[] StringsLoc;
  18. private uint[] StringsPadLoc;
  19. #endregion Fields
  20. #region Constructors
  21. public Mngrp() { }
  22. static public Mngrp Load() => Load<Mngrp>();
  23. protected override void DefaultValues()
  24. {
  25. SetValues(Memory.Archives.A_MENU, "mngrp.bin", "mngrphd.bin");
  26. }
  27. #endregion Constructors-
  28. #region Enums
  29. private enum SectionID
  30. {
  31. tkmnmes1,
  32. tkmnmes2,
  33. tkmnmes3,
  34. }
  35. #endregion Enums
  36. #region Methods
  37. protected void GetFileLocations()
  38. {
  39. ArchiveWorker aw = new ArchiveWorker(Archive, true);
  40. MemoryStream ms = null;
  41. using (BinaryReader br = new BinaryReader(ms = new MemoryStream(aw.GetBinaryFile(Filenames[1], true))))
  42. {
  43. GetFileLocations(br);
  44. ms = null;
  45. }
  46. }
  47. protected override void GetFileLocations(BinaryReader br)
  48. {
  49. while (br.BaseStream.Position < br.BaseStream.Length)
  50. {
  51. Loc loc = new Loc() { seek = br.ReadUInt32(), length = br.ReadUInt32() };
  52. if (loc.seek != 0xFFFFFFFF && loc.length != 0x00000000)
  53. {
  54. loc.seek--;
  55. Files.subPositions.Add(loc);
  56. }
  57. }
  58. }
  59. protected override void LoadArchiveFiles()
  60. {
  61. Files = new StringFile(118);
  62. GetFileLocations();
  63. ArchiveWorker aw = new ArchiveWorker(Archive, true);
  64. MemoryStream ms = null;
  65. using (BinaryReader br = new BinaryReader(ms = new MemoryStream(aw.GetBinaryFile(Filenames[0], true))))
  66. {
  67. //string contain padding values at start of file
  68. //then location data before strings
  69. StringsPadLoc = new uint[] { (uint)SectionID.tkmnmes1, (uint)SectionID.tkmnmes2, (uint)SectionID.tkmnmes3 };
  70. //only location data before strings
  71. StringsLoc = new uint[] { 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
  72. 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70,
  73. 71, 72, 73, 81, 82, 83, 84, 85, 86, 87, 88, 116};
  74. //complexstr has locations in first file,
  75. //and they have 8 bytes of stuff at the start of each entry, 6 bytes UNK and ushort length?
  76. //also can have multiple null ending strings per entry.
  77. ComplexStr = new Dictionary<uint, List<uint>> { { 74, new List<uint> { 75, 76, 77, 78, 79, 80 } } };
  78. //these files come in pairs. the bin has string offsets and 6 bytes of other data
  79. //msg is where the strings are.
  80. BinMSG = new Dictionary<uint, uint>
  81. {{106,111},{107,112},{108,113},{109,114},{110,115}};
  82. for (uint key = 0; key < Files.subPositions.Count; key++)
  83. {
  84. Loc fpos = Files.subPositions[(int)key];
  85. bool pad = (Array.IndexOf(StringsPadLoc, key) >= 0);
  86. if (pad || Array.IndexOf(StringsLoc, key) >= 0)
  87. Get_Strings_Offsets(br, Filenames[0], key, pad);
  88. else if (BinMSG.ContainsKey(key))
  89. {
  90. Get_Strings_BinMSG(br, Filenames[0], key, Files.subPositions[(int)BinMSG[key]].seek, 1, 6);
  91. }
  92. else if (ComplexStr.ContainsKey(key))
  93. {
  94. Get_Strings_ComplexStr(br, Filenames[0], key, ComplexStr[key]);
  95. }
  96. }
  97. ms = null;
  98. }
  99. }
  100. #endregion Methods
  101. }
  102. #endregion Classes
  103. }
  104. }