extractor_example.cpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. //
  2. // Created by Иван_Архипов on 30.10.2017.
  3. //
  4. #define _CRT_SECURE_NO_WARNINGS
  5. #include <iostream>
  6. #include <ctime>
  7. #include <algorithm>
  8. #ifdef WIN32
  9. #include <direct.h>
  10. #define mkdir(dir, mode) _mkdir(dir)
  11. #endif
  12. #include "LotroDat.h"
  13. using namespace LOTRO_DAT;
  14. // Change these 2 variables to your path and name of .dat file
  15. const std::string path = "";//"E:\\SteamLibrary\\steamapps\\common\\";//Lord Of The Rings Online\\";
  16. const std::string filename = "client_local_English.dat";
  17. // Change these variables to true if you want export catecory to files.
  18. const bool exportImagesToFiles = false;
  19. const bool exportFontsToFiles = false;
  20. const bool exportSoundsToFiles = false;
  21. const bool exportTexturesToFiles = false;
  22. const bool exportUnknownToFiles = false;
  23. // Change these variables to true if you want export catecory to databases.
  24. const bool exportTextsToDb = true;
  25. const bool exportImagesToDb = true;
  26. const bool exportFontsToDb = true;
  27. const bool exportSoundsToDb = true;
  28. const bool exportTexturesToDb = true;
  29. const bool exportUnknownToDb = false;
  30. // There is no need to change anything else
  31. int main() {
  32. std::cout << "Gi1dor's LotRO .dat extractor ver. 2.1.0" << std::endl;
  33. const clock_t begin_time = clock();
  34. mkdir("Extracted data", 744);
  35. std::time_t result = std::time(nullptr);
  36. char *ttime = std::asctime(std::localtime(&result));
  37. auto *out_time = new char[25];
  38. memcpy(out_time, ttime, 24);
  39. out_time[24] = '\0';
  40. std::string output_dir = std::string("Extracted data\\") + filename + " " + std::string(out_time) + "\\";
  41. std::replace(output_dir.begin(), output_dir.end(), ':', '-');
  42. mkdir(output_dir.c_str(), 744);
  43. freopen((output_dir + std::string("errors.log")).c_str(), "w", stderr);
  44. setbuf(stdout, NULL);
  45. setbuf(stderr, NULL);
  46. setvbuf (stdout, NULL, _IONBF, BUFSIZ);
  47. setvbuf (stderr, NULL, _IONBF, BUFSIZ);
  48. std::cout << "Starting search...\n" << std::flush;
  49. DatFile a;
  50. if (!a.InitDatFile(path + filename, 0)) {
  51. std::cout << "Unable to initialize .dat file in " << path + filename << std::endl;
  52. system("pause");
  53. return 0;
  54. }
  55. std::cout << "Total files found: " << a.files_number() << std::endl << std::flush;
  56. a.WriteUnorderedDictionary(output_dir);
  57. std::cout << "Beginning unpacking... Please, wait for some minutes."
  58. "\nMaybe it's a good idea to have a cup of tea, while unpacker is working...\n" << std::flush;
  59. Database output_db;
  60. if (exportImagesToDb) {
  61. output_db.InitDatabase(output_dir + std::string("Images.db"));
  62. std::cout << "Extracted " << a.ExtractAllFilesByType(JPG, &output_db) << " .jpg files to Images.db" << std::endl << std::flush;
  63. output_db.CloseDatabase();
  64. }
  65. if (exportSoundsToDb) {
  66. output_db.InitDatabase(output_dir + std::string("Sounds.db"));
  67. std::cout << "Extracted " << a.ExtractAllFilesByType(WAV, &output_db) << " .wav files to Sounds.db" << std::endl << std::flush;
  68. std::cout << "Extracted " << a.ExtractAllFilesByType(OGG, &output_db) << " .ogg files to Sounds.db" << std::endl << std::flush;
  69. output_db.CloseDatabase();
  70. }
  71. if (exportTextsToDb) {
  72. output_db.InitDatabase(output_dir + std::string("Texts.db"));
  73. std::cout << "Extracted " << a.ExtractAllFilesByType(TEXT, &output_db) << " text files to Texts.db" << std::endl << std::flush;
  74. output_db.CloseDatabase();
  75. }
  76. if (exportFontsToDb) {
  77. output_db.InitDatabase(output_dir + std::string("Fonts.db"));
  78. std::cout << "Extracted " << a.ExtractAllFilesByType(FONT, &output_db) << " font files to Fonts.db" << std::endl << std::flush;
  79. output_db.CloseDatabase();
  80. }
  81. if (exportTexturesToDb) {
  82. output_db.InitDatabase(output_dir + std::string("Textures.db"));
  83. std::cout << "Extracted " << a.ExtractAllFilesByType(DDS, &output_db) << " .dds files to Textures.db" << std::endl << std::flush;
  84. output_db.CloseDatabase();
  85. }
  86. if (exportImagesToFiles) {
  87. mkdir((output_dir + "jpg").c_str(), 744);
  88. std::cout << "Extracted " << a.ExtractAllFilesByType(JPG, output_dir + "jpg\\") << " .jpg files to directory" << std::endl << std::flush;
  89. }
  90. if (exportTexturesToFiles) {
  91. mkdir((output_dir + "dds").c_str(), 744);
  92. std::cout << "Extracted " << a.ExtractAllFilesByType(DDS, output_dir + "dds\\") << " .dds files to directory" << std::endl << std::flush;
  93. }
  94. if (exportSoundsToFiles) {
  95. mkdir((output_dir + "wav").c_str(), 744);
  96. std::cout << "Extracted " << a.ExtractAllFilesByType(WAV, output_dir + "wav\\") << " .wav files to directory" << std::endl << std::flush;
  97. mkdir((output_dir + "ogg").c_str(), 744);
  98. std::cout << "Extracted " << a.ExtractAllFilesByType(OGG, output_dir + "ogg\\") << " .ogg files to directory" << std::endl << std::flush;
  99. }
  100. if (exportFontsToFiles) {
  101. mkdir((output_dir + "fonts").c_str(), 744);
  102. std::cout << "Extracted " << a.ExtractAllFilesByType(FONT, output_dir + "fonts\\") << " font files to directory" << std::endl << std::flush;
  103. }
  104. if (exportUnknownToFiles) {
  105. mkdir((output_dir + "unknown").c_str(), 744);
  106. std::cout << "Extracted " << a.ExtractAllFilesByType(FONT, output_dir + "unknown\\") << " unknown files to directory" << std::endl << std::flush;
  107. }
  108. a.CloseDatFile();
  109. fprintf(stdout, "Spent %f seconds on running unpacker! Thank you for your patience!\n",
  110. float(clock() - begin_time) / CLOCKS_PER_SEC);
  111. system("pause");
  112. return 0;
  113. }