ScummVM API documentation
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_Current = kSvgVersion_360_final,
68  kSvgVersion_LowestSupported = kSvgVersion_321 // change if support dropped
69 };
70 
71 // Error codes for save restoration routine
72 enum SavegameErrorType {
73  kSvgErr_NoError,
74  kSvgErr_FileOpenFailed,
75  kSvgErr_SignatureFailed,
76  kSvgErr_FormatVersionNotSupported,
77  kSvgErr_IncompatibleEngine,
78  kSvgErr_GameGuidMismatch,
79  kSvgErr_ComponentListOpeningTagFormat,
80  kSvgErr_ComponentListClosingTagMissing,
81  kSvgErr_ComponentOpeningTagFormat,
82  kSvgErr_ComponentClosingTagFormat,
83  kSvgErr_ComponentSizeMismatch,
84  kSvgErr_UnsupportedComponent,
85  kSvgErr_ComponentSerialization,
86  kSvgErr_ComponentUnserialization,
87  kSvgErr_InconsistentFormat,
88  kSvgErr_UnsupportedComponentVersion,
89  kSvgErr_GameContentAssertion,
90  kSvgErr_InconsistentData,
91  kSvgErr_InconsistentPlugin,
92  kSvgErr_DifferentColorDepth,
93  kSvgErr_GameObjectInitFailed,
94  kNumSavegameError
95 };
96 
97 String GetSavegameErrorText(SavegameErrorType err);
98 
99 typedef TypedCodeError<SavegameErrorType, GetSavegameErrorText> SavegameError;
100 typedef ErrorHandle<SavegameError> HSaveError;
101 
102 // SavegameSource defines a successfully opened savegame stream
104  // Signature of the current savegame format
105  static const char *Signature;
106  // Signature of the legacy savegame format
107  static const char *LegacySignature;
108 
109  // Name of the savefile
110  String Filename;
111  // Savegame format version
112  SavegameVersion Version;
113  // A ponter to the opened stream
114  std::unique_ptr<Stream> InputStream;
115 
116  SavegameSource();
117 };
118 
119 // Supported elements of savegame description;
120 // these may be used as flags to define valid fields
121 enum SavegameDescElem {
122  kSvgDesc_None = 0,
123  kSvgDesc_EnvInfo = 0x0001,
124  kSvgDesc_UserText = 0x0002,
125  kSvgDesc_UserImage = 0x0004,
126  kSvgDesc_All = kSvgDesc_EnvInfo | kSvgDesc_UserText | kSvgDesc_UserImage
127 };
128 
129 // SavegameDescription describes savegame with information about the environment
130 // it was created in, and custom data provided by user
132  // Name of the engine that saved the game
133  String EngineName;
134  // Version of the engine that saved the game
135  Version EngineVersion;
136  // Guid of the game which made this save
137  String GameGuid;
138  // Legacy uniqueid of the game, for use in older games with no GUID
139  int LegacyID;
140  // Title of the game which made this save
141  String GameTitle;
142  // Name of the main data file used; this is needed to properly
143  // load saves made by "minigames"
144  String MainDataFilename;
145  // Game's main data version; should be checked early to know
146  // if the save was made for the supported game format
147  GameDataVersion MainDataVersion;
148  // Native color depth of the game; this is required to
149  // properly restore dynamic graphics from the save
150  int ColorDepth;
151 
152  String UserText;
153  std::unique_ptr<Bitmap> UserImage;
154 
156 };
157 
158 
159 // Opens savegame for reading; optionally reads description, if any is provided
160 HSaveError OpenSavegame(const String &filename, SavegameSource &src,
161  SavegameDescription &desc, SavegameDescElem elems = kSvgDesc_All);
162 // Opens savegame and reads the savegame description
163 HSaveError OpenSavegame(const String &filename, SavegameDescription &desc, SavegameDescElem elems = kSvgDesc_All);
164 
165 // Reads the game data from the save stream and reinitializes game state
166 HSaveError RestoreGameState(Stream *in, SavegameVersion svg_version);
167 
168 // Opens savegame for writing and puts in savegame description
169 Stream *StartSavegame(const String &filename, const String &user_text, const Bitmap *user_image);
170 
171 // Prepares game for saving state and writes game data into the save stream
172 void SaveGameState(Stream *out);
173 
174 } // namespace Engine
175 } // namespace AGS
176 } // namespace AGS3
177 
178 #endif
Definition: achievements_tables.h:27
Definition: allegro_bitmap.h:44
Definition: savegame.h:131
Definition: ptr.h:572
Definition: version.h:39
Definition: string.h:62
Definition: ptr.h:159
Definition: savegame.h:103
Definition: stream.h:52
Definition: engine.h:143
Definition: ags.h:40