extractor_example.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. //
  2. // Created by Иван_Архипов on 30.10.2017.
  3. //
  4. #include <iostream>
  5. #include <ctime>
  6. #include <algorithm>
  7. #ifdef WIN32
  8. #include <direct.h>
  9. #define mkdir(dir, mode) _mkdir(dir)
  10. #endif
  11. #include "LotroDat.h"
  12. using namespace LOTRO_DAT;
  13. using namespace std;
  14. // Change these variables to true if you want export category to files.
  15. bool exportImagesToFiles = false;
  16. bool exportFontsToFiles = false;
  17. bool exportSoundsToFiles = false;
  18. bool exportTexturesToFiles = false;
  19. bool exportUnknownToFiles = false;
  20. // Change these variables to true if you want export category to databases.
  21. bool exportTextsToDb = false;
  22. bool exportImagesToDb = false;
  23. bool exportFontsToDb = false;
  24. bool exportSoundsToDb = false;
  25. bool exportTexturesToDb = false;
  26. bool exportUnknownToDb = false;
  27. // There is no need to change anything else
  28. int main() {
  29. std::cout << "Gi1dor's LotRO .dat extractor ver. 5.2.0" << std::endl;
  30. std::cout << "Hello! I'm a basic shell version of .dat file extractor. I can open .dat file directly, "
  31. "if you write path to it (with name of file) in file \"dat_file_path.txt\"\n";
  32. DatFile file;
  33. ifstream in("dat_file_path.txt");
  34. if (!in.fail()) {
  35. std::string filename;
  36. getline(in, filename);
  37. std::cout << "Using .dat file from dat_file_path.txt...\n";
  38. std::cout << "Opening file " << filename << std::endl;
  39. if (file.InitDatFile(filename, 0) == false) {
  40. std::cout << "Dat file path from dat_file_path.txt - " << filename << " may be incorrect (cannot open "
  41. "DatFile due to error. See it in errors.log)\n";
  42. file.CloseDatFile();
  43. }
  44. }
  45. while (file.DatFileState() == CLOSED) {
  46. std::cout << "Please, tell, where the .dat file is\n";
  47. std::cout << "Enter path to file (including filename): ";
  48. std::string filename;
  49. std::getline(std::cin, filename);
  50. std::cout << "Opening file " << filename << std::endl;
  51. if (file.InitDatFile(filename, 0) == false) {
  52. std::cout << "Some error caused while opening the file... "
  53. "Could you enter .dat filename once more?" << std::endl;
  54. file.CloseDatFile();
  55. }
  56. }
  57. std::cout << "Great! File initialised successfully!\n";
  58. if (file.CheckIfNotPatched())
  59. std::cout << "MESSAGE: Dat file is new and haven't been patched yet\n";
  60. if (file.CheckIfPatchedByOldLauncher())
  61. std::cout << "MESSAGE: Dat file was patched by old launcher. Capability isn't guaranteed! Some functions may not work properly!!!\n";
  62. if (file.CheckIfUpdatedByGame())
  63. std::cout << "MESSAGE: .dat file was updated by game! Need to repair patches with functions RepairPatches() and FinishRepairingPatches()\n";
  64. std::cout << "Files number: " << file.files_number() << std::endl;
  65. int cmd = 0;
  66. while (true) {
  67. std::cout << "Please, choose, what should I do. I can extract .dat file to files (press 1), "
  68. "open another .dat file (press 2), or configure, what should I extract. Choose, what to do or exit (press -1)\n";
  69. if (cmd != 3) {
  70. std::cout << "Enter number of command (1-3): ";
  71. std::cin >> cmd;
  72. std::string tmp;
  73. std::getline(std::cin, tmp);
  74. }
  75. if (cmd == -1) {
  76. std::cout << "Exiting. Thanks for using me!\n";
  77. break;
  78. }
  79. if (cmd == 1) {
  80. const clock_t begin_time = clock();
  81. mkdir("Extracted data", 744);
  82. std::time_t result = std::time(nullptr);
  83. char *ttime = std::asctime(std::localtime(&result));
  84. auto *out_time = new char[25];
  85. memcpy(out_time, ttime, 24);
  86. out_time[24] = '\0';
  87. std::string output_dir = std::string("Extracted data\\") + file.filename().substr(file.filename().length() - 16, 16) + " " + std::string(out_time) + "\\";
  88. std::replace(output_dir.begin(), output_dir.end(), ':', '-');
  89. mkdir(output_dir.c_str(), 744);
  90. std::cout << "Total files found: " << file.files_number() << std::endl << std::flush;
  91. file.WriteUnorderedDictionary(output_dir);
  92. std::cout << "Beginning unpacking... Please, wait for some minutes."
  93. "\nMaybe it's a good idea to have a cup of tea, while unpacker is working...\n" << std::flush;
  94. Database output_db;
  95. if (exportImagesToDb) {
  96. output_db.InitDatabase(output_dir + std::string("Images.db"));
  97. std::cout << "Extracted " << file.ExtractAllFilesByType(JPG, &output_db) << " .jpg files to Images.db" << std::endl << std::flush;
  98. output_db.CloseDatabase();
  99. }
  100. if (exportSoundsToDb) {
  101. output_db.InitDatabase(output_dir + std::string("Sounds.db"));
  102. std::cout << "Extracted " << file.ExtractAllFilesByType(WAV, &output_db) << " .wav files to Sounds.db" << std::endl << std::flush;
  103. std::cout << "Extracted " << file.ExtractAllFilesByType(OGG, &output_db) << " .ogg files to Sounds.db" << std::endl << std::flush;
  104. output_db.CloseDatabase();
  105. }
  106. if (exportTextsToDb) {
  107. output_db.InitDatabase(output_dir + std::string("Texts.db"));
  108. std::cout << "Extracted " << file.ExtractAllFilesByType(TEXT, &output_db) << " text files to Texts.db" << std::endl << std::flush;
  109. output_db.CloseDatabase();
  110. }
  111. if (exportFontsToDb) {
  112. output_db.InitDatabase(output_dir + std::string("Fonts.db"));
  113. std::cout << "Extracted " << file.ExtractAllFilesByType(FONT, &output_db) << " font files to Fonts.db" << std::endl << std::flush;
  114. output_db.CloseDatabase();
  115. }
  116. if (exportTexturesToDb) {
  117. output_db.InitDatabase(output_dir + std::string("Textures.db"));
  118. std::cout << "Extracted " << file.ExtractAllFilesByType(DDS, &output_db) << " .dds files to Textures.db" << std::endl << std::flush;
  119. output_db.CloseDatabase();
  120. }
  121. if (exportImagesToFiles) {
  122. mkdir((output_dir + "jpg").c_str(), 744);
  123. std::cout << "Extracted " << file.ExtractAllFilesByType(JPG, output_dir + "jpg\\") << " .jpg files to directory" << std::endl << std::flush;
  124. }
  125. if (exportTexturesToFiles) {
  126. mkdir((output_dir + "dds").c_str(), 744);
  127. std::cout << "Extracted " << file.ExtractAllFilesByType(DDS, output_dir + "dds\\") << " .dds files to directory" << std::endl << std::flush;
  128. }
  129. if (exportSoundsToFiles) {
  130. mkdir((output_dir + "wav").c_str(), 744);
  131. std::cout << "Extracted " << file.ExtractAllFilesByType(WAV, output_dir + "wav\\") << " .wav files to directory" << std::endl << std::flush;
  132. mkdir((output_dir + "ogg").c_str(), 744);
  133. std::cout << "Extracted " << file.ExtractAllFilesByType(OGG, output_dir + "ogg\\") << " .ogg files to directory" << std::endl << std::flush;
  134. }
  135. if (exportFontsToFiles) {
  136. mkdir((output_dir + "fonts").c_str(), 744);
  137. std::cout << "Extracted " << file.ExtractAllFilesByType(FONT, output_dir + "fonts\\") << " font files to directory" << std::endl << std::flush;
  138. }
  139. if (exportUnknownToFiles) {
  140. mkdir((output_dir + "unknown").c_str(), 744);
  141. std::cout << "Extracted " << file.ExtractAllFilesByType(UNKNOWN, output_dir + "unknown\\") << " unknown files to directory" << std::endl << std::flush;
  142. }
  143. file.CloseDatFile();
  144. fprintf(stdout, "Spent %f seconds on running unpacker! Thank you for your patience!\n",
  145. float(clock() - begin_time) / CLOCKS_PER_SEC);
  146. }
  147. if (cmd == 2) {
  148. std::cout << "Closing file...\n";
  149. if (!file.CloseDatFile())
  150. std::cout << "An error occured while closing the file!!!\n";
  151. while (file.DatFileState() == CLOSED) {
  152. std::cout << "Please, tell, where the .dat file is\n";
  153. std::cout << "Enter path to file (including filename): ";
  154. std::string filename;
  155. std::getline(std::cin, filename);
  156. std::cout << "Opening file " << filename << std::endl;
  157. if (file.InitDatFile(filename, 0) == false) {
  158. std::cout << "Some error caused while opening the file... "
  159. "Could you enter .dat filename once more?" << std::endl;
  160. file.CloseDatFile();
  161. }
  162. }
  163. }
  164. if (cmd == 3) {
  165. std::cout << "Current parameters:\n";
  166. std::cout << "(01) Export texts to database - " << (exportTextsToDb ? "true\n" : "false\n");
  167. std::cout << "(11) Export images to files - " << (exportImagesToFiles ? "true\n" : "false\n");
  168. std::cout << "(12) Export images to database - " << (exportImagesToDb ? "true\n" : "false\n");
  169. std::cout << "(21) Export fonts to files - " << (exportFontsToFiles ? "true\n" : "false\n");
  170. std::cout << "(22) Export fonts to database - " << (exportFontsToDb ? "true\n" : "false\n");
  171. std::cout << "(31) Export sounds to files - " << (exportSoundsToFiles ? "true\n" : "false\n");
  172. std::cout << "(32) Export sounds to database - " << (exportSoundsToDb ? "true\n" : "false\n");
  173. std::cout << "(41) Export textures to files - " << (exportTexturesToFiles ? "true\n" : "false\n");
  174. std::cout << "(42) Export textures to database - " << (exportTexturesToDb ? "true\n" : "false\n");
  175. std::cout << "(51) Export unknown files to files - " << (exportUnknownToFiles ? "true\n" : "false\n");
  176. std::cout << "(52) Export unknown files to database - " << (exportUnknownToDb ? "true\n" : "false\n");
  177. std::cout << "Enter number of parameter to change (or -1 to exit this menu): ";
  178. int number = 0;
  179. std::cin >> number;
  180. std::string tmp;
  181. std::getline(std::cin, tmp);
  182. if (number == -1) {
  183. std::cout << "Returning to main menu..\n";
  184. cmd = 0;
  185. } else {
  186. switch (number) {
  187. case 01:
  188. exportTextsToDb = !exportTextsToDb;
  189. break;
  190. case 11:
  191. exportImagesToFiles = !exportImagesToFiles;
  192. break;
  193. case 12:
  194. exportImagesToDb = !exportImagesToDb;
  195. break;
  196. case 21:
  197. exportFontsToFiles = !exportFontsToFiles;
  198. break;
  199. case 22:
  200. exportFontsToDb = !exportFontsToDb;
  201. break;
  202. case 31:
  203. exportSoundsToFiles = !exportSoundsToFiles;
  204. break;
  205. case 32:
  206. exportSoundsToDb = !exportSoundsToDb;
  207. break;
  208. case 41:
  209. exportTexturesToFiles = !exportTexturesToFiles;
  210. break;
  211. case 42:
  212. exportTexturesToDb = !exportTexturesToDb;
  213. break;
  214. case 51:
  215. exportUnknownToFiles = !exportTexturesToFiles;
  216. break;
  217. case 52:
  218. exportUnknownToDb = !exportTexturesToDb;
  219. break;
  220. default:
  221. std::cout << "Incorrect number. Returning to main menu..\n";
  222. }
  223. }
  224. }
  225. }
  226. file.CloseDatFile();
  227. system("pause");
  228. return 0;
  229. }