| 1 | /*************************************************************************** |
| 2 | * fheroes2: https://github.com/ihhub/fheroes2 * |
| 3 | * Copyright (C) 2020 - 2025 * |
| 4 | * * |
| 5 | * This program is free software; you can redistribute it and/or modify * |
| 6 | * it under the terms of the GNU General Public License as published by * |
| 7 | * the Free Software Foundation; either version 2 of the License, or * |
| 8 | * (at your option) any later version. * |
| 9 | * * |
| 10 | * This program 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 | * You should have received a copy of the GNU General Public License * |
| 16 | * along with this program; if not, write to the * |
| 17 | * Free Software Foundation, Inc., * |
| 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
| 19 | ***************************************************************************/ |
| 20 | |
| 21 | #pragma once |
| 22 | |
| 23 | #include <cstddef> |
| 24 | #include <cstdint> |
| 25 | #include <functional> |
| 26 | #include <map> |
| 27 | #include <string> |
| 28 | #include <string_view> |
| 29 | #include <utility> |
| 30 | #include <vector> |
| 31 | |
| 32 | #include "serialize.h" |
| 33 | |
| 34 | namespace fheroes2 |
| 35 | { |
| 36 | class AGGFile |
| 37 | { |
| 38 | public: |
| 39 | bool isGood() const |
| 40 | { |
| 41 | return !_stream.fail() && !_files.empty(); |
| 42 | } |
| 43 | |
| 44 | bool open( const std::string & fileName ); |
| 45 | std::vector<uint8_t> read( const std::string & fileName ); |
| 46 | |
| 47 | private: |
| 48 | static const size_t _maxFilenameSize = 15; // 8.3 ASCIIZ file name + 2-bytes padding |
| 49 | |
| 50 | StreamFile _stream; |
| 51 | std::map<std::string, std::pair<uint32_t, uint32_t>, std::less<>> _files; |
| 52 | }; |
| 53 | |
| 54 | struct ICNHeader |
| 55 | { |
| 56 | int16_t offsetX{ 0 }; |
| 57 | int16_t offsetY{ 0 }; |
| 58 | uint16_t width{ 0 }; |
| 59 | uint16_t height{ 0 }; |
| 60 | // Used for adventure map animations, this can replace ICN::AnimationFrame. |
| 61 | // The frames count is always a modulus of 32 (only 5 bits are used): for animations with more than 31 frames the value is ( totalFrames - 32 ). |
| 62 | // TODO: Find a way to detect that 32 was deducted from the animationFrames value if it is possible. |
| 63 | // When the 6th bit in animationFrames is set then it is Monochromatic ICN image. |
| 64 | uint8_t animationFrames{ 0 }; |
| 65 | uint32_t offsetData{ 0 }; |
| 66 | }; |
| 67 | |
| 68 | uint32_t calculateAggFilenameHash( const std::string_view str ); |
| 69 | } |
| 70 | |
| 71 | IStreamBase & operator>>( IStreamBase & stream, fheroes2::ICNHeader & icn ); |