AnimationScriptDumper.cpp 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. #include "AnimationScriptDumper.h"
  2. void
  3. AdvanceScript(u32 value, u32& current, u32& end)
  4. {
  5. current += value;
  6. u32 temp_end = current;
  7. end = (temp_end > end) ? temp_end : end;
  8. }
  9. void
  10. AnimationScriptDumper(File* file, int offset_to_anim_file, Logger* dump)
  11. {
  12. int number_of_scripts = 0x20;
  13. for (u8 i = 0; i < number_of_scripts; ++i)
  14. {
  15. u32 script = offset_to_anim_file + file->GetU16LE(offset_to_anim_file + 0x68 + i * 0x04);
  16. u32 end = script;
  17. u8 opcode = file->GetU8(script);
  18. if (opcode == 0x00) // skip if script starts with 0x00
  19. {
  20. continue;
  21. }
  22. dump->Log("\nfunction action_script_" + IntToString(i) + "()\n");
  23. for (; script <= end;)
  24. {
  25. //dump->Log(HexToString(script, 4, '0') + " (end " + HexToString(end, 4, '0') + "): ");
  26. u8 opcode = file->GetU8(script);
  27. dump->Log(" ");
  28. if (opcode < 0x8E)
  29. {
  30. dump->Log("play_animation(" + IntToString(opcode) + ");\n");
  31. AdvanceScript(1, script, end);
  32. }
  33. else if (opcode == 0xA9)
  34. {
  35. dump->Log("animation_reset(); -- A9 this increment pointer by 2 and execute animation on second pointer. This called if we back from other action using EE.\n");
  36. end = (script + 2 > end) ? script + 2 : end;
  37. script += 1;
  38. }
  39. else if (opcode == 0xAA)
  40. {
  41. dump->Log("unpause_camera(); -- AA\n");
  42. AdvanceScript(1, script, end);
  43. }
  44. else if (opcode == 0xAD)
  45. {
  46. dump->Log("set_effect(\"machinegun_fire\", " +
  47. HexToString(file->GetU8(script + 1), 2, '0') +
  48. ", " +
  49. HexToString(file->GetU16LE(script + 2), 4, '0') +
  50. ", " +
  51. HexToString(file->GetU8(script + 4), 2, '0') +
  52. ", " +
  53. HexToString(file->GetU8(script + 5), 2, '0') +
  54. "); -- AD\n"
  55. );
  56. AdvanceScript(6, script, end);
  57. }
  58. else if (opcode == 0xB6)
  59. {
  60. dump->Log("pause_camera_finish_animation(" + IntToString(file->GetU8(script + 1)) + "); -- B6\n");
  61. AdvanceScript(2, script, end);
  62. }
  63. else if (opcode == 0xB9)
  64. {
  65. dump->Log("set_camera(" +
  66. HexToString(file->GetU8(script + 1), 2, '0') +
  67. "); -- B9\n"
  68. );
  69. AdvanceScript(2, script, end);
  70. }
  71. else if (opcode == 0xBE)
  72. {
  73. dump->Log("execute_hurt(" +
  74. HexToString(file->GetU8(script + 1), 2, '0') +
  75. "); -- BE\n"
  76. );
  77. AdvanceScript(2, script, end);
  78. }
  79. else if (opcode == 0xC1)
  80. {
  81. dump->Log("jump(); -- C1\n");
  82. script += 1;
  83. }
  84. else if (opcode == 0xC2)
  85. {
  86. dump->Log("execute_damage(" +
  87. HexToString(file->GetU8(script + 1), 2, '0') +
  88. "); -- C2\n"
  89. );
  90. AdvanceScript(2, script, end);
  91. }
  92. else if (opcode == 0xC5)
  93. {
  94. dump->Log("set_unit_fade_wait(); -- C9\n");
  95. AdvanceScript(1, script, end);
  96. }
  97. else if (opcode == 0xC6)
  98. {
  99. dump->Log("set_unit_fade_time(" +
  100. HexToString(file->GetU8(script + 1), 2, '0') +
  101. "); -- C6\n"
  102. );
  103. AdvanceScript(2, script, end);
  104. }
  105. else if (opcode == 0xC9)
  106. {
  107. dump->Log("jump_label(); -- C9\n");
  108. AdvanceScript(1, script, end);
  109. }
  110. else if (opcode == 0xCA)
  111. {
  112. dump->Log("jump_if_not_loaded(); -- CA\n");
  113. AdvanceScript(1, script, end);
  114. }
  115. else if (opcode == 0xD1)
  116. {
  117. dump->Log("move_to_target(\"linear_movement\", " +
  118. HexToString(file->GetU16LE(script + 1), 4, '0') +
  119. ", " +
  120. HexToString(file->GetU16LE(script + 3), 4, '0') +
  121. ", " +
  122. HexToString(file->GetU8(script + 5), 2, '0') +
  123. "); -- D1\n"
  124. );
  125. AdvanceScript(6, script, end);
  126. }
  127. else if (opcode == 0xD8)
  128. {
  129. dump->Log("play_sound_for_attacker(" +
  130. HexToString(file->GetU8(script + 1), 2, '0') +
  131. ", " +
  132. HexToString(file->GetU16LE(script + 2), 4, '0') +
  133. "); -- D8\n"
  134. );
  135. AdvanceScript(4, script, end);
  136. }
  137. else if (opcode == 0xE5)
  138. {
  139. dump->Log("return_direction(); -- E5\n");
  140. AdvanceScript(1, script, end);
  141. }
  142. else if (opcode == 0xE8)
  143. {
  144. dump->Log("load_additional_effect(); -- E8\n");
  145. AdvanceScript(1, script, end);
  146. }
  147. else if (opcode == 0xEA)
  148. {
  149. dump->Log("show_action_name(); -- EA\n");
  150. AdvanceScript(1, script, end);
  151. }
  152. else if (opcode == 0xEC)
  153. {
  154. dump->Log("execute_additional_effect(); -- EC\n");
  155. AdvanceScript(1, script, end);
  156. }
  157. else if (opcode == 0xEE)
  158. {
  159. dump->Log("return_to_idle(); -- EE\n");
  160. script += 1;
  161. }
  162. else if (opcode == 0xF0)
  163. {
  164. dump->Log("set_effect(\"foot_dust\"); -- F0\n");
  165. AdvanceScript(1, script, end);
  166. }
  167. else if (opcode == 0xF3)
  168. {
  169. dump->Log("wait(); -- F3\n");
  170. AdvanceScript(1, script, end);
  171. }
  172. else if (opcode == 0xF4)
  173. {
  174. dump->Log("set_wait(" +
  175. HexToString(file->GetU8(script + 1), 2, '0') +
  176. "); -- F4\n"
  177. );
  178. AdvanceScript(2, script, end);
  179. }
  180. else if (opcode == 0xF6)
  181. {
  182. dump->Log("play_die_if_dead(); -- F6\n");
  183. AdvanceScript(1, script, end);
  184. }
  185. else if (opcode == 0xF7)
  186. {
  187. dump->Log("execute_attack(" +
  188. HexToString(file->GetU8(script + 1), 2, '0') +
  189. "); -- F7\n"
  190. );
  191. AdvanceScript(2, script, end);
  192. }
  193. else if (opcode == 0xFA)
  194. {
  195. dump->Log("return_position(); -- FA\n");
  196. AdvanceScript(1, script, end);
  197. }
  198. else if (opcode == 0xFC)
  199. {
  200. dump->Log("set_direction(); -- FC\n");
  201. AdvanceScript(1, script, end);
  202. }
  203. else
  204. {
  205. dump->Log("[ACTION_OPCODE " + HexToString(opcode, 2, '0') + "]\n");
  206. script += 1;
  207. }
  208. }
  209. dump->Log("end;\n");
  210. }
  211. }