2007-05-30 21:56:52 +00: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.
|
2003-07-28 01:44:38 +00:00
|
|
|
*
|
2007-05-31 20:28:29 +00:00
|
|
|
* Additional copyright for this file:
|
|
|
|
* Copyright (C) 1994-1998 Revolution Software Ltd.
|
|
|
|
*
|
2003-07-28 01:44:38 +00: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 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
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2003-07-28 01:44:38 +00:00
|
|
|
*/
|
|
|
|
|
2003-09-20 17:48:53 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
2003-07-28 01:44:38 +00:00
|
|
|
// SAVE_REST.CPP save, restore & restart functions
|
|
|
|
//
|
|
|
|
// James 05feb97
|
|
|
|
//
|
|
|
|
// "Jesus Saves", but could he Restore or Restart? He can now...
|
|
|
|
//
|
2003-09-20 17:48:53 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2010-11-23 22:27:40 +00:00
|
|
|
#include "common/memstream.h"
|
2005-01-10 22:06:49 +00:00
|
|
|
#include "common/savefile.h"
|
2011-04-24 08:34:27 +00:00
|
|
|
#include "common/textconsole.h"
|
2006-02-17 15:07:36 +00:00
|
|
|
|
2003-11-08 18:15:35 +00:00
|
|
|
#include "sword2/sword2.h"
|
2003-10-28 19:51:30 +00:00
|
|
|
#include "sword2/defs.h"
|
2006-02-17 15:07:36 +00:00
|
|
|
#include "sword2/header.h"
|
2004-02-05 14:19:07 +00:00
|
|
|
#include "sword2/logic.h"
|
2006-02-17 15:07:36 +00:00
|
|
|
#include "sword2/object.h"
|
2005-02-19 14:02:16 +00:00
|
|
|
#include "sword2/mouse.h"
|
2004-02-05 14:19:07 +00:00
|
|
|
#include "sword2/resman.h"
|
2006-02-17 15:07:36 +00:00
|
|
|
#include "sword2/saveload.h"
|
|
|
|
#include "sword2/screen.h"
|
2004-11-14 15:00:01 +00:00
|
|
|
#include "sword2/sound.h"
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-10-04 00:52:27 +00:00
|
|
|
namespace Sword2 {
|
|
|
|
|
2011-06-02 03:38:47 +00:00
|
|
|
Common::String Sword2Engine::getSaveFileName(uint16 slotNo) {
|
|
|
|
return Common::String::format("%s.%.3d", _targetName.c_str(), slotNo);
|
2006-07-22 09:05:13 +00:00
|
|
|
}
|
2003-07-28 01:44:38 +00:00
|
|
|
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
/**
|
2006-07-22 09:05:13 +00:00
|
|
|
* Calculate size of required savegame buffer. A savegame consists of a header
|
|
|
|
* and the global variables.
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
*/
|
2003-09-13 13:04:55 +00:00
|
|
|
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
uint32 Sword2Engine::findBufferSize() {
|
|
|
|
return 212 + _resman->fetchLen(1);
|
2003-09-13 13:04:55 +00:00
|
|
|
}
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-04-26 07:37:25 +00:00
|
|
|
/**
|
|
|
|
* Save the game.
|
|
|
|
*/
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2009-05-06 09:12:24 +00:00
|
|
|
uint32 Sword2Engine::saveGame(uint16 slotNo, const byte *desc) {
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
char description[SAVE_DESCRIPTION_LEN];
|
2004-04-26 07:37:25 +00:00
|
|
|
uint32 bufferSize = findBufferSize();
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
byte *saveBuffer = (byte *)malloc(bufferSize);
|
|
|
|
ScreenInfo *screenInfo = _screen->getScreenInfo();
|
|
|
|
|
|
|
|
memset(description, 0, sizeof(description));
|
2009-05-06 09:12:24 +00:00
|
|
|
strncpy(description, (const char *)desc, SAVE_DESCRIPTION_LEN - 1);
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
|
|
|
|
Common::MemoryWriteStream writeS(saveBuffer, bufferSize);
|
|
|
|
|
|
|
|
byte *globalVars = _resman->openResource(1);
|
|
|
|
byte *objectHub = _resman->openResource(CUR_PLAYER_ID) + ResHeader::size();
|
2003-07-28 01:44:38 +00:00
|
|
|
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
// Script no. 7 - 'george_savedata_request' calls fnPassPlayerSaveData
|
|
|
|
_logic->runResScript(CUR_PLAYER_ID, 7);
|
|
|
|
|
|
|
|
writeS.writeUint32LE(0); // Checksum
|
|
|
|
writeS.write(description, SAVE_DESCRIPTION_LEN);
|
|
|
|
writeS.writeUint32LE(_resman->fetchLen(1));
|
|
|
|
writeS.writeUint32LE(screenInfo->background_layer_id);
|
|
|
|
writeS.writeUint32LE(_logic->getRunList());
|
|
|
|
writeS.writeUint32LE(screenInfo->feet_x);
|
|
|
|
writeS.writeUint32LE(screenInfo->feet_y);
|
|
|
|
writeS.writeUint32LE(_sound->getLoopingMusicId());
|
|
|
|
writeS.write(objectHub, ObjectHub::size());
|
|
|
|
writeS.write(_logic->_saveLogic, ObjectLogic::size());
|
|
|
|
writeS.write(_logic->_saveGraphic, ObjectGraphic::size());
|
|
|
|
writeS.write(_logic->_saveMega, ObjectMega::size());
|
|
|
|
writeS.write(globalVars, _resman->fetchLen(1));
|
|
|
|
|
|
|
|
WRITE_LE_UINT32(saveBuffer, calcChecksum(saveBuffer + 4, bufferSize - 4));
|
|
|
|
|
|
|
|
_resman->closeResource(CUR_PLAYER_ID);
|
|
|
|
_resman->closeResource(1);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
uint32 errorCode = saveData(slotNo, saveBuffer, bufferSize);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
free(saveBuffer);
|
2005-02-20 15:38:48 +00:00
|
|
|
|
|
|
|
if (errorCode != SR_OK) {
|
|
|
|
uint32 textId;
|
|
|
|
|
|
|
|
switch (errorCode) {
|
|
|
|
case SR_ERR_FILEOPEN:
|
2005-02-28 13:22:31 +00:00
|
|
|
textId = TEXT_SAVE_CANT_OPEN;
|
2005-02-20 15:38:48 +00:00
|
|
|
break;
|
2005-02-28 13:22:31 +00:00
|
|
|
default:
|
|
|
|
textId = TEXT_SAVE_FAILED;
|
2005-02-20 15:38:48 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
_screen->displayMsg(fetchTextLine(_resman->openResource(textId / SIZE), textId & 0xffff) + 2, 0);
|
|
|
|
}
|
|
|
|
|
2003-09-20 17:48:53 +00:00
|
|
|
return errorCode;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
uint32 Sword2Engine::saveData(uint16 slotNo, byte *buffer, uint32 bufferSize) {
|
2011-06-02 03:38:47 +00:00
|
|
|
Common::String saveFileName = getSaveFileName(slotNo);
|
2004-04-26 07:37:25 +00:00
|
|
|
|
2005-05-10 23:17:38 +00:00
|
|
|
Common::OutSaveFile *out;
|
2004-04-26 07:37:25 +00:00
|
|
|
|
2005-04-10 15:13:40 +00:00
|
|
|
if (!(out = _saveFileMan->openForSaving(saveFileName))) {
|
2003-09-20 17:48:53 +00:00
|
|
|
return SR_ERR_FILEOPEN;
|
|
|
|
}
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2005-11-05 14:24:13 +00:00
|
|
|
out->write(buffer, bufferSize);
|
2007-02-17 18:55:51 +00:00
|
|
|
out->finalize();
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2009-05-19 11:42:14 +00:00
|
|
|
if (!out->err()) {
|
2005-11-05 14:24:13 +00:00
|
|
|
delete out;
|
2003-09-20 17:48:53 +00:00
|
|
|
return SR_OK;
|
2005-11-05 14:24:13 +00:00
|
|
|
}
|
2003-08-23 14:33:57 +00:00
|
|
|
|
2005-11-05 14:24:13 +00:00
|
|
|
delete out;
|
2003-09-20 17:48:53 +00:00
|
|
|
return SR_ERR_WRITEFAIL;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2004-04-26 07:37:25 +00:00
|
|
|
/**
|
|
|
|
* Restore the game.
|
|
|
|
*/
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-03 07:47:42 +00:00
|
|
|
uint32 Sword2Engine::restoreGame(uint16 slotNo) {
|
2004-04-26 07:37:25 +00:00
|
|
|
uint32 bufferSize = findBufferSize();
|
2005-05-12 13:12:15 +00:00
|
|
|
byte *saveBufferMem = (byte *)malloc(bufferSize);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-04-26 07:37:25 +00:00
|
|
|
uint32 errorCode = restoreData(slotNo, saveBufferMem, bufferSize);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-04-26 07:37:25 +00:00
|
|
|
// If it was read in successfully, then restore the game from the
|
|
|
|
// buffer & free the buffer. Note that restoreFromBuffer() frees the
|
|
|
|
// buffer in order to clear it from memory before loading in the new
|
|
|
|
// screen and runlist, so we only need to free it in case of failure.
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-04-26 07:37:25 +00:00
|
|
|
if (errorCode == SR_OK)
|
2003-11-03 07:47:42 +00:00
|
|
|
errorCode = restoreFromBuffer(saveBufferMem, bufferSize);
|
2004-04-26 07:37:25 +00:00
|
|
|
else
|
2004-04-23 07:02:11 +00:00
|
|
|
free(saveBufferMem);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2005-02-20 15:38:48 +00:00
|
|
|
if (errorCode != SR_OK) {
|
|
|
|
uint32 textId;
|
|
|
|
|
|
|
|
switch (errorCode) {
|
|
|
|
case SR_ERR_FILEOPEN:
|
2005-02-28 13:22:31 +00:00
|
|
|
textId = TEXT_RESTORE_CANT_OPEN;
|
2005-02-20 15:38:48 +00:00
|
|
|
break;
|
|
|
|
case SR_ERR_INCOMPATIBLE:
|
2005-02-28 13:22:31 +00:00
|
|
|
textId = TEXT_RESTORE_INCOMPATIBLE;
|
2005-02-20 15:38:48 +00:00
|
|
|
break;
|
2005-02-28 13:22:31 +00:00
|
|
|
default:
|
|
|
|
textId = TEXT_RESTORE_FAILED;
|
2005-02-20 15:38:48 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
_screen->displayMsg(fetchTextLine(_resman->openResource(textId / SIZE), textId & 0xffff) + 2, 0);
|
|
|
|
} else {
|
|
|
|
// Prime system with a game cycle
|
|
|
|
|
|
|
|
// Reset the graphic 'BuildUnit' list before a new logic list
|
|
|
|
// (see fnRegisterFrame)
|
|
|
|
_screen->resetRenderLists();
|
|
|
|
|
|
|
|
// Reset the mouse hot-spot list. See fnRegisterMouse()
|
|
|
|
// and fnRegisterFrame()
|
|
|
|
_mouse->resetMouseList();
|
|
|
|
|
|
|
|
if (_logic->processSession())
|
|
|
|
error("restore 1st cycle failed??");
|
|
|
|
}
|
|
|
|
|
2004-03-28 13:13:16 +00:00
|
|
|
// Force the game engine to pick a cursor. This appears to be needed
|
|
|
|
// when using the -x command-line option to restore a game.
|
2005-02-19 14:02:16 +00:00
|
|
|
_mouse->setMouseTouching(1);
|
2003-09-20 17:48:53 +00:00
|
|
|
return errorCode;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
uint32 Sword2Engine::restoreData(uint16 slotNo, byte *buffer, uint32 bufferSize) {
|
2011-06-02 03:38:47 +00:00
|
|
|
Common::String saveFileName = getSaveFileName(slotNo);
|
2003-09-20 17:48:53 +00:00
|
|
|
|
2005-05-10 23:17:38 +00:00
|
|
|
Common::InSaveFile *in;
|
2004-04-26 07:37:25 +00:00
|
|
|
|
2005-04-10 15:13:40 +00:00
|
|
|
if (!(in = _saveFileMan->openForLoading(saveFileName))) {
|
2003-09-20 17:48:53 +00:00
|
|
|
// error: couldn't open file
|
|
|
|
return SR_ERR_FILEOPEN;
|
|
|
|
}
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-04-26 07:37:25 +00:00
|
|
|
// Read savegame into the buffer
|
|
|
|
uint32 itemsRead = in->read(buffer, bufferSize);
|
2003-08-23 14:33:57 +00:00
|
|
|
|
2004-04-26 07:37:25 +00:00
|
|
|
delete in;
|
|
|
|
|
|
|
|
if (itemsRead != bufferSize) {
|
|
|
|
// We didn't get all of it. At the moment we have no way of
|
|
|
|
// knowing why, so assume that it's an incompatible savegame.
|
2003-09-20 17:48:53 +00:00
|
|
|
|
|
|
|
return SR_ERR_INCOMPATIBLE;
|
|
|
|
}
|
2004-04-26 07:37:25 +00:00
|
|
|
|
|
|
|
return SR_OK;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
uint32 Sword2Engine::restoreFromBuffer(byte *buffer, uint32 size) {
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
Common::MemoryReadStream readS(buffer, size);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-20 17:48:53 +00:00
|
|
|
// Calc checksum & check that aginst the value stored in the header
|
2003-07-28 01:44:38 +00:00
|
|
|
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
if (readS.readUint32LE() != calcChecksum(buffer + 4, size - 4)) {
|
2004-04-23 07:02:11 +00:00
|
|
|
free(buffer);
|
2003-09-20 17:48:53 +00:00
|
|
|
return SR_ERR_INCOMPATIBLE;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
2003-09-20 17:48:53 +00:00
|
|
|
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
readS.seek(SAVE_DESCRIPTION_LEN, SEEK_CUR);
|
|
|
|
|
2004-04-26 07:37:25 +00:00
|
|
|
// Check savegame against length of current global variables resource
|
2003-09-20 17:48:53 +00:00
|
|
|
// This would most probably be trapped by the checksum test anyway,
|
2004-04-26 07:37:25 +00:00
|
|
|
// but it doesn't do any harm to check this as well.
|
2003-09-20 17:48:53 +00:00
|
|
|
|
2004-04-26 07:37:25 +00:00
|
|
|
// Historical note: During development, earlier savegames would often
|
|
|
|
// be shorter than the current expected length.
|
2003-07-28 01:44:38 +00:00
|
|
|
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
if (readS.readUint32LE() != _resman->fetchLen(1)) {
|
2004-04-23 07:02:11 +00:00
|
|
|
free(buffer);
|
2003-09-20 17:48:53 +00:00
|
|
|
return SR_ERR_INCOMPATIBLE;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
2003-09-20 17:48:53 +00:00
|
|
|
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
byte *globalVars = _resman->openResource(1);
|
|
|
|
byte *objectHub = _resman->openResource(CUR_PLAYER_ID) + ResHeader::size();
|
|
|
|
|
|
|
|
uint32 screenId = readS.readUint32LE();
|
|
|
|
uint32 runListId = readS.readUint32LE();
|
|
|
|
uint32 feetX = readS.readUint32LE();
|
|
|
|
uint32 feetY = readS.readUint32LE();
|
|
|
|
uint32 musicId = readS.readUint32LE();
|
2003-09-20 17:48:53 +00:00
|
|
|
|
2004-04-26 07:37:25 +00:00
|
|
|
// Trash all resources from memory except player object & global vars
|
2003-11-16 14:18:29 +00:00
|
|
|
_resman->killAll(false);
|
2003-11-15 09:38:00 +00:00
|
|
|
_logic->resetKillList();
|
2005-07-30 21:11:48 +00:00
|
|
|
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
readS.read(objectHub, ObjectHub::size());
|
|
|
|
readS.read(_logic->_saveLogic, ObjectLogic::size());
|
|
|
|
readS.read(_logic->_saveGraphic, ObjectGraphic::size());
|
|
|
|
readS.read(_logic->_saveMega, ObjectMega::size());
|
2003-09-20 17:48:53 +00:00
|
|
|
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
// Fill out the player object structures from the savegame structures.
|
|
|
|
// Also run the appropriate scripts to set up George's anim tables and
|
|
|
|
// walkdata, and Nico's anim tables.
|
2003-07-28 01:44:38 +00:00
|
|
|
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
// Script no. 8 - 'george_savedata_return' calls fnGetPlayerSaveData
|
|
|
|
_logic->runResScript(CUR_PLAYER_ID, 8);
|
2003-09-20 17:48:53 +00:00
|
|
|
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
// Script no. 14 - 'set_up_nico_anim_tables'
|
|
|
|
_logic->runResScript(CUR_PLAYER_ID, 14);
|
2003-09-20 17:48:53 +00:00
|
|
|
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
// Which megaset was the player at the time of saving?
|
|
|
|
ObjectMega obMega(_logic->_saveMega);
|
2003-09-20 17:48:53 +00:00
|
|
|
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
uint32 scriptNo = 0;
|
2003-09-20 17:48:53 +00:00
|
|
|
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
switch (obMega.getMegasetRes()) {
|
|
|
|
case 36: // GeoMega:
|
|
|
|
scriptNo = 9; // script no.9 - 'player_is_george'
|
|
|
|
break;
|
|
|
|
case 2003: // GeoMegaB:
|
|
|
|
scriptNo = 13; // script no.13 - 'player_is_georgeB'
|
|
|
|
break;
|
|
|
|
case 1366: // NicMegaA:
|
|
|
|
scriptNo = 11; // script no.11 - 'player_is_nicoA'
|
|
|
|
break;
|
|
|
|
case 1437: // NicMegaB:
|
|
|
|
scriptNo = 12; // script no.12 - 'player_is_nicoB'
|
|
|
|
break;
|
|
|
|
case 1575: // NicMegaC:
|
|
|
|
scriptNo = 10; // script no.10 - 'player_is_nicoC'
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
_logic->runResScript(CUR_PLAYER_ID, scriptNo);
|
|
|
|
|
|
|
|
// Copy variables from savegame buffer to memory
|
|
|
|
readS.read(globalVars, _resman->fetchLen(1));
|
2003-07-28 01:44:38 +00:00
|
|
|
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
_resman->closeResource(CUR_PLAYER_ID);
|
2008-01-28 00:14:17 +00:00
|
|
|
_resman->closeResource(1);
|
2003-09-20 17:48:53 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
free(buffer);
|
2003-09-20 17:48:53 +00:00
|
|
|
|
2004-04-26 07:37:25 +00:00
|
|
|
int32 pars[2];
|
|
|
|
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
pars[0] = screenId;
|
2003-07-28 01:44:38 +00:00
|
|
|
pars[1] = 1;
|
2003-11-15 09:38:00 +00:00
|
|
|
_logic->fnInitBackground(pars);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2005-02-19 14:02:16 +00:00
|
|
|
ScreenInfo *screenInfo = _screen->getScreenInfo();
|
|
|
|
|
2003-10-18 08:11:50 +00:00
|
|
|
// So palette not restored immediately after control panel - we want to
|
|
|
|
// fade up instead!
|
2005-02-19 14:02:16 +00:00
|
|
|
screenInfo->new_palette = 99;
|
2003-09-20 17:48:53 +00:00
|
|
|
|
2004-04-26 07:37:25 +00:00
|
|
|
// These need setting after the defaults get set in fnInitBackground.
|
|
|
|
// Remember that these can change through the game, so need saving &
|
|
|
|
// restoring too.
|
|
|
|
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
screenInfo->feet_x = feetX;
|
|
|
|
screenInfo->feet_y = feetY;
|
2003-09-20 17:48:53 +00:00
|
|
|
|
2004-04-26 07:37:25 +00:00
|
|
|
// Start the new run list
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
_logic->expressChangeSession(runListId);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-20 17:48:53 +00:00
|
|
|
// Force in the new scroll position, so unsightly scroll-catch-up does
|
|
|
|
// not occur when screen first draws after returning from restore panel
|
|
|
|
|
2005-02-19 14:02:16 +00:00
|
|
|
// Set the screen record of player position - ready for setScrolling()
|
2003-09-20 17:48:53 +00:00
|
|
|
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
screenInfo->player_feet_x = obMega.getFeetX();
|
|
|
|
screenInfo->player_feet_y = obMega.getFeetY();
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-20 17:48:53 +00:00
|
|
|
// if this screen is wide, recompute the scroll offsets now
|
2005-02-19 14:02:16 +00:00
|
|
|
if (screenInfo->scroll_flag)
|
|
|
|
_screen->setScrolling();
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-20 17:48:53 +00:00
|
|
|
// Any music required will be started after we've returned from
|
2004-01-04 14:59:36 +00:00
|
|
|
// restoreControl() - see systemMenuMouse() in mouse.cpp!
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-03-27 12:07:07 +00:00
|
|
|
// Restart any looping music. Originally this was - and still is - done
|
|
|
|
// in systemMenuMouse(), but with ScummVM we have other ways of
|
|
|
|
// restoring savegames so it's easier to put it here as well.
|
|
|
|
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
if (musicId) {
|
|
|
|
pars[0] = musicId;
|
2004-03-27 12:07:07 +00:00
|
|
|
pars[1] = FX_LOOP;
|
|
|
|
_logic->fnPlayMusic(pars);
|
|
|
|
} else
|
|
|
|
_logic->fnStopMusic(NULL);
|
|
|
|
|
2003-09-20 17:48:53 +00:00
|
|
|
return SR_OK;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2004-04-26 07:37:25 +00:00
|
|
|
/**
|
|
|
|
* Get the description of a savegame
|
|
|
|
*/
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
uint32 Sword2Engine::getSaveDescription(uint16 slotNo, byte *description) {
|
2011-06-02 03:38:47 +00:00
|
|
|
Common::String saveFileName = getSaveFileName(slotNo);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2005-05-10 23:17:38 +00:00
|
|
|
Common::InSaveFile *in;
|
2004-04-26 07:37:25 +00:00
|
|
|
|
2005-04-10 15:13:40 +00:00
|
|
|
if (!(in = _saveFileMan->openForLoading(saveFileName))) {
|
2003-09-20 17:48:53 +00:00
|
|
|
return SR_ERR_FILEOPEN;
|
|
|
|
}
|
2003-07-28 01:44:38 +00:00
|
|
|
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
in->readUint32LE();
|
|
|
|
in->read(description, SAVE_DESCRIPTION_LEN);
|
2004-04-26 07:37:25 +00:00
|
|
|
|
2003-08-23 14:33:57 +00:00
|
|
|
delete in;
|
2003-09-20 17:48:53 +00:00
|
|
|
return SR_OK;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2005-05-02 05:41:01 +00:00
|
|
|
bool Sword2Engine::saveExists() {
|
2008-10-13 04:24:18 +00:00
|
|
|
Common::String pattern = _targetName + ".???";
|
2010-03-18 15:54:40 +00:00
|
|
|
Common::StringArray filenames = _saveFileMan->listSavefiles(pattern);
|
2008-10-13 04:24:18 +00:00
|
|
|
|
|
|
|
return !filenames.empty();
|
2004-03-04 08:03:32 +00:00
|
|
|
}
|
|
|
|
|
2003-11-03 07:47:42 +00:00
|
|
|
bool Sword2Engine::saveExists(uint16 slotNo) {
|
2011-06-02 03:38:47 +00:00
|
|
|
Common::String saveFileName = getSaveFileName(slotNo);
|
2005-05-10 23:17:38 +00:00
|
|
|
Common::InSaveFile *in;
|
2004-04-26 07:37:25 +00:00
|
|
|
|
2005-04-10 15:13:40 +00:00
|
|
|
if (!(in = _saveFileMan->openForLoading(saveFileName))) {
|
2003-09-20 17:48:53 +00:00
|
|
|
return false;
|
|
|
|
}
|
2003-09-14 21:45:42 +00:00
|
|
|
|
2003-09-20 17:48:53 +00:00
|
|
|
delete in;
|
|
|
|
return true;
|
2003-09-14 21:45:42 +00:00
|
|
|
}
|
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
uint32 Sword2Engine::calcChecksum(byte *buffer, uint32 size) {
|
2003-11-03 07:47:42 +00:00
|
|
|
uint32 total = 0;
|
|
|
|
|
|
|
|
for (uint32 pos = 0; pos < size; pos++)
|
|
|
|
total += buffer[pos];
|
|
|
|
|
|
|
|
return total;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
2003-09-20 17:48:53 +00:00
|
|
|
|
2003-10-04 00:52:27 +00:00
|
|
|
} // End of namespace Sword2
|