diff --git a/BizHawk.Client.Common/movie/tasproj/TasMovie.Editing.cs b/BizHawk.Client.Common/movie/tasproj/TasMovie.Editing.cs index 6c8eb27985..a0a4390907 100644 --- a/BizHawk.Client.Common/movie/tasproj/TasMovie.Editing.cs +++ b/BizHawk.Client.Common/movie/tasproj/TasMovie.Editing.cs @@ -152,7 +152,7 @@ namespace BizHawk.Client.Common ChangeLog.EndBatch(); } } - public void RemoveFrames(int removeStart, int removeUpTo) + public void RemoveFrames(int removeStart, int removeUpTo, bool fromHistory = false) { bool endBatch = ChangeLog.BeginNewBatch("Remove Frames: " + removeStart + "-" + removeUpTo, true); ChangeLog.AddGeneralUndo(removeStart, InputLogLength - 1); @@ -173,7 +173,7 @@ namespace BizHawk.Client.Common if (m.Frame < removeUpTo) Markers.Remove(m); else - Markers.Move(m.Frame, m.Frame - (removeUpTo - removeStart)); + Markers.Move(m.Frame, m.Frame - (removeUpTo - removeStart), fromHistory); } } ChangeLog.IsRecording = wasRecording; @@ -281,7 +281,7 @@ namespace BizHawk.Client.Common ChangeLog.SetGeneralRedo(); } - public void InsertEmptyFrame(int frame, int count = 1) + public void InsertEmptyFrame(int frame, int count = 1, bool fromHistory = false) { bool endBatch = ChangeLog.BeginNewBatch("Insert Empty Frame: " + frame, true); ChangeLog.AddGeneralUndo(frame, InputLogLength + count - 1); @@ -289,6 +289,9 @@ namespace BizHawk.Client.Common var lg = LogGeneratorInstance(); lg.SetSource(Global.MovieSession.MovieControllerInstance()); + if (frame > _log.Count()) + frame = _log.Count(); + for (int i = 0; i < count; i++) _log.Insert(frame, lg.EmptyEntry); @@ -302,7 +305,7 @@ namespace BizHawk.Client.Common for (int i = firstIndex; i < Markers.Count; i++) { TasMovieMarker m = Markers.ElementAt(i); - Markers.Move(m.Frame, m.Frame + count); + Markers.Move(m.Frame, m.Frame + count, fromHistory); } } ChangeLog.IsRecording = wasRecording; diff --git a/BizHawk.Client.Common/movie/tasproj/TasMovie.History.cs b/BizHawk.Client.Common/movie/tasproj/TasMovie.History.cs index 6b89f0dd7b..d59a8b82e5 100644 --- a/BizHawk.Client.Common/movie/tasproj/TasMovie.History.cs +++ b/BizHawk.Client.Common/movie/tasproj/TasMovie.History.cs @@ -174,7 +174,7 @@ namespace BizHawk.Client.Common { get { - if (Names.Count == 0) + if (Names.Count == 0 || UndoIndex < 0) return null; else return Names[UndoIndex]; @@ -332,7 +332,15 @@ namespace BizHawk.Client.Common LastFrame = lastFrame; oldLog = new List(length); - undoLength = Math.Min(lastFrame + 1, movie.InputLogLength) - firstFrame; + var minuend = Math.Min(lastFrame + 1, movie.InputLogLength); + if (firstFrame > minuend) + undoLength = minuend; + else + undoLength = minuend - firstFrame; + + if (FirstFrame > oldLog.Count()) + FirstFrame = oldLog.Count(); + for (int i = 0; i < undoLength; i++) oldLog.Add(movie.GetLogEntries()[FirstFrame + i]); @@ -354,9 +362,9 @@ namespace BizHawk.Client.Common movie.BindMarkersToInput = bindMarkers; if (redoLength != length) - movie.InsertEmptyFrame(FirstFrame, length - redoLength); + movie.InsertEmptyFrame(FirstFrame, length - redoLength, true); if (undoLength != length) - movie.RemoveFrames(FirstFrame, movie.InputLogLength - undoLength); + movie.RemoveFrames(FirstFrame, movie.InputLogLength - undoLength, true); for (int i = 0; i < undoLength; i++) movie.SetFrame(FirstFrame + i, oldLog[i]); diff --git a/BizHawk.Client.Common/movie/tasproj/TasMovieMarker.cs b/BizHawk.Client.Common/movie/tasproj/TasMovieMarker.cs index c2054f51a5..0137bb51cb 100644 --- a/BizHawk.Client.Common/movie/tasproj/TasMovieMarker.cs +++ b/BizHawk.Client.Common/movie/tasproj/TasMovieMarker.cs @@ -219,6 +219,8 @@ namespace BizHawk.Client.Common public void Move(int fromFrame, int toFrame, bool fromHistory = false) { + if (fromFrame == 0) // no thanks! + return; TasMovieMarker m = Get(fromFrame); if (m == null) // TODO: Don't do this. return;