DatFile.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. class SubfileData;
  33. enum FILE_TYPE : int{
  34. TEXT,
  35. JPG,
  36. DDS,
  37. WAV,
  38. OGG,
  39. FONT,
  40. UNKNOWN
  41. };
  42. enum DAT_STATE {
  43. CLOSED,
  44. SUCCESS_OPENED,
  45. SUCCESS_SUPERBLOCK,
  46. SUCCESS_DIRECTORIES,
  47. SUCCESS_DICTIONARY,
  48. READY
  49. };
  50. class DatFile {
  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);
  61. bool PatchFile(const SubfileData &data);
  62. bool PatchAllDatabase(Database *db);
  63. void WriteUnorderedDictionary(std::string path) const;
  64. long long constant1() const;
  65. long long constant2() const;
  66. long long file_size() const;
  67. long long version1() const;
  68. long long version2() const;
  69. long long files_number() const;
  70. BinaryData GetFileData(const Subfile* file, long long offset = 0);
  71. void UpdateSubdirectories();
  72. private:
  73. void OpenDatFile(const char* dat_name);
  74. void ReadSuperBlock();
  75. void MakeDirectories();
  76. void MakeDictionary();
  77. void ReadData(BinaryData &data, long long size, long long offset = 0, long long data_offset = 0);
  78. void WriteData(const BinaryData &data, long long size, long long offset = 0, long long data_offset = 0);
  79. void ApplyFilePatch(Subfile *file, const BinaryData &data);
  80. std::vector<std::pair<long long, long long> > GetFragmentationJournal();
  81. void UpdateHeader();
  82. void UpdateFragmentationJournal(const std::vector<std::pair<long long, long long> > &journal);
  83. private:
  84. FILE *file_handler_;
  85. SubDirectory *root_directory_;
  86. std::unordered_map<long long, Subfile*> dictionary_;
  87. std::unordered_map<long long, BinaryData *> patched_list;
  88. long long constant1_;
  89. long long constant2_;
  90. long long file_size_;
  91. long long version1_;
  92. long long version2_;
  93. long long root_directory_offset_;
  94. long long fragmentation_journal_offset_;
  95. DAT_STATE dat_state_;
  96. int dat_id_;
  97. bool patched_;
  98. };
  99. }
  100. }
  101. #endif //LOTRO_DAT_PATCHER_DATFILE_H