diff options
Diffstat (limited to 'engines/dm/loadsave.cpp')
-rw-r--r-- | engines/dm/loadsave.cpp | 140 |
1 files changed, 125 insertions, 15 deletions
diff --git a/engines/dm/loadsave.cpp b/engines/dm/loadsave.cpp index 28b57f2651..9b50351376 100644 --- a/engines/dm/loadsave.cpp +++ b/engines/dm/loadsave.cpp @@ -42,32 +42,96 @@ namespace DM { #define C2_FORMAT_DM_AMIGA_2X_PC98_X68000_FM_TOWNS_CSB_ATARI_ST 2 #define C3_PLATFORM_AMIGA 3 #define C10_DUNGEON_DM 10 -LoadgameResponse DMEngine::f435_loadgame() { - bool newGame = _g298_newGame; - ChampionMan &cm = *_championMan; +LoadgameResponse DMEngine::f435_loadgame(int16 slot) { + Common::String fileName; + Common::SaveFileManager *saveFileManager = nullptr; + Common::InSaveFile *file = nullptr; + + if (!_g298_newGame) { + fileName = getSavefileName(slot); + saveFileManager = _system->getSavefileManager(); + file = saveFileManager->openForLoading(fileName); + } + _g528_saveFormat = C2_FORMAT_DM_AMIGA_2X_PC98_X68000_FM_TOWNS_CSB_ATARI_ST; _g527_platform = C3_PLATFORM_AMIGA; _g526_dungeonId = C10_DUNGEON_DM; - if (newGame) { + if (_g298_newGame) { + //L1366_B_FadePalette = !F0428_DIALOG_RequireGameDiskInDrive_NoDialogDrawn(C0_DO_NOT_FORCE_DIALOG_DM_CSB, true); +T0435002: _g524_restartGameAllowed = false; - cm._g305_partyChampionCount = 0; - cm._g414_leaderHandObject = Thing::_none; - _g525_gameId = _rnd->getRandomNumber(65536) * _rnd->getRandomNumber(65536); + _championMan->_g305_partyChampionCount = 0; + _championMan->_g414_leaderHandObject = Thing::_none; + _g525_gameId = ((int32)getRandomNumber(65536)) * getRandomNumber(65536); } else { - assert(false); - // MISSING CODE: load game - } - _dungeonMan->f434_loadDungeonFile(); + warning(false, "MISSING CODE: missing check for matching _g525_gameId in f435_loadgame"); + /*if (_vm->_g523_restartGameRequest && (L1372_s_SaveHeader.GameID != _vm->_g525_gameId)) { + L1367_pc_Message = G0546_pc_THATSNOTTHESAMEGAME; + goto T0435004; + }*/ + + SaveGameHeader header; + readSaveGameHeader(file, &header); + + warning(false, "MISSING CODE: missing check for matching format and platform in save in f435_loadgame"); + + _g313_gameTime = file->readUint32BE(); + // G0349_ul_LastRandomNumber = L1371_s_GlobalData.LastRandomNumber; + _championMan->_g305_partyChampionCount = file->readUint16BE(); + _dungeonMan->_g306_partyMapX = file->readSint16BE(); + _dungeonMan->_g307_partyMapY = file->readSint16BE(); + _dungeonMan->_g308_partyDir = (direction)file->readUint16BE(); + _dungeonMan->_g309_partyMapIndex = file->readByte(); + _championMan->_g411_leaderIndex = (ChampionIndex)file->readSint16BE(); + _championMan->_g514_magicCasterChampionIndex = (ChampionIndex)file->readSint16BE(); + _timeline->_g372_eventCount = file->readUint16BE(); + _timeline->_g373_firstUnusedEventIndex = file->readUint16BE(); + _timeline->_g369_eventMaxCount = file->readUint16BE(); + _groupMan->_g377_currActiveGroupCount = file->readUint16BE(); + _projexpl->_g361_lastCreatureAttackTime = file->readSint32BE(); + _projexpl->_g362_lastPartyMovementTime = file->readSint32BE(); + _g310_disabledMovementTicks = file->readSint16BE(); + _g311_projectileDisableMovementTicks = file->readSint16BE(); + _g312_lastProjectileDisabledMovementDirection = file->readSint16BE(); + _championMan->_g414_leaderHandObject = Thing(file->readUint16BE()); + _groupMan->_g376_maxActiveGroupCount = file->readUint16BE(); + if (!_g523_restartGameRequest) { + _timeline->f233_initTimeline(); + _groupMan->f196_initActiveGroups(); + } - if (newGame) { + _groupMan->load1_ActiveGroupPart(file); + _championMan->load2_PartyPart(file); + _timeline->load3_eventsPart(file); + _timeline->load4_timelinePart(file); + + _g525_gameId = file->readSint32BE(); + } + + _dungeonMan->f434_loadDungeonFile(); + if (_g298_newGame) { _timeline->f233_initTimeline(); _groupMan->f196_initActiveGroups(); + warning(false, "MISSING CODE: missing fadePlette stuff in f435_loadgame on newGame"); + /* + if (L1366_B_FadePalette) { + F0436_STARTEND_FadeToPalette(G0345_aui_BlankBuffer); + D26_WaitForVerticalBlank(); + D18_FillScreenBlack(); + F0436_STARTEND_FadeToPalette(_vm->_displayMan->_g347_paletteTopAndBottomScreen); + }*/ } else { - assert(false); - // MISSING CODE: load game + _g528_saveFormat = file->readSint16BE(); + _g527_platform = file->readSint16BE(); + _g526_dungeonId = file->readUint16BE(); + + _g524_restartGameAllowed = true; + warning(false, "MISSING CDOE: F0427_DIALOG_Draw in f435_loadgame"); } - cm._g303_partyDead = false; + _championMan->_g303_partyDead = false; + + delete file; return k1_LoadgameSuccess; } @@ -176,4 +240,50 @@ void DMEngine::writeSaveGameHeader(Common::OutSaveFile* out, const Common::Strin out->writeUint32BE(playTime); } + +bool DMEngine::readSaveGameHeader(Common::InSaveFile* in, SaveGameHeader* header) { + uint32 id = in->readUint32BE(); + + // Check if it's a valid ScummVM savegame + if (id != SAVEGAME_ID) + return false; + + // Read in the version + header->_version = in->readByte(); + + // Check that the save version isn't newer than this binary + if (header->_version > SAVEGAME_VERSION) + return false; + + // Read in the save name + Common::String saveName; + char ch; + while ((ch = (char)in->readByte()) != '\0') + saveName += ch; + header->_descr.setDescription(saveName); + + // Get the thumbnail + header->_descr.setThumbnail(Graphics::loadThumbnail(*in)); + + uint32 saveDate = in->readUint32BE(); + uint16 saveTime = in->readUint16BE(); + uint32 playTime = in->readUint32BE(); + + int day = (saveDate >> 24) & 0xFF; + int month = (saveDate >> 16) & 0xFF; + int year = saveDate & 0xFFFF; + header->_descr.setSaveDate(year, month, day); + + int hour = (saveTime >> 8) & 0xFF; + int minutes = saveTime & 0xFF; + header->_descr.setSaveTime(hour, minutes); + + header->_descr.setPlayTime(playTime * 1000); + if (g_engine) + g_engine->setTotalPlayTime(playTime * 1000); + + return true; } + +} + |