Skip to content

Commit

Permalink
FULLPIPE: Further work on game saving
Browse files Browse the repository at this point in the history
  • Loading branch information
sev- committed Sep 16, 2016
1 parent 1b335b6 commit 60e3b9f
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 60 deletions.
102 changes: 44 additions & 58 deletions engines/fullpipe/gameloader.cpp
Expand Up @@ -66,7 +66,7 @@ GameLoader::GameLoader() {
_field_F8 = 0;
_sceneSwitcher = 0;
_preloadCallback = 0;
_readSavegameCallback = 0;
_savegameCallback = 0;
_gameVar = 0;
_preloadSceneId = 0;
_preloadEntranceId = 0;
Expand Down Expand Up @@ -614,7 +614,7 @@ void GameLoader::writeSavegame(Scene *sc, const char *fname) {
GameVar *v = _gameVar->getSubVarByName("OBJSTATES")->getSubVarByName("SAVEGAME");

if (!v) {
// v = _gameVar->getSubVarByName("OBJSTATES")->getSubVarAsInt("SAVEGAME", 0);
v = _gameVar->getSubVarByName("OBJSTATES")->addSubVarAsInt("SAVEGAME", 0);

if (!v) {
warning("No state to save");
Expand All @@ -626,8 +626,7 @@ void GameLoader::writeSavegame(Scene *sc, const char *fname) {

v->setSubVarAsInt("Scene", sc->_sceneId);

#if 0
saveScenePicAniInfos(this, sc->_sceneId);
saveScenePicAniInfos(sc->_sceneId);
memset(&header, 0, sizeof(header));

header.saveSize = 48;
Expand All @@ -636,68 +635,55 @@ void GameLoader::writeSavegame(Scene *sc, const char *fname) {
header.unkField = 1;

// open save for reading
v = _gameVar->getSubVarByName("OBJSTATES");
Common::OutSaveFile *saveFile = g_system->getSavefileManager()->openForSaving(fname);

MfcArchive archive;
v = _gameVar->getSubVarByName("OBJSTATES");

sca = 0;
filenamea = 0;
GameVar *nxt = 0;
GameVar *prv = 0;
GameVar *par;
if (v) {
v12 = v11->_nextVarObj;
v13 = (char *)v11->prevVarObj;
v9 = v11->parentVarObj;
v11->parentVarObj = 0;
sca = (Scene *)v12;
v11->_nextVarObj = 0;
filenamea = v13;
v11->prevVarObj = 0;
nxt = v->_nextVarObj;
prv = v->_prevVarObj;
par = v->_parentVarObj;
v->_parentVarObj = 0;
v->_nextVarObj = 0;
v->_prevVarObj = 0;
}

carchive->writeObject(v);
if (v11) {
v11->parentVarObj = v9;
v11->_nextVarObj = (GameVar *)sca;
v11->prevVarObj = (GameVar *)filenamea;
writeObject(saveFile, v);

if (v) {
v->_parentVarObj = par;
v->_nextVarObj = nxt;
v->_prevVarObj = prv;
}
v14 = getGameLoaderInventory();
Inventory2_SerializePartially(v14, &carchive);
v15 = this->_sc2array.objs.m_nSize;
if (unsigned int)(carchive.m_lpBufCur + 4) > carchive.m_lpBufMax)
CArchive::Flush(&carchive);
*(_DWORD *)carchive.m_lpBufCur = v15;
v16 = 0;
carchive.m_lpBufCur += 4;
while (1) {
scb = (Scene *)v16;
if ( v16 >= this->_sc2array.objs.m_nSize )
break;
v17 = v16;
v18 = this->_sc2array.objs.m_pData[v16].picAniInfosCount;
if ( (unsigned int)(carchive.m_lpBufCur + 4) > carchive.m_lpBufMax ) {
CArchive::Flush(&carchive);
v16 = (int)scb;
}
*(_DWORD *)carchive.m_lpBufCur = v18;
v19 = &this->_sc2array.objs.m_pData[v17];
carchive.m_lpBufCur += 4;
v20 = v19->picAniInfosCount;
if ( v20 > 0 ) {
CArchive::Write(&carchive, v19->picAniInfos, 44 * v20);
v16 = (int)scb;

getGameLoaderInventory()->writePartial(saveFile);

saveFile->writeUint32LE(_sc2array.size());

for (uint i = 0; i < _sc2array.size(); i++) {
saveFile->writeUint32LE(_sc2array[i]._picAniInfosCount);

for (uint j = 0; j < _sc2array[i]._picAniInfosCount; j++) {
_sc2array[i]._picAniInfos[j]->save(saveFile);
}
++v16;
}
CArchive::Close(&carchive);
header.encSize = GameLoader_encryptSavegame((GameLoader *)header.unkField, (int)&cmemfile);
CFile::Write((int)&cfile, (int)&header, header.saveSize);
v21 = (void *)CMemFile::Detach(&cmemfile);
CFile::Write((int)&cfile, (int)v21, header.encSize);
free(v21);
v22 = (void (__fastcall *)(char *, signed int))this->_readSavegameCallback;
if ( v22 )
v22(&cfile, 1);
CFile::Close(&cfile);
#endif

//header.encSize = GameLoader_encryptSavegame((GameLoader *)header.unkField, (int)&cmemfile);
//CFile::Write((int)&cfile, (int)&header, header.saveSize);

//if (_savegameCallback)
// _savegameCallback(saveFile, 1);

saveFile->finalize();

delete saveFile;
}

void GameLoader::writeObject(Common::WriteStream *stream, GameVar *) {
warning("STUB: GameLoader::writeObject()");
}

Sc2::Sc2() {
Expand Down
4 changes: 3 additions & 1 deletion engines/fullpipe/gameloader.h
Expand Up @@ -101,6 +101,8 @@ class GameLoader : public CObject {
void readSavegame(const char *fname);
void writeSavegame(Scene *sc, const char *fname);

void writeObject(Common::WriteStream *stream, GameVar *);

void restoreDefPicAniInfos();

GameProject *_gameProject;
Expand All @@ -110,7 +112,7 @@ class GameLoader : public CObject {
Sc2Array _sc2array;
void *_sceneSwitcher;
bool (*_preloadCallback)(PreloadItem &pre, int flag);
void *_readSavegameCallback;
void *_savegameCallback;
int16 _field_F8;
int16 _field_FA;
PreloadItems _preloadItems;
Expand Down
5 changes: 5 additions & 0 deletions engines/fullpipe/inventory.cpp
Expand Up @@ -106,6 +106,11 @@ bool Inventory2::loadPartial(MfcArchive &file) { // Inventory2_SerializePartiall
return true;
}

bool Inventory2::writePartial(Common::WriteStream *file) {
warning("STUB: nventory2::writePartial()");
return true;
}

void Inventory2::addItem(int itemId, int count) {
if (getInventoryPoolItemIndexById(itemId) >= 0)
_inventoryItems.push_back(new InventoryItem(itemId, count));
Expand Down
1 change: 1 addition & 0 deletions engines/fullpipe/inventory.h
Expand Up @@ -101,6 +101,7 @@ class Inventory2 : public Inventory {
virtual ~Inventory2();

bool loadPartial(MfcArchive &file);
bool writePartial(Common::WriteStream *file);
void addItem(int itemId, int count);
void addItem2(StaticANIObject *obj);
void removeItem(int itemId, int count);
Expand Down
1 change: 1 addition & 0 deletions engines/fullpipe/module.mk
Expand Up @@ -23,6 +23,7 @@ MODULE_OBJS = \
scenes.o \
sound.o \
stateloader.o \
statesaver.o \
statics.o \
utils.o \
scenes/sceneIntro.o \
Expand Down
1 change: 1 addition & 0 deletions engines/fullpipe/objects.h
Expand Up @@ -61,6 +61,7 @@ struct PicAniInfo {
int32 someDynamicPhaseIndex;

bool load(MfcArchive &file);
bool save(Common::WriteStream *file);

PicAniInfo() { memset(this, 0, sizeof(PicAniInfo)); }
};
Expand Down
2 changes: 1 addition & 1 deletion engines/fullpipe/stateloader.cpp
Expand Up @@ -60,7 +60,7 @@ bool FullpipeEngine::loadGam(const char *fname, int scene) {

// _sceneSwitcher = sceneSwitcher; // substituted with direct call
_gameLoader->_preloadCallback = preloadCallback;
// _readSavegameCallback = gameLoaderReadSavegameCallback; // TODO
// _savegameCallback = gameLoaderSavegameCallback; // TODO

_aniMan = accessScene(SC_COMMON)->getAniMan();
_scene2 = 0;
Expand Down
51 changes: 51 additions & 0 deletions engines/fullpipe/statesaver.cpp
@@ -0,0 +1,51 @@
/* 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.
*
* 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.
*
* 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.
*
*/

#include "fullpipe/fullpipe.h"

#include "fullpipe/objects.h"

namespace Fullpipe {

bool PicAniInfo::save(Common::WriteStream *file) {
debugC(5, kDebugLoading, "PicAniInfo::save()");

file->writeUint32LE(type);
file->writeUint16LE(objectId);
file->writeUint16LE(field_6);
file->writeUint32LE(field_8);
file->writeUint16LE(sceneId);
file->writeUint16LE(field_E);
file->writeSint32LE(ox);
file->writeSint32LE(oy);
file->writeUint32LE(priority);
file->writeUint16LE(staticsId);
file->writeUint16LE(movementId);
file->writeUint16LE(dynamicPhaseIndex);
file->writeUint16LE(flags);
file->writeUint32LE(field_24);
file->writeUint32LE(someDynamicPhaseIndex);

return true;
}

} // End of namespace Fullpipe

0 comments on commit 60e3b9f

Please sign in to comment.