diff options
Diffstat (limited to 'engines/gob/saveload.h')
-rw-r--r-- | engines/gob/saveload.h | 427 |
1 files changed, 332 insertions, 95 deletions
diff --git a/engines/gob/saveload.h b/engines/gob/saveload.h index bf1e4c01a8..29f7ee2594 100644 --- a/engines/gob/saveload.h +++ b/engines/gob/saveload.h @@ -26,143 +26,380 @@ #ifndef GOB_SAVELOAD_H #define GOB_SAVELOAD_H +#include "common/array.h" #include "common/stream.h" #include "gob/video.h" +#include "gob/variables.h" namespace Gob { -enum SaveType { - kSaveNone = -1, - kSaveGame, - kSaveTempSprite, - kSaveNotes, - kSaveScreenshot, - kSaveIgnore +class TempSprite { +public: + TempSprite(); + ~TempSprite(); + + bool getProperties(int16 dataVar, int32 size, int32 offset, + int &index, bool &palette) const; + + int32 getSize() const; + + bool saveSprite(const SurfaceDesc &surfDesc); + bool savePalette(const Video::Color *palette); + bool loadSprite(SurfaceDesc &surfDesc); + bool loadPalette(Video::Color *palette); + + bool toBuffer(byte *buffer, int32 size, bool palette) const; + bool fromBuffer(const byte *buffer, int32 size, bool palette); + +private: + byte *_sprite; + int16 _width; + int16 _height; + int32 _size; + Video::Color _palette[256]; + + int getSpriteIndex(int32 size) const; + bool getSpritePalette(int32 size) const; }; -class SaveLoad { +class PlainSave { +public: + PlainSave(); + ~PlainSave(); + + bool save(int16 dataVar, int32 size, int32 offset, const char *name, + const Variables *variables); + bool load(int16 dataVar, int32 size, int32 offset, const char *name, + Variables *variables); + + bool save(int16 dataVar, int32 size, int32 offset, const char *name, + const byte *variables, const byte *variableSizes) const; + bool load(int16 dataVar, int32 size, int32 offset, const char *name, + byte *variables, byte *variableSizes) const; +}; + +class StagedSave { public: - int32 getSize(SaveType type); - bool load(SaveType type, int16 dataVar, int32 size, int32 offset); - bool save(SaveType type, int16 dataVar, int32 size, int32 offset); + StagedSave(); + ~StagedSave(); + + void addStage(int32 size, bool endianed = true); - virtual SaveType getSaveType(const char *fileName) = 0; + bool save(int16 dataVar, int32 size, int32 offset, const char *name, + const Variables *variables); + bool load(int16 dataVar, int32 size, int32 offset, const char *name, + Variables *variables); + + bool save(int16 dataVar, int32 size, int32 offset, const char *name, + const byte *variables, const byte *variableSizes); + bool load(int16 dataVar, int32 size, int32 offset, const char *name, + byte *variables, byte *variableSizes); + +private: + struct Stage { + byte *bufVar; + byte *bufVarSizes; + int32 size; + int32 offset; + bool endianed; + + Stage(int32 s = 0, int32 off = 0, bool end = true) : + bufVar(0), bufVarSizes(0), size(s), offset(off), endianed(end) {} + }; + + enum Mode { + kModeNone, + kModeSave, + kModeLoad + }; + + Common::Array<Stage> _stages; + enum Mode _mode; + char *_name; + + bool _loaded; + + int findStage(int16 dataVar, int32 size, int32 offset) const; + bool allSaved() const; + + uint32 getSize() const; + + void clear(); + void assertMode(Mode mode, const char *name); + + bool write() const; + bool read(); +}; + +class PagedBuffer { +public: + PagedBuffer(uint32 pageSize = 1024); + ~PagedBuffer(); + + bool empty() const; + uint32 getSize() const; + + void clear(); + + bool write(const byte *buffer, uint32 size, uint32 offset); + bool read(byte *buffer, uint32 size, uint32 offset) const; + + uint32 writeToStream(Common::WriteStream &out) const; + uint32 readFromStream(Common::ReadStream &in); + +private: + uint32 _size; + uint32 _pageSize; + Common::Array<byte *> _pages; + + void grow(uint32 size, uint32 offset); +}; + +class SaveLoad { +public: + enum SaveMode { + kSaveModeNone, + kSaveModeIgnore, + kSaveModeSave + }; SaveLoad(GobEngine *vm, const char *targetName); virtual ~SaveLoad(); -protected: - int _curSlot; - char **_saveFiles; + virtual SaveMode getSaveMode(const char *fileName) = 0; - int _stagesCount; - byte **_buffer; + int32 getSize(const char *fileName); + bool load(const char *fileName, int16 dataVar, int32 size, int32 offset); + bool save(const char *fileName, int16 dataVar, int32 size, int32 offset); - // While using the notepad or changing the font, the original executable - // temporarily dumps Draw::_backSurface to a file. Since that's not really - // a nice thing to do, we work around it. - SurfaceDesc *_tempSprite; - Video::Color _tempPal[256]; - int32 _tempSpriteSize; + char *setCurrentSlot(char *destName, int slot); + void buildIndex(byte *buffer, char *name, int n, int32 size, int32 offset = 0); + static const char *stripPath(const char *fileName); + + static bool fromEndian(byte *buf, const byte *sizes, uint32 count); + static bool toEndian(byte *buf, const byte *sizes, uint32 count); + static uint32 read(Common::ReadStream &in, + byte *buf, byte *sizes, uint32 count); + static uint32 write(Common::WriteStream &out, + const byte *buf, const byte *sizes, uint32 count); + + static bool loadDataEndian(Common::ReadStream &in, + int16 dataVar, uint32 size, byte *variables, byte *variableSizes); + static bool saveDataEndian(Common::WriteStream &out, + int16 dataVar, uint32 size, const byte *variables, const byte *variableSizes); + +protected: GobEngine *_vm; - int getSpriteIndex(int32 size) { - if (size < -1000) - size += 1000; - - return -size - 1; - } - bool getSpritePalette(int32 size) { - return size < -1000; - } - - const char *setCurSlot(int slot); - bool fromEndian(byte *buf, const byte *sizes, uint32 count); - bool toEndian(byte *buf, const byte *sizes, uint32 count); - uint32 read(Common::ReadStream &in, byte *buf, - byte *sizes, uint32 count); - uint32 write(Common::WriteStream &out, byte *buf, - byte *sizes, uint32 count); - - bool loadDataEndian(Common::ReadStream &in, int16 dataVar, uint32 size); - bool saveDataEndian(Common::WriteStream &out, int16 dataVar, uint32 size); - - bool loadTempSprite(uint32 index, bool palette); - bool saveTempSprite(uint32 index, bool palette); - bool loadSprite(Common::ReadStream &in, int32 size); - bool saveSprite(Common::WriteStream &out, int32 size); - - int32 getSizeTempSprite(); - bool loadTempSprite(int16 dataVar, int32 size, int32 offset); - bool saveTempSprite(int16 dataVar, int32 size, int32 offset); - - virtual uint32 getSaveGameSize() = 0; - - virtual int32 getSizeGame() = 0; - virtual int32 getSizeNotes() = 0; - virtual int32 getSizeScreenshot() = 0; - virtual bool loadGame(int16 dataVar, int32 size, int32 offset) = 0; - virtual bool loadNotes(int16 dataVar, int32 size, int32 offset) = 0; - virtual bool loadScreenshot(int16 dataVar, int32 size, int32 offset) = 0; - virtual bool saveGame(int16 dataVar, int32 size, int32 offset) = 0; - virtual bool saveNotes(int16 dataVar, int32 size, int32 offset) = 0; - virtual bool saveScreenshot(int16 dataVar, int32 size, int32 offset) = 0; + char *_targetName; + + virtual int getSaveType(const char *fileName) = 0; + + virtual int32 getSizeVersioned(int type) = 0; + virtual bool loadVersioned(int type, int16 dataVar, int32 size, int32 offset) = 0; + virtual bool saveVersioned(int type, int16 dataVar, int32 size, int32 offset) = 0; }; class SaveLoad_v2 : public SaveLoad { public: - virtual SaveType getSaveType(const char *fileName); + enum SaveType { + kSaveGame, + kSaveTempSprite, + kSaveNotes + }; SaveLoad_v2(GobEngine *vm, const char *targetName); - virtual ~SaveLoad_v2() {} + virtual ~SaveLoad_v2(); + + virtual SaveMode getSaveMode(const char *fileName); protected: - virtual uint32 getSaveGameSize(); - - virtual int32 getSizeGame(); - virtual int32 getSizeNotes(); - virtual int32 getSizeScreenshot(); - virtual bool loadGame(int16 dataVar, int32 size, int32 offset); - virtual bool loadNotes(int16 dataVar, int32 size, int32 offset); - virtual bool loadScreenshot(int16 dataVar, int32 size, int32 offset); - virtual bool saveGame(int16 dataVar, int32 size, int32 offset); - virtual bool saveNotes(int16 dataVar, int32 size, int32 offset); - virtual bool saveScreenshot(int16 dataVar, int32 size, int32 offset); - - void initBuffer(); + struct SaveFile { + const char *sourceName; + char *destName; + SaveMode mode; + SaveType type; + }; + + static SaveFile _saveFiles[]; + + int32 _varSize; + + TempSprite _tmpSprite; + PlainSave _notes; + StagedSave _save; + + byte _indexBuffer[600]; + bool _hasIndex; + + virtual int getSaveType(const char *fileName); + + virtual int32 getSizeVersioned(int type); + virtual bool loadVersioned(int type, int16 dataVar, int32 size, int32 offset); + virtual bool saveVersioned(int type, int16 dataVar, int32 size, int32 offset); + + int getSlot(int32 offset) const; + int getSlotRemainder(int32 offset) const; + + int32 getSizeGame(SaveFile &saveFile); + int32 getSizeTempSprite(SaveFile &saveFile); + int32 getSizeNotes(SaveFile &saveFile); + + bool loadGame(SaveFile &saveFile, int16 dataVar, int32 size, int32 offset); + bool loadTempSprite(SaveFile &saveFile, int16 dataVar, int32 size, int32 offset); + bool loadNotes(SaveFile &saveFile, int16 dataVar, int32 size, int32 offset); + + bool saveGame(SaveFile &saveFile, int16 dataVar, int32 size, int32 offset); + bool saveTempSprite(SaveFile &saveFile, int16 dataVar, int32 size, int32 offset); + bool saveNotes(SaveFile &saveFile, int16 dataVar, int32 size, int32 offset); + + void assertInited(); }; -class SaveLoad_v3 : public SaveLoad_v2 { -public: - virtual SaveType getSaveType(const char *fileName); +enum SaveType { + kSaveNone = -1, + kSaveGame, + kSaveTempSprite, + kSaveNotes, + kSaveScreenshot, + kSaveIgnore +}; - SaveLoad_v3(GobEngine *vm, const char *targetName, uint32 screenshotSize = 19968, +class SaveLoad_v3 : public SaveLoad { +public: + enum SaveType { + kSaveNone, + kSaveGame, + kSaveTempSprite, + kSaveNotes, + kSaveScreenshot + }; + + SaveLoad_v3(GobEngine *vm, const char *targetName, + uint32 screenshotSize = 19968, int32 indexOffset = 40, int32 screenshotOffset = 80); - virtual ~SaveLoad_v3() {} + virtual ~SaveLoad_v3(); + + virtual SaveMode getSaveMode(const char *fileName); protected: + struct SaveFile { + const char *sourceName; + char *destName; + SaveMode mode; + SaveType type; + int slot; + }; + bool _useScreenshots; bool _firstSizeGame; - int8 _saveSlot; uint32 _screenshotSize; int32 _indexOffset; int32 _screenshotOffset; - virtual uint32 getSaveGameSize(); + static SaveFile _saveFiles[]; + + int32 _varSize; + + TempSprite _screenshot; + TempSprite _tmpSprite; + PlainSave _notes; + StagedSave _save; + + byte _propBuffer[1000]; + byte _indexBuffer[1200]; + bool _hasIndex; + + virtual int getSaveType(const char *fileName); + + virtual int32 getSizeVersioned(int type); + virtual bool loadVersioned(int type, int16 dataVar, int32 size, int32 offset); + virtual bool saveVersioned(int type, int16 dataVar, int32 size, int32 offset); + + int getSlot(int32 offset) const; + int getSlotRemainder(int32 offset) const; + + int32 getSizeGame(SaveFile &saveFile); + int32 getSizeTempSprite(SaveFile &saveFile); + int32 getSizeNotes(SaveFile &saveFile); + int32 getSizeScreenshot(SaveFile &saveFile); + + bool loadGame(SaveFile &saveFile, int16 dataVar, int32 size, int32 offset); + bool loadTempSprite(SaveFile &saveFile, int16 dataVar, int32 size, int32 offset); + bool loadNotes(SaveFile &saveFile, int16 dataVar, int32 size, int32 offset); + bool loadScreenshot(SaveFile &saveFile, int16 dataVar, int32 size, int32 offset); + + bool saveGame(SaveFile &saveFile, int16 dataVar, int32 size, int32 offset); + bool saveTempSprite(SaveFile &saveFile, int16 dataVar, int32 size, int32 offset); + bool saveNotes(SaveFile &saveFile, int16 dataVar, int32 size, int32 offset); + bool saveScreenshot(SaveFile &saveFile, int16 dataVar, int32 size, int32 offset); + + void assertInited(); + + void buildScreenshotIndex(byte *buffer, char *name, int n); +}; + +class SaveLoad_v4 : public SaveLoad { +public: + enum SaveType { + kSaveNone, + kSaveScreenProps, + kSaveGame, + kSaveGameScreenProps + }; + + bool _firstSizeGame; + + SaveLoad_v4(GobEngine *vm, const char *targetName); + virtual ~SaveLoad_v4(); + + virtual SaveMode getSaveMode(const char *fileName); + +protected: + struct SaveFile { + const char *sourceName; + char *destName; + SaveMode mode; + SaveType type; + }; + + static SaveFile _saveFiles[]; + + int32 _varSize; + + StagedSave _save; + + byte _propBuffer[1000]; + byte _indexBuffer[1200]; + bool _hasIndex; + + byte *_screenProps; + + virtual int getSaveType(const char *fileName); + + virtual int32 getSizeVersioned(int type); + virtual bool loadVersioned(int type, int16 dataVar, int32 size, int32 offset); + virtual bool saveVersioned(int type, int16 dataVar, int32 size, int32 offset); + + int getSlot(int32 offset) const; + int getSlotRemainder(int32 offset) const; + + int32 getSizeScreenProps(SaveFile &saveFile); + int32 getSizeGame(SaveFile &saveFile); + int32 getSizeGameScreenProps(SaveFile &saveFile); + + bool loadScreenProps(SaveFile &saveFile, int16 dataVar, int32 size, int32 offset); + bool loadGame(SaveFile &saveFile, int16 dataVar, int32 size, int32 offset); + bool loadGameScreenProps(SaveFile &saveFile, int16 dataVar, int32 size, int32 offset); - virtual int32 getSizeGame(); - virtual int32 getSizeScreenshot(); - virtual bool loadGame(int16 dataVar, int32 size, int32 offset); - virtual bool loadScreenshot(int16 dataVar, int32 size, int32 offset); - virtual bool saveGame(int16 dataVar, int32 size, int32 offset); - virtual bool saveNotes(int16 dataVar, int32 size, int32 offset); - virtual bool saveScreenshot(int16 dataVar, int32 size, int32 offset); + bool saveScreenProps(SaveFile &saveFile, int16 dataVar, int32 size, int32 offset); + bool saveGame(SaveFile &saveFile, int16 dataVar, int32 size, int32 offset); + bool saveGameScreenProps(SaveFile &saveFile, int16 dataVar, int32 size, int32 offset); - bool saveGame(int32 screenshotSize); - void initBuffer(); + void assertInited(); }; } // End of namespace Gob |