Use `TryGetValue` instead of `ContainsKey` + indexer

This commit is contained in:
YoshiRulz 2021-11-09 20:22:21 +10:00
parent dd97e4e861
commit 56e22f34a5
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
29 changed files with 112 additions and 304 deletions

View File

@ -102,7 +102,7 @@ namespace BizHawk.Client.Common
if (DebuggableCore != null)
{
var registers = DebuggableCore.GetCpuFlagsAndRegisters();
return registers.ContainsKey(name) ? registers[name].Value : (ulong?) null;
return registers.TryGetValue(name, out var rv) ? rv.Value : (ulong?) null;
}
}
catch (NotImplementedException) {}

View File

@ -1020,11 +1020,7 @@ namespace BizHawk.Client.Common
/// Peeks a locked lua surface, or returns null if it isn't locked
/// </summary>
public IDisplaySurface PeekApiHawkLockedSurface(DisplaySurfaceID surfaceID)
{
if (_apiHawkIDToSurface.ContainsKey(surfaceID))
return _apiHawkIDToSurface[surfaceID];
return null;
}
=> _apiHawkIDToSurface.TryGetValue(surfaceID, out var surface) ? surface : null;
public IDisplaySurface LockApiHawkSurface(DisplaySurfaceID surfaceID, bool clear)
{
@ -1082,12 +1078,7 @@ namespace BizHawk.Client.Common
public void UnlockApiHawkSurface(IDisplaySurface surface)
{
if (surface is not DisplaySurface dispSurfaceImpl) throw new ArgumentException("don't mix " + nameof(IDisplaySurface) + " implementations!", nameof(surface));
if (!_apiHawkSurfaceToID.ContainsKey(dispSurfaceImpl))
{
throw new InvalidOperationException("Surface was not locked as a lua surface");
}
var surfaceID = _apiHawkSurfaceToID[dispSurfaceImpl];
if (!_apiHawkSurfaceToID.TryGetValue(dispSurfaceImpl, out var surfaceID)) throw new InvalidOperationException("Surface was not locked as a lua surface");
_apiHawkSurfaceToID.Remove(dispSurfaceImpl);
_apiHawkIDToSurface.Remove(surfaceID);
_apiHawkSurfaceSets[surfaceID].SetPending(dispSurfaceImpl);

View File

@ -19,19 +19,10 @@ namespace BizHawk.Client.Common
/// <exception cref="InvalidOperationException"><paramref name="button"/> not overridden</exception>
public bool IsPressed(string button)
{
if (_overrides.ContainsKey(button))
{
return _overrides[button];
}
throw new InvalidOperationException();
}
=> _overrides.TryGetValue(button, out var b) ? b : throw new InvalidOperationException();
public int AxisValue(string name)
=> _axisOverrides.ContainsKey(name)
? _axisOverrides[name]
: 0;
=> _axisOverrides.TryGetValue(name, out var i) ? i : 0;
public IReadOnlyCollection<(string Name, int Strength)> GetHapticsSnapshot() => throw new NotImplementedException(); // no idea --yoshi
@ -44,28 +35,11 @@ namespace BizHawk.Client.Common
public IEnumerable<string> InversedButtons => _inverses;
public void SetAxis(string name, int value)
{
if (_axisOverrides.ContainsKey(name))
{
_axisOverrides[name] = value;
}
else
{
_axisOverrides.Add(name, value);
}
}
=> _axisOverrides[name] = value;
public void SetButton(string button, bool value)
{
if (_overrides.ContainsKey(button))
{
_overrides[button] = value;
}
else
{
_overrides.Add(button, value);
}
_overrides[button] = value;
_inverses.Remove(button);
}

View File

@ -119,10 +119,10 @@ namespace BizHawk.Client.Common
{
var source = Source.IsPressed(button);
bool patternValue = false;
if (_boolPatterns.ContainsKey(button))
if (_boolPatterns.TryGetValue(button, out var pattern))
{
// I can't figure a way to determine right here if it should Peek or Get.
patternValue = _boolPatterns[button].PeekNextValue();
patternValue = pattern.PeekNextValue();
}
source ^= patternValue;
@ -131,19 +131,9 @@ namespace BizHawk.Client.Common
}
public int AxisValue(string name)
{
if (_axisPatterns.ContainsKey(name))
{
return _axisPatterns[name].PeekNextValue();
}
if (Source == null)
{
return 0;
}
return Source.AxisValue(name);
}
=> _axisPatterns.TryGetValue(name, out var pattern)
? pattern.PeekNextValue()
: Source?.AxisValue(name) ?? 0;
public IReadOnlyCollection<(string Name, int Strength)> GetHapticsSnapshot() => Source.GetHapticsSnapshot();

View File

@ -352,12 +352,8 @@ namespace BizHawk.Client.Common
if (Movie.IsAtEnd() && Movie.Core == CoreNames.Gambatte)
{
var coreCycles = (ulong) ((Gameboy)Movie.Emulator).CycleCount;
var cyclesSaved = Movie.HeaderEntries.ContainsKey(HeaderKeys.CycleCount);
ulong previousCycles = 0;
if (cyclesSaved)
{
previousCycles = Convert.ToUInt64(Movie.HeaderEntries[HeaderKeys.CycleCount]);
}
var cyclesSaved = Movie.HeaderEntries.TryGetValue(HeaderKeys.CycleCount, out var previousCyclesStr);
var previousCycles = cyclesSaved ? Convert.ToUInt64(previousCyclesStr) : 0UL;
var cyclesMatch = previousCycles == coreCycles;
if (!cyclesSaved || !cyclesMatch)
{

View File

@ -78,9 +78,6 @@ namespace BizHawk.Client.Common
};
public static double GetFrameRate(string systemId, bool pal)
{
var key = systemId + (pal ? "_PAL" : "");
return Rates.ContainsKey(key) ? Rates[key] : 60.0;
}
=> Rates.TryGetValue(systemId + (pal ? "_PAL" : ""), out var d) ? d : 60.0;
}
}

View File

@ -7,7 +7,7 @@ namespace BizHawk.Client.Common
{
public new string this[string key]
{
get => ContainsKey(key) ? base[key] : "";
get => TryGetValue(key, out var s) ? s : string.Empty;
set => base[key] = value;
}

View File

@ -20,14 +20,14 @@ namespace BizHawk.Client.Common
}
}
if (SystemOverrides.ContainsKey(systemId) && SystemOverrides[systemId].ContainsKey(key))
if (SystemOverrides.TryGetValue(systemId, out var overridesForSys) && overridesForSys.TryGetValue(key, out var c))
{
return SystemOverrides[systemId][key];
return c;
}
if (BaseMnemonicLookupTable.ContainsKey(key))
if (BaseMnemonicLookupTable.TryGetValue(key, out var c1))
{
return BaseMnemonicLookupTable[key];
return c1;
}
if (key.Length == 1)
@ -47,14 +47,14 @@ namespace BizHawk.Client.Common
.Replace("P4 ", "")
.Replace("Key ", "");
if (AxisSystemOverrides.ContainsKey(systemId) && AxisSystemOverrides[systemId].ContainsKey(key))
if (AxisSystemOverrides.TryGetValue(systemId, out var overridesForSystem) && overridesForSystem.TryGetValue(key, out var s))
{
return AxisSystemOverrides[systemId][key];
return s;
}
if (BaseAxisLookupTable.ContainsKey(key))
if (BaseAxisLookupTable.TryGetValue(key, out var s1))
{
return BaseAxisLookupTable[key];
return s1;
}
return button;

