sudm.h 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #pragma once
  2. #include <map>
  3. #include <vector>
  4. #include <string>
  5. #include "unknown_opcode_exception.h"
  6. namespace SUDM
  7. {
  8. class IScriptFormatter
  9. {
  10. public:
  11. virtual ~IScriptFormatter() = default;
  12. virtual void AddSpawnPoint(unsigned int /*targetMapId*/, const std::string& /*entity*/, const std::string& /*funcName*/, unsigned int /*address*/, int /*x*/, int /*y*/, int /*triangleId*/, int /*angle*/)
  13. {
  14. }
  15. virtual std::string SpawnPointName(unsigned int targetMapId, const std::string& entity, const std::string& funcName, unsigned int address)
  16. {
  17. return MapName(targetMapId) + "_" + entity + "_" + funcName + "_" + std::to_string(address);
  18. }
  19. virtual std::string MapName(unsigned int mapId) { return std::to_string(mapId); }
  20. // Renames a variable, return empty string for generated name, can return empty
  21. virtual std::string VarName(unsigned int /*bank*/, unsigned int /*addr*/) { return ""; }
  22. // Renames an entity, can't return empty
  23. virtual std::string EntityName(const std::string& entity) { return entity; }
  24. // Names an animation, can't return empty
  25. virtual std::string AnimationName(int /*charId*/, int id) { return std::to_string(id); }
  26. // Get name of char from its id, can't return empty
  27. virtual std::string CharName(int charId) { return std::to_string(charId); }
  28. // Renames a function in an entity, can't return empty
  29. virtual std::string FunctionName(const std::string& /*entity*/, const std::string& funcName) { return funcName; }
  30. // Sets the header comment for a function in an entity, can return empty
  31. virtual std::string FunctionComment(const std::string& /*entity*/, const std::string& /*funcName*/) { return ""; }
  32. };
  33. namespace FF7
  34. {
  35. namespace Field
  36. {
  37. // Entities list, with entity type of
  38. // entity_script
  39. // entity_model, which somehow links to model loader
  40. struct Line{
  41. std::string name;
  42. std::vector<float> point_a;
  43. std::vector<float> point_b;
  44. float ax, ay, az;
  45. float bx, by, bz;
  46. };
  47. struct DecompiledScript
  48. {
  49. std::string luaScript;
  50. std::map<std::string, int> entities;
  51. //std::map<size_t, FF7FieldEngine::Entity> entity_map;
  52. std::vector<Line> lines;
  53. };
  54. float ScaleFactor(const std::vector<unsigned char>& scriptBytes);
  55. /*
  56. * Throws ::InternalDecompilerError on failure.
  57. * scriptName - name of the script to be converted, should match file name.
  58. * scriptBytes - vector of raw byte data that makes up the script.
  59. * formatter - used to rename variables, drop functions etc.
  60. * textToAppend - raw text that is glued on to the end of the decompiled output.
  61. * textToPrepend - raw text that is glued to to the start of the decompiled output.
  62. * returns a string containing [textToPrepend] [decompiled script] [textToAppend]
  63. */
  64. DecompiledScript Decompile(std::string scriptName,
  65. const std::vector<unsigned char>& scriptBytes,
  66. IScriptFormatter& formatter,
  67. std::string textToAppend = "",
  68. std::string textToPrepend = "");
  69. }
  70. }
  71. }