ScummVM API documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
savegame.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 AGS_ENGINE_GAME_SAVEGAME_H
23 #define AGS_ENGINE_GAME_SAVEGAME_H
24 
25 #include "common/std/memory.h"
26 #include "ags/shared/core/platform.h"
27 #include "ags/shared/ac/game_version.h"
28 #include "ags/shared/util/error.h"
29 #include "ags/shared/util/version.h"
30 
31 namespace AGS3 {
32 namespace AGS {
33 
34 namespace Shared {
35 class Bitmap;
36 class Stream;
37 } // namespace Shared
38 
39 namespace Engine {
40 
41 using Shared::Bitmap;
42 using Shared::ErrorHandle;
43 using Shared::TypedCodeError;
44 using Shared::Stream;
45 using Shared::String;
46 using Shared::Version;
47 
48 typedef std::shared_ptr<Stream> PStream;
49 
50 //-----------------------------------------------------------------------------
51 // Savegame version history
52 //
53 // 8 last old style saved game format (of AGS 3.2.1)
54 // 9 first new style (self-descriptive block-based) format version
55 // Since 3.6.0: value is defined as AGS version represented as NN,NN,NN,NN.
56 //-----------------------------------------------------------------------------
57 enum SavegameVersion {
58  kSvgVersion_Undefined = 0,
59  kSvgVersion_321 = 8,
60  kSvgVersion_Components = 9,
61  kSvgVersion_Cmp_64bit = 10,
62  kSvgVersion_350_final = 11,
63  kSvgVersion_350_final2 = 12,
64  kSvgVersion_351 = 13,
65  kSvgVersion_360_beta = 3060023,
66  kSvgVersion_360_final = 3060041,
67  kSvgVersion_361 = 3060115,
68  kSvgVersion_361_p8 = 3060130,
69  kSvgVersion_Current = kSvgVersion_361_p8,
70  kSvgVersion_LowestSupported = kSvgVersion_321 // change if support dropped
71 };
72 
73 // Error codes for save restoration routine
74 enum SavegameErrorType {
75  kSvgErr_NoError,
76  kSvgErr_FileOpenFailed,
77  kSvgErr_SignatureFailed,
78  kSvgErr_FormatVersionNotSupported,
79  kSvgErr_IncompatibleEngine,
80  kSvgErr_GameGuidMismatch,
81  kSvgErr_ComponentListOpeningTagFormat,
82  kSvgErr_ComponentListClosingTagMissing,
83  kSvgErr_ComponentOpeningTagFormat,
84  kSvgErr_ComponentClosingTagFormat,
85  kSvgErr_ComponentSizeMismatch,
86  kSvgErr_UnsupportedComponent,
87  kSvgErr_ComponentSerialization,
88  kSvgErr_ComponentUnserialization,
89  kSvgErr_InconsistentFormat,
90  kSvgErr_UnsupportedComponentVersion,
91  kSvgErr_GameContentAssertion,
92  kSvgErr_InconsistentData,
93  kSvgErr_InconsistentPlugin,
94  kSvgErr_DifferentColorDepth,
95  kSvgErr_GameObjectInitFailed,
96  kNumSavegameError
97 };
98 
99 String GetSavegameErrorText(SavegameErrorType err);
100 
101 typedef TypedCodeError<SavegameErrorType, GetSavegameErrorText> SavegameError;
102 typedef ErrorHandle<SavegameError> HSaveError;
103 
104 // SavegameSource defines a successfully opened savegame stream
106  // Signature of the current savegame format
107  static const char *Signature;
108  // Signature of the legacy savegame format
109  static const char *LegacySignature;
110 
111  // Name of the savefile
112  String Filename;
113  // Savegame format version
114  SavegameVersion Version;
115  // A ponter to the opened stream
116  std::unique_ptr<Stream> InputStream;
117 
118  SavegameSource();
119 };
120 
121 // Supported elements of savegame description;
122 // these may be used as flags to define valid fields
123 enum SavegameDescElem {
124  kSvgDesc_None = 0,
125  kSvgDesc_EnvInfo = 0x0001,
126  kSvgDesc_UserText = 0x0002,
127  kSvgDesc_UserImage = 0x0004,
128  kSvgDesc_All = kSvgDesc_EnvInfo | kSvgDesc_UserText | kSvgDesc_UserImage
129 };
130 
131 // SavegameDescription describes savegame with information about the environment
132 // it was created in, and custom data provided by user
134  // Name of the engine that saved the game
135  String EngineName;
136  // Version of the engine that saved the game
137  Version EngineVersion;
138  // Guid of the game which made this save
139  String GameGuid;
140  // Legacy uniqueid of the game, for use in older games with no GUID
141  int LegacyID;
142  // Title of the game which made this save
143  String GameTitle;
144  // Name of the main data file used; this is needed to properly
145  // load saves made by "minigames"
146  String MainDataFilename;
147  // Game's main data version; should be checked early to know
148  // if the save was made for the supported game format
149  GameDataVersion MainDataVersion;
150  // Native color depth of the game; this is required to
151  // properly restore dynamic graphics from the save
152  int ColorDepth;
153 
154  String UserText;
155  std::unique_ptr<Bitmap> UserImage;
156 
158 };
159 
160 
161 // Opens savegame for reading; optionally reads description, if any is provided
162 HSaveError OpenSavegame(const String &filename, SavegameSource &src,
163  SavegameDescription &desc, SavegameDescElem elems = kSvgDesc_All);
164 // Opens savegame and reads the savegame description
165 HSaveError OpenSavegame(const String &filename, SavegameDescription &desc, SavegameDescElem elems = kSvgDesc_All);
166 
167 // Reads the game data from the save stream and reinitializes game state
168 HSaveError RestoreGameState(Stream *in, SavegameVersion svg_version);
169 
170 // Opens savegame for writing and puts in savegame description
171 Stream *StartSavegame(const String &filename, const String &user_text, const Bitmap *user_image);
172 
173 // Prepares game for saving state and writes game data into the save stream
174 void SaveGameState(Stream *out);
175 
176 } // namespace Engine
177 } // namespace AGS
178 } // namespace AGS3
179 
180 #endif
Definition: achievements_tables.h:27
Definition: allegro_bitmap.h:44
Definition: savegame.h:133
Definition: ptr.h:572
Definition: version.h:39
Definition: string.h:62
Definition: ptr.h:159
Definition: savegame.h:105
Definition: stream.h:52
Definition: engine.h:144
Definition: ags.h:40