diff --git a/src/BizHawk.Client.Common/movie/import/DsmImport.cs b/src/BizHawk.Client.Common/movie/import/DsmImport.cs index a409bd32f5..3f8d233414 100644 --- a/src/BizHawk.Client.Common/movie/import/DsmImport.cs +++ b/src/BizHawk.Client.Common/movie/import/DsmImport.cs @@ -16,7 +16,8 @@ namespace BizHawk.Client.Common BoolButtons = { "Up", "Down", "Left", "Right", "Start", "Select", "B", "A", "Y", "X", "L", "R", "LidOpen", "LidClose", "Touch", "Power" }, }.AddXYPair("Touch {0}", AxisPairOrientation.RightAndUp, 0.RangeTo(255), 128, 0.RangeTo(191), 96) //TODO verify direction against hardware .AddAxis("Mic Input", 0.RangeTo(2047), 0) - .AddAxis("GBA Light Sensor", 0.RangeTo(10), 0); + .AddAxis("GBA Light Sensor", 0.RangeTo(10), 0) + .MakeImmutable(); protected override void RunImport() { diff --git a/src/BizHawk.Client.Common/movie/import/Fm2Import.cs b/src/BizHawk.Client.Common/movie/import/Fm2Import.cs index 0dcc3faf51..bd7c0bc759 100644 --- a/src/BizHawk.Client.Common/movie/import/Fm2Import.cs +++ b/src/BizHawk.Client.Common/movie/import/Fm2Import.cs @@ -269,6 +269,7 @@ namespace BizHawk.Client.Common //TODO FDS def.BoolButtons.Add("Reset"); def.BoolButtons.Add("Power"); + def.MakeImmutable(); return deck; } } diff --git a/src/BizHawk.Client.Common/movie/import/VbmImport.cs b/src/BizHawk.Client.Common/movie/import/VbmImport.cs index c407c9fd34..7a3d51d942 100644 --- a/src/BizHawk.Client.Common/movie/import/VbmImport.cs +++ b/src/BizHawk.Client.Common/movie/import/VbmImport.cs @@ -299,7 +299,7 @@ namespace BizHawk.Client.Common.movie.import => new(new ControllerDefinition("Gameboy Controller") { BoolButtons = { "Up", "Down", "Left", "Right", "Start", "Select", "B", "A", "Power" } - }); + }.MakeImmutable()); private static SimpleController GbaController() => new(MGBAHawk.GBAController); diff --git a/src/BizHawk.Client.Common/movie/import/YmvImport.cs b/src/BizHawk.Client.Common/movie/import/YmvImport.cs index f69a2f8f86..e809999131 100644 --- a/src/BizHawk.Client.Common/movie/import/YmvImport.cs +++ b/src/BizHawk.Client.Common/movie/import/YmvImport.cs @@ -106,7 +106,7 @@ namespace BizHawk.Client.Common.movie.import { "Reset", "Power", "Previous Disk", "Next Disk", "P1 Left", "P1 Right", "P1 Up", "P1 Down", "P1 Start", "P1 A", "P1 B", "P1 C", "P1 X", "P1 Y", "P1 Z", "P1 L", "P1 R" } - }); + }.MakeImmutable()); // Split up the sections of the frame. var sections = line.Split(new[] { "|" }, StringSplitOptions.RemoveEmptyEntries); diff --git a/src/BizHawk.Client.EmuHawk/MainForm.cs b/src/BizHawk.Client.EmuHawk/MainForm.cs index 596a58f8f1..89f2fa1783 100644 --- a/src/BizHawk.Client.EmuHawk/MainForm.cs +++ b/src/BizHawk.Client.EmuHawk/MainForm.cs @@ -2104,7 +2104,7 @@ namespace BizHawk.Client.EmuHawk Controller controls = new(new ControllerDefinition("Emulator Frontend Controls") { BoolButtons = Config.HotkeyBindings.Select(static x => x.DisplayName).ToList(), - }); + }.MakeImmutable()); foreach (var b in Config.HotkeyBindings) { diff --git a/src/BizHawk.Client.EmuHawk/config/ControllerConfig.cs b/src/BizHawk.Client.EmuHawk/config/ControllerConfig.cs index 39501dfecc..9f5d9ec68a 100644 --- a/src/BizHawk.Client.EmuHawk/config/ControllerConfig.cs +++ b/src/BizHawk.Client.EmuHawk/config/ControllerConfig.cs @@ -101,8 +101,8 @@ namespace BizHawk.Client.EmuHawk private void LoadToPanel( Control dest, string controllerName, - IReadOnlyCollection controllerButtons, - Dictionary categoryLabels, + IList controllerButtons, + IDictionary categoryLabels, IDictionary> settingsBlock, TBindValue defaultValue, PanelCreator createPanel diff --git a/src/BizHawk.Client.EmuHawk/tools/Macros/MovieZone.cs b/src/BizHawk.Client.EmuHawk/tools/Macros/MovieZone.cs index ef7d27ac1d..96d2df3b58 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Macros/MovieZone.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Macros/MovieZone.cs @@ -85,7 +85,7 @@ namespace BizHawk.Client.EmuHawk } } - _controller = _movieSession.GenerateMovieController(d); + _controller = _movieSession.GenerateMovieController(d.MakeImmutable()); } public string Name { get; set; } @@ -118,7 +118,7 @@ namespace BizHawk.Client.EmuHawk } } - var newController = _movieSession.GenerateMovieController(d); + var newController = _movieSession.GenerateMovieController(d.MakeImmutable()); var logGenerator = _movieSession.Movie.LogGeneratorInstance(newController); logGenerator.GenerateLogEntry(); // Reference and create all buttons. diff --git a/src/BizHawk.Emulation.Common/Base Implementations/Axes/AxisDict.cs b/src/BizHawk.Emulation.Common/Base Implementations/Axes/AxisDict.cs index 88d3577762..325bebe51b 100644 --- a/src/BizHawk.Emulation.Common/Base Implementations/Axes/AxisDict.cs +++ b/src/BizHawk.Emulation.Common/Base Implementations/Axes/AxisDict.cs @@ -1,13 +1,17 @@ +using System; using System.Collections; using System.Collections.Generic; +using System.Collections.Immutable; namespace BizHawk.Emulation.Common { public sealed class AxisDict : IReadOnlyDictionary { - private readonly IList _keys = new List(); + private IList _keys = new List(); - private readonly IDictionary _specs = new Dictionary(); + private bool _mutable = true; + + private IDictionary _specs = new Dictionary(); public int Count => _keys.Count; @@ -22,11 +26,16 @@ namespace BizHawk.Emulation.Common public AxisSpec this[string index] { get => _specs[index]; - set => _specs[index] = value; + set + { + AssertMutable(); + _specs[index] = value; + } } public void Add(string key, AxisSpec value) { + AssertMutable(); _keys.Add(key); _specs.Add(key, value); if (value.Constraint != null) HasContraints = true; @@ -34,8 +43,15 @@ namespace BizHawk.Emulation.Common public void Add(KeyValuePair item) => Add(item.Key, item.Value); + private void AssertMutable() + { + const string ERR_MSG = "this " + nameof(AxisDict) + " has been built and sealed and may not be mutated"; + if (!_mutable) throw new InvalidOperationException(ERR_MSG); + } + public void Clear() { + AssertMutable(); _keys.Clear(); _specs.Clear(); HasContraints = false; @@ -49,6 +65,13 @@ namespace BizHawk.Emulation.Common public int IndexOf(string key) => _keys.IndexOf(key); + public void MakeImmutable() + { + _mutable = false; + _keys = _keys.ToImmutableList(); + _specs = _specs.ToImmutableDictionary(); + } + public AxisSpec SpecAtIndex(int index) => this[_keys[index]]; public bool TryGetValue(string key, out AxisSpec value) => _specs.TryGetValue(key, out value); diff --git a/src/BizHawk.Emulation.Common/Base Implementations/ControllerDefinition.cs b/src/BizHawk.Emulation.Common/Base Implementations/ControllerDefinition.cs index 9271d369ff..9c08bcab66 100644 --- a/src/BizHawk.Emulation.Common/Base Implementations/ControllerDefinition.cs +++ b/src/BizHawk.Emulation.Common/Base Implementations/ControllerDefinition.cs @@ -1,10 +1,13 @@ #nullable disable +using System; using System.Collections.Generic; +using System.Collections.Immutable; using System.Linq; using System.Text.RegularExpressions; using BizHawk.Common; +using BizHawk.Common.CollectionExtensions; namespace BizHawk.Emulation.Common { @@ -14,6 +17,10 @@ namespace BizHawk.Emulation.Common /// public class ControllerDefinition { + private IList _buttons = new List(); + + private bool _mutable = true; + public readonly string Name; public ControllerDefinition(string name) @@ -26,22 +33,31 @@ namespace BizHawk.Emulation.Common foreach (var kvp in copyFrom.Axes) Axes.Add(kvp); HapticsChannels.AddRange(copyFrom.HapticsChannels); CategoryLabels = copyFrom.CategoryLabels; + MakeImmutable(); } /// /// Gets or sets a list of all button types that have a boolean (on/off) value /// - public List BoolButtons { get; set; } = new List(); + public IList BoolButtons + { + get => _buttons; + set + { + AssertMutable(); + _buttons = value; + } + } public readonly AxisDict Axes = new AxisDict(); /// Contains names of virtual haptic feedback channels, e.g. { "P1 Mono" }, { "P2 Left", "P2 Right" }. - public List HapticsChannels { get; } = new(); + public IList HapticsChannels { get; private set; } = new List(); /// /// Gets the category labels. These labels provide a means of categorizing controls in various controller display and config screens /// - public Dictionary CategoryLabels { get; } = new Dictionary(); + public IDictionary CategoryLabels { get; private set; } = new Dictionary(); public void ApplyAxisConstraints(string constraintClass, IDictionary axes) { @@ -88,6 +104,23 @@ namespace BizHawk.Emulation.Common } } + private void AssertMutable() + { + const string ERR_MSG = "this " + nameof(ControllerDefinition) + " has been built and sealed, and may not be mutated"; + if (!_mutable) throw new InvalidOperationException(ERR_MSG); + } + + /// permanently disables the ability to mutate this instance; returns this reference + public ControllerDefinition MakeImmutable() + { + BoolButtons = BoolButtons.ToImmutableList(); + Axes.MakeImmutable(); + HapticsChannels = HapticsChannels.ToImmutableList(); + CategoryLabels = CategoryLabels.ToImmutableDictionary(); + _mutable = false; + return this; + } + public int PlayerNumber(string buttonName) { var match = PlayerRegex.Match(buttonName); diff --git a/src/BizHawk.Emulation.Common/Base Implementations/NullController.cs b/src/BizHawk.Emulation.Common/Base Implementations/NullController.cs index bd51b68c11..fdab4a2281 100644 --- a/src/BizHawk.Emulation.Common/Base Implementations/NullController.cs +++ b/src/BizHawk.Emulation.Common/Base Implementations/NullController.cs @@ -12,7 +12,7 @@ namespace BizHawk.Emulation.Common /// public class NullController : IController { - public ControllerDefinition Definition { get; } = new ControllerDefinition("Null Controller"); + public ControllerDefinition Definition { get; } = new ControllerDefinition("Null Controller").MakeImmutable(); public bool IsPressed(string button) => false; diff --git a/src/BizHawk.Emulation.Common/BizHawk.Emulation.Common.csproj b/src/BizHawk.Emulation.Common/BizHawk.Emulation.Common.csproj index 6c722d4d36..408de2ca00 100644 --- a/src/BizHawk.Emulation.Common/BizHawk.Emulation.Common.csproj +++ b/src/BizHawk.Emulation.Common/BizHawk.Emulation.Common.csproj @@ -7,6 +7,7 @@ true + diff --git a/src/BizHawk.Emulation.Cores/Arcades/MAME/MAME.IInputPollable.cs b/src/BizHawk.Emulation.Cores/Arcades/MAME/MAME.IInputPollable.cs index 6974e168c6..4ab313a87a 100644 --- a/src/BizHawk.Emulation.Cores/Arcades/MAME/MAME.IInputPollable.cs +++ b/src/BizHawk.Emulation.Cores/Arcades/MAME/MAME.IInputPollable.cs @@ -23,6 +23,7 @@ namespace BizHawk.Emulation.Cores.Arcades.MAME { string inputFields = MameGetString(MAMELuaCommand.GetInputFields); string[] portFields = inputFields.Split(';'); + MAMEController = new("MAME Controller"); MAMEController.BoolButtons.Clear(); _fieldsPorts.Clear(); @@ -38,6 +39,8 @@ namespace BizHawk.Emulation.Cores.Arcades.MAME MAMEController.BoolButtons.Add(field); } } + + MAMEController.MakeImmutable(); } private void SendInput() diff --git a/src/BizHawk.Emulation.Cores/Calculator/TI83.cs b/src/BizHawk.Emulation.Cores/Calculator/TI83.cs index b071d55630..536d35ced0 100644 --- a/src/BizHawk.Emulation.Cores/Calculator/TI83.cs +++ b/src/BizHawk.Emulation.Cores/Calculator/TI83.cs @@ -90,7 +90,7 @@ namespace BizHawk.Emulation.Cores.Calculators "STO", "LN", "LOG", "SQUARED", "NEG1", "MATH", "ALPHA", "GRAPH", "TRACE", "ZOOM", "WINDOW", "Y", "2ND", "MODE", "DEL", }, - }; + }.MakeImmutable(); private byte ReadMemory(ushort addr) { diff --git a/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/AmstradCPC.Controllers.cs b/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/AmstradCPC.Controllers.cs index 40e959f68f..ef3ce3749e 100644 --- a/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/AmstradCPC.Controllers.cs +++ b/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/AmstradCPC.Controllers.cs @@ -111,7 +111,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC definition.CategoryLabels[s] = "Amstrad Disk Drive"; } - return definition; + return definition.MakeImmutable(); } } } diff --git a/src/BizHawk.Emulation.Cores/Computers/AppleII/AppleII.cs b/src/BizHawk.Emulation.Cores/Computers/AppleII/AppleII.cs index 8e6b40c515..0cbb846bd3 100644 --- a/src/BizHawk.Emulation.Cores/Computers/AppleII/AppleII.cs +++ b/src/BizHawk.Emulation.Cores/Computers/AppleII/AppleII.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Linq; +using BizHawk.Common.CollectionExtensions; using BizHawk.Emulation.Common; using Jellyfish.Virtu; @@ -15,6 +16,7 @@ namespace BizHawk.Emulation.Cores.Computers.AppleII AppleIIController = new("Apple IIe Keyboard"); AppleIIController.BoolButtons.AddRange(RealButtons); AppleIIController.BoolButtons.AddRange(ExtraButtons); + AppleIIController.MakeImmutable(); } [CoreConstructor(VSystemID.Raw.AppleII)] diff --git a/src/BizHawk.Emulation.Cores/Computers/Commodore64/C64.cs b/src/BizHawk.Emulation.Cores/Computers/Commodore64/C64.cs index 7844a564f4..8300896c6d 100644 --- a/src/BizHawk.Emulation.Cores/Computers/Commodore64/C64.cs +++ b/src/BizHawk.Emulation.Cores/Computers/Commodore64/C64.cs @@ -150,7 +150,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64 "Previous Disk", "Next Disk", "Power", "Reset" } - }; + }.MakeImmutable(); private Motherboard _board; diff --git a/src/BizHawk.Emulation.Cores/Computers/MSX/MSX.Input.cs b/src/BizHawk.Emulation.Cores/Computers/MSX/MSX.Input.cs index 98ed54af15..3c05576331 100644 --- a/src/BizHawk.Emulation.Cores/Computers/MSX/MSX.Input.cs +++ b/src/BizHawk.Emulation.Cores/Computers/MSX/MSX.Input.cs @@ -22,7 +22,7 @@ namespace BizHawk.Emulation.Cores.Computers.MSX "RET", "SEL", "BACK", "STOP", "TAB", "ESC", "F5", "F4", "RIGHT", "DOWN", "UP", "LEFT", "DEL", "INS", "HOME", "SPACE" } - }; + }.MakeImmutable(); public static readonly ControllerDefinition MSXControllerJS = new ControllerDefinition("MSX Controller Joystick") { @@ -32,6 +32,6 @@ namespace BizHawk.Emulation.Cores.Computers.MSX "P1 Up", "P1 Down", "P1 Left", "P1 Right", "P1 B1", "P1 B2", "P2 Up", "P2 Down", "P2 Left", "P2 Right", "P2 B1", "P2 B2" } - }; + }.MakeImmutable(); } } \ No newline at end of file diff --git a/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/ZXSpectrum.Controllers.cs b/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/ZXSpectrum.Controllers.cs index 958a429d8e..a9453c2c2b 100644 --- a/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/ZXSpectrum.Controllers.cs +++ b/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/ZXSpectrum.Controllers.cs @@ -120,7 +120,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum definition.CategoryLabels[s] = "+3 Disk Drive"; } - return definition; + return definition.MakeImmutable(); } } } diff --git a/src/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600ControllerDeck.cs b/src/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600ControllerDeck.cs index 414b42047e..6558d8328d 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600ControllerDeck.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600ControllerDeck.cs @@ -28,6 +28,8 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 foreach (var kvp in Port1.Definition.Axes) Definition.Axes.Add(kvp); foreach (var kvp in Port2.Definition.Axes) Definition.Axes.Add(kvp); + + Definition.MakeImmutable(); } public byte ReadPort1(IController c) diff --git a/src/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600Controllers.cs b/src/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600Controllers.cs index 359d8d6038..73de38020a 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600Controllers.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600Controllers.cs @@ -117,7 +117,8 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 .Select(b => $"P{PortNum} " + b) .ToList() }.AddAxis($"P{PortNum} Paddle X 1", (-127).RangeTo(127), 0) - .AddAxis($"P{PortNum} Paddle X 2", (-127).RangeTo(127), 0); + .AddAxis($"P{PortNum} Paddle X 2", (-127).RangeTo(127), 0) + .MakeImmutable(); } public int PortNum { get; } @@ -233,7 +234,8 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 .Select(b => $"P{PortNum} " + b) .ToList() }.AddAxis($"P{PortNum} Wheel X 1", (-127).RangeTo(127), 0) - .AddAxis($"P{PortNum} Wheel X 2", (-127).RangeTo(127), 0); + .AddAxis($"P{PortNum} Wheel X 2", (-127).RangeTo(127), 0) + .MakeImmutable(); } public int PortNum { get; } diff --git a/src/BizHawk.Emulation.Cores/Consoles/Atari/A7800Hawk/A7800HawkControllerDeck.cs b/src/BizHawk.Emulation.Cores/Consoles/Atari/A7800Hawk/A7800HawkControllerDeck.cs index 920b4e5ce1..c1303b569e 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Atari/A7800Hawk/A7800HawkControllerDeck.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Atari/A7800Hawk/A7800HawkControllerDeck.cs @@ -38,6 +38,8 @@ namespace BizHawk.Emulation.Cores.Atari.A7800Hawk foreach (var kvp in Port1.Definition.Axes) Definition.Axes.Add(kvp); foreach (var kvp in Port2.Definition.Axes) Definition.Axes.Add(kvp); + + Definition.MakeImmutable(); } public byte ReadPort1(IController c) diff --git a/src/BizHawk.Emulation.Cores/Consoles/Atari/lynx/Lynx.cs b/src/BizHawk.Emulation.Cores/Consoles/Atari/lynx/Lynx.cs index c7160665fc..e31e1ea662 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Atari/lynx/Lynx.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Atari/lynx/Lynx.cs @@ -164,7 +164,7 @@ namespace BizHawk.Emulation.Cores.Atari.Lynx private static readonly ControllerDefinition LynxTroller = new ControllerDefinition("Lynx Controller") { BoolButtons = { "Up", "Down", "Left", "Right", "A", "B", "Option 1", "Option 2", "Pause", "Power" }, - }; + }.MakeImmutable(); public ControllerDefinition ControllerDefinition => LynxTroller; diff --git a/src/BizHawk.Emulation.Cores/Consoles/Belogic/Uzem.cs b/src/BizHawk.Emulation.Cores/Consoles/Belogic/Uzem.cs index 2a110319a9..a5fa6049cf 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Belogic/Uzem.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Belogic/Uzem.cs @@ -55,12 +55,13 @@ namespace BizHawk.Emulation.Cores.Consoles.Belogic "P2 Up", "P2 Down", "P2 Left", "P2 Right", "P2 Select", "P2 Start", "P2 X", "P2 A", "P2 B", "P2 Y", "P2 L", "P2 R", "Power" } - }; + }.MakeImmutable(); private static readonly ControllerDefinition Mouse = new ControllerDefinition("SNES Controller") { BoolButtons = { "P1 Mouse Left", "P1 Mouse Right", "Power" } - }.AddXYPair("P1 Mouse {0}", AxisPairOrientation.RightAndUp, (-127).RangeTo(127), 0); //TODO verify direction against hardware + }.AddXYPair("P1 Mouse {0}", AxisPairOrientation.RightAndUp, (-127).RangeTo(127), 0) //TODO verify direction against hardware + .MakeImmutable(); private static readonly string[] PadBits = { diff --git a/src/BizHawk.Emulation.Cores/Consoles/Coleco/ColecoControllerDeck.cs b/src/BizHawk.Emulation.Cores/Consoles/Coleco/ColecoControllerDeck.cs index adbe0607bc..9a509d268b 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Coleco/ColecoControllerDeck.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Coleco/ColecoControllerDeck.cs @@ -32,6 +32,8 @@ namespace BizHawk.Emulation.Cores.ColecoVision foreach (var kvp in Port1.Definition.Axes) Definition.Axes.Add(kvp); foreach (var kvp in Port2.Definition.Axes) Definition.Axes.Add(kvp); + + Definition.MakeImmutable(); } public float wheel1; diff --git a/src/BizHawk.Emulation.Cores/Consoles/Fairchild/ChannelF/ChannelF.Controllers.cs b/src/BizHawk.Emulation.Cores/Consoles/Fairchild/ChannelF/ChannelF.Controllers.cs index 9b15714ead..b546b3f7f8 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Fairchild/ChannelF/ChannelF.Controllers.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Fairchild/ChannelF/ChannelF.Controllers.cs @@ -52,7 +52,7 @@ namespace BizHawk.Emulation.Cores.Consoles.ChannelF definition.CategoryLabels[s] = "Console"; } - return definition; + return definition.MakeImmutable(); } } diff --git a/src/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawkControllerDeck.cs b/src/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawkControllerDeck.cs index c3e257b48b..71d05d1377 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawkControllerDeck.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/GCE/Vectrex/VectrexHawkControllerDeck.cs @@ -33,6 +33,8 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex foreach (var kvp in Port1.Definition.Axes) Definition.Axes.Add(kvp); foreach (var kvp in Port2.Definition.Axes) Definition.Axes.Add(kvp); + + Definition.MakeImmutable(); } public byte ReadPort1(IController c) diff --git a/src/BizHawk.Emulation.Cores/Consoles/Intellivision/Controllers/IntellivisionControllerDeck.cs b/src/BizHawk.Emulation.Cores/Consoles/Intellivision/Controllers/IntellivisionControllerDeck.cs index 0cb7a252a2..26b3cc892c 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Intellivision/Controllers/IntellivisionControllerDeck.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Intellivision/Controllers/IntellivisionControllerDeck.cs @@ -33,6 +33,8 @@ namespace BizHawk.Emulation.Cores.Intellivision foreach (var kvp in Port1.Definition.Axes) Definition.Axes.Add(kvp); foreach (var kvp in Port2.Definition.Axes) Definition.Axes.Add(kvp); + + Definition.MakeImmutable(); } public byte ReadPort1(IController c) diff --git a/src/BizHawk.Emulation.Cores/Consoles/Magnavox/Odyssey2/O2HawkControllerDeck.cs b/src/BizHawk.Emulation.Cores/Consoles/Magnavox/Odyssey2/O2HawkControllerDeck.cs index 352cc787f0..ac8dedf1cb 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Magnavox/Odyssey2/O2HawkControllerDeck.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Magnavox/Odyssey2/O2HawkControllerDeck.cs @@ -60,6 +60,8 @@ namespace BizHawk.Emulation.Cores.Consoles.O2Hawk } foreach (var kvp in Port1.Definition.Axes) Definition.Axes.Add(kvp); + + Definition.MakeImmutable(); } public byte ReadPort1(IController c) diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/BsnesControllers.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/BsnesControllers.cs index 463a02ac9a..71952c8a53 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/BsnesControllers.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/BsnesControllers.cs @@ -52,6 +52,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.BSNES // add buttons that the core itself will handle Definition.BoolButtons.Add("Reset"); Definition.BoolButtons.Add("Power"); + + Definition.MakeImmutable(); } public void CoreInputPoll(IController controller) diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBA/MGBAHawk.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBA/MGBAHawk.cs index a0cee68915..bea0c3f669 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBA/MGBAHawk.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBA/MGBAHawk.cs @@ -265,6 +265,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA { BoolButtons = { "Up", "Down", "Left", "Right", "Start", "Select", "B", "A", "L", "R", "Power" } }.AddXYZTriple("Tilt {0}", (-32767).RangeTo(32767), 0) - .AddAxis("Light Sensor", 0.RangeTo(255), 0); + .AddAxis("Light Sensor", 0.RangeTo(255), 0) + .MakeImmutable(); } } diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawkControllerDeck.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawkControllerDeck.cs index 4cbedf5479..936cacb418 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawkControllerDeck.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/GBHawkControllerDeck.cs @@ -23,6 +23,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk }; foreach (var kvp in Port1.Definition.Axes) Definition.Axes.Add(kvp); + + Definition.MakeImmutable(); } public byte ReadPort1(IController c) diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink/GBHawkLinkControllerDeck.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink/GBHawkLinkControllerDeck.cs index 82058d78a8..74a3f497bc 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink/GBHawkLinkControllerDeck.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink/GBHawkLinkControllerDeck.cs @@ -24,7 +24,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink .Concat(Port2.Definition.BoolButtons) .Concat(new[] { "Toggle Cable" } ) .ToList() - }; + }.MakeImmutable(); } public byte ReadPort1(IController c) diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink3x/GBHawkLink3xControllerDeck.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink3x/GBHawkLink3xControllerDeck.cs index f18bb4795e..65b6399ecc 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink3x/GBHawkLink3xControllerDeck.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink3x/GBHawkLink3xControllerDeck.cs @@ -30,7 +30,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink3x .Concat(new[] { "Toggle Cable CR" } ) .Concat(new[] { "Toggle Cable RL" } ) .ToList() - }; + }.MakeImmutable(); } public byte ReadPort1(IController c) diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink4x/GBHawkLink4xControllerDeck.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink4x/GBHawkLink4xControllerDeck.cs index 24fd59a096..d0f4aa29a4 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink4x/GBHawkLink4xControllerDeck.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink4x/GBHawkLink4xControllerDeck.cs @@ -35,7 +35,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink4x .Concat(new[] { "Toggle Cable X" } ) .Concat(new[] { "Toggle Cable 4x" }) .ToList() - }; + }.MakeImmutable(); } public byte ReadPort1(IController c) diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.cs index 6d4daf0a77..c7a149b30c 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using BizHawk.Common; +using BizHawk.Common.CollectionExtensions; using BizHawk.Emulation.Common; using BizHawk.Emulation.Cores.Consoles.Nintendo.Gameboy; @@ -281,7 +282,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy { ret.BoolButtons.AddRange(new[] { "Up", "Down", "Left", "Right", "Start", "Select", "B", "A", "Power" }); } - return ret; + return ret.MakeImmutable(); } private LibGambatte.Buttons ControllerCallback() diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.cs index d7a45c3189..ddbf85cd82 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.cs @@ -1,6 +1,7 @@ using System; using System.Linq; +using BizHawk.Common.CollectionExtensions; using BizHawk.Emulation.Common; namespace BizHawk.Emulation.Cores.Nintendo.Gameboy @@ -153,7 +154,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy ret.BoolButtons.Add("Toggle Link Shift"); ret.BoolButtons.Add("Toggle Link Spacing"); } - return ret; + return ret.MakeImmutable(); } private const int P1 = 0; diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64.ISettable.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64.ISettable.cs index 6ae79a158a..921fac2947 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64.ISettable.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64.ISettable.cs @@ -1,4 +1,5 @@ using BizHawk.Common; +using BizHawk.Common.CollectionExtensions; using BizHawk.Emulation.Common; namespace BizHawk.Emulation.Cores.Nintendo.N64 @@ -42,9 +43,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64 if (hasRumblePak) def.HapticsChannels.Add($"P{player} Rumble Pak"); } - ControllerDefinition.BoolButtons.Clear(); - ControllerDefinition.Axes.Clear(); - + ControllerDefinition = new("Nintendo 64 Controller"); ControllerDefinition.BoolButtons.AddRange(new[] { "Reset", "Power" }); for (var i = 0; i < 4; i++) { @@ -56,6 +55,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64 syncSettings.Controllers[i].PakType == N64SyncSettings.N64ControllerSettings.N64ControllerPakType.RUMBLE_PAK); } } + ControllerDefinition.MakeImmutable(); } } } diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64.cs index 0600e1b235..f6a90cc411 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64.cs @@ -246,7 +246,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64 public DisplayType Region => _display_type; - public ControllerDefinition ControllerDefinition { get; } = new("Nintendo 64 Controller"); + public ControllerDefinition ControllerDefinition { get; private set; } = new("Nintendo 64 Controller"); public void ResetCounters() { diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/MelonDS.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/MelonDS.cs index 94d2215e79..e23066205f 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/MelonDS.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/MelonDS.cs @@ -189,7 +189,9 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.NDS } }.AddXYPair("Touch {0}", AxisPairOrientation.RightAndUp, 0.RangeTo(255), 128, 0.RangeTo(191), 96) .AddAxis("Mic Volume", (0).RangeTo(100), 0) - .AddAxis("GBA Light Sensor", 0.RangeTo(10), 0); + .AddAxis("GBA Light Sensor", 0.RangeTo(10), 0) + .MakeImmutable(); + private LibMelonDS.Buttons GetButtons(IController c) { LibMelonDS.Buttons b = 0; diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.Core.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.Core.cs index c385109ec0..187fbde945 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.Core.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.Core.cs @@ -177,6 +177,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES ControllerDefinition.AddAxis("Reset Cycle", 0.RangeTo(500000), 0); } + ControllerDefinition.MakeImmutable(); + // don't replace the magicSoundProvider on reset, as it's not needed // if (magicSoundProvider != null) magicSoundProvider.Dispose(); diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.cs index 05aaa91b5a..f8152dfb21 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.cs @@ -256,7 +256,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES "P1 Up", "P1 Down", "P1 Left", "P1 Right", "P1 Start", "P1 Select", "P1 B", "P1 A", "Reset", "Power", "P2 Up", "P2 Down", "P2 Left", "P2 Right", "P2 Start", "P2 Select", "P2 B", "P2 A" } - }; + }.MakeImmutable(); public ControllerDefinition ControllerDefinition { get; private set; } diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/QuickNES/QuickNES.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/QuickNES/QuickNES.cs index 8eaef8e34a..8c392abfa4 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/QuickNES/QuickNES.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/QuickNES/QuickNES.cs @@ -6,6 +6,7 @@ using System.Linq; using System.Runtime.InteropServices; using BizHawk.Common; +using BizHawk.Common.CollectionExtensions; using BizHawk.Emulation.Common; using BizHawk.Emulation.Cores.Nintendo.NES; using BizHawk.BizInvoke; @@ -125,7 +126,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES if (_syncSettings.LeftPortConnected && _syncSettings.RightPortConnected) def.BoolButtons.AddRange(PadP2.Select(p => p.Name)); def.BoolButtons.AddRange(new[] { "Reset", "Power" }); // console buttons - ControllerDefinition = def; + ControllerDefinition = def.MakeImmutable(); } private struct PadEnt diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesControllerDeck.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesControllerDeck.cs index 17b12ca43a..2a24415f55 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesControllerDeck.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesControllerDeck.cs @@ -69,6 +69,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES // add buttons that the core itself will handle Definition.BoolButtons.Add("Reset"); Definition.BoolButtons.Add("Power"); + + Definition.MakeImmutable(); } public void NativeInit(LibsnesApi api) diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES9X/Snes9x.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES9X/Snes9x.cs index 1bf890733d..71f0cdf0c9 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES9X/Snes9x.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES9X/Snes9x.cs @@ -115,6 +115,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES9X // add buttons that the core itself will handle _controllerDefinition.BoolButtons.Add("Reset"); _controllerDefinition.BoolButtons.Add("Power"); + + _controllerDefinition.MakeImmutable(); } private void UpdateControls(IController c) diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SubGBHawk/SubGBHawk.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SubGBHawk/SubGBHawk.cs index 3809da22a1..d2c6349305 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SubGBHawk/SubGBHawk.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SubGBHawk/SubGBHawk.cs @@ -40,7 +40,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.SubGBHawk _tracer = new TraceBuffer(_GBCore.cpu.TraceHeader); ser.Register(_tracer); - _GBCore.ControllerDefinition.AddAxis("Input Cycle", 0.RangeTo(70224), 70224); + _GBCore.ControllerDefinition.AddAxis("Input Cycle", 0.RangeTo(70224), 70224) + .MakeImmutable(); } public GBHawk.GBHawk _GBCore; diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/VB/VirtualBoyee.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/VB/VirtualBoyee.cs index c5c687759c..4b4aac7cc4 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/VB/VirtualBoyee.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/VB/VirtualBoyee.cs @@ -110,7 +110,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.VB .OrderBy(b => _buttonOrdinals[b]) .Concat(new[] { "Power" }) .ToList() - }; + }.MakeImmutable(); public override ControllerDefinition ControllerDefinition => VirtualBoyController; diff --git a/src/BizHawk.Emulation.Cores/Consoles/PC Engine/PceControllerDeck.cs b/src/BizHawk.Emulation.Cores/Consoles/PC Engine/PceControllerDeck.cs index ad7998a41c..28c5e7c355 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/PC Engine/PceControllerDeck.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/PC Engine/PceControllerDeck.cs @@ -46,6 +46,7 @@ namespace BizHawk.Emulation.Cores.PCEngine foreach (var kvp in _port3.Definition.Axes) Definition.Axes.Add(kvp); foreach (var kvp in _port4.Definition.Axes) Definition.Axes.Add(kvp); foreach (var kvp in _port5.Definition.Axes) Definition.Axes.Add(kvp); + Definition.MakeImmutable(); } private readonly IPort _port1; diff --git a/src/BizHawk.Emulation.Cores/Consoles/Sega/GGHawkLink/GGHawkLinkControllerDeck.cs b/src/BizHawk.Emulation.Cores/Consoles/Sega/GGHawkLink/GGHawkLinkControllerDeck.cs index 043a20950e..6c29341cf6 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Sega/GGHawkLink/GGHawkLinkControllerDeck.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Sega/GGHawkLink/GGHawkLinkControllerDeck.cs @@ -25,7 +25,7 @@ namespace BizHawk.Emulation.Cores.Sega.GGHawkLink .Concat(Port2.Definition.BoolButtons) .Concat(new[] { "Toggle Cable" } ) .ToList() - }; + }.MakeImmutable(); } public byte ReadPort1(IController c) diff --git a/src/BizHawk.Emulation.Cores/Consoles/Sega/PicoDrive/PicoDrive.cs b/src/BizHawk.Emulation.Cores/Consoles/Sega/PicoDrive/PicoDrive.cs index c217b63c9b..d768bd9f01 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Sega/PicoDrive/PicoDrive.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Sega/PicoDrive/PicoDrive.cs @@ -131,7 +131,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.PicoDrive "P2 Up", "P2 Down", "P2 Left", "P2 Right", "P2 A", "P2 B", "P2 C", "P2 Start", "P2 X", "P2 Y", "P2 Z", "P2 Mode", "Power", "Reset" } - }; + }.MakeImmutable(); private static readonly string[] ButtonOrders = { diff --git a/src/BizHawk.Emulation.Cores/Consoles/Sega/SMS/SMSControllerDeck.cs b/src/BizHawk.Emulation.Cores/Consoles/Sega/SMS/SMSControllerDeck.cs index c7c50504cf..1222f60b51 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Sega/SMS/SMSControllerDeck.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Sega/SMS/SMSControllerDeck.cs @@ -23,7 +23,7 @@ namespace BizHawk.Emulation.Cores.Sega.MasterSystem BoolButtons = new[] { "Reset" } .Concat(Port1.Definition.BoolButtons) .ToList() - }; + }.MakeImmutable(); } else { @@ -38,7 +38,7 @@ namespace BizHawk.Emulation.Cores.Sega.MasterSystem .Concat(Port1.Definition.BoolButtons) .Concat(Port2.Definition.BoolButtons) .ToList() - }; + }.MakeImmutable(); } else { @@ -49,7 +49,7 @@ namespace BizHawk.Emulation.Cores.Sega.MasterSystem .Concat(Port2.Definition.BoolButtons) .Concat(KeyboardMap) .ToList() - }; + }.MakeImmutable(); } foreach (var kvp in Port1.Definition.Axes) Definition.Axes.Add(kvp); diff --git a/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GPGXControlConverter.cs b/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GPGXControlConverter.cs index a4f62a2e3d..4c4c32706b 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GPGXControlConverter.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GPGXControlConverter.cs @@ -235,6 +235,8 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx throw new Exception("Unknown Genesis control device! Something went wrong."); } } + + ControllerDef.MakeImmutable(); } public void Convert(IController source, LibGPGX.InputData target) diff --git a/src/BizHawk.Emulation.Cores/Consoles/Sony/PS2/DobieStation.cs b/src/BizHawk.Emulation.Cores/Consoles/Sony/PS2/DobieStation.cs index 2437c6843a..a199d583eb 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Sony/PS2/DobieStation.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Sony/PS2/DobieStation.cs @@ -163,7 +163,7 @@ namespace BizHawk.Emulation.Cores.Sony.PS2 { "LEFT X", new AxisSpec(0.RangeTo(255), 128) }, { "LEFT Y", new AxisSpec(0.RangeTo(255), 128) }, } - }; + }.MakeImmutable(); public class DobieSyncSettings { diff --git a/src/BizHawk.Emulation.Cores/Consoles/Sony/PSX/Octoshock.cs b/src/BizHawk.Emulation.Cores/Consoles/Sony/PSX/Octoshock.cs index e7f325d4ec..46612c01f8 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Sony/PSX/Octoshock.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Sony/PSX/Octoshock.cs @@ -354,7 +354,7 @@ namespace BizHawk.Emulation.Cores.Sony.PSX definition.AddAxis("Disc Select", 0.RangeTo(1), 1); - return definition; + return definition.MakeImmutable(); } private void SetControllerButtons() diff --git a/src/BizHawk.Emulation.Cores/Consoles/WonderSwan/WonderSwan.Controller.cs b/src/BizHawk.Emulation.Cores/Consoles/WonderSwan/WonderSwan.Controller.cs index 71c0e1d2d1..5a155d720b 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/WonderSwan/WonderSwan.Controller.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/WonderSwan/WonderSwan.Controller.cs @@ -61,7 +61,8 @@ namespace BizHawk.Emulation.Cores.WonderSwan { "P2 B", "Rotated" }, { "P2 A", "Rotated" }, } - }; + }.MakeImmutable(); + public ControllerDefinition ControllerDefinition => WonderSwanController; private BizSwan.Buttons GetButtons(IController controller) diff --git a/src/BizHawk.Emulation.Cores/Libretro/LibretroCore.cs b/src/BizHawk.Emulation.Cores/Libretro/LibretroCore.cs index cf6e961116..57492acd2b 100644 --- a/src/BizHawk.Emulation.Cores/Libretro/LibretroCore.cs +++ b/src/BizHawk.Emulation.Cores/Libretro/LibretroCore.cs @@ -275,7 +275,7 @@ namespace BizHawk.Emulation.Cores.Libretro definition.CategoryLabels[key] = "RetroKeyboard"; } - return definition; + return definition.MakeImmutable(); } public ControllerDefinition ControllerDefinition { get; } diff --git a/src/BizHawk.Emulation.Cores/Waterbox/NymaCore.Controller.cs b/src/BizHawk.Emulation.Cores/Waterbox/NymaCore.Controller.cs index 7e23a56b59..82bde4ee8e 100644 --- a/src/BizHawk.Emulation.Cores/Waterbox/NymaCore.Controller.cs +++ b/src/BizHawk.Emulation.Cores/Waterbox/NymaCore.Controller.cs @@ -263,7 +263,7 @@ namespace BizHawk.Emulation.Cores.Waterbox ret.BoolButtons.Add("Previous Disk"); ret.BoolButtons.Add("Next Disk"); } - Definition = ret; + Definition = ret.MakeImmutable(); finalDevices.Add(null); Devices = finalDevices.ToArray(); _switchPreviousFrame = switchPreviousFrame.ToArray(); diff --git a/src/BizHawk.Tests/Client.Common/Display/InputDisplayTests.cs b/src/BizHawk.Tests/Client.Common/Display/InputDisplayTests.cs index 76ed84514e..612287b86a 100644 --- a/src/BizHawk.Tests/Client.Common/Display/InputDisplayTests.cs +++ b/src/BizHawk.Tests/Client.Common/Display/InputDisplayTests.cs @@ -16,8 +16,11 @@ namespace BizHawk.Tests.Client.Common.Display [TestInitialize] public void Initializer() { - _boolController = new(new ControllerDefinition("Dummy Gamepad") { BoolButtons = { "A" } }); - _axisController = new(new ControllerDefinition("Dummy Gamepad").AddXYPair("Stick{0}", AxisPairOrientation.RightAndUp, 0.RangeTo(200), MidValue)); + _boolController = new(new ControllerDefinition("Dummy Gamepad") { BoolButtons = { "A" } }.MakeImmutable()); + _axisController = new( + new ControllerDefinition("Dummy Gamepad") + .AddXYPair("Stick{0}", AxisPairOrientation.RightAndUp, 0.RangeTo(200), MidValue) + .MakeImmutable()); } [TestMethod] diff --git a/src/BizHawk.Tests/Client.Common/Movie/LogGeneratorTests.cs b/src/BizHawk.Tests/Client.Common/Movie/LogGeneratorTests.cs index febd92ba49..d2f4c36c29 100644 --- a/src/BizHawk.Tests/Client.Common/Movie/LogGeneratorTests.cs +++ b/src/BizHawk.Tests/Client.Common/Movie/LogGeneratorTests.cs @@ -15,14 +15,17 @@ namespace BizHawk.Tests.Client.Common.Movie [TestInitialize] public void Initializer() { - _boolController = new(new ControllerDefinition("Dummy Gamepad") { BoolButtons = { "A" } }); - _axisController = new(new ControllerDefinition("Dummy Gamepad").AddXYPair("Stick{0}", AxisPairOrientation.RightAndUp, 0.RangeTo(200), 100)); + _boolController = new(new ControllerDefinition("Dummy Gamepad") { BoolButtons = { "A" } }.MakeImmutable()); + _axisController = new( + new ControllerDefinition("Dummy Gamepad") + .AddXYPair("Stick{0}", AxisPairOrientation.RightAndUp, 0.RangeTo(200), 100) + .MakeImmutable()); } [TestMethod] public void GenerateLogEntry_ExclamationForUnknownButtons() { - SimpleController controller = new(new ControllerDefinition("Dummy Gamepad") { BoolButtons = { "Unknown Button" } }); + SimpleController controller = new(new ControllerDefinition("Dummy Gamepad") { BoolButtons = { "Unknown Button" } }.MakeImmutable()); var lg = new Bk2LogEntryGenerator("NES", controller); controller["Unknown Button"] = true; var actual = lg.GenerateLogEntry();