init_debugger_battle.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. using Microsoft.Xna.Framework;
  2. using System;
  3. using System.IO;
  4. using System.Linq;
  5. namespace FF8
  6. {
  7. internal static class Init_debugger_battle
  8. {
  9. public struct EncounterFlag
  10. {
  11. public bool CantEspace;
  12. public bool NoVictorySequence;
  13. public bool ShowTimer;
  14. public bool NoEXP;
  15. public bool SkipEXPScreen;
  16. public bool SurpriseAttack;
  17. public bool BackAttacked;
  18. public bool isScriptedBattle;
  19. public byte Switch { set => SetFlags(value); }
  20. public void SetFlags(byte @switch)
  21. {
  22. CantEspace = (@switch & 1) == 1;
  23. NoVictorySequence = (@switch>>1 & 1) == 1;
  24. ShowTimer = (@switch >> 2 & 1) == 1;
  25. NoEXP = (@switch >> 3 & 1) == 1;
  26. SkipEXPScreen = (@switch >> 4 & 1) == 1;
  27. SurpriseAttack = (@switch >> 5 & 1) == 1;
  28. BackAttacked = (@switch >> 6 & 1) == 1;
  29. isScriptedBattle = (@switch >> 7 & 1) == 1;
  30. }
  31. }
  32. public struct Encounter
  33. {
  34. public byte Scenario;
  35. public EncounterFlag BattleFlags;
  36. public byte PrimaryCamera;
  37. public byte AlternativeCamera;
  38. public byte HiddenEnemies;
  39. public byte UnloadedEnemy;
  40. public byte UntargetableEnemy;
  41. public byte EnabledEnemy;
  42. public EnemyCoordinates enemyCoordinates;
  43. private byte[] Enemies; //sizeof 8
  44. public byte[] bUnk2; //sizeof 16*3 + 8
  45. public byte[] bLevels; //sizeof 8
  46. public byte[] BEnemies { get => Enemies.Select(x => (byte)(x - 0x10)).ToArray(); set => Enemies = value; }
  47. }
  48. internal struct EnemyCoordinates
  49. {
  50. public Coordinate cEnemy1;
  51. public Coordinate cEnemy2;
  52. public Coordinate cEnemy3;
  53. public Coordinate cEnemy4;
  54. public Coordinate cEnemy5;
  55. public Coordinate cEnemy6;
  56. public Coordinate cEnemy7;
  57. public Coordinate cEnemy8;
  58. public Coordinate GetEnemyCoordinateByIndex(byte index)
  59. {
  60. switch (index)
  61. {
  62. case 0:
  63. return cEnemy8;
  64. case 1:
  65. return cEnemy7;
  66. case 2:
  67. return cEnemy6;
  68. case 3:
  69. return cEnemy5;
  70. case 4:
  71. return cEnemy4;
  72. case 5:
  73. return cEnemy3;
  74. case 6:
  75. return cEnemy2;
  76. case 7:
  77. return cEnemy1;
  78. default:
  79. return cEnemy1;
  80. }
  81. }
  82. }
  83. internal struct Coordinate
  84. {
  85. public short x;
  86. public short y;
  87. public short z;
  88. public Vector3 GetVector() => new Vector3(
  89. x /100,
  90. y /100 ,
  91. -z /100 );
  92. }
  93. internal static void DEBUG()
  94. {
  95. ArchiveWorker aw = new ArchiveWorker(Memory.Archives.A_BATTLE);
  96. string[] test = aw.GetListOfFiles();
  97. string sEncounter = test.First(x => x.ToLower().Contains("scene.out"));
  98. byte[] sceneOut = ArchiveWorker.GetBinaryFile(Memory.Archives.A_BATTLE, sEncounter);
  99. ReadEncounter(sceneOut);
  100. }
  101. private static void ReadEncounter(byte[] enc)
  102. {
  103. int encounterCount = enc.Length / 128;
  104. Memory.encounters = new Encounter[encounterCount];
  105. using (MemoryStream ms = new MemoryStream(enc))
  106. using (BinaryReader br = new BinaryReader(ms))
  107. for (int i = 0; i < encounterCount; i++)
  108. Memory.encounters[i] = new Encounter()
  109. {
  110. Scenario = br.ReadByte(),
  111. BattleFlags = new EncounterFlag() { Switch = br.ReadByte() },
  112. PrimaryCamera = br.ReadByte(),
  113. AlternativeCamera = br.ReadByte(),
  114. HiddenEnemies = br.ReadByte(),
  115. UnloadedEnemy = br.ReadByte(),
  116. UntargetableEnemy = br.ReadByte(),
  117. EnabledEnemy = br.ReadByte(),
  118. enemyCoordinates = new EnemyCoordinates()
  119. {
  120. cEnemy1 = new Coordinate()
  121. {
  122. x = br.ReadInt16(),
  123. y = br.ReadInt16(),
  124. z = br.ReadInt16()
  125. },
  126. cEnemy2 = new Coordinate()
  127. {
  128. x = br.ReadInt16(),
  129. y = br.ReadInt16(),
  130. z = br.ReadInt16()
  131. },
  132. cEnemy3 = new Coordinate()
  133. {
  134. x = br.ReadInt16(),
  135. y = br.ReadInt16(),
  136. z = br.ReadInt16()
  137. },
  138. cEnemy4 = new Coordinate()
  139. {
  140. x = br.ReadInt16(),
  141. y = br.ReadInt16(),
  142. z = br.ReadInt16()
  143. },
  144. cEnemy5 = new Coordinate()
  145. {
  146. x = br.ReadInt16(),
  147. y = br.ReadInt16(),
  148. z = br.ReadInt16()
  149. },
  150. cEnemy6 = new Coordinate()
  151. {
  152. x = br.ReadInt16(),
  153. y = br.ReadInt16(),
  154. z = br.ReadInt16()
  155. },
  156. cEnemy7 = new Coordinate()
  157. {
  158. x = br.ReadInt16(),
  159. y = br.ReadInt16(),
  160. z = br.ReadInt16()
  161. },
  162. cEnemy8 = new Coordinate()
  163. {
  164. x = br.ReadInt16(),
  165. y = br.ReadInt16(),
  166. z = br.ReadInt16()
  167. }
  168. },
  169. BEnemies = br.ReadBytes(8),
  170. bUnk2 = br.ReadBytes(16 * 3 + 8),
  171. bLevels = br.ReadBytes(8)
  172. };
  173. }
  174. }
  175. }