From 0818e40149049939e505abf73167073f58cde477 Mon Sep 17 00:00:00 2001 From: adelikat Date: Thu, 6 Aug 2020 21:02:08 -0500 Subject: [PATCH] misc cleanups in client.common --- BizHawk.sln.DotSettings | 3 +++ .../Api/BizHawkExternalToolAttribute.cs | 2 +- .../Api/ClientWebSocketWrapper.cs | 4 +-- src/BizHawk.Client.Common/RomLoader.cs | 2 +- .../SharpCompressDearchivalMethod.cs | 4 --- .../config/CheatConfig.cs | 6 +---- .../display/IInputDisplayGenerator.cs | 2 +- .../lua/CommonLibs/CommLuaLibrary.cs | 13 ++++----- .../lua/LuaHelperLibs/BitLuaLibrary.cs | 4 +-- .../lua/LuaLibraryBase.cs | 2 +- .../movie/PlatformFrameRates.cs | 3 +-- src/BizHawk.Client.Common/movie/Subtitle.cs | 4 +-- .../movie/bk2/Bk2LogEntryGenerator.cs | 11 +------- .../movie/bk2/StringLogs.cs | 1 - .../movie/import/SmvImport.cs | 3 +-- .../movie/import/YmvImport.cs | 25 +++++++++-------- .../movie/tasproj/IStateManager.cs | 6 +---- .../movie/tasproj/TasMovie.Editing.cs | 11 ++++---- .../movie/tasproj/TasMovie.History.cs | 6 ++--- .../savestates/ZipStateLoader.cs | 6 ++--- src/BizHawk.Client.Common/tools/Cheat.cs | 3 +-- .../tools/Watch/Watch.cs | 27 +++++++------------ .../tools/Watch/WatchList/WatchList.cs | 1 - 23 files changed, 54 insertions(+), 95 deletions(-) diff --git a/BizHawk.sln.DotSettings b/BizHawk.sln.DotSettings index a9f0a74a9d..5ef64684b8 100644 --- a/BizHawk.sln.DotSettings +++ b/BizHawk.sln.DotSettings @@ -280,6 +280,7 @@ True True True + True True True True @@ -521,6 +522,7 @@ True True True + True True True True @@ -563,6 +565,7 @@ True True True + True True True True diff --git a/src/BizHawk.Client.Common/Api/BizHawkExternalToolAttribute.cs b/src/BizHawk.Client.Common/Api/BizHawkExternalToolAttribute.cs index 9bdbebef81..5a73324930 100644 --- a/src/BizHawk.Client.Common/Api/BizHawkExternalToolAttribute.cs +++ b/src/BizHawk.Client.Common/Api/BizHawkExternalToolAttribute.cs @@ -2,7 +2,7 @@ namespace BizHawk.Client.Common { - /// This class needs to be in the assembly or old tools will throw on load instead of being recognised as old. + /// This class needs to be in the assembly or old tools will throw on load instead of being recognized as old. [AttributeUsage(AttributeTargets.Assembly)] [Obsolete("last used in 2.4, use [ExternalTool] instead")] public sealed class BizHawkExternalToolAttribute : Attribute diff --git a/src/BizHawk.Client.Common/Api/ClientWebSocketWrapper.cs b/src/BizHawk.Client.Common/Api/ClientWebSocketWrapper.cs index 2b34d1c326..9f75457393 100644 --- a/src/BizHawk.Client.Common/Api/ClientWebSocketWrapper.cs +++ b/src/BizHawk.Client.Common/Api/ClientWebSocketWrapper.cs @@ -12,7 +12,7 @@ namespace BizHawk.Client.Common { private ClientWebSocket? _w; - /// calls getter (unless closed/disposed, then is alwars returned) + /// calls getter (unless closed/disposed, then is always returned) public WebSocketState State => _w?.State ?? WebSocketState.Closed; public ClientWebSocketWrapper(Uri uri, CancellationToken? cancellationToken = null) @@ -27,7 +27,7 @@ namespace BizHawk.Client.Common { if (_w == null) throw new ObjectDisposedException(nameof(_w)); var task = _w.CloseAsync(closeStatus, statusDescription, cancellationToken ?? CancellationToken.None); - _w?.Dispose(); + _w.Dispose(); _w = null; return task; } diff --git a/src/BizHawk.Client.Common/RomLoader.cs b/src/BizHawk.Client.Common/RomLoader.cs index 2478290ef8..e29b7784df 100644 --- a/src/BizHawk.Client.Common/RomLoader.cs +++ b/src/BizHawk.Client.Common/RomLoader.cs @@ -497,7 +497,7 @@ namespace BizHawk.Client.Common }) .ToList(), Discs = xmlGame.AssetFullPaths - .Where(path => Disc.IsValidExtension(Path.GetExtension(path))) + .Where(p => Disc.IsValidExtension(Path.GetExtension(p))) .Select(path => new { d = DiscExtensions.CreateAnyType(path, str => DoLoadErrorCallback(str, system, LoadErrorType.DiscError)), diff --git a/src/BizHawk.Client.Common/SharpCompressDearchivalMethod.cs b/src/BizHawk.Client.Common/SharpCompressDearchivalMethod.cs index 60afa99714..42b1895dbf 100644 --- a/src/BizHawk.Client.Common/SharpCompressDearchivalMethod.cs +++ b/src/BizHawk.Client.Common/SharpCompressDearchivalMethod.cs @@ -1,13 +1,9 @@ #nullable enable -using System; using System.IO; using System.Linq; - using BizHawk.Common; - using SharpCompress.Archives; -using SharpCompress.Common; namespace BizHawk.Client.Common { diff --git a/src/BizHawk.Client.Common/config/CheatConfig.cs b/src/BizHawk.Client.Common/config/CheatConfig.cs index 014aaa3685..fb8247e77a 100644 --- a/src/BizHawk.Client.Common/config/CheatConfig.cs +++ b/src/BizHawk.Client.Common/config/CheatConfig.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace BizHawk.Client.Common +namespace BizHawk.Client.Common { public interface ICheatConfig { diff --git a/src/BizHawk.Client.Common/display/IInputDisplayGenerator.cs b/src/BizHawk.Client.Common/display/IInputDisplayGenerator.cs index c8e091d8a7..bfe18ecec9 100644 --- a/src/BizHawk.Client.Common/display/IInputDisplayGenerator.cs +++ b/src/BizHawk.Client.Common/display/IInputDisplayGenerator.cs @@ -39,7 +39,7 @@ namespace BizHawk.Client.Common { if (_source.Definition.Axes.TryGetValue(button, out var range)) { - var val = (int)_source.AxisValue(button); + var val = _source.AxisValue(button); if (val == range.Mid) { diff --git a/src/BizHawk.Client.Common/lua/CommonLibs/CommLuaLibrary.cs b/src/BizHawk.Client.Common/lua/CommonLibs/CommLuaLibrary.cs index 9cf3bab09f..eb8ce1f214 100644 --- a/src/BizHawk.Client.Common/lua/CommonLibs/CommLuaLibrary.cs +++ b/src/BizHawk.Client.Common/lua/CommonLibs/CommLuaLibrary.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.ComponentModel; -using System.Diagnostics; using System.Net.WebSockets; using System.Text; @@ -48,7 +47,7 @@ namespace BizHawk.Client.Common public string SocketServerScreenShotResponse() { CheckSocketServer(); - return APIs.Comm.Sockets?.SendScreenshot(1000).ToString(); + return APIs.Comm.Sockets?.SendScreenshot(1000); } [LuaMethod("socketServerSend", "sends a string to the Socket server")] @@ -110,11 +109,9 @@ namespace BizHawk.Client.Common [LuaMethod("socketServerGetInfo", "returns the IP and port of the Lua socket server")] public string SocketServerGetInfo() { - if (!CheckSocketServer()) - { - return ""; - } - return APIs.Comm.Sockets.GetInfo(); + return CheckSocketServer() + ? APIs.Comm.Sockets.GetInfo() + : ""; } private bool CheckSocketServer() @@ -160,7 +157,7 @@ namespace BizHawk.Client.Common public string MmfRead(string mmf_filename, int expectedSize) { CheckMmf(); - return APIs.Comm.MMF?.ReadFromFile(mmf_filename, expectedSize).ToString(); + return APIs.Comm.MMF?.ReadFromFile(mmf_filename, expectedSize); } private void CheckMmf() diff --git a/src/BizHawk.Client.Common/lua/LuaHelperLibs/BitLuaLibrary.cs b/src/BizHawk.Client.Common/lua/LuaHelperLibs/BitLuaLibrary.cs index 710655e423..d19107fc79 100644 --- a/src/BizHawk.Client.Common/lua/LuaHelperLibs/BitLuaLibrary.cs +++ b/src/BizHawk.Client.Common/lua/LuaHelperLibs/BitLuaLibrary.cs @@ -70,7 +70,7 @@ namespace BizHawk.Client.Common [LuaMethod("rshift", "Logical shift right of 'val' by 'amt' bits")] public static uint Rshift(uint val, int amt) { - return (uint)(val >> amt); + return val >> amt; } [LuaMethodExample("local inbitars = bit.arshift( -1000, 4 );")] @@ -91,7 +91,7 @@ namespace BizHawk.Client.Common [LuaMethod("set", "Sets the bit 'pos' in 'num'")] public static uint Set(uint num, int pos) { - return (uint)(num | 1U << pos); + return num | 1U << pos; } [LuaMethodExample("local lobitcle = bit.clear( 25, 35 );")] diff --git a/src/BizHawk.Client.Common/lua/LuaLibraryBase.cs b/src/BizHawk.Client.Common/lua/LuaLibraryBase.cs index 6127fc4a8c..dfb541bfc0 100644 --- a/src/BizHawk.Client.Common/lua/LuaLibraryBase.cs +++ b/src/BizHawk.Client.Common/lua/LuaLibraryBase.cs @@ -64,7 +64,7 @@ namespace BizHawk.Client.Common null => null, double d => Color.FromArgb((int) (long) d), string s => Color.FromName(s), - _ => (Color?) null + _ => null }; } diff --git a/src/BizHawk.Client.Common/movie/PlatformFrameRates.cs b/src/BizHawk.Client.Common/movie/PlatformFrameRates.cs index 490b783384..fde0c24a95 100644 --- a/src/BizHawk.Client.Common/movie/PlatformFrameRates.cs +++ b/src/BizHawk.Client.Common/movie/PlatformFrameRates.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; namespace BizHawk.Client.Common { diff --git a/src/BizHawk.Client.Common/movie/Subtitle.cs b/src/BizHawk.Client.Common/movie/Subtitle.cs index 69eda5b1cd..e46359c448 100644 --- a/src/BizHawk.Client.Common/movie/Subtitle.cs +++ b/src/BizHawk.Client.Common/movie/Subtitle.cs @@ -53,8 +53,8 @@ namespace BizHawk.Client.Common sb.Append("\r\n"); // Frame timing - double start = (double)Frame; - double end = (double)(Frame + Duration); + double start = Frame; + double end = Frame + Duration; int startTime = (int)(start * 1000 / fps); int endTime = (int)(end * 1000 / fps); diff --git a/src/BizHawk.Client.Common/movie/bk2/Bk2LogEntryGenerator.cs b/src/BizHawk.Client.Common/movie/bk2/Bk2LogEntryGenerator.cs index 4972b11360..eb1ee121f1 100644 --- a/src/BizHawk.Client.Common/movie/bk2/Bk2LogEntryGenerator.cs +++ b/src/BizHawk.Client.Common/movie/bk2/Bk2LogEntryGenerator.cs @@ -75,16 +75,7 @@ namespace BizHawk.Client.Common { if (_source.Definition.Axes.TryGetValue(button, out var range)) { - int val; - - if (createEmpty) - { - val = range.Mid; - } - else - { - val = (int)_source.AxisValue(button); - } + var val = createEmpty ? range.Mid : _source.AxisValue(button); sb.Append(val.ToString().PadLeft(5, ' ')).Append(','); } diff --git a/src/BizHawk.Client.Common/movie/bk2/StringLogs.cs b/src/BizHawk.Client.Common/movie/bk2/StringLogs.cs index bfbfa560c8..20ea8f7e98 100644 --- a/src/BizHawk.Client.Common/movie/bk2/StringLogs.cs +++ b/src/BizHawk.Client.Common/movie/bk2/StringLogs.cs @@ -2,7 +2,6 @@ using System.Collections; using System.Collections.Generic; using System.IO; -using System.Security.AccessControl; using System.Text; using BizHawk.Common; diff --git a/src/BizHawk.Client.Common/movie/import/SmvImport.cs b/src/BizHawk.Client.Common/movie/import/SmvImport.cs index 6de72eba5f..95eb781b2a 100644 --- a/src/BizHawk.Client.Common/movie/import/SmvImport.cs +++ b/src/BizHawk.Client.Common/movie/import/SmvImport.cs @@ -1,5 +1,4 @@ -using System; -using System.IO; +using System.IO; using System.Linq; using System.Text; using BizHawk.Emulation.Cores; diff --git a/src/BizHawk.Client.Common/movie/import/YmvImport.cs b/src/BizHawk.Client.Common/movie/import/YmvImport.cs index 29a65b339a..aed16f2f73 100644 --- a/src/BizHawk.Client.Common/movie/import/YmvImport.cs +++ b/src/BizHawk.Client.Common/movie/import/YmvImport.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Linq; using BizHawk.Emulation.Common; -using BizHawk.Emulation.Cores.Consoles.Sega.Saturn; namespace BizHawk.Client.Common.movie.import { @@ -18,18 +17,18 @@ namespace BizHawk.Client.Common.movie.import { PortDevices = { - { 0, "gamepad" }, - { 1, "none" }, - { 2, "none" }, - { 3, "none" }, - { 4, "none" }, - { 5, "none" }, - { 6, "none" }, - { 7, "none" }, - { 8, "none" }, - { 9, "none" }, - { 10, "none" }, - { 11, "none" }, + [0] = "gamepad", + [1] = "none", + [2] = "none", + [3] = "none", + [4] = "none", + [5] = "none", + [6] = "none", + [7] = "none", + [8] = "none", + [9] = "none", + [10] = "none", + [11] = "none", } }; diff --git a/src/BizHawk.Client.Common/movie/tasproj/IStateManager.cs b/src/BizHawk.Client.Common/movie/tasproj/IStateManager.cs index 361b442c87..6e044bbb83 100644 --- a/src/BizHawk.Client.Common/movie/tasproj/IStateManager.cs +++ b/src/BizHawk.Client.Common/movie/tasproj/IStateManager.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.IO; using BizHawk.Emulation.Common; @@ -23,9 +22,6 @@ namespace BizHawk.Client.Common /// void Capture(int frame, IStatable source, bool force = false); - // TODO: should this be used for markers? - //void CaptureHighPriority(int frame, IStatable source); - bool HasState(int frame); /// diff --git a/src/BizHawk.Client.Common/movie/tasproj/TasMovie.Editing.cs b/src/BizHawk.Client.Common/movie/tasproj/TasMovie.Editing.cs index 63579e0039..7fd2dc21eb 100644 --- a/src/BizHawk.Client.Common/movie/tasproj/TasMovie.Editing.cs +++ b/src/BizHawk.Client.Common/movie/tasproj/TasMovie.Editing.cs @@ -111,18 +111,18 @@ namespace BizHawk.Client.Common { // Separate the given frames into contiguous blocks // and process each block independently - List framesToDelete = frames.OrderBy(f => f).ToList(); + List framesToDelete = frames.OrderBy(fr => fr).ToList(); // f is the current index for framesToDelete - int startFrame, prevFrame, frame; int f = 0; int numDeleted = 0; while (numDeleted != framesToDelete.Count) { - prevFrame = startFrame = framesToDelete[f]; + int startFrame; + var prevFrame = startFrame = framesToDelete[f]; f++; for (; f < framesToDelete.Count; f++) { - frame = framesToDelete[f]; + var frame = framesToDelete[f]; if (frame - 1 != prevFrame) { f--; @@ -183,8 +183,7 @@ namespace BizHawk.Client.Common public void InsertInput(int frame, string inputState) { - var inputLog = new List(); - inputLog.Add(inputState); + var inputLog = new List { inputState }; InsertInput(frame, inputLog); // ChangeLog handled within } diff --git a/src/BizHawk.Client.Common/movie/tasproj/TasMovie.History.cs b/src/BizHawk.Client.Common/movie/tasproj/TasMovie.History.cs index 1d143a2529..fecd4ef578 100644 --- a/src/BizHawk.Client.Common/movie/tasproj/TasMovie.History.cs +++ b/src/BizHawk.Client.Common/movie/tasproj/TasMovie.History.cs @@ -649,7 +649,7 @@ namespace BizHawk.Client.Common private readonly string _buttonName; private readonly bool _isAxis = false; - public MovieActionPaint(int startFrame, int endFrame, string button, bool newS, ITasMovie movie) + public MovieActionPaint(int startFrame, int endFrame, string button, bool newS, IMovie movie) { _newState = newS ? 1 : 0; FirstFrame = startFrame; @@ -663,7 +663,7 @@ namespace BizHawk.Client.Common } } - public MovieActionPaint(int startFrame, int endFrame, string button, int newS, ITasMovie movie) + public MovieActionPaint(int startFrame, int endFrame, string button, int newS, IMovie movie) { _newState = newS; FirstFrame = startFrame; @@ -740,7 +740,6 @@ namespace BizHawk.Client.Common public void Undo(ITasMovie movie) { bool wasRecording = movie.ChangeLog.IsRecording; - bool wasBinding = movie.BindMarkersToInput; movie.ChangeLog.IsRecording = false; movie.BindMarkersToInput = _bindMarkers; @@ -762,7 +761,6 @@ namespace BizHawk.Client.Common public void Redo(ITasMovie movie) { bool wasRecording = movie.ChangeLog.IsRecording; - bool wasBinding = movie.BindMarkersToInput; movie.ChangeLog.IsRecording = false; movie.BindMarkersToInput = _bindMarkers; diff --git a/src/BizHawk.Client.Common/savestates/ZipStateLoader.cs b/src/BizHawk.Client.Common/savestates/ZipStateLoader.cs index 43a6bc0c7d..d2fc44fdaa 100644 --- a/src/BizHawk.Client.Common/savestates/ZipStateLoader.cs +++ b/src/BizHawk.Client.Common/savestates/ZipStateLoader.cs @@ -109,10 +109,8 @@ namespace BizHawk.Client.Common { if (_entriesByName.TryGetValue(lump.ReadName, out var e)) { - using (var zs = _zip.GetInputStream(e)) - { - callback(zs, e.Size); - } + using var zs = _zip.GetInputStream(e); + callback(zs, e.Size); return true; } diff --git a/src/BizHawk.Client.Common/tools/Cheat.cs b/src/BizHawk.Client.Common/tools/Cheat.cs index 3ce13640d6..6d9114cb7b 100644 --- a/src/BizHawk.Client.Common/tools/Cheat.cs +++ b/src/BizHawk.Client.Common/tools/Cheat.cs @@ -1,5 +1,4 @@ using BizHawk.Emulation.Common; -using System; namespace BizHawk.Client.Common { @@ -184,7 +183,7 @@ namespace BizHawk.Client.Common { if (Compare.HasValue) { - _watch.Domain.SendCheatToCore((int)Address.Value, (byte)Value, Compare.Value, (int)ComparisonType); + _watch.Domain.SendCheatToCore((int)Address.Value, (byte)Value, Compare.Value, (int)ComparisonType); } else { diff --git a/src/BizHawk.Client.Common/tools/Watch/Watch.cs b/src/BizHawk.Client.Common/tools/Watch/Watch.cs index 1d092b3b0e..016802551e 100644 --- a/src/BizHawk.Client.Common/tools/Watch/Watch.cs +++ b/src/BizHawk.Client.Common/tools/Watch/Watch.cs @@ -267,32 +267,23 @@ namespace BizHawk.Client.Common protected byte GetByte() { - if (!IsValid) - { - return 0; - } - - return _domain.PeekByte(Address); + return IsValid + ? _domain.PeekByte(Address) + : (byte) 0; } protected ushort GetWord() { - if (!IsValid) - { - return 0; - } - - return _domain.PeekUshort(Address, BigEndian); + return IsValid + ? _domain.PeekUshort(Address, BigEndian) + : (ushort) 0; } protected uint GetDWord() { - if (!IsValid) - { - return 0; - } - - return _domain.PeekUint(Address, BigEndian); + return IsValid + ? _domain.PeekUint(Address, BigEndian) + : 0; } protected void PokeByte(byte val) diff --git a/src/BizHawk.Client.Common/tools/Watch/WatchList/WatchList.cs b/src/BizHawk.Client.Common/tools/Watch/WatchList/WatchList.cs index 7eeefe943d..5bf586b270 100644 --- a/src/BizHawk.Client.Common/tools/Watch/WatchList/WatchList.cs +++ b/src/BizHawk.Client.Common/tools/Watch/WatchList/WatchList.cs @@ -7,7 +7,6 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -using BizHawk.Common.StringExtensions; using BizHawk.Emulation.Common; namespace BizHawk.Client.Common