SaveStateList GrimMetaEngine::listSaves(const char *target) const { Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); Common::StringArray filenames; Common::String pattern = "grim*.gsv"; filenames = saveFileMan->listSavefiles(pattern); SaveStateList saveList; char str[256]; int32 strSize; for (Common::StringArray::const_iterator file = filenames.begin(); file != filenames.end(); ++file) { // Obtain the last digits of the filename, since they correspond to the save slot int slotNum = atoi(file->c_str() + 4); if (slotNum >= 0) { SaveGame *savedState = SaveGame::openForLoading(*file); if (savedState && savedState->isCompatible()) { savedState->beginSection('SUBS'); strSize = savedState->readLESint32(); savedState->read(str, strSize); savedState->endSection(); saveList.push_back(SaveStateDescriptor(slotNum, str)); } delete savedState; } } Common::sort(saveList.begin(), saveList.end(), cmpSave); return saveList; }
void Lua_V2::ThumbnailFromFile() { lua_Object texIdObj = lua_getparam(1); lua_Object filenameObj = lua_getparam(2); if (!lua_isnumber(texIdObj) || !lua_isstring(filenameObj)) { warning("Lua_V2::ThumbnailFromFile: wrong parameters"); return; } int index = (int)lua_getnumber(texIdObj); const char *filename = lua_getstring(filenameObj); int width = 256, height = 128; Bitmap *screenshot; SaveGame *savedState = SaveGame::openForLoading(filename); if (!savedState || !savedState->isCompatible()) { delete savedState; warning("Lua_V2::ThumbnailFromFile: savegame %s not compatible", filename); lua_pushnil(); return; } int dataSize = savedState->beginSection('SIMG'); if (dataSize != width * height * 2) { warning("Lua_V2::ThumbnailFromFile: savegame uses unexpected thumbnail size, ignore it"); lua_pushnil(); delete savedState; return; } uint16 *data = new uint16[dataSize / 2]; for (int l = 0; l < dataSize / 2; l++) { data[l] = savedState->readLEUint16(); } Graphics::PixelBuffer buf(Graphics::createPixelFormat<565>(), (byte *)data); screenshot = new Bitmap(buf, width, height, "screenshot"); if (!screenshot) { lua_pushnil(); warning("Lua_V2::ThumbnailFromFile: Could not restore screenshot from file %s", filename); delete[] data; delete savedState; return; } screenshot->_data->convertToColorFormat(Graphics::PixelFormat(4, 8, 8, 8, 8, 0, 8, 16, 24)); g_driver->createSpecialtyTexture(index, screenshot->getData(0).getRawBuffer(), width, height); delete[] data; savedState->endSection(); delete savedState; pushbool(true); }
void Lua_V1::GetSaveGameData() { lua_Object param = lua_getparam(1); if (!lua_isstring(param)) return; const char *filename = lua_getstring(param); SaveGame *savedState = SaveGame::openForLoading(filename); lua_Object result = lua_createtable(); if (!savedState || !savedState->isCompatible()) { lua_pushobject(result); lua_pushnumber(2); lua_pushstring("mo.set"); // Just a placeholder to not make it throw a lua error lua_settable(); lua_pushobject(result); if (!savedState) { warning("Savegame %s is invalid", filename); } else { warning("Savegame %s is incompatible with this ResidualVM build. Save version: %d.%d; current version: %d.%d", filename, savedState->saveMajorVersion(), savedState->saveMinorVersion(), SaveGame::SAVEGAME_MAJOR_VERSION, SaveGame::SAVEGAME_MINOR_VERSION); } delete savedState; return; } int32 dataSize = savedState->beginSection('SUBS'); char str[200]; int32 strSize; int count = 0; for (;;) { if (dataSize <= 0) break; strSize = savedState->readLESint32(); savedState->read(str, strSize); lua_pushobject(result); lua_pushnumber(count); lua_pushstring(str); lua_settable(); dataSize -= strSize; dataSize -= 4; count++; } lua_pushobject(result); savedState->endSection(); delete savedState; }
SaveStateList GrimMetaEngine::listSaves(const char *target) const { Common::String gameId = ConfMan.get("gameid", target); Common::Platform platform = Common::parsePlatform(ConfMan.get("platform", target)); Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); Common::StringArray filenames; Common::String pattern = gameId == "monkey4" ? "efmi###.gsv" : "grim##.gsv"; if (platform == Common::kPlatformPS2) pattern = "efmi###.ps2"; filenames = saveFileMan->listSavefiles(pattern); SaveStateList saveList; char str[256]; int32 strSize; for (Common::StringArray::const_iterator file = filenames.begin(); file != filenames.end(); ++file) { // Obtain the last digits of the filename, since they correspond to the save slot int slotNum = atoi(file->c_str() + 4); if (slotNum >= 0) { SaveGame *savedState = SaveGame::openForLoading(*file); if (savedState && savedState->isCompatible()) { if (platform == Common::kPlatformPS2) savedState->beginSection('PS2S'); else savedState->beginSection('SUBS'); strSize = savedState->readLESint32(); savedState->read(str, strSize); savedState->endSection(); saveList.push_back(SaveStateDescriptor(slotNum, str)); } delete savedState; } } Common::sort(saveList.begin(), saveList.end(), SaveStateDescriptorSlotComparator()); return saveList; }
void Lua_V1::GetSaveGameImage() { int width = 250, height = 188; Bitmap *screenshot; int dataSize; lua_Object param = lua_getparam(1); if (!lua_isstring(param)) { lua_pushnil(); return; } const char *filename = lua_getstring(param); SaveGame *savedState = SaveGame::openForLoading(filename); if (!savedState || !savedState->isCompatible()) { delete savedState; lua_pushnil(); return; } dataSize = savedState->beginSection('SIMG'); uint16 *data = new uint16[dataSize / 2]; for (int l = 0; l < dataSize / 2; l++) { data[l] = savedState->readLEUint16(); } Graphics::PixelBuffer buf(Graphics::createPixelFormat<565>(), (byte *)data); screenshot = new Bitmap(buf, width, height, "screenshot"); delete[] data; if (screenshot) { lua_pushusertag(screenshot->getId(), MKTAG('V','B','U','F')); } else { lua_pushnil(); warning("Could not restore screenshot from file"); delete savedState; return; } savedState->endSection(); delete savedState; }