DataInstaller.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  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 <string>
  17. #include <vector>
  18. #include <iostream>
  19. #include "common/VGearsApplication.h"
  20. #include "FieldDataInstaller.h"
  21. #include "KernelDataInstaller.h"
  22. #include "MediaDataInstaller.h"
  23. #include "ModelsAndAnimationsDb.h"
  24. /**
  25. * The data installer.
  26. */
  27. class DataInstaller{
  28. public:
  29. /**
  30. * The scale factor for line point coordinates.
  31. *
  32. * When a LINE opcode is found in the game scripts, the line points X and Y coordinates
  33. * must be scaled down by this factor.
  34. */
  35. static float LINE_SCALE_FACTOR;
  36. /**
  37. * Installer constructor
  38. *
  39. * @param[in] input_dir Path to the directory containing the original
  40. * data to parse.
  41. * @param[in] output_dir Path to the directory to write generated data
  42. * to.
  43. * @param[in] write_output_line Pointer to function to write output.
  44. */
  45. DataInstaller(
  46. const std::string input_dir, const std::string output_dir,
  47. std::function<void(std::string, int, bool)> write_output_line
  48. );
  49. /**
  50. * Installer destructor.
  51. */
  52. ~DataInstaller();
  53. /**
  54. * Handle the installation progress.
  55. *
  56. * @return Installation progress [0-100].
  57. */
  58. float Progress();
  59. private:
  60. /**
  61. * Calculates the installation progress.
  62. *
  63. * @return Installation progress [0-100]
  64. */
  65. const float CalcProgress();
  66. /**
  67. * Creates a directory in the outputh path.
  68. *
  69. * @param[in] dir Path of the directory to create, relative to the
  70. * output path..
  71. * @throws std::runtime_error If the directory can't be created.
  72. */
  73. void CreateDir(const std::string& dir);
  74. /**
  75. * Creates all directories required for the installation.
  76. *
  77. * It also adds certain location to the resource group manager.
  78. */
  79. void CreateDirectories();
  80. /**
  81. * Cleans up after the installation is complete.
  82. */
  83. void CleanInstall();
  84. /**
  85. * Installation steps.
  86. */
  87. enum InstallationSteps{
  88. /**
  89. * Installation not started.
  90. */
  91. IDLE = 0,
  92. /**
  93. * Create all directories required for the installation.
  94. */
  95. CREATE_DIRECTORIES,
  96. /**
  97. * Initialize data for installation.
  98. */
  99. INITIALIZE,
  100. /**
  101. * Parses item and materia prices from ff7.exe.
  102. */
  103. KERNEL_PRICES,
  104. /**
  105. * Parses command data from KERNEL.BIN.
  106. */
  107. KERNEL_COMMANDS,
  108. /**
  109. * Parses attack data from KERNEL.BIN.
  110. */
  111. KERNEL_ATTACKS,
  112. /**
  113. * Parses characters data from KERNEL.BIN.
  114. */
  115. KERNEL_CHARACTERS,
  116. /**
  117. * Parses item data from KERNEL.BIN.
  118. */
  119. KERNEL_ITEMS,
  120. /**
  121. * Parses growth data from KERNEL.BIN.
  122. */
  123. KERNEL_GROWTH,
  124. /**
  125. * Parses weapon data from KERNEL.BIN.
  126. */
  127. KERNEL_WEAPONS,
  128. /**
  129. * Parses armor data from KERNEL.BIN.
  130. */
  131. KERNEL_ARMORS,
  132. /**
  133. * Parses accessory data from KERNEL.BIN.
  134. */
  135. KERNEL_ACCESSORIES,
  136. /**
  137. * Parses materia data from KERNEL.BIN.
  138. */
  139. KERNEL_MATERIA,
  140. /**
  141. * Parses key item data data from KERNEL.BIN.
  142. */
  143. KERNEL_KEY_ITEMS,
  144. /**
  145. * Parses summon names data from KERNEL.BIN.
  146. */
  147. KERNEL_SUMMON_NAMES,
  148. /**
  149. * Parses the initial savemap from KERNEL.BIN.
  150. */
  151. KERNEL_SAVEMAP,
  152. /**
  153. * Extract game images and icons from menu.lgp.
  154. */
  155. MEDIA_IMAGES,
  156. /**
  157. * Prepares the installer for sound extraction.
  158. */
  159. MEDIA_SOUNDS_INIT,
  160. /**
  161. * Extract game sounds.
  162. */
  163. MEDIA_SOUNDS,
  164. /**
  165. * Build sounds index.
  166. */
  167. MEDIA_SOUNDS_INDEX,
  168. /**
  169. * Prepares the installer for music extraction.
  170. */
  171. MEDIA_MUSICS_INIT,
  172. /**
  173. * Extracts the game music.
  174. */
  175. MEDIA_MUSICS,
  176. /**
  177. * Extracts the game high quality music.
  178. */
  179. MEDIA_MUSICS_HQ,
  180. /**
  181. * Build the music index.
  182. */
  183. MEDIA_MUSICS_INDEX,
  184. /**
  185. * Initializer for {@see SPAWN_POINTS_AND_SCALE_FACTORS}.
  186. */
  187. FIELD_SPAWN_POINTS_AND_SCALE_FACTORS_INIT,
  188. /**
  189. * Step that collects spawn points and sclae factors.
  190. */
  191. FIELD_SPAWN_POINTS_AND_SCALE_FACTORS,
  192. /**
  193. * Step that convets fields to V-Gears format.
  194. */
  195. FIELD_CONVERT,
  196. /**
  197. * Initializer for {@see WRITE_MAPS}.
  198. */
  199. FIELD_WRITE_INIT,
  200. /**
  201. * Step that writes XML maps.
  202. */
  203. FIELD_WRITE,
  204. /**
  205. * Clean up after {@see WRITE_MAPS}.
  206. */
  207. FIELD_WRITE_END,
  208. /**
  209. * Initializer for {@see CONVERT_FIELD_MODELS}.
  210. */
  211. FIELD_CONVERT_MODELS_INIT,
  212. /**
  213. * Step that converts field models.
  214. */
  215. FIELD_CONVERT_MODELS,
  216. /**
  217. * Cleans up after the installation.
  218. */
  219. CLEAN,
  220. /**
  221. * Number of installation steps.
  222. */
  223. STATE_COUNT,
  224. /**
  225. * Installation finished.
  226. */
  227. DONE = 100,
  228. };
  229. /**
  230. * Current installation status.
  231. */
  232. InstallationSteps installation_state_ = IDLE;
  233. /**
  234. * Substeps in the current installation step.
  235. */
  236. int substeps_;
  237. /**
  238. * Current substep in the current installation step.
  239. */
  240. int cur_substep_;
  241. /**
  242. * Weight of each installation step.
  243. *
  244. * Used to calculate current progress.
  245. */
  246. int step_weight_[STATE_COUNT];
  247. /**
  248. * List of field model names.
  249. */
  250. std::vector<std::string> field_model_names_;
  251. /**
  252. * The path to the directory from which to read the PC game data.
  253. */
  254. std::string input_dir_;
  255. /**
  256. * The path to original PC game executable.
  257. */
  258. std::string exe_path_;
  259. /**
  260. * The path to the directory where to save the V-Gears data.
  261. */
  262. std::string output_dir_;
  263. /**
  264. * The installer application.
  265. *
  266. * It's a singleton so it can't be recreated. It will crash the second
  267. * time round.
  268. */
  269. VGears::Application application_;
  270. /**
  271. * LGP archive with field data.
  272. */
  273. std::unique_ptr<ScopedLgp> fields_lgp_;
  274. /**
  275. * The installer for fiel maps data.
  276. */
  277. std::unique_ptr<FieldDataInstaller> field_installer_;
  278. /**
  279. * The installer for kernel data.
  280. */
  281. std::unique_ptr<KernelDataInstaller> kernel_installer_;
  282. /**
  283. * The installer for media files.
  284. */
  285. std::unique_ptr<MediaDataInstaller> media_installer_;
  286. /**
  287. * Function used to print text to the log output, line by line.
  288. *
  289. * @param[in] msg the message to write.
  290. * @param[in] level Log level for the message.
  291. * @param[in] as_progress If true, the text will also be set as the current text behind the
  292. * progress bar.
  293. */
  294. std::function<void(std::string msg, int level, bool progress)> write_output_line_;
  295. };