extractor_example.cpp 12 KB

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