LzsFile.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 "common/File.h"
  18. #include "common/TypeDefine.h"
  19. /**
  20. * Represents an LZS file.
  21. *
  22. * More info about lzs fromat: {@link
  23. * https://wiki.ffrtt.ru/index.php?title=FF7/LZSS_format}
  24. */
  25. class LzsFile : public File{
  26. public:
  27. /**
  28. * Opens a lzs file and extracts it's contents
  29. *
  30. * @param file[in] Path to the file.
  31. */
  32. LzsFile(const Ogre::String& file);
  33. /**
  34. * Opens a lzs file and extracts it's contents
  35. *
  36. * @param file[in] Pointer to the file.
  37. */
  38. LzsFile(File* file);
  39. /**
  40. * Opens a lzs file fragment and extracts it's contents
  41. *
  42. * @param file[in] Path to the file.
  43. * @param offset[in] Offset to the file contents a which to start
  44. * reading.
  45. * @param ength[in] Length of the data to read from the file, in bytes.
  46. */
  47. LzsFile(File* file, u32 offset, u32 length);
  48. /**
  49. * Opens a lzs file fragment from a buffer and extracts it's contents
  50. *
  51. * @param file[in] Pointer to the buffer which holds the data.
  52. * @param offset[in] Offset to the buffer contents a which to start
  53. * reading.
  54. * @param ength[in] Length of the data to read, in bytes.
  55. */
  56. LzsFile(const u8* buffer, u32 offset, u32 length);
  57. /**
  58. * Destructor.
  59. */
  60. virtual ~LzsFile();
  61. private:
  62. /**
  63. * Extracts the file contents to the buffer.
  64. */
  65. void ExtractLzs();
  66. friend class LzsBuffer;
  67. };
  68. /**
  69. * A buffer forr the contents of a lzs file.
  70. */
  71. class LzsBuffer{
  72. public:
  73. /**
  74. * No costructor.
  75. */
  76. LzsBuffer() = delete;
  77. /**
  78. * Decompresses lzs data in a buffer.
  79. *
  80. * @param buffer[in] Buffer with the data of the lzs file.
  81. * @return Decompressed data.
  82. */
  83. static std::vector<QGears::uint8> Decompress(
  84. const std::vector<QGears::uint8>& buffer
  85. );
  86. };