ff7FieldTextWriter.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * Copyright (C) 2022 The V-Gears Team
  3. *
  4. * This file is part of V-Gears
  5. *
  6. * V-Gears is free software: you can redistribute it and/or modify it under
  7. * terms of the GNU General Public License as published by the Free Software
  8. * Foundation, version 3.0 (GPLv3) of the License.
  9. *
  10. * V-Gears is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #pragma once
  16. #include <vector>
  17. #include <memory>
  18. #include "common/TypeDefine.h"
  19. #include "common/Logger.h"
  20. /**
  21. * Handles the
  22. */
  23. class FF7FieldTextWriter{
  24. public:
  25. /**
  26. * Initializes the text file.
  27. *
  28. * Writes the XML text section opening tag.
  29. *
  30. * @param file_name[in] Path to the file to write te text to.
  31. */
  32. void Begin(std::string file_name);
  33. /**
  34. * Writes text to the XML file.
  35. *
  36. * @param script_section_buffer[in] The text data to write.
  37. * @param field_name[in] The field of the text.
  38. * @param english[in] True if the language to write.
  39. */
  40. void Write(
  41. const std::vector<u8>& script_section_buffer, std::string field_name,
  42. bool english = true
  43. );
  44. /**
  45. * Finalizes the text file.
  46. *
  47. * Writes the XML text section closing tag.
  48. */
  49. void End();
  50. private:
  51. /**
  52. * Adds text.
  53. *
  54. * @param text[in] The text to add.
  55. */
  56. void AddText(std::vector<unsigned char>& text);
  57. /**
  58. * Reads 16 bytes of data from the data (little endian).
  59. *
  60. * @param offset[in] Offset at which to read.
  61. * @return 16 bytes of data at the specified offset.
  62. * @throws std::out_of_range If the offset is out of the data.
  63. */
  64. u16 GetU16LE(u32 offset);
  65. /**
  66. * Reads 8 bytes of data from the data.
  67. *
  68. * @param offset[in] Offset at which to read.
  69. * @return 8 bytes of data at the specified offset.
  70. * @throws std::out_of_range If the offset is out of the data.
  71. */
  72. u8 GetU8(u32 offset);
  73. /**
  74. * The logger used to write text.
  75. */
  76. std::unique_ptr<Logger> logger_;
  77. /**
  78. * The data being read.
  79. */
  80. std::vector<u8> data_;
  81. /**
  82. * Indicates if the text XML tag has been openend and not closed.
  83. */
  84. bool tag_open_ = false;
  85. };