TextSubFile.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. //
  2. // Created by Иван_Архипов on 24.11.2017.
  3. //
  4. #ifndef LOTRO_DAT_LIBRARY_TEXTSUBFILE_H
  5. #define LOTRO_DAT_LIBRARY_TEXTSUBFILE_H
  6. #include "../SubFile.h"
  7. #include "../SubfileData.h"
  8. #include "../BinaryData.h"
  9. #include <vector>
  10. #include <unordered_map>
  11. namespace LOTRO_DAT {
  12. struct TextFragment {
  13. long long fragment_id;
  14. std::u16string text;
  15. std::string args;
  16. friend bool operator < (const TextFragment &first, const TextFragment &second) {
  17. return first.fragment_id < second.fragment_id;
  18. }
  19. };
  20. class TextSubFile : public SubFile {
  21. public:
  22. TextSubFile() = delete;
  23. explicit TextSubFile(const TextSubFile &other) = delete;
  24. SubFile &operator =(const TextSubFile &other) = delete;
  25. explicit TextSubFile(SubFile preinit_file);
  26. FILE_TYPE FileType() const override;
  27. std::string Extension() const override;
  28. SubfileData PrepareForExport(const BinaryData &file_data) override;
  29. BinaryData MakeForImport(const BinaryData &old_data, const SubfileData &data) override;
  30. private:
  31. std::vector<TextFragment> patch_fragments_;
  32. std::vector<std::u16string> text_pieces_;
  33. std::vector<long long> argument_references_;
  34. std::vector<std::vector<BinaryData>> argument_strings_;
  35. static BinaryData buffer_;
  36. private:
  37. void MakePieces(const BinaryData &data, long long &offset);
  38. void MakeArgumentReferences(const BinaryData &data, long long &offset);
  39. void MakeArgumentStrings(const BinaryData &data, long long &offset);
  40. void ParsePatchFragments(const SubfileData &data);
  41. BinaryData BuildPieces(const BinaryData &data, const TextFragment &new_data, long long &offset);
  42. BinaryData BuildArgumentReferences(const BinaryData &data, const TextFragment &new_data, long long &offset);
  43. BinaryData BuildArgumentStrings(const BinaryData &data, const TextFragment &new_data, long long &offset);
  44. BinaryData GetPieceData(const BinaryData &data, long long &offset) const;
  45. BinaryData GetArgumentReferenceData(const BinaryData &data, long long &offset) const;
  46. BinaryData GetArgumentStringsData(const BinaryData &data, long long &offset) const;
  47. };
  48. };
  49. #endif //LOTRO_DAT_LIBRARY_TEXTSUBFILE_H