2013-06-01 13:01:25 +03:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2014-02-18 02:34:20 +01:00
|
|
|
*
|
2013-06-01 13:01:25 +03: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:20 +01:00
|
|
|
*
|
2013-06-01 13:01:25 +03:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2020-10-03 23:50:25 +02:00
|
|
|
#include "ngi/ngi.h"
|
2013-06-01 17:20:40 +03:00
|
|
|
|
2020-10-03 23:47:47 +02:00
|
|
|
#include "ngi/constants.h"
|
|
|
|
#include "ngi/gameloader.h"
|
|
|
|
#include "ngi/interaction.h"
|
|
|
|
#include "ngi/objects.h"
|
|
|
|
#include "ngi/scene.h"
|
|
|
|
#include "ngi/statics.h"
|
2018-05-02 06:05:04 -07:00
|
|
|
|
2013-06-01 17:20:40 +03:00
|
|
|
#include "common/file.h"
|
2013-06-04 00:53:23 +03:00
|
|
|
#include "common/array.h"
|
2013-06-02 23:51:33 +03:00
|
|
|
#include "common/list.h"
|
2016-09-18 22:45:21 +02:00
|
|
|
#include "common/memstream.h"
|
2013-06-01 17:20:40 +03:00
|
|
|
|
2016-09-20 13:14:10 +02:00
|
|
|
#include "graphics/thumbnail.h"
|
|
|
|
|
2013-06-01 13:01:25 +03:00
|
|
|
namespace Fullpipe {
|
|
|
|
|
2016-09-27 19:10:07 +02:00
|
|
|
bool GameLoader::readSavegame(const char *fname) {
|
2016-09-18 22:45:21 +02:00
|
|
|
SaveHeader header;
|
2017-11-18 11:50:40 -06:00
|
|
|
Common::ScopedPtr<Common::InSaveFile> saveFile(g_system->getSavefileManager()->openForLoading(fname));
|
2016-09-18 22:45:21 +02:00
|
|
|
|
2016-09-19 10:13:47 +02:00
|
|
|
if (!saveFile) {
|
|
|
|
warning("Cannot open save %s for loading", fname);
|
2016-09-27 19:10:07 +02:00
|
|
|
return false;
|
2016-09-19 10:13:47 +02:00
|
|
|
}
|
|
|
|
|
2016-09-18 22:45:21 +02:00
|
|
|
header.version = saveFile->readUint32LE();
|
|
|
|
saveFile->read(header.magic, 32);
|
|
|
|
header.updateCounter = saveFile->readUint32LE();
|
|
|
|
header.unkField = saveFile->readUint32LE();
|
|
|
|
header.encSize = saveFile->readUint32LE();
|
|
|
|
|
2016-09-19 10:17:50 +02:00
|
|
|
debugC(3, kDebugLoading, "version: %d magic: %s updateCounter: %d unkField: %d encSize: %d, pos: %d",
|
|
|
|
header.version, header.magic, header.updateCounter, header.unkField, header.encSize, saveFile->pos());
|
|
|
|
|
2016-09-18 22:45:21 +02:00
|
|
|
if (header.version != 48)
|
2016-09-27 19:10:07 +02:00
|
|
|
return false;
|
2016-09-18 22:45:21 +02:00
|
|
|
|
|
|
|
_updateCounter = header.updateCounter;
|
|
|
|
|
2017-11-18 11:50:40 -06:00
|
|
|
Common::Array<byte> data(header.encSize);
|
|
|
|
saveFile->read(data.data(), header.encSize);
|
2016-09-18 22:45:21 +02:00
|
|
|
|
2017-11-18 11:50:40 -06:00
|
|
|
Common::Array<byte> map(800);
|
|
|
|
saveFile->read(map.data(), 800);
|
2016-09-18 22:45:21 +02:00
|
|
|
|
2018-03-24 23:09:06 +01:00
|
|
|
FullpipeSavegameHeader header2;
|
|
|
|
if (Fullpipe::readSavegameHeader(saveFile.get(), header2)) {
|
|
|
|
g_fp->setTotalPlayTime(header2.playtime * 1000);
|
|
|
|
}
|
|
|
|
|
2017-11-18 11:50:40 -06:00
|
|
|
{
|
|
|
|
Common::MemoryReadStream tempStream(map.data(), 800, DisposeAfterUse::NO);
|
|
|
|
MfcArchive temp(&tempStream);
|
2016-09-18 22:45:21 +02:00
|
|
|
|
2017-11-18 11:50:40 -06:00
|
|
|
if (_savegameCallback)
|
|
|
|
_savegameCallback(&temp, false);
|
|
|
|
}
|
2016-09-18 22:45:21 +02:00
|
|
|
|
|
|
|
// Deobfuscate the data
|
2016-11-28 06:42:47 +01:00
|
|
|
for (int i = 0; i < header.encSize; i++)
|
2016-09-18 22:45:21 +02:00
|
|
|
data[i] -= i & 0x7f;
|
|
|
|
|
2017-11-18 11:50:40 -06:00
|
|
|
Common::MemoryReadStream archiveStream(data.data(), header.encSize, DisposeAfterUse::NO);
|
|
|
|
MfcArchive archive(&archiveStream);
|
2016-09-18 22:45:21 +02:00
|
|
|
|
2017-11-18 11:50:40 -06:00
|
|
|
GameVar *var = archive.readClass<GameVar>();
|
2016-09-18 22:45:21 +02:00
|
|
|
|
|
|
|
GameVar *v = _gameVar->getSubVarByName("OBJSTATES");
|
|
|
|
|
|
|
|
if (!v) {
|
|
|
|
v = _gameVar->addSubVarAsInt("OBJSTATES", 0);
|
|
|
|
|
|
|
|
if (!v) {
|
|
|
|
warning("No state to save");
|
2017-11-18 11:50:40 -06:00
|
|
|
delete var;
|
2016-09-27 19:10:07 +02:00
|
|
|
return false;
|
2016-09-18 22:45:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-19 18:58:39 +02:00
|
|
|
addVar(var, v);
|
2016-09-18 22:45:21 +02:00
|
|
|
|
2017-11-18 11:50:40 -06:00
|
|
|
getGameLoaderInventory()->loadPartial(archive);
|
2016-09-18 22:45:21 +02:00
|
|
|
|
2017-11-18 11:50:40 -06:00
|
|
|
uint32 arrSize = archive.readUint32LE();
|
2016-09-18 22:45:21 +02:00
|
|
|
|
2016-09-23 09:53:00 +02:00
|
|
|
debugC(3, kDebugLoading, "Reading %d infos", arrSize);
|
|
|
|
|
2016-09-18 22:45:21 +02:00
|
|
|
for (uint i = 0; i < arrSize; i++) {
|
2016-09-25 19:38:44 +02:00
|
|
|
|
2017-11-18 11:50:40 -06:00
|
|
|
const uint picAniInfosCount = archive.readUint32LE();
|
2017-11-15 16:24:37 -06:00
|
|
|
if (picAniInfosCount)
|
|
|
|
debugC(3, kDebugLoading, "Count %d: %d", i, picAniInfosCount);
|
2016-09-18 22:45:21 +02:00
|
|
|
|
2017-11-15 16:24:37 -06:00
|
|
|
_sc2array[i]._picAniInfos.clear();
|
|
|
|
_sc2array[i]._picAniInfos.resize(picAniInfosCount);
|
2016-09-18 22:45:21 +02:00
|
|
|
|
2017-11-15 16:24:37 -06:00
|
|
|
for (uint j = 0; j < picAniInfosCount; j++) {
|
2017-11-18 11:50:40 -06:00
|
|
|
_sc2array[i]._picAniInfos[j].load(archive);
|
2016-09-18 22:45:21 +02:00
|
|
|
}
|
2016-09-25 20:03:50 +02:00
|
|
|
|
2017-11-15 16:24:37 -06:00
|
|
|
_sc2array[i]._isLoaded = false;
|
2016-09-18 22:45:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
getGameLoaderInventory()->rebuildItemRects();
|
|
|
|
|
|
|
|
PreloadItem preloadItem;
|
|
|
|
|
|
|
|
v = _gameVar->getSubVarByName("OBJSTATES")->getSubVarByName("SAVEGAME");
|
|
|
|
|
|
|
|
if (v) {
|
|
|
|
if (g_fp->_currentScene)
|
|
|
|
preloadItem.preloadId1 = g_fp->_currentScene->_sceneId & 0xffff;
|
|
|
|
else
|
|
|
|
preloadItem.preloadId1 = 0;
|
|
|
|
|
|
|
|
preloadItem.param = v->getSubVarAsInt("Entrance");
|
|
|
|
preloadItem.preloadId2 = 0;
|
|
|
|
preloadItem.sceneId = v->getSubVarAsInt("Scene");
|
|
|
|
|
|
|
|
if (_preloadCallback) {
|
|
|
|
if (!_preloadCallback(preloadItem, 0))
|
2016-09-27 19:10:07 +02:00
|
|
|
return false;
|
2016-09-18 22:45:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
clearGlobalMessageQueueList1();
|
|
|
|
|
|
|
|
if (g_fp->_currentScene)
|
|
|
|
unloadScene(g_fp->_currentScene->_sceneId);
|
|
|
|
|
|
|
|
g_fp->_currentScene = 0;
|
|
|
|
|
|
|
|
if (_preloadCallback)
|
|
|
|
_preloadCallback(preloadItem, 50);
|
|
|
|
|
|
|
|
loadScene(preloadItem.sceneId);
|
|
|
|
|
|
|
|
ExCommand *ex = new ExCommand(preloadItem.sceneId, 17, 62, 0, 0, 0, 1, 0, 0, 0);
|
|
|
|
ex->_excFlags = 2;
|
|
|
|
ex->_param = preloadItem.param;
|
|
|
|
|
|
|
|
if (_preloadCallback)
|
|
|
|
_preloadCallback(preloadItem, 100);
|
|
|
|
|
|
|
|
ex->postMessage();
|
|
|
|
}
|
2016-09-27 19:10:07 +02:00
|
|
|
|
|
|
|
return true;
|
2016-09-18 22:45:21 +02:00
|
|
|
}
|
|
|
|
|
2016-09-20 13:14:10 +02:00
|
|
|
void parseSavegameHeader(Fullpipe::FullpipeSavegameHeader &header, SaveStateDescriptor &desc) {
|
|
|
|
int day = (header.date >> 24) & 0xFF;
|
|
|
|
int month = (header.date >> 16) & 0xFF;
|
|
|
|
int year = header.date & 0xFFFF;
|
|
|
|
desc.setSaveDate(year, month, day);
|
|
|
|
int hour = (header.time >> 8) & 0xFF;
|
|
|
|
int minutes = header.time & 0xFF;
|
|
|
|
desc.setSaveTime(hour, minutes);
|
|
|
|
desc.setPlayTime(header.playtime * 1000);
|
2016-09-20 19:19:57 +02:00
|
|
|
|
2017-12-02 00:51:53 +01:00
|
|
|
desc.setDescription(header.description);
|
2016-09-20 13:14:10 +02:00
|
|
|
}
|
|
|
|
|
2016-09-20 19:34:22 +02:00
|
|
|
void fillDummyHeader(Fullpipe::FullpipeSavegameHeader &header) {
|
|
|
|
// This is wrong header, perhaps it is original savegame. Thus fill out dummy values
|
|
|
|
header.date = (20 << 24) | (9 << 16) | 2016;
|
|
|
|
header.time = (9 << 8) | 56;
|
2018-03-24 23:35:31 +01:00
|
|
|
header.playtime = 0;
|
2016-09-20 19:34:22 +02:00
|
|
|
}
|
|
|
|
|
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, FullpipeSavegameHeader &header, bool skipThumbnail) {
|
2016-09-20 13:14:10 +02:00
|
|
|
uint oldPos = in->pos();
|
|
|
|
|
2016-09-21 08:46:19 +02:00
|
|
|
in->seek(-4, SEEK_END);
|
2016-09-20 19:19:57 +02:00
|
|
|
|
2016-11-28 06:42:47 +01:00
|
|
|
int headerOffset = in->readUint32LE();
|
2016-09-20 13:14:10 +02:00
|
|
|
|
2016-09-20 19:19:57 +02:00
|
|
|
// Sanity check
|
|
|
|
if (headerOffset >= in->pos() || headerOffset == 0) {
|
|
|
|
in->seek(oldPos, SEEK_SET); // Rewind the file
|
2016-09-20 19:34:22 +02:00
|
|
|
fillDummyHeader(header);
|
2016-09-20 19:19:57 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-09-20 13:14:10 +02:00
|
|
|
in->seek(headerOffset, SEEK_SET);
|
|
|
|
|
2016-09-20 19:19:57 +02:00
|
|
|
in->read(header.id, 6);
|
|
|
|
|
2016-09-20 13:14:10 +02:00
|
|
|
// Validate the header Id
|
2016-09-20 19:19:57 +02:00
|
|
|
if (strcmp(header.id, "SVMCR")) {
|
2016-09-20 19:34:22 +02:00
|
|
|
in->seek(oldPos, SEEK_SET); // Rewind the file
|
|
|
|
fillDummyHeader(header);
|
2016-09-20 13:14:10 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
header.version = in->readByte();
|
2016-09-20 19:19:57 +02:00
|
|
|
header.date = in->readUint32LE();
|
|
|
|
header.time = in->readUint16LE();
|
|
|
|
header.playtime = in->readUint32LE();
|
|
|
|
|
2017-12-02 00:51:53 +01:00
|
|
|
if (header.version > 1)
|
|
|
|
header.description = in->readPascalString();
|
|
|
|
|
2016-09-20 19:19:57 +02:00
|
|
|
// Generate savename
|
|
|
|
SaveStateDescriptor desc;
|
|
|
|
|
|
|
|
parseSavegameHeader(header, desc);
|
2017-12-02 00:51:53 +01:00
|
|
|
|
2016-09-20 19:19:57 +02:00
|
|
|
header.saveName = Common::String::format("%s %s", desc.getSaveDate().c_str(), desc.getSaveTime().c_str());
|
2016-09-20 13:14:10 +02:00
|
|
|
|
2017-12-02 00:51:53 +01:00
|
|
|
if (header.description.empty())
|
|
|
|
header.description = header.saveName;
|
|
|
|
|
2016-09-20 13:14:10 +02:00
|
|
|
// Get the thumbnail
|
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)) {
|
|
|
|
in->seek(oldPos, SEEK_SET); // Rewind the file
|
|
|
|
return false;
|
|
|
|
}
|
2016-09-20 13:14:10 +02:00
|
|
|
|
|
|
|
in->seek(oldPos, SEEK_SET); // Rewind the file
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-09-18 22:45:21 +02:00
|
|
|
void GameLoader::addVar(GameVar *var, GameVar *subvar) {
|
|
|
|
if (var && subvar) {
|
|
|
|
int type = var->_varType;
|
|
|
|
if (type == subvar->_varType && (!type || type == 1))
|
|
|
|
subvar->_value.intValue = var->_value.intValue;
|
|
|
|
|
|
|
|
for (GameVar *v = var->_subVars; v; v = v->_nextVarObj) {
|
2017-03-22 04:11:49 +02:00
|
|
|
GameVar *nv = subvar->getSubVarByName(v->_varName.c_str());
|
2016-09-18 22:45:21 +02:00
|
|
|
if (!nv) {
|
|
|
|
nv = new GameVar;
|
2017-03-22 04:11:49 +02:00
|
|
|
nv->_varName = v->_varName;
|
2016-09-18 22:45:21 +02:00
|
|
|
nv->_varType = v->_varType;
|
|
|
|
|
|
|
|
subvar->addSubVar(nv);
|
|
|
|
}
|
|
|
|
|
|
|
|
addVar(v, nv);
|
|
|
|
}
|
|
|
|
}
|
2016-09-18 09:37:05 +02:00
|
|
|
}
|
|
|
|
|
2016-09-18 09:32:58 +02:00
|
|
|
void gameLoaderSavegameCallback(MfcArchive *archive, bool mode) {
|
|
|
|
if (mode)
|
|
|
|
for (int i = 0; i < 200; i++)
|
|
|
|
archive->writeUint32LE(g_fp->_mapTable[i]);
|
|
|
|
else
|
|
|
|
for (int i = 0; i < 200; i++)
|
|
|
|
g_fp->_mapTable[i] = archive->readUint32LE();
|
|
|
|
}
|
|
|
|
|
2013-08-08 01:14:24 +03:00
|
|
|
bool FullpipeEngine::loadGam(const char *fname, int scene) {
|
2017-11-14 12:48:41 -06:00
|
|
|
_gameLoader.reset(new GameLoader());
|
2013-06-01 13:01:25 +03:00
|
|
|
|
2013-07-28 17:22:18 +03:00
|
|
|
if (!_gameLoader->loadFile(fname))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
_currSoundListCount = 0;
|
|
|
|
initObjectStates();
|
2013-08-08 01:14:24 +03:00
|
|
|
// set_g_messageQueueCallback1(messageQueueCallback1); // substituted with direct call
|
2013-07-28 17:22:18 +03:00
|
|
|
|
|
|
|
addMessageHandlerByIndex(global_messageHandler1, 0, 4);
|
|
|
|
|
|
|
|
_inventory = getGameLoaderInventory();
|
2016-12-11 18:35:43 +01:00
|
|
|
|
|
|
|
if (isDemo() && getLanguage() == Common::RU_RUS) {
|
|
|
|
_inventory->addItem(ANI_INV_HAMMER, 1);
|
|
|
|
} else {
|
|
|
|
_inventory->setItemFlags(ANI_INV_MAP, 0x10003);
|
|
|
|
_inventory->addItem(ANI_INV_MAP, 1);
|
|
|
|
}
|
2013-06-20 15:26:21 -04:00
|
|
|
|
2013-07-28 17:22:18 +03:00
|
|
|
_inventory->rebuildItemRects();
|
2013-06-26 19:45:23 -04:00
|
|
|
|
2014-05-02 12:09:21 +03:00
|
|
|
for (uint i = 0; i < _inventory->getScene()->_picObjList.size(); i++)
|
2017-11-14 22:30:35 -06:00
|
|
|
_inventory->getScene()->_picObjList[i]->_picture->MemoryObject::load();
|
2013-07-06 22:45:11 +03:00
|
|
|
|
2013-08-08 01:14:24 +03:00
|
|
|
// _sceneSwitcher = sceneSwitcher; // substituted with direct call
|
2013-09-12 22:47:45 +03:00
|
|
|
_gameLoader->_preloadCallback = preloadCallback;
|
2016-09-18 09:32:58 +02:00
|
|
|
_gameLoader->_savegameCallback = gameLoaderSavegameCallback;
|
2013-07-20 16:08:05 +03:00
|
|
|
|
2013-07-28 17:22:18 +03:00
|
|
|
_aniMan = accessScene(SC_COMMON)->getAniMan();
|
|
|
|
_scene2 = 0;
|
2013-07-28 14:54:25 +03:00
|
|
|
|
2017-11-14 13:53:01 -06:00
|
|
|
_movTable.reset(_aniMan->countMovements());
|
2013-07-27 23:54:06 +03:00
|
|
|
|
2013-07-28 17:22:18 +03:00
|
|
|
_aniMan->setSpeed(1);
|
2013-07-27 23:54:06 +03:00
|
|
|
|
2013-07-28 17:22:18 +03:00
|
|
|
PictureObject *pic = accessScene(SC_INV)->getPictureObjectById(PIC_INV_MENU, 0);
|
2013-07-27 23:54:06 +03:00
|
|
|
|
2013-07-28 17:22:18 +03:00
|
|
|
pic->setFlags(pic->_flags & 0xFFFB);
|
2013-07-27 23:54:06 +03:00
|
|
|
|
2013-07-28 17:22:18 +03:00
|
|
|
// Not used in full game
|
|
|
|
//_evalVersionPic = accessScene(SC_COMMON)->getPictureObjectById(PIC_CMN_EVAL, 0);
|
2013-07-27 23:54:06 +03:00
|
|
|
|
2013-07-28 17:22:18 +03:00
|
|
|
initMap();
|
|
|
|
initCursors();
|
2013-07-27 23:54:06 +03:00
|
|
|
|
2013-07-28 17:22:18 +03:00
|
|
|
setMusicAllowed(_gameLoader->_gameVar->getSubVarAsInt("MUSIC_ALLOWED"));
|
2013-07-27 23:54:06 +03:00
|
|
|
|
2016-09-27 18:29:05 +02:00
|
|
|
if (scene == -1)
|
|
|
|
return true;
|
|
|
|
|
2013-08-08 01:14:24 +03:00
|
|
|
if (scene) {
|
2013-12-28 23:42:06 +02:00
|
|
|
_gameLoader->loadScene(726);
|
|
|
|
_gameLoader->gotoScene(726, TrubaLeft);
|
|
|
|
|
|
|
|
if (scene != 726)
|
|
|
|
_gameLoader->preloadScene(726, getSceneEntrance(scene));
|
2013-07-28 17:22:18 +03:00
|
|
|
} else {
|
2013-08-08 01:14:24 +03:00
|
|
|
if (_flgPlayIntro) {
|
|
|
|
_gameLoader->loadScene(SC_INTRO1);
|
|
|
|
_gameLoader->gotoScene(SC_INTRO1, TrubaUp);
|
|
|
|
} else {
|
2016-12-11 16:14:58 +01:00
|
|
|
if (g_fp->isDemo() && g_fp->getLanguage() == Common::RU_RUS) {
|
2016-12-11 00:06:57 +01:00
|
|
|
_gameLoader->loadScene(SC_9);
|
|
|
|
_gameLoader->gotoScene(SC_9, TrubaDown);
|
|
|
|
} else {
|
|
|
|
_gameLoader->loadScene(SC_1);
|
|
|
|
_gameLoader->gotoScene(SC_1, TrubaLeft);
|
|
|
|
}
|
2013-08-08 01:14:24 +03:00
|
|
|
}
|
2013-07-28 17:22:18 +03:00
|
|
|
}
|
2013-07-28 14:54:25 +03:00
|
|
|
|
2013-07-28 17:22:18 +03:00
|
|
|
if (!_currentScene)
|
2013-06-01 13:01:25 +03:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-06-06 23:52:43 +03:00
|
|
|
GameProject::GameProject() {
|
2013-06-01 17:20:40 +03:00
|
|
|
_field_4 = 0;
|
|
|
|
_field_10 = 12;
|
2013-06-06 23:52:43 +03:00
|
|
|
}
|
2013-06-01 17:20:40 +03:00
|
|
|
|
2013-06-06 23:52:43 +03:00
|
|
|
bool GameProject::load(MfcArchive &file) {
|
2016-07-28 00:36:53 +03:00
|
|
|
debugC(5, kDebugLoading, "GameProject::load()");
|
2013-07-12 09:03:02 +03:00
|
|
|
|
2013-06-09 00:27:42 +03:00
|
|
|
_field_4 = 0;
|
|
|
|
_field_10 = 12;
|
|
|
|
|
2013-12-20 16:08:02 +02:00
|
|
|
g_fp->_gameProjectVersion = file.readUint32LE();
|
|
|
|
g_fp->_pictureScale = file.readUint16LE();
|
|
|
|
g_fp->_scrollSpeed = file.readUint32LE();
|
2013-06-01 17:20:40 +03:00
|
|
|
|
2013-06-02 22:52:37 +03:00
|
|
|
_headerFilename = file.readPascalString();
|
2013-06-01 17:20:40 +03:00
|
|
|
|
2016-07-28 00:36:53 +03:00
|
|
|
debugC(1, kDebugLoading, "_gameProjectVersion = %d", g_fp->_gameProjectVersion);
|
|
|
|
debugC(1, kDebugLoading, "_pictureScale = %d", g_fp->_pictureScale);
|
|
|
|
debugC(1, kDebugLoading, "_scrollSpeed = %d", g_fp->_scrollSpeed);
|
2017-03-22 04:11:49 +02:00
|
|
|
debugC(1, kDebugLoading, "_headerFilename = %s", _headerFilename.c_str());
|
2013-06-01 17:20:40 +03:00
|
|
|
|
2017-11-14 12:57:07 -06:00
|
|
|
_sceneTagList.reset(new SceneTagList());
|
2013-06-06 23:52:43 +03:00
|
|
|
|
|
|
|
_sceneTagList->load(file);
|
2013-06-03 00:18:49 +03:00
|
|
|
|
2013-12-20 16:08:02 +02:00
|
|
|
if (g_fp->_gameProjectVersion >= 3)
|
2013-06-01 17:20:40 +03:00
|
|
|
_field_4 = file.readUint32LE();
|
|
|
|
|
2013-12-20 16:08:02 +02:00
|
|
|
if (g_fp->_gameProjectVersion >= 5) {
|
2013-06-01 17:20:40 +03:00
|
|
|
file.readUint32LE();
|
|
|
|
file.readUint32LE();
|
|
|
|
}
|
2013-06-06 23:52:43 +03:00
|
|
|
|
|
|
|
return true;
|
2013-06-01 17:20:40 +03:00
|
|
|
}
|
|
|
|
|
2013-09-18 19:37:07 +04:00
|
|
|
GameVar::GameVar() {
|
2013-06-10 01:03:15 +03:00
|
|
|
_subVars = 0;
|
|
|
|
_parentVarObj = 0;
|
|
|
|
_nextVarObj = 0;
|
|
|
|
_prevVarObj = 0;
|
|
|
|
_field_14 = 0;
|
|
|
|
_varType = 0;
|
|
|
|
_value.floatValue = 0;
|
2016-09-19 18:58:39 +02:00
|
|
|
|
|
|
|
_objtype = kObjTypeGameVar;
|
2013-06-10 01:03:15 +03:00
|
|
|
}
|
|
|
|
|
2014-01-08 18:37:39 +02:00
|
|
|
GameVar::~GameVar() {
|
2014-06-12 10:16:14 +03:00
|
|
|
if (_varType == 2)
|
|
|
|
free(_value.stringValue);
|
|
|
|
|
|
|
|
if (_parentVarObj && !_prevVarObj ) {
|
|
|
|
if (_parentVarObj->_subVars == this) {
|
|
|
|
_parentVarObj->_subVars = _nextVarObj;
|
|
|
|
} else if (_parentVarObj->_field_14 == this) {
|
|
|
|
_parentVarObj->_field_14 = _nextVarObj;
|
|
|
|
} else {
|
|
|
|
_parentVarObj = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_prevVarObj)
|
|
|
|
_prevVarObj->_nextVarObj = _nextVarObj;
|
|
|
|
|
|
|
|
if (_nextVarObj)
|
|
|
|
_nextVarObj->_prevVarObj = _prevVarObj;
|
|
|
|
|
|
|
|
_prevVarObj = 0;
|
|
|
|
_nextVarObj = 0;
|
|
|
|
|
|
|
|
GameVar *s = _subVars;
|
|
|
|
|
|
|
|
while (s) {
|
|
|
|
delete s;
|
|
|
|
s = _subVars;
|
|
|
|
}
|
|
|
|
|
|
|
|
s = _field_14;
|
|
|
|
|
|
|
|
while (s) {
|
|
|
|
delete s;
|
|
|
|
s = _field_14;
|
|
|
|
}
|
2014-01-08 18:37:39 +02:00
|
|
|
}
|
|
|
|
|
2013-09-18 19:37:07 +04:00
|
|
|
bool GameVar::load(MfcArchive &file) {
|
2013-07-19 18:13:00 +03:00
|
|
|
_varName = file.readPascalString();
|
2013-06-10 01:03:15 +03:00
|
|
|
_varType = file.readUint32LE();
|
|
|
|
|
2016-07-28 00:36:53 +03:00
|
|
|
debugCN(6, kDebugLoading, "[%03d] ", file.getLevel());
|
2013-06-11 01:34:37 +03:00
|
|
|
for (int i = 0; i < file.getLevel(); i++)
|
2016-07-28 00:36:53 +03:00
|
|
|
debugCN(6, kDebugLoading, " ");
|
2013-06-11 01:34:37 +03:00
|
|
|
|
2017-03-22 04:07:33 +02:00
|
|
|
debugCN(6, kDebugLoading, "<%s>: ", transCyrillic(_varName));
|
2013-06-11 01:34:37 +03:00
|
|
|
|
2013-06-10 01:03:15 +03:00
|
|
|
switch (_varType) {
|
|
|
|
case 0:
|
|
|
|
_value.intValue = file.readUint32LE();
|
2016-07-28 00:36:53 +03:00
|
|
|
debugC(6, kDebugLoading, "d --> %d", _value.intValue);
|
2013-06-10 01:03:15 +03:00
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
_value.intValue = file.readUint32LE(); // FIXME
|
2016-07-28 00:36:53 +03:00
|
|
|
debugC(6, kDebugLoading, "f --> %f", _value.floatValue);
|
2013-06-10 01:03:15 +03:00
|
|
|
break;
|
2017-03-22 04:11:49 +02:00
|
|
|
case 2: {
|
|
|
|
Common::String str = file.readPascalString();
|
|
|
|
_value.stringValue = (char *)calloc(str.size() + 1, 1);
|
|
|
|
Common::strlcpy(_value.stringValue, str.c_str(), str.size() + 1);
|
2016-07-28 00:36:53 +03:00
|
|
|
debugC(6, kDebugLoading, "s --> %s", _value.stringValue);
|
2017-03-22 04:11:49 +02:00
|
|
|
}
|
2013-06-10 01:03:15 +03:00
|
|
|
break;
|
|
|
|
default:
|
2013-06-11 01:17:11 +03:00
|
|
|
error("Unknown var type: %d (0x%x)", _varType, _varType);
|
2013-06-10 01:03:15 +03:00
|
|
|
}
|
|
|
|
|
2013-06-11 01:34:37 +03:00
|
|
|
file.incLevel();
|
2017-11-14 22:30:35 -06:00
|
|
|
_parentVarObj = file.readClass<GameVar>();
|
|
|
|
_prevVarObj = file.readClass<GameVar>();
|
|
|
|
_nextVarObj = file.readClass<GameVar>();
|
|
|
|
_field_14 = file.readClass<GameVar>();
|
|
|
|
_subVars = file.readClass<GameVar>();
|
2013-06-11 01:34:37 +03:00
|
|
|
file.decLevel();
|
2013-06-10 01:03:15 +03:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-03-24 00:35:37 +02:00
|
|
|
GameVar *GameVar::getSubVarByName(const Common::String &name) {
|
2013-09-18 19:37:07 +04:00
|
|
|
GameVar *sv = 0;
|
2013-06-19 14:46:25 -04:00
|
|
|
|
2013-07-06 22:56:11 +03:00
|
|
|
if (_subVars != 0) {
|
|
|
|
sv = _subVars;
|
2017-03-22 04:32:23 +02:00
|
|
|
for (;sv && scumm_stricmp(sv->_varName.c_str(), name.c_str()); sv = sv->_nextVarObj)
|
2013-07-06 22:56:11 +03:00
|
|
|
;
|
|
|
|
}
|
|
|
|
return sv;
|
2013-06-19 14:46:25 -04:00
|
|
|
}
|
|
|
|
|
2017-03-24 00:35:37 +02:00
|
|
|
bool GameVar::setSubVarAsInt(const Common::String &name, int value) {
|
2013-09-18 19:37:07 +04:00
|
|
|
GameVar *var = getSubVarByName(name);
|
2013-06-19 14:46:25 -04:00
|
|
|
|
2013-07-06 22:56:11 +03:00
|
|
|
if (var) {
|
|
|
|
if (var->_varType == 0) {
|
|
|
|
var->_value.intValue = value;
|
2013-06-19 14:46:25 -04:00
|
|
|
|
2013-07-06 22:56:11 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2013-06-19 14:46:25 -04:00
|
|
|
|
2013-09-18 19:37:07 +04:00
|
|
|
var = new GameVar();
|
2013-07-06 22:56:11 +03:00
|
|
|
var->_varType = 0;
|
|
|
|
var->_value.intValue = value;
|
2017-03-22 04:11:49 +02:00
|
|
|
var->_varName = name;
|
2013-06-19 14:46:25 -04:00
|
|
|
|
2013-07-06 22:56:11 +03:00
|
|
|
return addSubVar(var);
|
2013-06-19 14:46:25 -04:00
|
|
|
}
|
|
|
|
|
2017-03-24 00:35:37 +02:00
|
|
|
int GameVar::getSubVarAsInt(const Common::String &name) {
|
2013-09-18 19:37:07 +04:00
|
|
|
GameVar *var = getSubVarByName(name);
|
2013-06-19 14:46:25 -04:00
|
|
|
|
2013-07-06 22:56:11 +03:00
|
|
|
if (var)
|
|
|
|
return var->_value.intValue;
|
|
|
|
else
|
|
|
|
return 0;
|
2013-06-19 14:46:25 -04:00
|
|
|
}
|
|
|
|
|
2017-03-24 00:35:37 +02:00
|
|
|
GameVar *GameVar::addSubVarAsInt(const Common::String &name, int value) {
|
2013-07-06 22:56:11 +03:00
|
|
|
if (getSubVarByName(name)) {
|
|
|
|
return 0;
|
|
|
|
} else {
|
2013-09-18 19:37:07 +04:00
|
|
|
GameVar *var = new GameVar();
|
2013-06-19 14:46:25 -04:00
|
|
|
|
2013-07-06 22:56:11 +03:00
|
|
|
var->_varType = 0;
|
|
|
|
var->_value.intValue = value;
|
2013-06-19 14:46:25 -04:00
|
|
|
|
2017-03-22 04:11:49 +02:00
|
|
|
var->_varName = name;
|
2013-06-19 14:46:25 -04:00
|
|
|
|
2013-07-06 22:56:11 +03:00
|
|
|
return (addSubVar(var) != 0) ? var : 0;
|
|
|
|
}
|
2013-06-19 14:46:25 -04:00
|
|
|
}
|
|
|
|
|
2013-09-18 19:37:07 +04:00
|
|
|
bool GameVar::addSubVar(GameVar *subvar) {
|
|
|
|
GameVar *var = _subVars;
|
2013-06-19 14:46:25 -04:00
|
|
|
|
2013-07-06 22:56:11 +03:00
|
|
|
if (var) {
|
2013-09-18 19:37:07 +04:00
|
|
|
for (GameVar *i = var->_nextVarObj; i; i = i->_nextVarObj)
|
2013-07-06 22:56:11 +03:00
|
|
|
var = i;
|
2013-06-19 14:46:25 -04:00
|
|
|
|
2013-07-06 22:56:11 +03:00
|
|
|
var->_nextVarObj = subvar;
|
|
|
|
subvar->_prevVarObj = var;
|
2013-08-02 01:37:50 +03:00
|
|
|
subvar->_parentVarObj = this;
|
2013-06-19 14:46:25 -04:00
|
|
|
|
2013-07-06 22:56:11 +03:00
|
|
|
return true;
|
|
|
|
} else {
|
2013-08-02 01:37:50 +03:00
|
|
|
_subVars = subvar;
|
|
|
|
subvar->_parentVarObj = this;
|
2013-06-19 14:46:25 -04:00
|
|
|
|
2013-07-06 22:56:11 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2013-06-19 14:46:25 -04:00
|
|
|
}
|
|
|
|
|
2013-09-18 19:37:07 +04:00
|
|
|
int GameVar::getSubVarsCount() {
|
2013-07-28 15:53:43 +03:00
|
|
|
int res;
|
2013-09-18 19:37:07 +04:00
|
|
|
GameVar *sub = _subVars;
|
2013-07-28 15:53:43 +03:00
|
|
|
|
|
|
|
for (res = 0; sub; res++)
|
|
|
|
sub = sub->_nextVarObj;
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2013-09-18 19:37:07 +04:00
|
|
|
GameVar *GameVar::getSubVarByIndex(int idx) {
|
|
|
|
GameVar *sub = _subVars;
|
2013-08-14 09:30:30 +03:00
|
|
|
|
|
|
|
while (idx--) {
|
|
|
|
sub = sub->_nextVarObj;
|
|
|
|
|
|
|
|
if (!sub)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return sub;
|
|
|
|
}
|
|
|
|
|
2013-06-18 17:07:28 -04:00
|
|
|
bool PicAniInfo::load(MfcArchive &file) {
|
2016-07-28 00:36:53 +03:00
|
|
|
debugC(5, kDebugLoading, "PicAniInfo::load()");
|
2013-07-12 09:03:02 +03:00
|
|
|
|
2013-07-06 22:56:11 +03:00
|
|
|
type = file.readUint32LE();
|
|
|
|
objectId = file.readUint16LE();
|
|
|
|
field_6 = file.readUint16LE();
|
|
|
|
field_8 = file.readUint32LE();
|
2013-08-06 01:50:16 +03:00
|
|
|
sceneId = file.readUint16LE();
|
2013-07-06 22:56:11 +03:00
|
|
|
field_E = file.readUint16LE();
|
2016-08-29 22:23:45 +02:00
|
|
|
ox = file.readSint32LE();
|
|
|
|
oy = file.readSint32LE();
|
2013-07-06 22:56:11 +03:00
|
|
|
priority = file.readUint32LE();
|
|
|
|
staticsId = file.readUint16LE();
|
|
|
|
movementId = file.readUint16LE();
|
|
|
|
dynamicPhaseIndex = file.readUint16LE();
|
|
|
|
flags = file.readUint16LE();
|
|
|
|
field_24 = file.readUint32LE();
|
|
|
|
someDynamicPhaseIndex = file.readUint32LE();
|
|
|
|
|
|
|
|
return true;
|
2013-06-18 17:07:28 -04:00
|
|
|
}
|
|
|
|
|
2013-06-01 13:01:25 +03:00
|
|
|
} // End of namespace Fullpipe
|