sudm.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #include "sudm.h"
  2. #include "decompiler/ff7_field/ff7_field_engine.h"
  3. #include "decompiler/ff7_field/ff7_field_disassembler.h"
  4. #include "decompiler/ff7_field/ff7_field_codegen.h"
  5. #include "decompiler/control_flow.h"
  6. namespace SUDM
  7. {
  8. namespace FF7
  9. {
  10. namespace Animation
  11. {
  12. // TODO
  13. }
  14. namespace AI
  15. {
  16. // TODO
  17. }
  18. namespace World
  19. {
  20. // TODO
  21. }
  22. namespace Field
  23. {
  24. float ScaleFactor(const std::vector<unsigned char>& scriptBytes)
  25. {
  26. // Could be cleaner, but just does enough work to pull out the fields scale
  27. IScriptFormatter formatter;
  28. ::FF7::FF7FieldEngine engine(formatter, "Unused");
  29. InstVec insts;
  30. engine.getDisassembler(insts, scriptBytes);
  31. return engine.ScaleFactor();
  32. }
  33. DecompiledScript Decompile(std::string scriptName,
  34. const std::vector<unsigned char>& scriptBytes,
  35. IScriptFormatter& formatter,
  36. std::string textToAppend,
  37. std::string textToPrepend)
  38. {
  39. // Disassemble the script
  40. ::FF7::FF7FieldEngine engine(formatter, scriptName);
  41. InstVec insts;
  42. auto disassembler = engine.getDisassembler(insts, scriptBytes);
  43. disassembler->disassemble();
  44. //disassembler->dumpDisassembly(std::cout);
  45. // Create CFG
  46. auto controlFlow = std::make_unique<ControlFlow>(insts, engine);
  47. controlFlow->createGroups();
  48. // Decompile/analyze
  49. //Graph graph = controlFlow->analyze();
  50. //engine.postCFG(insts, graph);
  51. Graph graph;
  52. DecompiledScript ds;
  53. // Generate code and return it
  54. std::stringstream output;
  55. auto cg = engine.getCodeGenerator(insts, output);
  56. cg->generate(insts, graph);
  57. ds.luaScript = textToPrepend + output.str() + textToAppend;
  58. ds.entities = engine.GetEntities();
  59. return ds;
  60. }
  61. }
  62. }
  63. namespace FF8
  64. {
  65. namespace Field
  66. {
  67. // TODO
  68. }
  69. }
  70. namespace FF9
  71. {
  72. namespace Field
  73. {
  74. // TODO
  75. }
  76. }
  77. }