2009-02-18 15:05:00 +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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* $URL$
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2009-02-21 10:47:56 +00:00
|
|
|
/* Savegame handling for EngineState structs. Makes heavy use of cfsml magic. */
|
2009-02-20 23:41:15 +00:00
|
|
|
/* DON'T EDIT savegame.cpp ! Only modify savegame.cfsml, if something needs
|
2009-02-18 15:05:00 +00:00
|
|
|
** to be changed. Refer to freesci/docs/misc/cfsml.spec if you don't understand
|
|
|
|
** savegame.cfsml. If this doesn't solve your problem, contact the maintainer.
|
|
|
|
*/
|
|
|
|
|
2009-02-21 18:39:53 +00:00
|
|
|
#include <time.h> // FIXME: For struct tm
|
2009-02-21 22:50:35 +00:00
|
|
|
#include "common/stream.h"
|
|
|
|
#include "common/system.h"
|
2009-02-24 05:39:10 +00:00
|
|
|
#include "sci/sci_memory.h"
|
2009-02-24 20:39:34 +00:00
|
|
|
#include "sci/gfx/operations.h"
|
2009-02-21 22:50:35 +00:00
|
|
|
#include "sci/gfx/menubar.h"
|
2009-03-07 19:23:47 +00:00
|
|
|
#include "sci/gfx/gfx_state_internal.h" // required for gfxw_port_t, gfxw_container_t
|
2009-03-01 06:17:52 +00:00
|
|
|
#include "sci/sfx/core.h"
|
2009-03-06 18:11:12 +00:00
|
|
|
#include "sci/sfx/iterator.h"
|
2009-02-27 19:37:29 +00:00
|
|
|
#include "sci/engine/state.h"
|
2009-02-24 23:16:42 +00:00
|
|
|
#include "sci/engine/intmap.h"
|
2009-02-18 15:05:00 +00:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
#pragma warning( disable : 4101 )
|
|
|
|
#endif
|
|
|
|
|
2009-02-21 10:23:36 +00:00
|
|
|
namespace Sci {
|
|
|
|
|
2009-02-18 15:05:00 +00:00
|
|
|
#define HUNK_TYPE_GFX_SNAPSHOT_STRING "g\n"
|
|
|
|
|
|
|
|
/* Missing:
|
|
|
|
** - SFXdriver
|
|
|
|
** - File input/output state (this is likely not to happen)
|
|
|
|
*/
|
|
|
|
|
2009-02-20 23:41:15 +00:00
|
|
|
|
|
|
|
const unsigned int PRINTFBUFLEN = 128;
|
|
|
|
int WSprintf(Common::WriteStream* str, const char *format, ...) {
|
|
|
|
va_list args;
|
|
|
|
char buf[PRINTFBUFLEN]; // default buffer to prevent new in common case
|
|
|
|
char* writebuf = buf;
|
|
|
|
|
|
|
|
unsigned int s = PRINTFBUFLEN;
|
|
|
|
unsigned int outsize;
|
|
|
|
while (true) {
|
|
|
|
va_start(args, format);
|
|
|
|
outsize = vsnprintf(writebuf, s, format, args);
|
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
if (outsize == s) {
|
|
|
|
if (s > 16384) { // there are limits...
|
|
|
|
delete[] writebuf;
|
|
|
|
warning("Saving failed: line much too long");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
s *= 2;
|
|
|
|
if (writebuf != buf) delete[] writebuf;
|
|
|
|
writebuf = new char[s];
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32 ret = str->write(writebuf, outsize);
|
|
|
|
|
|
|
|
if (writebuf != buf) delete[] writebuf;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int SRSgetc(Common::SeekableReadStream* str) {
|
|
|
|
char c = str->readSByte();
|
|
|
|
if (str->err() || str->eos())
|
|
|
|
return EOF;
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
char* SRSgets(char* s, int size, Common::SeekableReadStream* str) {
|
|
|
|
return str->readLine_NEW(s, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-02-21 10:47:56 +00:00
|
|
|
static EngineState *_global_save_state;
|
2009-02-20 19:08:38 +00:00
|
|
|
// Needed for some graphical stuff.
|
2009-02-18 15:05:00 +00:00
|
|
|
#define FILE_VERSION _global_save_state->savegame_version
|
|
|
|
|
|
|
|
|
2009-02-28 10:05:07 +00:00
|
|
|
void write_reg_t(Common::WriteStream *fh, reg_t const *foo) {
|
2009-02-20 23:41:15 +00:00
|
|
|
WSprintf(fh, PREG, PRINT_REG(*foo));
|
2009-02-18 15:05:00 +00:00
|
|
|
}
|
|
|
|
|
2009-02-20 23:41:15 +00:00
|
|
|
int read_reg_t(Common::SeekableReadStream *fh, reg_t *foo, const char *lastval, int *line, int *hiteof) {
|
2009-02-21 03:59:57 +00:00
|
|
|
unsigned int segment, offset;
|
2009-02-18 15:05:00 +00:00
|
|
|
|
2009-02-20 17:23:54 +00:00
|
|
|
if (sscanf(lastval, PREG, &segment, &offset) < 2) {
|
2009-02-18 15:05:00 +00:00
|
|
|
sciprintf("Error parsing reg_t on line %d\n", *line);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
*foo = make_reg(segment, offset);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-02-28 10:05:07 +00:00
|
|
|
void write_sci_version(Common::WriteStream *fh, sci_version_t const *foo) {
|
2009-02-20 23:41:15 +00:00
|
|
|
WSprintf(fh, "%d.%03d.%03d", SCI_VERSION_MAJOR(*foo), SCI_VERSION_MINOR(*foo), SCI_VERSION_PATCHLEVEL(*foo));
|
2009-02-18 15:05:00 +00:00
|
|
|
}
|
|
|
|
|
2009-02-20 23:41:15 +00:00
|
|
|
int read_sci_version(Common::SeekableReadStream *fh, sci_version_t *foo, const char *lastval, int *line, int *hiteof) {
|
2009-02-18 15:05:00 +00:00
|
|
|
return version_parse(lastval, foo);
|
|
|
|
}
|
|
|
|
|
2009-02-28 10:05:07 +00:00
|
|
|
void write_PTN(Common::WriteStream *fh, parse_tree_node_t const *foo) {
|
2009-02-18 15:05:00 +00:00
|
|
|
if (foo->type == PARSE_TREE_NODE_LEAF)
|
2009-02-20 23:41:15 +00:00
|
|
|
WSprintf(fh, "L%d", foo->content.value);
|
2009-02-18 15:05:00 +00:00
|
|
|
else
|
2009-02-20 23:41:15 +00:00
|
|
|
WSprintf(fh, "B(%d,%d)", foo->content.branches[0], foo->content.branches[1]);
|
2009-02-18 15:05:00 +00:00
|
|
|
}
|
|
|
|
|
2009-02-20 23:41:15 +00:00
|
|
|
int read_PTN(Common::SeekableReadStream *fh, parse_tree_node_t *foo, const char *lastval, int *line, int *hiteof) {
|
2009-02-18 15:05:00 +00:00
|
|
|
if (lastval[0] == 'L') {
|
|
|
|
const char *c = lastval + 1;
|
|
|
|
char *strend;
|
|
|
|
|
|
|
|
while (*c && isspace(*c))
|
|
|
|
++c;
|
|
|
|
|
|
|
|
if (!*c)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
foo->content.value = strtol(c, &strend, 0);
|
|
|
|
|
2009-02-20 17:23:54 +00:00
|
|
|
return (strend == c); // Error if nothing could be read
|
2009-02-18 15:05:00 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
} else if (lastval[0] == 'B') {
|
|
|
|
const char *c = lastval + 1;
|
|
|
|
char *strend;
|
|
|
|
|
2009-02-20 17:23:54 +00:00
|
|
|
while (*c && isspace(*c))
|
|
|
|
++c;
|
2009-02-18 15:05:00 +00:00
|
|
|
if (*c++ != '(') return 1;
|
2009-02-20 17:23:54 +00:00
|
|
|
while (*c && isspace(*c))
|
|
|
|
++c;
|
2009-02-18 15:05:00 +00:00
|
|
|
|
|
|
|
foo->content.branches[0] = strtol(c, &strend, 0);
|
|
|
|
if (strend == c)
|
|
|
|
return 1;
|
|
|
|
c = strend;
|
|
|
|
|
2009-02-20 17:23:54 +00:00
|
|
|
while (*c && isspace(*c))
|
|
|
|
++c;
|
2009-02-18 15:05:00 +00:00
|
|
|
if (*c++ != ',')
|
|
|
|
return 1;
|
|
|
|
|
2009-02-20 17:23:54 +00:00
|
|
|
while (*c && isspace(*c))
|
|
|
|
++c;
|
2009-02-18 15:05:00 +00:00
|
|
|
|
|
|
|
foo->content.branches[1] = strtol(c, &strend, 0);
|
|
|
|
if (strend == c)
|
|
|
|
return 1;
|
|
|
|
c = strend;
|
|
|
|
|
2009-02-20 17:23:54 +00:00
|
|
|
while (*c && isspace(*c))
|
|
|
|
++c;
|
|
|
|
if (*c++ != ')')
|
|
|
|
return 1;
|
2009-02-18 15:05:00 +00:00
|
|
|
|
|
|
|
return 0;
|
2009-02-20 17:23:54 +00:00
|
|
|
} else return 1; // failure to parse anything
|
2009-02-18 15:05:00 +00:00
|
|
|
}
|
|
|
|
|
2009-02-28 11:07:36 +00:00
|
|
|
void write_CommonString(Common::WriteStream *fh, Common::String const *string);
|
|
|
|
int read_CommonString(Common::SeekableReadStream *fh, Common::String *string, const char *lastval, int *line, int *hiteof);
|
|
|
|
|
2009-02-28 10:05:07 +00:00
|
|
|
void write_menubar_tp(Common::WriteStream *fh, const menubar_t * const *foo);
|
2009-02-20 23:41:15 +00:00
|
|
|
int read_menubar_tp(Common::SeekableReadStream *fh, menubar_t **foo, const char *lastval, int *line, int *hiteof);
|
2009-02-18 15:05:00 +00:00
|
|
|
|
2009-02-28 11:12:59 +00:00
|
|
|
void write_MemObjPtr(Common::WriteStream *fh, const MemObject * const *foo);
|
|
|
|
int read_MemObjPtr(Common::SeekableReadStream *fh, MemObject **foo, const char *lastval, int *line, int *hiteof);
|
2009-02-18 15:05:00 +00:00
|
|
|
|
2009-02-28 10:05:07 +00:00
|
|
|
void write_songlib_t(Common::WriteStream *fh, songlib_t const *foo);
|
2009-02-20 23:41:15 +00:00
|
|
|
int read_songlib_t(Common::SeekableReadStream *fh, songlib_t *foo, const char *lastval, int *line, int *hiteof);
|
2009-02-18 15:05:00 +00:00
|
|
|
|
2009-02-20 23:41:15 +00:00
|
|
|
int read_song_tp(Common::SeekableReadStream *fh, song_t **foo, const char *lastval, int *line, int *hiteof);
|
2009-02-18 15:05:00 +00:00
|
|
|
|
2009-02-28 10:05:07 +00:00
|
|
|
void write_IntMapperPtr(Common::WriteStream *fh, const IntMapper * const *foo);
|
2009-02-24 02:59:50 +00:00
|
|
|
int read_IntMapperPtr(Common::SeekableReadStream *fh, IntMapper **foo, const char *lastval, int *line, int *hiteof);
|
|
|
|
|
2009-02-28 10:05:07 +00:00
|
|
|
void write_IntMapperNodePtr(Common::WriteStream *fh, const IntMapper::Node * const *foo);
|
2009-02-24 02:59:50 +00:00
|
|
|
int read_IntMapperNodePtr(Common::SeekableReadStream *fh, IntMapper::Node **foo, const char *lastval, int *line, int *hiteof);
|
|
|
|
|
2009-02-28 10:05:07 +00:00
|
|
|
void write_SegManagerPtr(Common::WriteStream *fh, const SegManager * const *foo);
|
2009-02-23 00:14:51 +00:00
|
|
|
int read_SegManagerPtr(Common::SeekableReadStream *fh, SegManager **foo, const char *lastval, int *line, int *hiteof);
|
|
|
|
|
2009-02-28 11:12:59 +00:00
|
|
|
typedef MemObject *mem_obj_ptr;
|
2009-02-18 15:05:00 +00:00
|
|
|
|
2009-02-18 17:57:57 +00:00
|
|
|
// Unused types
|
|
|
|
/*
|
|
|
|
TYPE long "long" LIKE int;
|
2009-02-21 21:16:41 +00:00
|
|
|
TYPE int16 "int16" LIKE int;
|
2009-02-18 17:57:57 +00:00
|
|
|
|
|
|
|
RECORD synonym_t "synonym_t" {
|
|
|
|
int replaceant;
|
|
|
|
int replacement;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2009-02-18 15:05:00 +00:00
|
|
|
%CFSML
|
|
|
|
|
2009-02-23 00:14:51 +00:00
|
|
|
TYPE bool "bool" LIKE int;
|
2009-02-18 15:05:00 +00:00
|
|
|
TYPE byte "byte" LIKE int;
|
2009-02-28 11:07:36 +00:00
|
|
|
TYPE Common::String ""Common::String" USING write_CommonString read_CommonString;
|
2009-02-28 11:12:59 +00:00
|
|
|
TYPE SegmentId "SegmentId" LIKE int;
|
2009-02-18 15:05:00 +00:00
|
|
|
TYPE sci_version_t "sci_version_t" USING write_sci_version read_sci_version;
|
|
|
|
TYPE menubar_tp "menubar_t *" USING write_menubar_tp read_menubar_tp;
|
2009-02-28 11:12:59 +00:00
|
|
|
TYPE MemObject "MemObject" USING write_MemObject read_MemObject;
|
|
|
|
TYPE mem_obj_ptr "MemObject *" USING write_MemObjPtr read_MemObjPtr;
|
2009-02-18 15:05:00 +00:00
|
|
|
TYPE reg_t "reg_t" USING write_reg_t read_reg_t;
|
|
|
|
TYPE size_t "size_t" LIKE int;
|
2009-02-24 02:59:50 +00:00
|
|
|
TYPE IntMapperPtr "IntMapper *" USING write_IntMapperPtr read_IntMapperPtr;
|
|
|
|
TYPE IntMapperNodePtr "IntMapper::Node *" USING write_IntMapperNodePtr read_IntMapperNodePtr;
|
2009-02-18 15:05:00 +00:00
|
|
|
TYPE songlib_t "songlib_t" USING write_songlib_t read_songlib_t;
|
|
|
|
TYPE song_tp "song_t *" USING write_song_tp read_song_tp;
|
2009-03-06 07:25:06 +00:00
|
|
|
TYPE SongIterator "SongIterator" USING write_song_iterator_t read_song_iterator_t;
|
2009-02-18 15:05:00 +00:00
|
|
|
TYPE song_handle_t "song_handle_t" LIKE int;
|
2009-02-23 00:14:51 +00:00
|
|
|
TYPE SegManagerPtr "SegManager *" USING write_SegManagerPtr read_SegManagerPtr;
|
2009-02-18 15:05:00 +00:00
|
|
|
|
|
|
|
RECORD song_t "song_t" {
|
|
|
|
song_handle_t handle;
|
|
|
|
int resource_num;
|
|
|
|
int priority;
|
|
|
|
int status;
|
|
|
|
int restore_behavior;
|
|
|
|
int restore_time;
|
|
|
|
int loops;
|
|
|
|
int hold;
|
|
|
|
}
|
2009-02-22 13:11:43 +00:00
|
|
|
|
2009-02-24 02:59:50 +00:00
|
|
|
RECORD IntMapper "IntMapper" {
|
2009-02-18 15:05:00 +00:00
|
|
|
int base_value;
|
2009-02-24 02:59:50 +00:00
|
|
|
IntMapperNodePtr nodes[STATIC DCS_INT_HASH_MAX];
|
2009-02-18 15:05:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RECORD menu_item_t "menu_item_t" {
|
|
|
|
int type;
|
|
|
|
string keytext;
|
|
|
|
int keytext_size;
|
|
|
|
|
|
|
|
int flags;
|
|
|
|
byte said[STATIC MENU_SAID_SPEC_SIZE];
|
|
|
|
reg_t said_pos;
|
|
|
|
string text;
|
|
|
|
reg_t text_pos;
|
|
|
|
int modifiers;
|
|
|
|
int key;
|
|
|
|
int enabled;
|
|
|
|
int tag;
|
|
|
|
}
|
|
|
|
|
|
|
|
RECORD menu_t "menu_t" {
|
|
|
|
string title;
|
|
|
|
int title_width;
|
|
|
|
int width;
|
|
|
|
|
|
|
|
menu_item_t items[DYNAMIC items_nr];
|
|
|
|
}
|
|
|
|
|
|
|
|
RECORD menubar_t "menubar_t" {
|
|
|
|
menu_t menus[DYNAMIC menus_nr];
|
|
|
|
}
|
|
|
|
|
2009-02-21 11:04:47 +00:00
|
|
|
RECORD SegManager "SegManager" {
|
2009-02-24 02:59:50 +00:00
|
|
|
IntMapperPtr id_seg_map;
|
2009-02-18 15:05:00 +00:00
|
|
|
mem_obj_ptr heap[DYNAMIC heap_size];
|
|
|
|
int heap_size;
|
|
|
|
int reserved_id;
|
|
|
|
int exports_wide;
|
|
|
|
int gc_mark_bits;
|
|
|
|
size_t mem_allocated;
|
2009-02-28 11:12:59 +00:00
|
|
|
SegmentId Clones_seg_id;
|
|
|
|
SegmentId Lists_seg_id;
|
|
|
|
SegmentId Nodes_seg_id;
|
2009-02-18 15:05:00 +00:00
|
|
|
}
|
|
|
|
|
2009-02-28 11:12:59 +00:00
|
|
|
RECORD Class "Class" {
|
2009-02-18 15:05:00 +00:00
|
|
|
int script;
|
|
|
|
reg_t reg;
|
|
|
|
}
|
|
|
|
|
|
|
|
RECORD sfx_state_t "sfx_state_t" {
|
|
|
|
songlib_t songlib;
|
|
|
|
}
|
|
|
|
|
2009-02-20 23:41:15 +00:00
|
|
|
RECORD SavegameMetadata "SavegameMetadata" {
|
2009-02-28 11:07:36 +00:00
|
|
|
Common::String savegame_name;
|
2009-02-20 23:41:15 +00:00
|
|
|
int savegame_version;
|
2009-02-28 11:07:36 +00:00
|
|
|
Common::String game_version;
|
2009-02-20 23:41:15 +00:00
|
|
|
sci_version_t version;
|
|
|
|
int savegame_date;
|
|
|
|
int savegame_time;
|
|
|
|
}
|
|
|
|
|
2009-02-21 10:47:56 +00:00
|
|
|
RECORD EngineState "EngineState" {
|
2009-02-18 15:05:00 +00:00
|
|
|
int savegame_version;
|
|
|
|
|
|
|
|
string game_version;
|
|
|
|
sci_version_t version;
|
|
|
|
menubar_tp menubar;
|
|
|
|
int status_bar_foreground;
|
|
|
|
int status_bar_background;
|
2009-02-23 00:14:51 +00:00
|
|
|
SegManagerPtr seg_manager;
|
2009-02-18 15:05:00 +00:00
|
|
|
int classtable_size;
|
2009-02-28 11:12:59 +00:00
|
|
|
Class classtable[DYNAMIC classtable_size];
|
2009-02-18 15:05:00 +00:00
|
|
|
sfx_state_t sound;
|
|
|
|
}
|
|
|
|
|
2009-02-28 11:12:59 +00:00
|
|
|
RECORD LocalVariables "LocalVariables" {
|
2009-02-18 15:05:00 +00:00
|
|
|
int script_id;
|
|
|
|
int nr;
|
|
|
|
reg_t locals[DYNAMIC nr];
|
|
|
|
}
|
|
|
|
|
2009-02-28 11:12:59 +00:00
|
|
|
RECORD Object "Object" {
|
2009-02-18 15:05:00 +00:00
|
|
|
int flags;
|
|
|
|
reg_t pos;
|
|
|
|
int variables_nr;
|
|
|
|
int variable_names_nr;
|
|
|
|
int methods_nr;
|
|
|
|
reg_t variables[DYNAMIC variables_nr];
|
|
|
|
}
|
|
|
|
|
2009-02-28 11:12:59 +00:00
|
|
|
RECORD Clone "Clone" {
|
2009-02-18 15:05:00 +00:00
|
|
|
int flags;
|
|
|
|
reg_t pos;
|
|
|
|
int variables_nr;
|
|
|
|
int variable_names_nr;
|
|
|
|
int methods_nr;
|
|
|
|
reg_t variables[DYNAMIC variables_nr];
|
|
|
|
}
|
|
|
|
|
2009-02-28 11:12:59 +00:00
|
|
|
RECORD List "List" {
|
2009-02-18 15:05:00 +00:00
|
|
|
reg_t first;
|
|
|
|
reg_t last;
|
|
|
|
}
|
|
|
|
|
2009-02-28 11:12:59 +00:00
|
|
|
RECORD Node "Node" {
|
2009-02-18 15:05:00 +00:00
|
|
|
reg_t pred;
|
|
|
|
reg_t succ;
|
|
|
|
reg_t key;
|
|
|
|
reg_t value;
|
|
|
|
}
|
|
|
|
|
2009-02-28 11:12:59 +00:00
|
|
|
RECORD CloneEntry "CloneEntry" {
|
2009-02-18 15:05:00 +00:00
|
|
|
int next_free;
|
2009-02-28 11:12:59 +00:00
|
|
|
Clone entry;
|
2009-02-18 15:05:00 +00:00
|
|
|
}
|
|
|
|
|
2009-02-28 11:12:59 +00:00
|
|
|
RECORD CloneTable "CloneTable" {
|
2009-02-18 15:05:00 +00:00
|
|
|
int entries_nr;
|
|
|
|
int first_free;
|
|
|
|
int entries_used;
|
|
|
|
int max_entry;
|
2009-02-28 11:12:59 +00:00
|
|
|
CloneEntry table[DYNAMIC entries_nr];
|
2009-02-18 15:05:00 +00:00
|
|
|
}
|
|
|
|
|
2009-02-28 11:12:59 +00:00
|
|
|
RECORD ListEntry "ListEntry" {
|
2009-02-18 15:05:00 +00:00
|
|
|
int next_free;
|
2009-02-28 11:12:59 +00:00
|
|
|
List entry;
|
2009-02-18 15:05:00 +00:00
|
|
|
}
|
|
|
|
|
2009-02-28 11:12:59 +00:00
|
|
|
RECORD ListTable "ListTable" {
|
2009-02-18 15:05:00 +00:00
|
|
|
int entries_nr;
|
|
|
|
int first_free;
|
|
|
|
int entries_used;
|
|
|
|
int max_entry;
|
2009-02-28 11:12:59 +00:00
|
|
|
ListEntry table[DYNAMIC entries_nr];
|
2009-02-18 15:05:00 +00:00
|
|
|
}
|
|
|
|
|
2009-02-28 11:12:59 +00:00
|
|
|
RECORD NodeEntry "NodeEntry" {
|
2009-02-18 15:05:00 +00:00
|
|
|
int next_free;
|
2009-02-28 11:12:59 +00:00
|
|
|
Node entry;
|
2009-02-18 15:05:00 +00:00
|
|
|
}
|
|
|
|
|
2009-02-28 11:12:59 +00:00
|
|
|
RECORD NodeTable "NodeTable" {
|
2009-02-18 15:05:00 +00:00
|
|
|
int entries_nr;
|
|
|
|
int first_free;
|
|
|
|
int entries_used;
|
|
|
|
int max_entry;
|
2009-02-28 11:12:59 +00:00
|
|
|
NodeEntry table[DYNAMIC entries_nr];
|
2009-02-18 15:05:00 +00:00
|
|
|
}
|
|
|
|
|
2009-02-28 11:12:59 +00:00
|
|
|
RECORD Script "Script" {
|
2009-02-18 15:05:00 +00:00
|
|
|
int nr;
|
|
|
|
|
|
|
|
size_t buf_size;
|
|
|
|
size_t script_size;
|
|
|
|
size_t heap_size;
|
|
|
|
|
2009-02-24 02:59:50 +00:00
|
|
|
IntMapperPtr obj_indices;
|
2009-02-18 15:05:00 +00:00
|
|
|
int exports_nr;
|
|
|
|
int synonyms_nr;
|
|
|
|
int lockers;
|
|
|
|
int objects_allocated;
|
|
|
|
int objects_nr;
|
2009-02-28 11:12:59 +00:00
|
|
|
Object objects[DYNAMIC objects_allocated];
|
2009-02-18 15:05:00 +00:00
|
|
|
|
|
|
|
int locals_offset;
|
|
|
|
int locals_segment;
|
|
|
|
|
|
|
|
int marked_as_deleted;
|
|
|
|
}
|
|
|
|
|
2009-02-26 23:03:35 +00:00
|
|
|
RECORD SystemString "SystemString" {
|
2009-02-18 15:05:00 +00:00
|
|
|
string name;
|
|
|
|
int max_size;
|
|
|
|
string value;
|
|
|
|
}
|
|
|
|
|
2009-02-26 23:03:35 +00:00
|
|
|
RECORD SystemStrings "SystemStrings" {
|
|
|
|
SystemString strings[STATIC SYS_STRINGS_MAX];
|
2009-02-18 15:05:00 +00:00
|
|
|
}
|
|
|
|
|
2009-02-28 11:12:59 +00:00
|
|
|
RECORD DynMem "DynMem" {
|
2009-02-18 15:05:00 +00:00
|
|
|
int size;
|
|
|
|
string description;
|
|
|
|
byte buf[DYNAMIC size];
|
|
|
|
}
|
|
|
|
|
|
|
|
%END CFSML
|
|
|
|
|
2009-02-28 10:05:07 +00:00
|
|
|
void write_songlib_t(Common::WriteStream *fh, songlib_t const *songlib) {
|
2009-02-18 15:05:00 +00:00
|
|
|
song_t *seeker = *(songlib->lib);
|
|
|
|
int songcount = song_lib_count(*songlib);
|
|
|
|
|
2009-02-20 23:41:15 +00:00
|
|
|
WSprintf(fh, "{\n");
|
|
|
|
WSprintf(fh, "songcount = %d\n", songcount);
|
|
|
|
WSprintf(fh, "list = \n");
|
|
|
|
WSprintf(fh, "[\n");
|
2009-02-18 15:05:00 +00:00
|
|
|
while (seeker) {
|
2009-03-06 07:25:48 +00:00
|
|
|
seeker->restore_time = seeker->it->getTimepos();
|
2009-02-18 15:05:00 +00:00
|
|
|
%CFSMLWRITE song_t seeker INTO fh;
|
|
|
|
seeker = seeker->next;
|
|
|
|
}
|
2009-02-20 23:41:15 +00:00
|
|
|
WSprintf(fh, "]\n");
|
|
|
|
WSprintf(fh, "}\n");
|
2009-02-18 15:05:00 +00:00
|
|
|
}
|
|
|
|
|
2009-02-20 23:41:15 +00:00
|
|
|
int read_songlib_t(Common::SeekableReadStream *fh, songlib_t *songlib, const char *lastval, int *line, int *hiteof) {
|
2009-02-18 15:05:00 +00:00
|
|
|
int songcount;
|
|
|
|
int i;
|
|
|
|
song_t *newsong;
|
|
|
|
|
2009-02-20 23:41:15 +00:00
|
|
|
if (strcmp(lastval, "{")) {
|
|
|
|
_cfsml_error("Opening brackets expected at line %d\n", *line);
|
|
|
|
return CFSML_FAILURE;
|
|
|
|
}
|
|
|
|
// FIXME: error checking
|
2009-02-21 00:18:02 +00:00
|
|
|
Common::String l = fh->readLine();
|
|
|
|
sscanf(l.c_str(), "songcount = %d", &songcount);
|
|
|
|
l = fh->readLine(); // "list = "
|
|
|
|
l = fh->readLine(); // "["
|
2009-02-18 15:05:00 +00:00
|
|
|
*line += 4;
|
|
|
|
song_lib_init(songlib);
|
|
|
|
for (i = 0; i < songcount; i++) {
|
|
|
|
%CFSMLREAD song_tp &newsong FROM fh ERRVAR *hiteof FIRSTTOKEN lastval LINECOUNTER *line;
|
|
|
|
song_lib_add(*songlib, newsong);
|
2009-02-22 13:11:43 +00:00
|
|
|
}
|
2009-02-21 00:18:02 +00:00
|
|
|
l = fh->readLine(); // "]"
|
|
|
|
l = fh->readLine(); // "}"
|
2009-02-18 15:05:00 +00:00
|
|
|
*line += 2;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-02-28 10:05:07 +00:00
|
|
|
void write_song_tp(Common::WriteStream *fh, const song_t * const *foo) {
|
2009-02-18 15:05:00 +00:00
|
|
|
%CFSMLWRITE song_t *foo INTO fh;
|
|
|
|
}
|
|
|
|
|
2009-03-06 07:25:06 +00:00
|
|
|
SongIterator *build_iterator(EngineState *s, int song_nr, int type, songit_id_t id);
|
2009-02-18 15:05:00 +00:00
|
|
|
|
2009-02-20 23:41:15 +00:00
|
|
|
int read_song_tp(Common::SeekableReadStream *fh, song_t **foo, const char *lastval, int *line, int *hiteof) {
|
2009-02-20 17:23:54 +00:00
|
|
|
char *token;
|
|
|
|
int assignment;
|
|
|
|
*foo = (song_t*) malloc(sizeof(song_t));
|
|
|
|
token = _cfsml_get_identifier(fh, line, hiteof, &assignment);
|
|
|
|
%CFSMLREAD song_t (*foo) FROM fh ERRVAR *hiteof FIRSTTOKEN token LINECOUNTER *line;
|
2009-03-09 16:15:35 +00:00
|
|
|
(*foo)->_delay = 0;
|
2009-02-20 17:23:54 +00:00
|
|
|
(*foo)->it = NULL;
|
|
|
|
(*foo)->next_playing = (*foo)->next_stopping = (*foo)->next = NULL;
|
|
|
|
return 0;
|
2009-02-18 15:05:00 +00:00
|
|
|
}
|
2009-02-20 17:23:54 +00:00
|
|
|
|
2009-02-28 10:05:07 +00:00
|
|
|
void write_IntMapperPtr(Common::WriteStream *fh, const IntMapper * const *foo) {
|
2009-02-24 02:59:50 +00:00
|
|
|
%CFSMLWRITE IntMapper *foo INTO fh;
|
|
|
|
}
|
|
|
|
|
|
|
|
int read_IntMapperPtr(Common::SeekableReadStream *fh, IntMapper **foo, const char *lastval, int *line, int *hiteof) {
|
|
|
|
*foo = new IntMapper();
|
|
|
|
%CFSMLREAD IntMapper (*foo) FROM fh ERRVAR *hiteof FIRSTTOKEN lastval LINECOUNTER *line;
|
2009-02-18 15:05:00 +00:00
|
|
|
(*foo)->holes = NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-02-28 10:05:07 +00:00
|
|
|
void write_IntMapperNodePtr(Common::WriteStream *fh, const IntMapper::Node * const *foo) {
|
2009-02-18 15:05:00 +00:00
|
|
|
if (!(*foo)) {
|
2009-02-20 23:41:15 +00:00
|
|
|
WSprintf(fh, "\\null");
|
2009-02-18 15:05:00 +00:00
|
|
|
} else {
|
2009-02-24 02:59:50 +00:00
|
|
|
WSprintf(fh,"[\n%d=>%d\n", (*foo)->key, (*foo)->idx);
|
2009-02-18 15:05:00 +00:00
|
|
|
if ((*foo)->next) {
|
2009-02-24 02:59:50 +00:00
|
|
|
%CFSMLWRITE IntMapperNodePtr &((*foo)->next) INTO fh;
|
2009-02-20 19:08:38 +00:00
|
|
|
} else
|
2009-02-20 23:41:15 +00:00
|
|
|
WSprintf(fh, "L");
|
|
|
|
WSprintf(fh, "]");
|
2009-02-18 15:05:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-24 02:59:50 +00:00
|
|
|
int read_IntMapperNodePtr(Common::SeekableReadStream *fh, IntMapper::Node **foo, const char *lastval, int *line, int *hiteof) {
|
2009-02-18 15:05:00 +00:00
|
|
|
static char buffer[80];
|
|
|
|
|
|
|
|
if (lastval[0] == '\\') {
|
2009-02-20 17:23:54 +00:00
|
|
|
*foo = NULL; // No hash map node
|
2009-02-18 15:05:00 +00:00
|
|
|
} else {
|
2009-02-24 02:59:50 +00:00
|
|
|
*foo = (IntMapper::Node*)malloc(sizeof(IntMapper::Node));
|
2009-02-18 15:05:00 +00:00
|
|
|
if (lastval[0] != '[') {
|
|
|
|
sciprintf("Expected opening bracket in hash_map_node_t on line %d\n", *line);
|
|
|
|
return 1;
|
|
|
|
}
|
2009-02-22 13:11:43 +00:00
|
|
|
|
2009-02-18 15:05:00 +00:00
|
|
|
do {
|
|
|
|
(*line)++;
|
2009-02-20 23:41:15 +00:00
|
|
|
SRSgets(buffer, 80, fh);
|
2009-02-18 15:05:00 +00:00
|
|
|
if (buffer[0] == 'L') {
|
|
|
|
(*foo)->next = NULL;
|
|
|
|
buffer[0] = buffer[1];
|
2009-02-20 17:23:54 +00:00
|
|
|
} // HACK: deliberately no else clause here
|
2009-02-18 15:05:00 +00:00
|
|
|
if (buffer[0] == ']') {
|
|
|
|
break;
|
2009-02-24 02:59:50 +00:00
|
|
|
} else if (buffer[0] == '[') {
|
|
|
|
if (read_IntMapperNodePtr(fh, &((*foo)->next), buffer, line, hiteof))
|
2009-02-18 15:05:00 +00:00
|
|
|
return 1;
|
2009-02-24 02:59:50 +00:00
|
|
|
} else if (sscanf(buffer, "%d=>%d", &((*foo)->key), &((*foo)->idx))<2) {
|
2009-02-18 15:05:00 +00:00
|
|
|
sciprintf("Error parsing hash_map_node_t on line %d\n", *line);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
} while (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-02-28 10:05:07 +00:00
|
|
|
void write_menubar_tp(Common::WriteStream *fh, const menubar_t * const *foo) {
|
2009-02-18 15:05:00 +00:00
|
|
|
if (*foo) {
|
|
|
|
%CFSMLWRITE menubar_t (*foo) INTO fh;
|
2009-02-20 17:23:54 +00:00
|
|
|
} else { // Nothing to write
|
2009-02-20 23:41:15 +00:00
|
|
|
WSprintf(fh, "\\null\\");
|
2009-02-18 15:05:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-20 23:41:15 +00:00
|
|
|
int read_menubar_tp(Common::SeekableReadStream *fh, menubar_t **foo, const char *lastval, int *line, int *hiteof) {
|
2009-02-18 15:05:00 +00:00
|
|
|
if (lastval[0] == '\\') {
|
2009-02-20 17:23:54 +00:00
|
|
|
*foo = NULL; // No menu bar
|
2009-02-18 15:05:00 +00:00
|
|
|
} else {
|
|
|
|
*foo = (menubar_t *) sci_malloc(sizeof(menubar_t));
|
|
|
|
%CFSMLREAD menubar_t (*foo) FROM fh ERRVAR *hiteof FIRSTTOKEN lastval LINECOUNTER *line;
|
|
|
|
}
|
|
|
|
return *hiteof;
|
|
|
|
}
|
|
|
|
|
2009-02-24 02:59:50 +00:00
|
|
|
static struct {
|
|
|
|
int type;
|
|
|
|
const char *name;
|
|
|
|
} mem_obj_string_names[] = {
|
|
|
|
{MEM_OBJ_INVALID, "INVALID"},
|
|
|
|
{MEM_OBJ_SCRIPT, "SCRIPT"},
|
|
|
|
{MEM_OBJ_CLONES, "CLONES"},
|
|
|
|
{MEM_OBJ_LOCALS, "LOCALS"},
|
|
|
|
{MEM_OBJ_STACK, "STACK"},
|
|
|
|
{MEM_OBJ_SYS_STRINGS,"SYS_STRINGS"},
|
|
|
|
{MEM_OBJ_LISTS,"LISTS"},
|
|
|
|
{MEM_OBJ_NODES,"NODES"},
|
|
|
|
{MEM_OBJ_HUNK,"HUNK"},
|
2009-03-10 14:52:02 +00:00
|
|
|
{MEM_OBJ_DYNMEM,"DYNMEM"},
|
|
|
|
{MEM_OBJ_STRING_FRAG,"STRING_FRAGS"},
|
|
|
|
};
|
2009-02-24 02:59:50 +00:00
|
|
|
|
|
|
|
int mem_obj_string_to_enum(const char *str) {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i <= MEM_OBJ_MAX; i++) {
|
|
|
|
if (!scumm_stricmp(mem_obj_string_names[i].name, str))
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-02-28 11:12:59 +00:00
|
|
|
void write_MemObject(Common::WriteStream *fh, MemObject const *foo) {
|
2009-02-22 13:11:43 +00:00
|
|
|
WSprintf(fh, "%s\n", mem_obj_string_names[foo->type].name);
|
2009-02-18 15:05:00 +00:00
|
|
|
%CFSMLWRITE int &foo->segmgr_id INTO fh;
|
|
|
|
switch (foo->type) {
|
|
|
|
case MEM_OBJ_SCRIPT:
|
2009-02-28 11:12:59 +00:00
|
|
|
%CFSMLWRITE Script &foo->data.script INTO fh;
|
2009-02-18 15:05:00 +00:00
|
|
|
break;
|
|
|
|
case MEM_OBJ_CLONES:
|
2009-02-28 11:12:59 +00:00
|
|
|
%CFSMLWRITE CloneTable &foo->data.clones INTO fh;
|
2009-02-18 15:05:00 +00:00
|
|
|
break;
|
|
|
|
case MEM_OBJ_LOCALS:
|
2009-02-28 11:12:59 +00:00
|
|
|
%CFSMLWRITE LocalVariables &foo->data.locals INTO fh;
|
2009-02-18 15:05:00 +00:00
|
|
|
break;
|
|
|
|
case MEM_OBJ_SYS_STRINGS:
|
2009-02-26 23:03:35 +00:00
|
|
|
%CFSMLWRITE SystemStrings &foo->data.sys_strings INTO fh;
|
2009-02-18 15:05:00 +00:00
|
|
|
break;
|
|
|
|
case MEM_OBJ_STACK:
|
|
|
|
%CFSMLWRITE int &foo->data.stack.nr INTO fh;
|
|
|
|
break;
|
|
|
|
case MEM_OBJ_HUNK:
|
|
|
|
break;
|
2009-03-10 14:52:02 +00:00
|
|
|
case MEM_OBJ_STRING_FRAG:
|
|
|
|
break;
|
2009-02-22 13:11:43 +00:00
|
|
|
case MEM_OBJ_LISTS:
|
2009-02-28 11:12:59 +00:00
|
|
|
%CFSMLWRITE ListTable &foo->data.lists INTO fh;
|
2009-02-18 15:05:00 +00:00
|
|
|
break;
|
2009-02-22 13:11:43 +00:00
|
|
|
case MEM_OBJ_NODES:
|
2009-02-28 11:12:59 +00:00
|
|
|
%CFSMLWRITE NodeTable &foo->data.nodes INTO fh;
|
2009-02-18 15:05:00 +00:00
|
|
|
break;
|
|
|
|
case MEM_OBJ_DYNMEM:
|
2009-02-28 11:12:59 +00:00
|
|
|
%CFSMLWRITE DynMem &foo->data.dynmem INTO fh;
|
2009-02-18 15:05:00 +00:00
|
|
|
break;
|
2009-02-21 23:27:24 +00:00
|
|
|
default:
|
|
|
|
break;
|
2009-02-18 15:05:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-28 11:12:59 +00:00
|
|
|
int read_MemObject(Common::SeekableReadStream *fh, MemObject *foo, const char *lastval, int *line, int *hiteof) {
|
2009-02-21 23:27:24 +00:00
|
|
|
foo->type = (memObjType)mem_obj_string_to_enum(lastval);
|
2009-02-18 15:05:00 +00:00
|
|
|
if (foo->type < 0) {
|
2009-02-28 11:12:59 +00:00
|
|
|
sciprintf("Unknown MemObject type %s on line %d\n", lastval, *line);
|
2009-02-18 15:05:00 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
%CFSMLREAD int &foo->segmgr_id FROM fh ERRVAR *hiteof LINECOUNTER *line;
|
|
|
|
switch (foo->type) {
|
|
|
|
case MEM_OBJ_SCRIPT:
|
2009-02-28 11:12:59 +00:00
|
|
|
%CFSMLREAD Script &foo->data.script FROM fh ERRVAR *hiteof LINECOUNTER *line;
|
2009-02-18 15:05:00 +00:00
|
|
|
break;
|
|
|
|
case MEM_OBJ_CLONES:
|
2009-02-28 11:12:59 +00:00
|
|
|
%CFSMLREAD CloneTable &foo->data.clones FROM fh ERRVAR *hiteof LINECOUNTER *line;
|
2009-02-18 15:05:00 +00:00
|
|
|
break;
|
|
|
|
case MEM_OBJ_LOCALS:
|
2009-02-28 11:12:59 +00:00
|
|
|
%CFSMLREAD LocalVariables &foo->data.locals FROM fh ERRVAR *hiteof LINECOUNTER *line;
|
2009-02-18 15:05:00 +00:00
|
|
|
break;
|
|
|
|
case MEM_OBJ_SYS_STRINGS:
|
2009-02-26 23:03:35 +00:00
|
|
|
%CFSMLREAD SystemStrings &foo->data.sys_strings FROM fh ERRVAR *hiteof LINECOUNTER *line;
|
2009-02-18 15:05:00 +00:00
|
|
|
break;
|
|
|
|
case MEM_OBJ_LISTS:
|
2009-02-28 11:12:59 +00:00
|
|
|
%CFSMLREAD ListTable &foo->data.lists FROM fh ERRVAR *hiteof LINECOUNTER *line;
|
2009-02-18 15:05:00 +00:00
|
|
|
break;
|
|
|
|
case MEM_OBJ_NODES:
|
2009-02-28 11:12:59 +00:00
|
|
|
%CFSMLREAD NodeTable &foo->data.nodes FROM fh ERRVAR *hiteof LINECOUNTER *line;
|
2009-02-18 15:05:00 +00:00
|
|
|
break;
|
|
|
|
case MEM_OBJ_STACK:
|
|
|
|
%CFSMLREAD int &foo->data.stack.nr FROM fh ERRVAR *hiteof LINECOUNTER *line;
|
|
|
|
foo->data.stack.entries = (reg_t *)sci_calloc(foo->data.stack.nr, sizeof(reg_t));
|
|
|
|
break;
|
|
|
|
case MEM_OBJ_HUNK:
|
2009-02-28 11:12:59 +00:00
|
|
|
init_Hunk_table(&foo->data.hunks);
|
2009-02-18 15:05:00 +00:00
|
|
|
break;
|
2009-03-10 14:52:02 +00:00
|
|
|
case MEM_OBJ_STRING_FRAG:
|
|
|
|
break;
|
2009-02-18 15:05:00 +00:00
|
|
|
case MEM_OBJ_DYNMEM:
|
2009-02-28 11:12:59 +00:00
|
|
|
%CFSMLREAD DynMem &foo->data.dynmem FROM fh ERRVAR *hiteof LINECOUNTER *line;
|
2009-02-18 15:05:00 +00:00
|
|
|
break;
|
2009-02-21 23:27:24 +00:00
|
|
|
default:
|
|
|
|
break;
|
2009-02-18 15:05:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return *hiteof;
|
|
|
|
}
|
|
|
|
|
2009-02-28 11:12:59 +00:00
|
|
|
void write_MemObjPtr(Common::WriteStream *fh, const MemObject * const *foo) {
|
2009-02-18 15:05:00 +00:00
|
|
|
if (*foo) {
|
2009-02-28 11:12:59 +00:00
|
|
|
%CFSMLWRITE MemObject (*foo) INTO fh;
|
2009-02-20 17:23:54 +00:00
|
|
|
} else { // Nothing to write
|
2009-02-20 23:41:15 +00:00
|
|
|
WSprintf(fh, "\\null\\");
|
2009-02-18 15:05:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-28 11:12:59 +00:00
|
|
|
int read_MemObjPtr(Common::SeekableReadStream *fh, MemObject **foo, const char *lastval, int *line, int *hiteof) {
|
2009-02-18 15:05:00 +00:00
|
|
|
if (lastval[0] == '\\') {
|
2009-02-20 17:23:54 +00:00
|
|
|
*foo = NULL; // No menu bar
|
2009-02-18 15:05:00 +00:00
|
|
|
} else {
|
2009-02-28 11:12:59 +00:00
|
|
|
*foo = (MemObject *)sci_malloc(sizeof(MemObject));
|
|
|
|
%CFSMLREAD MemObject (*foo) FROM fh ERRVAR *hiteof FIRSTTOKEN lastval LINECOUNTER *line;
|
2009-02-18 15:05:00 +00:00
|
|
|
return *hiteof;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-02-28 11:07:36 +00:00
|
|
|
void write_CommonString(Common::WriteStream *fh, Common::String const *string)
|
|
|
|
{
|
|
|
|
const char *t = string->c_str();
|
|
|
|
%CFSMLWRITE string (&t) INTO fh;
|
|
|
|
}
|
|
|
|
|
|
|
|
int read_CommonString(Common::SeekableReadStream *fh, Common::String *string, const char *lastval, int *line, int *hiteof)
|
|
|
|
{
|
|
|
|
char *t;
|
|
|
|
// Do an atomic read to prevent t from being freed if we hit an eof later
|
|
|
|
%CFSMLREAD-ATOMIC string (&t) FROM fh ERRVAR *hiteof FIRSTTOKEN lastval LINECOUNTER *line;
|
|
|
|
if (*hiteof) return *hiteof;
|
|
|
|
*string = t;
|
|
|
|
free(t);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-02-28 10:05:07 +00:00
|
|
|
void write_SegManagerPtr(Common::WriteStream *fh, const SegManager * const *foo) {
|
2009-02-23 00:14:51 +00:00
|
|
|
%CFSMLWRITE bool &((*foo)->isSci1_1) INTO fh;
|
|
|
|
%CFSMLWRITE SegManager *foo INTO fh;
|
|
|
|
}
|
|
|
|
|
|
|
|
int read_SegManagerPtr(Common::SeekableReadStream *fh, SegManager **foo, const char *lastval, int *line, int *hiteof) {
|
|
|
|
char *token;
|
|
|
|
int assignment;
|
|
|
|
bool sci11;
|
2009-02-25 23:50:16 +00:00
|
|
|
%CFSMLREAD bool (&sci11) FROM fh ERRVAR *hiteof FIRSTTOKEN lastval LINECOUNTER *line;
|
2009-02-23 00:14:51 +00:00
|
|
|
*foo = new SegManager(sci11);
|
|
|
|
token = _cfsml_get_identifier(fh, line, hiteof, &assignment);
|
|
|
|
%CFSMLREAD SegManager (*foo) FROM fh ERRVAR *hiteof FIRSTTOKEN token LINECOUNTER *line;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-02-20 17:23:54 +00:00
|
|
|
// This function is called to undo some strange stuff done in preparation
|
|
|
|
// to writing a gamestate to disk
|
2009-02-21 10:47:56 +00:00
|
|
|
void _gamestate_unfrob(EngineState *s) {
|
2009-02-18 15:05:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-21 10:47:56 +00:00
|
|
|
int gamestate_save(EngineState *s, Common::WriteStream *fh, const char* savename) {
|
2009-02-20 23:41:15 +00:00
|
|
|
tm curTime;
|
|
|
|
g_system->getTimeAndDate(curTime);
|
|
|
|
|
2009-02-28 11:07:36 +00:00
|
|
|
SavegameMetadata meta;
|
|
|
|
meta.savegame_version = FREESCI_CURRENT_SAVEGAME_VERSION;
|
|
|
|
meta.savegame_name = savename;
|
|
|
|
meta.version = s->version;
|
|
|
|
meta.game_version = s->game_version;
|
|
|
|
meta.savegame_date = ((curTime.tm_mday & 0xFF) << 24) | (((curTime.tm_mon + 1) & 0xFF) << 16) | ((curTime.tm_year + 1900) & 0xFFFF);
|
|
|
|
meta.savegame_time = ((curTime.tm_hour & 0xFF) << 16) | (((curTime.tm_min) & 0xFF) << 8) | ((curTime.tm_sec) & 0xFF);
|
2009-02-20 23:41:15 +00:00
|
|
|
|
2009-02-18 15:05:00 +00:00
|
|
|
_global_save_state = s;
|
|
|
|
s->savegame_version = FREESCI_CURRENT_SAVEGAME_VERSION;
|
|
|
|
s->dyn_views_list_serial = (s->dyn_views)? s->dyn_views->serial : -2;
|
|
|
|
s->drop_views_list_serial = (s->drop_views)? s->drop_views->serial : -2;
|
|
|
|
s->port_serial = (s->port)? s->port->serial : -2;
|
|
|
|
|
|
|
|
if (s->execution_stack_base) {
|
|
|
|
sciprintf("Cannot save from below kernel function\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
if (s->sound_server) {
|
|
|
|
if ((s->sound_server->save)(s, dirname)) {
|
|
|
|
sciprintf("Saving failed for the sound subsystem\n");
|
|
|
|
chdir("..");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
2009-02-20 17:23:54 +00:00
|
|
|
// Calculate the time spent with this game
|
2009-02-25 21:43:57 +00:00
|
|
|
s->game_time = (g_system->getMillis() - s->game_start_time) / 1000;
|
2009-02-18 15:05:00 +00:00
|
|
|
|
2009-02-28 11:07:36 +00:00
|
|
|
%CFSMLWRITE SavegameMetadata (&meta) INTO fh;
|
2009-02-21 10:47:56 +00:00
|
|
|
%CFSMLWRITE EngineState s INTO fh;
|
2009-02-18 15:05:00 +00:00
|
|
|
|
|
|
|
_gamestate_unfrob(s);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-02-28 11:12:59 +00:00
|
|
|
static SegmentId find_unique_seg_by_type(SegManager *self, int type) {
|
2009-02-18 15:05:00 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < self->heap_size; i++)
|
|
|
|
if (self->heap[i] &&
|
|
|
|
self->heap[i]->type == type)
|
|
|
|
return i;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-02-21 10:47:56 +00:00
|
|
|
static byte *find_unique_script_block(EngineState *s, byte *buf, int type) {
|
2009-02-18 15:05:00 +00:00
|
|
|
int magic_pos_adder = s->version >= SCI_VERSION_FTU_NEW_SCRIPT_HEADER ? 0 : 2;
|
|
|
|
|
|
|
|
buf += magic_pos_adder;
|
|
|
|
do {
|
2009-03-07 18:43:15 +00:00
|
|
|
int seeker_type = READ_LE_UINT16(buf);
|
2009-02-18 15:05:00 +00:00
|
|
|
int seeker_size;
|
|
|
|
|
|
|
|
if (seeker_type == 0) break;
|
|
|
|
if (seeker_type == type) return buf;
|
|
|
|
|
2009-03-07 18:43:15 +00:00
|
|
|
seeker_size = READ_LE_UINT16(buf + 2);
|
2009-02-18 15:05:00 +00:00
|
|
|
buf += seeker_size;
|
|
|
|
} while(1);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-02-21 10:47:56 +00:00
|
|
|
static void reconstruct_stack(EngineState *retval) {
|
2009-02-28 11:12:59 +00:00
|
|
|
SegmentId stack_seg = find_unique_seg_by_type(retval->seg_manager, MEM_OBJ_STACK);
|
2009-02-21 23:27:24 +00:00
|
|
|
dstack_t *stack = &(retval->seg_manager->heap[stack_seg]->data.stack);
|
2009-02-18 15:05:00 +00:00
|
|
|
|
|
|
|
retval->stack_segment = stack_seg;
|
|
|
|
retval->stack_base = stack->entries;
|
|
|
|
retval->stack_top = retval->stack_base + VM_STACK_SIZE;
|
|
|
|
}
|
|
|
|
|
2009-02-28 11:12:59 +00:00
|
|
|
static int clone_entry_used(CloneTable *table, int n) {
|
2009-02-18 15:05:00 +00:00
|
|
|
int backup;
|
|
|
|
int seeker = table->first_free;
|
2009-02-28 11:12:59 +00:00
|
|
|
CloneEntry *entries = table->table;
|
2009-02-18 15:05:00 +00:00
|
|
|
|
|
|
|
if (seeker == HEAPENTRY_INVALID) return 1;
|
|
|
|
|
|
|
|
do {
|
|
|
|
if (seeker == n) return 0;
|
|
|
|
backup = seeker;
|
|
|
|
seeker = entries[seeker].next_free;
|
|
|
|
} while (entries[backup].next_free != HEAPENTRY_INVALID);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-02-28 11:12:59 +00:00
|
|
|
static void load_script(EngineState *s, SegmentId seg) {
|
2009-02-28 22:19:22 +00:00
|
|
|
Resource *script, *heap = NULL;
|
2009-02-28 11:12:59 +00:00
|
|
|
Script *scr = &(s->seg_manager->heap[seg]->data.script);
|
2009-02-18 15:05:00 +00:00
|
|
|
|
2009-02-20 17:23:54 +00:00
|
|
|
scr->buf = (byte *)malloc(scr->buf_size);
|
2009-02-18 15:05:00 +00:00
|
|
|
|
2009-02-28 23:46:50 +00:00
|
|
|
script = s->resmgr->findResource(kResourceTypeScript, scr->nr, 0);
|
2009-02-18 15:05:00 +00:00
|
|
|
if (s->version >= SCI_VERSION(1,001,000))
|
2009-02-28 23:46:50 +00:00
|
|
|
heap = s->resmgr->findResource(kResourceTypeHeap, scr->nr, 0);
|
2009-02-18 15:05:00 +00:00
|
|
|
|
2009-02-21 23:27:24 +00:00
|
|
|
switch (s->seg_manager->isSci1_1) {
|
2009-02-18 15:05:00 +00:00
|
|
|
case 0 :
|
2009-02-21 23:27:24 +00:00
|
|
|
s->seg_manager->mcpyInOut(0, script->data, script->size, seg, SEG_ID);
|
2009-02-18 15:05:00 +00:00
|
|
|
break;
|
|
|
|
case 1 :
|
2009-02-21 23:27:24 +00:00
|
|
|
s->seg_manager->mcpyInOut(0, script->data, script->size, seg, SEG_ID);
|
|
|
|
s->seg_manager->mcpyInOut(scr->script_size, heap->data, heap->size, seg, SEG_ID);
|
2009-02-18 15:05:00 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-21 11:04:47 +00:00
|
|
|
static void reconstruct_scripts(EngineState *s, SegManager *self) {
|
2009-02-18 15:05:00 +00:00
|
|
|
int i;
|
2009-02-28 11:12:59 +00:00
|
|
|
MemObject *mobj;
|
2009-02-20 17:23:54 +00:00
|
|
|
for (i = 0; i < self->heap_size; i++) {
|
2009-02-18 15:05:00 +00:00
|
|
|
if (self->heap[i]) {
|
|
|
|
mobj = self->heap[i];
|
|
|
|
switch (mobj->type) {
|
|
|
|
case MEM_OBJ_SCRIPT: {
|
|
|
|
int j;
|
2009-02-28 11:12:59 +00:00
|
|
|
Script *scr = &mobj->data.script;
|
2009-02-18 15:05:00 +00:00
|
|
|
|
|
|
|
load_script(s, i);
|
2009-02-21 23:27:24 +00:00
|
|
|
scr->locals_block = scr->locals_segment == 0 ? NULL : &s->seg_manager->heap[scr->locals_segment]->data.locals;
|
2009-02-21 21:16:41 +00:00
|
|
|
scr->export_table = (uint16 *) find_unique_script_block(s, scr->buf, sci_obj_exports);
|
2009-02-18 15:05:00 +00:00
|
|
|
scr->synonyms = find_unique_script_block(s, scr->buf, sci_obj_synonyms);
|
|
|
|
scr->code = NULL;
|
|
|
|
scr->code_blocks_nr = 0;
|
|
|
|
scr->code_blocks_allocated = 0;
|
|
|
|
|
2009-02-21 23:27:24 +00:00
|
|
|
if (!self->isSci1_1)
|
2009-02-18 15:05:00 +00:00
|
|
|
scr->export_table += 3;
|
2009-02-22 13:11:43 +00:00
|
|
|
|
2009-02-18 15:05:00 +00:00
|
|
|
for (j = 0; j < scr->objects_nr; j++) {
|
|
|
|
byte *data = scr->buf + scr->objects[j].pos.offset;
|
|
|
|
scr->objects[j].base = scr->buf;
|
|
|
|
scr->objects[j].base_obj = data;
|
|
|
|
}
|
2009-02-21 23:27:24 +00:00
|
|
|
break;
|
2009-02-18 15:05:00 +00:00
|
|
|
}
|
2009-02-21 23:27:24 +00:00
|
|
|
default:
|
|
|
|
break;
|
2009-02-18 15:05:00 +00:00
|
|
|
}
|
|
|
|
}
|
2009-02-20 17:23:54 +00:00
|
|
|
}
|
2009-02-18 15:05:00 +00:00
|
|
|
|
2009-02-20 17:23:54 +00:00
|
|
|
for (i = 0; i < self->heap_size; i++) {
|
2009-02-18 15:05:00 +00:00
|
|
|
if (self->heap[i]) {
|
|
|
|
mobj = self->heap[i];
|
|
|
|
switch (mobj->type) {
|
|
|
|
case MEM_OBJ_SCRIPT: {
|
|
|
|
int j;
|
2009-02-28 11:12:59 +00:00
|
|
|
Script *scr = &mobj->data.script;
|
2009-02-18 15:05:00 +00:00
|
|
|
|
|
|
|
for (j = 0; j < scr->objects_nr; j++) {
|
|
|
|
byte *data = scr->buf + scr->objects[j].pos.offset;
|
|
|
|
|
2009-02-21 23:27:24 +00:00
|
|
|
if (self->isSci1_1) {
|
2009-03-07 18:43:15 +00:00
|
|
|
uint16 *funct_area = (uint16 *) (scr->buf + READ_LE_UINT16( data + 6 ));
|
|
|
|
uint16 *prop_area = (uint16 *) (scr->buf + READ_LE_UINT16( data + 4 ));
|
2009-02-18 15:05:00 +00:00
|
|
|
|
|
|
|
scr->objects[j].base_method = funct_area;
|
|
|
|
scr->objects[j].base_vars = prop_area;
|
|
|
|
} else {
|
2009-03-07 18:43:15 +00:00
|
|
|
int funct_area = READ_LE_UINT16( data + SCRIPT_FUNCTAREAPTR_OFFSET );
|
2009-02-28 11:12:59 +00:00
|
|
|
Object *base_obj;
|
2009-02-18 15:05:00 +00:00
|
|
|
|
|
|
|
base_obj = obj_get(s, scr->objects[j].variables[SCRIPT_SPECIES_SELECTOR]);
|
|
|
|
|
|
|
|
if (!base_obj) {
|
|
|
|
sciprintf("Object without a base class: Script %d, index %d (reg address "PREG"\n",
|
|
|
|
scr->nr, j, PRINT_REG(scr->objects[j].variables[SCRIPT_SPECIES_SELECTOR]));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
scr->objects[j].variable_names_nr = base_obj->variables_nr;
|
|
|
|
scr->objects[j].base_obj = base_obj->base_obj;
|
|
|
|
|
2009-02-21 21:16:41 +00:00
|
|
|
scr->objects[j].base_method = (uint16 *) (data + funct_area);
|
|
|
|
scr->objects[j].base_vars = (uint16 *) (data + scr->objects[j].variable_names_nr * 2 + SCRIPT_SELECTOR_OFFSET);
|
2009-02-18 15:05:00 +00:00
|
|
|
}
|
|
|
|
}
|
2009-02-21 23:27:24 +00:00
|
|
|
break;
|
2009-02-18 15:05:00 +00:00
|
|
|
}
|
2009-02-21 23:27:24 +00:00
|
|
|
default:
|
|
|
|
break;
|
2009-02-18 15:05:00 +00:00
|
|
|
}
|
|
|
|
}
|
2009-02-20 17:23:54 +00:00
|
|
|
}
|
2009-02-18 15:05:00 +00:00
|
|
|
}
|
|
|
|
|
2009-02-21 11:04:47 +00:00
|
|
|
void reconstruct_clones(EngineState *s, SegManager *self) {
|
2009-02-18 15:05:00 +00:00
|
|
|
int i;
|
2009-02-28 11:12:59 +00:00
|
|
|
MemObject *mobj;
|
2009-02-18 15:05:00 +00:00
|
|
|
|
2009-02-20 17:23:54 +00:00
|
|
|
for (i = 0; i < self->heap_size; i++) {
|
2009-02-18 15:05:00 +00:00
|
|
|
if (self->heap[i]) {
|
|
|
|
mobj = self->heap[i];
|
|
|
|
switch (mobj->type) {
|
|
|
|
case MEM_OBJ_CLONES: {
|
|
|
|
int j;
|
2009-02-28 11:12:59 +00:00
|
|
|
CloneEntry *seeker = mobj->data.clones.table;
|
2009-02-22 13:11:43 +00:00
|
|
|
|
2009-02-18 15:05:00 +00:00
|
|
|
sciprintf("Free list: ");
|
2009-02-20 17:23:54 +00:00
|
|
|
for (j = mobj->data.clones.first_free; j != HEAPENTRY_INVALID; j = mobj->data.clones.table[j].next_free) {
|
2009-02-18 15:05:00 +00:00
|
|
|
sciprintf("%d ", j);
|
|
|
|
}
|
|
|
|
sciprintf("\n");
|
|
|
|
|
|
|
|
sciprintf("Entries w/zero vars: ");
|
|
|
|
for (j = 0; j < mobj->data.clones.max_entry; j++) {
|
|
|
|
if (mobj->data.clones.table[j].entry.variables == NULL)
|
|
|
|
sciprintf("%d ", j);
|
|
|
|
}
|
|
|
|
sciprintf("\n");
|
|
|
|
|
|
|
|
for (j = 0; j < mobj->data.clones.max_entry; j++) {
|
2009-02-28 11:12:59 +00:00
|
|
|
Object *base_obj;
|
2009-02-18 15:05:00 +00:00
|
|
|
|
|
|
|
if (!clone_entry_used(&mobj->data.clones, j)) {
|
|
|
|
seeker++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
base_obj = obj_get(s, seeker->entry.variables[SCRIPT_SPECIES_SELECTOR]);
|
|
|
|
if (!base_obj) {
|
|
|
|
sciprintf("Clone entry without a base class: %d\n", j);
|
|
|
|
seeker->entry.base = seeker->entry.base_obj = NULL;
|
|
|
|
seeker->entry.base_vars = seeker->entry.base_method = NULL;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
seeker->entry.base = base_obj->base;
|
|
|
|
seeker->entry.base_obj = base_obj->base_obj;
|
|
|
|
seeker->entry.base_vars = base_obj->base_vars;
|
|
|
|
seeker->entry.base_method = base_obj->base_method;
|
|
|
|
|
|
|
|
seeker++;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2009-02-21 23:27:24 +00:00
|
|
|
default:
|
|
|
|
break;
|
2009-02-18 15:05:00 +00:00
|
|
|
}
|
|
|
|
}
|
2009-02-20 17:23:54 +00:00
|
|
|
}
|
2009-02-18 15:05:00 +00:00
|
|
|
}
|
|
|
|
|
2009-02-21 10:47:56 +00:00
|
|
|
int _reset_graphics_input(EngineState *s);
|
2009-02-20 17:23:54 +00:00
|
|
|
|
2009-02-21 10:47:56 +00:00
|
|
|
static void reconstruct_sounds(EngineState *s) {
|
2009-02-20 17:23:54 +00:00
|
|
|
song_t *seeker;
|
2009-02-28 22:19:22 +00:00
|
|
|
int it_type = s->resmgr->_sciVersion >= SCI_VERSION_01 ? SCI_SONG_ITERATOR_TYPE_SCI1 : SCI_SONG_ITERATOR_TYPE_SCI0;
|
2009-02-20 17:23:54 +00:00
|
|
|
|
|
|
|
if (s->sound.songlib.lib)
|
|
|
|
seeker = *(s->sound.songlib.lib);
|
|
|
|
else {
|
|
|
|
song_lib_init(&s->sound.songlib);
|
|
|
|
seeker = NULL;
|
|
|
|
}
|
2009-02-18 15:05:00 +00:00
|
|
|
|
2009-02-20 17:23:54 +00:00
|
|
|
while (seeker) {
|
2009-03-06 07:25:06 +00:00
|
|
|
SongIterator *base, *ff;
|
2009-02-20 17:23:54 +00:00
|
|
|
int oldstatus;
|
2009-03-06 07:25:06 +00:00
|
|
|
SongIteratorMessage msg;
|
2009-02-20 17:23:54 +00:00
|
|
|
|
|
|
|
base = ff = build_iterator(s, seeker->resource_num, it_type, seeker->handle);
|
|
|
|
if (seeker->restore_behavior == RESTORE_BEHAVIOR_CONTINUE)
|
2009-03-07 06:56:39 +00:00
|
|
|
ff = new_fast_forward_iterator(base, seeker->restore_time);
|
2009-03-06 07:25:48 +00:00
|
|
|
ff->init();
|
2009-02-20 17:23:54 +00:00
|
|
|
|
2009-03-06 07:25:37 +00:00
|
|
|
msg = SongIteratorMessage(seeker->handle, SIMSG_SET_LOOPS(seeker->loops));
|
2009-02-20 17:23:54 +00:00
|
|
|
songit_handle_message(&ff, msg);
|
2009-03-06 07:25:37 +00:00
|
|
|
msg = SongIteratorMessage(seeker->handle, SIMSG_SET_HOLD(seeker->hold));
|
2009-02-20 17:23:54 +00:00
|
|
|
songit_handle_message(&ff, msg);
|
|
|
|
|
|
|
|
oldstatus = seeker->status;
|
|
|
|
seeker->status = SOUND_STATUS_STOPPED;
|
|
|
|
seeker->it = ff;
|
|
|
|
sfx_song_set_status(&s->sound, seeker->handle, oldstatus);
|
|
|
|
seeker = seeker->next;
|
|
|
|
}
|
2009-02-18 15:05:00 +00:00
|
|
|
}
|
|
|
|
|
2009-03-10 14:52:02 +00:00
|
|
|
void internal_stringfrag_strncpy(EngineState *s, reg_t *dest, reg_t *src, int len);
|
|
|
|
|
2009-02-21 10:47:56 +00:00
|
|
|
EngineState *gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) {
|
2009-02-18 15:05:00 +00:00
|
|
|
int read_eof = 0;
|
2009-02-21 10:47:56 +00:00
|
|
|
EngineState *retval;
|
2009-02-18 15:05:00 +00:00
|
|
|
songlib_t temp;
|
|
|
|
|
|
|
|
/*
|
|
|
|
if (s->sound_server) {
|
|
|
|
if ((s->sound_server->restore)(s, dirname)) {
|
|
|
|
sciprintf("Restoring failed for the sound subsystem\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2009-02-22 21:38:46 +00:00
|
|
|
retval = new EngineState();
|
2009-02-18 15:05:00 +00:00
|
|
|
|
|
|
|
retval->savegame_version = -1;
|
|
|
|
_global_save_state = retval;
|
|
|
|
retval->gfx_state = s->gfx_state;
|
|
|
|
|
2009-02-28 11:07:36 +00:00
|
|
|
SavegameMetadata meta;
|
2009-02-20 23:41:15 +00:00
|
|
|
|
2009-02-28 11:07:36 +00:00
|
|
|
%CFSMLREAD-ATOMIC SavegameMetadata (&meta) FROM fh ERRVAR read_eof;
|
2009-02-27 19:50:22 +00:00
|
|
|
|
2009-02-28 11:07:36 +00:00
|
|
|
if (read_eof)
|
|
|
|
return false;
|
2009-02-27 19:50:22 +00:00
|
|
|
|
2009-02-28 11:07:36 +00:00
|
|
|
if ((meta.savegame_version < FREESCI_MINIMUM_SAVEGAME_VERSION) ||
|
|
|
|
(meta.savegame_version > FREESCI_CURRENT_SAVEGAME_VERSION)) {
|
|
|
|
if (meta.savegame_version < FREESCI_MINIMUM_SAVEGAME_VERSION)
|
2009-02-20 23:41:15 +00:00
|
|
|
sciprintf("Old savegame version detected- can't load\n");
|
|
|
|
else
|
2009-02-28 11:07:36 +00:00
|
|
|
sciprintf("Savegame version is %d- maximum supported is %0d\n", meta.savegame_version, FREESCI_CURRENT_SAVEGAME_VERSION);
|
2009-02-20 23:41:15 +00:00
|
|
|
|
2009-02-18 15:05:00 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-02-20 17:23:54 +00:00
|
|
|
// Backwards compatibility settings
|
2009-02-18 15:05:00 +00:00
|
|
|
retval->dyn_views = NULL;
|
|
|
|
retval->drop_views = NULL;
|
|
|
|
retval->port = NULL;
|
|
|
|
retval->save_dir_copy_buf = NULL;
|
|
|
|
|
|
|
|
retval->sound_mute = s->sound_mute;
|
|
|
|
retval->sound_volume = s->sound_volume;
|
|
|
|
|
2009-02-21 10:47:56 +00:00
|
|
|
%CFSMLREAD-ATOMIC EngineState retval FROM fh ERRVAR read_eof;
|
2009-02-18 15:05:00 +00:00
|
|
|
|
|
|
|
sfx_exit(&s->sound);
|
|
|
|
_gamestate_unfrob(retval);
|
|
|
|
|
2009-02-20 17:23:54 +00:00
|
|
|
// Set exec stack base to zero
|
2009-02-18 15:05:00 +00:00
|
|
|
retval->execution_stack_base = 0;
|
|
|
|
retval->execution_stack_pos = 0;
|
|
|
|
|
2009-02-20 17:23:54 +00:00
|
|
|
// Now copy all current state information
|
|
|
|
// Graphics and input state:
|
2009-02-18 15:05:00 +00:00
|
|
|
retval->animation_delay = s->animation_delay;
|
|
|
|
retval->animation_granularity = s->animation_granularity;
|
|
|
|
retval->gfx_state = s->gfx_state;
|
|
|
|
|
|
|
|
retval->resmgr = s->resmgr;
|
|
|
|
|
|
|
|
temp = retval->sound.songlib;
|
|
|
|
sfx_init(&retval->sound, retval->resmgr, s->sfx_init_flags);
|
|
|
|
retval->sfx_init_flags = s->sfx_init_flags;
|
|
|
|
song_lib_free(retval->sound.songlib);
|
|
|
|
retval->sound.songlib = temp;
|
|
|
|
|
|
|
|
_reset_graphics_input(retval);
|
|
|
|
reconstruct_stack(retval);
|
2009-02-21 23:27:24 +00:00
|
|
|
reconstruct_scripts(retval, retval->seg_manager);
|
|
|
|
reconstruct_clones(retval, retval->seg_manager);
|
2009-02-18 15:05:00 +00:00
|
|
|
retval->game_obj = s->game_obj;
|
2009-02-21 23:27:24 +00:00
|
|
|
retval->script_000 = &retval->seg_manager->heap[script_get_segment(s, 0, SCRIPT_GET_DONT_LOAD)]->data.script;
|
2009-02-18 15:05:00 +00:00
|
|
|
retval->gc_countdown = GC_INTERVAL - 1;
|
|
|
|
retval->save_dir_copy = make_reg(s->sys_strings_segment, SYS_STRING_SAVEDIR);
|
|
|
|
retval->save_dir_edit_offset = 0;
|
2009-02-21 23:27:24 +00:00
|
|
|
retval->sys_strings_segment = find_unique_seg_by_type(retval->seg_manager, MEM_OBJ_SYS_STRINGS);
|
2009-02-28 11:12:59 +00:00
|
|
|
retval->sys_strings = &(((MemObject *)(GET_SEGMENT(*retval->seg_manager, retval->sys_strings_segment, MEM_OBJ_SYS_STRINGS)))->data.sys_strings);
|
2009-02-18 15:05:00 +00:00
|
|
|
|
2009-02-26 23:03:35 +00:00
|
|
|
// Restore system strings
|
|
|
|
SystemString *str;
|
|
|
|
|
|
|
|
// First, pad memory
|
|
|
|
for (int i = 0; i < SYS_STRINGS_MAX; i++) {
|
|
|
|
str = &retval->sys_strings->strings[i];
|
2009-03-10 14:52:02 +00:00
|
|
|
char *data = (char *) str->value;
|
2009-02-26 23:03:35 +00:00
|
|
|
if (data) {
|
2009-03-10 14:52:02 +00:00
|
|
|
str->value = (reg_t *)sci_malloc(str->max_size + 1);
|
|
|
|
strcpy((char *)str->value, data);
|
2009-02-26 23:03:35 +00:00
|
|
|
free(data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
str = &retval->sys_strings->strings[SYS_STRING_SAVEDIR];
|
2009-03-10 14:52:02 +00:00
|
|
|
internal_stringfrag_strncpy(s, str->value, s->sys_strings->strings[SYS_STRING_SAVEDIR].value, str->max_size);
|
|
|
|
str->value[str->max_size].segment = s->string_frag_segment; // Make sure to terminate
|
|
|
|
str->value[str->max_size].offset &= 0xff00; // Make sure to terminate
|
2009-02-26 23:03:35 +00:00
|
|
|
|
2009-02-20 17:23:54 +00:00
|
|
|
// Time state:
|
2009-02-21 15:40:14 +00:00
|
|
|
retval->last_wait_time = g_system->getMillis();
|
2009-02-25 21:43:57 +00:00
|
|
|
retval->game_start_time = g_system->getMillis() - retval->game_time * 1000;
|
2009-02-18 15:05:00 +00:00
|
|
|
|
2009-02-20 17:23:54 +00:00
|
|
|
// static parser information:
|
2009-02-18 15:05:00 +00:00
|
|
|
retval->parser_rules = s->parser_rules;
|
|
|
|
retval->parser_words_nr = s->parser_words_nr;
|
|
|
|
retval->parser_words = s->parser_words;
|
2009-03-08 08:17:43 +00:00
|
|
|
retval->_parserSuffixes = s->_parserSuffixes;
|
2009-02-18 15:05:00 +00:00
|
|
|
retval->parser_branches_nr = s->parser_branches_nr;
|
|
|
|
retval->parser_branches = s->parser_branches;
|
|
|
|
|
2009-02-20 17:23:54 +00:00
|
|
|
// static VM/Kernel information:
|
2009-02-23 03:04:52 +00:00
|
|
|
retval->_selectorNames = s->_selectorNames;
|
2009-02-18 15:05:00 +00:00
|
|
|
retval->kernel_names_nr = s->kernel_names_nr;
|
|
|
|
retval->kernel_names = s->kernel_names;
|
|
|
|
retval->kfunct_table = s->kfunct_table;
|
|
|
|
retval->kfunct_nr = s->kfunct_nr;
|
|
|
|
retval->opcodes = s->opcodes;
|
|
|
|
|
|
|
|
memcpy(&(retval->selector_map), &(s->selector_map), sizeof(selector_map_t));
|
|
|
|
|
|
|
|
retval->max_version = retval->version;
|
|
|
|
retval->min_version = retval->version;
|
|
|
|
retval->parser_base = make_reg(s->sys_strings_segment, SYS_STRING_PARSER_BASE);
|
|
|
|
|
2009-02-20 17:23:54 +00:00
|
|
|
// Copy breakpoint information from current game instance
|
2009-02-18 15:05:00 +00:00
|
|
|
retval->have_bp = s->have_bp;
|
|
|
|
retval->bp_list = s->bp_list;
|
|
|
|
|
|
|
|
retval->debug_mode = s->debug_mode;
|
|
|
|
|
|
|
|
retval->kernel_opt_flags = 0;
|
2009-02-18 17:57:57 +00:00
|
|
|
retval->have_mouse_flag = 1;
|
2009-02-18 15:05:00 +00:00
|
|
|
|
|
|
|
retval->successor = NULL;
|
|
|
|
retval->pic_priority_table = (int*)gfxop_get_pic_metainfo(retval->gfx_state);
|
|
|
|
retval->game_name = sci_strdup(obj_get_name(retval, retval->game_obj));
|
|
|
|
|
|
|
|
retval->sound.it = NULL;
|
|
|
|
retval->sound.flags = s->sound.flags;
|
|
|
|
retval->sound.song = NULL;
|
|
|
|
retval->sound.suspended = s->sound.suspended;
|
|
|
|
retval->sound.debug = s->sound.debug;
|
|
|
|
reconstruct_sounds(retval);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
2009-02-20 23:41:15 +00:00
|
|
|
|
|
|
|
bool get_savegame_metadata(Common::SeekableReadStream* stream, SavegameMetadata* meta) {
|
|
|
|
int read_eof = 0;
|
|
|
|
|
|
|
|
%CFSMLREAD-ATOMIC SavegameMetadata meta FROM stream ERRVAR read_eof;
|
|
|
|
|
2009-02-28 11:07:36 +00:00
|
|
|
if (read_eof)
|
2009-02-20 23:41:15 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if ((meta->savegame_version < FREESCI_MINIMUM_SAVEGAME_VERSION) ||
|
|
|
|
(meta->savegame_version > FREESCI_CURRENT_SAVEGAME_VERSION)) {
|
|
|
|
if (meta->savegame_version < FREESCI_MINIMUM_SAVEGAME_VERSION)
|
|
|
|
sciprintf("Old savegame version detected- can't load\n");
|
|
|
|
else
|
|
|
|
sciprintf("Savegame version is %d- maximum supported is %0d\n", meta->savegame_version, FREESCI_CURRENT_SAVEGAME_VERSION);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-02-21 10:23:36 +00:00
|
|
|
} // End of namespace Sci
|