AbFile.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * Copyright (C) 2022 The V-Gears Team
  3. *
  4. * This file is part of V-Gears
  5. *
  6. * V-Gears is free software: you can redistribute it and/or modify it under
  7. * terms of the GNU General Public License as published by the Free Software
  8. * Foundation, version 3.0 (GPLv3) of the License.
  9. *
  10. * V-Gears 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. #pragma once
  16. #include <vector>
  17. #include "common/File.h"
  18. #include "common/TypeDefine.h"
  19. /**
  20. * Represents an animation scripts file.
  21. *
  22. * *ab files are bundled into battle.lgp. They contain animation scripts. More info about them in
  23. * {@see https://forums.qhimm.com/index.php?topic=14204.0}
  24. */
  25. class AbFile{
  26. public:
  27. /**
  28. * Constructor.
  29. *
  30. * Reads the file.
  31. *
  32. * @param[in, out] file The file to read from. The file contents will not be altered, but
  33. * it's offset will be changed while reading it.
  34. * @param[in] enemy Indicates if the animation is for an enemy. Enemies have a different
  35. * number of animations than characters or backgrounds.
  36. */
  37. AbFile(File file, bool enemy);
  38. /**
  39. * Generates script files from the ba file.
  40. *
  41. * A file will be generated with every script in the *ab file. The file will be created in
  42. * the specified path, and will be named like the model id, followed by the ".lua"
  43. * extension. For example, if path is "/home/user/.v-gears", the model id is "rt", the file
  44. * name will be: "/home/user/.v-gears/rt.lua". Each script will be named "script" + index
  45. * (script1(), script2() ... script44() ...)
  46. *
  47. * @param[in] model_id ID of the model the animation belongs to, usually a two letter
  48. * code. Used to generate the file name.
  49. * @param[in] path Path to the directory where the files will be saved.
  50. * @return The number of scripts written to the file.
  51. */
  52. unsigned int GenerateScripts(std::string model_id, std::string path) const;
  53. private:
  54. /**
  55. * Reads the Ab file and extracts all the data.
  56. */
  57. void Read();
  58. /**
  59. * Decompiles a script in the *ab file.
  60. *
  61. * It won't nodify the file current offset.
  62. *
  63. * @param[in] offset Offset at which the script starts.
  64. * @return The script text.
  65. */
  66. std::string DecompileScript(u32 offset);
  67. /**
  68. * The ab file.
  69. */
  70. File ab_file_;
  71. /**
  72. * Indicates if the model is for an enemy.
  73. */
  74. bool is_enemy_;
  75. /**
  76. * List of animations.
  77. */
  78. std::vector<std::string> scripts_;
  79. };