diff --git a/Common.ruleset b/Common.ruleset
index 4ad09dafa9..0b678725a8 100644
--- a/Common.ruleset
+++ b/Common.ruleset
@@ -122,7 +122,7 @@
-
+
diff --git a/src/BizHawk.Client.Common/Api/Classes/GuiApi.cs b/src/BizHawk.Client.Common/Api/Classes/GuiApi.cs
index 1603f9db63..047188f0cf 100644
--- a/src/BizHawk.Client.Common/Api/Classes/GuiApi.cs
+++ b/src/BizHawk.Client.Common/Api/Classes/GuiApi.cs
@@ -356,9 +356,11 @@ namespace BizHawk.Client.Common
return;
}
using var g = GetGraphics(surfaceID);
- var isCached = _imageCache.ContainsKey(path);
- var img = isCached ? _imageCache[path] : Image.FromFile(path);
- if (!isCached && cache) _imageCache[path] = img;
+ if (!_imageCache.TryGetValue(path, out var img))
+ {
+ img = Image.FromFile(path);
+ if (cache) _imageCache[path] = img;
+ }
g.CompositingMode = _compositingMode;
g.DrawImage(
img,
diff --git a/src/BizHawk.Client.Common/movie/MovieSession.cs b/src/BizHawk.Client.Common/movie/MovieSession.cs
index cc86797627..0343f39fbf 100644
--- a/src/BizHawk.Client.Common/movie/MovieSession.cs
+++ b/src/BizHawk.Client.Common/movie/MovieSession.cs
@@ -211,8 +211,8 @@ namespace BizHawk.Client.Common
{
if (string.IsNullOrWhiteSpace(movie.Core))
{
- PopupMessage(preferredCores.TryGetValue(systemId, out _)
- ? $"No core specified in the movie file, using the preferred core {preferredCores[systemId]} instead."
+ PopupMessage(preferredCores.TryGetValue(systemId, out var coreName)
+ ? $"No core specified in the movie file, using the preferred core {coreName} instead."
: "No core specified in the movie file, using the default core instead.");
}
else
diff --git a/src/BizHawk.Client.Common/movie/tasproj/StateDictionary.cs b/src/BizHawk.Client.Common/movie/tasproj/StateDictionary.cs
index b565d7ef06..4e980ecfe8 100644
--- a/src/BizHawk.Client.Common/movie/tasproj/StateDictionary.cs
+++ b/src/BizHawk.Client.Common/movie/tasproj/StateDictionary.cs
@@ -25,16 +25,23 @@ namespace BizHawk.Client.Common
public void SetState(int frame, Stream stream)
{
- if (!_streams.ContainsKey(frame))
+ if (_streams.TryGetValue(frame, out var foundStream))
{
- string filename = TempFileManager.GetTempFilename("State");
- _streams[frame] = new FileStream(filename, FileMode.Create, FileAccess.ReadWrite, FileShare.None, 4096, FileOptions.DeleteOnClose);
+ foundStream.Seek(0, SeekOrigin.Begin);
}
else
- _streams[frame].Seek(0, SeekOrigin.Begin);
+ {
+ _streams[frame] = foundStream = new FileStream(
+ TempFileManager.GetTempFilename("State"),
+ FileMode.Create,
+ FileAccess.ReadWrite,
+ FileShare.None,
+ 4096,
+ FileOptions.DeleteOnClose);
+ }
- _streams[frame].SetLength(stream.Length);
- stream.CopyTo(_streams[frame]);
+ foundStream.SetLength(stream.Length);
+ stream.CopyTo(foundStream);
}
public ICollection Keys => _streams.Keys;
diff --git a/src/BizHawk.Client.EmuHawk/RetroAchievements/RCheevos.GameInfo.cs b/src/BizHawk.Client.EmuHawk/RetroAchievements/RCheevos.GameInfo.cs
index c03a27fddf..059cad5d4c 100644
--- a/src/BizHawk.Client.EmuHawk/RetroAchievements/RCheevos.GameInfo.cs
+++ b/src/BizHawk.Client.EmuHawk/RetroAchievements/RCheevos.GameInfo.cs
@@ -150,15 +150,7 @@ namespace BizHawk.Client.EmuHawk
protected override int IdentifyHash(string hash)
{
_gameHash ??= hash;
-
- if (_cachedGameIds.ContainsKey(hash))
- {
- return _cachedGameIds[hash];
- }
-
- var ret = SendHash(hash);
- _cachedGameIds.Add(hash, ret);
- return ret;
+ return _cachedGameIds.TryGetValue(hash, out var id) ? id : (_cachedGameIds[hash] = SendHash(hash));
}
protected override int IdentifyRom(byte[] rom)
diff --git a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.ListView.cs b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.ListView.cs
index 5bccfde705..b18d945755 100644
--- a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.ListView.cs
+++ b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.ListView.cs
@@ -249,13 +249,13 @@ namespace BizHawk.Client.EmuHawk
color = Palette.AnalogEdit_Col;
}
- if (!_alternateRowColor.ContainsKey(columnName))
+ if (!_alternateRowColor.TryGetValue(columnName, out var useAltColor))
{
int playerNumber = ControllerDefinition.PlayerNumber(columnName);
- _alternateRowColor[columnName] = playerNumber != 0 && playerNumber % 2 == 0;
+ _alternateRowColor[columnName] = useAltColor = playerNumber % 2 is 0 && playerNumber is not 0;
}
- if (_alternateRowColor[columnName])
+ if (useAltColor)
{
color = Color.FromArgb(0x0D, 0x00, 0x00, 0x00);
}
diff --git a/src/BizHawk.Common/SettingsUtil.cs b/src/BizHawk.Common/SettingsUtil.cs
index a5eda4401d..6777541ca2 100644
--- a/src/BizHawk.Common/SettingsUtil.cs
+++ b/src/BizHawk.Common/SettingsUtil.cs
@@ -89,10 +89,10 @@ namespace BizHawk.Common
{
il.Emit(OpCodes.Unbox_Any, desiredType);
}
- else if (IntTypes.ContainsKey(sourceType) && IntTypes.ContainsKey(desiredType))
+ else if (IntTypes.ContainsKey(sourceType) && IntTypes.TryGetValue(desiredType, out var desiredOpcode))
{
il.Emit(OpCodes.Unbox_Any, sourceType);
- il.Emit(IntTypes[desiredType]);
+ il.Emit(desiredOpcode);
}
else
{
diff --git a/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/AmstradCPC.IMemoryDomains.cs b/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/AmstradCPC.IMemoryDomains.cs
index d4b4d60b99..9d21bada1b 100644
--- a/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/AmstradCPC.IMemoryDomains.cs
+++ b/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/AmstradCPC.IMemoryDomains.cs
@@ -57,6 +57,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
private void SyncByteArrayDomain(string name, byte[] data)
{
+#pragma warning disable MEN014 // see ZXHawk copy
if (_memoryDomainsInit || _byteArrayDomains.ContainsKey(name))
{
var m = _byteArrayDomains[name];
@@ -67,6 +68,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
var m = new MemoryDomainByteArray(name, MemoryDomain.Endian.Little, data, true, 1);
_byteArrayDomains.Add(name, m);
}
+#pragma warning restore MEN014
}
}
}
diff --git a/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/ZXSpectrum.IMemoryDomains.cs b/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/ZXSpectrum.IMemoryDomains.cs
index e23c31c8ca..a76ae31d0e 100644
--- a/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/ZXSpectrum.IMemoryDomains.cs
+++ b/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/ZXSpectrum.IMemoryDomains.cs
@@ -89,6 +89,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
private void SyncByteArrayDomain(string name, byte[] data)
{
+#pragma warning disable MEN014 // unclear how this check works from looking only at this code --yoshi
if (_memoryDomainsInit || _byteArrayDomains.ContainsKey(name))
{
var m = _byteArrayDomains[name];
@@ -99,6 +100,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
var m = new MemoryDomainByteArray(name, MemoryDomain.Endian.Little, data, true, 1);
_byteArrayDomains.Add(name, m);
}
+#pragma warning restore MEN014
}
}
}
diff --git a/src/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.cs b/src/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.cs
index 56c8739e5a..aedd6d4ec9 100644
--- a/src/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.cs
+++ b/src/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.cs
@@ -38,6 +38,7 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
Rom = rom;
_game = game;
+#pragma warning disable MEN014 // could rewrite this to be 1 read + 0-1 writes, but nah --yoshi
if (!game.GetOptions().ContainsKey("m"))
{
game.AddOption("m", DetectMapper(rom));
@@ -51,6 +52,7 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
}
Console.WriteLine("Game uses mapper " + game.GetOptions()["m"]);
+#pragma warning restore MEN014
Console.WriteLine(romHashSHA1);
RebootCore();
SetupMemoryDomains();
diff --git a/src/BizHawk.Emulation.Cores/Consoles/Fairchild/ChannelF/ChannelF.MemoryDomains.cs b/src/BizHawk.Emulation.Cores/Consoles/Fairchild/ChannelF/ChannelF.MemoryDomains.cs
index 6881bbfe37..f77585ee8e 100644
--- a/src/BizHawk.Emulation.Cores/Consoles/Fairchild/ChannelF/ChannelF.MemoryDomains.cs
+++ b/src/BizHawk.Emulation.Cores/Consoles/Fairchild/ChannelF/ChannelF.MemoryDomains.cs
@@ -47,6 +47,7 @@ namespace BizHawk.Emulation.Cores.Consoles.ChannelF
public void SyncByteArrayDomain(string name, byte[] data)
{
+#pragma warning disable MEN014 // see ZXHawk copy
if (_memoryDomainsInit || _byteArrayDomains.ContainsKey(name))
{
var m = _byteArrayDomains[name];
@@ -57,6 +58,7 @@ namespace BizHawk.Emulation.Cores.Consoles.ChannelF
var m = new MemoryDomainByteArray(name, MemoryDomain.Endian.Big, data, false, 1);
_byteArrayDomains.Add(name, m);
}
+#pragma warning restore MEN014
}
}
}
diff --git a/src/BizHawk.Emulation.Cores/Consoles/PC Engine/PCEngine.cs b/src/BizHawk.Emulation.Cores/Consoles/PC Engine/PCEngine.cs
index b99054a565..f3b13a3e05 100644
--- a/src/BizHawk.Emulation.Cores/Consoles/PC Engine/PCEngine.cs
+++ b/src/BizHawk.Emulation.Cores/Consoles/PC Engine/PCEngine.cs
@@ -333,10 +333,7 @@ namespace BizHawk.Emulation.Cores.PCEngine
Dictionary sizes = new Dictionary();
foreach (var m in mm)
{
- if (!sizes.ContainsKey(m.Name) || m.MaxOffs >= sizes[m.Name])
- {
- sizes[m.Name] = m.MaxOffs;
- }
+ if (!sizes.TryGetValue(m.Name, out var size) || size <= m.MaxOffs) sizes[m.Name] = m.MaxOffs;
}
var keys = new List(sizes.Keys);
diff --git a/src/BizHawk.Emulation.Cores/Waterbox/NymaCore.Settings.cs b/src/BizHawk.Emulation.Cores/Waterbox/NymaCore.Settings.cs
index ad36a0a6e2..05663da7bb 100644
--- a/src/BizHawk.Emulation.Cores/Waterbox/NymaCore.Settings.cs
+++ b/src/BizHawk.Emulation.Cores/Waterbox/NymaCore.Settings.cs
@@ -287,8 +287,10 @@ namespace BizHawk.Emulation.Cores.Waterbox
foreach (var portInfo in allPorts)
{
- if (s.AllOverrides.ContainsKey(portInfo.FullName) && s.AllOverrides[portInfo.FullName].Default != null)
- portInfo.DefaultDeviceShortName = s.AllOverrides[portInfo.FullName].Default;
+ if (s.AllOverrides.TryGetValue(portInfo.FullName, out var portOverride) && portOverride.Default is not null)
+ {
+ portInfo.DefaultDeviceShortName = portOverride.Default;
+ }
s.Ports.Add(new NymaSettingsInfo.Port
{