diff --git a/BizHawk.Client.Common/config/ConfigService.cs b/BizHawk.Client.Common/config/ConfigService.cs index 97751ffbb7..11203628ba 100644 --- a/BizHawk.Client.Common/config/ConfigService.cs +++ b/BizHawk.Client.Common/config/ConfigService.cs @@ -63,5 +63,35 @@ namespace BizHawk.Client.Common Serializer.Serialize(w, config); } } + + // movie 1.0 header stuff + + private class TypeNameEncapsulator + { + public object o; + } + + public static object LoadWithType(string serialized) + { + using (TextReader tr = new StringReader(serialized)) + using (JsonTextReader jr = new JsonTextReader(tr)) + { + TypeNameEncapsulator tne = (TypeNameEncapsulator)Serializer.Deserialize(jr, typeof(TypeNameEncapsulator)); + return tne.o; + } + } + + public static string SaveWithType(object o) + { + using (StringWriter sw = new StringWriter()) + using (JsonTextWriter jw = new JsonTextWriter(sw) { Formatting = Formatting.None }) + { + TypeNameEncapsulator tne = new TypeNameEncapsulator { o = o }; + Serializer.Serialize(jw, tne, typeof(TypeNameEncapsulator)); + sw.Flush(); + return sw.ToString(); + } + } + } } diff --git a/BizHawk.Client.EmuHawk/MainForm.Movie.cs b/BizHawk.Client.EmuHawk/MainForm.Movie.cs index 6863a95630..cc4b63fab3 100644 --- a/BizHawk.Client.EmuHawk/MainForm.Movie.cs +++ b/BizHawk.Client.EmuHawk/MainForm.Movie.cs @@ -49,25 +49,17 @@ namespace BizHawk.Client.EmuHawk if (Global.MovieSession.Movie.Header[HeaderKeys.CORE] == quicknesName) { Global.Config.NES_InQuickNES = true; - - _syncSettingsHack = JsonConvert.DeserializeObject( - Global.MovieSession.Movie.Header.SyncSettingsJson, - typeof(QuickNES.QuickNESSyncSettings)); } else { Global.Config.NES_InQuickNES = false; - - _syncSettingsHack = JsonConvert.DeserializeObject( - Global.MovieSession.Movie.Header.SyncSettingsJson, - typeof(NES.NESSyncSettings)); } } - - _syncSettingsHack = JsonConvert.DeserializeObject( - Global.MovieSession.Movie.Header.SyncSettingsJson, - Global.Emulator.GetSyncSettings().GetType()); - + string s = Global.MovieSession.Movie.Header.SyncSettingsJson; + if (!string.IsNullOrWhiteSpace(s)) + { + _syncSettingsHack = ConfigService.LoadWithType(Global.MovieSession.Movie.Header.SyncSettingsJson); + } LoadRom(GlobalWin.MainForm.CurrentlyOpenRom, true, !record); } finally diff --git a/BizHawk.Client.EmuHawk/movie/RecordMovie.cs b/BizHawk.Client.EmuHawk/movie/RecordMovie.cs index 3d20858db4..b7b3187063 100644 --- a/BizHawk.Client.EmuHawk/movie/RecordMovie.cs +++ b/BizHawk.Client.EmuHawk/movie/RecordMovie.cs @@ -103,7 +103,7 @@ namespace BizHawk.Client.EmuHawk _movieToRecord.Header[HeaderKeys.PLATFORM] = Global.Game.System; // Sync Settings, for movies 1.0, just dump a json blob into a header line - _movieToRecord.Header[HeaderKeys.SYNCSETTINGS] = JsonConvert.SerializeObject(Global.Emulator.GetSyncSettings()); + _movieToRecord.Header[HeaderKeys.SYNCSETTINGS] = ConfigService.SaveWithType(Global.Emulator.GetSyncSettings()); if (Global.Game != null) {