ScummVM API documentation
savefile.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 * This file is dual-licensed.
22 * In addition to the GPLv3 license mentioned above, this code is also
23 * licensed under LGPL 2.1. See LICENSES/COPYING.LGPL file for the
24 * full text of the license.
25 *
26 */
27
28#ifndef GOB_SAVE_SAVEFILE_H
29#define GOB_SAVE_SAVEFILE_H
30
31#include "common/endian.h"
32#include "common/array.h"
33#include "common/savefile.h"
34
35namespace Gob {
36
37class GobEngine;
38class Surface;
39
50public:
52 static const int kSize = 20;
53 static const uint32 kID1 = MKTAG(0,'S','C','V');
54 static const uint32 kID2 = MKTAG('M','G','O','B');
55
56 SaveHeader(uint32 type = 0, uint32 version = 0, uint32 size = 0);
57
58 bool operator==(const SaveHeader &header) const;
59 bool operator!=(const SaveHeader &header) const;
60
62 bool read(Common::ReadStream &stream);
64 bool verify(Common::ReadStream &stream) const;
70 bool write(Common::WriteStream &stream) const;
71
72 uint32 getType() const;
73 uint32 getVersion() const;
74 uint32 getSize() const;
75
76 void setType(uint32 type);
77 void setVersion(uint32 version);
78 void setSize(uint32 size);
79
80private:
82 uint32 _type;
84 uint32 _version;
86 uint32 _size;
87};
88
90class SavePart {
91public:
92 SavePart();
93 virtual ~SavePart();
94
96 virtual uint32 getSize() const;
97
99 virtual bool read(Common::ReadStream &stream) = 0;
101 virtual bool write(Common::WriteStream &stream) const = 0;
102
103protected:
104 SaveHeader _header;
105};
106
108class SavePartMem : public SavePart {
109public:
110 static const uint32 kVersion = 1;
111 static const uint32 kID = MKTAG('P','M','E','M');
112
113 SavePartMem(uint32 size);
114 ~SavePartMem() override;
115
116 bool read(Common::ReadStream &stream) override;
117 bool write(Common::WriteStream &stream) const override;
118
120 bool readFrom(const byte *data, uint32 offset, uint32 size);
122 bool writeInto(byte *data, uint32 offset, uint32 size) const;
123
124private:
125 uint32 _size;
126 byte *_data;
127};
128
130class SavePartVars : public SavePart {
131public:
132 static const uint32 kVersion = 1;
133 static const uint32 kID = MKTAG('V','A','R','S');
134
135 SavePartVars(GobEngine *vm, uint32 size);
136 ~SavePartVars() override;
137
138 bool read(Common::ReadStream &stream) override;
139 bool write(Common::WriteStream &stream) const override;
140
142 bool readFrom(uint32 var, uint32 offset, uint32 size);
144 bool writeInto(uint32 var, uint32 offset, uint32 size) const;
145
147 bool readFromRaw(const byte *data, uint32 offset, uint32 size);
148
150 bool writeIntoRaw(byte *data, uint32 offset, uint32 size) const;
151
152 const byte* data() const { return _data; }
153
154private:
155 GobEngine *_vm;
156
157 uint32 _size;
158 byte *_data;
159};
160
162class SavePartSprite : public SavePart {
163public:
164 static const uint32 kVersion = 2;
165 static const uint32 kID = MKTAG('S','P','R','T');
166
167 SavePartSprite(uint32 width, uint32 height, bool trueColor = false);
168 ~SavePartSprite() override;
169
170 bool read(Common::ReadStream &stream) override;
171 bool write(Common::WriteStream &stream) const override;
172
174 bool readPalette(const byte *palette);
176 bool readSprite(const Surface &sprite);
177
179 bool readSpriteRaw(const byte *data, uint32 size);
180
182 bool writePalette(byte *palette) const;
184 bool writeSprite(Surface &sprite) const;
185
186private:
187 uint32 _width;
188 uint32 _height;
189
190 uint32 _spriteSize;
191
192 bool _oldFormat;
193 bool _trueColor;
194
195 byte *_dataSprite;
196 byte *_dataPalette;
197};
198
200class SavePartInfo : public SavePart {
201public:
202 static const uint32 kVersion = 1;
203 static const uint32 kID = MKTAG('I','N','F','O');
204
213 SavePartInfo(uint32 descMaxLength, uint32 gameID,
214 uint32 gameVersion, byte endian, uint32 varCount);
215 ~SavePartInfo() override;
216
218 const char *getDesc() const;
220 uint32 getDescMaxLength() const;
221
223 void setVarCount(uint32 varCount);
225 void setDesc(const char *desc = 0);
227 void setDesc(const byte *desc, uint32 size);
228
229 bool read(Common::ReadStream &stream) override;
230 bool write(Common::WriteStream &stream) const override;
231
232private:
233 char *_desc;
234 uint32 _descMaxLength;
235 uint32 _gameID;
236 uint32 _gameVersion;
237 uint32 _varCount;
238 byte _endian;
239};
240
243public:
244 static const uint32 kVersion = 1;
245 static const uint32 kID = MKTAG('C','O','N','T');
246
252 SaveContainer(uint32 partCount, uint32 slot);
254
255 uint32 getSlot() const;
256 uint32 getSize() const;
257
259 bool hasAllParts() const;
260
262 void clear();
263
265 bool writePart(uint32 partN, const SavePart *part);
267 bool readPart(uint32 partN, SavePart *part) const;
269 bool readPartHeader(uint32 partN, SaveHeader *header) const;
270
272 static bool isSave(Common::SeekableReadStream &stream);
273
274protected:
276 struct Part {
277 uint32 size;
278 byte *data;
279
280 Part(uint32 s);
281 ~Part();
282
283 Common::WriteStream *createWriteStream();
284 Common::ReadStream *createReadStream() const;
285 };
286
288 struct PartInfo {
289 uint32 id;
290 uint32 offset;
291 uint32 size;
292 };
293
294 typedef Common::Array<Part *>::iterator PartIterator;
295 typedef Common::Array<Part *>::const_iterator PartConstIterator;
296
297 uint32 _partCount;
298 uint32 _slot;
299
300 SaveHeader _header;
302
303 uint32 calcSize() const;
304
305 bool read(Common::ReadStream &stream);
306 bool write(Common::WriteStream &stream) const;
307
310};
311
313class SaveReader : public SaveContainer {
314public:
315 SaveReader(uint32 partCount, uint32 slot, const Common::String &fileName);
316 SaveReader(uint32 partCount, uint32 slot, Common::SeekableReadStream &stream);
317 ~SaveReader();
318
319 bool load();
320
321 bool readPart(uint32 partN, SavePart *part) const;
322 bool readPartHeader(uint32 partN, SaveHeader *header) const;
323
327 static bool getInfo(const Common::String &fileName, SavePartInfo &info);
328
329protected:
330 Common::String _fileName;
332
333 bool _loaded;
334
335 static Common::InSaveFile *openSave(const Common::String &fileName);
336 Common::InSaveFile *openSave();
337};
338
341public:
342 SaveWriter(uint32 partCount, uint32 slot);
343 SaveWriter(uint32 partCount, uint32 slot, const Common::String &fileName);
344 ~SaveWriter();
345
346 bool writePart(uint32 partN, const SavePart *part);
347
348 bool save(Common::WriteStream &stream);
349 bool deleteFile();
350
351protected:
352 bool save();
353
354 Common::String _fileName;
355
357 bool canSave() const;
358
359 static Common::OutSaveFile *openSave(const Common::String &fileName);
360 Common::OutSaveFile *openSave();
361};
362
363} // End of namespace Gob
364
365#endif // GOB_SAVE_SAVEFILE_H
Definition: array.h:52
T * iterator
Definition: array.h:54
const T * const_iterator
Definition: array.h:55
Definition: savefile.h:54
Definition: stream.h:385
Definition: stream.h:745
Definition: str.h:59
Definition: stream.h:77
Definition: gob.h:166
Definition: savefile.h:242
SaveContainer(uint32 partCount, uint32 slot)
bool readPart(uint32 partN, SavePart *part) const
bool writePart(uint32 partN, const SavePart *part)
bool readPartHeader(uint32 partN, SaveHeader *header) const
static bool isSave(Common::SeekableReadStream &stream)
static Common::Array< PartInfo > * getPartsInfo(Common::SeekableReadStream &stream)
bool hasAllParts() const
Definition: savefile.h:49
bool verify(Common::ReadStream &stream) const
static const int kSize
Definition: savefile.h:52
bool read(Common::ReadStream &stream)
bool verifyReadSize(Common::ReadStream &stream)
bool write(Common::WriteStream &stream) const
Definition: savefile.h:90
virtual bool read(Common::ReadStream &stream)=0
virtual bool write(Common::WriteStream &stream) const =0
virtual uint32 getSize() const
Definition: savefile.h:200
void setVarCount(uint32 varCount)
bool write(Common::WriteStream &stream) const override
bool read(Common::ReadStream &stream) override
void setDesc(const char *desc=0)
const char * getDesc() const
uint32 getDescMaxLength() const
SavePartInfo(uint32 descMaxLength, uint32 gameID, uint32 gameVersion, byte endian, uint32 varCount)
void setDesc(const byte *desc, uint32 size)
Definition: savefile.h:108
bool readFrom(const byte *data, uint32 offset, uint32 size)
bool write(Common::WriteStream &stream) const override
bool writeInto(byte *data, uint32 offset, uint32 size) const
bool read(Common::ReadStream &stream) override
Definition: savefile.h:162
bool write(Common::WriteStream &stream) const override
bool read(Common::ReadStream &stream) override
bool readSprite(const Surface &sprite)
bool writePalette(byte *palette) const
bool writeSprite(Surface &sprite) const
bool readPalette(const byte *palette)
bool readSpriteRaw(const byte *data, uint32 size)
Definition: savefile.h:130
bool writeInto(uint32 var, uint32 offset, uint32 size) const
bool read(Common::ReadStream &stream) override
bool readFrom(uint32 var, uint32 offset, uint32 size)
bool readFromRaw(const byte *data, uint32 offset, uint32 size)
bool writeIntoRaw(byte *data, uint32 offset, uint32 size) const
bool write(Common::WriteStream &stream) const override
Definition: savefile.h:313
static bool getInfo(Common::SeekableReadStream &stream, SavePartInfo &info)
static bool getInfo(const Common::String &fileName, SavePartInfo &info)
Definition: savefile.h:340
bool canSave() const
Definition: surface.h:106
#define MKTAG(a0, a1, a2, a3)
Definition: endian.h:188
Definition: savefile.h:276
Definition: savefile.h:288