Ejemplo n.º 1
0
        public override void RecordFrame(int frame, IController source)
        {
            if (frame != 0)
            {
                ChangeLog.AddGeneralUndo(frame - 1, frame - 1, $"Record Frame: {frame}");
            }

            var lg = LogGeneratorInstance(source);

            SetFrameAt(frame, lg.GenerateLogEntry());

            Changes = true;

            LagLog.RemoveFrom(frame);
            LagLog[frame] = _inputPollable.IsLagFrame;

            if (this.IsRecording())
            {
                TasStateManager.Invalidate(frame + 1);
            }

            if (frame != 0)
            {
                ChangeLog.SetGeneralRedo();
            }
        }
Ejemplo n.º 2
0
 public ITasMovieRecord this[int index] => new TasMovieRecord
 {
     HasState  = TasStateManager.HasState(index),
     LogEntry  = GetInputLogEntry(index),
     Lagged    = LagLog[index + 1],
     WasLagged = LagLog.History(index + 1)
 };
Ejemplo n.º 3
0
 private void ClearTasprojExtras()
 {
     LagLog.Clear();
     StateManager.Clear();
     Markers.Clear();
     ChangeLog.ClearLog();
 }
Ejemplo n.º 4
0
        public override void PokeFrame(int frame, IController source)
        {
            base.PokeFrame(frame, source);

            LagLog.RemoveRange(frame, LagLog.Count - frame);
            StateManager.Invalidate(frame);
        }
        public override void RecordFrame(int frame, IController source)
        {
            // RetroEdit: This check is questionable; recording at frame 0 is valid and should be reversible.
            // Also, frame - 1, why?
            // Is the precondition compensating for frame - 1 reindexing?
            if (frame != 0)
            {
                ChangeLog.AddGeneralUndo(frame - 1, frame - 1, $"Record Frame: {frame}");
            }

            var lg = LogGeneratorInstance(source);

            SetFrameAt(frame, lg.GenerateLogEntry());

            Changes = true;

            LagLog.RemoveFrom(frame);
            LagLog[frame] = _inputPollable.IsLagFrame;

            if (this.IsRecording())
            {
                TasStateManager.InvalidateAfter(frame);
                GreenzoneInvalidated(frame + 1);
            }

            if (frame != 0)
            {
                ChangeLog.SetGeneralRedo();
            }
        }
Ejemplo n.º 6
0
        private void AddTasProjLumps(ZipStateSaver bs, bool isBackup = false)
        {
            var settings = JsonConvert.SerializeObject(TasStateManager.Settings);

            bs.PutLump(BinaryStateLump.StateHistorySettings, tw => tw.WriteLine(settings));
            bs.PutLump(BinaryStateLump.LagLog, tw => LagLog.Save(tw));
            bs.PutLump(BinaryStateLump.Markers, tw => tw.WriteLine(Markers.ToString()));

            if (ClientSettingsForSave != null)
            {
                var clientSettingsJson = ClientSettingsForSave();
                bs.PutLump(BinaryStateLump.ClientSettings, (TextWriter tw) => tw.Write(clientSettingsJson));
            }

            if (VerificationLog.Any())
            {
                bs.PutLump(BinaryStateLump.VerificationLog, tw => tw.WriteLine(VerificationLog.ToInputLog()));
            }

            if (Branches.Any())
            {
                Branches.Save(bs);
            }

            bs.PutLump(BinaryStateLump.Session, tw => tw.WriteLine(JsonConvert.SerializeObject(TasSession)));

            if (TasStateManager.Settings.SaveStateHistory && !isBackup)
            {
                bs.PutLump(BinaryStateLump.StateHistory, bw => TasStateManager.Save(bw));
            }
        }
Ejemplo n.º 7
0
        // Removes lag log and greenzone after this frame
        private void InvalidateAfter(int frame)
        {
            var anyInvalidated = LagLog.RemoveFrom(frame);

            TasStateManager.Invalidate(frame + 1);
            Changes         = anyInvalidated;
            LastEditedFrame = frame;

            if (anyInvalidated && Global.MovieSession.Movie.IsCountingRerecords)
            {
                Rerecords++;
            }
        }
