protected bool LoadState(string path)
{
using (var file = ServiceLocator.FileStorage.OpenFileRead(path))
{
var br = new BinaryReader(file);
var hdr = LoadSaveGameHeader(br);
var serializer = Serializer.CreateReader(br, hdr.Version);
// Since version 56 we save additional information about the creation of
// the save game and the save time.
if (hdr.Version >= 56)
{
var infos = LoadInfos(br);
if (infos == null)
{
//warning("Info section could not be found");
//delete in;
return false;
}
//SetTotalPlayTime(infos.playtime * 1000);
}
//else
//{
// start time counting
//setTotalPlayTime();
//}
// Due to a bug in scummvm up to and including 0.3.0, save games could be saved
// in the V8/V9 format but were tagged with a V7 mark. Ouch. So we just pretend V7 == V8 here
if (hdr.Version == 7)
hdr.Version = 8;
//_saveLoadDescription = hdr.name;
// Unless specifically requested with _saveSound, we do not save the iMUSE
// state for temporary state saves - such as certain cutscenes in DOTT,
// FOA, Sam and Max, etc.
//
// Thus, we should probably not stop music when restoring from one of
// these saves. This change stops the Mole Man theme from going quiet in
// Sam & Max when Doug tells you about the Ball of Twine, as mentioned in
// patch #886058.
//
// If we don't have iMUSE at all we may as well stop the sounds. The previous
// default behavior here was to stopAllSounds on all state restores.
if (IMuse == null || _saveSound || !_saveTemporaryState)
Sound.StopAllSounds();
// Sound->stopCD();
Sound.PauseSounds(true);
//closeRoom();
_inventory = new ushort[_inventory.Length];
_invData = new ObjectData[_invData.Length];
_newNames.Clear();
// Because old savegames won't fill the entire gfxUsageBits[] array,
// clear it here just to be sure it won't hold any unforseen garbage.
Gdi.ClearGfxUsageBits();
// Nuke all resources
//for (ResType type = rtFirst; type <= rtLast; type = ResType(type + 1))
// if (type != rtTemp && type != rtBuffer && (type != rtSound || _saveSound || !compat))
// for (ResId idx = 0; idx < _res->_types[type].size(); idx++)
// {
// _res->nukeResource(type, idx);
// }
Array.Clear(_strings, 0, _strings.Length);
ResetScummVars();
//if (_game.features & GF_OLD_BUNDLE)
// loadCharset(0); // FIXME - HACK ?
//
// Now do the actual loading
//
SaveOrLoad(serializer);
// Update volume settings
// SyncSoundSettings();
if (Game.Version < 7)
{
Camera.LastPosition.X = Camera.CurrentPosition.X;
}
var sb = _screenB;
var sh = _screenH;
// Restore the virtual screens and force a fade to black.
InitScreens(0, ScreenHeight);
Gdi.Fill(MainVirtScreen.Surfaces[0].Pixels, MainVirtScreen.Pitch, 0, MainVirtScreen.Width, MainVirtScreen.Height);
MainVirtScreen.SetDirtyRange(0, MainVirtScreen.Height);
UpdateDirtyScreen(MainVirtScreen);
//UpdatePalette();
_gfxManager.SetPalette(_currentPalette.Colors);
InitScreens(sb, sh);
_completeScreenRedraw = true;
// Reset charset mask
_charset.HasMask = false;
ClearTextSurface();
ClearDrawObjectQueue();
_verbMouseOver = 0;
CameraMoved();
Gdi.NumZBuffer = GetNumZBuffers();
Gdi.SetMaskHeight(roomData.Header.Height);
if (VariableRoomFlag.HasValue)
{
Variables[VariableRoomFlag.Value] = 1;
}
// Sync with current config setting
if (VariableVoiceMode.HasValue)
{
Variables[VariableVoiceMode.Value] = (int)VoiceMode.VoiceAndText;
}
Sound.PauseSounds(false);
}
return true;
}