DatFile.h 2.8 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 SubDirectory;
  50. friend class Subfile;
  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. bool PatchTextFile(long long file_id, long long gossip_id, std::string text, std::string args_order = "", std::string args = "");
  60. bool PatchTextFile(long long file_id, long long gossip_id, Database *db);
  61. bool PatchBinaryFile(long long file_id, std::string file_path);
  62. bool PatchBinaryFile(long long file_id, 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. void ReadData(BinaryData &data, long long size, long long offset = 0, long long data_offset = 0);
  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 WriteData(const BinaryData &data, long long size, long long offset = 0, long long data_offset = 0);
  80. long long constant1_;
  81. long long constant2_;
  82. long long file_size_;
  83. long long version1_;
  84. long long version2_;
  85. long long root_directory_offset_;
  86. DAT_STATE dat_state_;
  87. int dat_id_;
  88. };
  89. }
  90. }
  91. #endif //LOTRO_DAT_PATCHER_DATFILE_H