init_debugger_battle.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. using Microsoft.Xna.Framework;
  2. using System.IO;
  3. using System.Linq;
  4. namespace OpenVIII
  5. {
  6. public static class Init_debugger_battle
  7. {
  8. public struct EncounterFlag
  9. {
  10. public bool CantEspace;
  11. public bool NoVictorySequence;
  12. public bool ShowTimer;
  13. public bool NoEXP;
  14. public bool SkipEXPScreen;
  15. public bool SurpriseAttack;
  16. public bool BackAttacked;
  17. public bool isScriptedBattle;
  18. public byte Switch { set => SetFlags(value); }
  19. public void SetFlags(byte @switch)
  20. {
  21. CantEspace = (@switch & 1) == 1;
  22. NoVictorySequence = (@switch >> 1 & 1) == 1;
  23. ShowTimer = (@switch >> 2 & 1) == 1;
  24. NoEXP = (@switch >> 3 & 1) == 1;
  25. SkipEXPScreen = (@switch >> 4 & 1) == 1;
  26. SurpriseAttack = (@switch >> 5 & 1) == 1;
  27. BackAttacked = (@switch >> 6 & 1) == 1;
  28. isScriptedBattle = (@switch >> 7 & 1) == 1;
  29. }
  30. }
  31. public struct Encounter
  32. {
  33. public byte Scenario;
  34. public EncounterFlag BattleFlags;
  35. public byte PrimaryCamera;
  36. public byte AlternativeCamera;
  37. public byte HiddenEnemies;
  38. public byte UnloadedEnemy;
  39. public byte UntargetableEnemy;
  40. public byte EnabledEnemy;
  41. public EnemyCoordinates enemyCoordinates;
  42. private byte[] Enemies; //sizeof 8
  43. public byte[] bUnk2; //sizeof 16*3 + 8
  44. public byte[] bLevels; //sizeof 8
  45. public byte[] BEnemies { get => Enemies.Select(x => (byte)(x - 0x10)).ToArray(); set => Enemies = value; }
  46. public int ResolveCameraAnimation(byte cameraPointerValue) => cameraPointerValue & 0b1111;
  47. public int ResolveCameraSet(byte cameraPointerValue) => (cameraPointerValue >> 4) & 0b1111;
  48. }
  49. public struct EnemyCoordinates
  50. {
  51. public Coordinate cEnemy1;
  52. public Coordinate cEnemy2;
  53. public Coordinate cEnemy3;
  54. public Coordinate cEnemy4;
  55. public Coordinate cEnemy5;
  56. public Coordinate cEnemy6;
  57. public Coordinate cEnemy7;
  58. public Coordinate cEnemy8;
  59. public Coordinate GetEnemyCoordinateByIndex(byte index)
  60. {
  61. switch (index)
  62. {
  63. case 0:
  64. return cEnemy8;
  65. case 1:
  66. return cEnemy7;
  67. case 2:
  68. return cEnemy6;
  69. case 3:
  70. return cEnemy5;
  71. case 4:
  72. return cEnemy4;
  73. case 5:
  74. return cEnemy3;
  75. case 6:
  76. return cEnemy2;
  77. case 7:
  78. return cEnemy1;
  79. default:
  80. return cEnemy1;
  81. }
  82. }
  83. }
  84. public struct Coordinate
  85. {
  86. public short x;
  87. public short y;
  88. public short z;
  89. public Vector3 GetVector() => new Vector3(
  90. x,
  91. y,
  92. -z) / 100f;
  93. }
  94. public static void Init()
  95. {
  96. ArchiveWorker aw = new ArchiveWorker(Memory.Archives.A_BATTLE);
  97. string[] test = aw.GetListOfFiles();
  98. string sEncounter = test.First(x => x.ToLower().Contains("scene.out"));
  99. byte[] sceneOut = ArchiveWorker.GetBinaryFile(Memory.Archives.A_BATTLE, sEncounter);
  100. ReadEncounter(sceneOut);
  101. }
  102. private static void ReadEncounter(byte[] enc)
  103. {
  104. int encounterCount = enc.Length / 128;
  105. Memory.encounters = new Encounter[encounterCount];
  106. MemoryStream ms = null;
  107. using (BinaryReader br = new BinaryReader(ms = new MemoryStream(enc)))
  108. {
  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. ms = null;
  176. }
  177. }
  178. }
  179. }