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 HOPKINS_SAVELOAD_H
24 #define HOPKINS_SAVELOAD_H
25 
26 #include "hopkins/globals.h"
27 #include "hopkins/graphics.h"
28 
29 #include "common/scummsys.h"
30 #include "common/savefile.h"
31 #include "common/serializer.h"
32 #include "common/str.h"
33 
34 namespace Hopkins {
35 
36 class HopkinsEngine;
37 
38 #define HOPKINS_SAVEGAME_VERSION 4
39 
40 struct hopkinsSavegameHeader {
41 	uint8 _version;
42 	Common::String _saveName;
43 	Graphics::Surface *_thumbnail;
44 	int _year, _month, _day;
45 	int _hour, _minute;
46 	int _totalFrames;
47 };
48 
49 class SaveLoadManager {
50 private:
51 	HopkinsEngine *_vm;
52 
53 	void createThumbnail(Graphics::Surface *s);
54 	void syncSavegameData(Common::Serializer &s, int version);
55 	void syncCharacterLocation(Common::Serializer &s, CharacterLocation &item);
56 public:
57 	SaveLoadManager(HopkinsEngine *vm);
58 
59 	bool saveExists(const Common::String &file);
60 	bool save(const Common::String &file, const void *buf, size_t n);
61 	bool saveFile(const Common::String &file, const void *buf, size_t n);
62 	void load(const Common::String &file, byte *buf);
63 
64 	WARN_UNUSED_RESULT static bool readSavegameHeader(Common::InSaveFile *in, hopkinsSavegameHeader &header, bool skipThumbnail = true);
65 	void writeSavegameHeader(Common::OutSaveFile *out, hopkinsSavegameHeader &header);
66 	WARN_UNUSED_RESULT bool readSavegameHeader(int slot, hopkinsSavegameHeader &header, bool skipThumbnail = true);
67 	Common::Error saveGame(int slot, const Common::String &saveName);
68 	Common::Error loadGame(int slot);
69 
70 	/**
71 	 * Converts a 16-bit thumbnail to 8 bit paletted using the currently active palette.
72 	 */
73 	void convertThumb16To8(Graphics::Surface *thumb16, Graphics::Surface *thumb8);
74 };
75 
76 } // End of namespace Hopkins
77 
78 #endif /* HOPKINS_SAVELOAD_H */
79