Fix `.tasproj` autoload loading mismatched savestates

This commit is contained in:
James Groom 2024-05-17 09:16:41 +10:00 committed by GitHub
parent a63efffa14
commit 84fd85c749
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 32 additions and 1 deletions

View File

@ -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<string, string> 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)

View File

@ -81,6 +81,8 @@ namespace BizHawk.Client.Common
IMovie movie,
bool record,
string systemId,
string loadedRomHash,
PathEntryCollection pathEntries,
IDictionary<string, string> preferredCores);
/// <summary>

View File

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

View File

@ -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");