DatFile.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 "Database.h"
  17. // Dat file names definitions
  18. #define CLIENT_LOCAL_ENGLISH 0
  19. #define CLIENT_GENERAL 1
  20. #define CLIENT_SOUND 2
  21. #define CLIENT_SURFACE 3
  22. #define CLIENT_HIGHRES 4
  23. extern "C++"
  24. {
  25. namespace LOTRO_DAT
  26. {
  27. class BinaryData;
  28. class DatException;
  29. class SubDirectory;
  30. class Subfile;
  31. enum FILE_TYPE : int{
  32. TEXT,
  33. JPG,
  34. DDS,
  35. WAV,
  36. OGG,
  37. FONT,
  38. UNKNOWN
  39. };
  40. enum DAT_STATE {
  41. CLOSED,
  42. SUCCESS_OPENED,
  43. SUCCESS_SUPERBLOCK,
  44. SUCCESS_DIRECTORIES,
  45. SUCCESS_DICTIONARY,
  46. READY
  47. };
  48. class DatFile
  49. {
  50. friend class SubDirectory;
  51. public:
  52. DatFile();
  53. explicit DatFile(const char* filename, int dat_id);
  54. ~DatFile();
  55. bool ExtractFile(long long file_id, const std::string path = "");
  56. bool ExtractFile(long long file_id, Database *db);
  57. int ExtractAllFilesByType(FILE_TYPE type, std::string path = "");
  58. int ExtractAllFilesByType(FILE_TYPE type, Database *db);
  59. void WriteUnorderedDictionary(std::string path) const;
  60. long long constant1() const;
  61. long long constant2() const;
  62. long long file_size() const;
  63. long long version1() const;
  64. long long version2() const;
  65. long long files_number() const;
  66. BinaryData GetFileData(const Subfile* file, long long offset = 0);
  67. private:
  68. FILE *file_handler_;
  69. SubDirectory *root_directory_;
  70. std::unordered_map<long long, Subfile*> dictionary_;
  71. void OpenDatFile(const char* dat_name);
  72. void ReadSuperBlock();
  73. void MakeDirectories();
  74. void MakeDictionary();
  75. void ReadData(BinaryData &data, long long size, long long offset = 0, long long data_offset = 0);
  76. void WriteData(const BinaryData &data, long long size, long long offset = 0, long long data_offset = 0);
  77. void ApplyFilePatch(const Subfile* file, const BinaryData &data);
  78. void UpdateSubdirectories();
  79. std::vector<std::pair<long long, long long> > GetFragmentationJournal();
  80. void UpdateHeader();
  81. void UpdateFragmentationJournal(const std::vector<std::pair<long long, long long> > &journal);
  82. long long constant1_;
  83. long long constant2_;
  84. long long file_size_;
  85. long long version1_;
  86. long long version2_;
  87. long long root_directory_offset_;
  88. long long fragmentation_journal_offset_;
  89. DAT_STATE dat_state_;
  90. int dat_id_;
  91. bool patched_;
  92. };
  93. }
  94. }
  95. #endif //LOTRO_DAT_PATCHER_DATFILE_H