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
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (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, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #ifndef BLADERUNNER_SAVEFILE_H
24 #define BLADERUNNER_SAVEFILE_H
25 
26 #include "common/array.h"
27 #include "common/memstream.h"
28 #include "common/savefile.h"
29 #include "common/types.h"
30 
31 #include "graphics/surface.h"
32 
33 #include "engines/savestate.h"
34 
35 namespace Common {
36 class OutSaveFile;
37 class String;
38 struct Rect;
39 }
40 
41 namespace BladeRunner {
42 
43 class Vector2;
44 class Vector3;
45 class BoundingBox;
46 
47 
48 struct SaveFileHeader {
49 	uint8              _version;
50 	Common::String     _name;
51 	int                _year;
52 	int                _month;
53 	int                _day;
54 	int                _hour;
55 	int                _minute;
56 	uint32             _playTime;
57 	Graphics::Surface *_thumbnail;
58 };
59 
60 class SaveFileManager {
61 private:
62 	static const uint32 kTag = MKTAG('B', 'R', 'S', 'V');
63 	// kVersion: 3 as of Feb 5th 2020 (UTC) - ScummVM development version 2.2.0git
64 	// kVersion: 4 as of Apr 17th 2021 - Added full-size thumbnails
65 	static const uint32 kVersion = 4;
66 
67 public:
68 	// kVersion
69 	// ----------
70 	//        2:: max of 32 characters for the saved game name
71 	//        3:: max of 41 characters for the saved game name (this matches the original game's setting)
72 	static const uint32 kNameLengthV2  = 32;
73 	static const uint32 kNameLength    = 41;
74 	static const uint32 kThumbnailSize = 9600; // 80x60x16bpp
75 
76 	static SaveStateList list(const MetaEngine *metaEngine, const Common::String &target);
77 	static SaveStateDescriptor queryMetaInfos(const MetaEngine *metaEngine, const Common::String &target, int slot);
78 
79 	static Common::InSaveFile *openForLoading(const Common::String &target, int slot);
80 	static Common::OutSaveFile *openForSaving(const Common::String &target, int slot);
81 
82 	static void remove(const Common::String &target, int slot);
83 
84 	static bool readHeader(Common::SeekableReadStream &in, SaveFileHeader &header, bool skipThumbnail = true);
85 	static bool writeHeader(Common::WriteStream &out, SaveFileHeader &header);
86 
87 };
88 
89 class SaveFileWriteStream : public Common::WriteStream {
90 private:
91 	Common::WriteStream &_s;
92 
93 public:
94 	SaveFileWriteStream(Common::WriteStream &s);
95 
write(const void * dataPtr,uint32 dataSize)96 	uint32 write(const void *dataPtr, uint32 dataSize) override { return _s.write(dataPtr, dataSize); }
flush()97 	bool flush() override { return _s.flush(); }
pos()98 	int64 pos() const override { return _s.pos(); }
99 
100 	void debug(char *p);
101 
102 	void padBytes(int count);
103 
104 	void writeInt(int32 v); // this writes a 4 byte int (uses writeUint32LE)
105 	void writeFloat(float v);
106 	void writeBool(bool v);
107 	void writeStringSz(const Common::String &s, uint sz);
108 	void writeVector2(const Vector2 &v);
109 	void writeVector3(const Vector3 &v);
110 	void writeRect(const Common::Rect &v);
111 	void writeBoundingBox(const BoundingBox &v, bool serialized);
112 };
113 
114 class SaveFileReadStream : public Common::SeekableReadStream {
115 private:
116 	Common::SeekableReadStream &_s;
117 
118 public:
119 	SaveFileReadStream(Common::SeekableReadStream &s);
120 
eos()121 	bool eos() const override { return _s.eos(); }
read(void * dataPtr,uint32 dataSize)122 	uint32 read(void *dataPtr, uint32 dataSize) override { return _s.read(dataPtr, dataSize); }
pos()123 	int64 pos() const override { return _s.pos(); }
size()124 	int64 size() const override { return _s.size(); }
125 	bool seek(int64 offset, int whence = SEEK_SET) override { return _s.seek(offset, whence); }
126 
127 	int32 readInt();
128 	float readFloat();
129 	bool readBool();
130 	Common::String readStringSz(uint sz);
131 	Vector2 readVector2();
132 	Vector3 readVector3();
133 	Common::Rect readRect();
134 	BoundingBox readBoundingBox(bool serialized);
135 };
136 
137 } // End of namespace BladeRunner
138 
139 #endif
140