Ejemplo n.º 8
0
        public override void RecordFrame(int frame, IController source)
        {
            base.RecordFrame(frame, source);

            if (frame < LagLog.Count)
            {
                LagLog.RemoveRange(frame, LagLog.Count - frame);
            }

            LagLog.Add(Global.Emulator.IsLagFrame);

            StateManager.Invalidate(frame);
            StateManager.Capture();
        }
Ejemplo n.º 9
0
        public override void Truncate(int frame)
        {
            base.Truncate(frame);

            if (frame < LagLog.Count)
            {
                LagLog.RemoveRange(frame + 2, LagLog.Count - frame - 1);
            }

            StateManager.Invalidate(frame + 1);

            if (frame < _log.Count - 1)
            {
                Changes = true;
            }
            // TODO: Markers? What does taseditor do?
        }
Ejemplo n.º 10
0
        public override void RecordFrame(int frame, IController source)
        {
            if (frame != 0)
            {
                ChangeLog.AddGeneralUndo(frame, frame, "Record Frame: " + frame);
            }

            base.RecordFrame(frame, source);

            LagLog.RemoveFrom(frame);
            LagLog[frame] = Global.Emulator.AsInputPollable().IsLagFrame;

            if (frame != 0)
            {
                ChangeLog.SetGeneralRedo();
            }
        }
Ejemplo n.º 11
0
        protected override void Write(string fn)
        {
            var file = new FileInfo(fn);

            if (!file.Directory.Exists)
            {
                Directory.CreateDirectory(file.Directory.ToString());
            }

            using (var fs = new FileStream(fn, FileMode.Create, FileAccess.Write))
                using (var bs = new BinaryStateSaver(fs, false))
                {
                    bs.PutLump(BinaryStateLump.Movieheader, tw => tw.WriteLine(Header.ToString()));
                    bs.PutLump(BinaryStateLump.Comments, tw => tw.WriteLine(CommentsString()));
                    bs.PutLump(BinaryStateLump.Subtitles, tw => tw.WriteLine(Subtitles.ToString()));
                    bs.PutLump(BinaryStateLump.SyncSettings, tw => tw.WriteLine(SyncSettingsJson));

                    bs.PutLump(BinaryStateLump.Input, tw => tw.WriteLine(RawInputLog()));


                    bs.PutLump(BinaryStateLump.GreenzoneSettings, tw => tw.WriteLine(StateManager.Settings.ToString()));
                    if (StateManager.Settings.SaveGreenzone)
                    {
                        bs.PutLump(BinaryStateLump.Greenzone, (BinaryWriter bw) => bw.Write(StateManager.ToArray()));
                    }

                    bs.PutLump(BinaryStateLump.LagLog, (BinaryWriter bw) => bw.Write(LagLog.ToByteArray()));
                    bs.PutLump(BinaryStateLump.Markers, tw => tw.WriteLine(Markers.ToString()));

                    if (StartsFromSavestate)
                    {
                        if (TextSavestate != null)
                        {
                            bs.PutLump(BinaryStateLump.CorestateText, (TextWriter tw) => tw.Write(TextSavestate));
                        }
                        else
                        {
                            bs.PutLump(BinaryStateLump.Corestate, (BinaryWriter bw) => bw.Write(BinarySavestate));
                        }
                    }
                }

            Changes = false;
        }
Ejemplo n.º 12
0
        public ITasMovieRecord this[int index]
        {
            get
            {
                var lagIndex = index + 1;
                var lagged   = LagLog[lagIndex];
                if (lagged == null && Emulator.Frame == lagIndex)
                {
                    lagged = _inputPollable.IsLagFrame;
                }

                return(new TasMovieRecord
                {
                    HasState = TasStateManager.HasState(index),
                    LogEntry = GetInputLogEntry(index),
                    Lagged = lagged,
                    WasLagged = LagLog.History(lagIndex)
                });
            }
        }
