init_debugger_battle.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. using Microsoft.Xna.Framework;
  2. using System;
  3. using System.IO;
  4. using System.Linq;
  5. namespace FF8
  6. {
  7. public 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. public int ResolveCameraAnimation(byte cameraPointerValue) => cameraPointerValue & 0b1111;
  48. public int ResolveCameraSet(byte cameraPointerValue) => (cameraPointerValue >> 4) & 0b1111;
  49. }
  50. public struct EnemyCoordinates
  51. {
  52. public Coordinate cEnemy1;
  53. public Coordinate cEnemy2;
  54. public Coordinate cEnemy3;
  55. public Coordinate cEnemy4;
  56. public Coordinate cEnemy5;
  57. public Coordinate cEnemy6;
  58. public Coordinate cEnemy7;
  59. public Coordinate cEnemy8;
  60. public Coordinate GetEnemyCoordinateByIndex(byte index)
  61. {
  62. switch (index)
  63. {
  64. case 0:
  65. return cEnemy8;
  66. case 1:
  67. return cEnemy7;
  68. case 2:
  69. return cEnemy6;
  70. case 3:
  71. return cEnemy5;
  72. case 4:
  73. return cEnemy4;
  74. case 5:
  75. return cEnemy3;
  76. case 6:
  77. return cEnemy2;
  78. case 7:
  79. return cEnemy1;
  80. default:
  81. return cEnemy1;
  82. }
  83. }
  84. }
  85. public struct Coordinate
  86. {
  87. public short x;
  88. public short y;
  89. public short z;
  90. public Vector3 GetVector() => new Vector3(
  91. x /100,
  92. y /100 ,
  93. -z /100 );
  94. }
  95. public static void Init()
  96. {
  97. ArchiveWorker aw = new ArchiveWorker(Memory.Archives.A_BATTLE);
  98. string[] test = aw.GetListOfFiles();
  99. string sEncounter = test.First(x => x.ToLower().Contains("scene.out"));
  100. byte[] sceneOut = ArchiveWorker.GetBinaryFile(Memory.Archives.A_BATTLE, sEncounter);
  101. ReadEncounter(sceneOut);
  102. }
  103. private static void ReadEncounter(byte[] enc)
  104. {
  105. int encounterCount = enc.Length / 128;
  106. Memory.encounters = new Encounter[encounterCount];
  107. using (MemoryStream ms = new MemoryStream(enc))
  108. using (BinaryReader br = new BinaryReader(ms))
  109. for (int i = 0; i < encounterCount; i++)
  110. Memory.encounters[i] = new Encounter()
  111. {
  112. Scenario = br.ReadByte(),
  113. BattleFlags = new EncounterFlag() { Switch = br.ReadByte() },
  114. PrimaryCamera = br.ReadByte(),
  115. AlternativeCamera = br.ReadByte(),
  116. HiddenEnemies = br.ReadByte(),
  117. UnloadedEnemy = br.ReadByte(),
  118. UntargetableEnemy = br.ReadByte(),
  119. EnabledEnemy = br.ReadByte(),
  120. enemyCoordinates = new EnemyCoordinates()
  121. {
  122. cEnemy1 = new Coordinate()
  123. {
  124. x = br.ReadInt16(),
  125. y = br.ReadInt16(),
  126. z = br.ReadInt16()
  127. },
  128. cEnemy2 = new Coordinate()
  129. {
  130. x = br.ReadInt16(),
  131. y = br.ReadInt16(),
  132. z = br.ReadInt16()
  133. },
  134. cEnemy3 = new Coordinate()
  135. {
  136. x = br.ReadInt16(),
  137. y = br.ReadInt16(),
  138. z = br.ReadInt16()
  139. },
  140. cEnemy4 = new Coordinate()
  141. {
  142. x = br.ReadInt16(),
  143. y = br.ReadInt16(),
  144. z = br.ReadInt16()
  145. },
  146. cEnemy5 = new Coordinate()
  147. {
  148. x = br.ReadInt16(),
  149. y = br.ReadInt16(),
  150. z = br.ReadInt16()
  151. },
  152. cEnemy6 = new Coordinate()
  153. {
  154. x = br.ReadInt16(),
  155. y = br.ReadInt16(),
  156. z = br.ReadInt16()
  157. },
  158. cEnemy7 = new Coordinate()
  159. {
  160. x = br.ReadInt16(),
  161. y = br.ReadInt16(),
  162. z = br.ReadInt16()
  163. },
  164. cEnemy8 = new Coordinate()
  165. {
  166. x = br.ReadInt16(),
  167. y = br.ReadInt16(),
  168. z = br.ReadInt16()
  169. }
  170. },
  171. BEnemies = br.ReadBytes(8),
  172. bUnk2 = br.ReadBytes(16 * 3 + 8),
  173. bLevels = br.ReadBytes(8)
  174. };
  175. }
  176. }
  177. }