From e188f86582fb50d2343118254f932c162dc94fe9 Mon Sep 17 00:00:00 2001 From: zhupengfei Date: Wed, 8 Jul 2020 21:24:50 +0800 Subject: [PATCH] core/movie: Add future event and timeline check As specified in TASVideos [Laws of TAS](http://tasvideos.org/LawsOfTAS/OnSavestates.html) --- src/core/movie.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/core/movie.cpp b/src/core/movie.cpp index 1e27b45f2..0c90950b4 100644 --- a/src/core/movie.cpp +++ b/src/core/movie.cpp @@ -2,6 +2,7 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include #include #include #include @@ -182,10 +183,16 @@ void Movie::serialize(Archive& ar, const unsigned int file_version) { if (play_mode == PlayMode::Recording) { SaveMovie(); } - if (current_byte >= recorded_input.size()) { - throw std::runtime_error( - "This savestate was created at a later point and must be loaded in R+W mode"); + if (recorded_input_.size() >= recorded_input.size()) { + throw std::runtime_error("Future event savestate not allowed in R/O mode"); } + // Ensure that the current movie and savestate movie are in the same timeline + if (std::mismatch(recorded_input_.begin(), recorded_input_.end(), + recorded_input.begin()) + .first != recorded_input_.end()) { + throw std::runtime_error("Timeline mismatch not allowed in R/O mode"); + } + play_mode = PlayMode::Playing; total_input = GetInputCount(recorded_input); } else {