test.cpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. //
  2. // Created by Иван_Архипов on 30.10.2017.
  3. //
  4. #define _CRT_SECURE_NO_WARNINGS
  5. #include <iostream>
  6. #include <windows.h>
  7. #include <ctime>
  8. #include "LotroDatPatcher.h"
  9. using namespace LOTRO_DAT;
  10. int main() {
  11. const clock_t begin_time = clock();
  12. // Change these 2 variables to your path and name of .dat file
  13. std::string path = "E:\\SteamLibrary\\steamapps\\common\\Lord of the Rings Online\\";
  14. std::string filename = "client_local_English.dat";
  15. bool exportTextsToDb = false; // Not implemented - do not turn to true;
  16. bool exportImagesToDb = true;
  17. bool exportFontsToDb = false; // Not implemented - do not turn to true;
  18. bool exportSoundsToDb = true;
  19. bool exportTexturesToDb = true;
  20. // There is no need to touch something else
  21. std::string output_dir = std::string("Data (") + filename + std::string(")\\");
  22. std::string txt_dir = "txt\\";
  23. std::string jpg_dir = "jpg\\";
  24. std::string dds_dir = "dds\\";
  25. std::string wav_dir = "wav\\";
  26. std::string ogg_dir = "ogg\\";
  27. std::string font_dir = "font\\";
  28. std::string unk_dir = "unk\\";
  29. int txt_all = 0, txt_suc = 0;
  30. int jpg_all = 0, jpg_suc = 0;
  31. int dds_all = 0, dds_suc = 0;
  32. int wav_all = 0, wav_suc = 0;
  33. int ogg_all = 0, ogg_suc = 0;
  34. int font_all = 0, font_suc = 0;
  35. int unk_all = 0, unk_suc = 0;
  36. CreateDirectory(output_dir.c_str(), nullptr);
  37. CreateDirectory((output_dir + txt_dir).c_str(), nullptr);
  38. CreateDirectory((output_dir + jpg_dir).c_str(), nullptr);
  39. CreateDirectory((output_dir + dds_dir).c_str(), nullptr);
  40. CreateDirectory((output_dir + wav_dir).c_str(), nullptr);
  41. CreateDirectory((output_dir + ogg_dir).c_str(), nullptr);
  42. CreateDirectory((output_dir + font_dir).c_str(), nullptr);
  43. CreateDirectory((output_dir + unk_dir).c_str(), nullptr);
  44. Database *images = nullptr;
  45. Database *sounds = nullptr;
  46. Database *texts = nullptr;
  47. Database *fonts = nullptr;
  48. Database *textures = nullptr;
  49. if (exportImagesToDb) images = new Database(output_dir + std::string("Images.db"));
  50. if (exportSoundsToDb) sounds = new Database(output_dir + std::string("Sounds.db"));
  51. if (exportTextsToDb) texts = new Database(output_dir + std::string("Texts.db"));
  52. if (exportFontsToDb) fonts = new Database(output_dir + std::string("Fonts.db"));
  53. if (exportTexturesToDb) textures= new Database(output_dir + std::string("Textures.db"));
  54. std::cerr << "Starting search...\n";
  55. DatFile a(path + filename);
  56. std::cerr << "Total files found: " << a.dictionary().size() << std::endl;
  57. std::cerr << "Writing unordered dictionary:\n";
  58. FILE *f;
  59. fopen_s(&f, (output_dir + "dict.txt").c_str(), "w");
  60. fprintf(f, "file_id | offset | extension\n");
  61. for (auto i : a.dictionary()) {
  62. std::string extension = "unk";
  63. EXTENSION ext = i.second->ext();
  64. if (ext == TXT) extension = "txt";
  65. if (ext == JPG) extension = "jpg";
  66. if (ext == DDS) extension = "dds";
  67. if (ext == WAV) extension = "wav";
  68. if (ext == OGG) extension = "ogg";
  69. if (ext == FONT) extension = "font";
  70. fprintf(f, "%lld %lld %s\n", i.second->file_id(), i.second->file_offset(), extension.c_str());
  71. }
  72. fclose(f);
  73. std::cerr << "Beginning unpacking...\n";
  74. long long all = a.dictionary().size();
  75. long long counter = 0;
  76. for (auto i : a.dictionary())
  77. {
  78. EXTENSION ext = i.second->ext();
  79. if (ext == TXT) {
  80. txt_all++;
  81. //txt_suc += i.second->ExportFile((output_dir + txt_dir + std::to_string(i.second->file_id())).c_str(), texts);
  82. }
  83. if (ext == JPG) {
  84. jpg_all++;
  85. jpg_suc += i.second->ExportFile((output_dir + jpg_dir + std::to_string(i.second->file_id())).c_str(), images);
  86. }
  87. if (ext == DDS) {
  88. dds_all++;
  89. dds_suc += i.second->ExportFile((output_dir + dds_dir + std::to_string(i.second->file_id())).c_str(), textures);
  90. }
  91. if (ext == WAV) {
  92. wav_all++;
  93. wav_suc += i.second->ExportFile((output_dir + wav_dir + std::to_string(i.second->file_id())).c_str(), sounds);
  94. }
  95. if (ext == OGG) {
  96. ogg_all++;
  97. ogg_suc += i.second->ExportFile((output_dir + ogg_dir + std::to_string(i.second->file_id())).c_str(), sounds);
  98. }
  99. if (ext == FONT) {
  100. font_all++;
  101. //font_suc += i.second->ExportFile((output_dir + font_dir + std::to_string(i.second->file_id())).c_str(), fonts);
  102. }
  103. if (ext == UNKNOWN)
  104. {
  105. //cout << " - unk\n";
  106. unk_all++;
  107. //unk_suc += i.second->ExportFile((output_dir + unk_dir + std::to_string(i.second->file_id())).c_str());
  108. }
  109. counter++;
  110. if ((counter - 1) * 100ll / all != counter * 100ll / all) {
  111. fprintf(stderr, "Done: %lld%%\n", counter * 100ll / all);
  112. }
  113. }
  114. std::cerr << "Total found:" << std::endl;
  115. std::cerr << "Txt: " << txt_all << std::endl
  116. << "JPG: " << jpg_all << std::endl
  117. << "DDS: " << dds_all << std::endl
  118. << "WAV: " << wav_all << std::endl
  119. << "OGG: " << ogg_all << std::endl
  120. << "Fonts " << font_all << std::endl
  121. << "Unknown: " << unk_all << std::endl;
  122. std::cerr << "Total exported:" << std::endl;
  123. std::cerr << "Txt: " << txt_suc << std::endl
  124. << "JPG: " << jpg_suc << std::endl
  125. << "DDS: " << dds_suc << std::endl
  126. << "WAV: " << wav_suc << std::endl
  127. << "OGG: " << ogg_suc << std::endl
  128. << "Fonts " << font_suc << std::endl
  129. << "Unknown: " << unk_suc << std::endl;
  130. fprintf(stderr, "Spent %f seconds on running unpacker! Thank you for your patience!\n", float(clock() - begin_time) / CLOCKS_PER_SEC);
  131. std::cerr << "Success. Press enter to close\n";
  132. system("pause");
  133. return 0;
  134. }