Strings.Kernel.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. /// <summary>
  13. /// <para>Kernel.bin Strings</para>
  14. /// <para>Has Multibyte Characters, Requires Namedic</para>
  15. /// </summary>
  16. public class Kernel : StringsBase
  17. {
  18. #region Fields
  19. protected uint[] StringsPadLoc;
  20. #endregion Fields
  21. #region Constructors
  22. public Kernel()
  23. { }
  24. static public Kernel Load() => Load<Kernel>();
  25. protected override void DefaultValues()
  26. {
  27. SetValues(Memory.Archives.A_MAIN, "kernel.bin");
  28. }
  29. #endregion Constructors
  30. #region Properties
  31. /// <summary>
  32. /// <para>uint pointer locations, tuple(uint StringLocation,uint get, unit skip)</para>
  33. /// <para>
  34. /// So you read the pointers at location, you get so many pointers then skip so many
  35. /// bytes before getting more pointers. Do this till start of next section.
  36. /// </para>
  37. /// </summary>
  38. /// <remarks>Colly's list of string pointers. Adapted.</remarks>
  39. /// <see cref="http://www.balamb.pl/qh/kernel-pointers.htm"/>
  40. public Dictionary<uint, Tuple<uint, uint, uint>> StringLocations
  41. { get; private set; }
  42. #endregion Properties
  43. #region Methods
  44. /// <summary>
  45. /// Read Section Pointers
  46. /// </summary>
  47. /// <param name="br"></param>
  48. protected override void GetFileLocations(BinaryReader br)
  49. {
  50. uint count = br.ReadUInt32();
  51. while (count-- > 0)
  52. {
  53. Loc l = new Loc { seek = br.ReadUInt32() };
  54. if (count <= 0) l.length = (uint)br.BaseStream.Length - l.seek;
  55. else
  56. {
  57. l.length = br.ReadUInt32() - l.seek;
  58. br.BaseStream.Seek(-4, SeekOrigin.Current);
  59. }
  60. Files.subPositions.Add(l);
  61. }
  62. }
  63. /// <summary>
  64. /// Fetch strings from kernel.bin
  65. /// </summary>
  66. /// <see cref="http://www.balamb.pl/qh/kernel-pointers.htm"/>
  67. protected override void LoadArchiveFiles()
  68. {
  69. Settings = (FF8StringReference.Settings.MultiCharByte | FF8StringReference.Settings.Namedic);
  70. ArchiveWorker aw = new ArchiveWorker(Archive);
  71. Files = new StringFile(56);
  72. MemoryStream ms = null;
  73. using (BinaryReader br = new BinaryReader(ms = new MemoryStream(aw.GetBinaryFile(Filenames[0], true))))
  74. {
  75. GetFileLocations(br);
  76. //index, grab, skip
  77. StringLocations = new Dictionary<uint, Tuple<uint, uint, uint>> {
  78. //working
  79. {0, new Tuple<uint, uint, uint>(31,2,4) },
  80. {1, new Tuple<uint, uint, uint>(32,2,56) },
  81. {2, new Tuple<uint, uint, uint>(33,2,128) },
  82. {3, new Tuple<uint, uint, uint>(34,1,18) },//38,58,178, or 78
  83. {4, new Tuple<uint, uint, uint>(35,1,10) },
  84. {5, new Tuple<uint, uint, uint>(36,2,20) },
  85. {6, new Tuple<uint, uint, uint>(37,1,34) },//+1interval 70 //character names here.
  86. {7, new Tuple<uint, uint, uint>(38,2,20) },
  87. {8, new Tuple<uint, uint, uint>(39,1,0) },
  88. {9, new Tuple<uint, uint, uint>(40,1,18) },
  89. {11, new Tuple<uint, uint, uint>(41,2,4) },
  90. {12, new Tuple<uint, uint, uint>(42,2,4) },
  91. {13, new Tuple<uint, uint, uint>(43,2,4) },
  92. {14, new Tuple<uint, uint, uint>(44,2,4) },
  93. {15, new Tuple<uint, uint, uint>(45,2,4) },
  94. {16, new Tuple<uint, uint, uint>(46,2,4) },
  95. {17, new Tuple<uint, uint, uint>(47,2,4) },
  96. {18, new Tuple<uint, uint, uint>(48,2,20) },
  97. {19, new Tuple<uint, uint, uint>(49,2,12) },
  98. {21, new Tuple<uint, uint, uint>(50,2,20) },
  99. {22, new Tuple<uint, uint, uint>(51,2,28) },
  100. {24, new Tuple<uint, uint, uint>(52,2,4) },
  101. {25, new Tuple<uint, uint, uint>(53,1,18) },
  102. {28, new Tuple<uint, uint, uint>(54,1,10) },
  103. {30, new Tuple<uint, uint, uint>(55,1,0) },
  104. };
  105. for (uint key = 0; key < Files.subPositions.Count; key++)
  106. {
  107. Loc fpos = Files.subPositions[(int)key];
  108. if (StringLocations.ContainsKey(key))
  109. {
  110. Get_Strings_BinMSG(br, Filenames[0], key, Files.subPositions[(int)(StringLocations[key].Item1)].seek, StringLocations[key].Item2, StringLocations[key].Item3);
  111. }
  112. }
  113. ms = null;
  114. }
  115. }
  116. #endregion Methods
  117. }
  118. #endregion Classes
  119. }
  120. }