mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-16 14:50:17 +00:00
GOB: Implement Urban Runner autosave
Makes the "Try again" after a death work svn-id: r55293
This commit is contained in:
parent
4413754ad2
commit
efe0dea82c
@ -517,9 +517,30 @@ protected:
|
||||
void refreshProps();
|
||||
};
|
||||
|
||||
/** Handles the autosave. */
|
||||
class AutoHandler : public SaveHandler {
|
||||
public:
|
||||
AutoHandler(GobEngine *vm, const Common::String &target);
|
||||
~AutoHandler();
|
||||
|
||||
int32 getSize();
|
||||
bool load(int16 dataVar, int32 size, int32 offset);
|
||||
bool save(int16 dataVar, int32 size, int32 offset);
|
||||
|
||||
private:
|
||||
class File : public SlotFileStatic {
|
||||
public:
|
||||
File(GobEngine *vm, const Common::String &base);
|
||||
~File();
|
||||
};
|
||||
|
||||
File _file;
|
||||
};
|
||||
|
||||
static SaveFile _saveFiles[];
|
||||
|
||||
GameHandler *_gameHandler;
|
||||
AutoHandler *_autoHandler;
|
||||
|
||||
SaveHandler *getHandler(const char *fileName) const;
|
||||
const char *getDescription(const char *fileName) const;
|
||||
|
@ -31,9 +31,10 @@
|
||||
namespace Gob {
|
||||
|
||||
SaveLoad_v6::SaveFile SaveLoad_v6::_saveFiles[] = {
|
||||
{ "cat.inf", kSaveModeSave, 0, "savegame"}, // Save file
|
||||
{ "mdo.def", kSaveModeExists, 0, 0},
|
||||
{"no_cd.txt", kSaveModeExists, 0, 0},
|
||||
{ "cat.inf" , kSaveModeSave, 0, "savegame"}, // Save file
|
||||
{ "cata1.inf", kSaveModeSave, 0, "autosave"}, // Autosave file
|
||||
{ "mdo.def" , kSaveModeExists, 0, 0},
|
||||
{"no_cd.txt" , kSaveModeExists, 0, 0},
|
||||
};
|
||||
|
||||
|
||||
@ -275,15 +276,113 @@ void SaveLoad_v6::GameHandler::refreshProps() {
|
||||
}
|
||||
|
||||
|
||||
SaveLoad_v6::AutoHandler::File::File(GobEngine *vm, const Common::String &base) :
|
||||
SlotFileStatic(vm, base, "aut") {
|
||||
}
|
||||
|
||||
SaveLoad_v6::AutoHandler::File::~File() {
|
||||
}
|
||||
|
||||
|
||||
SaveLoad_v6::AutoHandler::AutoHandler(GobEngine *vm, const Common::String &target) :
|
||||
SaveHandler(vm), _file(vm, target) {
|
||||
}
|
||||
|
||||
SaveLoad_v6::AutoHandler::~AutoHandler() {
|
||||
}
|
||||
|
||||
int32 SaveLoad_v6::AutoHandler::getSize() {
|
||||
Common::String fileName = _file.build();
|
||||
if (fileName.empty())
|
||||
return -1;
|
||||
|
||||
SaveReader reader(1, 0, fileName);
|
||||
SaveHeader header;
|
||||
|
||||
if (!reader.load())
|
||||
return -1;
|
||||
|
||||
if (!reader.readPartHeader(0, &header))
|
||||
return -1;
|
||||
|
||||
// Return the part's size
|
||||
return header.getSize() + 2900;
|
||||
}
|
||||
|
||||
bool SaveLoad_v6::AutoHandler::load(int16 dataVar, int32 size, int32 offset) {
|
||||
uint32 varSize = SaveHandler::getVarSize(_vm);
|
||||
if (varSize == 0)
|
||||
return false;
|
||||
|
||||
if ((size != 0) || (offset != 2900)) {
|
||||
warning("Invalid autoloading procedure (%d, %d, %d)", dataVar, size, offset);
|
||||
return false;
|
||||
}
|
||||
|
||||
Common::String fileName = _file.build();
|
||||
if (fileName.empty())
|
||||
return false;
|
||||
|
||||
SaveReader reader(1, 0, fileName);
|
||||
SaveHeader header;
|
||||
SavePartVars vars(_vm, varSize);
|
||||
|
||||
if (!reader.load())
|
||||
return false;
|
||||
|
||||
if (!reader.readPartHeader(0, &header))
|
||||
return false;
|
||||
|
||||
if (header.getSize() != varSize) {
|
||||
warning("Autosave mismatch (%d, %d)", header.getSize(), varSize);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!reader.readPart(0, &vars))
|
||||
return false;
|
||||
|
||||
if (!vars.writeInto(0, 0, varSize))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SaveLoad_v6::AutoHandler::save(int16 dataVar, int32 size, int32 offset) {
|
||||
uint32 varSize = SaveHandler::getVarSize(_vm);
|
||||
if (varSize == 0)
|
||||
return false;
|
||||
|
||||
if ((size != 0) || (offset != 2900)) {
|
||||
warning("Invalid autosaving procedure (%d, %d, %d)", dataVar, size, offset);
|
||||
return false;
|
||||
}
|
||||
|
||||
Common::String fileName = _file.build();
|
||||
if (fileName.empty())
|
||||
return false;
|
||||
|
||||
SaveWriter writer(1, 0, fileName);
|
||||
SavePartVars vars(_vm, varSize);
|
||||
|
||||
if (!vars.readFrom(0, 0, varSize))
|
||||
return false;
|
||||
|
||||
return writer.writePart(0, &vars);
|
||||
}
|
||||
|
||||
|
||||
SaveLoad_v6::SaveLoad_v6(GobEngine *vm, const char *targetName) :
|
||||
SaveLoad(vm) {
|
||||
|
||||
_gameHandler = new GameHandler(vm, targetName);
|
||||
_autoHandler = new AutoHandler(vm, targetName);
|
||||
|
||||
_saveFiles[0].handler = _gameHandler;
|
||||
_saveFiles[1].handler = _autoHandler;
|
||||
}
|
||||
|
||||
SaveLoad_v6::~SaveLoad_v6() {
|
||||
delete _autoHandler;
|
||||
delete _gameHandler;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user