MediaDataInstaller.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. private:
  64. /**
  65. * Number of sound files to extract.
  66. */
  67. static int TOTAL_SOUNDS;
  68. /**
  69. * The standard WAV header.
  70. *
  71. * 78 bytes to be written to every wav file before anything else.
  72. */
  73. static u8 WAV_HEADER[78];
  74. /**
  75. * The structure of each audio file pointer in a sound FMT file. 74 bytes.
  76. */
  77. struct FmtFile{
  78. /**
  79. * Size of the wav file in the dat. 4 bytes.
  80. */
  81. u32 size;
  82. /**
  83. * Offset of the wav file in the dat. 4 bytes.
  84. */
  85. u32 offset;
  86. /**
  87. * Information for sound looping. 12 bytes.
  88. */
  89. u8 loop_metadata[16];
  90. /**
  91. * Microsoft WAVFORMATEX header for the wav file. 44 bytes.
  92. */
  93. u8 wav_header[18];
  94. /**
  95. * Samples per block. 2 bytes.
  96. */
  97. u16 samples_per_block;
  98. /**
  99. * Number of ADPCM coefficients (used for compression, should always be 7). 2 bytes.
  100. */
  101. u16 adpcm;
  102. /**
  103. * Standard Microsoft ADPCMCoefSets. 28 bytes.
  104. */
  105. u8 adpcm_sets[28];
  106. };
  107. /**
  108. * The path to the directory from which to read the PC game data.
  109. */
  110. std::string input_dir_;
  111. /**
  112. * The path to the directory where to save the V-Gears data.
  113. */
  114. std::string output_dir_;
  115. /**
  116. * The menu.lgp file.
  117. */
  118. VGears::LGPArchive menu_;
  119. /**
  120. * The WINDOW.BIN file.
  121. */
  122. BinGZipFile window_;
  123. /**
  124. * The sounds .fmt file.
  125. */
  126. File fmt_;
  127. /**
  128. * The sounds .dat file.
  129. */
  130. File dat_;
  131. /**
  132. * Number of sounds already processed.
  133. */
  134. int processed_sounds_;
  135. /**
  136. * Map for sound files with descriptive names.
  137. */
  138. std::unordered_map<int, std::string> sound_map_;
  139. /**
  140. * Sound data for each entry to write to the XML file
  141. */
  142. std::vector<std::string> sounds_;
  143. };