Ejemplo n.º 13
0
        public override void RecordFrame(int frame, IController source)
        {
            if (frame != 0)
            {
                ChangeLog.AddGeneralUndo(frame - 1, frame - 1, $"Record Frame: {frame}");
            }

            base.RecordFrame(frame, source);

            LagLog.RemoveFrom(frame);
            LagLog[frame] = Global.Emulator.AsInputPollable().IsLagFrame;

            if (this.IsRecording())
            {
                TasStateManager.Invalidate(frame + 1);
            }

            if (frame != 0)
            {
                ChangeLog.SetGeneralRedo();
            }
        }
Ejemplo n.º 14
0
        public override void Truncate(int frame)
        {
            bool endBatch = ChangeLog.BeginNewBatch("Truncate Movie: " + frame, true);

            ChangeLog.AddGeneralUndo(frame, InputLogLength - 1);

            if (frame < _log.Count - 1)
            {
                Changes = true;
            }

            base.Truncate(frame);

            LagLog.RemoveFrom(frame);
            StateManager.Invalidate(frame);
            Markers.TruncateAt(frame);

            ChangeLog.SetGeneralRedo();
            if (endBatch)
            {
                ChangeLog.EndBatch();
            }
        }
Ejemplo n.º 15
0
 public void RemoveLagHistory(int frame)
 {
     LagLog.RemoveHistoryAt(frame);
 }
Ejemplo n.º 16
0
 private void ClearTasprojExtrasBeforeLoad()
 {
     LagLog.Clear();
     StateManager.Clear();
 }
Ejemplo n.º 17
0
        protected override void Write(string fn, bool backup = false)
        {
            var file = new FileInfo(fn);

            if (!file.Directory.Exists)
            {
                Directory.CreateDirectory(file.Directory.ToString());
            }

            using (var bs = new BinaryStateSaver(fn, false))
            {
                bs.PutLump(BinaryStateLump.Movieheader, tw => tw.WriteLine(Header.ToString()));
                bs.PutLump(BinaryStateLump.Comments, tw => tw.WriteLine(CommentsString()));
                bs.PutLump(BinaryStateLump.Subtitles, tw => tw.WriteLine(Subtitles.ToString()));
                bs.PutLump(BinaryStateLump.SyncSettings, tw => tw.WriteLine(SyncSettingsJson));
                bs.PutLump(BinaryStateLump.Input, tw => WriteInputLog(tw));

                // TasProj extras
                bs.PutLump(BinaryStateLump.StateHistorySettings, tw => tw.WriteLine(StateManager.Settings.ToString()));

                bs.PutLump(BinaryStateLump.LagLog, (BinaryWriter bw) => LagLog.Save(bw));
                bs.PutLump(BinaryStateLump.Markers, tw => tw.WriteLine(Markers.ToString()));

                if (StartsFromSavestate)
                {
                    if (TextSavestate != null)
                    {
                        bs.PutLump(BinaryStateLump.CorestateText, (TextWriter tw) => tw.Write(TextSavestate));
                    }
                    else
                    {
                        bs.PutLump(BinaryStateLump.Corestate, (BinaryWriter bw) => bw.Write(BinarySavestate));
                    }
                }
                else if (StartsFromSaveRam)
                {
                    bs.PutLump(BinaryStateLump.MovieSaveRam, (BinaryWriter bw) => bw.Write(SaveRam));
                }

                if (ClientSettingsForSave != null)
                {
                    var clientSettingsJson = ClientSettingsForSave();
                    bs.PutLump(BinaryStateLump.ClientSettings, (TextWriter tw) => tw.Write(clientSettingsJson));
                }

                if (VerificationLog.Any())
                {
                    bs.PutLump(BinaryStateLump.VerificationLog, tw => tw.WriteLine(InputLogToString(VerificationLog)));
                }

                if (Branches.Any())
                {
                    Branches.Save(bs);
                    if (StateManager.Settings.BranchStatesInTasproj)
                    {
                        bs.PutLump(BinaryStateLump.BranchStateHistory, (BinaryWriter bw) => StateManager.SaveBranchStates(bw));
                    }
                }

                bs.PutLump(BinaryStateLump.Session, tw => tw.WriteLine(Session.ToString()));

                if (StateManager.Settings.SaveStateHistory)
                {
                    bs.PutLump(BinaryStateLump.StateHistory, (BinaryWriter bw) => StateManager.Save(bw));
                }
            }

            if (!backup)
            {
                Changes = false;
            }
        }
