Skip to content

Commit

Permalink
PEGASUS: Fix saving while in the space chase
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Hoops committed Sep 23, 2012
1 parent 5074742 commit 3a5b3a5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
31 changes: 31 additions & 0 deletions engines/pegasus/pegasus.cpp
Expand Up @@ -527,6 +527,20 @@ bool PegasusEngine::loadFromStream(Common::ReadStream *stream) {
}

bool PegasusEngine::writeToStream(Common::WriteStream *stream, int saveType) {
// WORKAROUND: If we don't have the interface, we can't actually save.
// However, we should still have a continue point, so we will just dump that
// out. This is needed for saving a game while in the space chase.
if (!g_interface) {
// Saving a continue stream from a continue stream should
// never happen. In addition, we do need to have a continue
// stream for this to work.
if (saveType != kNormalSave || !_continuePoint)
return false;

writeContinueStream(stream);
return true;
}

if (g_neighborhood)
g_neighborhood->flushGameState();

Expand Down Expand Up @@ -602,10 +616,27 @@ void PegasusEngine::loadFromContinuePoint() {
if (!_continuePoint)
error("Attempting to load from non-existant continue point");

_continuePoint->seek(0);

if (!loadFromStream(_continuePoint))
error("Failed loading continue point");
}

void PegasusEngine::writeContinueStream(Common::WriteStream *stream) {
// We're going to pretty much copy the stream, except for the save type
_continuePoint->seek(0);
stream->writeUint32BE(_continuePoint->readUint32BE());
_continuePoint->readUint32BE(); // skip the continue type
stream->writeUint32BE(kPegasusPrimeDisk1GameType + _currentCD - 1);

// Now just copy over the rest
uint32 size = _continuePoint->size() - _continuePoint->pos();
byte *data = new byte[size];
_continuePoint->read(data, size);
stream->write(data, size);
delete[] data;
}

Common::Error PegasusEngine::loadGameState(int slot) {
Common::StringArray filenames = _saveFileMan->listSavefiles("pegasus-*.sav");
Common::InSaveFile *loadFile = _saveFileMan->openForLoading(filenames[slot]);
Expand Down
3 changes: 2 additions & 1 deletion engines/pegasus/pegasus.h
Expand Up @@ -246,7 +246,8 @@ friend class InputHandler;
bool loadFromStream(Common::ReadStream *stream);
bool writeToStream(Common::WriteStream *stream, int saveType);
void loadFromContinuePoint();
Common::ReadStream *_continuePoint;
void writeContinueStream(Common::WriteStream *stream);
Common::SeekableReadStream *_continuePoint;
bool _saveAllowed, _loadAllowed; // It's so nice that this was in the original code already :P
Common::Error showLoadDialog();
Common::Error showSaveDialog();
Expand Down

0 comments on commit 3a5b3a5

Please sign in to comment.