FieldDecompiler.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * V-Gears
  3. * Copyright (C) 2022 V-Gears Team
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #pragma once
  19. #include <string>
  20. #include "decompiler/Decompiler.h"
  21. #include "FieldScriptFormatter.h"
  22. /**
  23. * Decompiler for field maps.
  24. */
  25. class FieldDecompiler: public Decompiler{
  26. public:
  27. /**
  28. * A line.
  29. */
  30. struct Line{
  31. /**
  32. * Name of the line entity.
  33. */
  34. std::string name;
  35. /**
  36. * First point of the line.
  37. */
  38. std::vector<float> point_a;
  39. /**
  40. * Second point of the line.
  41. */
  42. std::vector<float> point_b;
  43. };
  44. /**
  45. * An entity.
  46. */
  47. struct FieldEntity{
  48. /**
  49. * Character identifier of the entity.
  50. */
  51. uint char_id;
  52. /**
  53. * Index of the entity in the field.
  54. */
  55. uint index;
  56. /**
  57. * Name of the entity.
  58. */
  59. std::string name;
  60. };
  61. /**
  62. * The field decompiled script.
  63. */
  64. struct DecompiledScript{
  65. /**
  66. * The LUA script for the field.
  67. */
  68. std::string luaScript;
  69. /**
  70. * The field entities.
  71. *
  72. * Lines are not included.
  73. */
  74. std::vector<FieldEntity> entities;
  75. /**
  76. * Lines in the field.
  77. */
  78. std::vector<Line> lines;
  79. };
  80. /**
  81. * Retrieves the scale factor of a field.
  82. *
  83. * @param script_bytes[in] Vector of raw byte data that makes up
  84. * the script.
  85. * @return The scale fctor.
  86. */
  87. static float ScaleFactor(const std::vector<unsigned char>& script_bytes);
  88. /**
  89. * Decompiles a field script.
  90. *
  91. * @param script_name[in] Name of the script to be converted,
  92. * should match file name.
  93. * @param script_bytes[in] Vector of raw byte data that makes up
  94. * the script.
  95. * @param formatter[in] Formatter used to rename variables, drop
  96. * functions...
  97. * @param text_after[in] Raw text that is added at to the end of
  98. * the decompiled output.
  99. * @param text_before[in] Raw text that is added at to the start of
  100. * the decompiled output.
  101. * @return A string with the decompiled script.
  102. * @throws DecompilerException on failure.
  103. */
  104. static DecompiledScript Decompile(
  105. std::string script_name, const std::vector<unsigned char>& script_bytes,
  106. FieldScriptFormatter& formatter, std::string text_after = "", std::string text_before = ""
  107. );
  108. };