Ejemplo n.º 18
0
        private void LoadTasprojExtras(ZipStateLoader bl, bool preload)
        {
            bl.GetLump(BinaryStateLump.LagLog, false, delegate(TextReader tr)
            {
                LagLog.Load(tr);
            });

            bl.GetLump(BinaryStateLump.StateHistorySettings, false, delegate(TextReader tr)
            {
                var json = tr.ReadToEnd();
                try
                {
                    TasStateManager.Settings = JsonConvert.DeserializeObject <TasStateManagerSettings>(json);
                }
                catch
                {
                    // Do nothing, and use default settings instead
                }
            });

            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
                }
            });

            if (!preload)
            {
                if (TasStateManager.Settings.SaveStateHistory)
                {
                    bl.GetLump(BinaryStateLump.StateHistory, false, delegate(BinaryReader br, long length)
                    {
                        TasStateManager.Load(br);
                    });
                }
            }
        }
Ejemplo n.º 19
0
 public void InsertLagHistory(int frame, bool isLag)
 {
     LagLog.InsertHistoryAt(frame, isLag);
 }
Ejemplo n.º 20
0
        protected override void Write(string fn, bool isBackup = false)
        {
            if (Emulator is Emulation.Cores.Nintendo.SubNESHawk.SubNESHawk subNes)
            {
                Header[HeaderKeys.VBlankCount] = subNes.VblankCount.ToString();
            }
            else if (Emulator is Emulation.Cores.Nintendo.Gameboy.Gameboy gameboy)
            {
                Header[HeaderKeys.CycleCount] = gameboy.CycleCount.ToString();
            }
            else if (Emulator is Emulation.Cores.Nintendo.SubGBHawk.SubGBHawk subGb)
            {
                Header[HeaderKeys.CycleCount] = subGb.CycleCount.ToString();
            }

            var file = new FileInfo(fn);

            if (file.Directory != null && !file.Directory.Exists)
            {
                Directory.CreateDirectory(file.Directory.ToString());
            }

            using var bs = new ZipStateSaver(fn, Global.Config.Savestates.MovieCompressionLevel);
            bs.PutLump(BinaryStateLump.Movieheader, tw => tw.WriteLine(Header.ToString()));
            bs.PutLump(BinaryStateLump.Comments, tw => tw.WriteLine(CommentsString()));
            bs.PutLump(BinaryStateLump.Subtitles, tw => tw.WriteLine(Subtitles.ToString()));
            bs.PutLump(BinaryStateLump.SyncSettings, tw => tw.WriteLine(SyncSettingsJson));
            bs.PutLump(BinaryStateLump.Input, WriteInputLog);

            // TasProj extras
            var settings = JsonConvert.SerializeObject(TasStateManager.Settings);

            bs.PutLump(BinaryStateLump.StateHistorySettings, tw => tw.WriteLine(settings));

            bs.PutLump(BinaryStateLump.LagLog, tw => LagLog.Save(tw));
            bs.PutLump(BinaryStateLump.Markers, tw => tw.WriteLine(Markers.ToString()));

            if (StartsFromSavestate)
            {
                if (TextSavestate != null)
                {
                    bs.PutLump(BinaryStateLump.CorestateText, (TextWriter tw) => tw.Write(TextSavestate));
                }
                else
                {
                    bs.PutLump(BinaryStateLump.Corestate, (BinaryWriter bw) => bw.Write(BinarySavestate));
                }
            }
            else if (StartsFromSaveRam)
            {
                bs.PutLump(BinaryStateLump.MovieSaveRam, (BinaryWriter bw) => bw.Write(SaveRam));
            }

            if (ClientSettingsForSave != null)
            {
                var clientSettingsJson = ClientSettingsForSave();
                bs.PutLump(BinaryStateLump.ClientSettings, (TextWriter tw) => tw.Write(clientSettingsJson));
            }

            if (VerificationLog.Any())
            {
                bs.PutLump(BinaryStateLump.VerificationLog, tw => tw.WriteLine(VerificationLog.ToInputLog()));
            }

            if (Branches.Any())
            {
                Branches.Save(bs);
            }

            bs.PutLump(BinaryStateLump.Session, tw => tw.WriteLine(JsonConvert.SerializeObject(TasSession)));

            if (TasStateManager.Settings.SaveStateHistory && !isBackup)
            {
                bs.PutLump(BinaryStateLump.StateHistory, bw => TasStateManager.Save(bw));
            }

            if (!isBackup)
            {
                Changes = false;
            }
        }