View File

@ -28,17 +28,9 @@ namespace BizHawk.Client.Common
public ulong Rerecords
{
get
{
if (!Header.ContainsKey(HeaderKeys.Rerecords))
{
// Modifying the header itself can cause a race condition between loading a movie and rendering the rerecord count, causing a movie's rerecord count to be overwritten with 0 during loading.
return 0;
}
return ulong.Parse(Header[HeaderKeys.Rerecords]);
}
get => Header.TryGetValue(HeaderKeys.Rerecords, out var s)
? ulong.Parse(s)
: 0UL; // Modifying the header itself can cause a race condition between loading a movie and rendering the rerecord count, causing a movie's rerecord count to be overwritten with 0 during loading.
set
{
if (Header[HeaderKeys.Rerecords] != value.ToString())
@ -51,7 +43,9 @@ namespace BizHawk.Client.Common
public virtual bool StartsFromSavestate
{
get => Header.ContainsKey(HeaderKeys.StartsFromSavestate) && bool.Parse(Header[HeaderKeys.StartsFromSavestate]);
// ReSharper disable SimplifyConditionalTernaryExpression
get => Header.TryGetValue(HeaderKeys.StartsFromSavestate, out var s) ? bool.Parse(s) : false;
// ReSharper restore SimplifyConditionalTernaryExpression
set
{
if (value)
@ -67,7 +61,9 @@ namespace BizHawk.Client.Common
public bool StartsFromSaveRam
{
get => Header.ContainsKey(HeaderKeys.StartsFromSaveram) && bool.Parse(Header[HeaderKeys.StartsFromSaveram]);
// ReSharper disable SimplifyConditionalTernaryExpression
get => Header.TryGetValue(HeaderKeys.StartsFromSaveram, out var s) ? bool.Parse(s) : false;
// ReSharper restore SimplifyConditionalTernaryExpression
set
{
if (value)
@ -79,17 +75,14 @@ namespace BizHawk.Client.Common
}
else
{
if (Header.ContainsKey(HeaderKeys.StartsFromSaveram))
{
Header.Remove(HeaderKeys.StartsFromSaveram);
}
Header.Remove(HeaderKeys.StartsFromSaveram);
}
}
}
public string GameName
{
get => Header.ContainsKey(HeaderKeys.GameName) ? Header[HeaderKeys.GameName] : "";
get => Header.TryGetValue(HeaderKeys.GameName, out var s) ? s : string.Empty;
set
{
if (Header[HeaderKeys.GameName] != value)
@ -102,7 +95,7 @@ namespace BizHawk.Client.Common
public string SystemID
{
get => Header.ContainsKey(HeaderKeys.Platform) ? Header[HeaderKeys.Platform] : "";
get => Header.TryGetValue(HeaderKeys.Platform, out var s) ? s : string.Empty;
set
{
if (Header[HeaderKeys.Platform] != value)
@ -216,7 +209,9 @@ namespace BizHawk.Client.Common
return sb.ToString();
}
public bool IsPal => Header.ContainsKey(HeaderKeys.Pal) && Header[HeaderKeys.Pal] == "1";
// ReSharper disable SimplifyConditionalTernaryExpression
public bool IsPal => Header.TryGetValue(HeaderKeys.Pal, out var s) ? s == "1" : false;
// ReSharper restore SimplifyConditionalTernaryExpression
public string TextSavestate { get; set; }
public byte[] BinarySavestate { get; set; }

View File

@ -70,19 +70,17 @@ namespace BizHawk.Client.Common
double dblSeconds;
var core = Header[HeaderKeys.Core];
if (Header.ContainsKey(HeaderKeys.CycleCount) && (core == CoreNames.Gambatte || core == CoreNames.SubGbHawk))
if (Header.TryGetValue(HeaderKeys.CycleCount, out var numCyclesStr) && (core == CoreNames.Gambatte || core == CoreNames.SubGbHawk))
{
ulong numCycles = Convert.ToUInt64(Header[HeaderKeys.CycleCount]);
var numCycles = Convert.ToUInt64(numCyclesStr);
double cyclesPerSecond = PlatformFrameRates.GetFrameRate("GB_Clock", IsPal);
dblSeconds = numCycles / cyclesPerSecond;
}
else
{
ulong numFrames = (ulong) FrameCount;
if (Header.ContainsKey(HeaderKeys.VBlankCount))
{
numFrames = Convert.ToUInt64(Header[HeaderKeys.VBlankCount]);
}
var numFrames = Header.TryGetValue(HeaderKeys.VBlankCount, out var numFramesStr)
? Convert.ToUInt64(numFramesStr)
: (ulong) FrameCount;
dblSeconds = numFrames / FrameRate;
}

View File

@ -17,9 +17,7 @@ namespace BizHawk.Client.Common
public string SavestateBinaryBase64Blob
{
get => ContainsKey(HeaderKeys.SavestateBinaryBase64Blob)
? this[HeaderKeys.SavestateBinaryBase64Blob]
: null;
get => TryGetValue(HeaderKeys.SavestateBinaryBase64Blob, out var s) ? s : null;
set
{
if (value == null)
@ -35,18 +33,8 @@ namespace BizHawk.Client.Common
public new string this[string key]
{
get => ContainsKey(key) ? base[key] : "";
set
{
if (ContainsKey(key))
{
base[key] = value;
}
else
{
Add(key, value);
}
}
get => TryGetValue(key, out var s) ? s : string.Empty;
set => base[key] = value;
}
public new void Clear()

View File

@ -137,19 +137,12 @@ namespace BizHawk.Client.EmuHawk
// saving works, those entries will still be preserved in the config file, tho
foreach (var button in controllerButtons)
{
Match m;
string categoryLabel;
if (categoryLabels.ContainsKey(button))
if (!categoryLabels.TryGetValue(button, out var categoryLabel))
{
categoryLabel = categoryLabels[button];
}
else if ((m = ButtonMatchesPlayer.Match(button)).Success)
{
categoryLabel = $"Player {m.Groups[1].Value}";
}
else
{
categoryLabel = "Console"; // anything that wants not console can set it in the categorylabels
var m = ButtonMatchesPlayer.Match(button);
categoryLabel = m.Success
? $"Player {m.Groups[1].Value}"
: "Console"; // anything that wants not console can set it in the categorylabels
}
if (!buckets.ContainsKey(categoryLabel))

View File

@ -195,15 +195,15 @@ namespace BizHawk.Client.EmuHawk
lvFirmwares.Items.Add(lvi);
// build the groups in the ListView as we go:
if (!groups.ContainsKey(sysID))
if (!groups.TryGetValue(sysID, out var group))
{
if (!SystemGroupNames.TryGetValue(sysID, out var name))
name = "FIX ME (FirmwaresConfig.cs)";
lvFirmwares.Groups.Add(sysID, name);
var lvg = lvFirmwares.Groups[lvFirmwares.Groups.Count - 1];
groups[sysID] = lvg;
group = groups[sysID] = lvg;
}
lvi.Group = groups[sysID];
lvi.Group = group;
}
// now that we have some items in the ListView, we can size some columns to sensible widths

View File

@ -381,10 +381,7 @@ namespace BizHawk.Client.EmuHawk
private char Remap(byte val)
{
if (_textTable.Any())
{
return _textTable.ContainsKey(val) ? _textTable[val] : '?';
}
if (_textTable.Count != 0) return _textTable.TryGetValue(val, out var c) ? c : '?';
if (val < ' ' || val >= 0x7F)
{

View File

@ -165,12 +165,7 @@ namespace BizHawk.Client.EmuHawk
public void DrawImage(string path, int x, int y, int? width = null, int? height = null, bool cache = true)
{
Image img;
if (_imageCache.ContainsKey(path))
{
img = _imageCache[path];
}
else
if (!_imageCache.TryGetValue(path, out var img))
{
img = Image.FromFile(path);
if (cache)
@ -195,12 +190,7 @@ namespace BizHawk.Client.EmuHawk
public void DrawImageRegion(string path, int sourceX, int sourceY, int sourceWidth, int sourceHeight, int destX, int destY, int? destWidth = null, int? destHeight = null)
{
Image img;
if (_imageCache.ContainsKey(path))
{
img = _imageCache[path];
}
else
if (!_imageCache.TryGetValue(path, out var img))
{
img = Image.FromFile(path);
_imageCache.Add(path, img);

View File

@ -105,9 +105,9 @@ namespace BizHawk.Client.EmuHawk
bw.Flush();
string md5 = _waveformTemp.HashMD5();
if (!_psgEntryTable.ContainsKey(md5))
if (!_psgEntryTable.TryGetValue(md5, out var entry))
{
var entry = new PsgEntry
entry = new PsgEntry
{
Name = md5,
WaveForm = waveform,
@ -122,7 +122,6 @@ namespace BizHawk.Client.EmuHawk
}
else
{
PsgEntry entry = _psgEntryTable[md5];
entry.Active = true;
// are we playing the same sample as before?
@ -141,7 +140,7 @@ namespace BizHawk.Client.EmuHawk
}
}
lvChannels.Items[i].SubItems[3].Text = _psgEntryTable[md5].Name;
lvChannels.Items[i].SubItems[3].Text = entry.Name;
}
if (sync)

View File

@ -802,15 +802,7 @@ namespace BizHawk.Common
var name = begin.Groups[1].Value;
ss.Push(curs);
var news = new Section { Name = name };
if (!curs.ContainsKey(name))
{
curs[name] = news;
}
else
{
throw new Exception($"Duplicate key \"{name}\" in serializer savestate!");
}
curs.Add(name, news);
curs = news;
}
else
@ -825,14 +817,7 @@ namespace BizHawk.Common
var key = parts[0];
// UGLY: adds whole string instead of splitting the key. later, split the key, and have the individual Sync methods give up that responsibility
if (!curs.Items.ContainsKey(key))
{
curs.Items[key] = parts[1];
}
else
{
throw new Exception($"Duplicate key \"{key}\" in serializer savestate!");
}
curs.Items.Add(key, parts[1]);
}
}

View File

@ -93,17 +93,9 @@ namespace BizHawk.Emulation.Common
foreach (var kvp in this)
{
if (!other.ContainsKey(kvp.Key))
{
return false;
}
var oval = other[kvp.Key];
if (oval.Length != kvp.Value.Length)
{
return false;
}
if (!other.TryGetValue(kvp.Key, out var oval) || oval.Length != kvp.Value.Length) return false;
}
// don't need to check keys present in other but not in this -- `Count` would differ
return true;
}

View File

@ -144,9 +144,9 @@ namespace BizHawk.Emulation.Common
ForcedCore = items.Length >= 8 ? items[7].ToLowerInvariant() : ""
};
if (!silent && DB.ContainsKey(game.Hash))
if (!silent && DB.TryGetValue(game.Hash, out var dupe))
{
Console.WriteLine("gamedb: Multiple hash entries {0}, duplicate detected on \"{1}\" and \"{2}\"", game.Hash, game.Name, DB[game.Hash].Name);
Console.WriteLine("gamedb: Multiple hash entries {0}, duplicate detected on \"{1}\" and \"{2}\"", game.Hash, game.Name, dupe.Name);
}
DB[game.Hash] = game;

View File

@ -85,7 +85,7 @@ namespace BizHawk.Emulation.Common
public string OptionValue(string option)
{
return Options.ContainsKey(option) ? Options[option] : null;
return Options.TryGetValue(option, out var s) ? s : null;
}
public int GetIntValue(string option)

View File

@ -88,21 +88,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
/// Adds a single metadata item to the Dictionary
/// </summary>
public void AddMetaData(BlockDescriptorTitle descriptor, string data)
{
// check whether entry already exists
bool check = MetaData.ContainsKey(descriptor);
if (check)
{
// already exists - update
MetaData[descriptor] = data;
}
else
{
// create new
MetaData.Add(descriptor, data);
}
}
=> MetaData[descriptor] = data;
/// <summary>
/// List containing the pulse timing values

View File

@ -63,20 +63,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
/// Adds a single metadata item to the Dictionary
/// </summary>
public void AddMetaData(BlockDescriptorTitle descriptor, string data)
{
// check whether entry already exists
bool check = MetaData.ContainsKey(descriptor);
if (check)
{
// already exists - update
MetaData[descriptor] = data;
}
else
{
// create new
MetaData.Add(descriptor, data);
}
}
=> MetaData[descriptor] = data;
/// <summary>
/// List containing the pulse timing values

View File

@ -223,19 +223,13 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
RomDetails = $"{_game.Name}\r\nSHA1:{Rom.HashSHA1()}\r\nMD5:{Rom.HashMD5()}\r\nMapper Impl \"{_mapper.GetType()}\"";
// Some games (ex. 3D tic tac toe), turn off the screen for extended periods, so we need to allow for this here.
if (_game.GetOptions().ContainsKey("SP_FRAME"))
if (_game.GetOptions().TryGetValue("SP_FRAME", out var spFrameStr) && spFrameStr == "true")
{
if (_game.GetOptions()["SP_FRAME"] == "true")
{
SP_FRAME = true;
}
SP_FRAME = true;
}
if (_game.GetOptions().ContainsKey("SP_RESET"))
if (_game.GetOptions().TryGetValue("SP_RESET", out var spResetStr) && spResetStr == "true")
{
if (_game.GetOptions()["SP_RESET"] == "true")
{
SP_RESET = true;
}
SP_RESET = true;
}
}

View File

@ -133,36 +133,30 @@ namespace BizHawk.Emulation.Cores.Atari.A7800Hawk
{
_isPAL = true;
}
if (dict.ContainsKey("board"))
{
s_mapper = dict["board"];
}
else
{
throw new Exception("No Board selected for this game");
}
if (!dict.TryGetValue("board", out s_mapper)) throw new Exception("No Board selected for this game");
// check if the game uses pokey or RAM
if (dict.ContainsKey("RAM"))
if (dict.TryGetValue("RAM", out var cartRAMStr))
{
int.TryParse(dict["RAM"], out cart_RAM);
int.TryParse(cartRAMStr, out cart_RAM);
}
if (dict.ContainsKey("Pokey"))
if (dict.TryGetValue("Pokey", out var pokeyStr))
{
bool.TryParse(dict["Pokey"], out is_pokey);
bool.TryParse(pokeyStr, out is_pokey);
}
if (dict.ContainsKey("Pokey_450"))
if (dict.TryGetValue("Pokey_450", out var pokey450Str))
{
bool.TryParse(dict["Pokey_450"], out is_pokey_450);
bool.TryParse(pokey450Str, out is_pokey_450);
}
// some games will not function with the high score bios
// if such a game is being played, tell the user and disable it
if (dict.ContainsKey("No_HS"))
if (dict.TryGetValue("No_HS", out var noHSStr))
{
bool.TryParse(dict["No_HS"], out var no_hs);
bool.TryParse(noHSStr, out var no_hs);
if (no_hs)
{

View File

@ -39,27 +39,10 @@ namespace BizHawk.Emulation.Cores.Intellivision
}
// look up hash in gamedb to see what mapper to use
// if none found default is zero
string hash_sha1 = null;
string s_mapper = null;
hash_sha1 = "sha1:" + rom.HashSHA1(16, rom.Length - 16);
var gi = Database.CheckDatabase(hash_sha1);
if (gi != null)
{
var dict = gi.GetOptions();
if (!dict.ContainsKey("board"))
{
throw new Exception("INTV gamedb entries must have a board identifier!");
}
s_mapper = dict["board"];
}
else
{
s_mapper = "0";
}
var gi = Database.CheckDatabase($"sha1:{rom.HashSHA1(16, rom.Length - 16)}");
if (gi != null && !gi.GetOptions().TryGetValue("board", out s_mapper)) throw new Exception("INTV gamedb entries must have a board identifier!");
_mapper = 0;
int.TryParse(s_mapper, out _mapper);
return rom.Length;

View File

@ -163,54 +163,35 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
//try generating a bootgod cart descriptor from the game database
var dict = gi.GetOptions();
cart.GameInfo = gi;
if (!dict.ContainsKey("board"))
throw new Exception("NES gamedb entries must have a board identifier!");
cart.BoardType = dict["board"];
if (dict.ContainsKey("system"))
cart.System = dict["system"];
cart.PrgSize = -1;
cart.VramSize = -1;
cart.WramSize = -1;
cart.ChrSize = -1;
if (dict.ContainsKey("PRG"))
cart.PrgSize = short.Parse(dict["PRG"]);
if (dict.ContainsKey("CHR"))
cart.ChrSize = short.Parse(dict["CHR"]);
if(dict.ContainsKey("VRAM"))
cart.VramSize = short.Parse(dict["VRAM"]);
if (dict.ContainsKey("WRAM"))
cart.WramSize = short.Parse(dict["WRAM"]);
if (dict.ContainsKey("PAD_H"))
cart.PadH = byte.Parse(dict["PAD_H"]);
if (dict.ContainsKey("PAD_V"))
cart.PadV = byte.Parse(dict["PAD_V"]);
if(dict.ContainsKey("MIR"))
if (dict["MIR"] == "H")
if (!dict.TryGetValue("board", out var board)) throw new Exception("NES gamedb entries must have a board identifier!");
cart.BoardType = board;
if (dict.TryGetValue("system", out var system)) cart.System = system;
cart.PrgSize = dict.TryGetValue("PRG", out var prgSizeStr) ? short.Parse(prgSizeStr) : -1;
cart.ChrSize = dict.TryGetValue("CHR", out var chrSizeStr) ? short.Parse(chrSizeStr) : -1;
cart.VramSize = dict.TryGetValue("VRAM", out var vramSizeStr) ? short.Parse(vramSizeStr) : -1;
cart.WramSize = dict.TryGetValue("WRAM", out var wramSizeStr) ? short.Parse(wramSizeStr) : -1;
if (dict.TryGetValue("PAD_H", out var padHStr)) cart.PadH = byte.Parse(padHStr);
if (dict.TryGetValue("PAD_V", out var padVStr)) cart.PadV = byte.Parse(padVStr);
if (dict.TryGetValue("MIR", out var mirStr))
{
if (mirStr == "H")
{
cart.PadV = 1; cart.PadH = 0;
}
else if (dict["MIR"] == "V")
else if (mirStr == "V")
{
cart.PadH = 1; cart.PadV = 0;
}
if (dict.ContainsKey("BAD"))
cart.Bad = true;
if (dict.ContainsKey("MMC3"))
cart.Chips.Add(dict["MMC3"]);
if (dict.ContainsKey("PCB"))
cart.Pcb = dict["PCB"];
if (dict.ContainsKey("BATT"))
cart.WramBattery = bool.Parse(dict["BATT"]);
if(dict.ContainsKey("palette"))
{
cart.Palette = dict["palette"];
}
if (dict.ContainsKey("vs_security"))
{
cart.VsSecurity = byte.Parse(dict["vs_security"]);
}
if (dict.ContainsKey("BAD")) cart.Bad = true;
if (dict.TryGetValue("MMC3", out var mmc3)) cart.Chips.Add(mmc3);
if (dict.TryGetValue("PCB", out var pcb)) cart.Pcb = pcb;
if (dict.TryGetValue("BATT", out var batteryStr)) cart.WramBattery = bool.Parse(batteryStr);
if (dict.TryGetValue("palette", out var palette)) cart.Palette = palette;
if (dict.TryGetValue("vs_security", out var vsSecurityStr)) cart.VsSecurity = byte.Parse(vsSecurityStr);
return cart;
}

View File

@ -58,9 +58,9 @@ namespace BizHawk.Emulation.Cores.Sony.PSX
Data = cbDeflater(fs, compressed_size);
//load lib if needed
if (TagsDictionary.ContainsKey("_lib"))
if (TagsDictionary.TryGetValue("_lib", out var relPath))
{
var fpLib = Path.Combine(Path.GetDirectoryName(fpPSF), TagsDictionary["_lib"]);
var fpLib = Path.Combine(Path.GetDirectoryName(fpPSF), relPath);
if (!File.Exists(fpLib))
return false;
PSF lib = new PSF();

View File

@ -64,7 +64,7 @@ namespace BizHawk.Emulation.Cores.Waterbox
for (int port = 0, devByteStart = 0; port < allPorts.Count; port++)
{
var portInfo = allPorts[port];
var deviceName = config.ContainsKey(port) ? config[port] : portInfo.DefaultDeviceShortName;
if (!config.TryGetValue(port, out var deviceName)) deviceName = portInfo.DefaultDeviceShortName;
finalDevices.Add(deviceName);
if (hiddenPorts.Contains(portInfo.ShortName))

View File

@ -233,14 +233,12 @@ namespace BizHawk.Emulation.DiscSystem
if (ccdSection.Name != "CLONECD")
throw new CCDParseException("Malformed CCD format: confusing first section name");
if (!ccdSection.ContainsKey("VERSION"))
if (!ccdSection.TryGetValue("VERSION", out var version))
throw new CCDParseException("Malformed CCD format: missing version in CloneCD section");
if(sections[1].Name != "DISC")
throw new CCDParseException("Malformed CCD format: section[1] isn't [Disc]");
int version = ccdSection["VERSION"];
return version;
}