MediaDataInstaller.h 5.4 KB

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