Ejemplo n.º 21
0
        public override bool Load()
        {
            var file = new FileInfo(Filename);

            if (!file.Exists)
            {
                return(false);
            }

            using (var bl = BinaryStateLoader.LoadAndDetect(Filename, true))
            {
                if (bl == null)
                {
                    return(false);
                }

                ClearBeforeLoad();
                ClearTasprojExtras();

                bl.GetLump(BinaryStateLump.Movieheader, true, delegate(TextReader tr)
                {
                    string line;
                    while ((line = tr.ReadLine()) != null)
                    {
                        if (!string.IsNullOrWhiteSpace(line))
                        {
                            var pair = line.Split(new[] { ' ' }, 2, StringSplitOptions.RemoveEmptyEntries);

                            if (pair.Length > 1)
                            {
                                Header.Add(pair[0], pair[1]);
                            }
                        }
                    }
                });

                bl.GetLump(BinaryStateLump.Comments, true, delegate(TextReader tr)
                {
                    string line;
                    while ((line = tr.ReadLine()) != null)
                    {
                        if (!string.IsNullOrWhiteSpace(line))
                        {
                            Comments.Add(line);
                        }
                    }
                });

                bl.GetLump(BinaryStateLump.Subtitles, true, delegate(TextReader tr)
                {
                    string line;
                    while ((line = tr.ReadLine()) != null)
                    {
                        if (!string.IsNullOrWhiteSpace(line))
                        {
                            Subtitles.AddFromString(line);
                        }
                    }
                });

                bl.GetLump(BinaryStateLump.SyncSettings, true, delegate(TextReader tr)
                {
                    string line;
                    while ((line = tr.ReadLine()) != null)
                    {
                        if (!string.IsNullOrWhiteSpace(line))
                        {
                            SyncSettingsJson = line;
                        }
                    }
                });

                bl.GetLump(BinaryStateLump.Input, true, delegate(TextReader tr)                 // Note: ExtractInputLog will clear Lag and State data potentially, this must come before loading those
                {
                    var errorMessage    = string.Empty;
                    IsCountingRerecords = false;
                    ExtractInputLog(tr, out errorMessage);
                    IsCountingRerecords = true;
                });

                if (StartsFromSavestate)
                {
                    bl.GetCoreState(
                        delegate(BinaryReader br, long length)
                    {
                        BinarySavestate = br.ReadBytes((int)length);
                    },
                        delegate(TextReader tr)
                    {
                        TextSavestate = tr.ReadToEnd();
                    });
                }

                // TasMovie enhanced information
                if (bl.HasLump(BinaryStateLump.LagLog))
                {
                    bl.GetLump(BinaryStateLump.LagLog, false, delegate(BinaryReader br, long length)
                    {
                        LagLog.Load(br);
                    });
                }

                bl.GetLump(BinaryStateLump.StateHistorySettings, false, delegate(TextReader tr)
                {
                    StateManager.Settings.PopulateFromString(tr.ReadToEnd());
                });

                if (StateManager.Settings.SaveStateHistory)
                {
                    bl.GetLump(BinaryStateLump.StateHistory, false, delegate(BinaryReader br, long length)
                    {
                        StateManager.Load(br);
                    });
                }
                // Movie should always have a state at frame 0.
                if (!this.StartsFromSavestate)
                {
                    StateManager.Capture();
                }

                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 && bl.HasLump(BinaryStateLump.ClientSettings))
                {
                    string clientSettings = string.Empty;
                    bl.GetLump(BinaryStateLump.ClientSettings, true, delegate(TextReader tr)
                    {
                        string line;
                        while ((line = tr.ReadLine()) != null)
                        {
                            if (!string.IsNullOrWhiteSpace(line))
                            {
                                clientSettings = line;
                            }
                        }
                    });

                    GetClientSettingsOnLoad(clientSettings);
                }

                if (bl.HasLump(BinaryStateLump.VerificationLog))
                {
                    bl.GetLump(BinaryStateLump.VerificationLog, true, delegate(TextReader tr)
                    {
                        VerificationLog.Clear();
                        while (true)
                        {
                            var line = tr.ReadLine();
                            if (string.IsNullOrEmpty(line))
                            {
                                break;
                            }

                            if (line.StartsWith("|"))
                            {
                                VerificationLog.Add(line);
                            }
                        }
                    });
                }
            }

            Changes = false;
            return(true);
        }
