diff --git a/.editorconfig b/.editorconfig
index e7fa14bdf8c..4eb6270c60a 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -63,16 +63,16 @@ dotnet_diagnostic.IDE0032.severity = suggestion
# Simplify default expression
dotnet_diagnostic.IDE0034.severity = suggestion
# Use pattern matching to avoid is check followed by a cast (without variable)
-dotnet_diagnostic.IDE0038.severity = warning
+dotnet_diagnostic.IDE0038.severity = warning # Note that this doesn't work with `dotnet build` but does work inside Visual Studio.
# Use is null check
dotnet_diagnostic.IDE0041.severity = warning
# Deconstruct variable declaration
dotnet_diagnostic.IDE0042.severity = suggestion
# dotnet_diagnostic.IDE0049.severity = error # see SA1121
# Remove unused private member
-dotnet_diagnostic.IDE0051.severity = suggestion
+dotnet_diagnostic.IDE0051.severity = warning
# Remove unread private member
-dotnet_diagnostic.IDE0052.severity = silent # TODO: should be warning imo, but there's too much violation currently
+dotnet_diagnostic.IDE0052.severity = warning
# Use compound assignment
dotnet_diagnostic.IDE0054.severity = warning
# Use index operator
@@ -97,6 +97,8 @@ dotnet_diagnostic.IDE0071.severity = suggestion
dotnet_diagnostic.IDE0074.severity = suggestion
# Use pattern matching
dotnet_diagnostic.IDE0078.severity = suggestion
+# Suppression operator has no effect and can be misinterpreted
+dotnet_diagnostic.IDE0080.severity = warning
# Convert typeof to nameof
dotnet_diagnostic.IDE0082.severity = warning
# Use pattern matching (not operator)
diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs
index 9bf8ffb97c8..d9ed1394360 100644
--- a/.git-blame-ignore-revs
+++ b/.git-blame-ignore-revs
@@ -21,3 +21,6 @@ fec63fb66afe70a22cf328eecdaf09e37c21ada5
# Remove line-end whitespace across main solution
605deb682dacec3342c650e76fb77972e5ffbe04
+
+# Fix use of mixed spaces and tabs for indentation
+1f62c65b6a9ccbe0837481a8c691ac4598868a83
diff --git a/src/BizHawk.Bizware.Input/SDL2/SDL2Gamepad.cs b/src/BizHawk.Bizware.Input/SDL2/SDL2Gamepad.cs
index 200f266cb0a..8eef3d78c42 100644
--- a/src/BizHawk.Bizware.Input/SDL2/SDL2Gamepad.cs
+++ b/src/BizHawk.Bizware.Input/SDL2/SDL2Gamepad.cs
@@ -367,4 +367,3 @@ public void SetVibration(int left, int right)
}
}
}
-
diff --git a/src/BizHawk.Client.Common/cheats/GbaGameSharkDecoder.cs b/src/BizHawk.Client.Common/cheats/GbaGameSharkDecoder.cs
index da83762119d..5ca78e946b5 100644
--- a/src/BizHawk.Client.Common/cheats/GbaGameSharkDecoder.cs
+++ b/src/BizHawk.Client.Common/cheats/GbaGameSharkDecoder.cs
@@ -7,7 +7,6 @@ namespace BizHawk.Client.Common.cheats
public static class GbaGameSharkDecoder
{
private static readonly uint[] GameSharkSeeds = { 0x09F4FBBDU, 0x9681884AU, 0x352027E9U, 0xF3DEE5A7U };
- private static readonly uint[] ProActionReplaySeeds = { 0x7AA9648FU, 0x7FAE6994U, 0xC0EFAAD5U, 0x42712C57U };
private static string Decrypt(string code)
{
@@ -28,6 +27,8 @@ private static string Decrypt(string code)
}
// TODO: When to use this?
+#if false
+ private static readonly uint[] ProActionReplaySeeds = { 0x7AA9648FU, 0x7FAE6994U, 0xC0EFAAD5U, 0x42712C57U };
private static string DecryptPro(string code)
{
var sum = 0xC6EF3720;
@@ -43,6 +44,7 @@ private static string DecryptPro(string code)
return $"{op1:X8} {op2:X8}";
}
+#endif
public static IDecodeResult Decode(string code)
{
diff --git a/src/BizHawk.Client.Common/config/ConfigPersistAttribute.cs b/src/BizHawk.Client.Common/config/ConfigPersistAttribute.cs
index 03839199183..7ffc42495a7 100644
--- a/src/BizHawk.Client.Common/config/ConfigPersistAttribute.cs
+++ b/src/BizHawk.Client.Common/config/ConfigPersistAttribute.cs
@@ -2,6 +2,7 @@ namespace BizHawk.Client.Common
{
/// Indicates that a property is to be saved to config for persistence.
[AttributeUsage(AttributeTargets.Property)]
+ [Obsolete("Use interface IConfigPersist instead.")]
public sealed class ConfigPersistAttribute : Attribute
{
}
diff --git a/src/BizHawk.Client.Common/config/IConfigPersist.cs b/src/BizHawk.Client.Common/config/IConfigPersist.cs
new file mode 100644
index 00000000000..2e0098a8c9f
--- /dev/null
+++ b/src/BizHawk.Client.Common/config/IConfigPersist.cs
@@ -0,0 +1,56 @@
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Globalization;
+
+namespace BizHawk.Client.Common
+{
+ public interface IConfigPersist
+ {
+ public class Provider
+ {
+ private Dictionary _data;
+
+ public Provider(Dictionary data)
+ {
+ _data = data;
+ }
+
+ public bool Get(string name, ref T value)
+ {
+ if (_data.TryGetValue(name, out var val))
+ {
+ if (val is string str && typeof(T) != typeof(string))
+ {
+ // if a type has a TypeConverter, and that converter can convert to string,
+ // that will be used in place of object markup by JSON.NET
+
+ // but that doesn't work with $type metadata, and JSON.NET fails to fall
+ // back on regular object serialization when needed. so try to undo a TypeConverter
+ // operation here
+ var converter = TypeDescriptor.GetConverter(typeof(T));
+ val = converter.ConvertFromString(null, CultureInfo.InvariantCulture, str);
+ }
+ else if (val is not bool && typeof(T).IsPrimitive)
+ {
+ // numeric constants are similarly hosed
+ val = Convert.ChangeType(val, typeof(T), CultureInfo.InvariantCulture);
+ }
+
+ value = (T)val;
+ return true;
+ }
+ return false;
+ }
+ }
+
+ ///
+ /// Load the provided configuration.
+ ///
+ void LoadConfig(Provider provider);
+
+ ///
+ /// Return a dictionary representing the current configuration.
+ ///
+ Dictionary SaveConfig();
+ }
+}
diff --git a/src/BizHawk.Client.Common/config/IRestoreDefaults.cs b/src/BizHawk.Client.Common/config/IRestoreDefaults.cs
new file mode 100644
index 00000000000..39e1a49532a
--- /dev/null
+++ b/src/BizHawk.Client.Common/config/IRestoreDefaults.cs
@@ -0,0 +1,10 @@
+namespace BizHawk.Client.Common
+{
+ ///
+ /// When the implementing class also implements , this interface's method is called when the generated Restore Defaults menu item is clicked.
+ ///
+ public interface IRestoreDefaults
+ {
+ void RestoreDefaults();
+ }
+}
diff --git a/src/BizHawk.Client.Common/config/RestoreDefaultsAttribute.cs b/src/BizHawk.Client.Common/config/RestoreDefaultsAttribute.cs
index c891c6fc556..e758ae144a3 100644
--- a/src/BizHawk.Client.Common/config/RestoreDefaultsAttribute.cs
+++ b/src/BizHawk.Client.Common/config/RestoreDefaultsAttribute.cs
@@ -3,6 +3,7 @@ namespace BizHawk.Client.Common
/// Indicates which method of an is to be called when the generated Restore Defaults menu item is clicked.
/// If not present on any instance method, the menu item will do nothing. If present on multiple, the first will be called.
[AttributeUsage(AttributeTargets.Method)]
+ [Obsolete("Use interface IRestoreDefaults instead.")]
public sealed class RestoreDefaultsAttribute : Attribute
{
}
diff --git a/src/BizHawk.Client.Common/fwmanager/FirmwareManager.cs b/src/BizHawk.Client.Common/fwmanager/FirmwareManager.cs
index dd6b39efd89..943d75404aa 100644
--- a/src/BizHawk.Client.Common/fwmanager/FirmwareManager.cs
+++ b/src/BizHawk.Client.Common/fwmanager/FirmwareManager.cs
@@ -13,7 +13,6 @@ namespace BizHawk.Client.Common
{
public sealed class FirmwareManager
{
- private static readonly FirmwareID NDS_FIRMWARE = new("NDS", "firmware");
private const int DSI_NAND_LENGTH = 251658240 + 64;
public static (byte[] Patched, string ActualHash) PerformPatchInMemory(byte[] @base, in FirmwarePatchOption patchOption)
diff --git a/src/BizHawk.Client.Common/lua/CommonLibs/CommLuaLibrary.cs b/src/BizHawk.Client.Common/lua/CommonLibs/CommLuaLibrary.cs
index 81b34a90173..ef84385b389 100644
--- a/src/BizHawk.Client.Common/lua/CommonLibs/CommLuaLibrary.cs
+++ b/src/BizHawk.Client.Common/lua/CommonLibs/CommLuaLibrary.cs
@@ -1,4 +1,6 @@
+#if ENABLE_WEBSOCKETS
using System.Collections.Generic;
+#endif
using System.ComponentModel;
using System.Linq;
using System.Text;
@@ -10,7 +12,9 @@ namespace BizHawk.Client.Common
[Description("A library for communicating with other programs")]
public sealed class CommLuaLibrary : LuaLibraryBase
{
+#if ENABLE_WEBSOCKETS
private readonly IDictionary _websockets = new Dictionary();
+#endif
public CommLuaLibrary(ILuaLibraries luaLibsImpl, ApiContainer apiContainer, Action logOutputCallback)
: base(luaLibsImpl, apiContainer, logOutputCallback) {}
diff --git a/src/BizHawk.Client.Common/lua/CommonLibs/MovieLuaLibrary.cs b/src/BizHawk.Client.Common/lua/CommonLibs/MovieLuaLibrary.cs
index b2060e62ba4..bc28cfe5ef1 100644
--- a/src/BizHawk.Client.Common/lua/CommonLibs/MovieLuaLibrary.cs
+++ b/src/BizHawk.Client.Common/lua/CommonLibs/MovieLuaLibrary.cs
@@ -31,8 +31,8 @@ public string Filename()
[LuaMethod("getinput", "Returns a table of buttons pressed on a given frame of the loaded movie")]
public LuaTable GetInput(int frame, int? controller = null)
=> APIs.Movie.GetInput(frame, controller) is IReadOnlyDictionary dict
- ? _th.DictToTable(dict)
- : null;
+ ? _th.DictToTable(dict)
+ : null;
[LuaMethodExample("local stmovget = movie.getinputasmnemonic( 500 );")]
[LuaMethod("getinputasmnemonic", "Returns the input of a given frame of the loaded movie in a raw inputlog string")]
diff --git a/src/BizHawk.Client.EmuHawk/AVOut/JMDWriter.cs b/src/BizHawk.Client.EmuHawk/AVOut/JMDWriter.cs
index 864e056892d..73728172de8 100644
--- a/src/BizHawk.Client.EmuHawk/AVOut/JMDWriter.cs
+++ b/src/BizHawk.Client.EmuHawk/AVOut/JMDWriter.cs
@@ -26,7 +26,7 @@ public class JmdWriter : IVideoWriter
private const int NO_COMPRESSION = 0;
private const int BEST_COMPRESSION = 9;
private const int DEFAULT_COMPRESSION = -1;
- private const int BEST_SPEED = 1;
+ //private const int BEST_SPEED = 1;
private static CompressionLevel GetCompressionLevel(int v)
{
diff --git a/src/BizHawk.Client.EmuHawk/AVOut/SynclessRecorder.cs b/src/BizHawk.Client.EmuHawk/AVOut/SynclessRecorder.cs
index 7dc76f9606a..de8afb8733c 100644
--- a/src/BizHawk.Client.EmuHawk/AVOut/SynclessRecorder.cs
+++ b/src/BizHawk.Client.EmuHawk/AVOut/SynclessRecorder.cs
@@ -1,5 +1,7 @@
using System.IO;
+#if false
using System.Collections.Generic;
+#endif
using System.Drawing.Imaging;
using System.Text;
@@ -113,6 +115,7 @@ public void SetMetaData(string gameName, string authors, ulong lengthMs, ulong r
public string DesiredExtension() => "syncless.txt";
+#if false
///
/// splits the string into chunks of length s
///
@@ -139,6 +142,7 @@ private static List StringChunkSplit(string s, int len)
return output;
}
+#endif
private string GetAndCreatePathForFrameNum(int index)
{
diff --git a/src/BizHawk.Client.EmuHawk/CoreFeatureAnalysis.cs b/src/BizHawk.Client.EmuHawk/CoreFeatureAnalysis.cs
index 37f6120a426..5f4a237bdde 100644
--- a/src/BizHawk.Client.EmuHawk/CoreFeatureAnalysis.cs
+++ b/src/BizHawk.Client.EmuHawk/CoreFeatureAnalysis.cs
@@ -11,7 +11,7 @@
namespace BizHawk.Client.EmuHawk
{
- public partial class CoreFeatureAnalysis : ToolFormBase, IToolFormAutoConfig
+ public partial class CoreFeatureAnalysis : ToolFormBase, IToolFormAutoConfig, IConfigPersist
{
private class CoreInfo
{
@@ -93,8 +93,20 @@ public FunctionInfo(MethodInfo m, object service)
public static Icon ToolIcon
=> Properties.Resources.Logo;
- [ConfigPersist]
- private Dictionary KnownCores { get; set; }
+ private Dictionary KnownCores;
+
+ void IConfigPersist.LoadConfig(IConfigPersist.Provider provider)
+ {
+ provider.Get(nameof(KnownCores), ref KnownCores);
+ }
+
+ Dictionary IConfigPersist.SaveConfig()
+ {
+ return new()
+ {
+ [nameof(KnownCores)] = KnownCores,
+ };
+ }
// ReSharper disable once UnusedAutoPropertyAccessor.Local
[RequiredService]
diff --git a/src/BizHawk.Client.EmuHawk/CustomControls/InputRoll/InputRoll.cs b/src/BizHawk.Client.EmuHawk/CustomControls/InputRoll/InputRoll.cs
index 0034e9519c3..95ccd8ae6ba 100644
--- a/src/BizHawk.Client.EmuHawk/CustomControls/InputRoll/InputRoll.cs
+++ b/src/BizHawk.Client.EmuHawk/CustomControls/InputRoll/InputRoll.cs
@@ -1150,7 +1150,7 @@ protected override void OnMouseDown(MouseEventArgs e)
{
// do marker drag here
}
- else if (ModifierKeys is Keys.Shift && CurrentCell.Column! is { Type: ColumnType.Text } col)
+ else if (ModifierKeys is Keys.Shift && CurrentCell.Column is { Type: ColumnType.Text } col)
{
if (_selectedItems.Count is not 0)
{
diff --git a/src/BizHawk.Client.EmuHawk/tools/BasicBot/BasicBot.cs b/src/BizHawk.Client.EmuHawk/tools/BasicBot/BasicBot.cs
index 5bf3d3155ce..4bd216d4220 100644
--- a/src/BizHawk.Client.EmuHawk/tools/BasicBot/BasicBot.cs
+++ b/src/BizHawk.Client.EmuHawk/tools/BasicBot/BasicBot.cs
@@ -13,7 +13,7 @@
namespace BizHawk.Client.EmuHawk
{
- public sealed partial class BasicBot : ToolFormBase, IToolFormAutoConfig
+ public sealed partial class BasicBot : ToolFormBase, IToolFormAutoConfig, IConfigPersist
{
private static readonly FilesystemFilterSet BotFilesFSFilterSet = new(new FilesystemFilter("Bot files", new[] { "bot" }));
@@ -69,8 +69,19 @@ private string CurrentFileName
[RequiredService]
private IMemoryDomains MemoryDomains { get; set; }
- [ConfigPersist]
- public BasicBotSettings Settings { get; set; }
+ private BasicBotSettings Settings;
+
+ void IConfigPersist.LoadConfig(IConfigPersist.Provider provider)
+ {
+ provider.Get(nameof(Settings), ref Settings);
+ }
+ Dictionary IConfigPersist.SaveConfig()
+ {
+ return new()
+ {
+ [nameof(Settings)] = Settings,
+ };
+ }
public class BasicBotSettings
{
diff --git a/src/BizHawk.Client.EmuHawk/tools/CDL.cs b/src/BizHawk.Client.EmuHawk/tools/CDL.cs
index 5c12ce5572e..3c2cb505a4f 100644
--- a/src/BizHawk.Client.EmuHawk/tools/CDL.cs
+++ b/src/BizHawk.Client.EmuHawk/tools/CDL.cs
@@ -1,3 +1,4 @@
+using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
@@ -17,7 +18,7 @@
// TODO - context menu should have copy option too
namespace BizHawk.Client.EmuHawk
{
- public partial class CDL : ToolFormBase, IToolFormAutoConfig
+ public partial class CDL : ToolFormBase, IToolFormAutoConfig, IConfigPersist
{
private static readonly FilesystemFilterSet CDLFilesFSFilterSet = new(new FilesystemFilter("Code Data Logger Files", new[] { "cdl" }));
@@ -26,21 +27,35 @@ public static Icon ToolIcon
private RecentFiles _recentFld = new RecentFiles();
- [ConfigPersist]
private RecentFiles _recent
{
get => _recentFld;
set => _recentFld = value;
}
- [ConfigPersist]
- private bool CDLAutoSave { get; set; } = true;
+ private bool CDLAutoSave = true;
- [ConfigPersist]
- private bool CDLAutoStart { get; set; } = true;
+ private bool CDLAutoStart = true;
- [ConfigPersist]
- private bool CDLAutoResume { get; set; } = true;
+ private bool CDLAutoResume = true;
+
+ void IConfigPersist.LoadConfig(IConfigPersist.Provider provider)
+ {
+ provider.Get(nameof(_recentFld), ref _recentFld);
+ provider.Get(nameof(CDLAutoSave), ref CDLAutoSave);
+ provider.Get(nameof(CDLAutoStart), ref CDLAutoStart);
+ provider.Get(nameof(CDLAutoResume), ref CDLAutoResume);
+ }
+ Dictionary IConfigPersist.SaveConfig()
+ {
+ return new()
+ {
+ [nameof(_recent)] = _recent,
+ [nameof(CDLAutoSave)] = CDLAutoSave,
+ [nameof(CDLAutoStart)] = CDLAutoStart,
+ [nameof(CDLAutoResume)] = CDLAutoResume,
+ };
+ }
private void SetCurrentFilename(string fname)
{
diff --git a/src/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs b/src/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs
index 3c8447ea799..ed187cb5215 100644
--- a/src/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs
+++ b/src/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs
@@ -13,7 +13,7 @@
namespace BizHawk.Client.EmuHawk
{
- public partial class Cheats : ToolFormBase, IToolFormAutoConfig
+ public partial class Cheats : ToolFormBase, IToolFormAutoConfig, IRestoreDefaults, IConfigPersist
{
private const string NameColumn = "NamesColumn";
private const string AddressColumn = "AddressColumn";
@@ -78,8 +78,19 @@ public Cheats()
[RequiredService]
private IMemoryDomains Core { get; set; }
- [ConfigPersist]
- public CheatsSettings Settings { get; set; }
+ public CheatsSettings Settings;
+
+ void IConfigPersist.LoadConfig(IConfigPersist.Provider provider)
+ {
+ provider.Get(nameof(Settings), ref Settings);
+ }
+ Dictionary IConfigPersist.SaveConfig()
+ {
+ return new()
+ {
+ [nameof(Settings)] = Settings,
+ };
+ }
public override void Restart()
{
@@ -513,8 +524,7 @@ private void AutoSaveCheatsMenuItem_Click(object sender, EventArgs e)
private void CheatsOnOffLoadMenuItem_Click(object sender, EventArgs e)
=> Config.Cheats.DisableOnLoad = !Config.Cheats.DisableOnLoad;
- [RestoreDefaults]
- private void RestoreDefaults()
+ void IRestoreDefaults.RestoreDefaults()
{
Settings = new CheatsSettings();
diff --git a/src/BizHawk.Client.EmuHawk/tools/Debugger/AddBreakpointDialog.cs b/src/BizHawk.Client.EmuHawk/tools/Debugger/AddBreakpointDialog.cs
index 834922c386b..cfe6d4bd814 100644
--- a/src/BizHawk.Client.EmuHawk/tools/Debugger/AddBreakpointDialog.cs
+++ b/src/BizHawk.Client.EmuHawk/tools/Debugger/AddBreakpointDialog.cs
@@ -9,9 +9,21 @@ public partial class AddBreakpointDialog : Form
public AddBreakpointDialog(BreakpointOperation op)
{
InitializeComponent();
- Operation = op;
AddressMaskBox.SetHexProperties(0xFFFFFFFF);
AddressMask = 0xFFFFFFFF;
+
+ switch (op)
+ {
+ case BreakpointOperation.Add:
+ Text = "Add Breakpoint";
+ break;
+ case BreakpointOperation.Duplicate:
+ Text = "Duplicate Breakpoint";
+ break;
+ case BreakpointOperation.Edit:
+ Text = "Edit Breakpoint";
+ break;
+ }
}
public AddBreakpointDialog(BreakpointOperation op, uint address, uint mask, MemoryCallbackType type)
@@ -23,31 +35,6 @@ public AddBreakpointDialog(BreakpointOperation op, uint address, uint mask, Memo
BreakType = type;
}
- private BreakpointOperation _operation;
-
- private BreakpointOperation Operation
- {
- get => _operation;
-
- set
- {
- switch (value)
- {
- case BreakpointOperation.Add:
- Text = "Add Breakpoint";
- break;
- case BreakpointOperation.Duplicate:
- Text = "Duplicate Breakpoint";
- break;
- case BreakpointOperation.Edit:
- Text = "Edit Breakpoint";
- break;
- }
-
- _operation = value;
- }
- }
-
public void DisableExecuteOption()
{
if (ExecuteRadio.Checked)
diff --git a/src/BizHawk.Client.EmuHawk/tools/ExternalToolManager.cs b/src/BizHawk.Client.EmuHawk/tools/ExternalToolManager.cs
index 1c2d494ef4f..d689465291c 100644
--- a/src/BizHawk.Client.EmuHawk/tools/ExternalToolManager.cs
+++ b/src/BizHawk.Client.EmuHawk/tools/ExternalToolManager.cs
@@ -17,7 +17,9 @@ public sealed class ExternalToolManager
{
public struct MenuItemInfo
{
+#if !DEBUG
private readonly string _asmChecksum;
+#endif
private readonly string _entryPointTypeName;
@@ -33,12 +35,12 @@ public MenuItemInfo(
string asmFilename,
string entryPointTypeName)
{
- _asmChecksum = asmChecksum;
_entryPointTypeName = entryPointTypeName;
_extToolMan = extToolMan;
#if DEBUG
_skipExtToolWarning = true;
#else
+ _asmChecksum = asmChecksum;
_skipExtToolWarning = _extToolMan._config.TrustedExtTools.TryGetValue(asmFilename, out var s) && s == _asmChecksum;
#endif
AsmFilename = asmFilename;
diff --git a/src/BizHawk.Client.EmuHawk/tools/GB/GBGPUView.cs b/src/BizHawk.Client.EmuHawk/tools/GB/GBGPUView.cs
index 03ecbb6b622..98e7c2c61a2 100644
--- a/src/BizHawk.Client.EmuHawk/tools/GB/GBGPUView.cs
+++ b/src/BizHawk.Client.EmuHawk/tools/GB/GBGPUView.cs
@@ -1,3 +1,4 @@
+using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Text;
@@ -10,7 +11,7 @@
namespace BizHawk.Client.EmuHawk
{
- public partial class GbGpuView : ToolFormBase, IToolFormAutoConfig
+ public partial class GbGpuView : ToolFormBase, IToolFormAutoConfig, IConfigPersist
{
public static Icon ToolIcon
=> Properties.Resources.GambatteIcon;
@@ -58,7 +59,6 @@ private IntPtr ComputeTilesPalFromMemory(IGPUMemoryAreas m)
private Color _spriteback;
- [ConfigPersist]
public Color Spriteback
{
get => _spriteback;
@@ -70,6 +70,19 @@ public Color Spriteback
}
}
+ void IConfigPersist.LoadConfig(IConfigPersist.Provider provider)
+ {
+ Color outValue = default;
+ if (provider.Get(nameof(Spriteback), ref outValue)) Spriteback = outValue;
+ }
+ Dictionary IConfigPersist.SaveConfig()
+ {
+ return new()
+ {
+ [nameof(Spriteback)] = Spriteback,
+ };
+ }
+
protected override string WindowTitleStatic => "GPU Viewer";
public GbGpuView()
diff --git a/src/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.cs b/src/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.cs
index 1e32aae52f6..508943bd684 100644
--- a/src/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.cs
+++ b/src/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.cs
@@ -20,7 +20,7 @@
namespace BizHawk.Client.EmuHawk
{
// int to long TODO: 32 bit domains have more digits than the hex editor can account for and the address covers up the 0 column
- public partial class HexEditor : ToolFormBase, IToolFormAutoConfig
+ public partial class HexEditor : ToolFormBase, IToolFormAutoConfig, IConfigPersist
{
private sealed class N64MatrixDisplayDialog : Form
{
@@ -121,17 +121,13 @@ private bool AreAnyHighlighted
private HexFind _hexFind;
private string _lastRom = "";
- [ConfigPersist]
- private string LastDomain { get; set; }
+ private string LastDomain;
- [ConfigPersist]
- private bool BigEndian { get; set; }
+ private bool BigEndian;
- [ConfigPersist]
- private int DataSize { get; set; }
+ private int DataSize;
- [ConfigPersist]
- private RecentFiles RecentTables { get; set; }
+ private RecentFiles RecentTables;
internal class ColorConfig
{
@@ -143,8 +139,27 @@ internal class ColorConfig
public Color HighlightFreeze { get; set; } = Color.Violet;
}
- [ConfigPersist]
- internal ColorConfig Colors { get; set; } = new ColorConfig();
+ internal ColorConfig Colors = new ColorConfig();
+
+ void IConfigPersist.LoadConfig(IConfigPersist.Provider provider)
+ {
+ provider.Get(nameof(LastDomain), ref LastDomain);
+ provider.Get(nameof(BigEndian), ref BigEndian);
+ provider.Get(nameof(DataSize), ref DataSize);
+ provider.Get(nameof(RecentTables), ref RecentTables);
+ provider.Get(nameof(Colors), ref Colors);
+ }
+ Dictionary IConfigPersist.SaveConfig()
+ {
+ return new()
+ {
+ [nameof(LastDomain)] = LastDomain,
+ [nameof(BigEndian)] = BigEndian,
+ [nameof(DataSize)] = DataSize,
+ [nameof(RecentTables)] = RecentTables,
+ [nameof(Colors)] = Colors,
+ };
+ }
private WatchSize WatchSize => (WatchSize)DataSize;
diff --git a/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs b/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs
index 25892fd6061..4bf686b3cf2 100644
--- a/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs
+++ b/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs
@@ -18,7 +18,7 @@
namespace BizHawk.Client.EmuHawk
{
- public partial class LuaConsole : ToolFormBase, IToolFormAutoConfig
+ public partial class LuaConsole : ToolFormBase, IToolFormAutoConfig, IRestoreDefaults, IConfigPersist
{
private const string IconColumnName = "Icon";
private const string ScriptColumnName = "Script";
@@ -74,8 +74,19 @@ public LuaConsoleSettings()
public bool WarnedOnceOnOverwrite { get; set; }
}
- [ConfigPersist]
- public LuaConsoleSettings Settings { get; set; }
+ public LuaConsoleSettings Settings;
+
+ void IConfigPersist.LoadConfig(IConfigPersist.Provider provider)
+ {
+ provider.Get(nameof(Settings), ref Settings);
+ }
+ Dictionary IConfigPersist.SaveConfig()
+ {
+ return new()
+ {
+ [nameof(Settings)] = Settings,
+ };
+ }
protected override string WindowTitleStatic => "Lua Console";
@@ -1532,8 +1543,7 @@ private void RefreshLuaScript(LuaFile file)
ToggleLuaScript(file);
}
- [RestoreDefaults]
- private void RestoreDefaults()
+ void IRestoreDefaults.RestoreDefaults()
{
Settings = new LuaConsoleSettings();
LuaListView.AllColumns.Clear();
diff --git a/src/BizHawk.Client.EmuHawk/tools/Lua/LuaLibraries.cs b/src/BizHawk.Client.EmuHawk/tools/Lua/LuaLibraries.cs
index c466bd7996f..fa9fb311d93 100644
--- a/src/BizHawk.Client.EmuHawk/tools/Lua/LuaLibraries.cs
+++ b/src/BizHawk.Client.EmuHawk/tools/Lua/LuaLibraries.cs
@@ -3,7 +3,6 @@
using System.IO;
using System.Linq;
using System.Reflection;
-using System.Threading;
using NLua;
using NLua.Native;
@@ -60,7 +59,6 @@ void EnumerateLuaFunctions(string name, Type type, LuaLibraryBase instance)
_displayManager = displayManager;
_inputManager = inputManager;
_mainForm = mainForm;
- LuaWait = new AutoResetEvent(false);
PathEntries = config.PathEntries;
RegisteredFunctions = registeredFuncList;
ScriptList = scriptList;
@@ -153,8 +151,6 @@ void EnumerateLuaFunctions(string name, Type type, LuaLibraryBase instance)
private readonly DisplayManagerBase _displayManager;
- private GuiApi GuiAPI => (GuiApi)_apiContainer.Gui;
-
private readonly InputManager _inputManager;
private readonly MainForm _mainForm;
@@ -182,8 +178,6 @@ void EnumerateLuaFunctions(string name, Type type, LuaLibraryBase instance)
private readonly IDictionary Libraries = new Dictionary();
- private EventWaitHandle LuaWait;
-
public PathEntryCollection PathEntries { get; private set; }
public LuaFileList ScriptList { get; }
diff --git a/src/BizHawk.Client.EmuHawk/tools/NES/NESNameTableViewer.cs b/src/BizHawk.Client.EmuHawk/tools/NES/NESNameTableViewer.cs
index f9e03ec0e15..0a5a598ac1a 100644
--- a/src/BizHawk.Client.EmuHawk/tools/NES/NESNameTableViewer.cs
+++ b/src/BizHawk.Client.EmuHawk/tools/NES/NESNameTableViewer.cs
@@ -1,3 +1,4 @@
+using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;
@@ -8,7 +9,7 @@
namespace BizHawk.Client.EmuHawk
{
- public partial class NESNameTableViewer : ToolFormBase, IToolFormAutoConfig
+ public partial class NESNameTableViewer : ToolFormBase, IToolFormAutoConfig, IConfigPersist
{
// TODO:
// Show Scroll Lines + UI Toggle
@@ -28,13 +29,25 @@ private INESPPUViewable _ppu
private IEmulator _emu
=> _core!;
- [ConfigPersist]
private int RefreshRateConfig
{
get => RefreshRate.Value;
set => RefreshRate.Value = value;
}
+ void IConfigPersist.LoadConfig(IConfigPersist.Provider provider)
+ {
+ int outValue = default;
+ if (provider.Get(nameof(RefreshRateConfig), ref outValue)) RefreshRateConfig = outValue;
+ }
+ Dictionary IConfigPersist.SaveConfig()
+ {
+ return new()
+ {
+ [nameof(RefreshRateConfig)] = RefreshRateConfig,
+ };
+ }
+
private int _scanline;
protected override string WindowTitleStatic => "Nametable Viewer";
diff --git a/src/BizHawk.Client.EmuHawk/tools/NES/NESPPU.cs b/src/BizHawk.Client.EmuHawk/tools/NES/NESPPU.cs
index 543589ae794..062ca9d452e 100644
--- a/src/BizHawk.Client.EmuHawk/tools/NES/NESPPU.cs
+++ b/src/BizHawk.Client.EmuHawk/tools/NES/NESPPU.cs
@@ -1,3 +1,4 @@
+using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;
@@ -8,7 +9,7 @@
namespace BizHawk.Client.EmuHawk
{
- public partial class NesPPU : ToolFormBase, IToolFormAutoConfig
+ public partial class NesPPU : ToolFormBase, IToolFormAutoConfig, IConfigPersist
{
// TODO:
// If 8/16 sprite mode, mouse over should put 32x64 version of sprite
@@ -39,7 +40,6 @@ private INESPPUViewable _ppu
private IEmulator _emu
=> _core!;
- [ConfigPersist]
private int RefreshRateConfig
{
get => RefreshRate.Value;
@@ -47,13 +47,28 @@ private int RefreshRateConfig
}
private bool _chrRomView;
- [ConfigPersist]
private bool ChrRomView
{
get => _chrRomView;
set { _chrRomView = value; CalculateFormSize(); }
}
+ void IConfigPersist.LoadConfig(IConfigPersist.Provider provider)
+ {
+ int outValue = default;
+ if (provider.Get(nameof(RefreshRateConfig), ref outValue)) RefreshRateConfig = outValue;
+ bool outValue2 = default;
+ if (provider.Get(nameof(ChrRomView), ref outValue2)) ChrRomView = outValue2;
+ }
+ Dictionary IConfigPersist.SaveConfig()
+ {
+ return new()
+ {
+ [nameof(RefreshRateConfig)] = RefreshRateConfig,
+ [nameof(ChrRomView)] = ChrRomView,
+ };
+ }
+
protected override string WindowTitleStatic => "PPU Viewer";
public NesPPU()
diff --git a/src/BizHawk.Client.EmuHawk/tools/PCE/PCEBGViewer.cs b/src/BizHawk.Client.EmuHawk/tools/PCE/PCEBGViewer.cs
index c21bf8530e9..b1dd99bc008 100644
--- a/src/BizHawk.Client.EmuHawk/tools/PCE/PCEBGViewer.cs
+++ b/src/BizHawk.Client.EmuHawk/tools/PCE/PCEBGViewer.cs
@@ -1,3 +1,4 @@
+using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;
@@ -9,7 +10,7 @@
namespace BizHawk.Client.EmuHawk
{
[SpecializedTool("BG Viewer")]
- public partial class PceBgViewer : ToolFormBase, IToolFormAutoConfig
+ public partial class PceBgViewer : ToolFormBase, IToolFormAutoConfig, IConfigPersist
{
public static Icon ToolIcon
=> Properties.Resources.PceIcon;
@@ -19,14 +20,25 @@ public static Icon ToolIcon
[RequiredService]
public IEmulator Emulator { get; private set; }
- [ConfigPersist]
- // ReSharper disable once UnusedMember.Local
private int RefreshRateConfig
{
get => RefreshRate.Value;
set => RefreshRate.Value = Math.Max(Math.Min(value, RefreshRate.Maximum), RefreshRate.Minimum);
}
+ void IConfigPersist.LoadConfig(IConfigPersist.Provider provider)
+ {
+ int outValue = default;
+ if (provider.Get(nameof(RefreshRateConfig), ref outValue)) RefreshRateConfig = outValue;
+ }
+ Dictionary IConfigPersist.SaveConfig()
+ {
+ return new()
+ {
+ [nameof(RefreshRateConfig)] = RefreshRateConfig,
+ };
+ }
+
private int _vdcType;
protected override string WindowTitleStatic => "Background Viewer";
diff --git a/src/BizHawk.Client.EmuHawk/tools/SNES/SNESGraphicsDebugger.cs b/src/BizHawk.Client.EmuHawk/tools/SNES/SNESGraphicsDebugger.cs
index 975972f0f7a..cacf800f8ed 100644
--- a/src/BizHawk.Client.EmuHawk/tools/SNES/SNESGraphicsDebugger.cs
+++ b/src/BizHawk.Client.EmuHawk/tools/SNES/SNESGraphicsDebugger.cs
@@ -36,22 +36,36 @@
namespace BizHawk.Client.EmuHawk
{
- public unsafe partial class SNESGraphicsDebugger : ToolFormBase, IToolFormAutoConfig
+ public unsafe partial class SNESGraphicsDebugger : ToolFormBase, IToolFormAutoConfig, IConfigPersist
{
private readonly List displayTypeItems = new List();
[RequiredService]
private IBSNESForGfxDebugger Emulator { get; set; }
- [ConfigPersist]
public bool UseUserBackdropColor
{
get => checkBackdropColor.Checked;
set => checkBackdropColor.Checked = value;
}
- [ConfigPersist]
public int UserBackdropColor { get; set; }
+ void IConfigPersist.LoadConfig(IConfigPersist.Provider provider)
+ {
+ bool outValue = default;
+ if (provider.Get(nameof(UseUserBackdropColor), ref outValue)) UseUserBackdropColor = outValue;
+ int outValue2 = default;
+ if (provider.Get(nameof(UserBackdropColor), ref outValue2)) UserBackdropColor = outValue2;
+ }
+ Dictionary IConfigPersist.SaveConfig()
+ {
+ return new()
+ {
+ [nameof(UseUserBackdropColor)] = UseUserBackdropColor,
+ [nameof(UserBackdropColor)] = UserBackdropColor,
+ };
+ }
+
protected override string WindowTitleStatic => "Graphics Debugger";
public SNESGraphicsDebugger()
diff --git a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.MenuItems.cs b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.MenuItems.cs
index 2e78e58b4a0..ec692a6858b 100644
--- a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.MenuItems.cs
+++ b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.MenuItems.cs
@@ -12,7 +12,7 @@
namespace BizHawk.Client.EmuHawk
{
- public partial class TAStudio
+ public partial class TAStudio : IRestoreDefaults
{
private static readonly FilesystemFilterSet MoviesFSFilterSet = new(
new FilesystemFilter("All Available Files", MovieService.MovieExtensions.Reverse().ToArray()),
@@ -1255,9 +1255,7 @@ void UpdateAggregateCheckState()
});
}
- // ReSharper disable once UnusedMember.Local
- [RestoreDefaults]
- private void RestoreDefaults()
+ void IRestoreDefaults.RestoreDefaults()
{
SetUpColumns();
SetUpToolStripColumns();
diff --git a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs
index 07712656610..2601700cf08 100644
--- a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs
+++ b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs
@@ -13,7 +13,7 @@
namespace BizHawk.Client.EmuHawk
{
- public partial class TAStudio : ToolFormBase, IToolFormAutoConfig, IControlMainform
+ public partial class TAStudio : ToolFormBase, IToolFormAutoConfig, IControlMainform, IConfigPersist
{
public static readonly FilesystemFilterSet TAStudioProjectsFSFilterSet = new(FilesystemFilter.TAStudioProjects);
@@ -56,13 +56,25 @@ public static Icon ToolIcon
private int _seekingTo = -1;
- [ConfigPersist]
- public TAStudioSettings Settings { get; set; } = new TAStudioSettings();
+ public TAStudioSettings Settings = new TAStudioSettings();
public TAStudioPalette Palette => Settings.Palette;
- [ConfigPersist]
- public Font TasViewFont { get; set; } = new Font("Arial", 8.25F, FontStyle.Bold, GraphicsUnit.Point, 0);
+ public Font TasViewFont = new Font("Arial", 8.25F, FontStyle.Bold, GraphicsUnit.Point, 0);
+
+ void IConfigPersist.LoadConfig(IConfigPersist.Provider provider)
+ {
+ provider.Get(nameof(Settings), ref Settings);
+ provider.Get(nameof(TasViewFont), ref TasViewFont);
+ }
+ Dictionary IConfigPersist.SaveConfig()
+ {
+ return new()
+ {
+ [nameof(Settings)] = Settings,
+ [nameof(TasViewFont)] = TasViewFont,
+ };
+ }
///
/// This is meant to be used by Lua.
@@ -497,23 +509,6 @@ public IMovieController GetBranchInput(string branchId, int frame)
return controller;
}
- private int? FirstNonEmptySelectedFrame
- {
- get
- {
- var empty = Bk2LogEntryGenerator.EmptyEntry(MovieSession.MovieController);
- foreach (var row in TasView.SelectedRows)
- {
- if (CurrentTasMovie[row].LogEntry != empty)
- {
- return row;
- }
- }
-
- return null;
- }
- }
-
private ITasMovie ConvertCurrentMovieToTasproj()
{
var tasMovie = MovieSession.Movie.ToTasMovie();
@@ -972,6 +967,7 @@ protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
return base.ProcessCmdKey(ref msg, keyData);
}
+#if false
private bool AutoAdjustInput()
{
var lagLog = CurrentTasMovie[Emulator.Frame - 1]; // Minus one because get frame is +1;
@@ -1024,6 +1020,7 @@ private bool AutoAdjustInput()
return false;
}
+#endif
private void MainVerticalSplit_SplitterMoved(object sender, SplitterEventArgs e)
{
diff --git a/src/BizHawk.Client.EmuHawk/tools/TI83/TI83KeyPad.cs b/src/BizHawk.Client.EmuHawk/tools/TI83/TI83KeyPad.cs
index 7facceb6e13..a613574473b 100644
--- a/src/BizHawk.Client.EmuHawk/tools/TI83/TI83KeyPad.cs
+++ b/src/BizHawk.Client.EmuHawk/tools/TI83/TI83KeyPad.cs
@@ -1,3 +1,4 @@
+using System.Collections.Generic;
using System.Drawing;
using BizHawk.Client.Common;
@@ -8,7 +9,7 @@
namespace BizHawk.Client.EmuHawk
{
- public sealed partial class TI83KeyPad : ToolFormBase, IToolFormAutoConfig
+ public sealed partial class TI83KeyPad : ToolFormBase, IToolFormAutoConfig, IConfigPersist
{
public static Icon ToolIcon
=> Resources.CalculateIcon;
@@ -30,8 +31,21 @@ public TI83KeyPad()
if (OSTailoredCode.IsUnixHost) MinimumSize = (MaximumSize += new Size(48, 32)); // also updates current size
}
- [ConfigPersist]
- public bool TI83ToolTips { get; set; } = true;
+ public bool TI83ToolTips = true;
+
+ void IConfigPersist.LoadConfig(IConfigPersist.Provider provider)
+ {
+ bool outValue = default;
+ if (provider.Get(nameof(TI83ToolTips), ref outValue)) TI83ToolTips = outValue;
+ }
+ Dictionary IConfigPersist.SaveConfig()
+ {
+ return new()
+ {
+ [nameof(TI83ToolTips)] = TI83ToolTips,
+ };
+ }
+
private void TI83KeyPad_Load(object sender, EventArgs e)
{
diff --git a/src/BizHawk.Client.EmuHawk/tools/ToolManager.cs b/src/BizHawk.Client.EmuHawk/tools/ToolManager.cs
index bec31d413cb..f26f0211bb2 100644
--- a/src/BizHawk.Client.EmuHawk/tools/ToolManager.cs
+++ b/src/BizHawk.Client.EmuHawk/tools/ToolManager.cs
@@ -1,10 +1,8 @@
using System.Collections.Generic;
using System.Drawing;
-using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
-using System.ComponentModel;
using System.Windows.Forms;
using BizHawk.Client.Common;
@@ -139,9 +137,10 @@ public T Load(bool focus = true, string toolPath = "")
AttachSettingHooks(autoConfigTool, _config.CommonToolSettings.GetValueOrPutNew(toolTypeName));
}
// custom settings
- if (HasCustomConfig(newTool))
+ if (newTool is IConfigPersist persister)
{
- InstallCustomConfig(newTool, _config.CustomToolSettings.GetValueOrPutNew(toolTypeName));
+ persister.LoadConfig(new(_config.CustomToolSettings.GetValueOrPutNew(toolTypeName)));
+ ((Form)(IToolForm)newTool).FormClosing += (o, e) => _config.CustomToolSettings[toolTypeName] = persister.SaveConfig();
}
newTool.Restart();
@@ -183,9 +182,10 @@ public IExternalToolForm LoadExternalToolForm(string toolPath, string customForm
AttachSettingHooks(autoConfigTool, _config.CommonToolSettings.GetValueOrPutNew(customFormTypeName));
}
// custom settings
- if (HasCustomConfig(newTool))
+ if (newTool is IConfigPersist persister)
{
- InstallCustomConfig(newTool, _config.CustomToolSettings.GetValueOrPutNew(customFormTypeName));
+ persister.LoadConfig(new(_config.CustomToolSettings.GetValueOrPutNew(customFormTypeName)));
+ ((Form)(IToolForm)newTool).FormClosing += (o, e) => _config.CustomToolSettings[customFormTypeName] = persister.SaveConfig();
}
newTool.Restart();
@@ -378,60 +378,18 @@ private void AttachSettingHooks(IToolFormAutoConfig tool, ToolDialogSettings set
RefreshSettings(form, dest, settings, idx);
form.Size = oldSize;
- form.GetType().GetMethodsWithAttrib(typeof(RestoreDefaultsAttribute))
- .FirstOrDefault()?.Invoke(form, Array.Empty