diff --git a/BizHawk.Client.Common/SavestateManager.cs b/BizHawk.Client.Common/SavestateManager.cs index eca69a466a..9eedae1e61 100644 --- a/BizHawk.Client.Common/SavestateManager.cs +++ b/BizHawk.Client.Common/SavestateManager.cs @@ -5,6 +5,7 @@ using BizHawk.Common; using BizHawk.Common.BufferExtensions; using BizHawk.Common.IOExtensions; using BizHawk.Emulation.Common; +using BizHawk.Emulation.Common.IEmulatorExtensions; namespace BizHawk.Client.Common { @@ -12,7 +13,7 @@ namespace BizHawk.Client.Common { public static void SaveStateFile(string filename, string name) { - var core = Global.Emulator as IStatable; + var core = Global.Emulator.AsStatable(); // the old method of text savestate save is now gone. // a text savestate is just like a binary savestate, but with a different core lump using (var bs = new BinaryStateSaver(filename)) @@ -77,7 +78,7 @@ namespace BizHawk.Client.Common public static bool LoadStateFile(string path, string name) { - var core = Global.Emulator as IStatable; + var core = Global.Emulator.AsStatable(); // try to detect binary first var bl = BinaryStateLoader.LoadAndDetect(path); diff --git a/BizHawk.Client.Common/movie/tasproj/TasMovie.cs b/BizHawk.Client.Common/movie/tasproj/TasMovie.cs index 33821aec61..c6c06aa198 100644 --- a/BizHawk.Client.Common/movie/tasproj/TasMovie.cs +++ b/BizHawk.Client.Common/movie/tasproj/TasMovie.cs @@ -31,7 +31,7 @@ namespace BizHawk.Client.Common throw new InvalidOperationException("Cannot create a TasMovie against a core that does not implement IStatable"); } - var core = (IStatable)Global.Emulator; + var core = Global.Emulator.AsStatable(); StateManager = new TasStateManager(this, core); Header[HeaderKeys.MOVIEVERSION] = "BizHawk v2.0 Tasproj v1.0"; @@ -48,7 +48,7 @@ namespace BizHawk.Client.Common throw new InvalidOperationException("Cannot create a TasMovie against a core that does not implement IStatable"); } - var core = (IStatable)Global.Emulator; + var core = Global.Emulator.AsStatable(); StateManager = new TasStateManager(this, core); Header[HeaderKeys.MOVIEVERSION] = "BizHawk v2.0 Tasproj v1.0"; diff --git a/BizHawk.Client.Common/rewind/Rewinder.cs b/BizHawk.Client.Common/rewind/Rewinder.cs index 2d0ed045cb..d827a3ff3d 100644 --- a/BizHawk.Client.Common/rewind/Rewinder.cs +++ b/BizHawk.Client.Common/rewind/Rewinder.cs @@ -69,7 +69,7 @@ namespace BizHawk.Client.Common // log a frame if (_lastState != null && Global.Emulator.Frame % _rewindFrequency == 0) { - _rewindThread.Capture(((IStatable)Global.Emulator).SaveStateBinary()); + _rewindThread.Capture(Global.Emulator.AsStatable().SaveStateBinary()); } } } @@ -79,7 +79,7 @@ namespace BizHawk.Client.Common if (Global.Emulator.HasSavestates()) { // This is the first frame. Capture the state, and put it in LastState for future deltas to be compared against. - _lastState = (byte[]) ((IStatable)Global.Emulator).SaveStateBinary().Clone(); + _lastState = (byte[])Global.Emulator.AsStatable().SaveStateBinary().Clone(); int state_size; if (_lastState.Length >= Global.Config.Rewind_LargeStateSize) @@ -365,7 +365,7 @@ namespace BizHawk.Client.Common var fullstate = reader.ReadBoolean(); if (fullstate) { - ((IStatable)Global.Emulator).LoadStateBinary(reader); + Global.Emulator.AsStatable().LoadStateBinary(reader); } else { @@ -382,7 +382,7 @@ namespace BizHawk.Client.Common reader.Close(); output.Position = 0; - ((IStatable)Global.Emulator).LoadStateBinary(new BinaryReader(output)); + Global.Emulator.AsStatable().LoadStateBinary(new BinaryReader(output)); } } } diff --git a/BizHawk.Client.EmuHawk/MainForm.Movie.cs b/BizHawk.Client.EmuHawk/MainForm.Movie.cs index ea8812e552..bab5b19bff 100644 --- a/BizHawk.Client.EmuHawk/MainForm.Movie.cs +++ b/BizHawk.Client.EmuHawk/MainForm.Movie.cs @@ -51,11 +51,11 @@ namespace BizHawk.Client.EmuHawk { if (movie.TextSavestate != null) { - (Global.Emulator as IStatable).LoadStateText(new StringReader(movie.TextSavestate)); + Global.Emulator.AsStatable().LoadStateText(new StringReader(movie.TextSavestate)); } else { - (Global.Emulator as IStatable).LoadStateBinary(new BinaryReader(new MemoryStream(movie.BinarySavestate, false))); + Global.Emulator.AsStatable().LoadStateBinary(new BinaryReader(new MemoryStream(movie.BinarySavestate, false))); } if (movie.SavestateFramebuffer != null) { diff --git a/BizHawk.Client.EmuHawk/MainForm.cs b/BizHawk.Client.EmuHawk/MainForm.cs index eff4a04b65..c2edcaf54d 100644 --- a/BizHawk.Client.EmuHawk/MainForm.cs +++ b/BizHawk.Client.EmuHawk/MainForm.cs @@ -3520,6 +3520,7 @@ namespace BizHawk.Client.EmuHawk ClearHolds(); PauseOnFrame = null; ToolHelpers.UpdateCheatRelatedTools(null, null); + UpdateStatusSlots(); } } diff --git a/BizHawk.Client.EmuHawk/config/RewindConfig.cs b/BizHawk.Client.EmuHawk/config/RewindConfig.cs index 248d693894..9e25b54546 100644 --- a/BizHawk.Client.EmuHawk/config/RewindConfig.cs +++ b/BizHawk.Client.EmuHawk/config/RewindConfig.cs @@ -2,8 +2,9 @@ using System.Windows.Forms; using System.Drawing; -using BizHawk.Client.Common; using BizHawk.Emulation.Common; +using BizHawk.Emulation.Common.IEmulatorExtensions; +using BizHawk.Client.Common; namespace BizHawk.Client.EmuHawk { @@ -34,7 +35,7 @@ namespace BizHawk.Client.EmuHawk DiskBufferCheckbox.Checked = Global.Config.Rewind_OnDisk; RewindIsThreadedCheckbox.Checked = Global.Config.Rewind_IsThreaded; - _stateSize = ((IStatable)Global.Emulator).SaveStateBinary().Length; + _stateSize = Global.Emulator.AsStatable().SaveStateBinary().Length; BufferSizeUpDown.Value = Global.Config.Rewind_BufferSize; _mediumStateSize = Global.Config.Rewind_MediumStateSize; diff --git a/BizHawk.Client.EmuHawk/movie/RecordMovie.cs b/BizHawk.Client.EmuHawk/movie/RecordMovie.cs index 99db81bd78..9f3b4417ce 100644 --- a/BizHawk.Client.EmuHawk/movie/RecordMovie.cs +++ b/BizHawk.Client.EmuHawk/movie/RecordMovie.cs @@ -81,7 +81,7 @@ namespace BizHawk.Client.EmuHawk if (StartFromCombo.SelectedItem.ToString() == "Now" && Global.Emulator.HasSavestates()) { - var core = Global.Emulator as IStatable; + var core = Global.Emulator.AsStatable(); movieToRecord.StartsFromSavestate = true; diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/GreenzoneSettings.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/GreenzoneSettings.cs index e79b2630ac..ace72dfa6b 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/GreenzoneSettings.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/GreenzoneSettings.cs @@ -8,6 +8,7 @@ using System.Text; using System.Windows.Forms; using BizHawk.Emulation.Common; +using BizHawk.Emulation.Common.IEmulatorExtensions; using BizHawk.Client.Common; namespace BizHawk.Client.EmuHawk @@ -24,7 +25,7 @@ namespace BizHawk.Client.EmuHawk private void GreenzoneSettings_Load(object sender, EventArgs e) { - _stateSizeMb = ((IStatable)Global.Emulator).SaveStateBinary().Length / (decimal)1024 / (decimal)1024; + _stateSizeMb = Global.Emulator.AsStatable().SaveStateBinary().Length / (decimal)1024 / (decimal)1024; SaveGreenzoneCheckbox.Checked = Settings.SaveGreenzone; CapacityNumeric.Value = Settings.Capacitymb == 0 ? 1 : Settings.Capacitymb < CapacityNumeric.Maximum ? diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.MenuItems.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.MenuItems.cs index cde3dd251a..598c9e4278 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.MenuItems.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.MenuItems.cs @@ -6,11 +6,13 @@ using System.Linq; using System.Text; using System.Windows.Forms; +using BizHawk.Emulation.Common; +using BizHawk.Emulation.Common.IEmulatorExtensions; + using BizHawk.Client.Common; using BizHawk.Client.Common.MovieConversionExtensions; using BizHawk.Client.EmuHawk.ToolExtensions; using BizHawk.Client.EmuHawk.WinFormExtensions; -using BizHawk.Emulation.Common; namespace BizHawk.Client.EmuHawk { @@ -508,7 +510,7 @@ namespace BizHawk.Client.EmuHawk if (CurrentTasMovie.TasStateManager.HasState(frame)) { - var state = (byte[])(((IStatable)Global.Emulator).SaveStateBinary().Clone()); + var state = (byte[])Global.Emulator.AsStatable().SaveStateBinary().Clone(); var greenzone = CurrentTasMovie.TasStateManager[frame]; if (!state.SequenceEqual(greenzone.Value)) @@ -750,7 +752,7 @@ namespace BizHawk.Client.EmuHawk var newProject = CurrentTasMovie.ConvertToSavestateAnchoredMovie( index, - (byte[])((IStatable)Global.Emulator).SaveStateBinary().Clone()); + (byte[])Global.Emulator.AsStatable().SaveStateBinary().Clone()); GlobalWin.MainForm.PauseEmulator(); LoadProject(newProject.Filename); diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs index 90f9ec75a7..3a6c3db1ef 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs @@ -6,6 +6,7 @@ using System.Windows.Forms; using System.ComponentModel; using BizHawk.Emulation.Common; +using BizHawk.Emulation.Common.IEmulatorExtensions; using BizHawk.Client.Common; using BizHawk.Client.Common.MovieConversionExtensions; @@ -315,7 +316,7 @@ namespace BizHawk.Client.EmuHawk private void LoadState(KeyValuePair state) { - ((IStatable)Global.Emulator).LoadStateBinary(new BinaryReader(new MemoryStream(state.Value.ToArray()))); + Global.Emulator.AsStatable().LoadStateBinary(new BinaryReader(new MemoryStream(state.Value.ToArray()))); if (state.Key == 0 && CurrentTasMovie.StartsFromSavestate) { diff --git a/BizHawk.Emulation.Common/Extensions.cs b/BizHawk.Emulation.Common/Extensions.cs index 5e17487a82..7ded983033 100644 --- a/BizHawk.Emulation.Common/Extensions.cs +++ b/BizHawk.Emulation.Common/Extensions.cs @@ -19,7 +19,12 @@ namespace BizHawk.Emulation.Common.IEmulatorExtensions public static bool HasMemoryDomains(this IEmulator core) { - return core != null && core.ServiceProvider.HasService(); + if (core == null) + { + return false; + } + + return core.ServiceProvider.HasService(); } public static IMemoryDomains AsMemoryDomains(this IEmulator core) @@ -29,7 +34,12 @@ namespace BizHawk.Emulation.Common.IEmulatorExtensions public static bool HasSaveRam(this IEmulator core) { - return core != null && core.ServiceProvider.HasService(); + if (core == null) + { + return false; + } + + return core.ServiceProvider.HasService(); } public static ISaveRam AsSaveRam(this IEmulator core) @@ -39,7 +49,12 @@ namespace BizHawk.Emulation.Common.IEmulatorExtensions public static bool HasSavestates(this IEmulator core) { - return core != null && core.ServiceProvider.HasService(); + if (core == null) + { + return false; + } + + return core.ServiceProvider.HasService(); } public static IStatable AsStatable(this IEmulator core) @@ -49,7 +64,12 @@ namespace BizHawk.Emulation.Common.IEmulatorExtensions public static bool CanPollInput(this IEmulator core) { - return core != null && core.ServiceProvider.HasService(); + if (core == null) + { + return false; + } + + return core.ServiceProvider.HasService(); } public static IInputPollable AsInputPollable(this IEmulator core) @@ -79,6 +99,11 @@ namespace BizHawk.Emulation.Common.IEmulatorExtensions public static bool CanDebug(this IEmulator core) { + if (core == null) + { + return false; + } + return core.ServiceProvider.HasService(); }