Common::Error saveSavegameData(int saveGameIdx, const Common::String &saveName) { const char *filename = _vm->getSavegameFile(saveGameIdx); Common::SaveFileManager *saveMan = g_system->getSavefileManager(); Common::OutSaveFile *f = saveMan->openForSaving(filename); if (f == NULL) return Common::kNoGameDataFoundError; // Save the savegame header CruiseSavegameHeader header; header.saveName = saveName; writeSavegameHeader(f, header); if (f->err()) { delete f; saveMan->removeSavefile(filename); return Common::kWritingFailed; } else { // Create the remainder of the savegame Common::Serializer s(NULL, f); DoSync(s); f->finalize(); delete f; return Common::kNoError; } }
Common::Error SaveLoadManager::saveGame(int slot, const Common::String &saveName) { /* Pack any necessary data into the savegame data structure */ // Set the selected slot number _vm->_globals->_saveData->_data[svLastSavegameSlot] = slot; // Set up the inventory for (int i = 0; i < 35; ++i) _vm->_globals->_saveData->_inventory[i] = _vm->_globals->_inventory[i]; _vm->_globals->_saveData->_mapCarPosX = _vm->_objectsMan->_mapCarPosX; _vm->_globals->_saveData->_mapCarPosY = _vm->_objectsMan->_mapCarPosY; /* Create the savegame */ Common::OutSaveFile *savefile = g_system->getSavefileManager()->openForSaving(_vm->generateSaveName(slot)); if (!savefile) return Common::kCreatingFileFailed; // Set up the serializer Common::Serializer serializer(NULL, savefile); // Write out the savegame header hopkinsSavegameHeader header; header._saveName = saveName; header._version = HOPKINS_SAVEGAME_VERSION; writeSavegameHeader(savefile, header); // Write out the savegame data syncSavegameData(serializer, header._version); // Save file complete savefile->finalize(); delete savefile; return Common::kNoError; }
Common::Error saveSavegameData(int saveGameIdx, const Common::String &saveName, DraciEngine &vm) { Common::String filename = vm.getSavegameFile(saveGameIdx); Common::SaveFileManager *saveMan = g_system->getSavefileManager(); Common::OutSaveFile *f = saveMan->openForSaving(filename); if (f == NULL) return Common::kNoGameDataFoundError; TimeDate curTime; vm._system->getTimeAndDate(curTime); // Save the savegame header DraciSavegameHeader header; header.saveName = saveName; header.date = ((curTime.tm_mday & 0xFF) << 24) | (((curTime.tm_mon + 1) & 0xFF) << 16) | ((curTime.tm_year + 1900) & 0xFFFF); header.time = ((curTime.tm_hour & 0xFF) << 8) | ((curTime.tm_min) & 0xFF); header.playtime = vm.getTotalPlayTime() / 1000; writeSavegameHeader(f, header); if (f->err()) { delete f; saveMan->removeSavefile(filename); return Common::kWritingFailed; } else { // Create the remainder of the savegame Common::Serializer s(NULL, f); vm._game->DoSync(s); f->finalize(); delete f; return Common::kNoError; } }
Common::Error SavesManager::saveGameState(int slot, const Common::String &desc) { Common::OutSaveFile *out = g_system->getSavefileManager()->openForSaving( generateSaveName(slot)); if (!out) return Common::kCreatingFileFailed; // Push map and party data to the save archives Map &map = *g_vm->_map; map.saveMaze(); // Write the savegame header XeenSavegameHeader header; header._saveName = desc; writeSavegameHeader(out, header); // Loop through saving the sides' save archives SaveArchive *archives[2] = { File::_xeenSave, File::_darkSave }; for (int idx = 0; idx < 2; ++idx) { if (archives[idx]) { archives[idx]->save(*out); } else { // Side isn't present out->writeUint32LE(0); } } // Write out miscellaneous FileManager &files = *g_vm->_files; files.save(*out); out->finalize(); delete out; return Common::kNoError; }
Common::Error Saver::save(int slot, const Common::String &saveName) { assert(!getMacroRestoreFlag()); Common::StackLock slock1(g_globals->_soundManager._serverDisabledMutex); // Signal any objects registered for notification _saveNotifiers.notify(false); // Set fields _macroSaveFlag = true; _saveSlot = slot; // Try and create the save file Common::OutSaveFile *saveFile = g_system->getSavefileManager()->openForSaving(g_vm->generateSaveName(slot)); if (!saveFile) return Common::kCreatingFileFailed; // Set up the serializer Serializer serializer(NULL, saveFile); serializer.setSaveVersion(TSAGE_SAVEGAME_VERSION); // Write out the savegame header tSageSavegameHeader header; header.saveName = saveName; header.version = TSAGE_SAVEGAME_VERSION; writeSavegameHeader(saveFile, header); // Save out objects that need to come at the start of the savegame for (SynchronizedList<SaveListener *>::iterator i = _listeners.begin(); i != _listeners.end(); ++i) { (*i)->listenerSynchronize(serializer); } // Save each registered SaveObject descendant object into the savegame file for (SynchronizedList<SavedObject *>::iterator i = _objList.begin(); i != _objList.end(); ++i) { SavedObject *so = *i; serializer.validate(so->getClassName()); so->synchronize(serializer); } // Save file complete saveFile->writeString("END"); saveFile->finalize(); delete saveFile; // Final post-save notification _macroSaveFlag = false; _saveNotifiers.notify(true); return Common::kNoError; }
void Game::saveGame(int slotNumber, const Common::String &saveName) { Common::OutSaveFile *out = g_system->getSavefileManager()->openForSaving( _vm->generateSaveName(slotNumber)); MADSSavegameHeader header; header._saveName = saveName; writeSavegameHeader(out, header); Common::Serializer s(nullptr, out); synchronize(s, true); synchronize(s, false); out->finalize(); delete out; }
void CGEEngine::saveGame(int slotNumber, const Common::String &desc) { // Set up the serializer Common::String slotName = generateSaveName(slotNumber); Common::OutSaveFile *saveFile = g_system->getSavefileManager()->openForSaving(slotName); // Write out the ScummVM savegame header SavegameHeader header; header.saveName = desc; header.version = kSavegameVersion; writeSavegameHeader(saveFile, header); // Write out the data of the savegame syncGame(NULL, saveFile, false); // Finish writing out game data saveFile->finalize(); delete saveFile; }
Common::Error XeenEngine::saveGameState(int slot, const Common::String &desc) { Common::OutSaveFile *out = g_system->getSavefileManager()->openForSaving( generateSaveName(slot)); if (!out) return Common::kCreatingFileFailed; XeenSavegameHeader header; header._saveName = desc; writeSavegameHeader(out, header); Common::Serializer s(nullptr, out); synchronize(s); out->finalize(); delete out; return Common::kNoError; }
void CProjectItem::saveGame(int slotId, const CString &desc) { CompressedFile file; Common::OutSaveFile *saveFile = g_system->getSavefileManager()->openForSaving( g_vm->generateSaveName(slotId), false); file.open(saveFile); // Signal the game is being saved preSave(); // Write out the savegame header TitanicSavegameHeader header; header._saveName = desc; writeSavegameHeader(&file, header); // Save the contents out saveData(&file, this); // Save the game manager data _gameManager->save(&file); // Close the file and signal that the saving has finished file.close(); postSave(); }