DatFile.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 "Database.h"
  16. // Dat file names definitions
  17. #define CLIENT_LOCAL_ENGLISH 0
  18. #define CLIENT_GENERAL 1
  19. #define CLIENT_SOUND 2
  20. #define CLIENT_SURFACE 3
  21. #define CLIENT_HIGHRES 4
  22. extern "C++"
  23. {
  24. namespace LOTRO_DAT
  25. {
  26. class BinaryData;
  27. class DatException;
  28. class SubDirectory;
  29. class Subfile;
  30. enum FILE_TYPE : int{
  31. TEXT,
  32. JPG,
  33. DDS,
  34. WAV,
  35. OGG,
  36. FONT,
  37. UNKNOWN
  38. };
  39. enum DAT_STATE {
  40. CLOSED,
  41. SUCCESS_OPENED,
  42. SUCCESS_SUPERBLOCK,
  43. SUCCESS_DIRECTORIES,
  44. SUCCESS_DICTIONARY,
  45. READY
  46. };
  47. class DatFile
  48. {
  49. friend class Subfile;
  50. friend class SubDirectory;
  51. public:
  52. DatFile();
  53. explicit DatFile(const char* filename, int dat_id);
  54. explicit DatFile(const std::string &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 PatchTextFile(long long file_id, long long gossip_id, std::string text, std::string args_order = "", std::string args = "");
  61. bool PatchTextFile(long long file_id, long long gossip_id, Database *db);
  62. bool PatchBinaryFile(long long file_id, std::string file_path);
  63. bool PatchBinaryFile(long long file_id, Database *db);
  64. void WriteUnorderedDictionary(std::string path) const;
  65. long long constant1() const;
  66. long long constant2() const;
  67. long long file_size() const;
  68. long long version1() const;
  69. long long version2() const;
  70. long long files_number() const;
  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. long long constant1_;
  82. long long constant2_;
  83. long long file_size_;
  84. long long version1_;
  85. long long version2_;
  86. long long root_directory_offset_;
  87. DAT_STATE dat_state_;
  88. int dat_id_;
  89. };
  90. }
  91. }
  92. #endif //LOTRO_DAT_PATCHER_DATFILE_H