2007-05-30 21:56:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
2007-04-27 12:58:35 +00:00
|
|
|
*
|
2007-05-30 21:56:52 +00:00
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
2007-04-27 12:58:35 +00:00
|
|
|
*
|
2021-12-26 18:47:58 +01:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
2014-02-18 02:34:18 +01:00
|
|
|
*
|
2007-04-27 12:58:35 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2014-02-18 02:34:18 +01:00
|
|
|
*
|
2007-04-27 12:58:35 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
2021-12-26 18:47:58 +01:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2007-04-27 12:58:35 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "cruise/cruise_main.h"
|
2009-04-01 10:43:24 +00:00
|
|
|
#include "cruise/cruise.h"
|
2009-06-10 12:15:50 +00:00
|
|
|
#include "cruise/vars.h"
|
2007-04-27 12:58:35 +00:00
|
|
|
|
2009-03-16 09:17:49 +00:00
|
|
|
#include "common/serializer.h"
|
2007-12-20 14:30:51 +00:00
|
|
|
#include "common/savefile.h"
|
|
|
|
#include "common/system.h"
|
2011-04-24 11:34:27 +03:00
|
|
|
#include "common/textconsole.h"
|
2007-12-20 14:30:51 +00:00
|
|
|
|
2009-04-18 10:16:08 +00:00
|
|
|
#include "graphics/scaler.h"
|
|
|
|
#include "graphics/thumbnail.h"
|
|
|
|
|
2007-04-27 12:58:35 +00:00
|
|
|
namespace Cruise {
|
|
|
|
|
2007-11-10 19:47:07 +00:00
|
|
|
struct overlayRestoreTemporary {
|
|
|
|
int _sBssSize;
|
|
|
|
uint8* _pBss;
|
|
|
|
int _sNumObj;
|
|
|
|
objectParams* _pObj;
|
|
|
|
};
|
|
|
|
|
|
|
|
overlayRestoreTemporary ovlRestoreData[90];
|
|
|
|
|
ALL: Load savegame thumbnail only when necessary
This commit introduces the following changes:
1. Graphics::loadThumbnail()
Now returns a boolean and takes a new argument skipThumbnail which
defaults to false. In case of true, loadThumbnail() reads past the
thumbnail data in the input stream instead of actually loading the
thumbnail. This simplifies savegame handling where, up until now,
many engines always read the whole savegame metadata (including
the thumbnail) and then threw away the thumbnail when not needed
(which is in almost all cases, the most common exception being
MetaEngine::querySaveMetaInfos() which is responsible for loading
savegame metadata for displaying it in the GUI launcher.
2. readSavegameHeader()
Engines which already implement such a method (name varies) now take
a new argument skipThumbnail (default: true) which is passed
through to loadThumbnail(). This means that the default case for
readSavegameHeader() is now _not_ loading the thumbnail from a
savegame and just reading past it. In those cases, e.g.
querySaveMetaInfos(), where we actually are interested in loading
the thumbnail readSavegameHeader() needs to explicitely be called
with skipThumbnail == false.
Engines whose readSavegameHeader() (name varies) already takes an
argument loadThumbnail have been adapted to have a similar
prototype and semantics.
I.e. readSaveHeader(in, loadThumbnail, header) now is
readSaveHeader(in, header, skipThumbnail).
3. Error handling
Engines which previously did not check the return value of
readSavegameHeader() (name varies) now do so ensuring that possibly
broken savegames (be it a broken thumbnail or something else) don't
make it into the GUI launcher list in the first place.
2018-04-06 00:06:38 +02:00
|
|
|
WARN_UNUSED_RESULT bool readSavegameHeader(Common::InSaveFile *in, CruiseSavegameHeader &header, bool skipThumbnail) {
|
2009-04-18 10:16:08 +00:00
|
|
|
char saveIdentBuffer[6];
|
|
|
|
|
|
|
|
// Validate the header Id
|
|
|
|
in->read(saveIdentBuffer, 6);
|
|
|
|
if (strcmp(saveIdentBuffer, "SVMCR"))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
header.version = in->readByte();
|
|
|
|
if (header.version != CRUISE_SAVEGAME_VERSION)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Read in the string
|
|
|
|
header.saveName.clear();
|
|
|
|
char ch;
|
|
|
|
while ((ch = (char)in->readByte()) != '\0') header.saveName += ch;
|
|
|
|
|
|
|
|
// Get the thumbnail
|
2018-07-31 09:22:26 +01:00
|
|
|
header.thumbnail = nullptr;
|
ALL: Load savegame thumbnail only when necessary
This commit introduces the following changes:
1. Graphics::loadThumbnail()
Now returns a boolean and takes a new argument skipThumbnail which
defaults to false. In case of true, loadThumbnail() reads past the
thumbnail data in the input stream instead of actually loading the
thumbnail. This simplifies savegame handling where, up until now,
many engines always read the whole savegame metadata (including
the thumbnail) and then threw away the thumbnail when not needed
(which is in almost all cases, the most common exception being
MetaEngine::querySaveMetaInfos() which is responsible for loading
savegame metadata for displaying it in the GUI launcher.
2. readSavegameHeader()
Engines which already implement such a method (name varies) now take
a new argument skipThumbnail (default: true) which is passed
through to loadThumbnail(). This means that the default case for
readSavegameHeader() is now _not_ loading the thumbnail from a
savegame and just reading past it. In those cases, e.g.
querySaveMetaInfos(), where we actually are interested in loading
the thumbnail readSavegameHeader() needs to explicitely be called
with skipThumbnail == false.
Engines whose readSavegameHeader() (name varies) already takes an
argument loadThumbnail have been adapted to have a similar
prototype and semantics.
I.e. readSaveHeader(in, loadThumbnail, header) now is
readSaveHeader(in, header, skipThumbnail).
3. Error handling
Engines which previously did not check the return value of
readSavegameHeader() (name varies) now do so ensuring that possibly
broken savegames (be it a broken thumbnail or something else) don't
make it into the GUI launcher list in the first place.
2018-04-06 00:06:38 +02:00
|
|
|
if (!Graphics::loadThumbnail(*in, header.thumbnail, skipThumbnail)) {
|
2009-04-18 10:16:08 +00:00
|
|
|
return false;
|
ALL: Load savegame thumbnail only when necessary
This commit introduces the following changes:
1. Graphics::loadThumbnail()
Now returns a boolean and takes a new argument skipThumbnail which
defaults to false. In case of true, loadThumbnail() reads past the
thumbnail data in the input stream instead of actually loading the
thumbnail. This simplifies savegame handling where, up until now,
many engines always read the whole savegame metadata (including
the thumbnail) and then threw away the thumbnail when not needed
(which is in almost all cases, the most common exception being
MetaEngine::querySaveMetaInfos() which is responsible for loading
savegame metadata for displaying it in the GUI launcher.
2. readSavegameHeader()
Engines which already implement such a method (name varies) now take
a new argument skipThumbnail (default: true) which is passed
through to loadThumbnail(). This means that the default case for
readSavegameHeader() is now _not_ loading the thumbnail from a
savegame and just reading past it. In those cases, e.g.
querySaveMetaInfos(), where we actually are interested in loading
the thumbnail readSavegameHeader() needs to explicitely be called
with skipThumbnail == false.
Engines whose readSavegameHeader() (name varies) already takes an
argument loadThumbnail have been adapted to have a similar
prototype and semantics.
I.e. readSaveHeader(in, loadThumbnail, header) now is
readSaveHeader(in, header, skipThumbnail).
3. Error handling
Engines which previously did not check the return value of
readSavegameHeader() (name varies) now do so ensuring that possibly
broken savegames (be it a broken thumbnail or something else) don't
make it into the GUI launcher list in the first place.
2018-04-06 00:06:38 +02:00
|
|
|
}
|
2009-04-18 10:16:08 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void writeSavegameHeader(Common::OutSaveFile *out, CruiseSavegameHeader &header) {
|
|
|
|
// Write out a savegame header
|
|
|
|
char saveIdentBuffer[6];
|
2022-09-24 12:31:08 +02:00
|
|
|
Common::strcpy_s(saveIdentBuffer, "SVMCR");
|
2009-04-18 10:16:08 +00:00
|
|
|
out->write(saveIdentBuffer, 6);
|
|
|
|
|
|
|
|
out->writeByte(CRUISE_SAVEGAME_VERSION);
|
|
|
|
|
|
|
|
// Write savegame name
|
|
|
|
out->write(header.saveName.c_str(), header.saveName.size() + 1);
|
|
|
|
|
|
|
|
// Create a thumbnail and save it
|
|
|
|
Graphics::Surface *thumb = new Graphics::Surface();
|
|
|
|
::createThumbnail(thumb, globalScreen, 320, 200, workpal);
|
|
|
|
Graphics::saveThumbnail(*out, *thumb);
|
2011-11-21 19:38:52 +11:00
|
|
|
thumb->free();
|
2009-04-18 10:16:08 +00:00
|
|
|
delete thumb;
|
|
|
|
}
|
|
|
|
|
2009-03-16 09:17:49 +00:00
|
|
|
static void syncPalette(Common::Serializer &s, uint8 *p) {
|
2009-02-09 11:30:18 +00:00
|
|
|
// This is different from the original, where palette entries are 2 bytes each
|
|
|
|
s.syncBytes(p, NBCOLORS * 3);
|
|
|
|
}
|
|
|
|
|
2009-03-16 09:17:49 +00:00
|
|
|
static void syncBasicInfo(Common::Serializer &s) {
|
2009-02-09 11:30:18 +00:00
|
|
|
s.syncAsSint16LE(activeMouse);
|
|
|
|
s.syncAsSint16LE(userEnabled);
|
|
|
|
s.syncAsSint16LE(dialogueEnabled);
|
|
|
|
s.syncAsSint16LE(dialogueOvl);
|
|
|
|
s.syncAsSint16LE(dialogueObj);
|
|
|
|
s.syncAsSint16LE(userDelay);
|
|
|
|
s.syncAsSint16LE(sysKey);
|
|
|
|
s.syncAsSint16LE(sysX);
|
|
|
|
s.syncAsSint16LE(sysY);
|
|
|
|
s.syncAsSint16LE(automoveInc);
|
|
|
|
s.syncAsSint16LE(automoveMax);
|
|
|
|
s.syncAsSint16LE(displayOn);
|
|
|
|
s.syncAsSint16LE(isMessage);
|
|
|
|
s.syncAsSint16LE(fadeFlag);
|
|
|
|
s.syncAsSint16LE(automaticMode);
|
|
|
|
s.syncAsSint16LE(titleColor);
|
|
|
|
s.syncAsSint16LE(itemColor);
|
|
|
|
s.syncAsSint16LE(selectColor);
|
|
|
|
s.syncAsSint16LE(subColor);
|
|
|
|
s.syncAsSint16LE(narratorOvl);
|
|
|
|
s.syncAsSint16LE(narratorIdx);
|
|
|
|
s.syncAsSint16LE(aniX);
|
|
|
|
s.syncAsSint16LE(aniY);
|
2009-03-24 11:30:37 +00:00
|
|
|
s.syncAsUint16LE(animationStart);
|
2009-02-09 11:30:18 +00:00
|
|
|
s.syncAsSint16LE(masterScreen);
|
|
|
|
s.syncAsSint16LE(switchPal);
|
|
|
|
s.syncAsSint16LE(scroll);
|
|
|
|
s.syncAsSint16LE(fadeFlag);
|
|
|
|
s.syncAsSint16LE(doFade);
|
|
|
|
s.syncAsSint16LE(numOfLoadedOverlay);
|
|
|
|
s.syncAsSint16LE(stateID);
|
|
|
|
s.syncAsSint16LE(fontFileIndex);
|
|
|
|
s.syncAsSint16LE(currentActiveMenu);
|
|
|
|
s.syncAsSint16LE(userWait);
|
|
|
|
s.syncAsSint16LE(autoOvl);
|
|
|
|
s.syncAsSint16LE(autoMsg);
|
|
|
|
s.syncAsSint16LE(autoTrack);
|
|
|
|
s.syncAsSint16LE(var39);
|
|
|
|
s.syncAsSint16LE(var42);
|
|
|
|
s.syncAsSint16LE(var45);
|
|
|
|
s.syncAsSint16LE(var46);
|
|
|
|
s.syncAsSint16LE(var47);
|
|
|
|
s.syncAsSint16LE(var48);
|
|
|
|
s.syncAsSint16LE(flagCt);
|
|
|
|
s.syncAsSint16LE(var41);
|
2009-04-18 10:16:08 +00:00
|
|
|
s.syncAsSint16LE(playerMenuEnabled);
|
2009-06-10 12:15:50 +00:00
|
|
|
s.syncAsSint16LE(protectionCode);
|
2009-02-09 11:30:18 +00:00
|
|
|
}
|
|
|
|
|
2009-03-16 09:17:49 +00:00
|
|
|
static void syncBackgroundTable(Common::Serializer &s) {
|
2009-02-09 11:30:18 +00:00
|
|
|
// restore backgroundTable
|
|
|
|
for (int i = 0; i < 8; i++) {
|
2010-02-20 10:37:08 +00:00
|
|
|
if (s.isSaving() && (strlen(backgroundTable[i].name) > 8))
|
|
|
|
warning("Saving a background resource that has too long a name");
|
|
|
|
|
2009-05-19 11:23:13 +00:00
|
|
|
s.syncBytes((byte *)backgroundTable[i].name, 9);
|
|
|
|
s.syncBytes((byte *)backgroundTable[i].extention, 6);
|
2009-02-09 11:30:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-16 09:17:49 +00:00
|
|
|
static void syncPalScreen(Common::Serializer &s) {
|
2009-02-09 11:30:18 +00:00
|
|
|
for (int i = 0; i < NBSCREENS; ++i) {
|
|
|
|
for (int j = 0; j < NBCOLORS; ++j)
|
|
|
|
s.syncAsUint16LE(palScreen[i][j]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-16 09:17:49 +00:00
|
|
|
static void syncSoundList(Common::Serializer &s) {
|
2009-02-09 11:30:18 +00:00
|
|
|
for (int i = 0; i < 4; ++i) {
|
|
|
|
SoundEntry &se = soundList[i];
|
|
|
|
s.syncAsSint16LE(se.frameNum);
|
|
|
|
s.syncAsUint16LE(se.frequency);
|
|
|
|
s.syncAsSint16LE(se.volume);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-16 09:17:49 +00:00
|
|
|
static void syncFilesDatabase(Common::Serializer &s) {
|
2009-02-09 11:30:18 +00:00
|
|
|
uint8 dummyVal = 0;
|
2009-03-24 11:30:37 +00:00
|
|
|
uint32 tmp;
|
2009-02-09 11:30:18 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < NUM_FILE_ENTRIES; i++) {
|
|
|
|
dataFileEntry &fe = filesDatabase[i];
|
|
|
|
|
|
|
|
s.syncAsUint16LE(fe.widthInColumn);
|
|
|
|
s.syncAsUint16LE(fe.width);
|
|
|
|
s.syncAsUint16LE(fe.resType);
|
|
|
|
s.syncAsUint16LE(fe.height);
|
2009-05-24 15:17:42 +00:00
|
|
|
|
2013-12-10 18:34:48 +01:00
|
|
|
// Remember whether this file database was open or not.
|
|
|
|
// Upon loading, loadSavegameData uses this information
|
|
|
|
// in order to re-open the file databases accordingly.
|
2009-03-24 11:30:37 +00:00
|
|
|
tmp = (fe.subData.ptr) ? 1 : 0;
|
|
|
|
s.syncAsUint32LE(tmp);
|
2009-02-09 11:30:18 +00:00
|
|
|
if (s.isLoading()) {
|
2021-11-13 23:40:20 +02:00
|
|
|
fe.subData.ptr = tmp ? (uint8 *)1 : nullptr;
|
2009-02-09 11:30:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
s.syncAsSint16LE(fe.subData.index);
|
2009-05-19 11:23:13 +00:00
|
|
|
s.syncBytes((byte *)fe.subData.name, 13);
|
2009-02-09 11:30:18 +00:00
|
|
|
s.syncAsByte(dummyVal);
|
|
|
|
|
|
|
|
s.syncAsSint16LE(fe.subData.transparency);
|
|
|
|
|
2013-12-10 18:34:48 +01:00
|
|
|
// Treat fe.subData.ptrMask the same as fe.subData.ptr.
|
2009-03-24 11:30:37 +00:00
|
|
|
tmp = (fe.subData.ptrMask) ? 1 : 0;
|
|
|
|
s.syncAsUint32LE(tmp);
|
2009-02-09 11:30:18 +00:00
|
|
|
if (s.isLoading()) {
|
2021-11-13 23:40:20 +02:00
|
|
|
fe.subData.ptrMask = tmp ? (uint8 *)1 : nullptr;
|
2009-02-09 11:30:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
s.syncAsUint16LE(fe.subData.resourceType);
|
|
|
|
s.syncAsSint16LE(fe.subData.compression);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-16 09:17:49 +00:00
|
|
|
static void syncPreloadData(Common::Serializer &s) {
|
2009-02-09 11:30:18 +00:00
|
|
|
uint8 dummyByte = 0;
|
|
|
|
uint32 dummyLong = 0;
|
|
|
|
|
|
|
|
for (int i = 0; i < 64; i++) {
|
|
|
|
preloadStruct &pe = preloadData[i];
|
|
|
|
|
2009-05-19 11:23:13 +00:00
|
|
|
s.syncBytes((byte *)pe.name, 15);
|
2009-02-09 11:30:18 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-16 09:17:49 +00:00
|
|
|
static void syncOverlays1(Common::Serializer &s) {
|
2009-02-09 11:30:18 +00:00
|
|
|
uint8 dummyByte = 0;
|
|
|
|
uint32 dummyLong = 0;
|
|
|
|
|
|
|
|
for (int i = 0; i < numOfLoadedOverlay; i++) {
|
|
|
|
overlayStruct &oe = overlayTable[i];
|
|
|
|
|
2009-05-19 11:23:13 +00:00
|
|
|
s.syncBytes((byte *)oe.overlayName, 13);
|
2009-02-09 11:30:18 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-16 09:17:49 +00:00
|
|
|
static void syncOverlays2(Common::Serializer &s) {
|
2009-02-09 11:30:18 +00:00
|
|
|
|
|
|
|
for (int i = 1; i < numOfLoadedOverlay; i++) {
|
|
|
|
|
|
|
|
if (s.isSaving()) {
|
|
|
|
// Saving code
|
|
|
|
if (!overlayTable[i].alreadyLoaded)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
ovlDataStruct *ovlData = overlayTable[i].ovlData;
|
|
|
|
|
|
|
|
// save BSS
|
|
|
|
s.syncAsSint16LE(ovlData->sizeOfData4);
|
|
|
|
if (ovlData->sizeOfData4)
|
|
|
|
s.syncBytes(ovlData->data4Ptr, ovlData->sizeOfData4);
|
|
|
|
|
|
|
|
// save variables
|
|
|
|
s.syncAsSint16LE(ovlData->size9);
|
|
|
|
for (int j = 0; j < ovlData->size9; j++) {
|
|
|
|
s.syncAsSint16LE(ovlData->arrayObjVar[j].X);
|
|
|
|
s.syncAsSint16LE(ovlData->arrayObjVar[j].Y);
|
|
|
|
s.syncAsSint16LE(ovlData->arrayObjVar[j].Z);
|
|
|
|
s.syncAsSint16LE(ovlData->arrayObjVar[j].frame);
|
|
|
|
s.syncAsSint16LE(ovlData->arrayObjVar[j].scale);
|
|
|
|
s.syncAsSint16LE(ovlData->arrayObjVar[j].state);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Loading code
|
|
|
|
ovlRestoreData[i]._sBssSize = ovlRestoreData[i]._sNumObj = 0;
|
2021-11-13 23:40:20 +02:00
|
|
|
ovlRestoreData[i]._pBss = nullptr;
|
|
|
|
ovlRestoreData[i]._pObj = nullptr;
|
2009-02-09 11:30:18 +00:00
|
|
|
|
|
|
|
if (overlayTable[i].alreadyLoaded) {
|
|
|
|
s.syncAsSint16LE(ovlRestoreData[i]._sBssSize);
|
|
|
|
|
|
|
|
if (ovlRestoreData[i]._sBssSize) {
|
|
|
|
ovlRestoreData[i]._pBss = (uint8 *) mallocAndZero(ovlRestoreData[i]._sBssSize);
|
2014-06-08 17:55:05 +02:00
|
|
|
assert(ovlRestoreData[i]._pBss);
|
2009-02-09 11:30:18 +00:00
|
|
|
|
|
|
|
s.syncBytes(ovlRestoreData[i]._pBss, ovlRestoreData[i]._sBssSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
s.syncAsSint16LE(ovlRestoreData[i]._sNumObj);
|
|
|
|
|
|
|
|
if (ovlRestoreData[i]._sNumObj) {
|
|
|
|
ovlRestoreData[i]._pObj = (objectParams *) mallocAndZero(ovlRestoreData[i]._sNumObj * sizeof(objectParams));
|
2014-06-08 17:55:05 +02:00
|
|
|
assert(ovlRestoreData[i]._pObj);
|
2009-02-09 11:30:18 +00:00
|
|
|
|
|
|
|
for (int j = 0; j < ovlRestoreData[i]._sNumObj; j++) {
|
|
|
|
s.syncAsSint16LE(ovlRestoreData[i]._pObj[j].X);
|
|
|
|
s.syncAsSint16LE(ovlRestoreData[i]._pObj[j].Y);
|
|
|
|
s.syncAsSint16LE(ovlRestoreData[i]._pObj[j].Z);
|
|
|
|
s.syncAsSint16LE(ovlRestoreData[i]._pObj[j].frame);
|
|
|
|
s.syncAsSint16LE(ovlRestoreData[i]._pObj[j].scale);
|
|
|
|
s.syncAsSint16LE(ovlRestoreData[i]._pObj[j].state);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-16 09:17:49 +00:00
|
|
|
void syncScript(Common::Serializer &s, scriptInstanceStruct *entry) {
|
2009-02-09 11:30:18 +00:00
|
|
|
int numScripts = 0;
|
|
|
|
uint32 dummyLong = 0;
|
|
|
|
uint16 dummyWord = 0;
|
|
|
|
|
|
|
|
if (s.isSaving()) {
|
|
|
|
// Figure out the number of scripts to save
|
|
|
|
scriptInstanceStruct* pCurrent = entry->nextScriptPtr;
|
|
|
|
while (pCurrent) {
|
|
|
|
++numScripts;
|
|
|
|
pCurrent = pCurrent->nextScriptPtr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s.syncAsSint16LE(numScripts);
|
|
|
|
|
|
|
|
scriptInstanceStruct *ptr = entry->nextScriptPtr;
|
|
|
|
for (int i = 0; i < numScripts; ++i) {
|
|
|
|
if (s.isLoading())
|
|
|
|
ptr = (scriptInstanceStruct *)mallocAndZero(sizeof(scriptInstanceStruct));
|
|
|
|
|
|
|
|
s.syncAsUint16LE(dummyWord);
|
|
|
|
s.syncAsSint16LE(ptr->ccr);
|
2009-05-17 06:59:19 +00:00
|
|
|
s.syncAsSint16LE(ptr->scriptOffset);
|
2009-02-09 11:30:18 +00:00
|
|
|
s.syncAsUint32LE(dummyLong);
|
2009-10-09 10:32:33 +00:00
|
|
|
s.syncAsSint16LE(ptr->dataSize);
|
2009-02-09 11:30:18 +00:00
|
|
|
s.syncAsSint16LE(ptr->scriptNumber);
|
|
|
|
s.syncAsSint16LE(ptr->overlayNumber);
|
|
|
|
s.syncAsSint16LE(ptr->sysKey);
|
|
|
|
s.syncAsSint16LE(ptr->freeze);
|
|
|
|
s.syncAsSint16LE(ptr->type);
|
|
|
|
s.syncAsSint16LE(ptr->var16);
|
|
|
|
s.syncAsSint16LE(ptr->var18);
|
|
|
|
s.syncAsSint16LE(ptr->var1A);
|
|
|
|
|
2009-10-09 10:32:33 +00:00
|
|
|
s.syncAsSint16LE(ptr->dataSize);
|
2009-02-09 11:30:18 +00:00
|
|
|
|
2009-10-09 10:32:33 +00:00
|
|
|
if (ptr->dataSize) {
|
2009-02-09 11:30:18 +00:00
|
|
|
if (s.isLoading())
|
2009-10-09 10:32:33 +00:00
|
|
|
ptr->data = (byte *)mallocAndZero(ptr->dataSize);
|
|
|
|
s.syncBytes(ptr->data, ptr->dataSize);
|
2009-02-09 11:30:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (s.isLoading()) {
|
2021-11-13 23:40:20 +02:00
|
|
|
ptr->nextScriptPtr = nullptr;
|
2009-02-09 11:30:18 +00:00
|
|
|
entry->nextScriptPtr = ptr;
|
|
|
|
entry = ptr;
|
|
|
|
} else {
|
|
|
|
ptr = ptr->nextScriptPtr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-16 09:17:49 +00:00
|
|
|
static void syncCell(Common::Serializer &s) {
|
2009-02-09 11:30:18 +00:00
|
|
|
int chunkCount = 0;
|
|
|
|
cellStruct *t, *p;
|
|
|
|
uint16 dummyWord = 0;
|
|
|
|
|
|
|
|
if (s.isSaving()) {
|
|
|
|
// Figure out the number of chunks to save
|
|
|
|
t = cellHead.next;
|
|
|
|
while (t) {
|
|
|
|
++chunkCount;
|
|
|
|
t = t->next;
|
|
|
|
}
|
|
|
|
} else {
|
2021-11-13 23:40:20 +02:00
|
|
|
cellHead.next = nullptr; // Not in ASM code, but I guess the variable is defaulted in the EXE
|
2009-02-09 11:30:18 +00:00
|
|
|
}
|
|
|
|
s.syncAsSint16LE(chunkCount);
|
|
|
|
|
|
|
|
t = s.isSaving() ? cellHead.next : &cellHead;
|
|
|
|
for (int i = 0; i < chunkCount; ++i) {
|
|
|
|
p = s.isSaving() ? t : (cellStruct *)mallocAndZero(sizeof(cellStruct));
|
|
|
|
|
|
|
|
s.syncAsUint16LE(dummyWord);
|
|
|
|
s.syncAsUint16LE(dummyWord);
|
|
|
|
|
|
|
|
s.syncAsSint16LE(p->idx);
|
|
|
|
s.syncAsSint16LE(p->type);
|
|
|
|
s.syncAsSint16LE(p->overlay);
|
|
|
|
s.syncAsSint16LE(p->x);
|
|
|
|
s.syncAsSint16LE(p->field_C);
|
|
|
|
s.syncAsSint16LE(p->spriteIdx);
|
|
|
|
s.syncAsSint16LE(p->color);
|
|
|
|
s.syncAsSint16LE(p->backgroundPlane);
|
|
|
|
s.syncAsSint16LE(p->freeze);
|
|
|
|
s.syncAsSint16LE(p->parent);
|
|
|
|
s.syncAsSint16LE(p->parentOverlay);
|
|
|
|
s.syncAsSint16LE(p->parentType);
|
|
|
|
s.syncAsSint16LE(p->followObjectOverlayIdx);
|
|
|
|
s.syncAsSint16LE(p->followObjectIdx);
|
|
|
|
s.syncAsSint16LE(p->animStart);
|
|
|
|
s.syncAsSint16LE(p->animEnd);
|
|
|
|
s.syncAsSint16LE(p->animWait);
|
|
|
|
s.syncAsSint16LE(p->animStep);
|
|
|
|
s.syncAsSint16LE(p->animChange);
|
|
|
|
s.syncAsSint16LE(p->animType);
|
|
|
|
s.syncAsSint16LE(p->animSignal);
|
|
|
|
s.syncAsSint16LE(p->animCounter);
|
|
|
|
s.syncAsSint16LE(p->animLoop);
|
|
|
|
s.syncAsUint16LE(dummyWord);
|
|
|
|
|
|
|
|
if (s.isSaving())
|
|
|
|
t = t->next;
|
|
|
|
else {
|
2021-11-13 23:40:20 +02:00
|
|
|
p->next = nullptr;
|
2009-02-09 11:30:18 +00:00
|
|
|
t->next = p;
|
|
|
|
p->prev = cellHead.prev;
|
|
|
|
cellHead.prev = p;
|
|
|
|
t = p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-16 09:17:49 +00:00
|
|
|
static void syncIncrust(Common::Serializer &s) {
|
2009-02-09 11:30:18 +00:00
|
|
|
int numEntries = 0;
|
|
|
|
backgroundIncrustStruct *pl, *pl1;
|
|
|
|
uint8 dummyByte = 0;
|
|
|
|
uint16 dummyWord = 0;
|
|
|
|
uint32 dummyLong = 0;
|
|
|
|
|
|
|
|
if (s.isSaving()) {
|
|
|
|
// Figure out the number of entries to save
|
|
|
|
pl = backgroundIncrustHead.next;
|
|
|
|
while (pl) {
|
|
|
|
++numEntries;
|
|
|
|
pl = pl->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s.syncAsSint16LE(numEntries);
|
|
|
|
|
|
|
|
pl = s.isSaving() ? backgroundIncrustHead.next : &backgroundIncrustHead;
|
|
|
|
pl1 = &backgroundIncrustHead;
|
|
|
|
|
|
|
|
for (int i = 0; i < numEntries; ++i) {
|
|
|
|
backgroundIncrustStruct *t = s.isSaving() ? pl :
|
|
|
|
(backgroundIncrustStruct *)mallocAndZero(sizeof(backgroundIncrustStruct));
|
|
|
|
|
|
|
|
s.syncAsUint32LE(dummyLong);
|
|
|
|
|
|
|
|
s.syncAsSint16LE(t->objectIdx);
|
|
|
|
s.syncAsSint16LE(t->type);
|
|
|
|
s.syncAsSint16LE(t->overlayIdx);
|
|
|
|
s.syncAsSint16LE(t->X);
|
|
|
|
s.syncAsSint16LE(t->Y);
|
2009-05-16 04:03:37 +00:00
|
|
|
s.syncAsSint16LE(t->frame);
|
2009-02-09 11:30:18 +00:00
|
|
|
s.syncAsSint16LE(t->scale);
|
|
|
|
s.syncAsSint16LE(t->backgroundIdx);
|
|
|
|
s.syncAsSint16LE(t->scriptNumber);
|
|
|
|
s.syncAsSint16LE(t->scriptOverlayIdx);
|
|
|
|
s.syncAsUint32LE(dummyLong);
|
2009-05-15 07:03:56 +00:00
|
|
|
s.syncAsSint16LE(t->saveWidth);
|
2009-02-09 11:30:18 +00:00
|
|
|
s.syncAsSint16LE(t->saveHeight);
|
|
|
|
s.syncAsSint16LE(t->saveSize);
|
|
|
|
s.syncAsSint16LE(t->savedX);
|
|
|
|
s.syncAsSint16LE(t->savedY);
|
2009-05-19 11:23:13 +00:00
|
|
|
s.syncBytes((byte *)t->name, 13);
|
2009-02-09 11:30:18 +00:00
|
|
|
s.syncAsByte(dummyByte);
|
|
|
|
s.syncAsSint16LE(t->spriteId);
|
|
|
|
s.syncAsUint16LE(dummyWord);
|
|
|
|
|
|
|
|
if (t->saveSize) {
|
2009-05-15 06:46:56 +00:00
|
|
|
if (s.isLoading())
|
2009-10-09 08:15:30 +00:00
|
|
|
t->ptr = (byte *)MemAlloc(t->saveSize);
|
2009-05-15 06:46:56 +00:00
|
|
|
|
|
|
|
s.syncBytes(t->ptr, t->saveSize);
|
2009-02-09 11:30:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (s.isSaving())
|
|
|
|
pl = pl->next;
|
|
|
|
else {
|
2021-11-13 23:40:20 +02:00
|
|
|
t->next = nullptr;
|
2009-02-09 11:30:18 +00:00
|
|
|
pl->next = t;
|
|
|
|
t->prev = pl1->prev;
|
|
|
|
pl1->prev = t;
|
|
|
|
pl = t;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-16 09:17:49 +00:00
|
|
|
static void syncActors(Common::Serializer &s) {
|
2009-02-09 11:30:18 +00:00
|
|
|
int numEntries = 0;
|
|
|
|
actorStruct *ptr;
|
|
|
|
uint16 dummyLong = 0;
|
|
|
|
|
|
|
|
if (s.isSaving()) {
|
|
|
|
ptr = actorHead.next;
|
|
|
|
while (ptr) {
|
|
|
|
++numEntries;
|
|
|
|
ptr = ptr->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s.syncAsSint16LE(numEntries);
|
|
|
|
|
|
|
|
ptr = s.isSaving() ? actorHead.next : &actorHead;
|
|
|
|
for (int i = 0; i < numEntries; ++i) {
|
|
|
|
actorStruct *p = s.isSaving() ? ptr : (actorStruct *)mallocAndZero(sizeof(actorStruct));
|
|
|
|
|
|
|
|
s.syncAsUint32LE(dummyLong);
|
|
|
|
s.syncAsSint16LE(p->idx);
|
|
|
|
s.syncAsSint16LE(p->type);
|
|
|
|
s.syncAsSint16LE(p->overlayNumber);
|
|
|
|
s.syncAsSint16LE(p->x_dest);
|
|
|
|
s.syncAsSint16LE(p->y_dest);
|
|
|
|
s.syncAsSint16LE(p->x);
|
|
|
|
s.syncAsSint16LE(p->y);
|
|
|
|
s.syncAsSint16LE(p->startDirection);
|
|
|
|
s.syncAsSint16LE(p->nextDirection);
|
|
|
|
s.syncAsSint16LE(p->endDirection);
|
|
|
|
s.syncAsSint16LE(p->stepX);
|
|
|
|
s.syncAsSint16LE(p->stepY);
|
|
|
|
s.syncAsSint16LE(p->pathId);
|
|
|
|
s.syncAsSint16LE(p->phase);
|
|
|
|
s.syncAsSint16LE(p->counter);
|
|
|
|
s.syncAsSint16LE(p->poly);
|
|
|
|
s.syncAsSint16LE(p->flag);
|
|
|
|
s.syncAsSint16LE(p->start);
|
|
|
|
s.syncAsSint16LE(p->freeze);
|
|
|
|
|
|
|
|
if (s.isSaving())
|
|
|
|
ptr = ptr->next;
|
|
|
|
else {
|
2021-11-13 23:40:20 +02:00
|
|
|
p->next = nullptr;
|
2009-02-09 11:30:18 +00:00
|
|
|
ptr->next = p;
|
|
|
|
p->prev = actorHead.prev;
|
|
|
|
actorHead.prev = p;
|
|
|
|
ptr = p->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-16 09:17:49 +00:00
|
|
|
static void syncSongs(Common::Serializer &s) {
|
2009-02-09 11:30:18 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-01 03:27:54 +00:00
|
|
|
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]);
|
|
|
|
}
|
2010-01-25 01:39:44 +00:00
|
|
|
|
2009-06-01 03:27:54 +00:00
|
|
|
s.syncAsSint16LE(p.inc_jo1);
|
|
|
|
s.syncAsSint16LE(p.inc_jo2);
|
|
|
|
s.syncAsSint16LE(p.dir_perso);
|
|
|
|
s.syncAsSint16LE(p.inc_jo0);
|
|
|
|
}
|
|
|
|
|
2009-03-16 09:17:49 +00:00
|
|
|
static void syncCT(Common::Serializer &s) {
|
2010-08-09 10:30:40 +00:00
|
|
|
int v = (_vm->_polyStruct) ? 1 : 0;
|
2009-02-09 11:30:18 +00:00
|
|
|
s.syncAsSint32LE(v);
|
2009-05-28 08:49:56 +00:00
|
|
|
if (s.isLoading())
|
2021-11-13 23:40:20 +02:00
|
|
|
_vm->_polyStruct = (v != 0) ? &_vm->_polyStructNorm : nullptr;
|
2009-02-09 11:30:18 +00:00
|
|
|
|
|
|
|
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
|
2021-11-13 23:40:20 +02:00
|
|
|
persoTable[i] = (v == 0) ? nullptr : (persoStruct *)mallocAndZero(sizeof(persoStruct));
|
2009-02-09 11:30:18 +00:00
|
|
|
|
2009-06-01 03:27:54 +00:00
|
|
|
if (v != 0)
|
|
|
|
syncPerso(s, *persoTable[i]);
|
2009-02-09 11:30:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-16 09:17:49 +00:00
|
|
|
static void DoSync(Common::Serializer &s) {
|
2009-02-09 11:30:18 +00:00
|
|
|
syncBasicInfo(s);
|
2009-06-14 03:39:30 +00:00
|
|
|
_vm->sound().doSync(s);
|
2009-02-09 11:30:18 +00:00
|
|
|
|
|
|
|
syncPalette(s, newPal);
|
|
|
|
syncPalette(s, workpal);
|
|
|
|
|
2009-05-19 11:23:13 +00:00
|
|
|
s.syncBytes((byte *)currentCtpName, 40);
|
2009-02-09 11:30:18 +00:00
|
|
|
|
|
|
|
syncBackgroundTable(s);
|
|
|
|
syncPalScreen(s);
|
|
|
|
syncSoundList(s);
|
2009-05-24 15:17:42 +00:00
|
|
|
|
2009-02-09 11:30:18 +00:00
|
|
|
for (int i = 0; i < stateID; ++i)
|
|
|
|
s.syncAsSint16LE(globalVars[i]);
|
|
|
|
|
|
|
|
syncFilesDatabase(s);
|
|
|
|
syncOverlays1(s);
|
|
|
|
syncPreloadData(s);
|
|
|
|
syncOverlays2(s);
|
|
|
|
syncScript(s, &procHead);
|
|
|
|
syncScript(s, &relHead);
|
|
|
|
syncCell(s);
|
|
|
|
syncIncrust(s);
|
|
|
|
syncActors(s);
|
|
|
|
syncSongs(s);
|
|
|
|
syncCT(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-16 02:43:41 +00:00
|
|
|
void resetPreload() {
|
|
|
|
for (unsigned long int i = 0; i < 64; i++) {
|
|
|
|
if (strlen(preloadData[i].name)) {
|
|
|
|
if (preloadData[i].ptr) {
|
2009-10-09 08:15:30 +00:00
|
|
|
MemFree(preloadData[i].ptr);
|
2021-11-13 23:40:20 +02:00
|
|
|
preloadData[i].ptr = nullptr;
|
2007-12-18 20:12:42 +00:00
|
|
|
}
|
2022-09-24 12:31:08 +02:00
|
|
|
preloadData[i].name[0] = '\0';
|
2007-12-18 20:12:42 +00:00
|
|
|
preloadData[i].nofree = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-16 02:43:41 +00:00
|
|
|
void unloadOverlay(const char*name, int overlayNumber) {
|
2007-12-18 20:12:42 +00:00
|
|
|
releaseOverlay(name);
|
|
|
|
|
2022-09-24 12:31:08 +02:00
|
|
|
overlayTable[overlayNumber].overlayName[0] = '\0';
|
2021-11-13 23:40:20 +02:00
|
|
|
overlayTable[overlayNumber].ovlData = nullptr;
|
2007-12-18 20:12:42 +00:00
|
|
|
overlayTable[overlayNumber].alreadyLoaded = 0;
|
|
|
|
}
|
|
|
|
|
2009-11-02 21:54:57 +00:00
|
|
|
void initVars() {
|
2007-12-18 20:12:42 +00:00
|
|
|
closeAllMenu();
|
2009-04-04 01:21:25 +00:00
|
|
|
resetFileEntryRange(0, NUM_FILE_ENTRIES);
|
2007-12-18 20:12:42 +00:00
|
|
|
|
|
|
|
resetPreload();
|
|
|
|
freeCTP();
|
2009-10-10 05:08:56 +00:00
|
|
|
freeBackgroundIncrustList(&backgroundIncrustHead);
|
2007-12-18 20:12:42 +00:00
|
|
|
|
|
|
|
freezeCell(&cellHead, -1, -1, -1, -1, -1, 0);
|
|
|
|
// TODO: unfreeze anims
|
|
|
|
|
|
|
|
freeObjectList(&cellHead);
|
|
|
|
removeAnimation(&actorHead, -1, -1, -1);
|
|
|
|
|
2009-10-10 05:08:56 +00:00
|
|
|
removeAllScripts(&relHead);
|
|
|
|
removeAllScripts(&procHead);
|
2007-12-18 20:12:42 +00:00
|
|
|
changeScriptParamInList(-1, -1, &procHead, -1, 0);
|
|
|
|
removeFinishedScripts(&procHead);
|
|
|
|
|
|
|
|
changeScriptParamInList(-1, -1, &relHead, -1, 0);
|
|
|
|
removeFinishedScripts(&relHead);
|
|
|
|
|
2009-01-16 02:43:41 +00:00
|
|
|
for (unsigned long int i = 0; i < 90; i++) {
|
|
|
|
if (strlen(overlayTable[i].overlayName) && overlayTable[i].alreadyLoaded) {
|
2007-12-18 20:12:42 +00:00
|
|
|
unloadOverlay(overlayTable[i].overlayName, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO:
|
|
|
|
// stopSound();
|
|
|
|
// removeSound();
|
|
|
|
|
|
|
|
closeBase();
|
|
|
|
closeCnf();
|
|
|
|
|
|
|
|
initOverlayTable();
|
|
|
|
|
|
|
|
stateID = 0;
|
2007-12-24 16:57:14 +00:00
|
|
|
masterScreen = 0;
|
2007-12-18 20:12:42 +00:00
|
|
|
|
|
|
|
freeDisk();
|
|
|
|
|
2009-02-09 11:30:18 +00:00
|
|
|
soundList[0].frameNum = -1;
|
|
|
|
soundList[1].frameNum = -1;
|
|
|
|
soundList[2].frameNum = -1;
|
|
|
|
soundList[3].frameNum = -1;
|
2007-12-18 20:12:42 +00:00
|
|
|
|
|
|
|
for (unsigned long int i = 0; i < 8; i++) {
|
2021-11-13 23:40:20 +02:00
|
|
|
menuTable[i] = nullptr;
|
2007-12-18 20:12:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (unsigned long int i = 0; i < 2000; i++) {
|
|
|
|
globalVars[i] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (unsigned long int i = 0; i < 8; i++) {
|
|
|
|
backgroundTable[i].name[0] = 0;
|
|
|
|
}
|
|
|
|
|
2009-04-04 01:21:25 +00:00
|
|
|
for (unsigned long int i = 0; i < NUM_FILE_ENTRIES; i++) {
|
2021-11-13 23:40:20 +02:00
|
|
|
filesDatabase[i].subData.ptr = nullptr;
|
|
|
|
filesDatabase[i].subData.ptrMask = nullptr;
|
2007-12-18 20:12:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
initBigVar3();
|
|
|
|
|
|
|
|
resetPtr2(&procHead);
|
|
|
|
resetPtr2(&relHead);
|
|
|
|
|
|
|
|
resetPtr(&cellHead);
|
|
|
|
|
|
|
|
resetActorPtr(&actorHead);
|
|
|
|
resetBackgroundIncrustList(&backgroundIncrustHead);
|
|
|
|
|
|
|
|
vblLimit = 0;
|
2014-06-09 17:53:27 +02:00
|
|
|
remdo = false;
|
2007-12-18 20:12:42 +00:00
|
|
|
songLoaded = 0;
|
|
|
|
songPlayed = 0;
|
|
|
|
songLoop = 1;
|
|
|
|
activeMouse = 0;
|
|
|
|
userEnabled = 1;
|
|
|
|
dialogueEnabled = 0;
|
|
|
|
dialogueOvl = 0;
|
|
|
|
dialogueObj = 0;
|
|
|
|
userDelay = 0;
|
|
|
|
sysKey = -1;
|
|
|
|
sysX = 0;
|
|
|
|
sysY = 0;
|
|
|
|
automoveInc = 0;
|
|
|
|
automoveMax = 0;
|
|
|
|
displayOn = true;
|
|
|
|
|
|
|
|
// here used to init clip
|
|
|
|
|
|
|
|
isMessage = 0;
|
|
|
|
fadeFlag = 0;
|
|
|
|
automaticMode = 0;
|
|
|
|
|
|
|
|
// video param (vga and mcga mode)
|
|
|
|
|
|
|
|
titleColor = 2;
|
|
|
|
itemColor = 1;
|
|
|
|
selectColor = 3;
|
|
|
|
subColor = 5;
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
narratorOvl = 0;
|
|
|
|
narratorIdx = 0;
|
|
|
|
aniX = 0;
|
|
|
|
aniY = 0;
|
|
|
|
animationStart = false;
|
|
|
|
selectDown = 0;
|
|
|
|
menuDown = 0;
|
|
|
|
buttonDown = 0;
|
|
|
|
var41 = 0;
|
2009-04-18 10:16:08 +00:00
|
|
|
playerMenuEnabled = 0;
|
2014-06-09 17:53:27 +02:00
|
|
|
PCFadeFlag = false;
|
2007-12-18 20:12:42 +00:00
|
|
|
}
|
|
|
|
|
2009-04-18 10:16:08 +00:00
|
|
|
Common::Error saveSavegameData(int saveGameIdx, const Common::String &saveName) {
|
|
|
|
const char *filename = _vm->getSavegameFile(saveGameIdx);
|
2007-12-20 14:30:51 +00:00
|
|
|
Common::SaveFileManager *saveMan = g_system->getSavefileManager();
|
2009-04-18 10:16:08 +00:00
|
|
|
Common::OutSaveFile *f = saveMan->openForSaving(filename);
|
2021-11-13 23:40:20 +02:00
|
|
|
if (f == nullptr)
|
2009-04-18 10:16:08 +00:00
|
|
|
return Common::kNoGameDataFoundError;
|
2007-12-20 14:30:51 +00:00
|
|
|
|
2009-04-18 10:16:08 +00:00
|
|
|
// Save the savegame header
|
|
|
|
CruiseSavegameHeader header;
|
|
|
|
header.saveName = saveName;
|
|
|
|
writeSavegameHeader(f, header);
|
2007-12-20 14:30:51 +00:00
|
|
|
|
2009-05-19 11:42:14 +00:00
|
|
|
if (f->err()) {
|
2009-04-18 10:16:08 +00:00
|
|
|
delete f;
|
|
|
|
saveMan->removeSavefile(filename);
|
|
|
|
return Common::kWritingFailed;
|
|
|
|
} else {
|
|
|
|
// Create the remainder of the savegame
|
2021-11-13 23:40:20 +02:00
|
|
|
Common::Serializer s(nullptr, f);
|
2009-02-09 11:30:18 +00:00
|
|
|
DoSync(s);
|
2007-12-20 14:30:51 +00:00
|
|
|
|
2009-02-09 11:30:18 +00:00
|
|
|
f->finalize();
|
|
|
|
delete f;
|
2009-04-18 10:16:08 +00:00
|
|
|
return Common::kNoError;
|
2007-12-20 14:30:51 +00:00
|
|
|
}
|
2007-12-18 20:12:42 +00:00
|
|
|
}
|
|
|
|
|
2009-04-18 10:16:08 +00:00
|
|
|
Common::Error loadSavegameData(int saveGameIdx) {
|
|
|
|
Common::String saveName;
|
2007-04-27 22:33:45 +00:00
|
|
|
cellStruct *currentcellHead;
|
|
|
|
|
2007-12-20 14:30:51 +00:00
|
|
|
Common::SaveFileManager *saveMan = g_system->getSavefileManager();
|
2009-04-18 10:16:08 +00:00
|
|
|
Common::InSaveFile *f = saveMan->openForLoading(_vm->getSavegameFile(saveGameIdx));
|
2007-04-27 22:33:45 +00:00
|
|
|
|
2021-11-13 23:40:20 +02:00
|
|
|
if (f == nullptr) {
|
2007-07-01 12:47:07 +00:00
|
|
|
printInfoBlackBox("Savegame not found...");
|
2007-04-27 22:33:45 +00:00
|
|
|
waitForPlayerInput();
|
2009-04-18 10:16:08 +00:00
|
|
|
return Common::kNoGameDataFoundError;
|
2007-04-27 22:33:45 +00:00
|
|
|
}
|
|
|
|
|
2007-07-01 12:47:07 +00:00
|
|
|
printInfoBlackBox("Loading in progress...");
|
2007-04-27 22:33:45 +00:00
|
|
|
|
2009-02-09 11:30:18 +00:00
|
|
|
initVars();
|
2009-06-20 08:15:01 +00:00
|
|
|
_vm->sound().stopMusic();
|
2007-11-08 22:59:29 +00:00
|
|
|
|
2009-04-18 10:16:08 +00:00
|
|
|
// Skip over the savegame header
|
|
|
|
CruiseSavegameHeader header;
|
ALL: Load savegame thumbnail only when necessary
This commit introduces the following changes:
1. Graphics::loadThumbnail()
Now returns a boolean and takes a new argument skipThumbnail which
defaults to false. In case of true, loadThumbnail() reads past the
thumbnail data in the input stream instead of actually loading the
thumbnail. This simplifies savegame handling where, up until now,
many engines always read the whole savegame metadata (including
the thumbnail) and then threw away the thumbnail when not needed
(which is in almost all cases, the most common exception being
MetaEngine::querySaveMetaInfos() which is responsible for loading
savegame metadata for displaying it in the GUI launcher.
2. readSavegameHeader()
Engines which already implement such a method (name varies) now take
a new argument skipThumbnail (default: true) which is passed
through to loadThumbnail(). This means that the default case for
readSavegameHeader() is now _not_ loading the thumbnail from a
savegame and just reading past it. In those cases, e.g.
querySaveMetaInfos(), where we actually are interested in loading
the thumbnail readSavegameHeader() needs to explicitely be called
with skipThumbnail == false.
Engines whose readSavegameHeader() (name varies) already takes an
argument loadThumbnail have been adapted to have a similar
prototype and semantics.
I.e. readSaveHeader(in, loadThumbnail, header) now is
readSaveHeader(in, header, skipThumbnail).
3. Error handling
Engines which previously did not check the return value of
readSavegameHeader() (name varies) now do so ensuring that possibly
broken savegames (be it a broken thumbnail or something else) don't
make it into the GUI launcher list in the first place.
2018-04-06 00:06:38 +02:00
|
|
|
if (!readSavegameHeader(f, header)) {
|
|
|
|
delete f;
|
|
|
|
return Common::kReadingFailed;
|
|
|
|
}
|
2009-04-18 10:16:08 +00:00
|
|
|
|
|
|
|
// Synchronise the remaining data of the savegame
|
2021-11-13 23:40:20 +02:00
|
|
|
Common::Serializer s(f, nullptr);
|
2009-02-09 11:30:18 +00:00
|
|
|
DoSync(s);
|
2007-11-08 22:59:29 +00:00
|
|
|
|
2009-02-09 11:30:18 +00:00
|
|
|
delete f;
|
2007-11-08 22:59:29 +00:00
|
|
|
|
2009-02-09 11:30:18 +00:00
|
|
|
// Post processing
|
2007-11-08 22:59:29 +00:00
|
|
|
|
2009-02-09 11:30:18 +00:00
|
|
|
for (int j = 0; j < 64; j++)
|
2021-11-13 23:40:20 +02:00
|
|
|
preloadData[j].ptr = nullptr;
|
2007-04-27 22:33:45 +00:00
|
|
|
|
2007-11-08 22:59:29 +00:00
|
|
|
for (int j = 1; j < numOfLoadedOverlay; j++) {
|
2007-04-27 22:33:45 +00:00
|
|
|
if (overlayTable[j].alreadyLoaded) {
|
|
|
|
overlayTable[j].alreadyLoaded = 0;
|
2007-11-10 17:15:48 +00:00
|
|
|
loadOverlay(overlayTable[j].overlayName);
|
2007-04-27 22:33:45 +00:00
|
|
|
|
|
|
|
if (overlayTable[j].alreadyLoaded) {
|
2007-11-08 22:59:29 +00:00
|
|
|
ovlDataStruct *ovlData = overlayTable[j].ovlData;
|
2007-04-27 22:33:45 +00:00
|
|
|
|
2007-11-10 19:47:07 +00:00
|
|
|
// overlay BSS
|
|
|
|
|
|
|
|
if (ovlRestoreData[j]._sBssSize) {
|
2007-04-27 22:33:45 +00:00
|
|
|
if (ovlData->data4Ptr) {
|
2009-10-09 08:15:30 +00:00
|
|
|
MemFree(ovlData->data4Ptr);
|
2007-04-27 22:33:45 +00:00
|
|
|
}
|
|
|
|
|
2007-11-10 19:47:07 +00:00
|
|
|
ovlData->data4Ptr = ovlRestoreData[j]._pBss;
|
|
|
|
ovlData->sizeOfData4 = ovlRestoreData[j]._sBssSize;
|
2007-04-27 22:33:45 +00:00
|
|
|
}
|
|
|
|
|
2007-11-10 19:47:07 +00:00
|
|
|
// overlay object data
|
|
|
|
|
|
|
|
if (ovlRestoreData[j]._sNumObj) {
|
2007-10-28 17:40:04 +00:00
|
|
|
if (ovlData->arrayObjVar) {
|
2009-10-09 08:15:30 +00:00
|
|
|
MemFree(ovlData->arrayObjVar);
|
2007-04-27 22:33:45 +00:00
|
|
|
}
|
|
|
|
|
2007-11-10 19:47:07 +00:00
|
|
|
ovlData->arrayObjVar = ovlRestoreData[j]._pObj;
|
|
|
|
ovlData->size9 = ovlRestoreData[j]._sNumObj;
|
2007-04-27 22:33:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
updateAllScriptsImports();
|
|
|
|
|
2007-11-10 17:15:48 +00:00
|
|
|
lastAni[0] = 0;
|
2007-04-27 22:33:45 +00:00
|
|
|
|
2009-04-04 01:21:25 +00:00
|
|
|
for (int i = 0; i < NUM_FILE_ENTRIES; i++) {
|
2007-11-10 17:15:48 +00:00
|
|
|
if (filesDatabase[i].subData.ptr) {
|
2014-06-01 01:21:32 +02:00
|
|
|
int j = i + 1;
|
|
|
|
for (; j < NUM_FILE_ENTRIES &&
|
2013-12-10 18:34:48 +01:00
|
|
|
filesDatabase[j].subData.ptr &&
|
|
|
|
!strcmp(filesDatabase[i].subData.name, filesDatabase[j].subData.name) &&
|
|
|
|
(filesDatabase[j].subData.index == (j - i));
|
|
|
|
j++)
|
2009-01-29 05:26:12 +00:00
|
|
|
;
|
2007-04-27 22:33:45 +00:00
|
|
|
|
2014-06-01 01:21:32 +02:00
|
|
|
for (int k = i; k < j; k++) {
|
2021-11-13 23:40:20 +02:00
|
|
|
filesDatabase[k].subData.ptr = nullptr;
|
|
|
|
filesDatabase[k].subData.ptrMask = nullptr;
|
2007-04-27 22:33:45 +00:00
|
|
|
}
|
|
|
|
|
2007-12-20 14:30:51 +00:00
|
|
|
/*if (j < 2) {
|
2010-11-07 01:03:58 +00:00
|
|
|
error("Unsupported mono file load");
|
2007-04-27 22:33:45 +00:00
|
|
|
//loadFileMode1(filesDatabase[j].subData.name,filesDatabase[j].subData.var4);
|
2009-07-03 06:19:20 +00:00
|
|
|
} else */
|
2010-01-25 01:39:44 +00:00
|
|
|
if (strlen(filesDatabase[i].subData.name) > 0) {
|
2007-11-10 17:15:48 +00:00
|
|
|
loadFileRange(filesDatabase[i].subData.name, filesDatabase[i].subData.index, i, j - i);
|
2009-07-03 06:19:20 +00:00
|
|
|
} else {
|
2021-11-13 23:40:20 +02:00
|
|
|
filesDatabase[i].subData.ptr = nullptr;
|
|
|
|
filesDatabase[i].subData.ptrMask = nullptr;
|
2007-04-27 22:33:45 +00:00
|
|
|
}
|
|
|
|
|
2009-07-03 06:19:20 +00:00
|
|
|
i = j - 1;
|
2007-04-27 22:33:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-10 17:15:48 +00:00
|
|
|
lastAni[0] = 0;
|
2007-04-27 22:33:45 +00:00
|
|
|
|
|
|
|
currentcellHead = cellHead.next;
|
|
|
|
|
|
|
|
while (currentcellHead) {
|
|
|
|
if (currentcellHead->type == 5) {
|
2014-06-08 17:55:05 +02:00
|
|
|
assert(0);
|
2014-06-06 07:19:56 +02:00
|
|
|
#if 0
|
|
|
|
uint8 *ptr = mainProc14(currentcellHead->overlay, currentcellHead->idx);
|
|
|
|
if (ptr)
|
|
|
|
*(int16 *)(currentcellHead->datas+0x2E) = getSprite(ptr,*(int16 *)(currentcellHead->datas+0xE));
|
|
|
|
else
|
|
|
|
*(int16 *)(currentcellHead->datas+0x2E) = 0;
|
|
|
|
#endif
|
2007-04-27 22:33:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
currentcellHead = currentcellHead->next;
|
|
|
|
}
|
|
|
|
|
2007-11-10 17:15:48 +00:00
|
|
|
if (strlen(currentCtpName)) {
|
2007-12-27 12:05:43 +00:00
|
|
|
loadCtFromSave = 1;
|
|
|
|
initCt(currentCtpName);
|
|
|
|
loadCtFromSave = 0;
|
2007-04-27 22:33:45 +00:00
|
|
|
}
|
|
|
|
//prepareFadeOut();
|
|
|
|
//gfxModuleData.gfxFunction8();
|
|
|
|
|
2007-11-08 22:59:29 +00:00
|
|
|
for (int j = 0; j < 8; j++) {
|
2007-04-27 22:33:45 +00:00
|
|
|
if (strlen((char *)backgroundTable[j].name)) {
|
|
|
|
loadBackground(backgroundTable[j].name, j);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-09 11:30:18 +00:00
|
|
|
regenerateBackgroundIncrust(&backgroundIncrustHead);
|
2007-04-27 22:33:45 +00:00
|
|
|
|
|
|
|
// to finish
|
|
|
|
|
2007-10-28 13:21:01 +00:00
|
|
|
changeCursor(CURSOR_NORMAL);
|
2014-06-10 07:20:10 +02:00
|
|
|
mainDraw(true);
|
2007-04-27 22:33:45 +00:00
|
|
|
flipScreen();
|
|
|
|
|
2009-04-18 10:16:08 +00:00
|
|
|
return Common::kNoError;
|
2007-04-27 12:58:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // End of namespace Cruise
|