sudm.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 DecompiledScript
  41. {
  42. std::string luaScript;
  43. std::map<std::string, int> entities;
  44. };
  45. float ScaleFactor(const std::vector<unsigned char>& scriptBytes);
  46. /*
  47. * Throws ::InternalDecompilerError on failure.
  48. * scriptName - name of the script to be converted, should match file name.
  49. * scriptBytes - vector of raw byte data that makes up the script.
  50. * formatter - used to rename variables, drop functions etc.
  51. * textToAppend - raw text that is glued on to the end of the decompiled output.
  52. * textToPrepend - raw text that is glued to to the start of the decompiled output.
  53. * returns a string containing [textToPrepend] [decompiled script] [textToAppend]
  54. */
  55. DecompiledScript Decompile(std::string scriptName,
  56. const std::vector<unsigned char>& scriptBytes,
  57. IScriptFormatter& formatter,
  58. std::string textToAppend = "",
  59. std::string textToPrepend = "");
  60. }
  61. }
  62. }