public static ZwinderStateManager Create(BinaryReader br, ZwinderStateManagerSettings settings, Func <int, bool> reserveCallback) { // Initial format had no version number, but I think it's a safe bet no valid file has buffer size 2^56 or more so this should work. int version = br.ReadByte(); var current = ZwinderBuffer.Create(br, settings.Current(), version == 0); var recent = ZwinderBuffer.Create(br, settings.Recent()); var gaps = ZwinderBuffer.Create(br, settings.GapFiller()); if (version == 0) { settings.AncientStateInterval = br.ReadInt32(); } var ret = new ZwinderStateManager(current, recent, gaps, reserveCallback, settings); var ancientCount = br.ReadInt32(); for (var i = 0; i < ancientCount; i++) { var key = br.ReadInt32(); var length = br.ReadInt32(); var data = br.ReadBytes(length); ret._reserved.Add(key, data); } ret.RebuildStateCache(); return(ret); }
public static ZwinderStateManager Create(BinaryReader br, ZwinderStateManagerSettings settings, Func <int, bool> reserveCallback) { var current = ZwinderBuffer.Create(br); var recent = ZwinderBuffer.Create(br); var gaps = ZwinderBuffer.Create(br); var ancientInterval = br.ReadInt32(); var ret = new ZwinderStateManager(current, recent, gaps, ancientInterval, reserveCallback) { Settings = settings }; var ancientCount = br.ReadInt32(); for (var i = 0; i < ancientCount; i++) { var key = br.ReadInt32(); var length = br.ReadInt32(); var data = br.ReadBytes(length); ret._reserved.Add(key, data); } ret.RebuildStateCache(); return(ret); }
public static ZwinderStateManager Create(BinaryReader br, ZwinderStateManagerSettings settings) { var current = ZwinderBuffer.Create(br); var recent = ZwinderBuffer.Create(br); var highPriority = ZwinderBuffer.Create(br); var original = br.ReadBytes(br.ReadInt32()); var ancientInterval = br.ReadInt32(); var ret = new ZwinderStateManager(current, recent, highPriority, original, ancientInterval) { Settings = settings }; var ancientCount = br.ReadInt32(); for (var i = 0; i < ancientCount; i++) { var key = br.ReadInt32(); var length = br.ReadInt32(); var data = br.ReadBytes(length); ret._ancient.Add(new KeyValuePair <int, byte[]>(key, data)); } return(ret); }
/// <exception cref="InvalidOperationException">loaded core does not implement <see cref="IStatable"/></exception> internal TasMovie(IMovieSession session, string path) : base(session, path) { Branches = new TasBranchCollection(this); ChangeLog = new TasMovieChangeLog(this); Header[HeaderKeys.MovieVersion] = $"BizHawk v2.0 Tasproj v{CurrentVersion}"; Markers = new TasMovieMarkerList(this); Markers.CollectionChanged += Markers_CollectionChanged; Markers.Add(0, "Power on"); TasStateManager = new ZwinderStateManager(); }
/// <exception cref="InvalidOperationException">loaded core does not implement <see cref="IStatable"/></exception> internal TasMovie(IMovieSession session, string path) : base(session, path) { Branches = new TasBranchCollection(this); ChangeLog = new TasMovieChangeLog(this); Header[HeaderKeys.MovieVersion] = $"BizHawk v2.0 Tasproj v{CurrentVersion.ToString(CultureInfo.InvariantCulture)}"; Markers = new TasMovieMarkerList(this); Markers.CollectionChanged += Markers_CollectionChanged; Markers.Add(0, "Power on"); TasStateManager = new ZwinderStateManager( session.Settings.DefaultTasStateManagerSettings, IsReserved); }
private void LoadTasprojExtras(ZipStateLoader bl) { bl.GetLump(BinaryStateLump.LagLog, false, delegate(TextReader tr) { LagLog.Load(tr); }); bl.GetLump(BinaryStateLump.Markers, false, delegate(TextReader tr) { string line; while ((line = tr.ReadLine()) != null) { if (!string.IsNullOrWhiteSpace(line)) { Markers.Add(new TasMovieMarker(line)); } } }); if (GetClientSettingsOnLoad != null) { string clientSettings = ""; bl.GetLump(BinaryStateLump.ClientSettings, false, delegate(TextReader tr) { string line; while ((line = tr.ReadLine()) != null) { if (!string.IsNullOrWhiteSpace(line)) { clientSettings = line; } } }); if (!string.IsNullOrWhiteSpace(clientSettings)) { GetClientSettingsOnLoad(clientSettings); } } bl.GetLump(BinaryStateLump.VerificationLog, false, delegate(TextReader tr) { VerificationLog.Clear(); while (true) { var line = tr.ReadLine(); if (string.IsNullOrEmpty(line)) { break; } if (line.StartsWith("|")) { VerificationLog.Add(line); } } }); Branches.Load(bl, this); bl.GetLump(BinaryStateLump.Session, false, delegate(TextReader tr) { var json = tr.ReadToEnd(); try { TasSession = JsonConvert.DeserializeObject <TasSession>(json); } catch { // Do nothing, and use default settings instead } }); ZwinderStateManagerSettings settings = new ZwinderStateManagerSettings(); bl.GetLump(BinaryStateLump.StateHistorySettings, false, delegate(TextReader tr) { var json = tr.ReadToEnd(); try { settings = JsonConvert.DeserializeObject <ZwinderStateManagerSettings>(json); } catch { // Do nothing, and use default settings instead } }); bl.GetLump(BinaryStateLump.StateHistory, false, delegate(BinaryReader br, long length) { TasStateManager?.Dispose(); TasStateManager = ZwinderStateManager.Create(br, settings, IsReserved); }); }
private void LoadTasprojExtras(ZipStateLoader bl) { bl.GetLump(BinaryStateLump.LagLog, false, delegate(TextReader tr) { LagLog.Load(tr); }); bl.GetLump(BinaryStateLump.Markers, false, delegate(TextReader tr) { string line; while ((line = tr.ReadLine()) != null) { if (!string.IsNullOrWhiteSpace(line)) { Markers.Add(new TasMovieMarker(line)); } } }); if (GetClientSettingsOnLoad != null) { string clientSettings = ""; bl.GetLump(BinaryStateLump.ClientSettings, false, delegate(TextReader tr) { string line; while ((line = tr.ReadLine()) != null) { if (!string.IsNullOrWhiteSpace(line)) { clientSettings = line; } } }); if (!string.IsNullOrWhiteSpace(clientSettings)) { GetClientSettingsOnLoad(clientSettings); } } bl.GetLump(BinaryStateLump.VerificationLog, false, delegate(TextReader tr) { VerificationLog.Clear(); while (true) { var line = tr.ReadLine(); if (string.IsNullOrEmpty(line)) { break; } if (line.StartsWith("|")) { VerificationLog.Add(line); } } }); Branches.Load(bl, this); bl.GetLump(BinaryStateLump.Session, false, delegate(TextReader tr) { var json = tr.ReadToEnd(); try { TasSession = JsonConvert.DeserializeObject <TasSession>(json); } catch { // Do nothing, and use default settings instead } }); ZwinderStateManagerSettings settings = new ZwinderStateManagerSettings(); bl.GetLump(BinaryStateLump.StateHistorySettings, false, delegate(TextReader tr) { var json = tr.ReadToEnd(); try { settings = JsonConvert.DeserializeObject <ZwinderStateManagerSettings>(json); } catch { // Do nothing, and use default settings instead } }); bl.GetLump(BinaryStateLump.StateHistory, false, delegate(BinaryReader br, long length) { try { TasStateManager?.Dispose(); TasStateManager = ZwinderStateManager.Create(br, settings, IsReserved); } catch { // Continue with a fresh manager. If state history got corrupted, the file is still very much useable // and we would want the user to be able to load, and regenerate their state history // however, we still have an issue of how state history got corrupted TasStateManager = new ZwinderStateManager( Session.Settings.DefaultTasStateManagerSettings, IsReserved); Session.PopupMessage("State history was corrupted, clearing and working with a fresh history."); } }); }