Ejemplo n.º 22
0
        public override bool Load(bool preload)
        {
            var file = new FileInfo(Filename);

            if (!file.Exists)
            {
                return(false);
            }

            using (var bl = BinaryStateLoader.LoadAndDetect(Filename, true))
            {
                if (bl == null)
                {
                    return(false);
                }

                ClearBeforeLoad();
                ClearTasprojExtras();

                bl.GetLump(BinaryStateLump.Movieheader, true, delegate(TextReader tr)
                {
                    string line;
                    while ((line = tr.ReadLine()) != null)
                    {
                        if (!string.IsNullOrWhiteSpace(line))
                        {
                            var pair = line.Split(new[] { ' ' }, 2, StringSplitOptions.RemoveEmptyEntries);

                            if (pair.Length > 1)
                            {
                                Header.Add(pair[0], pair[1]);
                            }
                        }
                    }
                });

                bl.GetLump(BinaryStateLump.Comments, true, delegate(TextReader tr)
                {
                    string line;
                    while ((line = tr.ReadLine()) != null)
                    {
                        if (!string.IsNullOrWhiteSpace(line))
                        {
                            Comments.Add(line);
                        }
                    }
                });

                bl.GetLump(BinaryStateLump.Subtitles, true, delegate(TextReader tr)
                {
                    string line;
                    while ((line = tr.ReadLine()) != null)
                    {
                        if (!string.IsNullOrWhiteSpace(line))
                        {
                            Subtitles.AddFromString(line);
                        }
                    }
                });

                bl.GetLump(BinaryStateLump.SyncSettings, true, delegate(TextReader tr)
                {
                    string line;
                    while ((line = tr.ReadLine()) != null)
                    {
                        if (!string.IsNullOrWhiteSpace(line))
                        {
                            SyncSettingsJson = line;
                        }
                    }
                });

                bl.GetLump(BinaryStateLump.Input, true, delegate(TextReader tr)                 // Note: ExtractInputLog will clear Lag and State data potentially, this must come before loading those
                {
                    IsCountingRerecords = false;
                    ExtractInputLog(tr, out _);
                    IsCountingRerecords = true;
                });

                if (StartsFromSavestate)
                {
                    bl.GetCoreState(
                        delegate(BinaryReader br, long length)
                    {
                        BinarySavestate = br.ReadBytes((int)length);
                    },
                        delegate(TextReader tr)
                    {
                        TextSavestate = tr.ReadToEnd();
                    });
                }
                else if (StartsFromSaveRam)
                {
                    bl.GetLump(BinaryStateLump.MovieSaveRam, false,
                               delegate(BinaryReader br, long length)
                    {
                        SaveRam = br.ReadBytes((int)length);
                    });
                }

                // TasMovie enhanced information
                bl.GetLump(BinaryStateLump.LagLog, false, delegate(TextReader tr)
                {
                    LagLog.Load(tr);
                });

                bl.GetLump(BinaryStateLump.StateHistorySettings, false, delegate(TextReader tr)
                {
                    var json = tr.ReadToEnd();
                    try
                    {
                        TasStateManager.Settings = JsonConvert.DeserializeObject <TasStateManagerSettings>(json);
                    }
                    catch
                    {
                        // Do nothing, and use default settings instead
                    }
                });

                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
                    {
                        Session = JsonConvert.DeserializeObject <TasSession>(json);
                    }
                    catch
                    {
                        // Do nothing, and use default settings instead
                    }
                });

                if (!preload)
                {
                    if (TasStateManager.Settings.SaveStateHistory)
                    {
                        bl.GetLump(BinaryStateLump.StateHistory, false, delegate(BinaryReader br, long length)
                        {
                            TasStateManager.Load(br);
                        });
                    }
                }
            }

            Changes = false;
            return(true);
        }
