From dee8a04168fb0d0ccc58b73dd9fb8d0be9499b17 Mon Sep 17 00:00:00 2001 From: Sven Hesse Date: Sun, 8 Apr 2007 00:08:26 +0000 Subject: Restructured saving/loading. Should work for Gob3 now, too... svn-id: r26414 --- engines/gob/inter_v2.cpp | 55 ++++++++++++++++++++++-------------------------- 1 file changed, 25 insertions(+), 30 deletions(-) (limited to 'engines/gob/inter_v2.cpp') diff --git a/engines/gob/inter_v2.cpp b/engines/gob/inter_v2.cpp index 688f52a155..819ba6df11 100644 --- a/engines/gob/inter_v2.cpp +++ b/engines/gob/inter_v2.cpp @@ -43,6 +43,7 @@ #include "gob/scenery.h" #include "gob/sound.h" #include "gob/video.h" +#include "gob/saveload.h" namespace Gob { @@ -1776,21 +1777,16 @@ bool Inter_v2::o2_checkData(OpFuncParams ¶ms) { int16 handle; int16 varOff; int32 size; + SaveType type; evalExpr(0); varOff = _vm->_parse->parseVarIndex(); size = -1; handle = 1; - if (!scumm_stricmp(_vm->_global->_inter_resStr, "cat.inf")) - size = _vm->getSaveSize(SAVE_CAT); - else if (!scumm_stricmp(_vm->_global->_inter_resStr, "cat.cat")) - size = _vm->getSaveSize(SAVE_CAT); - else if (!scumm_stricmp(_vm->_global->_inter_resStr, "save.inf")) - size = _vm->getSaveSize(SAVE_SAV); - else if (!scumm_stricmp(_vm->_global->_inter_resStr, "bloc.inf")) - size = _vm->getSaveSize(SAVE_BLO); - else { + + type = _vm->_saveLoad->getSaveType(_vm->_global->_inter_resStr); + if (type == kSaveNone) { handle = _vm->_dataIO->openData(_vm->_global->_inter_resStr); if (handle >= 0) { @@ -1798,10 +1794,15 @@ bool Inter_v2::o2_checkData(OpFuncParams ¶ms) { size = _vm->_dataIO->getDataSize(_vm->_global->_inter_resStr); } else warning("File \"%s\" not found", _vm->_global->_inter_resStr); - } + } else + size = _vm->_saveLoad->getSize(type); + if (size == -1) handle = -1; + debugC(2, kDebugFileIO, "Requested size of file \"%s\": %d", + _vm->_global->_inter_resStr, size); + WRITE_VAR_OFFSET(varOff, handle); WRITE_VAR(16, (uint32) size); @@ -1815,6 +1816,7 @@ bool Inter_v2::o2_readData(OpFuncParams ¶ms) { int16 dataVar; int16 handle; byte *buf; + SaveType type; evalExpr(0); dataVar = _vm->_parse->parseVarIndex(); @@ -1825,17 +1827,11 @@ bool Inter_v2::o2_readData(OpFuncParams ¶ms) { debugC(2, kDebugFileIO, "Read from file \"%s\" (%d, %d bytes at %d)", _vm->_global->_inter_resStr, dataVar, size, offset); - if (!scumm_stricmp(_vm->_global->_inter_resStr, "cat.inf")) { - _vm->loadGameData(SAVE_CAT, dataVar, size, offset); - return false; - } else if (!scumm_stricmp(_vm->_global->_inter_resStr, "cat.cat")) { - _vm->loadGameData(SAVE_CAT, dataVar, size, offset); - return false; - } else if (!scumm_stricmp(_vm->_global->_inter_resStr, "save.inf")) { - _vm->loadGameData(SAVE_SAV, dataVar, size, offset); - return false; - } else if (!scumm_stricmp(_vm->_global->_inter_resStr, "bloc.inf")) { - _vm->loadGameData(SAVE_BLO, dataVar, size, offset); + type = _vm->_saveLoad->getSaveType(_vm->_global->_inter_resStr); + if (type != kSaveNone) { + WRITE_VAR(1, 1); + if (_vm->_saveLoad->load(type, dataVar, size, offset)) + WRITE_VAR(1, 0); return false; } @@ -1888,6 +1884,7 @@ bool Inter_v2::o2_writeData(OpFuncParams ¶ms) { int32 offset; int32 size; int16 dataVar; + SaveType type; evalExpr(0); dataVar = _vm->_parse->parseVarIndex(); @@ -1898,15 +1895,13 @@ bool Inter_v2::o2_writeData(OpFuncParams ¶ms) { debugC(2, kDebugFileIO, "Write to file \"%s\" (%d, %d bytes at %d)", _vm->_global->_inter_resStr, dataVar, size, offset); - if (!scumm_stricmp(_vm->_global->_inter_resStr, "cat.inf")) - _vm->saveGameData(SAVE_CAT, dataVar, size, offset); - else if (!scumm_stricmp(_vm->_global->_inter_resStr, "cat.cat")) - _vm->saveGameData(SAVE_CAT, dataVar, size, offset); - else if (!scumm_stricmp(_vm->_global->_inter_resStr, "save.inf")) - _vm->saveGameData(SAVE_SAV, dataVar, size, offset); - else if (!scumm_stricmp(_vm->_global->_inter_resStr, "bloc.inf")) - _vm->saveGameData(SAVE_BLO, dataVar, size, offset); - else + WRITE_VAR(1, 1); + + type = _vm->_saveLoad->getSaveType(_vm->_global->_inter_resStr); + if (type != kSaveNone) { + if (_vm->_saveLoad->save(type, dataVar, size, offset)) + WRITE_VAR(1, 0); + } else warning("Attempted to write to file \"%s\"", _vm->_global->_inter_resStr); return false; -- cgit v1.2.3