DatFile.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. //
  2. // Created by Иван_Архипов on 31.10.2017.
  3. //
  4. #ifndef LOTRO_DAT_PATCHER_DATFILE_H
  5. #define LOTRO_DAT_PATCHER_DATFILE_H
  6. #ifdef LOTRO_DAT_EXPORTS
  7. #define LOTRO_DAT_API __declspec(dllexport)
  8. #else
  9. #define LOTRO_DAT_API __declspec(dllimport)
  10. #endif
  11. #include <fstream>
  12. #include <map>
  13. #include <unordered_map>
  14. #include <set>
  15. #include <vector>
  16. #include <yaml-cpp/node/node.h>
  17. #include "Database.h"
  18. // Dat file names definitions
  19. #define CLIENT_LOCAL_ENGLISH 0
  20. #define CLIENT_GENERAL 1
  21. #define CLIENT_SOUND 2
  22. #define CLIENT_SURFACE 3
  23. #define CLIENT_HIGHRES 4
  24. extern "C++"
  25. {
  26. namespace LOTRO_DAT
  27. {
  28. class BinaryData;
  29. class DatException;
  30. class SubDirectory;
  31. class Subfile;
  32. enum FILE_TYPE : int{
  33. TEXT,
  34. JPG,
  35. DDS,
  36. WAV,
  37. OGG,
  38. FONT,
  39. UNKNOWN
  40. };
  41. enum DAT_STATE {
  42. CLOSED,
  43. SUCCESS_OPENED,
  44. SUCCESS_SUPERBLOCK,
  45. SUCCESS_DIRECTORIES,
  46. SUCCESS_DICTIONARY,
  47. READY
  48. };
  49. class DatFile
  50. {
  51. friend class SubDirectory;
  52. public:
  53. DatFile();
  54. explicit DatFile(const char* filename, int dat_id);
  55. ~DatFile();
  56. bool ExtractFile(long long file_id, const std::string &path = "");
  57. bool ExtractFile(long long file_id, Database *db);
  58. int ExtractAllFilesByType(FILE_TYPE type, std::string path = "");
  59. int ExtractAllFilesByType(FILE_TYPE type, Database *db);
  60. bool PatchFile(const char *filename, YAML::Node options, long long dat_id);
  61. bool PatchDatabase(Database *db);
  62. void WriteUnorderedDictionary(std::string path) const;
  63. long long constant1() const;
  64. long long constant2() const;
  65. long long file_size() const;
  66. long long version1() const;
  67. long long version2() const;
  68. long long files_number() const;
  69. BinaryData GetFileData(const Subfile* file, long long offset = 0);
  70. void UpdateSubdirectories();
  71. private:
  72. FILE *file_handler_;
  73. SubDirectory *root_directory_;
  74. std::unordered_map<long long, Subfile*> dictionary_;
  75. void OpenDatFile(const char* dat_name);
  76. void ReadSuperBlock();
  77. void MakeDirectories();
  78. void MakeDictionary();
  79. void ReadData(BinaryData &data, long long size, long long offset = 0, long long data_offset = 0);
  80. void WriteData(const BinaryData &data, long long size, long long offset = 0, long long data_offset = 0);
  81. void ApplyFilePatch(Subfile *file, const BinaryData &data);
  82. std::vector<std::pair<long long, long long> > GetFragmentationJournal();
  83. void UpdateHeader();
  84. void UpdateFragmentationJournal(const std::vector<std::pair<long long, long long> > &journal);
  85. void UpdateFileSize();
  86. std::unordered_map<long long, BinaryData *> patched_list;
  87. long long constant1_;
  88. long long constant2_;
  89. long long file_size_;
  90. long long version1_;
  91. long long version2_;
  92. long long root_directory_offset_;
  93. long long fragmentation_journal_offset_;
  94. DAT_STATE dat_state_;
  95. int dat_id_;
  96. bool patched_;
  97. };
  98. }
  99. }
  100. #endif //LOTRO_DAT_PATCHER_DATFILE_H