Ejemplo n.º 23
0
        protected override void Write(string fn)
        {
            _totalProgress = 0;

            var file = new FileInfo(fn);

            if (!file.Directory.Exists)
            {
                Directory.CreateDirectory(file.Directory.ToString());
            }

            using (var bs = new BinaryStateSaver(fn, false))
            {
                bs.PutLump(BinaryStateLump.Movieheader, tw => tw.WriteLine(Header.ToString()));
                ReportProgress(PROGRESS_STEP);
                bs.PutLump(BinaryStateLump.Comments, tw => tw.WriteLine(CommentsString()));
                ReportProgress(PROGRESS_STEP);
                bs.PutLump(BinaryStateLump.Subtitles, tw => tw.WriteLine(Subtitles.ToString()));
                ReportProgress(PROGRESS_STEP);
                bs.PutLump(BinaryStateLump.SyncSettings, tw => tw.WriteLine(SyncSettingsJson));
                ReportProgress(PROGRESS_STEP);
                bs.PutLump(BinaryStateLump.Input, tw => tw.WriteLine(RawInputLog()));
                ReportProgress(PROGRESS_STEP);

                // TasProj extras
                bs.PutLump(BinaryStateLump.StateHistorySettings, tw => tw.WriteLine(StateManager.Settings.ToString()));
                ReportProgress(PROGRESS_STEP);
                if (StateManager.Settings.SaveStateHistory)
                {
                    bs.PutLump(BinaryStateLump.StateHistory, (BinaryWriter bw) => StateManager.Save(bw));
                }
                ReportProgress(PROGRESS_STEP);

                bs.PutLump(BinaryStateLump.LagLog, (BinaryWriter bw) => LagLog.Save(bw));
                ReportProgress(PROGRESS_STEP);
                bs.PutLump(BinaryStateLump.Markers, tw => tw.WriteLine(Markers.ToString()));
                ReportProgress(PROGRESS_STEP);

                if (StartsFromSavestate)
                {
                    if (TextSavestate != null)
                    {
                        bs.PutLump(BinaryStateLump.CorestateText, (TextWriter tw) => tw.Write(TextSavestate));
                    }
                    else
                    {
                        bs.PutLump(BinaryStateLump.Corestate, (BinaryWriter bw) => bw.Write(BinarySavestate));
                    }
                }
                ReportProgress(PROGRESS_STEP);
                if (ClientSettingsForSave != null)
                {
                    var clientSettingsJson = ClientSettingsForSave();
                    bs.PutLump(BinaryStateLump.ClientSettings, (TextWriter tw) => tw.Write(clientSettingsJson));
                }
                ReportProgress(PROGRESS_STEP);

                if (VerificationLog.Any())
                {
                    bs.PutLump(BinaryStateLump.VerificationLog, tw => tw.WriteLine(InputLogToString(VerificationLog)));
                }
                ReportProgress(PROGRESS_STEP);
            }

            Changes = false;
        }
Ejemplo n.º 24
0
        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.");
                }
            });
        }