Program.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. using System;
  2. using System.Collections.Concurrent;
  3. using System.Globalization;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Xml;
  7. namespace OpenVIII.Dat_Dump
  8. {
  9. internal class Program
  10. {
  11. #region Methods
  12. private static ConcurrentDictionary<int, Debug_battleDat> MonsterData = new ConcurrentDictionary<int, Debug_battleDat>();
  13. private static ConcurrentDictionary<int, Debug_battleDat> CharacterData = new ConcurrentDictionary<int, Debug_battleDat>();
  14. private static void Main(string[] args)
  15. {
  16. start:
  17. Memory.Init(null, null, null);
  18. XmlWriterSettings xmlWriterSettings = new XmlWriterSettings
  19. {
  20. Indent = true,
  21. IndentChars = "\t", // note: default is two spaces
  22. NewLineOnAttributes = true,
  23. OmitXmlDeclaration = false,
  24. };
  25. using (StreamWriter csv2File = new StreamWriter(new FileStream("MonsterAttacks.csv", FileMode.Create, FileAccess.Write, FileShare.ReadWrite)))
  26. {
  27. using (StreamWriter csvFile = new StreamWriter(new FileStream("SequenceDump.csv", FileMode.Create, FileAccess.Write, FileShare.ReadWrite)))
  28. {
  29. csv2File.WriteLine($"{nameof(Enemy)}{ls}" +
  30. $"{nameof(Enemy.EII.Data.fileName)}{ls}" +
  31. $"{nameof(Debug_battleDat.Abilities)}{ls}" +
  32. $"Number{ls}" +
  33. $"{nameof(Debug_battleDat.Abilities.animation)}{ls}" +
  34. $"Type{ls}" +
  35. $"ID{ls}" +
  36. $"Name{ls}");
  37. csvFile.WriteLine($"Type{ls}Type ID{ls}Name{ls}Animation Count{ls}Sequence Count{ls}Sequence ID{ls}Offset{ls}Bytes");
  38. using (XmlWriter xmlWriter = XmlWriter.Create("SequenceDump.xml", xmlWriterSettings))
  39. {
  40. xmlWriter.WriteStartDocument();
  41. xmlWriter.WriteStartElement("dat");
  42. XmlMonsterData(xmlWriter, csvFile, csv2File);
  43. XmlCharacterData(xmlWriter, csvFile);
  44. xmlWriter.WriteEndElement();
  45. xmlWriter.WriteEndDocument();
  46. }
  47. }
  48. }
  49. Console.Write("Press [Enter] key to continue... ");
  50. FF8String sval = Console.ReadLine().Trim((Environment.NewLine + " _").ToCharArray());
  51. goto start;
  52. }
  53. private static void XmlMonsterData(XmlWriter xmlWriter, StreamWriter csvFile, StreamWriter csv2File)
  54. {
  55. xmlWriter.WriteStartElement("monsters");
  56. for (int i = 0; i <= 200; i++)
  57. {
  58. MonsterData.TryAdd(i, Debug_battleDat.Load(i, Debug_battleDat.EntityType.Monster));
  59. if (MonsterData.TryGetValue(i, out Debug_battleDat _BattleDat) && _BattleDat != null)
  60. {
  61. const string type = "monster";
  62. string id = i.ToString();
  63. FF8String name = _BattleDat.information.name ?? new FF8String("");
  64. string prefix = $"{type}{ls}{id}{ls}{name}";
  65. xmlWriter.WriteStartElement(type);
  66. xmlWriter.WriteAttributeString("id", id);
  67. xmlWriter.WriteAttributeString("name", name);
  68. prefix += $"{ls}{XMLAnimations(xmlWriter, _BattleDat)}";
  69. XMLSequences(xmlWriter, _BattleDat, csvFile, prefix);
  70. xmlWriter.WriteEndElement();
  71. Enemy e = Enemy.Load(new Module_battle_debug.EnemyInstanceInformation { Data = _BattleDat });
  72. void addability(string fieldname, Debug_battleDat.Abilities a, int number)
  73. {
  74. csv2File.WriteLine($"{name}{ls}" +
  75. $"{_BattleDat.fileName}{ls}" +
  76. $"{fieldname}{ls}" +
  77. $"{number}{ls}" +
  78. $"{a.animation}{ls}" +
  79. $"{(a.ITEM != null ? nameof(a.ITEM) : a.MAGIC != null ? nameof(a.MAGIC) : a.MONSTER != null ? nameof(a.MONSTER) : "")}{ls}" +
  80. $"{(a.ITEM != null ? a.ITEM.Value.ID : a.MAGIC != null ? a.MAGIC.ID : a.MONSTER != null ? a.MONSTER.ID : 0)}{ls}" +
  81. $"\"{(a.ITEM != null ? a.ITEM.Value.Name : a.MAGIC != null ? a.MAGIC.Name : a.MONSTER != null ? a.MONSTER.Name : new FF8String(""))}\"{ls}");
  82. }
  83. void addabilities(string fieldname, Debug_battleDat.Abilities[] abilites)
  84. {
  85. if (abilites != null)
  86. for (int number = 0; number < e.Info.abilitiesLow.Length; number++)
  87. {
  88. Debug_battleDat.Abilities a = abilites[number];
  89. addability(fieldname, a, number);
  90. }
  91. }
  92. addabilities(nameof(e.Info.abilitiesLow), e.Info.abilitiesLow);
  93. addabilities(nameof(e.Info.abilitiesMed), e.Info.abilitiesMed);
  94. addabilities(nameof(e.Info.abilitiesHigh), e.Info.abilitiesHigh);
  95. }
  96. }
  97. xmlWriter.WriteEndElement();
  98. }
  99. private static string ls => CultureInfo.CurrentCulture.TextInfo.ListSeparator;
  100. private static void XmlCharacterData(XmlWriter xmlWriter, StreamWriter csvFile)
  101. {
  102. xmlWriter.WriteStartElement("characters");
  103. for (int i = 0; i <= 10; i++)
  104. {
  105. Debug_battleDat test = Debug_battleDat.Load(i, Debug_battleDat.EntityType.Character, 0);
  106. if (test != null && CharacterData.TryAdd(i, test))
  107. {
  108. }
  109. if (CharacterData.TryGetValue(i, out Debug_battleDat _BattleDat))
  110. {
  111. const string type = "character";
  112. xmlWriter.WriteStartElement(type);
  113. string id = i.ToString();
  114. xmlWriter.WriteAttributeString("id", id);
  115. FF8String name = Memory.Strings.GetName((Characters)i);
  116. xmlWriter.WriteAttributeString("name", name);
  117. string prefix0 = $"{type}{ls}{id}{ls}";
  118. string prefix1 = $"{name}";
  119. prefix1 += $"{ls}{XMLAnimations(xmlWriter, _BattleDat)}";
  120. XMLSequences(xmlWriter, _BattleDat, csvFile, $"{prefix0}{prefix1}");
  121. XmlWeaponData(xmlWriter, i, ref _BattleDat, csvFile, prefix1);
  122. xmlWriter.WriteEndElement();
  123. }
  124. }
  125. xmlWriter.WriteEndElement();
  126. }
  127. private static void XmlWeaponData(XmlWriter xmlWriter, int character_id, ref Debug_battleDat r, StreamWriter csvFile, string prefix1)
  128. {
  129. ConcurrentDictionary<int, Debug_battleDat> WeaponData = new ConcurrentDictionary<int, Debug_battleDat>();
  130. xmlWriter.WriteStartElement("weapons");
  131. for (int i = 0; i <= 40; i++)
  132. {
  133. Debug_battleDat test;
  134. if (character_id == 1 || character_id == 9)
  135. test = Debug_battleDat.Load(character_id, Debug_battleDat.EntityType.Weapon, i, r);
  136. else
  137. test = Debug_battleDat.Load(character_id, Debug_battleDat.EntityType.Weapon, i);
  138. if (test != null && WeaponData.TryAdd(i, test))
  139. {
  140. }
  141. if (WeaponData.TryGetValue(i, out Debug_battleDat _BattleDat))
  142. {
  143. const string type = "weapon";
  144. string id = i.ToString();
  145. xmlWriter.WriteStartElement(type);
  146. xmlWriter.WriteAttributeString("id", id);
  147. int index = Module_battle_debug.Weapons[(Characters)character_id].FindIndex(v => v == i);
  148. Kernel_bin.Weapons_Data weapondata = Kernel_bin.WeaponsData.FirstOrDefault(v => v.Character == (Characters)character_id &&
  149. v.AltID == index);
  150. if (weapondata != default)
  151. {
  152. xmlWriter.WriteAttributeString("name", weapondata.Name);
  153. string prefix = $"{type}{ls}{id}{ls}{weapondata.Name}/{prefix1}"; //bringing over name from character.
  154. //xmlWriter.WriteAttributeString("name", Memory.Strings.GetName((Characters)i));
  155. XMLAnimations(xmlWriter, _BattleDat);
  156. XMLSequences(xmlWriter, _BattleDat, csvFile, prefix);
  157. }
  158. xmlWriter.WriteEndElement();
  159. }
  160. }
  161. xmlWriter.WriteEndElement();
  162. }
  163. private static void XMLSequences(XmlWriter xmlWriter, Debug_battleDat _BattleDat, StreamWriter csvFile, string prefix)
  164. {
  165. xmlWriter.WriteStartElement("sequences");
  166. string count = $"{_BattleDat.Sequences?.Count ?? 0}";
  167. xmlWriter.WriteAttributeString("count", count);
  168. if (_BattleDat.Sequences != null)
  169. foreach (Debug_battleDat.AnimationSequence s in _BattleDat.Sequences)
  170. {
  171. xmlWriter.WriteStartElement("sequence");
  172. string id = s.id.ToString();
  173. string offset = s.offset.ToString("X");
  174. string bytes = s.data.Length.ToString();
  175. xmlWriter.WriteAttributeString("id", id);
  176. xmlWriter.WriteAttributeString("offset", offset);
  177. xmlWriter.WriteAttributeString("bytes", bytes);
  178. csvFile?.Write($"{prefix ?? ""}{ls}{count}{ls}{id}{ls}{s.offset}{ls}{bytes}");
  179. foreach (byte b in s.data)
  180. {
  181. xmlWriter.WriteString($"{b.ToString("X2")} ");
  182. csvFile?.Write($"{ls}{b}");
  183. }
  184. csvFile?.Write(Environment.NewLine);
  185. xmlWriter.WriteEndElement();
  186. }
  187. csvFile?.Flush();
  188. xmlWriter.WriteEndElement();
  189. }
  190. private static string XMLAnimations(XmlWriter xmlWriter, Debug_battleDat _BattleDat)
  191. {
  192. string count = $"{_BattleDat.animHeader.animations?.Length ?? 0}";
  193. xmlWriter.WriteStartElement("animations");
  194. xmlWriter.WriteAttributeString("count", count);
  195. xmlWriter.WriteEndElement();
  196. return count;
  197. }
  198. #endregion Methods
  199. }
  200. }