static void syncTime(Common::Serializer &s, TimeDate &t) { s.syncAsUint16LE(t.tm_year); s.syncAsByte(t.tm_mon); s.syncAsByte(t.tm_mday); s.syncAsByte(t.tm_hour); s.syncAsByte(t.tm_min); s.syncAsByte(t.tm_sec); }
static void syncSoundList(Common::Serializer &s) { for (int i = 0; i < 4; ++i) { SoundEntry &se = soundList[i]; s.syncAsSint16LE(se.frameNum); s.syncAsUint16LE(se.frequency); s.syncAsSint16LE(se.volume); } }
void syncAllActorsAlive(Common::Serializer &s) { for (int i = 0; i < MAX_SAVED_ALIVES; i++) { s.syncAsByte(actorInfo[i].bAlive); s.syncAsByte(actorInfo[i].tagged); s.syncAsByte(actorInfo[i].tType); s.syncAsUint32LE(actorInfo[i].hTag); } }
void syncSCdata(Common::Serializer &s) { s.syncAsUint32LE(HookScene.scene); s.syncAsSint32LE(HookScene.entry); s.syncAsSint32LE(HookScene.trans); s.syncAsUint32LE(DelayedScene.scene); s.syncAsSint32LE(DelayedScene.entry); s.syncAsSint32LE(DelayedScene.trans); }
/** * (Un)serialize the timer data for save/restore game. */ void syncTimerInfo(Common::Serializer &s) { for (int i = 0; i < MAX_TIMERS; i++) { s.syncAsSint32LE(timers[i].tno); s.syncAsSint32LE(timers[i].ticks); s.syncAsSint32LE(timers[i].secs); s.syncAsSint32LE(timers[i].delta); s.syncAsSint32LE(timers[i].frame); } }
static void syncBackgroundTable(Common::Serializer &s) { // restore backgroundTable for (int i = 0; i < 8; i++) { if (s.isSaving() && (strlen(backgroundTable[i].name) > 8)) warning("Saving a background resource that has too long a name"); s.syncBytes((byte *)backgroundTable[i].name, 9); s.syncBytes((byte *)backgroundTable[i].extention, 6); } }
void Scene::synchronize(Common::Serializer &s) { _action.synchronize(s); _rails.synchronize(s); _userInterface.synchronize(s); s.syncAsByte(_reloadSceneFlag); s.syncAsByte(_roomChanged); s.syncAsUint16LE(_nextSceneId); s.syncAsUint16LE(_priorSceneId); _dynamicHotspots.synchronize(s); }
void UserInterface::synchronize(Common::Serializer &s) { InventoryObjects &invObjects = _vm->_game->_objects; if (s.isLoading()) { _selectedInvIndex = invObjects._inventoryList.empty() ? -1 : 0; } for (int i = 0; i < 8; ++i) s.syncAsSint16LE(_categoryIndexes[i]); }
void SaveLoad::sync<ScriptRegister::Script>(Common::Serializer &serializer, ScriptRegister::Script &var) { if (serializer.isSaving()) if (var.chunk) var.line = var.chunk->getCurLine(); serializer.syncAsUint32LE(var.line); if (serializer.isLoading()) var.chunk = 0; }
static void syncCT(Common::Serializer &s) { int v = (_vm->_polyStruct) ? 1 : 0; s.syncAsSint32LE(v); if (s.isLoading()) _vm->_polyStruct = (v != 0) ? &_vm->_polyStructNorm : NULL; if (v == 0) // There is no further data to load or save return; s.syncAsSint16LE(numberOfWalkboxes); if (numberOfWalkboxes) { for (int i = 0; i < numberOfWalkboxes; ++i) s.syncAsSint16LE(walkboxColor[i]); for (int i = 0; i < numberOfWalkboxes; ++i) s.syncAsSint16LE(walkboxState[i]); } for (int i = 0; i < 10; i++) { v = 0; if (s.isSaving()) v = (persoTable[i]) ? 1 : 0; s.syncAsSint32LE(v); if (s.isLoading()) // Set up the pointer for the next structure persoTable[i] = (v == 0) ? NULL : (persoStruct *)mallocAndZero(sizeof(persoStruct)); if (v != 0) syncPerso(s, *persoTable[i]); } }
static bool syncSaveGameHeader(Common::Serializer &s, SaveGameHeader &hdr) { s.syncAsUint32LE(hdr.id); s.syncAsUint32LE(hdr.size); s.syncAsUint32LE(hdr.ver); s.syncBytes((byte *)hdr.desc, SG_DESC_LEN); hdr.desc[SG_DESC_LEN - 1] = 0; syncTime(s, hdr.dateTime); int tmp = hdr.size - s.bytesSynced(); // NOTE: We can't use SAVEGAME_ID here when attempting to remove a saved game from the launcher, // as there is no TinselEngine initialized then. This means that we can't check if this is a DW1 // or DW2 savegame in this case, but it doesn't really matter, as the saved game is about to be // deleted anyway. Refer to bug #3387551. bool correctID = _vm ? (hdr.id == SAVEGAME_ID) : (hdr.id == DW1_SAVEGAME_ID || hdr.id == DW2_SAVEGAME_ID); // Perform sanity check if (tmp < 0 || !correctID || hdr.ver > CURRENT_VER || hdr.size > 1024) return false; if (tmp > 0) { // If there's header space left, handling syncing the Scn flag and game language s.syncAsByte(hdr.scnFlag); s.syncAsByte(hdr.language); tmp -= 2; if (_vm && s.isLoading()) { // If the engine is loaded, ensure the Scn/Gra usage is correct, and it's the correct language if ((hdr.scnFlag != ((_vm->getFeatures() & GF_SCNFILES) != 0)) || (hdr.language != _vm->_config->_language)) return false; } } // Handle the number of interpreter contexts that will be saved in the savegame if (tmp >= 2) { tmp -= 2; hdr.numInterpreters = NUM_INTERPRET; s.syncAsUint16LE(hdr.numInterpreters); } else { hdr.numInterpreters = (TinselV2 ? 70 : 64) - 20; } // Skip over any extra bytes s.skip(tmp); return true; }
void ActionSavedFields::synchronize(Common::Serializer &s) { s.syncAsByte(_commandError); s.syncAsSint16LE(_commandSource); s.syncAsSint16LE(_command); s.syncAsSint16LE(_mainObject); s.syncAsSint16LE(_secondObject); s.syncAsSint16LE(_mainObjectSource); s.syncAsSint16LE(_secondObjectSource); s.syncAsSint16LE(_articleNumber); s.syncAsSint16LE(_lookFlag); }
static void syncSongs(Common::Serializer &s) { int size = 0; if (songLoaded) { // TODO: implement s.syncAsByte(size); if (s.isLoading()) { saveVar1 = size; if (saveVar1) s.syncBytes(saveVar2, saveVar1); } } else { s.syncAsByte(size); } }
void StopWalkers::synchronize(Common::Serializer &s) { StopWalkerEntry rec; int count = size(); s.syncAsUint16LE(count); if (s.isLoading()) { clear(); for (int idx = 0; idx < count; ++idx) { rec.synchronize(s); push(rec); } } else { for (int idx = 0; idx < count; ++idx) (*this)[idx].synchronize(s); } }
////////////////////////////////////////////////////////////////////////// // Savegame ////////////////////////////////////////////////////////////////////////// void SoundQueue::saveLoadWithSerializer(Common::Serializer &s) { Common::StackLock locker(_mutex); s.syncAsUint32LE(_state); s.syncAsUint32LE(_currentType); // Compute the number of entries to save uint32 numEntries = count(); s.syncAsUint32LE(numEntries); // Save or load each entry data if (s.isSaving()) { for (Common::List<SoundEntry *>::iterator i = _soundList.begin(); i != _soundList.end(); ++i) (*i)->saveLoadWithSerializer(s); } else { warning("[Sound::saveLoadWithSerializer] Loading not implemented"); s.skip(numEntries * 64); } }
void DynamicHotspots::synchronize(Common::Serializer &s) { int count = _entries.size(); s.syncAsSint16LE(count); // The MIN in the below loop is a workaround to fix earlier savegame // loading accidentally adding new dynamic hotspots to the fixed list for (int i = 0; i < count; ++i) { _entries[MIN(i, (int)_entries.size() - 1)].synchronize(s); } }
void Sprite::saveLoadWithSerializer(Common::Serializer &ser) { ser.syncAsSint16LE(pos.x); ser.syncAsSint16LE(pos.y); ser.syncAsUint16LE(drawPriority); ser.syncAsUint16LE(drawPriority2); ser.syncString(field8); // Note: bitmap must be reloaded ser.syncAsUint16LE(drawMode); ser.syncAsUint16LE(textColor); ser.syncAsUint16LE(bitmapChanged); ser.syncAsUint16LE(rect2Valid); ser.syncAsUint16LE(isOnScreen); ser.syncAsUint16LE(field16); serializeRect(lastDrawRect, ser); serializeRect(drawRect, ser); serializeRect(rectangle2, ser); ser.syncAsSint16LE(drawX); ser.syncAsSint16LE(drawY); }
bool BuriedEngine::syncLocation(Common::Serializer &s, Location &location) { s.syncAsSint16LE(location.timeZone); s.syncAsSint16LE(location.environment); s.syncAsSint16LE(location.node); s.syncAsSint16LE(location.facing); s.syncAsSint16LE(location.orientation); s.syncAsSint16LE(location.depth); return s.bytesSynced() == 12; }
void SavesManager::syncBitFlags(Common::Serializer &s, bool *startP, bool *endP) { byte data = 0; int bitCounter = 0; for (bool *p = startP; p <= endP; ++p, bitCounter = (bitCounter + 1) % 8) { if (p == endP || bitCounter == 0) { if (p != endP || s.isSaving()) s.syncAsByte(data); if (p == endP) break; if (s.isSaving()) data = 0; } if (s.isLoading()) *p = (data >> bitCounter) != 0; else if (*p) data |= 1 << bitCounter; }
bool SaveHeader::sync(Common::Serializer &sz) { const uint32 SAVE_MAGIC_NUMBER = MKTAG('M', 'O', 'J', 'B'); const uint32 SAVE_FILE_VERSION = 1; if (sz.isLoading()) { uint32 magic = 0; sz.syncAsUint32BE(magic); if (magic != SAVE_MAGIC_NUMBER) { warning("Invalid save"); return false; } } else { uint32 magic = SAVE_MAGIC_NUMBER; sz.syncAsUint32BE(magic); } sz.syncVersion(SAVE_FILE_VERSION); sz.syncString(_description); return true; }
void SaveLoadManager::syncSavegameData(Common::Serializer &s, int version) { // The brief version 3 had the highscores embedded. They're in a separate file now, so skip if (version == 3 && s.isLoading()) s.skip(100); s.syncBytes(&_vm->_globals->_saveData->_data[0], 2050); syncCharacterLocation(s, _vm->_globals->_saveData->_cloneHopkins); syncCharacterLocation(s, _vm->_globals->_saveData->_realHopkins); syncCharacterLocation(s, _vm->_globals->_saveData->_samantha); for (int i = 0; i < 35; ++i) s.syncAsSint16LE(_vm->_globals->_saveData->_inventory[i]); if (version > 1) { s.syncAsSint16LE(_vm->_globals->_saveData->_mapCarPosX); s.syncAsSint16LE(_vm->_globals->_saveData->_mapCarPosY); } else { _vm->_globals->_saveData->_mapCarPosX = _vm->_globals->_saveData->_mapCarPosY = 0; } }
static bool syncSaveGameHeader(Common::Serializer &s, SaveGameHeader &hdr) { s.syncAsUint32LE(hdr.id); s.syncAsUint32LE(hdr.size); s.syncAsUint32LE(hdr.ver); s.syncBytes((byte *)hdr.desc, SG_DESC_LEN); hdr.desc[SG_DESC_LEN - 1] = 0; syncTime(s, hdr.dateTime); int tmp = hdr.size - s.bytesSynced(); // NOTE: We can't use SAVEGAME_ID here when attempting to remove a saved game from the launcher, // as there is no TinselEngine initialized then. This means that we can't check if this is a DW1 // or DW2 savegame in this case, but it doesn't really matter, as the saved game is about to be // deleted anyway. Refer to bug #3387551. bool correctID = _vm ? (hdr.id == SAVEGAME_ID) : (hdr.id == DW1_SAVEGAME_ID || hdr.id == DW2_SAVEGAME_ID); // Perform sanity check if (tmp < 0 || !correctID || hdr.ver > CURRENT_VER || hdr.size > 1024) return false; // Skip over any extra bytes s.skip(tmp); return true; }
static bool DoSync(Common::Serializer &s, int numInterp) { int sg = 0; if (TinselV2) { if (s.isSaving()) g_restoreCD = GetCurrentCD(); s.syncAsSint16LE(g_restoreCD); } if (TinselV2 && s.isLoading()) HoldItem(INV_NOICON); syncSavedData(s, *g_srsd, numInterp); syncGlobInfo(s); // Glitter globals syncInvInfo(s); // Inventory data // Held object if (s.isSaving()) sg = WhichItemHeld(); s.syncAsSint32LE(sg); if (s.isLoading()) { if (sg != -1 && !GetIsInvObject(sg)) // Not a valid inventory object, so return false return false; if (TinselV2) g_thingHeld = sg; else HoldItem(sg); } syncTimerInfo(s); // Timer data if (!TinselV2) syncPolyInfo(s); // Dead polygon data syncSCdata(s); // Hook Scene and delayed scene s.syncAsSint32LE(*g_SaveSceneSsCount); if (*g_SaveSceneSsCount != 0) { SAVED_DATA *sdPtr = g_SaveSceneSsData; for (int i = 0; i < *g_SaveSceneSsCount; ++i, ++sdPtr) syncSavedData(s, *sdPtr, numInterp); // Flag that there is a saved scene to return to. Note that in this context 'saved scene' // is a stored scene to return to from another scene, such as from the Summoning Book close-up // in Discworld 1 to whatever scene Rincewind was in prior to that g_ASceneIsSaved = true; } if (!TinselV2) syncAllActorsAlive(s); return true; }
////////////////////////////////////////////////////////////////////////// // Savegame ////////////////////////////////////////////////////////////////////////// void SoundQueue::saveLoadWithSerializer(Common::Serializer &s) { s.syncAsUint32LE(_ambientState); s.syncAsUint32LE(_currentTag); // Save or load each entry data if (s.isSaving()) { // Compute the number of entries to save uint32 numEntries = count(); s.syncAsUint32LE(numEntries); for (Common::List<SoundEntry *>::iterator i = _soundList.begin(); i != _soundList.end(); ++i) if ((*i)->needSaving()) (*i)->saveLoadWithSerializer(s); } else { uint32 numEntries; s.syncAsUint32LE(numEntries); for (uint32 i = 0; i < numEntries; i++) { SoundEntry* entry = new SoundEntry(_engine); entry->saveLoadWithSerializer(s); addToQueue(entry); } } }
static void syncPreloadData(Common::Serializer &s) { uint8 dummyByte = 0; uint32 dummyLong = 0; for (int i = 0; i < 64; i++) { preloadStruct &pe = preloadData[i]; s.syncBytes((byte *)pe.name, 15); s.syncAsByte(dummyByte); s.syncAsUint32LE(pe.size); s.syncAsUint32LE(pe.sourceSize); s.syncAsUint32LE(dummyLong); s.syncAsUint16LE(pe.nofree); s.syncAsUint16LE(pe.protect); s.syncAsUint16LE(pe.ovl); } }
/** * (Un)serialize an interpreter context for save/restore game. */ void INT_CONTEXT::syncWithSerializer(Common::Serializer &s) { if (s.isLoading()) { // Null out the pointer fields pProc = NULL; code = NULL; pinvo = NULL; } // Write out used fields s.syncAsUint32LE(GSort); s.syncAsUint32LE(hCode); s.syncAsUint32LE(event); s.syncAsSint32LE(hPoly); s.syncAsSint32LE(idActor); for (int i = 0; i < PCODE_STACK_SIZE; ++i) s.syncAsSint32LE(stack[i]); s.syncAsSint32LE(sp); s.syncAsSint32LE(bp); s.syncAsSint32LE(ip); s.syncAsUint32LE(bHalt); s.syncAsUint32LE(escOn); s.syncAsSint32LE(myEscape); }
static void syncSavedActor(Common::Serializer &s, SAVED_ACTOR &sa) { s.syncAsUint16LE(sa.actorID); s.syncAsUint16LE(sa.zFactor); s.syncAsUint16LE(sa.bAlive); s.syncAsUint16LE(sa.bHidden); s.syncAsUint32LE(sa.presFilm); s.syncAsUint16LE(sa.presRnum); s.syncAsUint16LE(sa.presPlayX); s.syncAsUint16LE(sa.presPlayY); }
static void syncOverlays1(Common::Serializer &s) { uint8 dummyByte = 0; uint32 dummyLong = 0; for (int i = 0; i < numOfLoadedOverlay; i++) { overlayStruct &oe = overlayTable[i]; s.syncBytes((byte *)oe.overlayName, 13); s.syncAsByte(dummyByte); s.syncAsUint32LE(dummyLong); s.syncAsUint16LE(oe.alreadyLoaded); s.syncAsUint16LE(oe.state); s.syncAsUint32LE(dummyLong); s.syncAsUint32LE(dummyLong); s.syncAsUint32LE(dummyLong); s.syncAsUint32LE(dummyLong); s.syncAsUint16LE(oe.executeScripts); } }
static void syncPerso(Common::Serializer &s, persoStruct &p) { s.syncAsSint16LE(p.inc_droite); s.syncAsSint16LE(p.inc_droite0); s.syncAsSint16LE(p.inc_chemin); for (int i = 0; i < 400; ++i) { s.syncAsSint16LE(p.coordinates[i].x); s.syncAsSint16LE(p.coordinates[i].y); } for (int i = 0; i < NUM_NODES + 3; ++i) { s.syncAsSint16LE(p.solution[i][0]); s.syncAsSint16LE(p.solution[i][1]); } s.syncAsSint16LE(p.inc_jo1); s.syncAsSint16LE(p.inc_jo2); s.syncAsSint16LE(p.dir_perso); s.syncAsSint16LE(p.inc_jo0); }
static void syncSavedMover(Common::Serializer &s, SAVED_MOVER &sm) { SCNHANDLE *pList[3] = { (SCNHANDLE *)&sm.walkReels, (SCNHANDLE *)&sm.standReels, (SCNHANDLE *)&sm.talkReels }; s.syncAsUint32LE(sm.bActive); s.syncAsSint32LE(sm.actorID); s.syncAsSint32LE(sm.objX); s.syncAsSint32LE(sm.objY); s.syncAsUint32LE(sm.hLastfilm); for (int pIndex = 0; pIndex < 3; ++pIndex) { SCNHANDLE *p = pList[pIndex]; for (int i = 0; i < TOTAL_SCALES * 4; ++i) s.syncAsUint32LE(*p++); } if (TinselV2) { s.syncAsByte(sm.bHidden); s.syncAsSint32LE(sm.brightness); s.syncAsSint32LE(sm.startColour); s.syncAsSint32LE(sm.paletteLength); } }