TextSubFile.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. bool operator < (const TextFragment &other) const {
  17. return fragment_id < other.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. 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