diff --git a/BizHawk.Client.Common/SavestateManager.cs b/BizHawk.Client.Common/SavestateManager.cs index f590e4c15f..0420b359fa 100644 --- a/BizHawk.Client.Common/SavestateManager.cs +++ b/BizHawk.Client.Common/SavestateManager.cs @@ -3,6 +3,7 @@ using System.IO; using System.Linq; using BizHawk.Common; +using BizHawk.Emulation.Common; using BizHawk.Emulation.Common.IEmulatorExtensions; namespace BizHawk.Client.Common @@ -16,8 +17,7 @@ namespace BizHawk.Client.Common // 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); - if (Global.Config.SaveStateType == SaveStateTypeE.Text - || (Global.Config.SaveStateType == SaveStateTypeE.Default && !core.BinarySaveStatesPreferred)) + if (Global.Config.SaveStateType == SaveStateTypeE.Text) { // text savestate format using (new SimpleTime("Save Core")) diff --git a/BizHawk.Client.Common/config/Config.cs b/BizHawk.Client.Common/config/Config.cs index 27d96254df..810ddb4de5 100644 --- a/BizHawk.Client.Common/config/Config.cs +++ b/BizHawk.Client.Common/config/Config.cs @@ -136,7 +136,7 @@ namespace BizHawk.Client.Common public RewindConfig Rewind { get; set; } = new RewindConfig(); // Savestate settings - public SaveStateTypeE SaveStateType { get; set; } = SaveStateTypeE.Default; + public SaveStateTypeE SaveStateType { get; set; } = SaveStateTypeE.Binary; public const int DefaultSaveStateCompressionLevelNormal = 1; public int SaveStateCompressionLevelNormal { get; set; } = DefaultSaveStateCompressionLevelNormal; public const int DefaultSaveStateCompressionLevelRewind = 0; // this isn't actually used yet diff --git a/BizHawk.Client.Common/config/ConfigEnums.cs b/BizHawk.Client.Common/config/ConfigEnums.cs index a4be9b6116..c94fac86e5 100644 --- a/BizHawk.Client.Common/config/ConfigEnums.cs +++ b/BizHawk.Client.Common/config/ConfigEnums.cs @@ -29,7 +29,7 @@ public enum SaveStateTypeE { - Default, Binary, Text + Binary, Text } public enum ClientProfile diff --git a/BizHawk.Client.EmuHawk/config/RewindConfig.Designer.cs b/BizHawk.Client.EmuHawk/config/RewindConfig.Designer.cs index 0b64eb0b05..7b1b4c7e6a 100644 --- a/BizHawk.Client.EmuHawk/config/RewindConfig.Designer.cs +++ b/BizHawk.Client.EmuHawk/config/RewindConfig.Designer.cs @@ -84,7 +84,6 @@ this.groupBox6 = new System.Windows.Forms.GroupBox(); this.rbStatesText = new System.Windows.Forms.RadioButton(); this.rbStatesBinary = new System.Windows.Forms.RadioButton(); - this.rbStatesDefault = new System.Windows.Forms.RadioButton(); this.toolTip1 = new System.Windows.Forms.ToolTip(this.components); this.btnResetCompression = new System.Windows.Forms.Button(); this.trackBarCompression = new System.Windows.Forms.TrackBar(); @@ -762,7 +761,6 @@ // this.groupBox6.Controls.Add(this.rbStatesText); this.groupBox6.Controls.Add(this.rbStatesBinary); - this.groupBox6.Controls.Add(this.rbStatesDefault); this.groupBox6.Location = new System.Drawing.Point(22, 78); this.groupBox6.Name = "groupBox6"; this.groupBox6.Size = new System.Drawing.Size(215, 48); @@ -773,7 +771,7 @@ // rbStatesText // this.rbStatesText.AutoSize = true; - this.rbStatesText.Location = new System.Drawing.Point(163, 18); + this.rbStatesText.Location = new System.Drawing.Point(88, 18); this.rbStatesText.Name = "rbStatesText"; this.rbStatesText.Size = new System.Drawing.Size(46, 17); this.rbStatesText.TabIndex = 1; @@ -784,7 +782,7 @@ // rbStatesBinary // this.rbStatesBinary.AutoSize = true; - this.rbStatesBinary.Location = new System.Drawing.Point(88, 18); + this.rbStatesBinary.Location = new System.Drawing.Point(6, 18); this.rbStatesBinary.Name = "rbStatesBinary"; this.rbStatesBinary.Size = new System.Drawing.Size(54, 17); this.rbStatesBinary.TabIndex = 1; @@ -792,17 +790,6 @@ this.rbStatesBinary.Text = "Binary"; this.rbStatesBinary.UseVisualStyleBackColor = true; // - // rbStatesDefault - // - this.rbStatesDefault.AutoSize = true; - this.rbStatesDefault.Location = new System.Drawing.Point(6, 18); - this.rbStatesDefault.Name = "rbStatesDefault"; - this.rbStatesDefault.Size = new System.Drawing.Size(59, 17); - this.rbStatesDefault.TabIndex = 0; - this.rbStatesDefault.TabStop = true; - this.rbStatesDefault.Text = "Default"; - this.rbStatesDefault.UseVisualStyleBackColor = true; - // // btnResetCompression // this.btnResetCompression.AutoSize = true; @@ -1088,7 +1075,6 @@ private System.Windows.Forms.GroupBox groupBox6; private System.Windows.Forms.RadioButton rbStatesText; private System.Windows.Forms.RadioButton rbStatesBinary; - private System.Windows.Forms.RadioButton rbStatesDefault; private System.Windows.Forms.ToolTip toolTip1; private System.Windows.Forms.TrackBar trackBarCompression; private System.Windows.Forms.NumericUpDown nudCompression; diff --git a/BizHawk.Client.EmuHawk/config/RewindConfig.cs b/BizHawk.Client.EmuHawk/config/RewindConfig.cs index 48ea75c55d..3725117a32 100644 --- a/BizHawk.Client.EmuHawk/config/RewindConfig.cs +++ b/BizHawk.Client.EmuHawk/config/RewindConfig.cs @@ -74,7 +74,6 @@ namespace BizHawk.Client.EmuHawk nudCompression.Value = _config.SaveStateCompressionLevelNormal; - rbStatesDefault.Checked = _config.SaveStateType == SaveStateTypeE.Default; rbStatesBinary.Checked = _config.SaveStateType == SaveStateTypeE.Binary; rbStatesText.Checked = _config.SaveStateType == SaveStateTypeE.Text; @@ -182,7 +181,6 @@ namespace BizHawk.Client.EmuHawk // These settings are not used by DoRewindSettings _config.Rewind.SpeedMultiplier = (int)RewindSpeedNumeric.Value; _config.SaveStateCompressionLevelNormal = (int)nudCompression.Value; - if (rbStatesDefault.Checked) _config.SaveStateType = SaveStateTypeE.Default; if (rbStatesBinary.Checked) _config.SaveStateType = SaveStateTypeE.Binary; if (rbStatesText.Checked) _config.SaveStateType = SaveStateTypeE.Text; _config.BackupSavestates = BackupSavestatesCheckbox.Checked; diff --git a/BizHawk.Client.EmuHawk/movie/RecordMovie.cs b/BizHawk.Client.EmuHawk/movie/RecordMovie.cs index f49ce72478..8054e5bd41 100644 --- a/BizHawk.Client.EmuHawk/movie/RecordMovie.cs +++ b/BizHawk.Client.EmuHawk/movie/RecordMovie.cs @@ -108,7 +108,7 @@ namespace BizHawk.Client.EmuHawk movieToRecord.StartsFromSavestate = true; movieToRecord.StartsFromSaveRam = false; - if (core.BinarySaveStatesPreferred) + if (_config.SaveStateType == SaveStateTypeE.Binary) { movieToRecord.BinarySavestate = (byte[])core.SaveStateBinary().Clone(); } diff --git a/BizHawk.Emulation.Common/Interfaces/Services/IStatable.cs b/BizHawk.Emulation.Common/Interfaces/Services/IStatable.cs index b2580671c9..cf2788bd07 100644 --- a/BizHawk.Emulation.Common/Interfaces/Services/IStatable.cs +++ b/BizHawk.Emulation.Common/Interfaces/Services/IStatable.cs @@ -1,4 +1,5 @@ using System.IO; +using BizHawk.Common.BufferExtensions; namespace BizHawk.Emulation.Common { @@ -19,18 +20,54 @@ namespace BizHawk.Emulation.Common /// public interface IStatable : IBinaryStateable, IEmulatorService { - /// - /// Gets a value indicating whether the core would rather give a binary savestate than a text one. Both must function regardless - /// - bool BinarySaveStatesPreferred { get; } - - void SaveStateText(TextWriter writer); - void LoadStateText(TextReader reader); - /// /// save state binary to a byte buffer /// /// you may NOT modify this. if you call SaveStateBinary() again with the same core, the old data MAY be overwritten. byte[] SaveStateBinary(); } + + /// + /// Allows a core to opt into text savestates. + /// If a core does not implement this interface, a default implementation + /// will be used that doesn't yield anything useful in the states, just binary as text + /// + public interface ITextStatable : IStatable + { + void SaveStateText(TextWriter writer); + + void LoadStateText(TextReader reader); + } + + public static class StatableExtensions + { + public static void SaveStateText(this IStatable core, TextWriter writer) + { + if (core is ITextStatable textCore) + { + textCore.SaveStateText(writer); + } + + var temp = core.SaveStateBinary(); + temp.SaveAsHexFast(writer); + } + + public static void LoadStateText(this IStatable core, TextReader reader) + { + if (core is ITextStatable textCore) + { + textCore.LoadStateText(reader); + } + + string hex = reader.ReadLine(); + if (hex != null) + { + var state = new byte[hex.Length / 2]; + state.ReadFromHexFast(hex); + using var ms = new MemoryStream(state); + using var br = new BinaryReader(ms); + core.LoadStateBinary(br); + } + } + } } diff --git a/BizHawk.Emulation.Cores/Calculator/TI83.IStatable.cs b/BizHawk.Emulation.Cores/Calculator/TI83.IStatable.cs index 536e1b6cf9..96e6bd9915 100644 --- a/BizHawk.Emulation.Cores/Calculator/TI83.IStatable.cs +++ b/BizHawk.Emulation.Cores/Calculator/TI83.IStatable.cs @@ -5,10 +5,8 @@ using BizHawk.Emulation.Common; namespace BizHawk.Emulation.Cores.Calculators { - public partial class TI83 : IStatable + public partial class TI83 : ITextStatable { - public bool BinarySaveStatesPreferred => true; - public void SaveStateText(TextWriter writer) { SyncState(new Serializer(writer)); diff --git a/BizHawk.Emulation.Cores/Computers/AmstradCPC/AmstradCPC.IStatable.cs b/BizHawk.Emulation.Cores/Computers/AmstradCPC/AmstradCPC.IStatable.cs index 5536d2c7d9..c60ed02e44 100644 --- a/BizHawk.Emulation.Cores/Computers/AmstradCPC/AmstradCPC.IStatable.cs +++ b/BizHawk.Emulation.Cores/Computers/AmstradCPC/AmstradCPC.IStatable.cs @@ -8,10 +8,8 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC /// CPCHawk: Core Class /// * IStatable * /// - public partial class AmstradCPC : IStatable + public partial class AmstradCPC : ITextStatable { - public bool BinarySaveStatesPreferred => true; - public void SaveStateText(TextWriter writer) { SyncState(new Serializer(writer)); diff --git a/BizHawk.Emulation.Cores/Computers/AppleII/AppleII.IStatable.cs b/BizHawk.Emulation.Cores/Computers/AppleII/AppleII.IStatable.cs index 4aacbaadfe..e6efc269d3 100644 --- a/BizHawk.Emulation.Cores/Computers/AppleII/AppleII.IStatable.cs +++ b/BizHawk.Emulation.Cores/Computers/AppleII/AppleII.IStatable.cs @@ -8,7 +8,7 @@ using Newtonsoft.Json.Serialization; namespace BizHawk.Emulation.Cores.Computers.AppleII { - public partial class AppleII : IStatable + public partial class AppleII : ITextStatable { private class CoreConverter : JsonConverter { @@ -32,8 +32,6 @@ namespace BizHawk.Emulation.Cores.Computers.AppleII } } - public bool BinarySaveStatesPreferred => true; - private void SerializeEverything(JsonWriter w) { // this is much faster than other possibilities for serialization diff --git a/BizHawk.Emulation.Cores/Computers/Commodore64/C64.IStatable.cs b/BizHawk.Emulation.Cores/Computers/Commodore64/C64.IStatable.cs index 33d7787322..21f78ba84d 100644 --- a/BizHawk.Emulation.Cores/Computers/Commodore64/C64.IStatable.cs +++ b/BizHawk.Emulation.Cores/Computers/Commodore64/C64.IStatable.cs @@ -5,10 +5,8 @@ using BizHawk.Emulation.Common; namespace BizHawk.Emulation.Cores.Computers.Commodore64 { - public sealed partial class C64 : IStatable + public sealed partial class C64 : ITextStatable { - public bool BinarySaveStatesPreferred => true; - public void LoadStateBinary(BinaryReader br) { SyncState(new Serializer(br)); diff --git a/BizHawk.Emulation.Cores/Computers/MSX/MSX.IStatable.cs b/BizHawk.Emulation.Cores/Computers/MSX/MSX.IStatable.cs index a7be3096b3..a237dc198a 100644 --- a/BizHawk.Emulation.Cores/Computers/MSX/MSX.IStatable.cs +++ b/BizHawk.Emulation.Cores/Computers/MSX/MSX.IStatable.cs @@ -6,10 +6,8 @@ using BizHawk.Emulation.Common; namespace BizHawk.Emulation.Cores.Computers.MSX { - public partial class MSX : IStatable + public partial class MSX : ITextStatable { - public bool BinarySaveStatesPreferred => true; - public void SaveStateText(TextWriter writer) { SyncState(new Serializer(writer)); diff --git a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/ZXSpectrum.IStatable.cs b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/ZXSpectrum.IStatable.cs index 2fa6068384..d2426e51d5 100644 --- a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/ZXSpectrum.IStatable.cs +++ b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/ZXSpectrum.IStatable.cs @@ -8,10 +8,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum /// ZXHawk: Core Class /// * IStatable * /// - public partial class ZXSpectrum : IStatable + public partial class ZXSpectrum : ITextStatable { - public bool BinarySaveStatesPreferred => true; - public void SaveStateText(TextWriter writer) { SyncState(new Serializer(writer)); diff --git a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.IStatable.cs b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.IStatable.cs index bbc8c721cd..1c9a65af26 100644 --- a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.IStatable.cs +++ b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.IStatable.cs @@ -5,10 +5,8 @@ using BizHawk.Emulation.Common; namespace BizHawk.Emulation.Cores.Atari.Atari2600 { - public partial class Atari2600 : IStatable + public partial class Atari2600 : ITextStatable { - public bool BinarySaveStatesPreferred => true; - public void SaveStateText(TextWriter writer) { SyncState(Serializer.CreateTextWriter(writer)); diff --git a/BizHawk.Emulation.Cores/Consoles/Atari/A7800Hawk/A7800Hawk.IStatable.cs b/BizHawk.Emulation.Cores/Consoles/Atari/A7800Hawk/A7800Hawk.IStatable.cs index e417f03e99..d9b89647ff 100644 --- a/BizHawk.Emulation.Cores/Consoles/Atari/A7800Hawk/A7800Hawk.IStatable.cs +++ b/BizHawk.Emulation.Cores/Consoles/Atari/A7800Hawk/A7800Hawk.IStatable.cs @@ -5,10 +5,8 @@ using BizHawk.Emulation.Common; namespace BizHawk.Emulation.Cores.Atari.A7800Hawk { - public partial class A7800Hawk : IStatable + public partial class A7800Hawk : ITextStatable { - public bool BinarySaveStatesPreferred => true; - public void SaveStateText(TextWriter writer) { SyncState(new Serializer(writer)); diff --git a/BizHawk.Emulation.Cores/Consoles/Atari/lynx/Lynx.IStatable.cs b/BizHawk.Emulation.Cores/Consoles/Atari/lynx/Lynx.IStatable.cs index 2f869099c9..d0407b0c87 100644 --- a/BizHawk.Emulation.Cores/Consoles/Atari/lynx/Lynx.IStatable.cs +++ b/BizHawk.Emulation.Cores/Consoles/Atari/lynx/Lynx.IStatable.cs @@ -6,10 +6,8 @@ using BizHawk.Emulation.Common; namespace BizHawk.Emulation.Cores.Atari.Lynx { - public partial class Lynx : IStatable + public partial class Lynx : ITextStatable { - public bool BinarySaveStatesPreferred => true; - public void SaveStateText(TextWriter writer) { var s = new TextState(); @@ -21,8 +19,6 @@ namespace BizHawk.Emulation.Cores.Atari.Lynx s.ExtraData.Frame = Frame; _ser.Serialize(writer, s); - - ////Console.WriteLine(BizHawk.Common.BufferExtensions.BufferExtensions.HashSHA1(SaveStateBinary())); } public void LoadStateText(TextReader reader) diff --git a/BizHawk.Emulation.Cores/Consoles/Coleco/ColecoVision.IStatable.cs b/BizHawk.Emulation.Cores/Consoles/Coleco/ColecoVision.IStatable.cs index 599f40ebea..dfbbc4d82e 100644 --- a/BizHawk.Emulation.Cores/Consoles/Coleco/ColecoVision.IStatable.cs +++ b/BizHawk.Emulation.Cores/Consoles/Coleco/ColecoVision.IStatable.cs @@ -5,10 +5,8 @@ using BizHawk.Emulation.Common; namespace BizHawk.Emulation.Cores.ColecoVision { - public partial class ColecoVision : IStatable + public partial class ColecoVision : ITextStatable { - public bool BinarySaveStatesPreferred => true; - public void SaveStateText(TextWriter writer) { SyncState(new Serializer(writer)); diff --git a/BizHawk.Emulation.Cores/Consoles/Fairchild/ChannelF/ChannelF.IStatable.cs b/BizHawk.Emulation.Cores/Consoles/Fairchild/ChannelF/ChannelF.IStatable.cs index 101f1fd378..5600562e8c 100644 --- a/BizHawk.Emulation.Cores/Consoles/Fairchild/ChannelF/ChannelF.IStatable.cs +++ b/BizHawk.Emulation.Cores/Consoles/Fairchild/ChannelF/ChannelF.IStatable.cs @@ -6,10 +6,8 @@ using BizHawk.Emulation.Common; namespace BizHawk.Emulation.Cores.Consoles.ChannelF { - public partial class ChannelF : IStatable + public partial class ChannelF : ITextStatable { - public bool BinarySaveStatesPreferred => true; - public void SaveStateText(TextWriter writer) { SyncState(new Serializer(writer)); diff --git a/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawk.IStatable.cs b/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawk.IStatable.cs index a0e0eb1caf..e88f8b5124 100644 --- a/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawk.IStatable.cs +++ b/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawk.IStatable.cs @@ -5,10 +5,8 @@ using BizHawk.Emulation.Common; namespace BizHawk.Emulation.Cores.Consoles.Vectrex { - public partial class VectrexHawk : IStatable + public partial class VectrexHawk : ITextStatable { - public bool BinarySaveStatesPreferred => true; - public void SaveStateText(TextWriter writer) { SyncState(new Serializer(writer)); diff --git a/BizHawk.Emulation.Cores/Consoles/Intellivision/Intellivision.IStatable.cs b/BizHawk.Emulation.Cores/Consoles/Intellivision/Intellivision.IStatable.cs index 36285ad7df..b88b5038cf 100644 --- a/BizHawk.Emulation.Cores/Consoles/Intellivision/Intellivision.IStatable.cs +++ b/BizHawk.Emulation.Cores/Consoles/Intellivision/Intellivision.IStatable.cs @@ -5,10 +5,8 @@ using BizHawk.Emulation.Common; namespace BizHawk.Emulation.Cores.Intellivision { - public partial class Intellivision : IStatable + public partial class Intellivision : ITextStatable { - public bool BinarySaveStatesPreferred => true; - public void SaveStateText(TextWriter writer) { SyncState(Serializer.CreateTextWriter(writer)); diff --git a/BizHawk.Emulation.Cores/Consoles/Magnavox/Odyssey2/O2Hawk.IStatable.cs b/BizHawk.Emulation.Cores/Consoles/Magnavox/Odyssey2/O2Hawk.IStatable.cs index 914c14d42b..f9e02a9819 100644 --- a/BizHawk.Emulation.Cores/Consoles/Magnavox/Odyssey2/O2Hawk.IStatable.cs +++ b/BizHawk.Emulation.Cores/Consoles/Magnavox/Odyssey2/O2Hawk.IStatable.cs @@ -5,10 +5,8 @@ using BizHawk.Emulation.Common; namespace BizHawk.Emulation.Cores.Consoles.O2Hawk { - public partial class O2Hawk : IStatable + public partial class O2Hawk : ITextStatable { - public bool BinarySaveStatesPreferred => true; - public void SaveStateText(TextWriter writer) { SyncState(new Serializer(writer)); diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBA/MGBAHawk.IStatable.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBA/MGBAHawk.IStatable.cs index e28e042b68..b822df8c92 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBA/MGBAHawk.IStatable.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBA/MGBAHawk.IStatable.cs @@ -10,21 +10,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA private byte[] _savebuff = new byte[0]; private byte[] _savebuff2 = new byte[13]; - public bool BinarySaveStatesPreferred => true; - - public void SaveStateText(TextWriter writer) - { - var tmp = SaveStateBinary(); - BizHawk.Common.BufferExtensions.BufferExtensions.SaveAsHexFast(tmp, writer); - } - public void LoadStateText(TextReader reader) - { - string hex = reader.ReadLine(); - byte[] state = new byte[hex.Length / 2]; - BizHawk.Common.BufferExtensions.BufferExtensions.ReadFromHexFast(state, hex); - LoadStateBinary(new BinaryReader(new MemoryStream(state))); - } - private void StartSaveStateBinaryInternal() { IntPtr p = IntPtr.Zero; diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBA/VBANext.IStatable.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBA/VBANext.IStatable.cs index 4456474a5c..a2d8d36355 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBA/VBANext.IStatable.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBA/VBANext.IStatable.cs @@ -6,10 +6,8 @@ using BizHawk.Emulation.Common; namespace BizHawk.Emulation.Cores.Nintendo.GBA { - public partial class VBANext : IStatable + public partial class VBANext : ITextStatable { - public bool BinarySaveStatesPreferred => true; - public void SaveStateText(TextWriter writer) { var s = new TextState(); @@ -21,8 +19,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA s.ExtraData.Frame = Frame; ser.Serialize(writer, s); - - //Console.WriteLine(BizHawk.Common.BufferExtensions.BufferExtensions.HashSHA1(SaveStateBinary())); } public void LoadStateText(TextReader reader) diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.IStatable.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.IStatable.cs index 93afa3e795..fc5c978328 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.IStatable.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawk.IStatable.cs @@ -5,10 +5,8 @@ using BizHawk.Emulation.Common; namespace BizHawk.Emulation.Cores.Nintendo.GBHawk { - public partial class GBHawk : IStatable + public partial class GBHawk : ITextStatable { - public bool BinarySaveStatesPreferred => true; - public void SaveStateText(TextWriter writer) { SyncState(new Serializer(writer)); diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink/GBHawkLink.IStatable.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink/GBHawkLink.IStatable.cs index f50e14261e..dd4957b69a 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink/GBHawkLink.IStatable.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink/GBHawkLink.IStatable.cs @@ -1,16 +1,12 @@ using System.IO; -using Newtonsoft.Json; using BizHawk.Common; using BizHawk.Emulation.Common; -using BizHawk.Emulation.Cores.Nintendo.GBHawk; namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink { - public partial class GBHawkLink : IStatable + public partial class GBHawkLink : ITextStatable { - public bool BinarySaveStatesPreferred => true; - public void SaveStateText(TextWriter writer) { L.SaveStateText(writer); @@ -50,8 +46,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink return ms.ToArray(); } - //private JsonSerializer ser = new JsonSerializer { Formatting = Formatting.Indented }; - private void SyncState(Serializer ser) { ser.Sync("Lag", ref _lagcount); diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink3x/GBHawkLink3x.IStatable.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink3x/GBHawkLink3x.IStatable.cs index 808ac83c8b..f450690a8c 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink3x/GBHawkLink3x.IStatable.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink3x/GBHawkLink3x.IStatable.cs @@ -1,16 +1,11 @@ using System.IO; -using Newtonsoft.Json; - using BizHawk.Common; using BizHawk.Emulation.Common; -using BizHawk.Emulation.Cores.Nintendo.GBHawk; namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink3x { - public partial class GBHawkLink3x : IStatable + public partial class GBHawkLink3x : ITextStatable { - public bool BinarySaveStatesPreferred => true; - public void SaveStateText(TextWriter writer) { L.SaveStateText(writer); @@ -54,8 +49,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink3x return ms.ToArray(); } - //private JsonSerializer ser = new JsonSerializer { Formatting = Formatting.Indented }; - private void SyncState(Serializer ser) { ser.Sync("Lag", ref _lagcount); diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink4x/GBHawkLink4x.IStatable.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink4x/GBHawkLink4x.IStatable.cs index ac26a03589..2bff0a195a 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink4x/GBHawkLink4x.IStatable.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink4x/GBHawkLink4x.IStatable.cs @@ -1,16 +1,12 @@ using System.IO; -using Newtonsoft.Json; using BizHawk.Common; using BizHawk.Emulation.Common; -using BizHawk.Emulation.Cores.Nintendo.GBHawk; namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink4x { - public partial class GBHawkLink4x : IStatable + public partial class GBHawkLink4x : ITextStatable { - public bool BinarySaveStatesPreferred => true; - public void SaveStateText(TextWriter writer) { A.SaveStateText(writer); diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.IStatable.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.IStatable.cs index b4c83a3c62..df7e423b81 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.IStatable.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.IStatable.cs @@ -6,10 +6,8 @@ using BizHawk.Emulation.Common; namespace BizHawk.Emulation.Cores.Nintendo.Gameboy { - public partial class Gameboy : IStatable + public partial class Gameboy : ITextStatable { - public bool BinarySaveStatesPreferred => true; - public void SaveStateText(TextWriter writer) { var s = SaveState(); diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IStatable.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IStatable.cs index ea6e8bf0ed..4874b0b8aa 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IStatable.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IStatable.cs @@ -8,8 +8,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy { public partial class GambatteLink : IStatable { - public bool BinarySaveStatesPreferred { get { return true; } } - public void SaveStateText(TextWriter writer) { var s = new DGBSerialized diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64.IStatable.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64.IStatable.cs index 247e146f19..bf4d39658d 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64.IStatable.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64.IStatable.cs @@ -1,7 +1,6 @@ using System; using System.IO; -using BizHawk.Common.BufferExtensions; using BizHawk.Emulation.Common; using BizHawk.Emulation.Cores.Nintendo.N64.NativeApi; @@ -9,24 +8,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64 { public partial class N64 : IStatable { - public bool BinarySaveStatesPreferred => true; - - // these functions are all exact copy paste from gambatte. - // if something's wrong here, it's probably wrong there too - public void SaveStateText(TextWriter writer) - { - var temp = SaveStateBinary(); - temp.SaveAsHexFast(writer); - } - - public void LoadStateText(TextReader reader) - { - var hex = reader.ReadLine(); - var state = new byte[hex.Length / 2]; - state.ReadFromHexFast(hex); - LoadStateBinary(new BinaryReader(new MemoryStream(state))); - } - public void SaveStateBinary(BinaryWriter writer) { byte[] data = SaveStatePrivateBuff; diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.IStatable.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.IStatable.cs index 3abba61465..0c39a4fd56 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.IStatable.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.IStatable.cs @@ -5,10 +5,8 @@ using BizHawk.Emulation.Common; namespace BizHawk.Emulation.Cores.Nintendo.NES { - public partial class NES : IStatable + public partial class NES : ITextStatable { - public bool BinarySaveStatesPreferred => false; - public void SaveStateText(TextWriter writer) { SyncState(Serializer.CreateTextWriter(writer)); diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/QuickNES/QuickNES.IStatable.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/QuickNES/QuickNES.IStatable.cs index 58e9a137c9..f42fd12dab 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/QuickNES/QuickNES.IStatable.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/QuickNES/QuickNES.IStatable.cs @@ -1,30 +1,11 @@ using System; using System.IO; -using BizHawk.Common.BufferExtensions; using BizHawk.Emulation.Common; namespace BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES { public partial class QuickNES : IStatable { - public bool BinarySaveStatesPreferred => true; - - public void SaveStateText(TextWriter writer) - { - CheckDisposed(); - var temp = SaveStateBinary(); - temp.SaveAsHexFast(writer); - } - - public void LoadStateText(TextReader reader) - { - CheckDisposed(); - string hex = reader.ReadLine(); - byte[] state = new byte[hex.Length / 2]; - state.ReadFromHexFast(hex); - LoadStateBinary(new BinaryReader(new MemoryStream(state))); - } - public void SaveStateBinary(BinaryWriter writer) { CheckDisposed(); diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.IStatable.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.IStatable.cs index 50a080a048..2876fe908d 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.IStatable.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.IStatable.cs @@ -1,27 +1,10 @@ using System.IO; -using BizHawk.Common.BufferExtensions; using BizHawk.Emulation.Common; namespace BizHawk.Emulation.Cores.Nintendo.SNES { public unsafe partial class LibsnesCore : IStatable { - public bool BinarySaveStatesPreferred => true; - - public void SaveStateText(TextWriter writer) - { - var temp = SaveStateBinary(); - temp.SaveAsHexFast(writer); - } - - public void LoadStateText(TextReader reader) - { - string hex = reader.ReadLine(); - byte[] state = new byte[hex.Length / 2]; - state.ReadFromHexFast(hex); - LoadStateBinary(new BinaryReader(new MemoryStream(state))); - } - public void SaveStateBinary(BinaryWriter writer) { Api.SaveStateBinary(writer); diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/SubNESHawk/SubNESHawk.IStatable.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/SubNESHawk/SubNESHawk.IStatable.cs index a8b098dfa9..e0908681ac 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/SubNESHawk/SubNESHawk.IStatable.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/SubNESHawk/SubNESHawk.IStatable.cs @@ -5,10 +5,8 @@ using BizHawk.Emulation.Common; namespace BizHawk.Emulation.Cores.Nintendo.SubNESHawk { - public partial class SubNESHawk : IStatable + public partial class SubNESHawk : ITextStatable { - public bool BinarySaveStatesPreferred => true; - public void SaveStateText(TextWriter writer) { subnes.SaveStateText(writer); @@ -44,8 +42,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.SubNESHawk return ms.ToArray(); } - //private JsonSerializer ser = new JsonSerializer { Formatting = Formatting.Indented }; - private void SyncState(Serializer ser) { ser.Sync("Lag", ref _lagCount); diff --git a/BizHawk.Emulation.Cores/Consoles/PC Engine/PCEngine.IStatable.cs b/BizHawk.Emulation.Cores/Consoles/PC Engine/PCEngine.IStatable.cs index 67c58347ec..804b99cf36 100644 --- a/BizHawk.Emulation.Cores/Consoles/PC Engine/PCEngine.IStatable.cs +++ b/BizHawk.Emulation.Cores/Consoles/PC Engine/PCEngine.IStatable.cs @@ -5,10 +5,8 @@ using BizHawk.Emulation.Common; namespace BizHawk.Emulation.Cores.PCEngine { - public sealed partial class PCEngine : IStatable + public sealed partial class PCEngine : ITextStatable { - public bool BinarySaveStatesPreferred => false; - public void SaveStateBinary(BinaryWriter bw) { SyncState(Serializer.CreateBinaryWriter(bw)); diff --git a/BizHawk.Emulation.Cores/Consoles/Sega/GGHawkLink/GGHawkLink.IStatable.cs b/BizHawk.Emulation.Cores/Consoles/Sega/GGHawkLink/GGHawkLink.IStatable.cs index f91074025a..f0254251f4 100644 --- a/BizHawk.Emulation.Cores/Consoles/Sega/GGHawkLink/GGHawkLink.IStatable.cs +++ b/BizHawk.Emulation.Cores/Consoles/Sega/GGHawkLink/GGHawkLink.IStatable.cs @@ -1,15 +1,12 @@ using System.IO; -using Newtonsoft.Json; using BizHawk.Common; using BizHawk.Emulation.Common; namespace BizHawk.Emulation.Cores.Sega.GGHawkLink { - public partial class GGHawkLink : IStatable + public partial class GGHawkLink : ITextStatable { - public bool BinarySaveStatesPreferred => true; - public void SaveStateText(TextWriter writer) { L.SaveStateText(writer); @@ -49,8 +46,6 @@ namespace BizHawk.Emulation.Cores.Sega.GGHawkLink return ms.ToArray(); } - //private JsonSerializer ser = new JsonSerializer { Formatting = Formatting.Indented }; - private void SyncState(Serializer ser) { ser.Sync("Lag", ref _lagCount); diff --git a/BizHawk.Emulation.Cores/Consoles/Sega/SMS/SMS.IStatable.cs b/BizHawk.Emulation.Cores/Consoles/Sega/SMS/SMS.IStatable.cs index d83575310c..c909264e02 100644 --- a/BizHawk.Emulation.Cores/Consoles/Sega/SMS/SMS.IStatable.cs +++ b/BizHawk.Emulation.Cores/Consoles/Sega/SMS/SMS.IStatable.cs @@ -5,10 +5,8 @@ using BizHawk.Emulation.Common; namespace BizHawk.Emulation.Cores.Sega.MasterSystem { - public partial class SMS : IStatable + public partial class SMS : ITextStatable { - public bool BinarySaveStatesPreferred => true; - public void SaveStateText(TextWriter writer) { SyncState(new Serializer(writer)); diff --git a/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GPGX.IStatable.cs b/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GPGX.IStatable.cs index 4fddc76c06..9aee0aca00 100644 --- a/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GPGX.IStatable.cs +++ b/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GPGX.IStatable.cs @@ -1,28 +1,10 @@ using System.IO; - -using BizHawk.Common.BufferExtensions; using BizHawk.Emulation.Common; namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx { public partial class GPGX : IStatable { - public bool BinarySaveStatesPreferred => true; - - public void SaveStateText(TextWriter writer) - { - var temp = SaveStateBinary(); - temp.SaveAsHexFast(writer); - } - - public void LoadStateText(TextReader reader) - { - string hex = reader.ReadLine(); - byte[] state = new byte[hex.Length / 2]; - state.ReadFromHexFast(hex); - LoadStateBinary(new BinaryReader(new MemoryStream(state))); - } - public void LoadStateBinary(BinaryReader reader) { _elf.LoadStateBinary(reader); diff --git a/BizHawk.Emulation.Cores/Consoles/Sony/PSX/Octoshock.cs b/BizHawk.Emulation.Cores/Consoles/Sony/PSX/Octoshock.cs index 7f6f2ceaa3..7ea9d57fdc 100644 --- a/BizHawk.Emulation.Cores/Consoles/Sony/PSX/Octoshock.cs +++ b/BizHawk.Emulation.Cores/Consoles/Sony/PSX/Octoshock.cs @@ -1072,62 +1072,6 @@ namespace BizHawk.Emulation.Cores.Sony.PSX #region Savestates //THIS IS STILL AWFUL - JsonSerializer ser = new JsonSerializer() { Formatting = Formatting.Indented }; - - class TextStateData - { - public int Frame; - public int LagCount; - public bool IsLagFrame; - public bool CurrentDiscEjected; - public int CurrentDiscIndexMounted; - } - - public void SaveStateText(TextWriter writer) - { - var s = new TextState(); - s.Prepare(); - - var transaction = new OctoshockDll.ShockStateTransaction() - { - transaction = OctoshockDll.eShockStateTransaction.TextSave, - ff = s.GetFunctionPointersSave() - }; - int result = OctoshockDll.shock_StateTransaction(psx, ref transaction); - if (result != OctoshockDll.SHOCK_OK) - throw new InvalidOperationException($"{nameof(OctoshockDll.eShockStateTransaction)}.{nameof(OctoshockDll.eShockStateTransaction.TextSave)} returned error!"); - - s.ExtraData.IsLagFrame = IsLagFrame; - s.ExtraData.LagCount = LagCount; - s.ExtraData.Frame = Frame; - s.ExtraData.CurrentDiscEjected = CurrentTrayOpen; - s.ExtraData.CurrentDiscIndexMounted = CurrentDiscIndexMounted; - - ser.Serialize(writer, s); - } - - public void LoadStateText(TextReader reader) - { - var s = (TextState)ser.Deserialize(reader, typeof(TextState)); - s.Prepare(); - var transaction = new OctoshockDll.ShockStateTransaction() - { - transaction = OctoshockDll.eShockStateTransaction.TextLoad, - ff = s.GetFunctionPointersLoad() - }; - - int result = OctoshockDll.shock_StateTransaction(psx, ref transaction); - if (result != OctoshockDll.SHOCK_OK) - throw new InvalidOperationException($"{nameof(OctoshockDll.eShockStateTransaction)}.{nameof(OctoshockDll.eShockStateTransaction.TextLoad)} returned error!"); - - IsLagFrame = s.ExtraData.IsLagFrame; - LagCount = s.ExtraData.LagCount; - Frame = s.ExtraData.Frame; - CurrentTrayOpen = s.ExtraData.CurrentDiscEjected; - CurrentDiscIndexMounted = s.ExtraData.CurrentDiscIndexMounted; - PokeDisc(); - } - byte[] savebuff; byte[] savebuff2; @@ -1208,8 +1152,6 @@ namespace BizHawk.Emulation.Cores.Sony.PSX return savebuff2; } - public bool BinarySaveStatesPreferred => true; - #endregion #region Settings diff --git a/BizHawk.Emulation.Cores/Consoles/WonderSwan/WonderSwan.IStatable.cs b/BizHawk.Emulation.Cores/Consoles/WonderSwan/WonderSwan.IStatable.cs index 7160d76c2a..5c79465eda 100644 --- a/BizHawk.Emulation.Cores/Consoles/WonderSwan/WonderSwan.IStatable.cs +++ b/BizHawk.Emulation.Cores/Consoles/WonderSwan/WonderSwan.IStatable.cs @@ -8,7 +8,7 @@ using System.Runtime.InteropServices; namespace BizHawk.Emulation.Cores.WonderSwan { - partial class WonderSwan: IStatable + partial class WonderSwan: ITextStatable { private void InitIStatable() { @@ -97,7 +97,5 @@ namespace BizHawk.Emulation.Cores.WonderSwan ms.Close(); return savebuff2; } - - public bool BinarySaveStatesPreferred => true; } } diff --git a/BizHawk.Emulation.Cores/Libretro/LibretroCore.cs b/BizHawk.Emulation.Cores/Libretro/LibretroCore.cs index 855b045fc4..c27d7324ee 100644 --- a/BizHawk.Emulation.Cores/Libretro/LibretroCore.cs +++ b/BizHawk.Emulation.Cores/Libretro/LibretroCore.cs @@ -4,15 +4,9 @@ //Since it's an IEmulator.. but... I dont know. Yeah, that's probably best using System; -using System.Linq; -using System.Xml; -using System.Xml.Linq; using System.IO; using System.Collections.Generic; using System.Runtime.InteropServices; - -using BizHawk.Common; -using BizHawk.Common.BufferExtensions; using BizHawk.Emulation.Common; namespace BizHawk.Emulation.Cores.Libretro @@ -364,20 +358,6 @@ namespace BizHawk.Emulation.Cores.Libretro private byte[] savebuff, savebuff2; - public void SaveStateText(System.IO.TextWriter writer) - { - var temp = SaveStateBinary(); - temp.SaveAsHexFast(writer); - } - - public void LoadStateText(System.IO.TextReader reader) - { - string hex = reader.ReadLine(); - byte[] state = new byte[hex.Length / 2]; - state.ReadFromHex(hex); - LoadStateBinary(new BinaryReader(new MemoryStream(state))); - } - public void SaveStateBinary(System.IO.BinaryWriter writer) { api.CMD_UpdateSerializeSize(); @@ -426,8 +406,6 @@ namespace BizHawk.Emulation.Cores.Libretro return savebuff2; } - public bool BinarySaveStatesPreferred { get { return true; } } - #endregion diff --git a/BizHawk.Emulation.Cores/Waterbox/WaterboxCore.cs b/BizHawk.Emulation.Cores/Waterbox/WaterboxCore.cs index 5121d13e8f..68f47e44ee 100644 --- a/BizHawk.Emulation.Cores/Waterbox/WaterboxCore.cs +++ b/BizHawk.Emulation.Cores/Waterbox/WaterboxCore.cs @@ -1,14 +1,10 @@ using BizHawk.Common; using BizHawk.BizInvoke; -using BizHawk.Common.BufferExtensions; using BizHawk.Emulation.Common; using System; -using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.InteropServices; -using System.Text; -using System.Threading.Tasks; namespace BizHawk.Emulation.Cores.Waterbox { @@ -254,22 +250,6 @@ namespace BizHawk.Emulation.Cores.Waterbox #region IStatable - public bool BinarySaveStatesPreferred => true; - - public void SaveStateText(TextWriter writer) - { - var temp = SaveStateBinary(); - temp.SaveAsHexFast(writer); - } - - public void LoadStateText(TextReader reader) - { - string hex = reader.ReadLine(); - byte[] state = new byte[hex.Length / 2]; - state.ReadFromHexFast(hex); - LoadStateBinary(new BinaryReader(new MemoryStream(state))); - } - public void LoadStateBinary(BinaryReader reader) { _exe.LoadStateBinary(reader);