ScummVM API documentation
cif.h
1/* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#ifndef NANCY_RESOURCE_CIF_H
23#define NANCY_RESOURCE_CIF_H
24
25#include "common/archive.h"
26#include "common/rect.h"
27#include "common/hashmap.h"
28
29namespace Common {
30class SeekableReadStream;
31class SeekableWriteStream;
32class Serializer;
33}
34
35namespace Nancy {
36
37struct CifInfo {
38 enum ResType : byte {
39 kResTypeAny,
40 // Type 1 seems to be obsolete
41 kResTypeImage = 2,
42 kResTypeScript = 3,
43 kResTypeEmpty = 4,
44 kResTypeXSheet = 6 // Nancy18+
45 };
46
47 enum ResCompression {
48 kResCompressionNone = 1,
49 kResCompression = 2
50 };
51
52 Common::Path name;
53 ResType type = kResTypeEmpty; // ResType
54 ResCompression comp = kResCompressionNone; // ResCompression
55 uint16 width = 0, pitch = 0, height = 0;
56 byte depth = 0; // Bit depth
57 uint32 compressedSize = 0, size = 0;
58 Common::Rect src, dest; // Used when drawing conversation cels
59
60 // Nancy30: the PNG of an image of type 4 is followed by the rect it is
61 // shown at by default
62 bool hasEmbeddedDest = false;
63
64 uint32 dataOffset = 0;
65};
66
67// Wrapper for a single file. Exclusively used for scene IFFs, though it can contain anything.
68class CifFile {
69public:
70 CifFile() : _stream(nullptr) {}
71 CifFile(const CifInfo &info) : _stream(nullptr), _info(info) {}
73 ~CifFile();
74
75 Common::SeekableReadStream *createReadStream() const;
76 Common::SeekableReadStream *createReadStreamRaw() const;
77 bool sync(Common::Serializer &ser);
78 CifInfo getInfo() const { return _info; }
79
80private:
82 CifInfo _info;
83};
84
85// Container type comprising of multiple CIF files. Contrary to its name it contains no tree structure.
86// Up to Nancy17 a tree starts with a table of info blocks, and holds only the files' data. From Nancy18
87// on it holds whole CIF files, and ends with an index of their names and offsets.
88class CifTree : public Common::Archive {
89public:
90 CifTree() : _stream(nullptr) {}
92 CifTree(const Common::ArchiveMemberPtr &member, const Common::Path &name);
93 virtual ~CifTree();
94
95 // Used for extracting additional image data for conversation cels (nancy2 and up)
96 const CifInfo &getCifInfo(const Common::Path &name) const;
97
98 // Archive interface
99 bool hasFile(const Common::Path &path) const override;
100 int listMembers(Common::ArchiveMemberList &list) const override;
101
102 const Common::ArchiveMemberPtr getMember(const Common::Path &path) const override;
104
105 Common::Path getName() const { return _name; }
106
107 static CifTree *makeCifTreeArchive(const Common::String &name, const Common::String &ext);
108 Common::SeekableReadStream *createReadStreamRaw(const Common::Path &path) const;
109 bool sync(Common::Serializer &ser);
110
111 // Nancy18+
112 bool readIndex(Common::SeekableReadStream &stream);
114
115 void addInfo(const CifInfo &info) { _writeFileMap.push_back(info); }
116 uint writeFileMapSize() const { return _writeFileMap.size(); }
117 uint32 getDataOffset(uint i) const { return _writeFileMap[i].dataOffset; }
118 void setDataOffset(uint i, uint32 offset) { _writeFileMap[i].dataOffset = offset; }
119
120 Common::Array<Common::Path> getPathsForType(CifInfo::ResType type = CifInfo::kResTypeAny) const;
121
122private:
123 // Trees backed by a plain file are opened only for as long as a read takes, since
124 // some platforms allow very few files to be open at the same time, and a game can
125 // load a lot of trees. Trees living inside another archive keep their stream, as
126 // reopening those means extracting them all over again.
127 Common::SeekableReadStream *openStream() const;
128 void closeStream(Common::SeekableReadStream *stream) const;
129
130 Common::Path _name;
134 Common::Array<CifInfo> _writeFileMap;
135};
136
137// Ciftree that only provides a file if a certain ConfMan flag is true. Used for handling game patches
138class PatchTree : public CifTree {
139public:
140 PatchTree(Common::SeekableReadStream *stream, const Common::Path &name) : CifTree(stream, name) {}
141 virtual ~PatchTree() {}
142
143 bool hasFile(const Common::Path &path) const override;
144
146};
147
148} // End of namespace Nancy
149
150#endif // NANCY_RESOURCE_CIF_H
Definition: archive.h:141
Definition: hashmap.h:85
Definition: list.h:44
Definition: path.h:52
Definition: stream.h:745
Definition: stream.h:351
Definition: serializer.h:80
Definition: str.h:59
Definition: cif.h:68
Definition: cif.h:88
const Common::ArchiveMemberPtr getMember(const Common::Path &path) const override
bool hasFile(const Common::Path &path) const override
int listMembers(Common::ArchiveMemberList &list) const override
Common::SeekableReadStream * createReadStreamForMember(const Common::Path &path) const override
Definition: cif.h:138
bool hasFile(const Common::Path &path) const override
Definition: algorithm.h:29
Definition: actionmanager.h:32
Definition: rect.h:536
Definition: cif.h:37