From c47a0c7426f5348153af6208db57e69b77bacf7e Mon Sep 17 00:00:00 2001 From: zeromus Date: Fri, 25 Apr 2014 02:19:46 +0000 Subject: [PATCH] make movie header savestates be binary, have their own key, and be stored in base64 form (actually, natt was right, they were stored as text, it's just that the "text" savestates from some cores are a ToHex'd byte array) --- BizHawk.Client.Common/movie/HeaderKeys.cs | 1 + BizHawk.Client.Common/movie/IMovieHeader.cs | 1 + BizHawk.Client.Common/movie/Movie.cs | 1 + BizHawk.Client.Common/movie/MovieHeader.cs | 12 +++++++++++ BizHawk.Client.EmuHawk/MainForm.Movie.cs | 3 ++- BizHawk.Client.EmuHawk/movie/RecordMovie.cs | 22 +++++---------------- 6 files changed, 22 insertions(+), 18 deletions(-) diff --git a/BizHawk.Client.Common/movie/HeaderKeys.cs b/BizHawk.Client.Common/movie/HeaderKeys.cs index 25b4486624..e38abe18e5 100644 --- a/BizHawk.Client.Common/movie/HeaderKeys.cs +++ b/BizHawk.Client.Common/movie/HeaderKeys.cs @@ -14,6 +14,7 @@ namespace BizHawk.Client.Common public const string AUTHOR = "Author"; public const string RERECORDS = "rerecordCount"; public const string STARTSFROMSAVESTATE = "StartsFromSavestate"; + public const string SAVESTATEBINARYBASE64BLOB = "SavestateBinaryBase64Blob"; //this string will not contain base64: ; it's implicit (this is to avoid another big string op to dice off the base64: substring) public const string FOURSCORE = "FourScore"; public const string SHA1 = "SHA1"; public const string FIRMWARESHA1 = "FirmwareSHA1"; diff --git a/BizHawk.Client.Common/movie/IMovieHeader.cs b/BizHawk.Client.Common/movie/IMovieHeader.cs index d0672d6459..62c4043dce 100644 --- a/BizHawk.Client.Common/movie/IMovieHeader.cs +++ b/BizHawk.Client.Common/movie/IMovieHeader.cs @@ -10,6 +10,7 @@ namespace BizHawk.Client.Common ulong Rerecords { get; set; } bool StartsFromSavestate { get; set; } + string SavestateBinaryBase64Blob { get; set; } string GameName { get; set; } string SystemID { get; set; } diff --git a/BizHawk.Client.Common/movie/Movie.cs b/BizHawk.Client.Common/movie/Movie.cs index 6845a6a36d..096368fc43 100644 --- a/BizHawk.Client.Common/movie/Movie.cs +++ b/BizHawk.Client.Common/movie/Movie.cs @@ -211,6 +211,7 @@ namespace BizHawk.Client.Common /// /// Load Header information only for displaying file information in dialogs such as play movie + /// TODO - consider not loading the SavestateBinaryBase64Blob key? /// public bool PreLoadText(HawkFile hawkFile) { diff --git a/BizHawk.Client.Common/movie/MovieHeader.cs b/BizHawk.Client.Common/movie/MovieHeader.cs index 4b744e56c4..c0fb905f76 100644 --- a/BizHawk.Client.Common/movie/MovieHeader.cs +++ b/BizHawk.Client.Common/movie/MovieHeader.cs @@ -23,6 +23,18 @@ namespace BizHawk.Client.Common public Dictionary BoardProperties { get; private set; } public SubtitleList Subtitles { get; private set; } + public string SavestateBinaryBase64Blob + { + get { + if (ContainsKey(HeaderKeys.SAVESTATEBINARYBASE64BLOB)) return this[HeaderKeys.SAVESTATEBINARYBASE64BLOB]; + else return null; + } + set { + if (value == null) Remove(HeaderKeys.SAVESTATEBINARYBASE64BLOB); + else Add(HeaderKeys.SAVESTATEBINARYBASE64BLOB, value); + } + } + public ulong Rerecords { get diff --git a/BizHawk.Client.EmuHawk/MainForm.Movie.cs b/BizHawk.Client.EmuHawk/MainForm.Movie.cs index 274706083b..5fb2487cc1 100644 --- a/BizHawk.Client.EmuHawk/MainForm.Movie.cs +++ b/BizHawk.Client.EmuHawk/MainForm.Movie.cs @@ -93,7 +93,8 @@ namespace BizHawk.Client.EmuHawk if (Global.MovieSession.Movie.Header.StartsFromSavestate) { - LoadState(Global.MovieSession.Movie.Filename, Path.GetFileName(Global.MovieSession.Movie.Filename)); + byte[] state = Convert.FromBase64String(Global.MovieSession.Movie.Header.SavestateBinaryBase64Blob); + Global.Emulator.LoadStateBinary(new BinaryReader(new MemoryStream(state))); Global.Emulator.ResetCounters(); } diff --git a/BizHawk.Client.EmuHawk/movie/RecordMovie.cs b/BizHawk.Client.EmuHawk/movie/RecordMovie.cs index e96204afd8..3bad987585 100644 --- a/BizHawk.Client.EmuHawk/movie/RecordMovie.cs +++ b/BizHawk.Client.EmuHawk/movie/RecordMovie.cs @@ -81,23 +81,11 @@ namespace BizHawk.Client.EmuHawk } _movieToRecord = new Movie(path, startsFromSavestate: true); - var temppath = path; - var writer = new StreamWriter(temppath); - Global.Emulator.SaveStateText(writer); - writer.Close(); - - var file = new FileInfo(temppath); - using (var sr = file.OpenText()) - { - string str; - while ((str = sr.ReadLine()) != null) - { - if (!String.IsNullOrWhiteSpace(str)) - { - _movieToRecord.Header.Comments.Add(str); - } - } - } + //TODO - some emulators (c++ cores) are just returning a hex string already + //theres no sense hexifying those again. we need to record that fact in the IEmulator somehow + var bytestate = Global.Emulator.SaveStateBinary(); + string stringstate = Convert.ToBase64String(bytestate); + _movieToRecord.Header.SavestateBinaryBase64Blob = stringstate; } else {