22 #ifndef LASTEXPRESS_SAVELOAD_H 23 #define LASTEXPRESS_SAVELOAD_H 73 #include "lastexpress/shared.h" 75 #include "common/savefile.h" 76 #include "common/serializer.h" 77 #include "common/memstream.h" 79 #include "engines/savestate.h" 84 #define DISABLE_COMPRESSION 1 87 #define SAVEGAME_SIGNATURE (0x12001200 ^ DISABLE_COMPRESSION) // 301994496 88 #define SAVEGAME_ENTRY_SIGNATURE 0xE660E660 // 3865110112 90 #define WRAP_SYNC_FUNCTION(instance, className, method) \ 91 new Common::Functor1Mem<Common::Serializer &, void, className>(instance, &className::method) 93 class LastExpressEngine;
97 SavegameStream() : MemoryWriteStreamDynamic(DisposeAfterUse::YES), _eos(
false) {
98 _enableCompression =
false;
104 _status = kStatusReady;
106 memset(_buffer, 0, 256);
109 int64
pos()
const override {
return MemoryWriteStreamDynamic::pos(); }
110 int64
size()
const override {
return MemoryWriteStreamDynamic::size(); }
111 bool seek(int64 offset,
int whence = SEEK_SET)
override {
return MemoryWriteStreamDynamic::seek(offset, whence); }
112 bool eos()
const override {
return _eos; }
113 uint32
read(
void *dataPtr, uint32 dataSize)
override;
114 uint32
write(
const void *dataPtr, uint32 dataSize)
override;
119 enum CompressedStreamStatus {
125 uint32 readUncompressed(
void *dataPtr, uint32 dataSize);
128 uint32 writeCompressed(
const void *dataPtr, uint32 dataSize);
129 uint32 readCompressed(
void *dataPtr, uint32 dataSize);
131 void writeBuffer(uint8 value,
bool onlyValue =
true);
138 bool _enableCompression;
144 CompressedStreamStatus _status;
151 static const int kMaximumSaveSlots = 6;
158 void clear(
bool clearStream =
false);
159 uint32 init(
const Common::String &target, GameId
id,
bool resetHeaders);
163 void loadGame(uint32 index);
164 void saveGame(SavegameType type, EntityIndex entity, uint32 value);
166 void loadVolumeBrightness();
167 void saveVolumeBrightness();
178 static bool isSavegamePresent(
const Common::String &target, GameId
id);
179 static bool isSavegameValid(
const Common::String &target, GameId
id);
181 bool isGameFinished(uint32 menuIndex, uint32 savegameIndex);
184 uint32 getTime(uint32 index) {
return getEntry(index)->time; }
185 ChapterIndex getChapter(uint32 index) {
return getEntry(index)->chapter; }
186 uint32 getValue(uint32 index) {
return getEntry(index)->value; }
187 uint32 getLastSavegameTicks()
const {
return _gameTicksLastSavegame; }
202 SavegameMainHeader() {
203 signature = SAVEGAME_SIGNATURE;
214 s.syncAsUint32LE(signature);
215 s.syncAsUint32LE(count);
216 s.syncAsUint32LE(offset);
217 s.syncAsUint32LE(offsetEntry);
218 s.syncAsUint32LE(keepIndex);
219 s.syncAsUint32LE(brightness);
220 s.syncAsUint32LE(volume);
221 s.syncAsUint32LE(field_1C);
225 if (signature != SAVEGAME_SIGNATURE)
235 if (offsetEntry < 32)
238 if (keepIndex != 1 && keepIndex != 0)
241 if (brightness < 0 || brightness > 6)
244 if (volume < 0 || volume > 7)
259 ChapterIndex chapter;
264 SavegameEntryHeader() {
265 signature = SAVEGAME_ENTRY_SIGNATURE;
266 type = kSavegameTypeIndex;
269 chapter = kChapterAll;
276 s.syncAsUint32LE(signature);
277 s.syncAsUint32LE(type);
278 s.syncAsUint32LE(time);
279 s.syncAsUint32LE(offset);
280 s.syncAsUint32LE(chapter);
281 s.syncAsUint32LE(value);
282 s.syncAsUint32LE(field_18);
283 s.syncAsUint32LE(field_1C);
287 if (signature != SAVEGAME_ENTRY_SIGNATURE)
290 if (type < kSavegameTypeTime || type > kSavegameTypeTickInterval)
293 if (time < kTimeStartGame || time > kTimeCityConstantinople)
296 if (offset <= 0 || offset & 0xF)
309 uint32 _gameTicksLastSavegame;
315 void writeEntry(SavegameType type, EntityIndex entity, uint32 val);
316 void readEntry(SavegameType *type, EntityIndex *entity, uint32 *val,
bool keepIndex);
321 SavegameEntryHeader *getEntry(uint32 index);
335 #endif // LASTEXPRESS_SAVELOAD_H
Definition: savefile.h:54
Definition: lastexpress.h:69
int64 size() const override
Definition: savegame.h:110
Definition: savegame.h:95
Definition: memstream.h:194
Definition: animation.h:45
Definition: serializer.h:79
bool eos() const override
Definition: savegame.h:112
Definition: savegame.h:149
bool seek(int64 offset, int whence=SEEK_SET) override
Definition: savegame.h:111
uint32 read(void *dataPtr, uint32 dataSize) override
Definition: serializer.h:308
uint32 write(const void *dataPtr, uint32 dataSize) override
int64 pos() const override
Definition: savegame.h:109