diff --git a/BizHawk.Client.Common/ControllerBinding.cs b/BizHawk.Client.Common/ControllerBinding.cs index 62ce889c64..4dc638d23c 100644 --- a/BizHawk.Client.Common/ControllerBinding.cs +++ b/BizHawk.Client.Common/ControllerBinding.cs @@ -48,12 +48,12 @@ namespace BizHawk.Client.Common { get { - if (_buttons.Any(x => x.Value)) + if (_buttons.Any(b => b.Value)) { return true; } - return _floatButtons.Any(x => x.Value != 0); + return _floatButtons.Any(b => b.Value != 0); } } diff --git a/BizHawk.Client.Common/CoreFileProvider.cs b/BizHawk.Client.Common/CoreFileProvider.cs index 39555e81cf..d251915264 100644 --- a/BizHawk.Client.Common/CoreFileProvider.cs +++ b/BizHawk.Client.Common/CoreFileProvider.cs @@ -132,7 +132,7 @@ namespace BizHawk.Client.Common public static void SyncCoreCommInputSignals(CoreComm target) { string superhack = null; - if (target.CoreFileProvider != null && target.CoreFileProvider is CoreFileProvider) + if (target.CoreFileProvider is CoreFileProvider) { superhack = ((CoreFileProvider)target.CoreFileProvider).SubfileDirectory; } diff --git a/BizHawk.Client.Common/QuickBmpFile.cs b/BizHawk.Client.Common/QuickBmpFile.cs index 5cb4965733..d4a5f7a5a2 100644 --- a/BizHawk.Client.Common/QuickBmpFile.cs +++ b/BizHawk.Client.Common/QuickBmpFile.cs @@ -2,6 +2,7 @@ using System.IO; using System.Runtime.InteropServices; +using BizHawk.Common; using BizHawk.Emulation.Common; namespace BizHawk.Client.Common @@ -267,19 +268,21 @@ namespace BizHawk.Client.Common fixed (byte* srcp = src) fixed (int* dstp = dst) { - using (new BizHawk.Common.SimpleTime("Blit")) - Blit(new BMP - { - Data = (int*)srcp, - Width = in_w, - Height = in_h - }, - new BMP - { - Data = dstp, - Width = v.BufferWidth, - Height = v.BufferHeight, - }); + using (new SimpleTime("Blit")) + { + Blit(new BMP + { + Data = (int*)srcp, + Width = in_w, + Height = in_h + }, + new BMP + { + Data = dstp, + Width = v.BufferWidth, + Height = v.BufferHeight, + }); + } } return true; @@ -311,19 +314,21 @@ namespace BizHawk.Client.Common fixed (int* srcp = src) fixed (byte* dstp = dst) { - using (new BizHawk.Common.SimpleTime("Blit")) - Blit(new BMP - { - Data = srcp, - Width = v.BufferWidth, - Height = v.BufferHeight - }, - new BMP - { - Data = (int*)dstp, - Width = w, - Height = h, - }); + using (new SimpleTime("Blit")) + { + Blit(new BMP + { + Data = srcp, + Width = v.BufferWidth, + Height = v.BufferHeight + }, + new BMP + { + Data = (int*)dstp, + Width = w, + Height = h, + }); + } } s.Write(dst, 0, dst.Length); diff --git a/BizHawk.Client.Common/RomLoader.cs b/BizHawk.Client.Common/RomLoader.cs index f6ef4f4aac..c0d2e21ab1 100644 --- a/BizHawk.Client.Common/RomLoader.cs +++ b/BizHawk.Client.Common/RomLoader.cs @@ -355,8 +355,7 @@ namespace BizHawk.Client.Common string discPath = e.Path; //--- load the disc in a context which will let us abort if it's going to take too long - var discMountJob = new DiscMountJob { IN_FromPath = discPath }; - discMountJob.IN_SlowLoadAbortThreshold = 8; + var discMountJob = new DiscMountJob { IN_FromPath = discPath, IN_SlowLoadAbortThreshold = 8 }; discMountJob.Run(); disc = discMountJob.OUT_Disc; diff --git a/BizHawk.Client.Common/SevenZipWriter.cs b/BizHawk.Client.Common/SevenZipWriter.cs index 2734ac1dc7..7e34127849 100644 --- a/BizHawk.Client.Common/SevenZipWriter.cs +++ b/BizHawk.Client.Common/SevenZipWriter.cs @@ -339,8 +339,7 @@ namespace BizHawk.Client.Common this.path = path; this.compressionlevel = compressionlevel; - svc = new SevenZip.SevenZipCompressor(); - svc.ArchiveFormat = SevenZip.OutArchiveFormat.Zip; + svc = new SevenZip.SevenZipCompressor { ArchiveFormat = SevenZip.OutArchiveFormat.Zip }; switch (compressionlevel) { diff --git a/BizHawk.Client.Common/SharpZipWriter.cs b/BizHawk.Client.Common/SharpZipWriter.cs index b5c8292c47..e95acc7e04 100644 --- a/BizHawk.Client.Common/SharpZipWriter.cs +++ b/BizHawk.Client.Common/SharpZipWriter.cs @@ -23,15 +23,10 @@ namespace BizHawk.Client.Common public void WriteItem(string name, Action callback) { - var e = new ZipEntry(name); - if (_level == 0) + var e = new ZipEntry(name) { - e.CompressionMethod = CompressionMethod.Stored; - } - else - { - e.CompressionMethod = CompressionMethod.Deflated; - } + CompressionMethod = _level == 0 ? CompressionMethod.Stored : CompressionMethod.Deflated + }; _zipOutputStream.PutNextEntry(e); callback(_zipOutputStream); diff --git a/BizHawk.Client.Common/config/Binding.cs b/BizHawk.Client.Common/config/Binding.cs index cd5c5a9403..029a7fde41 100644 --- a/BizHawk.Client.Common/config/Binding.cs +++ b/BizHawk.Client.Common/config/Binding.cs @@ -59,7 +59,7 @@ namespace BizHawk.Client.Common { get { - return Bindings.FirstOrDefault(x => x.DisplayName == index) ?? new Binding(); + return Bindings.FirstOrDefault(b => b.DisplayName == index) ?? new Binding(); } } @@ -80,7 +80,7 @@ namespace BizHawk.Client.Common // Add missing entries foreach (Binding defaultBinding in DefaultValues) { - var binding = Bindings.FirstOrDefault(x => x.DisplayName == defaultBinding.DisplayName); + var binding = Bindings.FirstOrDefault(b => b.DisplayName == defaultBinding.DisplayName); if (binding == null) { Bindings.Add(defaultBinding); @@ -96,7 +96,7 @@ namespace BizHawk.Client.Common } } - List entriesToRemove = (from entry in Bindings let binding = DefaultValues.FirstOrDefault(x => x.DisplayName == entry.DisplayName) where binding == null select entry).ToList(); + List entriesToRemove = (from entry in Bindings let binding = DefaultValues.FirstOrDefault(b => b.DisplayName == entry.DisplayName) where binding == null select entry).ToList(); // Remove entries that no longer exist in defaults foreach (Binding entry in entriesToRemove) @@ -105,7 +105,7 @@ namespace BizHawk.Client.Common } } - static List s_DefaultValues; + private static List s_DefaultValues; public static List DefaultValues { diff --git a/BizHawk.Client.Common/config/PathEntry.cs b/BizHawk.Client.Common/config/PathEntry.cs index 434644d1d8..f8178ab80e 100644 --- a/BizHawk.Client.Common/config/PathEntry.cs +++ b/BizHawk.Client.Common/config/PathEntry.cs @@ -7,11 +7,11 @@ namespace BizHawk.Client.Common { public class PathEntry { - public string SystemDisplayName; - public string Type; - public string Path; - public string System; - public int Ordinal; + public string SystemDisplayName { get; set; } + public string Type { get; set; } + public string Path { get; set; } + public string System { get; set; } + public int Ordinal { get; set; } public bool HasSystem(string systemID) { @@ -60,7 +60,7 @@ namespace BizHawk.Client.Common { get { - return Paths.FirstOrDefault(x => x.HasSystem(system) && x.Type == type) ?? TryGetDebugPath(system, type); + return Paths.FirstOrDefault(p => p.HasSystem(system) && p.Type == type) ?? TryGetDebugPath(system, type); } } @@ -94,7 +94,7 @@ namespace BizHawk.Client.Common // Add missing entries foreach (PathEntry defaultpath in DefaultValues) { - var path = Paths.FirstOrDefault(x => x.System == defaultpath.System && x.Type == defaultpath.Type); + var path = Paths.FirstOrDefault(p => p.System == defaultpath.System && p.Type == defaultpath.Type); if (path == null) { Paths.Add(defaultpath); @@ -106,7 +106,7 @@ namespace BizHawk.Client.Common // Remove entries that no longer exist in defaults foreach (PathEntry pathEntry in Paths) { - var path = DefaultValues.FirstOrDefault(x => x.System == pathEntry.System && x.Type == pathEntry.Type); + var path = DefaultValues.FirstOrDefault(p => p.System == pathEntry.System && p.Type == pathEntry.Type); if (path == null) { entriesToRemove.Add(pathEntry); @@ -119,10 +119,10 @@ namespace BizHawk.Client.Common } // Add missing displaynames - var missingDisplayPaths = Paths.Where(x => x.SystemDisplayName == null).ToList(); + var missingDisplayPaths = Paths.Where(p => p.SystemDisplayName == null).ToList(); foreach (PathEntry path in missingDisplayPaths) { - path.SystemDisplayName = DefaultValues.FirstOrDefault(x => x.System == path.System).SystemDisplayName; + path.SystemDisplayName = DefaultValues.First(p => p.System == path.System).SystemDisplayName; } } diff --git a/BizHawk.Client.Common/lua/EmuLuaLibrary.Emu.cs b/BizHawk.Client.Common/lua/EmuLuaLibrary.Emu.cs index 9dc6cb16eb..eb6f499207 100644 --- a/BizHawk.Client.Common/lua/EmuLuaLibrary.Emu.cs +++ b/BizHawk.Client.Common/lua/EmuLuaLibrary.Emu.cs @@ -89,9 +89,7 @@ namespace BizHawk.Client.Common } catch (NotImplementedException) { - Log(string.Format( - "Error: {0} does not yet implement disassemble()", - Emulator.Attributes().CoreName)); + Log($"Error: {Emulator.Attributes().CoreName} does not yet implement disassemble()"); return null; } } @@ -178,9 +176,7 @@ namespace BizHawk.Client.Common } catch (NotImplementedException) { - Log(string.Format( - "Error: {0} does not yet implement totalexecutedcycles()", - Emulator.Attributes().CoreName)); + Log($"Error: {Emulator.Attributes().CoreName} does not yet implement totalexecutedcycles()"); return 0; } @@ -238,7 +234,7 @@ namespace BizHawk.Client.Common } else { - Log(string.Format("Can not set lag information, {0} does not implement IInputPollable", Emulator.Attributes().CoreName)); + Log($"Can not set lag information, {Emulator.Attributes().CoreName} does not implement IInputPollable"); } } diff --git a/BizHawk.Client.Common/lua/EmuLuaLibrary.Events.cs b/BizHawk.Client.Common/lua/EmuLuaLibrary.Events.cs index 2dc629fb4e..ce0e1d03ea 100644 --- a/BizHawk.Client.Common/lua/EmuLuaLibrary.Events.cs +++ b/BizHawk.Client.Common/lua/EmuLuaLibrary.Events.cs @@ -135,13 +135,10 @@ namespace BizHawk.Client.Common private bool N64CoreTypeDynarec() { - if (Emulator is N64) + if ((Emulator as N64)?.GetSyncSettings().Core == N64SyncSettings.CoreType.Dynarec) { - if ((Emulator as N64).GetSyncSettings().Core == N64SyncSettings.CoreType.Dynarec) - { - Log("N64 Error: Memory callbacks are not implemented for Dynamic Recompiler core type\nUse Interpreter or Pure Interpreter\n"); - return true; - } + Log("N64 Error: Memory callbacks are not implemented for Dynamic Recompiler core type\nUse Interpreter or Pure Interpreter\n"); + return true; } return false; @@ -204,7 +201,7 @@ namespace BizHawk.Client.Common private void LogNotImplemented() { - Log(string.Format("Error: {0} does not yet implement input polling callbacks")); + Log($"Error: {Emulator.Attributes().CoreName} does not yet implement input polling callbacks"); } [LuaMethodAttributes( diff --git a/BizHawk.Client.Common/lua/EmuLuaLibrary.NES.cs b/BizHawk.Client.Common/lua/EmuLuaLibrary.NES.cs index a7053e2c37..14c49f4496 100644 --- a/BizHawk.Client.Common/lua/EmuLuaLibrary.NES.cs +++ b/BizHawk.Client.Common/lua/EmuLuaLibrary.NES.cs @@ -174,7 +174,7 @@ namespace BizHawk.Client.Common { var decoder = new NESGameGenieDecoder(code); Global.CheatList.RemoveRange( - Global.CheatList.Where(x => x.Address == decoder.Address)); + Global.CheatList.Where(c => c.Address == decoder.Address)); } } diff --git a/BizHawk.Client.Common/lua/LuaDocumentation.cs b/BizHawk.Client.Common/lua/LuaDocumentation.cs index a70a05810c..de5c224157 100644 --- a/BizHawk.Client.Common/lua/LuaDocumentation.cs +++ b/BizHawk.Client.Common/lua/LuaDocumentation.cs @@ -40,7 +40,7 @@ __Types and notation__ ** A standard Lua table "); - foreach (var library in this.Select(x => new { Name = x.Library, Description = x.LibraryDescription }).Distinct()) + foreach (var library in this.Select(lf => new { Name = lf.Library, Description = lf.LibraryDescription }).Distinct()) { sb .AppendFormat("%%TAB {0}%%", library.Name) @@ -54,7 +54,7 @@ __Types and notation__ .AppendLine(); } - foreach (var func in this.Where(x => x.Library == library.Name)) + foreach (var func in this.Where(lf => lf.Library == library.Name)) { sb .AppendFormat("__{0}.{1}__%%%", func.Library, func.Name) diff --git a/BizHawk.Client.Common/lua/LuaFile.cs b/BizHawk.Client.Common/lua/LuaFile.cs index 4481e21887..f50a890b6c 100644 --- a/BizHawk.Client.Common/lua/LuaFile.cs +++ b/BizHawk.Client.Common/lua/LuaFile.cs @@ -20,7 +20,7 @@ CurrentDirectory = System.IO.Path.GetDirectoryName(path); } - public LuaFile(bool isSeparator) + private LuaFile(bool isSeparator) { IsSeparator = isSeparator; Name = ""; @@ -28,11 +28,13 @@ State = RunState.Disabled; } + public static LuaFile SeparatorInstance => new LuaFile(true); + public string Name { get; set; } - public string Path { get; set; } + public string Path { get; } public bool Enabled => State != RunState.Disabled; public bool Paused => State == RunState.Paused; - public bool IsSeparator { get; set; } + public bool IsSeparator { get; } public LuaInterface.Lua Thread { get; set; } public bool FrameWaiting { get; set; } public string CurrentDirectory { get; set; } @@ -44,8 +46,6 @@ public RunState State { get; set; } - public static LuaFile SeparatorInstance => new LuaFile(true); - public void Stop() { State = RunState.Disabled; diff --git a/BizHawk.Client.Common/lua/LuaFileList.cs b/BizHawk.Client.Common/lua/LuaFileList.cs index 1038efb513..678a4c7809 100644 --- a/BizHawk.Client.Common/lua/LuaFileList.cs +++ b/BizHawk.Client.Common/lua/LuaFileList.cs @@ -45,7 +45,7 @@ namespace BizHawk.Client.Common public void StopAllScripts() { - ForEach(x => x.State = LuaFile.RunState.Disabled); + ForEach(lf => lf.State = LuaFile.RunState.Disabled); } public new void Clear() diff --git a/BizHawk.Client.Common/lua/LuaFunctionList.cs b/BizHawk.Client.Common/lua/LuaFunctionList.cs index b8ca167846..45ec368722 100644 --- a/BizHawk.Client.Common/lua/LuaFunctionList.cs +++ b/BizHawk.Client.Common/lua/LuaFunctionList.cs @@ -11,7 +11,7 @@ namespace BizHawk.Client.Common { get { - return this.FirstOrDefault(x => x.Guid.ToString() == guid); + return this.FirstOrDefault(nlf => nlf.Guid.ToString() == guid); } } @@ -34,13 +34,13 @@ namespace BizHawk.Client.Common { if (Global.Emulator.InputCallbacksAvailable()) { - Global.Emulator.AsInputPollable().InputCallbacks.RemoveAll(this.Select(x => x.Callback)); + Global.Emulator.AsInputPollable().InputCallbacks.RemoveAll(this.Select(w => w.Callback)); } if (Global.Emulator.MemoryCallbacksAvailable()) { var memoryCallbacks = Global.Emulator.AsDebuggable().MemoryCallbacks; - memoryCallbacks.RemoveAll(this.Select(x => x.Callback)); + memoryCallbacks.RemoveAll(this.Select(w => w.Callback)); } Clear(); diff --git a/BizHawk.Client.Common/lua/LuaLibraryBase.cs b/BizHawk.Client.Common/lua/LuaLibraryBase.cs index 26445810ed..72ab308983 100644 --- a/BizHawk.Client.Common/lua/LuaLibraryBase.cs +++ b/BizHawk.Client.Common/lua/LuaLibraryBase.cs @@ -10,24 +10,25 @@ namespace BizHawk.Client.Common { public abstract class LuaLibraryBase { - public LuaLibraryBase(Lua lua) + protected LuaLibraryBase(Lua lua) { Lua = lua; } - public LuaLibraryBase(Lua lua, Action logOutputCallback) + protected LuaLibraryBase(Lua lua, Action logOutputCallback) : this(lua) { LogOutputCallback = logOutputCallback; } - public abstract string Name { get; } - public Action LogOutputCallback { get; set; } - public Lua Lua { get; set; } + protected static Lua CurrentThread { get; private set; } - public static Lua CurrentThread { get; private set; } - static Thread CurrentHostThread; - static object ThreadMutex = new object(); + private static Thread CurrentHostThread; + private static readonly object ThreadMutex = new object(); + + public abstract string Name { get; } + public Action LogOutputCallback { protected get; set; } + protected Lua Lua { get; } public static void ClearCurrentThread() { @@ -52,31 +53,6 @@ namespace BizHawk.Client.Common } } - protected void Log(object message) - { - LogOutputCallback?.Invoke(message.ToString()); - } - - public virtual void LuaRegister(Type callingLibrary, LuaDocumentation docs = null) - { - Lua.NewTable(Name); - - var luaAttr = typeof(LuaMethodAttributes); - - var methods = GetType() - .GetMethods() - .Where(m => m.GetCustomAttributes(luaAttr, false).Any()); - - foreach (var method in methods) - { - var luaMethodAttr = method.GetCustomAttributes(luaAttr, false).First() as LuaMethodAttributes; - var luaName = Name + "." + luaMethodAttr.Name; - Lua.RegisterFunction(luaName, this, method); - - docs?.Add(new LibraryFunction(Name, callingLibrary.Description(), method)); - } - } - protected static int LuaInt(object luaArg) { return (int)(double)luaArg; @@ -94,8 +70,7 @@ namespace BizHawk.Client.Common return null; } - double tryNum = double.NaN; - + double tryNum; var result = double.TryParse(color.ToString(), out tryNum); if (result) @@ -111,5 +86,30 @@ namespace BizHawk.Client.Common return null; } + + protected void Log(object message) + { + LogOutputCallback?.Invoke(message.ToString()); + } + + public void LuaRegister(Type callingLibrary, LuaDocumentation docs = null) + { + Lua.NewTable(Name); + + var luaAttr = typeof(LuaMethodAttributes); + + var methods = GetType() + .GetMethods() + .Where(m => m.GetCustomAttributes(luaAttr, false).Any()); + + foreach (var method in methods) + { + var luaMethodAttr = (LuaMethodAttributes)method.GetCustomAttributes(luaAttr, false).First(); + var luaName = Name + "." + luaMethodAttr.Name; + Lua.RegisterFunction(luaName, this, method); + + docs?.Add(new LibraryFunction(Name, callingLibrary.Description(), method)); + } + } } } diff --git a/BizHawk.Client.Common/movie/MovieSession.cs b/BizHawk.Client.Common/movie/MovieSession.cs index d01aa32c15..6d76a8e5ef 100644 --- a/BizHawk.Client.Common/movie/MovieSession.cs +++ b/BizHawk.Client.Common/movie/MovieSession.cs @@ -22,10 +22,11 @@ namespace BizHawk.Client.Common } /// + /// Gets the queued movie /// When initializing a movie, it will be stored here until Rom processes have been completed, then it will be moved to the Movie property /// If an existing movie is still active, it will remain in the Movie property while the new movie is queued /// - public IMovie QueuedMovie { get; set; } + public IMovie QueuedMovie { get; private set; } // This wrapper but the logic could change, don't make the client code understand these details public bool MovieIsQueued => QueuedMovie != null; @@ -95,7 +96,7 @@ namespace BizHawk.Client.Common MessageCallback?.Invoke(message); } - public void LatchMultitrackPlayerInput(IController playerSource, MultitrackRewiringControllerAdapter rewiredSource) + private void LatchMultitrackPlayerInput(IController playerSource, MultitrackRewiringControllerAdapter rewiredSource) { if (MultiTrack.IsActive) { @@ -435,7 +436,6 @@ namespace BizHawk.Client.Common } } - // Movie Load Refactor TODO: a better name /// /// Sets the Movie property with the QueuedMovie, clears the queued movie, and starts the new movie /// diff --git a/BizHawk.Client.Common/movie/PlatformFrameRates.cs b/BizHawk.Client.Common/movie/PlatformFrameRates.cs index 0f429d0157..c2db715444 100644 --- a/BizHawk.Client.Common/movie/PlatformFrameRates.cs +++ b/BizHawk.Client.Common/movie/PlatformFrameRates.cs @@ -10,75 +10,75 @@ namespace BizHawk.Client.Common // are we collecting them anywhere else? for avi-writing code perhaps? // just some constants, according to specs - private static readonly double PAL_CARRIER = 15625 * 283.75 + 25; // 4.43361875 MHz - private static readonly double NTSC_CARRIER = 4500000 * 227.5 / 286; // 3.579545454... MHz - private static readonly double PAL_N_CARRIER = 15625 * 229.25 + 25; // 3.58205625 MHz + private static readonly double PALCarrier = (15625 * 283.75) + 25; // 4.43361875 MHz + private static readonly double NTSCCarrier = 4500000 * 227.5 / 286; // 3.579545454... MHz + private static readonly double PALNCarrier = (15625 * 229.25) + 25; // 3.58205625 MHz - private static readonly Dictionary _rates = new Dictionary - { - { "NES", 60.098813897440515532 }, // discussion here: http://forums.nesdev.com/viewtopic.php?t=492 ; a rational expression would be (19687500 / 11) / ((341*262-0.529780.5)/3) -> (118125000 / 1965513) -> 60.098813897440515529533511098629 (so our chosen number is very close) - { "NES_PAL", 50.006977968268290849 }, - { "FDS", 60.098813897440515532 }, - { "FDS_PAL", 50.006977968268290849 }, - { "SNES", (double)21477272 / (4 * 341 * 262) }, // 60.098475521 - { "SNES_PAL", (double)21281370 / (4 * 341 * 312) }, // 50.0069789082 - { "SGB", (double)21477272 / (4 * 341 * 262) }, // 60.098475521 - { "SGB_PAL", (double)21281370 / (4 * 341 * 312) }, // 50.0069789082 - { "PCE", (7159090.90909090 / 455 / 263) }, // 59.8261054535 - { "PCECD", (7159090.90909090 / 455 / 263) }, // 59.8261054535 - { "SMS", (3579545 / 262.0 / 228.0) }, // 59.9227434043 - { "SMS_PAL", (3546893 / 313.0 / 228.0) }, // 49.7014320946 - { "GG", (3579545 / 262.0 / 228.0) }, // 59.9227434043 - { "GG_PAL", (3546893 / 313.0 / 228.0) }, // 49.7014320946 - { "SG", (3579545 / 262.0 / 228.0) }, // 59.9227434043 - { "SG_PAL", (3546893 / 313.0 / 228.0) }, // 49.7014320946 - { "NGP", (6144000.0 / (515 * 198)) }, // 60.2530155928 - { "VBOY", (20000000.0 / (259 * 384 * 4)) }, // 50.2734877735 - { "Lynx", 16000000.0 / (16 * 105 * 159) }, // 59.89817310572028 - { "WSWAN", (3072000.0 / (159 * 256)) }, // 75.4716981132 - { "GB", 262144.0 / 4389.0 }, // 59.7275005696 - { "GBC", 262144.0 / 4389.0 }, // 59.7275005696 - { "GBA", 262144.0 / 4389.0 }, // 59.7275005696 - { "GEN", 53693175 / (3420.0 * 262) }, - { "GEN_PAL", 53203424 / (3420.0 * 313) }, + private static readonly Dictionary Rates = new Dictionary + { + ["NES"] = 60.098813897440515532, // discussion here: http://forums.nesdev.com/viewtopic.php?t=492 ; a rational expression would be (19687500 / 11) / ((341*262-0.529780.5)/3) -> (118125000 / 1965513) -> 60.098813897440515529533511098629 (so our chosen number is very close) + ["NES_PAL"] = 50.006977968268290849, + ["FDS"] = 60.098813897440515532, + ["FDS_PAL"] = 50.006977968268290849, + ["SNES"] = (double)21477272 / (4 * 341 * 262), // 60.098475521 + ["SNES_PAL"] = (double)21281370 / (4 * 341 * 312), // 50.0069789082 + ["SGB"] = (double)21477272 / (4 * 341 * 262), // 60.098475521 + ["SGB_PAL"] = (double)21281370 / (4 * 341 * 312), // 50.0069789082 + ["PCE"] = (7159090.90909090 / 455 / 263), // 59.8261054535 + ["PCECD"] = (7159090.90909090 / 455 / 263), // 59.8261054535 + ["SMS"] = (3579545 / 262.0 / 228.0), // 59.9227434043 + ["SMS_PAL"] = (3546893 / 313.0 / 228.0), // 49.7014320946 + ["GG"] = (3579545 / 262.0 / 228.0), // 59.9227434043 + ["GG_PAL"] = (3546893 / 313.0 / 228.0), // 49.7014320946 + ["SG"] = (3579545 / 262.0 / 228.0), // 59.9227434043 + ["SG_PAL"] = (3546893 / 313.0 / 228.0), // 49.7014320946 + ["NGP"] = (6144000.0 / (515 * 198)), // 60.2530155928 + ["VBOY"] = (20000000.0 / (259 * 384 * 4)), // 50.2734877735 + ["Lynx"] = 16000000.0 / (16 * 105 * 159), // 59.89817310572028 + ["WSWAN"] = (3072000.0 / (159 * 256)), // 75.4716981132 + ["GB"] = 262144.0 / 4389.0, // 59.7275005696 + ["GBC"] = 262144.0 / 4389.0, // 59.7275005696 + ["GBA"] = 262144.0 / 4389.0, // 59.7275005696 + ["GEN"] = 53693175 / (3420.0 * 262), + ["GEN_PAL"] = 53203424 / (3420.0 * 313), - // while the number of scanlines per frame is software controlled and variable, we - // enforce exactly 262 (NTSC) 312 (PAL) per reference time frame - { "A26", 315000000.0 / 88.0 / 262.0 / 228.0 }, // 59.922751013550531429197560173856 - // this pal clock ref is exact - { "A26_PAL", 3546895.0 / 312.0 / 228.0 }, // 49.860759671614934772829509671615 + // while the number of scanlines per frame is software controlled and variable, we + // enforce exactly 262 (NTSC) 312 (PAL) per reference time frame + ["A26"] = 315000000.0 / 88.0 / 262.0 / 228.0, // 59.922751013550531429197560173856 + // this pal clock ref is exact + ["A26_PAL"] = 3546895.0 / 312.0 / 228.0, // 49.860759671614934772829509671615 - { "A78", 59.9227510135505 }, - { "Coleco", 59.9227510135505 }, + ["A78"] = 59.9227510135505, + ["Coleco"] = 59.9227510135505, - // according to http://problemkaputt.de/psx-spx.htm - { "PSX", 44100.0 * 768 * 11 / 7 / 263 / 3413 }, // 59.292862562 - { "PSX_PAL", 44100.0 * 768 * 11 / 7 / 314 / 3406 }, // 49.7645593576 + // according to http://problemkaputt.de/psx-spx.htm + ["PSX"] = 44100.0 * 768 * 11 / 7 / 263 / 3413, // 59.292862562 + ["PSX_PAL"] = 44100.0 * 768 * 11 / 7 / 314 / 3406, // 49.7645593576 - { "C64_PAL", PAL_CARRIER * 2 / 9 / 312 / 63 }, - { "C64_NTSC", NTSC_CARRIER * 2 / 7 / 263 / 65 }, - { "C64_NTSC_OLD", NTSC_CARRIER * 2 / 7 / 262 / 64 }, - { "C64_DREAN", PAL_N_CARRIER * 2 / 7 / 312 / 65 }, - { "INTV", 59.92 } + ["C64_PAL"] = PALCarrier * 2 / 9 / 312 / 63, + ["C64_NTSC"] = NTSCCarrier * 2 / 7 / 263 / 65, + ["C64_NTSC_OLD"] = NTSCCarrier * 2 / 7 / 262 / 64, + ["C64_DREAN"] = PALNCarrier * 2 / 7 / 312 / 65, + ["INTV"] = 59.92 - // according to ryphecha, using - // clocks[2] = { 53.693182e06, 53.203425e06 }; //ntsc console, pal console - // lpf[2][2] = { { 263, 262.5 }, { 314, 312.5 } }; //ntsc,pal; noninterlaced, interlaced - // cpl[2] = { 3412.5, 3405 }; //ntsc mode, pal mode - // PAL PS1: 0, PAL Mode: 0, Interlaced: 0 --- 59.826106 (53.693182e06/(263*3412.5)) - // PAL PS1: 0, PAL Mode: 0, Interlaced: 1 --- 59.940060 (53.693182e06/(262.5*3412.5)) - // PAL PS1: 1, PAL Mode: 1, Interlaced: 0 --- 49.761427 (53.203425e06/(314*3405)) - // PAL PS1: 1, PAL Mode: 1, Interlaced: 1 --- 50.000282(53.203425e06/(312.5*3405)) - }; + // according to ryphecha, using + // clocks[2] = { 53.693182e06, 53.203425e06 }; //ntsc console, pal console + // lpf[2][2] = { { 263, 262.5 }, { 314, 312.5 } }; //ntsc,pal; noninterlaced, interlaced + // cpl[2] = { 3412.5, 3405 }; //ntsc mode, pal mode + // PAL PS1: 0, PAL Mode: 0, Interlaced: 0 --- 59.826106 (53.693182e06/(263*3412.5)) + // PAL PS1: 0, PAL Mode: 0, Interlaced: 1 --- 59.940060 (53.693182e06/(262.5*3412.5)) + // PAL PS1: 1, PAL Mode: 1, Interlaced: 0 --- 49.761427 (53.203425e06/(314*3405)) + // PAL PS1: 1, PAL Mode: 1, Interlaced: 1 --- 50.000282(53.203425e06/(312.5*3405)) + }; public double this[string systemId, bool pal] { get { var key = systemId + (pal ? "_PAL" : ""); - if (_rates.ContainsKey(key)) + if (Rates.ContainsKey(key)) { - return _rates[key]; + return Rates[key]; } return 60.0; diff --git a/BizHawk.Client.Common/movie/bk2/Bk2ControllerAdapter.cs b/BizHawk.Client.Common/movie/bk2/Bk2ControllerAdapter.cs index fd42e5ce89..157da701e7 100644 --- a/BizHawk.Client.Common/movie/bk2/Bk2ControllerAdapter.cs +++ b/BizHawk.Client.Common/movie/bk2/Bk2ControllerAdapter.cs @@ -93,12 +93,8 @@ namespace BizHawk.Client.Common foreach (var button in playerSource.Definition.BoolButtons) { var bnp = ButtonNameParser.Parse(button); - if (bnp == null) - { - continue; - } - if (bnp.PlayerNum != playerNum) + if (bnp?.PlayerNum != playerNum) { continue; } @@ -110,12 +106,8 @@ namespace BizHawk.Client.Common foreach (var button in Definition.FloatControls) { var bnp = ButtonNameParser.Parse(button); - if (bnp == null) - { - continue; - } - if (bnp.PlayerNum != playerNum) + if (bnp?.PlayerNum != playerNum) { continue; } @@ -143,7 +135,7 @@ namespace BizHawk.Client.Common } /// - /// latches sticky buttons from Global.AutofireStickyXORAdapter + /// latches sticky buttons from /// public void LatchSticky() { @@ -162,7 +154,7 @@ namespace BizHawk.Client.Common { var def = Global.Emulator.ControllerDefinition; var trimmed = mnemonic.Replace("|", ""); - var buttons = Definition.ControlsOrdered.SelectMany(x => x).ToList(); + var buttons = Definition.ControlsOrdered.SelectMany(c => c).ToList(); var iterator = 0; foreach (var key in buttons) diff --git a/BizHawk.Client.Common/movie/bk2/StringLogs.cs b/BizHawk.Client.Common/movie/bk2/StringLogs.cs index e5585b84c3..1f7b6f320c 100644 --- a/BizHawk.Client.Common/movie/bk2/StringLogs.cs +++ b/BizHawk.Client.Common/movie/bk2/StringLogs.cs @@ -58,7 +58,7 @@ namespace BizHawk.Client.Common /// A dumb-ish IStringLog with storage on disk with no provision for recovering lost space, except upon Clear() /// The purpose here is to avoid having too complicated buggy logic or a dependency on sqlite or such. /// It should be faster than those alternatives, but wasteful of disk space. - /// It should also be easier to add new IList-like methods than dealing with a database + /// It should also be easier to add new IList<string>-like methods than dealing with a database /// internal class StreamStringLog : IStringLog { @@ -132,6 +132,7 @@ namespace BizHawk.Client.Common stream.Position = Offsets[index]; return br.ReadString(); } + set { stream.Position = stream.Length; @@ -179,8 +180,10 @@ namespace BizHawk.Client.Common index = log.Count; return false; } + return true; } + void System.Collections.IEnumerator.Reset() { index = -1; } public void Dispose() { } diff --git a/BizHawk.Client.Common/movie/bkm/BkmControllerAdapter.cs b/BizHawk.Client.Common/movie/bkm/BkmControllerAdapter.cs index bf9bb50814..2279ac91f8 100644 --- a/BizHawk.Client.Common/movie/bkm/BkmControllerAdapter.cs +++ b/BizHawk.Client.Common/movie/bkm/BkmControllerAdapter.cs @@ -33,12 +33,8 @@ namespace BizHawk.Client.Common foreach (var button in playerSource.Definition.BoolButtons) { var bnp = ButtonNameParser.Parse(button); - if (bnp == null) - { - continue; - } - if (bnp.PlayerNum != playerNum) + if (bnp?.PlayerNum != playerNum) { continue; } diff --git a/BizHawk.Client.Common/movie/conversions/MovieConversionExtensions.cs b/BizHawk.Client.Common/movie/conversions/MovieConversionExtensions.cs index 4a872c023f..4ed8359521 100644 --- a/BizHawk.Client.Common/movie/conversions/MovieConversionExtensions.cs +++ b/BizHawk.Client.Common/movie/conversions/MovieConversionExtensions.cs @@ -144,8 +144,7 @@ namespace BizHawk.Client.Common.MovieConversionExtensions } } - var tas = new TasMovie(newFilename, true); - tas.BinarySavestate = savestate; + var tas = new TasMovie(newFilename, true) { BinarySavestate = savestate }; tas.ClearLagLog(); var entries = old.GetLogEntries(); @@ -220,8 +219,7 @@ namespace BizHawk.Client.Common.MovieConversionExtensions } } - var tas = new TasMovie(newFilename, true); - tas.SaveRam = saveRam; + var tas = new TasMovie(newFilename, true) { SaveRam = saveRam }; tas.TasStateManager.Clear(); tas.ClearLagLog(); diff --git a/BizHawk.Client.Common/movie/import/Fm2Import.cs b/BizHawk.Client.Common/movie/import/Fm2Import.cs index 2f4ccbcd83..a822f65c1d 100644 --- a/BizHawk.Client.Common/movie/import/Fm2Import.cs +++ b/BizHawk.Client.Common/movie/import/Fm2Import.cs @@ -181,6 +181,7 @@ namespace BizHawk.Client.Common { return null; } + try { return Convert.FromBase64String(blob.Substring(7)); diff --git a/BizHawk.Client.Common/movie/import/PJMImport.cs b/BizHawk.Client.Common/movie/import/PJMImport.cs index 4097e57865..3527d84b88 100644 --- a/BizHawk.Client.Common/movie/import/PJMImport.cs +++ b/BizHawk.Client.Common/movie/import/PJMImport.cs @@ -347,7 +347,6 @@ namespace BizHawk.Client.Common string rightXRaw = new string(br.ReadChars(4)).Trim(); string rightYRaw = new string(br.ReadChars(4)).Trim(); - Tuple leftX = new Tuple("P1 LStick X", float.Parse(leftXRaw)); Tuple leftY = new Tuple("P1 LStick Y", float.Parse(leftYRaw)); Tuple rightX = new Tuple("P1 RStick X", float.Parse(rightXRaw)); diff --git a/BizHawk.Client.Common/movie/tasproj/StateManagerState.cs b/BizHawk.Client.Common/movie/tasproj/StateManagerState.cs index d0f23013aa..01574211cd 100644 --- a/BizHawk.Client.Common/movie/tasproj/StateManagerState.cs +++ b/BizHawk.Client.Common/movie/tasproj/StateManagerState.cs @@ -8,7 +8,7 @@ namespace BizHawk.Client.Common /// internal class StateManagerState : IDisposable { - private static long _stateId = 0; + private static long _stateId; private readonly TasStateManager _manager; private readonly long _id; diff --git a/BizHawk.Client.Common/movie/tasproj/TasMovie.Editing.cs b/BizHawk.Client.Common/movie/tasproj/TasMovie.Editing.cs index 8805d6a2fd..53eeba7aad 100644 --- a/BizHawk.Client.Common/movie/tasproj/TasMovie.Editing.cs +++ b/BizHawk.Client.Common/movie/tasproj/TasMovie.Editing.cs @@ -8,7 +8,7 @@ namespace BizHawk.Client.Common { public partial class TasMovie { - public TasMovieChangeLog ChangeLog; + public TasMovieChangeLog ChangeLog { get; set; } public override void RecordFrame(int frame, IController source) { @@ -136,7 +136,7 @@ namespace BizHawk.Client.Common bool endBatch = ChangeLog.BeginNewBatch("Remove Multiple Frames", true); ChangeLog.AddGeneralUndo(invalidateAfter, InputLogLength - 1); - foreach (var frame in frames.OrderByDescending(x => x)) // Removin them in reverse order allows us to remove by index; + foreach (var frame in frames.OrderByDescending(f => f)) // Removing them in reverse order allows us to remove by index; { if (frame < _log.Count) { diff --git a/BizHawk.Client.Common/movie/tasproj/TasStateManager.cs b/BizHawk.Client.Common/movie/tasproj/TasStateManager.cs index 3ad6d8ba90..cfa4af1c6c 100644 --- a/BizHawk.Client.Common/movie/tasproj/TasStateManager.cs +++ b/BizHawk.Client.Common/movie/tasproj/TasStateManager.cs @@ -230,7 +230,7 @@ namespace BizHawk.Client.Common if (BranchStates.Any() && Settings.EraseBranchStatesFirst) { - var kvp = BranchStates.Count() > 1 ? BranchStates.ElementAt(1) : BranchStates.ElementAt(0); + var kvp = BranchStates.Count > 1 ? BranchStates.ElementAt(1) : BranchStates.ElementAt(0); shouldRemove.X = kvp.Key; shouldRemove.Y = kvp.Value.Keys[0]; @@ -497,7 +497,7 @@ namespace BizHawk.Client.Common } List> statesToRemove = - States.Where(x => x.Key >= frame).ToList(); + States.Where(s => s.Key >= frame).ToList(); anyInvalidated = statesToRemove.Any(); @@ -873,7 +873,7 @@ namespace BizHawk.Client.Common // Loop through branch states for the given frame. SortedList stateList = BranchStates[frame]; - for (int i = 0; i < stateList.Count(); i++) + for (int i = 0; i < stateList.Count; i++) { // Don't check the branch containing the state to match. if (i == _movie.BranchIndexByHash(branchHash)) @@ -930,8 +930,8 @@ namespace BizHawk.Client.Common BranchStates[kvp.Key] = stateList; } - stateList.Add(branchHash, kvp.Value); // We aren't creating any new states, just adding a reference to an already-existing one; so Used doesn't need to be updated. + stateList.Add(branchHash, kvp.Value); } } diff --git a/BizHawk.Client.Common/rewind/Rewinder.cs b/BizHawk.Client.Common/rewind/Rewinder.cs index 5c6f82d0d3..6a30bdf11d 100644 --- a/BizHawk.Client.Common/rewind/Rewinder.cs +++ b/BizHawk.Client.Common/rewind/Rewinder.cs @@ -100,11 +100,7 @@ namespace BizHawk.Client.Common public void Clear() { - if (_rewindBuffer != null) - { - _rewindBuffer.Clear(); - } - + _rewindBuffer?.Clear(); _lastState = new byte[0]; } diff --git a/BizHawk.Client.Common/rewind/StreamBlobDatabase.cs b/BizHawk.Client.Common/rewind/StreamBlobDatabase.cs index b994b6233e..de19d0e375 100644 --- a/BizHawk.Client.Common/rewind/StreamBlobDatabase.cs +++ b/BizHawk.Client.Common/rewind/StreamBlobDatabase.cs @@ -12,12 +12,14 @@ namespace BizHawk.Client.Common /// public class StreamBlobDatabase : IDisposable { - private StreamBlobDatabaseBufferManager _mBufferManage; + private readonly StreamBlobDatabaseBufferManager _mBufferManage; + private readonly LinkedList _mBookmarks = new LinkedList(); + private readonly long _mCapacity; + private byte[] _mAllocatedBuffer; private Stream _mStream; - private LinkedList _mBookmarks = new LinkedList(); private LinkedListNode _mHead, _mTail; - private long _mCapacity, _mSize; + private long _mSize; public StreamBlobDatabase(bool onDisk, long capacity, StreamBlobDatabaseBufferManager mBufferManage) { @@ -42,22 +44,22 @@ namespace BizHawk.Client.Common /// /// Gets the amount of the buffer that's used /// - public long Size { get { return _mSize; } } + public long Size => _mSize; /// /// Gets the current fullness ratio (Size/Capacity). Note that this wont reach 100% due to the buffer size not being a multiple of a fixed savestate size. /// - public float FullnessRatio { get { return (float)((double)Size / (double)_mCapacity); } } + public float FullnessRatio => (float)((double)Size / (double)_mCapacity); /// /// Gets the number of frames stored here /// - public int Count { get { return _mBookmarks.Count; } } + public int Count => _mBookmarks.Count; /// /// Gets the underlying stream to /// - public Stream Stream { get { return _mStream; } } + public Stream Stream => _mStream; public void Dispose() { @@ -79,7 +81,7 @@ namespace BizHawk.Client.Common } /// - /// The push and pop semantics are for historical reasons and not resemblence to normal definitions + /// The push and pop semantics are for historical reasons and not resemblance to normal definitions /// public void Push(ArraySegment seg) { @@ -91,7 +93,7 @@ namespace BizHawk.Client.Common } /// - /// The push and pop semantics are for historical reasons and not resemblence to normal definitions + /// The push and pop semantics are for historical reasons and not resemblance to normal definitions /// public MemoryStream PopMemoryStream() { @@ -276,14 +278,11 @@ namespace BizHawk.Client.Common Length = length; } - public int Timestamp { get; private set; } - public long Index { get; private set; } - public int Length { get; private set; } + public int Timestamp { get; } + public long Index { get; } + public int Length { get; } - public long EndExclusive - { - get { return Index + Length; } - } + public long EndExclusive => Index + Length; } private static byte[] test_BufferManage(byte[] inbuf, ref long size, bool allocate) @@ -306,7 +305,7 @@ namespace BizHawk.Client.Common return null; } - static byte[] test_rewindFellationBuf; + private static byte[] test_rewindFellationBuf; private static void test(string[] args) { diff --git a/BizHawk.Client.Common/tools/CheatList.cs b/BizHawk.Client.Common/tools/CheatList.cs index e924fb6f42..0ff5060c0a 100644 --- a/BizHawk.Client.Common/tools/CheatList.cs +++ b/BizHawk.Client.Common/tools/CheatList.cs @@ -25,12 +25,12 @@ namespace BizHawk.Client.Common public int CheatCount { - get { return _cheatList.Count(x => !x.IsSeparator); } + get { return _cheatList.Count(c => !c.IsSeparator); } } public int ActiveCount { - get { return _cheatList.Count(x => x.Enabled); } + get { return _cheatList.Count(c => c.Enabled); } } public bool Changes @@ -124,7 +124,7 @@ namespace BizHawk.Client.Common cheat.Changed += CheatChanged; if (Contains(cheat)) { - _cheatList.Remove(Global.CheatList.FirstOrDefault(x => x.Domain == cheat.Domain && x.Address == cheat.Address)); + _cheatList.Remove(Global.CheatList.FirstOrDefault(c => c.Domain == cheat.Domain && c.Address == cheat.Address)); } _cheatList.Add(cheat); @@ -140,16 +140,16 @@ namespace BizHawk.Client.Common Changes = true; } - public void Insert(int index, Cheat c) + public void Insert(int index, Cheat cheat) { - c.Changed += CheatChanged; - if (_cheatList.Any(x => x.Domain == c.Domain && x.Address == c.Address)) + cheat.Changed += CheatChanged; + if (_cheatList.Any(c => c.Domain == cheat.Domain && c.Address == cheat.Address)) { - _cheatList.First(x => x.Domain == c.Domain && x.Address == c.Address).Enable(); + _cheatList.First(c => c.Domain == cheat.Domain && c.Address == cheat.Address).Enable(); } else { - _cheatList.Insert(index, c); + _cheatList.Insert(index, cheat); } Changes = true; @@ -169,9 +169,9 @@ namespace BizHawk.Client.Common return true; } - public bool Remove(Cheat c) + public bool Remove(Cheat cheat) { - var result = _cheatList.Remove(c); + var result = _cheatList.Remove(cheat); if (result) { Changes = true; @@ -516,15 +516,15 @@ namespace BizHawk.Client.Common if (reverse) { _cheatList = _cheatList - .OrderByDescending(x => x.Name) - .ThenBy(x => x.Address ?? 0) + .OrderByDescending(c => c.Name) + .ThenBy(c => c.Address ?? 0) .ToList(); } else { _cheatList = _cheatList - .OrderBy(x => x.Name) - .ThenBy(x => x.Address ?? 0) + .OrderBy(c => c.Name) + .ThenBy(c => c.Address ?? 0) .ToList(); } @@ -533,15 +533,15 @@ namespace BizHawk.Client.Common if (reverse) { _cheatList = _cheatList - .OrderByDescending(x => x.Address ?? 0) - .ThenBy(x => x.Name) + .OrderByDescending(c => c.Address ?? 0) + .ThenBy(c => c.Name) .ToList(); } else { _cheatList = _cheatList - .OrderBy(x => x.Address ?? 0) - .ThenBy(x => x.Name) + .OrderBy(c => c.Address ?? 0) + .ThenBy(c => c.Name) .ToList(); } @@ -550,17 +550,17 @@ namespace BizHawk.Client.Common if (reverse) { _cheatList = _cheatList - .OrderByDescending(x => x.Value ?? 0) - .ThenBy(x => x.Name) - .ThenBy(x => x.Address ?? 0) + .OrderByDescending(c => c.Value ?? 0) + .ThenBy(c => c.Name) + .ThenBy(c => c.Address ?? 0) .ToList(); } else { _cheatList = _cheatList - .OrderBy(x => x.Value ?? 0) - .ThenBy(x => x.Name) - .ThenBy(x => x.Address ?? 0) + .OrderBy(c => c.Value ?? 0) + .ThenBy(c => c.Name) + .ThenBy(c => c.Address ?? 0) .ToList(); } @@ -569,17 +569,17 @@ namespace BizHawk.Client.Common if (reverse) { _cheatList = _cheatList - .OrderByDescending(x => x.Compare ?? 0) - .ThenBy(x => x.Name) - .ThenBy(x => x.Address ?? 0) + .OrderByDescending(c => c.Compare ?? 0) + .ThenBy(c => c.Name) + .ThenBy(c => c.Address ?? 0) .ToList(); } else { _cheatList = _cheatList - .OrderBy(x => x.Compare ?? 0) - .ThenBy(x => x.Name) - .ThenBy(x => x.Address ?? 0) + .OrderBy(c => c.Compare ?? 0) + .ThenBy(c => c.Name) + .ThenBy(c => c.Address ?? 0) .ToList(); } @@ -588,17 +588,17 @@ namespace BizHawk.Client.Common if (reverse) { _cheatList = _cheatList - .OrderByDescending(x => x.Enabled) - .ThenBy(x => x.Name) - .ThenBy(x => x.Address ?? 0) + .OrderByDescending(c => c.Enabled) + .ThenBy(c => c.Name) + .ThenBy(c => c.Address ?? 0) .ToList(); } else { _cheatList = _cheatList - .OrderBy(x => x.Enabled) - .ThenBy(x => x.Name) - .ThenBy(x => x.Address ?? 0) + .OrderBy(c => c.Enabled) + .ThenBy(c => c.Name) + .ThenBy(c => c.Address ?? 0) .ToList(); } @@ -607,17 +607,17 @@ namespace BizHawk.Client.Common if (reverse) { _cheatList = _cheatList - .OrderByDescending(x => x.Domain) - .ThenBy(x => x.Name) - .ThenBy(x => x.Address ?? 0) + .OrderByDescending(c => c.Domain) + .ThenBy(c => c.Name) + .ThenBy(c => c.Address ?? 0) .ToList(); } else { _cheatList = _cheatList - .OrderBy(x => x.Domain) - .ThenBy(x => x.Name) - .ThenBy(x => x.Address ?? 0) + .OrderBy(c => c.Domain) + .ThenBy(c => c.Name) + .ThenBy(c => c.Address ?? 0) .ToList(); } @@ -626,17 +626,17 @@ namespace BizHawk.Client.Common if (reverse) { _cheatList = _cheatList - .OrderByDescending(x => ((int)x.Size)) - .ThenBy(x => x.Name) - .ThenBy(x => x.Address ?? 0) + .OrderByDescending(c => ((int)c.Size)) + .ThenBy(c => c.Name) + .ThenBy(c => c.Address ?? 0) .ToList(); } else { _cheatList = _cheatList - .OrderBy(x => ((int)x.Size)) - .ThenBy(x => x.Name) - .ThenBy(x => x.Address ?? 0) + .OrderBy(c => ((int)c.Size)) + .ThenBy(c => c.Name) + .ThenBy(c => c.Address ?? 0) .ToList(); } @@ -645,17 +645,17 @@ namespace BizHawk.Client.Common if (reverse) { _cheatList = _cheatList - .OrderByDescending(x => x.BigEndian) - .ThenBy(x => x.Name) - .ThenBy(x => x.Address ?? 0) + .OrderByDescending(c => c.BigEndian) + .ThenBy(c => c.Name) + .ThenBy(c => c.Address ?? 0) .ToList(); } else { _cheatList = _cheatList - .OrderBy(x => x.BigEndian) - .ThenBy(x => x.Name) - .ThenBy(x => x.Address ?? 0) + .OrderBy(c => c.BigEndian) + .ThenBy(c => c.Name) + .ThenBy(c => c.Address ?? 0) .ToList(); } @@ -664,17 +664,17 @@ namespace BizHawk.Client.Common if (reverse) { _cheatList = _cheatList - .OrderByDescending(x => x.Type) - .ThenBy(x => x.Name) - .ThenBy(x => x.Address ?? 0) + .OrderByDescending(c => c.Type) + .ThenBy(c => c.Name) + .ThenBy(c => c.Address ?? 0) .ToList(); } else { _cheatList = _cheatList - .OrderBy(x => x.Type) - .ThenBy(x => x.Name) - .ThenBy(x => x.Address ?? 0) + .OrderBy(c => c.Type) + .ThenBy(c => c.Name) + .ThenBy(c => c.Address ?? 0) .ToList(); } @@ -683,17 +683,17 @@ namespace BizHawk.Client.Common if (reverse) { _cheatList = _cheatList - .OrderByDescending(x => x.ComparisonType) - .ThenBy(x => x.Name) - .ThenBy(x => x.Address ?? 0) + .OrderByDescending(c => c.ComparisonType) + .ThenBy(c => c.Name) + .ThenBy(c => c.Address ?? 0) .ToList(); } else { _cheatList = _cheatList - .OrderBy(x => x.ComparisonType) - .ThenBy(x => x.Name) - .ThenBy(x => x.Address ?? 0) + .OrderBy(c => c.ComparisonType) + .ThenBy(c => c.Name) + .ThenBy(c => c.Address ?? 0) .ToList(); } @@ -722,15 +722,15 @@ namespace BizHawk.Client.Common public Cheat Cheat { get; private set; } } - public const string NAME = "NamesColumn"; - public const string ADDRESS = "AddressColumn"; - public const string VALUE = "ValueColumn"; - public const string COMPARE = "CompareColumn"; - public const string ON = "OnColumn"; - public const string DOMAIN = "DomainColumn"; - public const string SIZE = "SizeColumn"; - public const string ENDIAN = "EndianColumn"; - public const string TYPE = "DisplayTypeColumn"; + private const string NAME = "NamesColumn"; + private const string ADDRESS = "AddressColumn"; + private const string VALUE = "ValueColumn"; + private const string COMPARE = "CompareColumn"; + private const string ON = "OnColumn"; + private const string DOMAIN = "DomainColumn"; + private const string SIZE = "SizeColumn"; + private const string ENDIAN = "EndianColumn"; + private const string TYPE = "DisplayTypeColumn"; private const string COMPARISONTYPE = "ComparisonTypeColumn"; } } diff --git a/BizHawk.Client.Common/tools/RamSearchEngine.cs b/BizHawk.Client.Common/tools/RamSearchEngine.cs index c5695645ba..945312ff44 100644 --- a/BizHawk.Client.Common/tools/RamSearchEngine.cs +++ b/BizHawk.Client.Common/tools/RamSearchEngine.cs @@ -6,6 +6,7 @@ using BizHawk.Common; using BizHawk.Common.CollectionExtensions; using BizHawk.Emulation.Common; +// ReSharper disable PossibleInvalidCastExceptionInForeachLoop namespace BizHawk.Client.Common { public class RamSearchEngine @@ -34,14 +35,16 @@ namespace BizHawk.Client.Common public RamSearchEngine(Settings settings, IMemoryDomains memoryDomains) { - _settings = new Settings(memoryDomains); - _settings.Mode = settings.Mode; - _settings.Domain = settings.Domain; - _settings.Size = settings.Size; - _settings.CheckMisAligned = settings.CheckMisAligned; - _settings.Type = settings.Type; - _settings.BigEndian = settings.BigEndian; - _settings.PreviousType = settings.PreviousType; + _settings = new Settings(memoryDomains) + { + Mode = settings.Mode, + Domain = settings.Domain, + Size = settings.Size, + CheckMisAligned = settings.CheckMisAligned, + Type = settings.Type, + BigEndian = settings.BigEndian, + PreviousType = settings.PreviousType + }; } public RamSearchEngine(Settings settings, IMemoryDomains memoryDomains, Compare compareTo, long? compareValue, int? differentBy) @@ -153,9 +156,8 @@ namespace BizHawk.Client.Common _watchList[index].Previous, (_watchList[index] as IMiniWatchDetails).ChangeCount); } - else - { - return Watch.GenerateWatch( + + return Watch.GenerateWatch( _settings.Domain, _watchList[index].Address, _settings.Size, @@ -163,9 +165,7 @@ namespace BizHawk.Client.Common _settings.BigEndian, "", 0, - _watchList[index].Previous, - 0); - } + _watchList[index].Previous); } } @@ -212,11 +212,11 @@ namespace BizHawk.Client.Common if (_isSorted) { - listOfOne = Enumerable.Repeat(_watchList.BinarySearch(x => x.Address, address), 1); + listOfOne = Enumerable.Repeat(_watchList.BinarySearch(w => w.Address, address), 1); } else { - listOfOne = Enumerable.Repeat(_watchList.FirstOrDefault(x => x.Address == address), 1); + listOfOne = Enumerable.Repeat(_watchList.FirstOrDefault(w => w.Address == address), 1); } switch (_compareTo) @@ -235,19 +235,13 @@ namespace BizHawk.Client.Common } } - public int Count - { - get { return _watchList.Count; } - } + public int Count => _watchList.Count; - public Settings.SearchMode Mode { get { return _settings.Mode; } } + public Settings.SearchMode Mode => _settings.Mode; - public MemoryDomain Domain - { - get { return _settings.Domain; } - } + public MemoryDomain Domain => _settings.Domain; - public Compare CompareTo + public Compare CompareTo { get { @@ -294,10 +288,6 @@ namespace BizHawk.Client.Common watch.Update(_settings.PreviousType, _settings.Domain, _settings.BigEndian); } } - else - { - return; - } } public void SetType(DisplayType type) @@ -325,7 +315,7 @@ namespace BizHawk.Client.Common public void SetPreviousToCurrent() { - _watchList.ForEach(x => x.SetPreviousToCurrent(_settings.Domain, _settings.BigEndian)); + _watchList.ForEach(w => w.SetPreviousToCurrent(_settings.Domain, _settings.BigEndian)); } public void ClearChangeCounts() @@ -350,8 +340,8 @@ namespace BizHawk.Client.Common _history.AddState(_watchList); } - var addresses = watches.Select(x => x.Address); - var removeList = _watchList.Where(x => addresses.Contains(x.Address)).ToList(); + var addresses = watches.Select(w => w.Address); + var removeList = _watchList.Where(w => addresses.Contains(w.Address)).ToList(); _watchList = _watchList.Except(removeList).ToList(); } @@ -438,35 +428,25 @@ namespace BizHawk.Client.Common case WatchList.ADDRESS: if (reverse) { - _watchList = _watchList.OrderByDescending(x => x.Address).ToList(); + _watchList = _watchList.OrderByDescending(w => w.Address).ToList(); } else { - _watchList = _watchList.OrderBy(x => x.Address).ToList(); + _watchList = _watchList.OrderBy(w => w.Address).ToList(); _isSorted = true; } break; case WatchList.VALUE: - if (reverse) - { - _watchList = _watchList.OrderByDescending(x => GetValue(x.Address)).ToList(); - } - else - { - _watchList = _watchList.OrderBy(x => GetValue(x.Address)).ToList(); - } + _watchList = reverse + ? _watchList.OrderByDescending(w => GetValue(w.Address)).ToList() + : _watchList.OrderBy(w => GetValue(w.Address)).ToList(); break; case WatchList.PREV: - if (reverse) - { - _watchList = _watchList.OrderByDescending(x => x.Previous).ToList(); - } - else - { - _watchList = _watchList.OrderBy(x => x.Previous).ToList(); - } + _watchList = reverse + ? _watchList.OrderByDescending(w => w.Previous).ToList() + : _watchList.OrderBy(w => w.Previous).ToList(); break; case WatchList.CHANGES: @@ -476,28 +456,23 @@ namespace BizHawk.Client.Common { _watchList = _watchList .Cast() - .OrderByDescending(x => x.ChangeCount) + .OrderByDescending(w => w.ChangeCount) .Cast().ToList(); } else { _watchList = _watchList .Cast() - .OrderBy(x => x.ChangeCount) + .OrderBy(w => w.ChangeCount) .Cast().ToList(); } } break; case WatchList.DIFF: - if (reverse) - { - _watchList = _watchList.OrderByDescending(x => (GetValue(x.Address) - x.Previous)).ToList(); - } - else - { - _watchList = _watchList.OrderBy(x => (GetValue(x.Address) - x.Previous)).ToList(); - } + _watchList = reverse + ? _watchList.OrderByDescending(w => (GetValue(w.Address) - w.Previous)).ToList() + : _watchList.OrderBy(w => GetValue(w.Address) - w.Previous).ToList(); break; } @@ -556,56 +531,57 @@ namespace BizHawk.Client.Common { default: case ComparisonOperator.Equal: - return watchList.Where(x => GetValue(x.Address) == x.Previous); + return watchList.Where(w => GetValue(w.Address) == w.Previous); case ComparisonOperator.NotEqual: - return watchList.Where(x => GetValue(x.Address) != x.Previous); + return watchList.Where(w => GetValue(w.Address) != w.Previous); case ComparisonOperator.GreaterThan: if (_settings.Type == DisplayType.Float) { - return watchList.Where(x => ToFloat(GetValue(x.Address)) > ToFloat(x.Previous)); + return watchList.Where(w => ToFloat(GetValue(w.Address)) > ToFloat(w.Previous)); } - return watchList.Where(x => SignExtendAsNeeded(GetValue(x.Address)) > SignExtendAsNeeded(x.Previous)); + return watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) > SignExtendAsNeeded(w.Previous)); case ComparisonOperator.GreaterThanEqual: if (_settings.Type == DisplayType.Float) { - return watchList.Where(x => ToFloat(GetValue(x.Address)) >= ToFloat(x.Previous)); + return watchList.Where(w => ToFloat(GetValue(w.Address)) >= ToFloat(w.Previous)); } - return watchList.Where(x => SignExtendAsNeeded(GetValue(x.Address)) >= SignExtendAsNeeded(x.Previous)); + return watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) >= SignExtendAsNeeded(w.Previous)); case ComparisonOperator.LessThan: if (_settings.Type == DisplayType.Float) { - return watchList.Where(x => ToFloat(GetValue(x.Address)) < ToFloat(x.Previous)); + return watchList.Where(w => ToFloat(GetValue(w.Address)) < ToFloat(w.Previous)); } - return watchList.Where(x => SignExtendAsNeeded(GetValue(x.Address)) < SignExtendAsNeeded(x.Previous)); + return watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) < SignExtendAsNeeded(w.Previous)); case ComparisonOperator.LessThanEqual: if (_settings.Type == DisplayType.Float) { - return watchList.Where(x => ToFloat(GetValue(x.Address)) <= ToFloat(x.Previous)); + return watchList.Where(w => ToFloat(GetValue(w.Address)) <= ToFloat(w.Previous)); } - return watchList.Where(x => SignExtendAsNeeded(GetValue(x.Address)) <= SignExtendAsNeeded(x.Previous)); + return watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) <= SignExtendAsNeeded(w.Previous)); case ComparisonOperator.DifferentBy: if (_differentBy.HasValue) { if (_settings.Type == DisplayType.Float) { - return watchList.Where(x => (ToFloat(GetValue(x.Address)) + _differentBy.Value == ToFloat(x.Previous)) - || (ToFloat(GetValue(x.Address)) - _differentBy.Value == ToFloat(x.Previous))); + return watchList.Where(w => ToFloat(GetValue(w.Address)) + _differentBy.Value == ToFloat(w.Previous) + || ToFloat(GetValue(w.Address)) - _differentBy.Value == ToFloat(w.Previous)); } - return watchList.Where(x => + return watchList.Where(w => { - long val = SignExtendAsNeeded(GetValue(x.Address)); - long prev = SignExtendAsNeeded(x.Previous); - return (val + _differentBy.Value == prev) || (val - _differentBy.Value == prev); + long val = SignExtendAsNeeded(GetValue(w.Address)); + long prev = SignExtendAsNeeded(w.Previous); + return val + _differentBy.Value == prev + || val - _differentBy.Value == prev; }); } else @@ -625,58 +601,58 @@ namespace BizHawk.Client.Common case ComparisonOperator.Equal: if (_settings.Type == DisplayType.Float) { - return watchList.Where(x => ToFloat(GetValue(x.Address)) == ToFloat(_compareValue.Value)); + return watchList.Where(w => ToFloat(GetValue(w.Address)) == ToFloat(_compareValue.Value)); } - return watchList.Where(x => GetValue(x.Address) == _compareValue.Value); + return watchList.Where(w => GetValue(w.Address) == _compareValue.Value); case ComparisonOperator.NotEqual: if (_settings.Type == DisplayType.Float) { - return watchList.Where(x => ToFloat(GetValue(x.Address)) != ToFloat(_compareValue.Value)); + return watchList.Where(w => ToFloat(GetValue(w.Address)) != ToFloat(_compareValue.Value)); } - return watchList.Where(x => GetValue(x.Address) != _compareValue.Value); + return watchList.Where(w => GetValue(w.Address) != _compareValue.Value); case ComparisonOperator.GreaterThan: if (_settings.Type == DisplayType.Float) { - return watchList.Where(x => ToFloat(GetValue(x.Address)) > ToFloat(_compareValue.Value)); + return watchList.Where(w => ToFloat(GetValue(w.Address)) > ToFloat(_compareValue.Value)); } - return watchList.Where(x => SignExtendAsNeeded(GetValue(x.Address)) > _compareValue.Value); + return watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) > _compareValue.Value); case ComparisonOperator.GreaterThanEqual: if (_settings.Type == DisplayType.Float) { - return watchList.Where(x => ToFloat(GetValue(x.Address)) >= ToFloat(_compareValue.Value)); + return watchList.Where(w => ToFloat(GetValue(w.Address)) >= ToFloat(_compareValue.Value)); } - return watchList.Where(x => SignExtendAsNeeded(GetValue(x.Address)) >= _compareValue.Value); + return watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) >= _compareValue.Value); case ComparisonOperator.LessThan: if (_settings.Type == DisplayType.Float) { - return watchList.Where(x => ToFloat(GetValue(x.Address)) < ToFloat(_compareValue.Value)); + return watchList.Where(w => ToFloat(GetValue(w.Address)) < ToFloat(_compareValue.Value)); } - return watchList.Where(x => SignExtendAsNeeded(GetValue(x.Address)) < _compareValue.Value); + return watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) < _compareValue.Value); case ComparisonOperator.LessThanEqual: if (_settings.Type == DisplayType.Float) { - return watchList.Where(x => ToFloat(GetValue(x.Address)) <= ToFloat(_compareValue.Value)); + return watchList.Where(w => ToFloat(GetValue(w.Address)) <= ToFloat(_compareValue.Value)); } - return watchList.Where(x => SignExtendAsNeeded(GetValue(x.Address)) <= _compareValue.Value); + return watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) <= _compareValue.Value); case ComparisonOperator.DifferentBy: if (_differentBy.HasValue) { if (_settings.Type == DisplayType.Float) { - return watchList.Where(x => (ToFloat(GetValue(x.Address)) + _differentBy.Value == _compareValue.Value) || - (ToFloat(GetValue(x.Address)) - _differentBy.Value == _compareValue.Value)); + return watchList.Where(w => ToFloat(GetValue(w.Address)) + _differentBy.Value == _compareValue.Value + || ToFloat(GetValue(w.Address)) - _differentBy.Value == _compareValue.Value); } - return watchList.Where(x - => (SignExtendAsNeeded(GetValue(x.Address)) + _differentBy.Value == _compareValue.Value) - || (SignExtendAsNeeded(GetValue(x.Address)) - _differentBy.Value == _compareValue.Value)); + return watchList.Where(w + => SignExtendAsNeeded(GetValue(w.Address)) + _differentBy.Value == _compareValue.Value + || SignExtendAsNeeded(GetValue(w.Address)) - _differentBy.Value == _compareValue.Value); } throw new InvalidOperationException(); @@ -694,21 +670,22 @@ namespace BizHawk.Client.Common { default: case ComparisonOperator.Equal: - return watchList.Where(x => x.Address == _compareValue.Value); + return watchList.Where(w => w.Address == _compareValue.Value); case ComparisonOperator.NotEqual: - return watchList.Where(x => x.Address != _compareValue.Value); + return watchList.Where(w => w.Address != _compareValue.Value); case ComparisonOperator.GreaterThan: - return watchList.Where(x => x.Address > _compareValue.Value); + return watchList.Where(w => w.Address > _compareValue.Value); case ComparisonOperator.GreaterThanEqual: - return watchList.Where(x => x.Address >= _compareValue.Value); + return watchList.Where(w => w.Address >= _compareValue.Value); case ComparisonOperator.LessThan: - return watchList.Where(x => x.Address < _compareValue.Value); + return watchList.Where(w => w.Address < _compareValue.Value); case ComparisonOperator.LessThanEqual: - return watchList.Where(x => x.Address <= _compareValue.Value); + return watchList.Where(w => w.Address <= _compareValue.Value); case ComparisonOperator.DifferentBy: if (_differentBy.HasValue) { - return watchList.Where(x => (x.Address + _differentBy.Value == _compareValue.Value) || (x.Address - _differentBy.Value == _compareValue.Value)); + return watchList.Where(w => w.Address + _differentBy.Value == _compareValue.Value + || w.Address - _differentBy.Value == _compareValue.Value); } throw new InvalidOperationException(); @@ -728,39 +705,40 @@ namespace BizHawk.Client.Common case ComparisonOperator.Equal: return watchList .Cast() - .Where(x => x.ChangeCount == _compareValue.Value) + .Where(w => w.ChangeCount == _compareValue.Value) .Cast(); case ComparisonOperator.NotEqual: return watchList .Cast() - .Where(x => x.ChangeCount != _compareValue.Value) + .Where(w => w.ChangeCount != _compareValue.Value) .Cast(); case ComparisonOperator.GreaterThan: return watchList .Cast() - .Where(x => x.ChangeCount > _compareValue.Value) + .Where(w => w.ChangeCount > _compareValue.Value) .Cast(); case ComparisonOperator.GreaterThanEqual: return watchList .Cast() - .Where(x => x.ChangeCount >= _compareValue.Value) + .Where(w => w.ChangeCount >= _compareValue.Value) .Cast(); case ComparisonOperator.LessThan: return watchList .Cast() - .Where(x => x.ChangeCount < _compareValue.Value) + .Where(w => w.ChangeCount < _compareValue.Value) .Cast(); case ComparisonOperator.LessThanEqual: return watchList .Cast() - .Where(x => x.ChangeCount <= _compareValue.Value) + .Where(w => w.ChangeCount <= _compareValue.Value) .Cast(); case ComparisonOperator.DifferentBy: if (_differentBy.HasValue) { return watchList .Cast() - .Where(x => (x.ChangeCount + _differentBy.Value == _compareValue.Value) || (x.ChangeCount - _differentBy.Value == _compareValue.Value)) + .Where(w => w.ChangeCount + _differentBy.Value == _compareValue.Value + || w.ChangeCount - _differentBy.Value == _compareValue.Value) .Cast(); } @@ -781,57 +759,57 @@ namespace BizHawk.Client.Common case ComparisonOperator.Equal: if (_settings.Type == DisplayType.Float) { - return watchList.Where(x => (ToFloat(GetValue(x.Address)) - ToFloat(x.Previous)) == _compareValue.Value); + return watchList.Where(w => ToFloat(GetValue(w.Address)) - ToFloat(w.Previous) == _compareValue.Value); } - return watchList.Where(x => (SignExtendAsNeeded(GetValue(x.Address)) - SignExtendAsNeeded(x.Previous)) == _compareValue.Value); + return watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) - SignExtendAsNeeded(w.Previous) == _compareValue.Value); case ComparisonOperator.NotEqual: if (_settings.Type == DisplayType.Float) { - return watchList.Where(x => (ToFloat(GetValue(x.Address)) - x.Previous) != _compareValue.Value); + return watchList.Where(w => ToFloat(GetValue(w.Address)) - w.Previous != _compareValue.Value); } - return watchList.Where(x => (SignExtendAsNeeded(GetValue(x.Address)) - SignExtendAsNeeded(x.Previous)) != _compareValue.Value); + return watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) - SignExtendAsNeeded(w.Previous) != _compareValue.Value); case ComparisonOperator.GreaterThan: if (_settings.Type == DisplayType.Float) { - return watchList.Where(x => (ToFloat(GetValue(x.Address)) - x.Previous) > _compareValue.Value); + return watchList.Where(w => ToFloat(GetValue(w.Address)) - w.Previous > _compareValue.Value); } - return watchList.Where(x => (SignExtendAsNeeded(GetValue(x.Address)) - SignExtendAsNeeded(x.Previous)) > _compareValue.Value); + return watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) - SignExtendAsNeeded(w.Previous) > _compareValue.Value); case ComparisonOperator.GreaterThanEqual: if (_settings.Type == DisplayType.Float) { - return watchList.Where(x => (ToFloat(GetValue(x.Address)) - x.Previous) >= _compareValue.Value); + return watchList.Where(w => ToFloat(GetValue(w.Address)) - w.Previous >= _compareValue.Value); } - return watchList.Where(x => (SignExtendAsNeeded(GetValue(x.Address)) - SignExtendAsNeeded(x.Previous)) >= _compareValue.Value); + return watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) - SignExtendAsNeeded(w.Previous) >= _compareValue.Value); case ComparisonOperator.LessThan: if (_settings.Type == DisplayType.Float) { - return watchList.Where(x => (ToFloat(GetValue(x.Address)) - x.Previous) < _compareValue.Value); + return watchList.Where(w => ToFloat(GetValue(w.Address)) - w.Previous < _compareValue.Value); } - return watchList.Where(x => (SignExtendAsNeeded(GetValue(x.Address)) - SignExtendAsNeeded(x.Previous)) < _compareValue.Value); + return watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) - SignExtendAsNeeded(w.Previous) < _compareValue.Value); case ComparisonOperator.LessThanEqual: if (_settings.Type == DisplayType.Float) { - return watchList.Where(x => (ToFloat(GetValue(x.Address)) - x.Previous) <= _compareValue.Value); + return watchList.Where(w => ToFloat(GetValue(w.Address)) - w.Previous <= _compareValue.Value); } - return watchList.Where(x => (SignExtendAsNeeded(GetValue(x.Address)) - SignExtendAsNeeded(x.Previous)) <= _compareValue.Value); + return watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) - SignExtendAsNeeded(w.Previous) <= _compareValue.Value); case ComparisonOperator.DifferentBy: if (_differentBy.HasValue) { if (_settings.Type == DisplayType.Float) { - return watchList.Where(x => (ToFloat(GetValue(x.Address)) - x.Previous + _differentBy.Value == _compareValue) || - (ToFloat(GetValue(x.Address)) - x.Previous - _differentBy.Value == x.Previous)); + return watchList.Where(w => ToFloat(GetValue(w.Address)) - w.Previous + _differentBy.Value == _compareValue + || ToFloat(GetValue(w.Address)) - w.Previous - _differentBy.Value == w.Previous); } - return watchList.Where(x - => (SignExtendAsNeeded(GetValue(x.Address)) - SignExtendAsNeeded(x.Previous) + _differentBy.Value == _compareValue) - || (SignExtendAsNeeded(GetValue(x.Address)) - SignExtendAsNeeded(x.Previous) - _differentBy.Value == _compareValue)); + return watchList.Where(w + => SignExtendAsNeeded(GetValue(w.Address)) - SignExtendAsNeeded(w.Previous) + _differentBy.Value == _compareValue + || SignExtendAsNeeded(GetValue(w.Address)) - SignExtendAsNeeded(w.Previous) - _differentBy.Value == _compareValue); } throw new InvalidOperationException(); @@ -906,7 +884,7 @@ namespace BizHawk.Client.Common #region Classes - public interface IMiniWatch + private interface IMiniWatch { long Address { get; } long Previous { get; } // do not store sign extended variables in here. @@ -923,7 +901,7 @@ namespace BizHawk.Client.Common private sealed class MiniByteWatch : IMiniWatch { - public long Address { get; private set; } + public long Address { get; } private byte _previous; public MiniByteWatch(MemoryDomain domain, long addr) @@ -942,7 +920,7 @@ namespace BizHawk.Client.Common private sealed class MiniWordWatch : IMiniWatch { - public long Address { get; private set; } + public long Address { get; } private ushort _previous; public MiniWordWatch(MemoryDomain domain, long addr, bool bigEndian) @@ -951,10 +929,7 @@ namespace BizHawk.Client.Common _previous = domain.PeekUshort(Address % domain.Size, bigEndian); } - public long Previous - { - get { return _previous; } - } + public long Previous => _previous; public void SetPreviousToCurrent(MemoryDomain domain, bool bigendian) { @@ -962,7 +937,7 @@ namespace BizHawk.Client.Common } } - public sealed class MiniDWordWatch : IMiniWatch + private sealed class MiniDWordWatch : IMiniWatch { public long Address { get; } private uint _previous; @@ -1096,7 +1071,7 @@ namespace BizHawk.Client.Common } } - public sealed class MiniDWordWatchDetailed : IMiniWatch, IMiniWatchDetails + private sealed class MiniDWordWatchDetailed : IMiniWatch, IMiniWatchDetails { public long Address { get; } diff --git a/BizHawk.Client.Common/tools/Watch/WatchList/WatchEqualityComparer.cs b/BizHawk.Client.Common/tools/Watch/WatchList/WatchEqualityComparer.cs index a7445904c3..2bf55c06c8 100644 --- a/BizHawk.Client.Common/tools/Watch/WatchList/WatchEqualityComparer.cs +++ b/BizHawk.Client.Common/tools/Watch/WatchList/WatchEqualityComparer.cs @@ -8,8 +8,7 @@ namespace BizHawk.Client.Common /// public sealed partial class WatchList { - private class WatchEqualityComparer - : IEqualityComparer + private class WatchEqualityComparer : IEqualityComparer { /// /// Determines if two are equals @@ -25,23 +24,21 @@ namespace BizHawk.Client.Common { return true; } - else - { - return false; - } - } - else if (ReferenceEquals(y, null)) + + return false; + } + + if (ReferenceEquals(y, null)) { return false; - } - else if (ReferenceEquals(x, y)) + } + + if (ReferenceEquals(x, y)) { return true; } - else - { - return false; - } + + return false; } /// diff --git a/BizHawk.sln.DotSettings b/BizHawk.sln.DotSettings index 5261a70afc..be60902ef3 100644 --- a/BizHawk.sln.DotSettings +++ b/BizHawk.sln.DotSettings @@ -2,6 +2,7 @@ False True ExplicitlyExcluded + DO_NOT_SHOW DO_NOT_SHOW DO_NOT_SHOW DO_NOT_SHOW @@ -26,6 +27,7 @@ DO_NOT_SHOW DO_NOT_SHOW DO_NOT_SHOW + DO_NOT_SHOW DO_NOT_SHOW DO_NOT_SHOW DO_NOT_SHOW @@ -57,6 +59,7 @@ GBC GG GL + ID II IO IPS