// // Created by Иван_Архипов on 31.10.2017. // #ifndef LOTRO_DAT_PATCHER_DATFILE_H #define LOTRO_DAT_PATCHER_DATFILE_H #ifdef LOTRO_DAT_EXPORTS #define LOTRO_DAT_API __declspec(dllexport) #else #define LOTRO_DAT_API __declspec(dllimport) #endif #include #include #include #include #include "Database.h" // Dat file names definitions #define CLIENT_LOCAL_ENGLISH 0 #define CLIENT_GENERAL 1 #define CLIENT_SOUND 2 #define CLIENT_SURFACE 3 #define CLIENT_HIGHRES 4 extern "C++" { namespace LOTRO_DAT { class BinaryData; class DatException; class SubDirectory; class Subfile; enum FILE_TYPE : int{ TEXT, JPG, DDS, WAV, OGG, FONT, UNKNOWN }; enum DAT_STATE { CLOSED, SUCCESS_OPENED, SUCCESS_SUPERBLOCK, SUCCESS_DIRECTORIES, SUCCESS_DICTIONARY, READY }; class DatFile { friend class Subfile; friend class SubDirectory; public: DatFile(); explicit DatFile(const char* filename, int dat_id); explicit DatFile(const std::string &filename, int dat_id); ~DatFile(); bool ExtractFile(long long file_id, const std::string path = ""); bool ExtractFile(long long file_id, Database *db); int ExtractAllFilesByType(FILE_TYPE type, std::string path = ""); int ExtractAllFilesByType(FILE_TYPE type, Database *db); bool PatchTextFile(long long file_id, long long gossip_id, std::string text, std::string args_order = "", std::string args = ""); bool PatchTextFile(long long file_id, long long gossip_id, Database *db); bool PatchBinaryFile(long long file_id, std::string file_path); bool PatchBinaryFile(long long file_id, Database *db); void WriteUnorderedDictionary(std::string path) const; long long constant1() const; long long constant2() const; long long file_size() const; long long version1() const; long long version2() const; long long files_number() const; private: FILE *file_handler_; SubDirectory *root_directory_; std::unordered_map dictionary_; void OpenDatFile(const char* dat_name); void ReadSuperBlock(); void MakeDirectories(); void MakeDictionary(); void ReadData(BinaryData &data, long long size, long long offset = 0, long long data_offset = 0); void WriteData(const BinaryData &data, long long size, long long offset = 0, long long data_offset = 0); long long constant1_; long long constant2_; long long file_size_; long long version1_; long long version2_; long long root_directory_offset_; DAT_STATE dat_state_; int dat_id_; }; } } #endif //LOTRO_DAT_PATCHER_DATFILE_H