From 84fd85c74933e802546f620737c39d89deda2765 Mon Sep 17 00:00:00 2001 From: James Groom Date: Fri, 17 May 2024 09:16:41 +1000 Subject: [PATCH] Fix `.tasproj` autoload loading mismatched savestates --- .../movie/MovieSession.cs | 20 +++++++++++++++++++ .../movie/interfaces/IMovieSession.cs | 2 ++ .../movie/tasproj/TasMovie.cs | 2 ++ src/BizHawk.Client.EmuHawk/MainForm.Movie.cs | 9 ++++++++- 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/BizHawk.Client.Common/movie/MovieSession.cs b/src/BizHawk.Client.Common/movie/MovieSession.cs index 23ad908845..83eb935ca7 100644 --- a/src/BizHawk.Client.Common/movie/MovieSession.cs +++ b/src/BizHawk.Client.Common/movie/MovieSession.cs @@ -2,6 +2,8 @@ using System.Collections.Generic; using System.IO; using System.Linq; + +using BizHawk.Common.PathExtensions; using BizHawk.Common.StringExtensions; using BizHawk.Emulation.Common; @@ -192,6 +194,8 @@ namespace BizHawk.Client.Common IMovie movie, bool record, string systemId, + string loadedRomHash, + PathEntryCollection pathEntries, IDictionary preferredCores) { if (movie.IsActive() && movie.Changes) @@ -208,6 +212,22 @@ namespace BizHawk.Client.Common throw new MoviePlatformMismatchException( $"Movie system Id ({movie.SystemID}) does not match the currently loaded platform ({systemId}), unable to load"); } + + if (!(string.IsNullOrEmpty(movie.Hash) || loadedRomHash.Equals(movie.Hash, StringComparison.Ordinal)) + && movie is TasMovie tasproj) + { + var result = _dialogParent.ModalMessageBox2( + caption: "Discard GreenZone?", + text: $"The TAStudio project {movie.Filename.MakeRelativeTo(pathEntries.MovieAbsolutePath())} appears to be for a different game than the one that's loaded.\n" + + "Choose \"No\" to continue anyway, which may lead to an invalid savestate being loaded.\n" + + "Choose \"Yes\" to discard the GreenZone (savestate history). This is safer, and at worst you'll only need to watch through the whole movie."); + //TODO add abort option + if (result) + { + tasproj.TasSession.UpdateValues(frame: 0, currentBranch: tasproj.TasSession.CurrentBranch); // wtf is this API --yoshi + tasproj.InvalidateEntireGreenzone(); + } + } } if (!record) diff --git a/src/BizHawk.Client.Common/movie/interfaces/IMovieSession.cs b/src/BizHawk.Client.Common/movie/interfaces/IMovieSession.cs index f48aa78d42..50880865a1 100644 --- a/src/BizHawk.Client.Common/movie/interfaces/IMovieSession.cs +++ b/src/BizHawk.Client.Common/movie/interfaces/IMovieSession.cs @@ -81,6 +81,8 @@ namespace BizHawk.Client.Common IMovie movie, bool record, string systemId, + string loadedRomHash, + PathEntryCollection pathEntries, IDictionary preferredCores); /// diff --git a/src/BizHawk.Client.Common/movie/tasproj/TasMovie.cs b/src/BizHawk.Client.Common/movie/tasproj/TasMovie.cs index 5629419cf4..96e282f2c6 100644 --- a/src/BizHawk.Client.Common/movie/tasproj/TasMovie.cs +++ b/src/BizHawk.Client.Common/movie/tasproj/TasMovie.cs @@ -149,6 +149,8 @@ namespace BizHawk.Client.Common } } + public void InvalidateEntireGreenzone() + => InvalidateAfter(0); private (int Frame, IMovieController Controller) _displayCache = (-1, new Bk2Controller("", NullController.Instance.Definition)); diff --git a/src/BizHawk.Client.EmuHawk/MainForm.Movie.cs b/src/BizHawk.Client.EmuHawk/MainForm.Movie.cs index 6412e72012..fe87bf433c 100644 --- a/src/BizHawk.Client.EmuHawk/MainForm.Movie.cs +++ b/src/BizHawk.Client.EmuHawk/MainForm.Movie.cs @@ -27,7 +27,13 @@ namespace BizHawk.Client.EmuHawk { try { - MovieSession.QueueNewMovie(movie, record, Emulator.SystemId, Config.PreferredCores); + MovieSession.QueueNewMovie( + movie, + record: record, + systemId: Emulator.SystemId, + loadedRomHash: Game.Hash, + Config.PathEntries, + Config.PreferredCores); } catch (MoviePlatformMismatchException ex) { @@ -54,6 +60,7 @@ namespace BizHawk.Client.EmuHawk SetMainformMovieInfo(); + // turns out this was too late for .tasproj autoloading and restoring playback position (loads savestate but wasn't checking game match) if (string.IsNullOrEmpty(MovieSession.Movie.Hash)) { AddOnScreenMessage("Movie is missing hash, skipping hash check");