MediaDataInstaller.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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 <unordered_map>
  17. #include "data/VGearsLGPArchive.h"
  18. #include "common/BinGZipFile.h"
  19. #include "TexFile.h"
  20. /**
  21. * The media data installer.
  22. */
  23. class MediaDataInstaller{
  24. public:
  25. /**
  26. * Constructor
  27. *
  28. * @param[in] input_dir Path to the directory containing the original data to parse.
  29. * @param[in] output_dir Path to the directory of the installation data.
  30. * @param[in] keep_originals True to keep original data after conversion, false to remove.
  31. * @param[in] no_ffmpeg True to prevent system calls to ffmpeg command, false to allow.
  32. * @param[in] no_timidity True to prevent system calls to timidity command, false to allow.
  33. */
  34. MediaDataInstaller(
  35. const std::string input_dir, const std::string output_dir, const bool keep_originals,
  36. const bool no_ffmpeg, const bool no_timidity
  37. );
  38. /**
  39. * Destructor.
  40. */
  41. ~MediaDataInstaller();
  42. /**
  43. * Populates the audio name maps.
  44. */
  45. void PopulateMaps();
  46. /**
  47. * Extracts all images contained in the menu LGP file and installs them.
  48. *
  49. * For composed textures, it extracts individual images. All images are saved under the
  50. * "images" directory. This also includes font maps.
  51. */
  52. void InstallSprites();
  53. /**
  54. * Prepares the installer for the sounds extraction.
  55. *
  56. * @return The total number of sounds to process.
  57. */
  58. int InstallSoundsInit();
  59. /**
  60. * Extracts the next sound file contained in the audio.dat file and installs it.
  61. *
  62. * @return True if there are no more sounds to extract, false otherwise.
  63. */
  64. bool InstallSounds();
  65. /**
  66. * Writes the XML file with all audio entries.
  67. */
  68. void WriteSoundIndex();
  69. /**
  70. * Prepares the installer for the sounds extraction.
  71. *
  72. * @return The total number of sounds to process.
  73. */
  74. int InstallMusicsInit();
  75. /**
  76. * Extracts the next music file contained in the midi.lgp, converts it and installs it.
  77. *
  78. * @return True if there are no more musics to extract, false otherwise.
  79. */
  80. bool InstallMusics();
  81. /**
  82. * Converts high quality musiscs to OGG.
  83. *
  84. * There are four of them.
  85. */
  86. void InstallHQMusics();
  87. /**
  88. * Writes the XML file with all music tracks.
  89. */
  90. void WriteMusicsIndex();
  91. private:
  92. /**
  93. * Number of sound files to extract.
  94. */
  95. static int TOTAL_SOUNDS;
  96. /**
  97. * The standard WAV header.
  98. *
  99. * 78 bytes to be written to every wav file before anything else.
  100. */
  101. static u8 WAV_HEADER[78];
  102. /**
  103. * The structure of each audio file pointer in a sound FMT file. 74 bytes.
  104. */
  105. struct FmtFile{
  106. /**
  107. * Size of the wav file in the dat. 4 bytes.
  108. */
  109. u32 size;
  110. /**
  111. * Offset of the wav file in the dat. 4 bytes.
  112. */
  113. u32 offset;
  114. /**
  115. * Information for sound looping. 12 bytes.
  116. */
  117. u8 loop_metadata[16];
  118. /**
  119. * Microsoft WAVFORMATEX header for the wav file. 44 bytes.
  120. */
  121. u8 wav_header[18];
  122. /**
  123. * Samples per block. 2 bytes.
  124. */
  125. u16 samples_per_block;
  126. /**
  127. * Number of ADPCM coefficients (used for compression, should always be 7). 2 bytes.
  128. */
  129. u16 adpcm;
  130. /**
  131. * Standard Microsoft ADPCMCoefSets. 28 bytes.
  132. */
  133. u8 adpcm_sets[28];
  134. };
  135. /**
  136. * The path to the directory from which to read the PC game data.
  137. */
  138. std::string input_dir_;
  139. /**
  140. * The path to the directory where to save the V-Gears data.
  141. */
  142. std::string output_dir_;
  143. /**
  144. * The menu.lgp file.
  145. */
  146. VGears::LGPArchive menu_;
  147. /**
  148. * The WINDOW.BIN file.
  149. */
  150. BinGZipFile window_;
  151. /**
  152. * The sounds .fmt file.
  153. */
  154. File fmt_;
  155. /**
  156. * The sounds .dat file.
  157. */
  158. File dat_;
  159. /**
  160. * Number of sounds already processed.
  161. */
  162. int processed_sounds_;
  163. /**
  164. * Map for sound files with descriptive names.
  165. */
  166. std::unordered_map<int, std::string> sound_map_;
  167. /**
  168. * Sound data for each entry to write to the XML file
  169. */
  170. std::vector<std::string> sounds_;
  171. /**
  172. * The midi.lgp file.
  173. */
  174. VGears::LGPArchive midi_;
  175. /**
  176. * Number of music tracks already processed.
  177. */
  178. int processed_musics_;
  179. /**
  180. * Map for music files with descriptive names.
  181. */
  182. std::unordered_map<int, std::string> musics_map_;
  183. /**
  184. * Sound data for each entry to write to the XML file
  185. */
  186. std::vector<std::string> musics_;
  187. /**
  188. * If true, orginal files will not be deleted after conversion.
  189. */
  190. bool keep_originals_;
  191. /**
  192. * Flag to prevent system calls to ffmpeg.
  193. */
  194. bool no_ffmpeg_;
  195. /**
  196. * Flag to prevent system calls to timidity.
  197. */
  198. bool no_timidity_;
  199. };