diff --git a/BetterGenshinImpact/App.xaml.cs b/BetterGenshinImpact/App.xaml.cs index 2baa0b1e..ae8bf9aa 100644 --- a/BetterGenshinImpact/App.xaml.cs +++ b/BetterGenshinImpact/App.xaml.cs @@ -20,7 +20,6 @@ using System.Diagnostics; using System.IO; using System.Threading.Tasks; using System.Windows; -using System.Windows.Controls; using Wpf.Ui; namespace BetterGenshinImpact; diff --git a/BetterGenshinImpact/Core/Config/AllConfig.cs b/BetterGenshinImpact/Core/Config/AllConfig.cs index 58b8b505..d231bfa7 100644 --- a/BetterGenshinImpact/Core/Config/AllConfig.cs +++ b/BetterGenshinImpact/Core/Config/AllConfig.cs @@ -1,4 +1,5 @@ using BetterGenshinImpact.GameTask; +using BetterGenshinImpact.GameTask.AutoCook; using BetterGenshinImpact.GameTask.AutoDomain; using BetterGenshinImpact.GameTask.AutoFight; using BetterGenshinImpact.GameTask.AutoFishing; @@ -13,7 +14,6 @@ using Fischless.GameCapture; using System; using System.ComponentModel; using System.Text.Json.Serialization; -using BetterGenshinImpact.GameTask.AutoCook; namespace BetterGenshinImpact.Core.Config; diff --git a/BetterGenshinImpact/Core/Monitor/DirectInputMonitor.cs b/BetterGenshinImpact/Core/Monitor/DirectInputMonitor.cs index f617f06d..d77956fd 100644 --- a/BetterGenshinImpact/Core/Monitor/DirectInputMonitor.cs +++ b/BetterGenshinImpact/Core/Monitor/DirectInputMonitor.cs @@ -1,7 +1,6 @@ using BetterGenshinImpact.Core.Recorder; using SharpDX.DirectInput; using System; -using System.Diagnostics; using System.Threading; using System.Threading.Tasks; diff --git a/BetterGenshinImpact/Core/Recognition/OCR/PaddleOcrService.cs b/BetterGenshinImpact/Core/Recognition/OCR/PaddleOcrService.cs index cbf49957..8c76a7e0 100644 --- a/BetterGenshinImpact/Core/Recognition/OCR/PaddleOcrService.cs +++ b/BetterGenshinImpact/Core/Recognition/OCR/PaddleOcrService.cs @@ -4,10 +4,8 @@ using Sdcb.PaddleInference; using Sdcb.PaddleOCR; using Sdcb.PaddleOCR.Models; using System; -using System.ComponentModel; using System.Diagnostics; using System.IO; -using BetterGenshinImpact.GameTask; namespace BetterGenshinImpact.Core.Recognition.OCR; diff --git a/BetterGenshinImpact/Core/Recognition/ONNX/SVTR/PickTextInference.cs b/BetterGenshinImpact/Core/Recognition/ONNX/SVTR/PickTextInference.cs index 5e3984c6..fe4abf05 100644 --- a/BetterGenshinImpact/Core/Recognition/ONNX/SVTR/PickTextInference.cs +++ b/BetterGenshinImpact/Core/Recognition/ONNX/SVTR/PickTextInference.cs @@ -1,16 +1,12 @@ using BetterGenshinImpact.Core.Config; -using BetterGenshinImpact.GameTask; using Microsoft.ML.OnnxRuntime; using Microsoft.ML.OnnxRuntime.Tensors; using OpenCvSharp; using System; using System.Buffers; using System.Collections.Generic; -using System.ComponentModel; using System.Diagnostics; using System.IO; -using System.Linq; -using System.Runtime.CompilerServices; using System.Text; using System.Text.Json; diff --git a/BetterGenshinImpact/Core/Recognition/OpenCv/CropHelper.cs b/BetterGenshinImpact/Core/Recognition/OpenCv/CropHelper.cs index 89fd33a5..471f27ca 100644 --- a/BetterGenshinImpact/Core/Recognition/OpenCv/CropHelper.cs +++ b/BetterGenshinImpact/Core/Recognition/OpenCv/CropHelper.cs @@ -1,5 +1,5 @@ -using System; -using OpenCvSharp; +using OpenCvSharp; +using System; namespace BetterGenshinImpact.Core.Recognition.OpenCv; diff --git a/BetterGenshinImpact/Core/Recognition/OpenCv/FeatureMatch/FeatureMatcher.cs b/BetterGenshinImpact/Core/Recognition/OpenCv/FeatureMatch/FeatureMatcher.cs index cad6ef07..e2acdb88 100644 --- a/BetterGenshinImpact/Core/Recognition/OpenCv/FeatureMatch/FeatureMatcher.cs +++ b/BetterGenshinImpact/Core/Recognition/OpenCv/FeatureMatch/FeatureMatcher.cs @@ -1,12 +1,12 @@ using BetterGenshinImpact.Core.Recognition.OpenCv.Model; +using BetterGenshinImpact.GameTask.Common.Map; using BetterGenshinImpact.Helpers; using OpenCvSharp; +using OpenCvSharp.Features2D; using OpenCvSharp.XFeatures2D; using System; using System.Collections.Generic; using System.Diagnostics; -using BetterGenshinImpact.GameTask.Common.Map; -using OpenCvSharp.Features2D; using System.Linq; namespace BetterGenshinImpact.Core.Recognition.OpenCv.FeatureMatch; @@ -415,7 +415,7 @@ public class FeatureMatcher var matches = flnMatcher.KnnMatch(queryDescriptors, _trainDescriptors, k: 2); // 应用比例测试来过滤匹配点 - List goodMatches = new List(); + List goodMatches = []; foreach (var match in matches) { if (match.Length == 2 && match[0].Distance < 0.75 * match[1].Distance) diff --git a/BetterGenshinImpact/Core/Recognition/OpenCv/MatchTemplateHelper.cs b/BetterGenshinImpact/Core/Recognition/OpenCv/MatchTemplateHelper.cs index 2d8ee856..727af74c 100644 --- a/BetterGenshinImpact/Core/Recognition/OpenCv/MatchTemplateHelper.cs +++ b/BetterGenshinImpact/Core/Recognition/OpenCv/MatchTemplateHelper.cs @@ -155,7 +155,7 @@ public class MatchTemplateHelper /// public static List MatchMultiPicForOnePic(Mat srcMat, List imgSubList, double threshold = 0.8) { - List list = new(); + List list = []; foreach (var sub in imgSubList) while (true) { @@ -185,7 +185,7 @@ public class MatchTemplateHelper /// public static List MatchOnePicForOnePic(Mat srcMat, Mat dstMat, Mat? maskMat = null, double threshold = 0.8) { - List list = new(); + List list = []; while (true) { @@ -217,7 +217,7 @@ public class MatchTemplateHelper /// public static List MatchOnePicForOnePic(Mat srcMat, Mat dstMat, TemplateMatchModes matchMode, Mat? maskMat, double threshold, int maxCount = -1) { - List list = new(); + List list = []; if (maxCount < 0) { diff --git a/BetterGenshinImpact/Core/Recognition/OpenCv/Model/KeyPointFeatureBlock.cs b/BetterGenshinImpact/Core/Recognition/OpenCv/Model/KeyPointFeatureBlock.cs index 80124c2c..bf36be8c 100644 --- a/BetterGenshinImpact/Core/Recognition/OpenCv/Model/KeyPointFeatureBlock.cs +++ b/BetterGenshinImpact/Core/Recognition/OpenCv/Model/KeyPointFeatureBlock.cs @@ -1,5 +1,5 @@ -using System.Collections.Generic; -using OpenCvSharp; +using OpenCvSharp; +using System.Collections.Generic; namespace BetterGenshinImpact.Core.Recognition.OpenCv.Model; @@ -9,7 +9,7 @@ namespace BetterGenshinImpact.Core.Recognition.OpenCv.Model; /// public class KeyPointFeatureBlock { - public List KeyPointList { get; set; } = new(); + public List KeyPointList { get; set; } = []; private KeyPoint[]? keyPointArray; @@ -25,7 +25,7 @@ public class KeyPointFeatureBlock /// /// 在完整 KeyPoint[] 中的下标 /// - public List KeyPointIndexList { get; set; } = new(); + public List KeyPointIndexList { get; set; } = []; public Mat? Descriptor; diff --git a/BetterGenshinImpact/Core/Recognition/RecognitionObject.cs b/BetterGenshinImpact/Core/Recognition/RecognitionObject.cs index d1c90a6a..778e6d4a 100644 --- a/BetterGenshinImpact/Core/Recognition/RecognitionObject.cs +++ b/BetterGenshinImpact/Core/Recognition/RecognitionObject.cs @@ -123,26 +123,26 @@ public class RecognitionObject /// /// 部分文字识别结果不准确,进行替换。可选。 /// - public Dictionary ReplaceDictionary { get; set; } = new(); + public Dictionary ReplaceDictionary { get; set; } = []; /// /// 包含匹配 /// 多个值全匹配的情况下才算成功 /// 复杂情况请用下面的正则匹配 /// - public List AllContainMatchText { get; set; } = new(); + public List AllContainMatchText { get; set; } = []; /// /// 包含匹配 /// 一个值匹配就算成功 /// - public List OneContainMatchText { get; set; } = new(); + public List OneContainMatchText { get; set; } = []; /// /// 正则匹配 /// 多个值全匹配的情况下才算成功 /// - public List RegexMatchText { get; set; } = new(); + public List RegexMatchText { get; set; } = []; #endregion OCR文字识别 } diff --git a/BetterGenshinImpact/Core/Recorder/GlobalKeyMouseRecord.cs b/BetterGenshinImpact/Core/Recorder/GlobalKeyMouseRecord.cs index ed4163c8..96a86a5d 100644 --- a/BetterGenshinImpact/Core/Recorder/GlobalKeyMouseRecord.cs +++ b/BetterGenshinImpact/Core/Recorder/GlobalKeyMouseRecord.cs @@ -19,7 +19,7 @@ public class GlobalKeyMouseRecord : Singleton private KeyMouseRecorder? _recorder; - private readonly Dictionary _keyDownState = new(); + private readonly Dictionary _keyDownState = []; private DirectInputMonitor? _directInputMonitor; @@ -147,7 +147,7 @@ public class GlobalKeyMouseRecord : Singleton return; } - if (_keyDownState.ContainsKey(e.KeyCode) && _keyDownState[e.KeyCode]) + if (_keyDownState.TryGetValue(e.KeyCode, out bool state) && state) { // Debug.WriteLine($"KeyUp: {e.KeyCode}"); _keyDownState[e.KeyCode] = false; diff --git a/BetterGenshinImpact/Core/Recorder/KeyMouseMacroPlayer.cs b/BetterGenshinImpact/Core/Recorder/KeyMouseMacroPlayer.cs index f0b52477..fcdf660b 100644 --- a/BetterGenshinImpact/Core/Recorder/KeyMouseMacroPlayer.cs +++ b/BetterGenshinImpact/Core/Recorder/KeyMouseMacroPlayer.cs @@ -1,6 +1,10 @@ using BetterGenshinImpact.Core.Recorder.Model; using BetterGenshinImpact.Core.Simulator; +using BetterGenshinImpact.GameTask; +using BetterGenshinImpact.GameTask.Common; +using BetterGenshinImpact.GameTask.Common.Map; using BetterGenshinImpact.Helpers; +using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; using System.Drawing; @@ -8,10 +12,6 @@ using System.Text.Json; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; -using BetterGenshinImpact.GameTask; -using BetterGenshinImpact.GameTask.Common; -using BetterGenshinImpact.GameTask.Common.Map; -using Microsoft.Extensions.Logging; using Vanara.PInvoke; namespace BetterGenshinImpact.Core.Recorder; diff --git a/BetterGenshinImpact/Core/Recorder/KeyMouseRecorder.cs b/BetterGenshinImpact/Core/Recorder/KeyMouseRecorder.cs index eb333de5..6d90aed5 100644 --- a/BetterGenshinImpact/Core/Recorder/KeyMouseRecorder.cs +++ b/BetterGenshinImpact/Core/Recorder/KeyMouseRecorder.cs @@ -1,14 +1,14 @@ using BetterGenshinImpact.Core.Recorder.Model; +using BetterGenshinImpact.GameTask; +using BetterGenshinImpact.GameTask.Common; +using BetterGenshinImpact.GameTask.Common.Map; using Gma.System.MouseKeyHook; +using SharpDX.DirectInput; using System; using System.Collections.Generic; using System.Text.Json; using System.Text.Json.Serialization; using System.Windows.Forms; -using SharpDX.DirectInput; -using BetterGenshinImpact.GameTask; -using BetterGenshinImpact.GameTask.Common.Map; -using BetterGenshinImpact.GameTask.Common; namespace BetterGenshinImpact.Core.Recorder; diff --git a/BetterGenshinImpact/Core/Script/Dependence/Dispatcher.cs b/BetterGenshinImpact/Core/Script/Dependence/Dispatcher.cs index c78cd130..9af7dc11 100644 --- a/BetterGenshinImpact/Core/Script/Dependence/Dispatcher.cs +++ b/BetterGenshinImpact/Core/Script/Dependence/Dispatcher.cs @@ -1,9 +1,6 @@ -using System; -using System.Diagnostics; -using BetterGenshinImpact.Core.Script.Dependence.Model; +using BetterGenshinImpact.Core.Script.Dependence.Model; using BetterGenshinImpact.GameTask; -using Microsoft.ClearScript; -using Microsoft.ClearScript.V8; +using System; namespace BetterGenshinImpact.Core.Script.Dependence; @@ -18,7 +15,7 @@ public class Dispatcher var realtimeTimer = timer; if (realtimeTimer == null) { - throw new ArgumentNullException(nameof(RealtimeTimer), "实时任务对象不能为空"); + throw new ArgumentNullException(nameof(realtimeTimer), "实时任务对象不能为空"); } if (string.IsNullOrEmpty(realtimeTimer.Name)) { diff --git a/BetterGenshinImpact/Core/Script/Dependence/Genshin.cs b/BetterGenshinImpact/Core/Script/Dependence/Genshin.cs index c20bcf11..9e9c893e 100644 --- a/BetterGenshinImpact/Core/Script/Dependence/Genshin.cs +++ b/BetterGenshinImpact/Core/Script/Dependence/Genshin.cs @@ -1,5 +1,5 @@ -using System.Threading.Tasks; -using BetterGenshinImpact.GameTask.AutoTrackPath; +using BetterGenshinImpact.GameTask.AutoTrackPath; +using System.Threading.Tasks; namespace BetterGenshinImpact.Core.Script.Dependence; diff --git a/BetterGenshinImpact/Core/Script/Dependence/LimitedFile.cs b/BetterGenshinImpact/Core/Script/Dependence/LimitedFile.cs index 3647c618..f0e9900b 100644 --- a/BetterGenshinImpact/Core/Script/Dependence/LimitedFile.cs +++ b/BetterGenshinImpact/Core/Script/Dependence/LimitedFile.cs @@ -1,7 +1,7 @@ -using System; +using BetterGenshinImpact.Core.Script.Utils; +using System; using System.IO; using System.Threading.Tasks; -using BetterGenshinImpact.Core.Script.Utils; namespace BetterGenshinImpact.Core.Script.Dependence; diff --git a/BetterGenshinImpact/Core/Script/EngineExtend.cs b/BetterGenshinImpact/Core/Script/EngineExtend.cs index b4374b7e..81b6feb4 100644 --- a/BetterGenshinImpact/Core/Script/EngineExtend.cs +++ b/BetterGenshinImpact/Core/Script/EngineExtend.cs @@ -1,7 +1,6 @@ using BetterGenshinImpact.Core.Script.Dependence; using BetterGenshinImpact.Core.Script.Dependence.Model; using Microsoft.ClearScript; -using System; using System.Threading.Tasks; namespace BetterGenshinImpact.Core.Script; diff --git a/BetterGenshinImpact/Core/Script/Group/ScriptGroup.cs b/BetterGenshinImpact/Core/Script/Group/ScriptGroup.cs index d7707f7f..dc9ae861 100644 --- a/BetterGenshinImpact/Core/Script/Group/ScriptGroup.cs +++ b/BetterGenshinImpact/Core/Script/Group/ScriptGroup.cs @@ -1,9 +1,9 @@ -using CommunityToolkit.Mvvm.ComponentModel; +using BetterGenshinImpact.Service; +using CommunityToolkit.Mvvm.ComponentModel; using System; using System.Collections.ObjectModel; using System.Collections.Specialized; using System.Text.Json; -using BetterGenshinImpact.Service; namespace BetterGenshinImpact.Core.Script.Group; diff --git a/BetterGenshinImpact/Core/Script/Project/Manifest.cs b/BetterGenshinImpact/Core/Script/Project/Manifest.cs index 3ceb5f27..1670b03a 100644 --- a/BetterGenshinImpact/Core/Script/Project/Manifest.cs +++ b/BetterGenshinImpact/Core/Script/Project/Manifest.cs @@ -1,9 +1,8 @@ -using System; +using BetterGenshinImpact.Service; +using System; using System.Collections.Generic; using System.IO; using System.Text.Json; -using System.Windows.Documents; -using BetterGenshinImpact.Service; namespace BetterGenshinImpact.Core.Script.Project; diff --git a/BetterGenshinImpact/Core/Simulator/PostMessageSimulator.cs b/BetterGenshinImpact/Core/Simulator/PostMessageSimulator.cs index 1089fde2..92db342a 100644 --- a/BetterGenshinImpact/Core/Simulator/PostMessageSimulator.cs +++ b/BetterGenshinImpact/Core/Simulator/PostMessageSimulator.cs @@ -125,7 +125,7 @@ public class PostMessageSimulator //User32.PostMessage(_hWnd, User32.WindowMessage.WM_ACTIVATE, 1, 0); User32.PostMessage(_hWnd, User32.WindowMessage.WM_KEYDOWN, (nint)vk, 0x1e0001); User32.PostMessage(_hWnd, User32.WindowMessage.WM_CHAR, (nint)vk, 0x1e0001); - User32.PostMessage(_hWnd, User32.WindowMessage.WM_KEYUP, (nint)vk, (nint)0xc01e0001); + User32.PostMessage(_hWnd, User32.WindowMessage.WM_KEYUP, (nint)vk, unchecked((nint)0xc01e0001)); return this; } @@ -134,7 +134,7 @@ public class PostMessageSimulator User32.PostMessage(_hWnd, User32.WindowMessage.WM_KEYDOWN, (nint)vk, 0x1e0001); Thread.Sleep(ms); User32.PostMessage(_hWnd, User32.WindowMessage.WM_CHAR, (nint)vk, 0x1e0001); - User32.PostMessage(_hWnd, User32.WindowMessage.WM_KEYUP, (nint)vk, (nint)0xc01e0001); + User32.PostMessage(_hWnd, User32.WindowMessage.WM_KEYUP, (nint)vk, unchecked((nint)0xc01e0001)); return this; } @@ -143,7 +143,7 @@ public class PostMessageSimulator User32.PostMessage(_hWnd, User32.WindowMessage.WM_KEYDOWN, (nint)vk, 0x1e0001); Thread.Sleep(1000); User32.PostMessage(_hWnd, User32.WindowMessage.WM_CHAR, (nint)vk, 0x1e0001); - User32.PostMessage(_hWnd, User32.WindowMessage.WM_KEYUP, (nint)vk, (nint)0xc01e0001); + User32.PostMessage(_hWnd, User32.WindowMessage.WM_KEYUP, (nint)vk, unchecked((nint)0xc01e0001)); return this; } @@ -155,7 +155,7 @@ public class PostMessageSimulator public PostMessageSimulator KeyUp(User32.VK vk) { - User32.PostMessage(_hWnd, User32.WindowMessage.WM_KEYUP, (nint)vk, (nint)0xc01e0001); + User32.PostMessage(_hWnd, User32.WindowMessage.WM_KEYUP, (nint)vk, unchecked((nint)0xc01e0001)); return this; } @@ -164,7 +164,7 @@ public class PostMessageSimulator User32.PostMessage(_hWnd, User32.WindowMessage.WM_ACTIVATE, 1, 0); User32.PostMessage(_hWnd, User32.WindowMessage.WM_KEYDOWN, (nint)vk, 0x1e0001); User32.PostMessage(_hWnd, User32.WindowMessage.WM_CHAR, (nint)vk, 0x1e0001); - User32.PostMessage(_hWnd, User32.WindowMessage.WM_KEYUP, (nint)vk, (nint)0xc01e0001); + User32.PostMessage(_hWnd, User32.WindowMessage.WM_KEYUP, (nint)vk, unchecked((nint)0xc01e0001)); return this; } @@ -178,7 +178,7 @@ public class PostMessageSimulator public PostMessageSimulator KeyUpBackground(User32.VK vk) { User32.PostMessage(_hWnd, User32.WindowMessage.WM_ACTIVATE, 1, 0); - User32.PostMessage(_hWnd, User32.WindowMessage.WM_KEYUP, (nint)vk, (nint)0xc01e0001); + User32.PostMessage(_hWnd, User32.WindowMessage.WM_KEYUP, (nint)vk, unchecked((nint)0xc01e0001)); return this; } diff --git a/BetterGenshinImpact/GameTask/AutoDomain/AutoDomainTask.cs b/BetterGenshinImpact/GameTask/AutoDomain/AutoDomainTask.cs index a3b8c636..399c00df 100644 --- a/BetterGenshinImpact/GameTask/AutoDomain/AutoDomainTask.cs +++ b/BetterGenshinImpact/GameTask/AutoDomain/AutoDomainTask.cs @@ -25,7 +25,6 @@ using System.Drawing.Imaging; using System.IO; using System.Threading; using System.Threading.Tasks; -using System.Xml.Linq; using static BetterGenshinImpact.GameTask.Common.TaskControl; using static Vanara.PInvoke.User32; @@ -306,7 +305,7 @@ public class AutoDomainTask private Task StartFight(CombatScenes combatScenes, List combatCommands) { - CancellationTokenSource cts = new CancellationTokenSource(); + CancellationTokenSource cts = new(); _taskParam.Cts.Token.Register(cts.Cancel); combatScenes.BeforeTask(cts); // 战斗操作 @@ -412,7 +411,7 @@ public class AutoDomainTask /// private Task FindPetrifiedTree() { - CancellationTokenSource treeCts = new CancellationTokenSource(); + CancellationTokenSource treeCts = new(); _taskParam.Cts.Token.Register(treeCts.Cancel); // 中键回正视角 Simulation.SendInput.Mouse.MiddleButtonClick(); diff --git a/BetterGenshinImpact/GameTask/AutoFight/Assets/AutoFightAssets.cs b/BetterGenshinImpact/GameTask/AutoFight/Assets/AutoFightAssets.cs index ef277e55..49d9c962 100644 --- a/BetterGenshinImpact/GameTask/AutoFight/Assets/AutoFightAssets.cs +++ b/BetterGenshinImpact/GameTask/AutoFight/Assets/AutoFightAssets.cs @@ -1,7 +1,7 @@ -using System.Collections.Generic; -using BetterGenshinImpact.Core.Recognition; +using BetterGenshinImpact.Core.Recognition; using BetterGenshinImpact.GameTask.Model; using OpenCvSharp; +using System.Collections.Generic; namespace BetterGenshinImpact.GameTask.AutoFight.Assets; diff --git a/BetterGenshinImpact/GameTask/AutoFight/AutoFightConfig.cs b/BetterGenshinImpact/GameTask/AutoFight/AutoFightConfig.cs index 433696a9..09b51c6b 100644 --- a/BetterGenshinImpact/GameTask/AutoFight/AutoFightConfig.cs +++ b/BetterGenshinImpact/GameTask/AutoFight/AutoFightConfig.cs @@ -1,9 +1,5 @@ using CommunityToolkit.Mvvm.ComponentModel; using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace BetterGenshinImpact.GameTask.AutoFight; diff --git a/BetterGenshinImpact/GameTask/AutoFight/AutoFightParam.cs b/BetterGenshinImpact/GameTask/AutoFight/AutoFightParam.cs index 14239749..ba336136 100644 --- a/BetterGenshinImpact/GameTask/AutoFight/AutoFightParam.cs +++ b/BetterGenshinImpact/GameTask/AutoFight/AutoFightParam.cs @@ -1,10 +1,5 @@ using BetterGenshinImpact.GameTask.Model; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using System.Threading; -using System.Threading.Tasks; namespace BetterGenshinImpact.GameTask.AutoFight; diff --git a/BetterGenshinImpact/GameTask/AutoFight/Config/CombatAvatar.cs b/BetterGenshinImpact/GameTask/AutoFight/Config/CombatAvatar.cs index 239ca1ae..b22c5205 100644 --- a/BetterGenshinImpact/GameTask/AutoFight/Config/CombatAvatar.cs +++ b/BetterGenshinImpact/GameTask/AutoFight/Config/CombatAvatar.cs @@ -44,6 +44,6 @@ public class CombatAvatar /// /// 别名 /// - public List Alias { get; set; } = new(); + public List Alias { get; set; } = []; } \ No newline at end of file diff --git a/BetterGenshinImpact/GameTask/AutoFight/Config/DefaultAutoFightConfig.cs b/BetterGenshinImpact/GameTask/AutoFight/Config/DefaultAutoFightConfig.cs index f2b25fc7..919c9c70 100644 --- a/BetterGenshinImpact/GameTask/AutoFight/Config/DefaultAutoFightConfig.cs +++ b/BetterGenshinImpact/GameTask/AutoFight/Config/DefaultAutoFightConfig.cs @@ -27,12 +27,7 @@ public class DefaultAutoFightConfig public static string AvatarAliasToStandardName(string alias) { - var avatar = CombatAvatars.Find(x => x.Alias.Contains(alias)); - if (avatar == null) - { - throw new Exception($"角色名称校验失败:{alias}"); - } - + var avatar = CombatAvatars.Find(x => x.Alias.Contains(alias)) ?? throw new Exception($"角色名称校验失败:{alias}"); return avatar.Name; } } diff --git a/BetterGenshinImpact/GameTask/AutoFight/Model/Avatar.cs b/BetterGenshinImpact/GameTask/AutoFight/Model/Avatar.cs index c5db2167..4578f418 100644 --- a/BetterGenshinImpact/GameTask/AutoFight/Model/Avatar.cs +++ b/BetterGenshinImpact/GameTask/AutoFight/Model/Avatar.cs @@ -1,19 +1,16 @@ -using System; -using System.Diagnostics; -using BetterGenshinImpact.Core.Recognition.OCR; +using BetterGenshinImpact.Core.Recognition.OCR; using BetterGenshinImpact.Core.Recognition.OpenCv; using BetterGenshinImpact.Core.Simulator; using BetterGenshinImpact.GameTask.AutoFight.Config; +using BetterGenshinImpact.GameTask.Model.Area; using BetterGenshinImpact.Helpers; using Microsoft.Extensions.Logging; using OpenCvSharp; +using System; using System.Linq; using System.Threading; -using BetterGenshinImpact.GameTask.AutoGeniusInvokation.Exception; -using BetterGenshinImpact.GameTask.Model.Area; using Vanara.PInvoke; using static BetterGenshinImpact.GameTask.Common.TaskControl; -using static Vanara.PInvoke.User32; namespace BetterGenshinImpact.GameTask.AutoFight.Model; @@ -218,7 +215,7 @@ public class Avatar if (contours.Length > 0) { var boxes = contours.Select(Cv2.BoundingRect).Where(w => w.Width >= 20 * assetScale && w.Height >= 18 * assetScale).OrderByDescending(w => w.Width).ToList(); - if (boxes.Any()) + if (boxes.Count is not 0) { IndexRect = boxes.First(); return false; diff --git a/BetterGenshinImpact/GameTask/AutoFight/Model/CombatScenes.cs b/BetterGenshinImpact/GameTask/AutoFight/Model/CombatScenes.cs index 2c25d037..cf865797 100644 --- a/BetterGenshinImpact/GameTask/AutoFight/Model/CombatScenes.cs +++ b/BetterGenshinImpact/GameTask/AutoFight/Model/CombatScenes.cs @@ -1,9 +1,10 @@ using BetterGenshinImpact.Core.Config; using BetterGenshinImpact.Core.Recognition.OCR; +using BetterGenshinImpact.Core.Recognition.ONNX; using BetterGenshinImpact.Core.Recognition.OpenCv; using BetterGenshinImpact.GameTask.AutoFight.Assets; using BetterGenshinImpact.GameTask.AutoFight.Config; -using BetterGenshinImpact.GameTask.Model; +using BetterGenshinImpact.GameTask.Model.Area; using BetterGenshinImpact.Helpers; using Compunet.YoloV8; using Microsoft.Extensions.Logging; @@ -18,8 +19,6 @@ using System.Drawing.Imaging; using System.IO; using System.Linq; using System.Threading; -using BetterGenshinImpact.Core.Recognition.ONNX; -using BetterGenshinImpact.GameTask.Model.Area; using static BetterGenshinImpact.GameTask.Common.TaskControl; namespace BetterGenshinImpact.GameTask.AutoFight.Model; @@ -34,7 +33,7 @@ public class CombatScenes : IDisposable /// public Avatar[] Avatars { get; set; } = new Avatar[1]; - public Dictionary AvatarMap { get; set; } = new(); + public Dictionary AvatarMap { get; set; } = []; public int AvatarCount { get; set; } @@ -70,9 +69,9 @@ public class CombatScenes : IDisposable if (!string.IsNullOrEmpty(pair.Item2)) { var costumeName = pair.Item2; - if (AutoFightAssets.Instance.AvatarCostumeMap.ContainsKey(costumeName)) + if (AutoFightAssets.Instance.AvatarCostumeMap.TryGetValue(costumeName, out string? name)) { - costumeName = AutoFightAssets.Instance.AvatarCostumeMap[costumeName]; + costumeName = name; } displayNames[i] = $"{pair.Item1}({costumeName})"; @@ -83,7 +82,7 @@ public class CombatScenes : IDisposable } } Logger.LogInformation("识别到的队伍角色:{Text}", string.Join(",", displayNames)); - Avatars = BuildAvatars(names.ToList()); + Avatars = BuildAvatars([.. names]); AvatarMap = Avatars.ToDictionary(x => x.Name); } catch (Exception e) @@ -145,7 +144,7 @@ public class CombatScenes : IDisposable private void InitializeTeamFromConfig(string teamNames) { - var names = teamNames.Split(new[] { ",", "," }, StringSplitOptions.TrimEntries); + var names = teamNames.Split([",", ","], StringSplitOptions.TrimEntries); if (names.Length != 4) { throw new Exception($"强制指定队伍角色数量不正确,必须是4个,当前{names.Length}个"); @@ -159,7 +158,7 @@ public class CombatScenes : IDisposable Logger.LogInformation("强制指定队伍角色:{Text}", string.Join(",", names)); TaskContext.Instance().Config.AutoFightConfig.TeamNames = string.Join(",", names); - Avatars = BuildAvatars(names.ToList()); + Avatars = BuildAvatars([.. names]); AvatarMap = Avatars.ToDictionary(x => x.Name); } @@ -232,8 +231,8 @@ public class CombatScenes : IDisposable [Obsolete] private void ParseTeamOcrResult(PaddleOcrResult result, ImageRegion rectArea) { - List names = new(); - List nameRects = new(); + List names = []; + List nameRects = []; foreach (var item in result.Regions) { var name = StringUtils.ExtractChinese(item.Text); diff --git a/BetterGenshinImpact/GameTask/AutoFight/OneKeyFightTask.cs b/BetterGenshinImpact/GameTask/AutoFight/OneKeyFightTask.cs index 5ac78f12..669172d6 100644 --- a/BetterGenshinImpact/GameTask/AutoFight/OneKeyFightTask.cs +++ b/BetterGenshinImpact/GameTask/AutoFight/OneKeyFightTask.cs @@ -1,18 +1,18 @@ -using System; +using BetterGenshinImpact.Core.Config; +using BetterGenshinImpact.GameTask.AutoFight.Model; +using BetterGenshinImpact.GameTask.AutoFight.Script; +using BetterGenshinImpact.GameTask.Model.Enum; +using BetterGenshinImpact.Model; +using BetterGenshinImpact.Service; +using Microsoft.Extensions.Logging; +using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text.Json; -using BetterGenshinImpact.GameTask.AutoFight.Model; -using BetterGenshinImpact.Model; -using System.Threading.Tasks; using System.Threading; -using BetterGenshinImpact.Core.Config; +using System.Threading.Tasks; using static BetterGenshinImpact.GameTask.Common.TaskControl; -using BetterGenshinImpact.GameTask.AutoFight.Script; -using BetterGenshinImpact.GameTask.Model.Enum; -using BetterGenshinImpact.Service; -using Microsoft.Extensions.Logging; namespace BetterGenshinImpact.GameTask.AutoFight; @@ -193,7 +193,7 @@ public class OneKeyFightTask : Singleton var avatarMacros = JsonSerializer.Deserialize>(json, ConfigService.JsonOptions); if (avatarMacros == null) { - return new Dictionary>(); + return []; } var result = new Dictionary>(); foreach (var avatarMacro in avatarMacros) diff --git a/BetterGenshinImpact/GameTask/AutoFight/Script/CombatCommand.cs b/BetterGenshinImpact/GameTask/AutoFight/Script/CombatCommand.cs index 5ed5c367..c230c95c 100644 --- a/BetterGenshinImpact/GameTask/AutoFight/Script/CombatCommand.cs +++ b/BetterGenshinImpact/GameTask/AutoFight/Script/CombatCommand.cs @@ -2,7 +2,6 @@ using BetterGenshinImpact.Helpers; using System; using System.Collections.Generic; -using System.Windows.Input; using TimeSpan = System.TimeSpan; namespace BetterGenshinImpact.GameTask.AutoFight.Script; diff --git a/BetterGenshinImpact/GameTask/AutoFight/Script/CombatScriptBag.cs b/BetterGenshinImpact/GameTask/AutoFight/Script/CombatScriptBag.cs index 94330825..18cba950 100644 --- a/BetterGenshinImpact/GameTask/AutoFight/Script/CombatScriptBag.cs +++ b/BetterGenshinImpact/GameTask/AutoFight/Script/CombatScriptBag.cs @@ -1,7 +1,7 @@ -using System; -using BetterGenshinImpact.GameTask.AutoFight.Model; -using System.Collections.Generic; +using BetterGenshinImpact.GameTask.AutoFight.Model; using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; using static BetterGenshinImpact.GameTask.Common.TaskControl; namespace BetterGenshinImpact.GameTask.AutoFight.Script; diff --git a/BetterGenshinImpact/GameTask/AutoFight/Script/CombatScriptParser.cs b/BetterGenshinImpact/GameTask/AutoFight/Script/CombatScriptParser.cs index a6796c56..b4505c32 100644 --- a/BetterGenshinImpact/GameTask/AutoFight/Script/CombatScriptParser.cs +++ b/BetterGenshinImpact/GameTask/AutoFight/Script/CombatScriptParser.cs @@ -50,7 +50,7 @@ public class CombatScriptParser public static CombatScript Parse(string path) { var script = File.ReadAllText(path); - var lines = script.Split(new[] { "\r\n", "\r", "\n", ";" }, StringSplitOptions.RemoveEmptyEntries); + var lines = script.Split(["\r\n", "\r", "\n", ";"], StringSplitOptions.RemoveEmptyEntries); var result = new List(); foreach (var line in lines) { @@ -58,7 +58,7 @@ public class CombatScriptParser .Replace("(", "(") .Replace(")", ")") .Replace(",", ","); - if (l.StartsWith("//") || l.StartsWith("#") || string.IsNullOrEmpty(l)) + if (l.StartsWith("//") || l.StartsWith('#') || string.IsNullOrEmpty(l)) { continue; } @@ -74,8 +74,8 @@ public class CombatScriptParser public static CombatScript Parse(List lines) { - List combatCommands = new(); - HashSet combatAvatarNames = new(); + List combatCommands = []; + HashSet combatAvatarNames = []; foreach (var line in lines) { var oneLineCombatCommands = ParseLine(line, combatAvatarNames); @@ -120,7 +120,7 @@ public class CombatScriptParser continue; } - if (command.Contains("(") && !command.Contains(")")) + if (command.Contains('(') && !command.Contains(')')) { var j = i + 1; // 括号被逗号分隔,需要合并 @@ -133,7 +133,7 @@ public class CombatScriptParser throw new Exception("战斗脚本格式错误,指令括号无法配对"); } - if (command.Contains(")")) + if (command.Contains(')')) { i = j; break; @@ -142,7 +142,7 @@ public class CombatScriptParser j++; } - if (!(command.Contains("(") && command.Contains(")"))) + if (!(command.Contains('(') && command.Contains(')'))) { Logger.LogError("战斗脚本格式错误,指令 {Cmd} 括号不完整", command); throw new Exception("战斗脚本格式错误,指令括号不完整"); diff --git a/BetterGenshinImpact/GameTask/AutoFight/Script/Method.cs b/BetterGenshinImpact/GameTask/AutoFight/Script/Method.cs index 98b86013..bbe6fb6d 100644 --- a/BetterGenshinImpact/GameTask/AutoFight/Script/Method.cs +++ b/BetterGenshinImpact/GameTask/AutoFight/Script/Method.cs @@ -1,36 +1,36 @@ -using System; +using Microsoft.Extensions.Logging; +using System; using System.Collections.Generic; -using Microsoft.Extensions.Logging; using static BetterGenshinImpact.GameTask.Common.TaskControl; namespace BetterGenshinImpact.GameTask.AutoFight.Script; public class Method { - public static readonly Method Skill = new(new() { "skill", "e" }); - public static readonly Method Burst = new(new() { "burst", "q" }); - public static readonly Method Attack = new(new() { "attack", "普攻", "普通攻击" }); - public static readonly Method Charge = new(new() { "charge", "重击" }); - public static readonly Method Wait = new(new() { "wait", "after", "等待" }); + public static readonly Method Skill = new(["skill", "e"]); + public static readonly Method Burst = new(["burst", "q"]); + public static readonly Method Attack = new(["attack", "普攻", "普通攻击"]); + public static readonly Method Charge = new(["charge", "重击"]); + public static readonly Method Wait = new(["wait", "after", "等待"]); - public static readonly Method Walk = new(new() { "walk", "行走" }); - public static readonly Method W = new(new() { "w" }); - public static readonly Method A = new(new() { "a" }); - public static readonly Method S = new(new() { "s" }); - public static readonly Method D = new(new() { "d" }); + public static readonly Method Walk = new(["walk", "行走"]); + public static readonly Method W = new(["w"]); + public static readonly Method A = new(["a"]); + public static readonly Method S = new(["s"]); + public static readonly Method D = new(["d"]); - public static readonly Method Aim = new(new() { "aim", "r", "瞄准" }); - public static readonly Method Dash = new(new() { "dash", "冲刺" }); - public static readonly Method Jump = new(new() { "jump", "j", "跳跃" }); + public static readonly Method Aim = new(["aim", "r", "瞄准"]); + public static readonly Method Dash = new(["dash", "冲刺"]); + public static readonly Method Jump = new(["jump", "j", "跳跃"]); // 宏 - public static readonly Method MouseDown = new(new() { "mousedown" }); - public static readonly Method MouseUp = new(new() { "mouseup" }); - public static readonly Method Click = new(new() { "click" }); - public static readonly Method MoveBy = new(new() { "moveby" }); - public static readonly Method KeyDown = new(new() { "keydown" }); - public static readonly Method KeyUp = new(new() { "keyup" }); - public static readonly Method KeyPress = new(new() { "keypress" }); + public static readonly Method MouseDown = new(["mousedown"]); + public static readonly Method MouseUp = new(["mouseup"]); + public static readonly Method Click = new(["click"]); + public static readonly Method MoveBy = new(["moveby"]); + public static readonly Method KeyDown = new(["keydown"]); + public static readonly Method KeyUp = new(["keyup"]); + public static readonly Method KeyPress = new(["keypress"]); public static IEnumerable Values { diff --git a/BetterGenshinImpact/GameTask/AutoFishing/AutoFishingConfig.cs b/BetterGenshinImpact/GameTask/AutoFishing/AutoFishingConfig.cs index 2b7dfaf2..b10374e2 100644 --- a/BetterGenshinImpact/GameTask/AutoFishing/AutoFishingConfig.cs +++ b/BetterGenshinImpact/GameTask/AutoFishing/AutoFishingConfig.cs @@ -1,6 +1,5 @@ -using OpenCvSharp; +using CommunityToolkit.Mvvm.ComponentModel; using System; -using CommunityToolkit.Mvvm.ComponentModel; namespace BetterGenshinImpact.GameTask.AutoFishing; diff --git a/BetterGenshinImpact/GameTask/AutoFishing/AutoFishingTrigger.cs b/BetterGenshinImpact/GameTask/AutoFishing/AutoFishingTrigger.cs index 88ffa3fc..7aa59c80 100644 --- a/BetterGenshinImpact/GameTask/AutoFishing/AutoFishingTrigger.cs +++ b/BetterGenshinImpact/GameTask/AutoFishing/AutoFishingTrigger.cs @@ -2,18 +2,16 @@ using BetterGenshinImpact.Core.Recognition; using BetterGenshinImpact.Core.Recognition.OCR; using BetterGenshinImpact.Core.Recognition.ONNX; -using BetterGenshinImpact.Core.Recognition.OpenCv; using BetterGenshinImpact.Core.Simulator; using BetterGenshinImpact.GameTask.AutoFishing.Assets; using BetterGenshinImpact.GameTask.AutoFishing.Model; using BetterGenshinImpact.GameTask.AutoGeniusInvokation.Exception; using BetterGenshinImpact.GameTask.Common; +using BetterGenshinImpact.GameTask.Common.BgiVision; +using BetterGenshinImpact.GameTask.Model.Area; using BetterGenshinImpact.Helpers; using BetterGenshinImpact.Helpers.Extensions; -using BetterGenshinImpact.Model; using BetterGenshinImpact.View.Drawable; -using CommunityToolkit.Mvvm.Messaging; -using CommunityToolkit.Mvvm.Messaging.Messages; using Compunet.YoloV8; using Microsoft.Extensions.Logging; using OpenCvSharp; @@ -23,8 +21,6 @@ using System.Diagnostics; using System.Drawing.Imaging; using System.IO; using System.Threading; -using BetterGenshinImpact.GameTask.Common.BgiVision; -using BetterGenshinImpact.GameTask.Model.Area; using static Vanara.PInvoke.User32; using Color = System.Drawing.Color; using Pen = System.Drawing.Pen; diff --git a/BetterGenshinImpact/GameTask/AutoFishing/Model/BigFishType.cs b/BetterGenshinImpact/GameTask/AutoFishing/Model/BigFishType.cs index 8e16f0ab..6af9af13 100644 --- a/BetterGenshinImpact/GameTask/AutoFishing/Model/BigFishType.cs +++ b/BetterGenshinImpact/GameTask/AutoFishing/Model/BigFishType.cs @@ -1,6 +1,5 @@ using System.Collections.Generic; using System.Linq; -using System.Xml.Linq; namespace BetterGenshinImpact.GameTask.AutoFishing.Model; diff --git a/BetterGenshinImpact/GameTask/AutoFishing/Model/FishType.cs b/BetterGenshinImpact/GameTask/AutoFishing/Model/FishType.cs index 89e6ca23..984cc0a1 100644 --- a/BetterGenshinImpact/GameTask/AutoFishing/Model/FishType.cs +++ b/BetterGenshinImpact/GameTask/AutoFishing/Model/FishType.cs @@ -44,7 +44,7 @@ public class FishType public static readonly FishType MaintenanceMekPlatinumCollection = new("maintenance mek- platinum collection", "flashing maintenance mek bait", "维护机关·白金典藏型"); public static readonly FishType MaintenanceMekSituationController = new("maintenance mek- situation controller", "flashing maintenance mek bait", "维护机关·态势控制者"); public static readonly FishType MaintenanceMekWaterBodyCleaner = new("maintenance mek- water body cleaner", "flashing maintenance mek bait", "维护机关·水域清理者"); - public static readonly FishType MaintenanceMekWaterGoldLeader = new ("maintenance mek- gold leader", "flashing maintenance mek bait", "维护机关·澄金领队型"); + public static readonly FishType MaintenanceMekWaterGoldLeader = new("maintenance mek- gold leader", "flashing maintenance mek bait", "维护机关·澄金领队型"); public static IEnumerable Values diff --git a/BetterGenshinImpact/GameTask/AutoFishing/Model/Fishpond.cs b/BetterGenshinImpact/GameTask/AutoFishing/Model/Fishpond.cs index 25eddd56..9891761e 100644 --- a/BetterGenshinImpact/GameTask/AutoFishing/Model/Fishpond.cs +++ b/BetterGenshinImpact/GameTask/AutoFishing/Model/Fishpond.cs @@ -1,10 +1,9 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using BetterGenshinImpact.Core.Recognition.OpenCv; +using BetterGenshinImpact.Core.Recognition.OpenCv; using Compunet.YoloV8.Data; using OpenCvSharp; -using static OpenCvSharp.Cv2; +using System; +using System.Collections.Generic; +using System.Linq; namespace BetterGenshinImpact.GameTask.AutoFishing.Model; @@ -23,7 +22,7 @@ public class Fishpond /// /// 鱼池中的鱼 /// - public List Fishes { get; set; } = new(); + public List Fishes { get; set; } = []; public Fishpond(DetectionResult result) { @@ -45,7 +44,7 @@ public class Fishpond } // 可信度最高的鱼放在最前面 - Fishes = Fishes.OrderByDescending(fish => fish.Confidence).ToList(); + Fishes = [.. Fishes.OrderByDescending(fish => fish.Confidence)]; FishpondRect = CalculateFishpondRect(); } @@ -98,7 +97,7 @@ public class Fishpond /// public List FilterByBaitName(string baitName) { - return Fishes.Where(fish => fish.FishType.BaitName == baitName).OrderByDescending(fish => fish.Confidence).ToList(); + return [.. Fishes.Where(fish => fish.FishType.BaitName == baitName).OrderByDescending(fish => fish.Confidence)]; } public OneFish? FilterByBaitNameAndRecently(string baitName, Rect prevTargetFishRect) @@ -132,10 +131,10 @@ public class Fishpond /// public string MostMatchBait() { - Dictionary dict = new(); + Dictionary dict = []; foreach (var fish in Fishes) { - if (dict.ContainsKey(fish.FishType.BaitName)) + if (dict.TryGetValue(fish.FishType.BaitName, out _)) { dict[fish.FishType.BaitName]++; } diff --git a/BetterGenshinImpact/GameTask/AutoFishing/RodInput.cs b/BetterGenshinImpact/GameTask/AutoFishing/RodInput.cs index ef468f37..cb33932e 100644 --- a/BetterGenshinImpact/GameTask/AutoFishing/RodInput.cs +++ b/BetterGenshinImpact/GameTask/AutoFishing/RodInput.cs @@ -1,20 +1,14 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BetterGenshinImpact.GameTask.AutoFishing; +namespace BetterGenshinImpact.GameTask.AutoFishing; public record RodInput { - public double rod_x1; - public double rod_x2; - public double rod_y1; - public double rod_y2; - public double fish_x1; - public double fish_x2; - public double fish_y1; - public double fish_y2; - public int fish_label; + public double rod_x1; + public double rod_x2; + public double rod_y1; + public double rod_y2; + public double fish_x1; + public double fish_x2; + public double fish_y1; + public double fish_y2; + public int fish_label; } \ No newline at end of file diff --git a/BetterGenshinImpact/GameTask/AutoFishing/RodNet.cs b/BetterGenshinImpact/GameTask/AutoFishing/RodNet.cs index 49413f27..c4a09342 100644 --- a/BetterGenshinImpact/GameTask/AutoFishing/RodNet.cs +++ b/BetterGenshinImpact/GameTask/AutoFishing/RodNet.cs @@ -1,6 +1,6 @@ -using System; +using OpenCvSharp; +using System; using System.Linq; -using OpenCvSharp; namespace BetterGenshinImpact.GameTask.AutoFishing; @@ -11,10 +11,10 @@ public class RodNet { const double alpha = 1734.34 / 2.5; - static readonly double[] dz = { 0.561117562965, 0.637026851288, 0.705579317577, + static readonly double[] dz = [ 0.561117562965, 0.637026851288, 0.705579317577, 1.062734463845, 0.949307580751, 1.015620474332, 1.797904203405, 1.513476738412, 1.013873007495, - 1.159949954831, 1.353650974146, 1.302893195071 }; + 1.159949954831, 1.353650974146, 1.302893195071 ]; static readonly double[,] theta = { {-0.262674397633, 0.317025388945, -0.457150765450, 0.174522158281, @@ -31,10 +31,10 @@ public class RodNet -1.285988918494} }; - static readonly double[] B = { 1.241950004386, 3.051113640564, -3.848898190087 }; + static readonly double[] B = [1.241950004386, 3.051113640564, -3.848898190087]; - static readonly double[] offset = { 0.4, 0.2, 0.4, 0, 0.3, 0.3, - 0.3, 0.15, 0.5, 0.5, 0.5, 0.5 }; + static readonly double[] offset = [ 0.4, 0.2, 0.4, 0, 0.3, 0.3, + 0.3, 0.15, 0.5, 0.5, 0.5, 0.5 ]; static void F(double[] dst, double[] x, double[] y) { @@ -124,9 +124,7 @@ public class RodNet if (a < b) { - double temp = a; - a = b; - b = temp; + (b, a) = (a, b); } v0 = (288 - (input.rod_y1 + input.rod_y2) / 2) / alpha; @@ -135,8 +133,8 @@ public class RodNet v = (288 - (input.fish_y1 + input.fish_y2) / 2) / alpha; double[] y0z0t = new double[3]; - double[] abv0 = { a, b, v0 }; - double[] init = { 30, 15, 1 }; + double[] abv0 = [a, b, v0]; + double[] init = [30, 15, 1]; bool solveSuccess = NewtonRaphson(F, DfInv, y0z0t, abv0, init, 3, 1000, 1e-6); @@ -166,7 +164,7 @@ public class RodNet public static int GetRodState(Rect rod, Rect fish, int fishTypeIndex) { - RodInput input = new RodInput + RodInput input = new() { rod_x1 = rod.Left, rod_x2 = rod.Right, diff --git a/BetterGenshinImpact/GameTask/AutoGeniusInvokation/AutoGeniusInvokationConfig.cs b/BetterGenshinImpact/GameTask/AutoGeniusInvokation/AutoGeniusInvokationConfig.cs index 054310bb..e4cc9614 100644 --- a/BetterGenshinImpact/GameTask/AutoGeniusInvokation/AutoGeniusInvokationConfig.cs +++ b/BetterGenshinImpact/GameTask/AutoGeniusInvokation/AutoGeniusInvokationConfig.cs @@ -1,11 +1,7 @@ using CommunityToolkit.Mvvm.ComponentModel; +using OpenCvSharp; using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using OpenCvSharp; -using BetterGenshinImpact.Core.Config; namespace BetterGenshinImpact.GameTask.AutoGeniusInvokation; @@ -19,12 +15,12 @@ public partial class AutoGeniusInvokationConfig : ObservableObject [ObservableProperty] private int _sleepDelay = 0; - public List DefaultCharacterCardRects { get; set; } = new() - { + public List DefaultCharacterCardRects { get; set; } = + [ new(667, 632, 165, 282), new(877, 632, 165, 282), new(1088, 632, 165, 282) - }; + ]; /// diff --git a/BetterGenshinImpact/GameTask/AutoGeniusInvokation/AutoGeniusInvokationTask.cs b/BetterGenshinImpact/GameTask/AutoGeniusInvokation/AutoGeniusInvokationTask.cs index 4a842d75..ff874bdb 100644 --- a/BetterGenshinImpact/GameTask/AutoGeniusInvokation/AutoGeniusInvokationTask.cs +++ b/BetterGenshinImpact/GameTask/AutoGeniusInvokation/AutoGeniusInvokationTask.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using BetterGenshinImpact.GameTask.AutoGeniusInvokation.Model; -using static Vanara.PInvoke.Gdi32; +using BetterGenshinImpact.Helpers.Extensions; namespace BetterGenshinImpact.GameTask.AutoGeniusInvokation; @@ -16,6 +10,6 @@ public class AutoGeniusInvokationTask // 读取策略信息 var duel = ScriptParser.Parse(taskParam.StrategyContent); SystemControl.ActivateWindow(); - duel.RunAsync(taskParam); + duel.RunAsync(taskParam).SafeForget(); } } \ No newline at end of file diff --git a/BetterGenshinImpact/GameTask/AutoGeniusInvokation/Config/CharacterCard.cs b/BetterGenshinImpact/GameTask/AutoGeniusInvokation/Config/CharacterCard.cs index 7f664d6b..563bc519 100644 --- a/BetterGenshinImpact/GameTask/AutoGeniusInvokation/Config/CharacterCard.cs +++ b/BetterGenshinImpact/GameTask/AutoGeniusInvokation/Config/CharacterCard.cs @@ -1,8 +1,8 @@ -using System; -using System.Collections.Generic; -using BetterGenshinImpact.GameTask.AutoGeniusInvokation.Model; +using BetterGenshinImpact.GameTask.AutoGeniusInvokation.Model; using BetterGenshinImpact.GameTask.Common; using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; namespace BetterGenshinImpact.GameTask.AutoGeniusInvokation.Config; @@ -47,12 +47,12 @@ public class SkillsItem /// /// /// - public List SkillTag { get; set; } = new(); + public List SkillTag { get; set; } = []; /// /// /// - public List Cost { get; set; } = new(); + public List Cost { get; set; } = []; } [Serializable] @@ -101,7 +101,7 @@ public class CharacterCard /// /// /// - public List Skills { get; set; } = new(); + public List Skills { get; set; } = []; public static void CopyCardProperty(Character source, CharacterCard characterCard) { diff --git a/BetterGenshinImpact/GameTask/AutoGeniusInvokation/GeniusInvokationControl.cs b/BetterGenshinImpact/GameTask/AutoGeniusInvokation/GeniusInvokationControl.cs index a9d0c656..94147383 100644 --- a/BetterGenshinImpact/GameTask/AutoGeniusInvokation/GeniusInvokationControl.cs +++ b/BetterGenshinImpact/GameTask/AutoGeniusInvokation/GeniusInvokationControl.cs @@ -5,6 +5,8 @@ using BetterGenshinImpact.GameTask.AutoGeniusInvokation.Assets; using BetterGenshinImpact.GameTask.AutoGeniusInvokation.Exception; using BetterGenshinImpact.GameTask.AutoGeniusInvokation.Model; using BetterGenshinImpact.GameTask.Common; +using BetterGenshinImpact.GameTask.Model.Area; +using BetterGenshinImpact.Helpers; using BetterGenshinImpact.Helpers.Extensions; using Microsoft.Extensions.Logging; using OpenCvSharp; @@ -12,12 +14,10 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; -using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; -using BetterGenshinImpact.GameTask.Model.Area; -using Point = OpenCvSharp.Point; using static BetterGenshinImpact.GameTask.Common.TaskControl; +using Point = OpenCvSharp.Point; namespace BetterGenshinImpact.GameTask.AutoGeniusInvokation; @@ -1041,7 +1041,7 @@ public class GeniusInvokationControl var srcMat = CaptureGameMat(); int halfHeight = srcMat.Height / 2; - Mat bottomMat = new Mat(srcMat, new Rect(0, halfHeight, srcMat.Width, srcMat.Height - halfHeight)); + Mat bottomMat = new(srcMat, new Rect(0, halfHeight, srcMat.Width, srcMat.Height - halfHeight)); var lowPurple = new Scalar(239, 239, 239); var highPurple = new Scalar(255, 255, 255); @@ -1056,10 +1056,11 @@ public class GeniusInvokationControl if (contours.Length > 0) { // .Where(w => w.Width > 1 && w.Height >= 5) - var rects = contours.Select(Cv2.BoundingRect).ToList(); - - // 按照Y轴高度排序 - rects = rects.OrderBy(r => r.Y).ToList(); + var rects = contours + .Select(Cv2.BoundingRect) + // 按照Y轴高度排序 + .OrderBy(r => r.Y) + .ToList(); // 第一个和角色卡重叠的矩形 foreach (var rect in rects) @@ -1142,7 +1143,7 @@ public class GeniusInvokationControl if (!string.IsNullOrWhiteSpace(text)) { var hp = -2; - if (Regex.IsMatch(text, @"^[0-9]+$")) + if (RegexHelper.FullNumberRegex().IsMatch(text)) { hp = int.Parse(text); } @@ -1223,7 +1224,7 @@ public class GeniusInvokationControl #endif return -10; } - else if (Regex.IsMatch(text, @"^[0-9]+$")) + else if (RegexHelper.FullNumberRegex().IsMatch(text)) { _logger.LogInformation("通过OCR识别当前骰子数量: {Text}", text); return int.Parse(text); diff --git a/BetterGenshinImpact/GameTask/AutoGeniusInvokation/GeniusInvokationTaskParam.cs b/BetterGenshinImpact/GameTask/AutoGeniusInvokation/GeniusInvokationTaskParam.cs index bf93a323..072010d6 100644 --- a/BetterGenshinImpact/GameTask/AutoGeniusInvokation/GeniusInvokationTaskParam.cs +++ b/BetterGenshinImpact/GameTask/AutoGeniusInvokation/GeniusInvokationTaskParam.cs @@ -1,5 +1,5 @@ -using System.Threading; -using BetterGenshinImpact.GameTask.Model; +using BetterGenshinImpact.GameTask.Model; +using System.Threading; namespace BetterGenshinImpact.GameTask.AutoGeniusInvokation; diff --git a/BetterGenshinImpact/GameTask/AutoGeniusInvokation/Model/ActionCommand.cs b/BetterGenshinImpact/GameTask/AutoGeniusInvokation/Model/ActionCommand.cs index 5b08370d..b64a28f9 100644 --- a/BetterGenshinImpact/GameTask/AutoGeniusInvokation/Model/ActionCommand.cs +++ b/BetterGenshinImpact/GameTask/AutoGeniusInvokation/Model/ActionCommand.cs @@ -7,7 +7,7 @@ namespace BetterGenshinImpact.GameTask.AutoGeniusInvokation.Model /// /// 角色 /// - public Character Character { get; set; } + public Character Character { get; set; } = default!; public ActionEnum Action { get; set; } @@ -16,7 +16,7 @@ namespace BetterGenshinImpact.GameTask.AutoGeniusInvokation.Model /// public int TargetIndex { get; set; } - public override string ToString() + public override string? ToString() { if (Action == ActionEnum.UseSkill) { diff --git a/BetterGenshinImpact/GameTask/AutoGeniusInvokation/Model/ActionEnum.cs b/BetterGenshinImpact/GameTask/AutoGeniusInvokation/Model/ActionEnum.cs index 565e8a8c..e58e5fd7 100644 --- a/BetterGenshinImpact/GameTask/AutoGeniusInvokation/Model/ActionEnum.cs +++ b/BetterGenshinImpact/GameTask/AutoGeniusInvokation/Model/ActionEnum.cs @@ -12,34 +12,24 @@ namespace BetterGenshinImpact.GameTask.AutoGeniusInvokation.Model public static ActionEnum ChineseToActionEnum(this string type) { type = type.ToLower(); - switch (type) + return type switch { - case "出战": - //return ActionEnum.ChooseFirst; - throw new ArgumentOutOfRangeException(nameof(type), type, null); - case "切换": - //return ActionEnum.SwitchLater; - throw new ArgumentOutOfRangeException(nameof(type), type, null); - case "使用": - return ActionEnum.UseSkill; - default: - throw new ArgumentOutOfRangeException(nameof(type), type, null); - } + "出战" => /* ActionEnum.ChooseFirst, */ throw new ArgumentOutOfRangeException(nameof(type), type, null), + "切换" => /* ActionEnum.SwitchLater, */ throw new ArgumentOutOfRangeException(nameof(type), type, null), + "使用" => ActionEnum.UseSkill, + _ => throw new ArgumentOutOfRangeException(nameof(type), type, null), + }; } public static string ToChinese(this ActionEnum type) { - switch (type) + return type switch { - case ActionEnum.ChooseFirst: - return "出战"; - case ActionEnum.SwitchLater: - return "切换"; - case ActionEnum.UseSkill: - return "使用"; - default: - throw new ArgumentOutOfRangeException(nameof(type), type, null); - } + ActionEnum.ChooseFirst => "出战", + ActionEnum.SwitchLater => "切换", + ActionEnum.UseSkill => "使用", + _ => throw new ArgumentOutOfRangeException(nameof(type), type, null), + }; } } } diff --git a/BetterGenshinImpact/GameTask/AutoGeniusInvokation/Model/Character.cs b/BetterGenshinImpact/GameTask/AutoGeniusInvokation/Model/Character.cs index f4580a08..3737099a 100644 --- a/BetterGenshinImpact/GameTask/AutoGeniusInvokation/Model/Character.cs +++ b/BetterGenshinImpact/GameTask/AutoGeniusInvokation/Model/Character.cs @@ -1,9 +1,9 @@ using BetterGenshinImpact.Core.Recognition.OpenCv; using BetterGenshinImpact.Helpers.Extensions; +using Microsoft.Extensions.Logging; using OpenCvSharp; using System.Collections.Generic; using System.Text; -using Microsoft.Extensions.Logging; namespace BetterGenshinImpact.GameTask.AutoGeniusInvokation.Model { @@ -16,9 +16,9 @@ namespace BetterGenshinImpact.GameTask.AutoGeniusInvokation.Model /// public int Index { get; set; } - public string Name { get; set; } + public string Name { get; set; } = default!; public ElementalType Element { get; set; } - public Skill[] Skills { get; set; } + public Skill[] Skills { get; set; } = default!; /// @@ -46,7 +46,7 @@ namespace BetterGenshinImpact.GameTask.AutoGeniusInvokation.Model /// /// 角色身上的负面状态 /// - public List StatusList { get; set; } = new List(); + public List StatusList { get; set; } = []; /// /// 角色区域 @@ -60,7 +60,7 @@ namespace BetterGenshinImpact.GameTask.AutoGeniusInvokation.Model public override string ToString() { - StringBuilder sb = new StringBuilder(); + StringBuilder sb = new(); sb.Append($"角色{Index},"); if (Hp != -2) { diff --git a/BetterGenshinImpact/GameTask/AutoGeniusInvokation/Model/CharacterStatusEnum.cs b/BetterGenshinImpact/GameTask/AutoGeniusInvokation/Model/CharacterStatusEnum.cs index f193d3f4..469153cd 100644 --- a/BetterGenshinImpact/GameTask/AutoGeniusInvokation/Model/CharacterStatusEnum.cs +++ b/BetterGenshinImpact/GameTask/AutoGeniusInvokation/Model/CharacterStatusEnum.cs @@ -2,7 +2,7 @@ { public enum CharacterStatusEnum { - Frozen, + Frozen, Dizziness } } diff --git a/BetterGenshinImpact/GameTask/AutoGeniusInvokation/Model/Duel.cs b/BetterGenshinImpact/GameTask/AutoGeniusInvokation/Model/Duel.cs index 524270fc..75803329 100644 --- a/BetterGenshinImpact/GameTask/AutoGeniusInvokation/Model/Duel.cs +++ b/BetterGenshinImpact/GameTask/AutoGeniusInvokation/Model/Duel.cs @@ -9,7 +9,6 @@ using Microsoft.Extensions.Logging; using OpenCvSharp; using System; using System.Collections.Generic; -using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -22,13 +21,13 @@ public class Duel { private readonly ILogger _logger = App.GetLogger(); - public Character CurrentCharacter { get; set; } + public Character CurrentCharacter { get; set; } = default!; public Character[] Characters { get; set; } = new Character[4]; /// /// 行动指令队列 /// - public List ActionCommandQueue { get; set; } = new List(); + public List ActionCommandQueue { get; set; } = []; /// /// 当前回合数 @@ -38,7 +37,7 @@ public class Duel /// /// 角色牌位置 /// - public List CharacterCardRects { get; set; } + public List CharacterCardRects { get; set; } = default!; /// /// 手牌数量 @@ -50,7 +49,7 @@ public class Duel /// public int CurrentDiceCount { get; set; } = 0; - public CancellationTokenSource Cts { get; set; } + public CancellationTokenSource Cts { get; set; } = default!; private int _keqingECount = 0; @@ -95,7 +94,7 @@ public class Duel if (CharacterCardRects is not { Count: 3 }) { - CharacterCardRects = new List(); + CharacterCardRects = []; var defaultCharacterCardRects = TaskContext.Instance().Config.AutoGeniusInvokationConfig.DefaultCharacterCardRects; var assetScale = TaskContext.Instance().SystemInfo.AssetScale; for (var i = 0; i < defaultCharacterCardRects.Count; i++) @@ -135,7 +134,7 @@ public class Duel var elementSet = PredictionDiceType(); // 0 投骰子 - GeniusInvokationControl.GetInstance().ReRollDice(elementSet.ToArray()); + GeniusInvokationControl.GetInstance().ReRollDice([.. elementSet]); // 等待到我的回合 // 投骰子动画时间是不确定的 // 可能是对方先手 GeniusInvokationControl.GetInstance().WaitForMyTurn(this, 1000); @@ -429,7 +428,7 @@ public class Duel /// public List GetCharacterSwitchOrder() { - List orderList = new List(); + List orderList = []; for (var i = 0; i < ActionCommandQueue.Count; i++) { if (!orderList.Contains(ActionCommandQueue[i].Character.Index)) diff --git a/BetterGenshinImpact/GameTask/AutoGeniusInvokation/Model/ElementalType.cs b/BetterGenshinImpact/GameTask/AutoGeniusInvokation/Model/ElementalType.cs index 1e72d0ee..728613fa 100644 --- a/BetterGenshinImpact/GameTask/AutoGeniusInvokation/Model/ElementalType.cs +++ b/BetterGenshinImpact/GameTask/AutoGeniusInvokation/Model/ElementalType.cs @@ -19,83 +19,56 @@ namespace BetterGenshinImpact.GameTask.AutoGeniusInvokation.Model public static ElementalType ToElementalType(this string type) { type = type.ToLower(); - switch (type) + return type switch { - case "omni": - return ElementalType.Omni; - case "cryo": - return ElementalType.Cryo; - case "hydro": - return ElementalType.Hydro; - case "pyro": - return ElementalType.Pyro; - case "electro": - return ElementalType.Electro; - case "dendro": - return ElementalType.Dendro; - case "anemo": - return ElementalType.Anemo; - case "geo": - return ElementalType.Geo; - default: - throw new ArgumentOutOfRangeException(nameof(type), type, null); - } + "omni" => ElementalType.Omni, + "cryo" => ElementalType.Cryo, + "hydro" => ElementalType.Hydro, + "pyro" => ElementalType.Pyro, + "electro" => ElementalType.Electro, + "dendro" => ElementalType.Dendro, + "anemo" => ElementalType.Anemo, + "geo" => ElementalType.Geo, + _ => throw new ArgumentOutOfRangeException(nameof(type), type, null), + }; } public static ElementalType ChineseToElementalType(this string type) { type = type.ToLower(); - switch (type) + return type switch { - case "全": - return ElementalType.Omni; - case "冰": - return ElementalType.Cryo; - case "水": - return ElementalType.Hydro; - case "火": - return ElementalType.Pyro; - case "雷": - return ElementalType.Electro; - case "草": - return ElementalType.Dendro; - case "风": - return ElementalType.Anemo; - case "岩": - return ElementalType.Geo; - default: - throw new ArgumentOutOfRangeException(nameof(type), type, null); - } + "全" => ElementalType.Omni, + "冰" => ElementalType.Cryo, + "水" => ElementalType.Hydro, + "火" => ElementalType.Pyro, + "雷" => ElementalType.Electro, + "草" => ElementalType.Dendro, + "风" => ElementalType.Anemo, + "岩" => ElementalType.Geo, + _ => throw new ArgumentOutOfRangeException(nameof(type), type, null), + }; } public static string ToChinese(this ElementalType type) { - switch (type) + return type switch { - case ElementalType.Omni: - return "全"; - case ElementalType.Cryo: - return "冰"; - case ElementalType.Hydro: - return "水"; - case ElementalType.Pyro: - return "火"; - case ElementalType.Electro: - return "雷"; - case ElementalType.Dendro: - return "草"; - case ElementalType.Anemo: - return "风"; - case ElementalType.Geo: - return "岩"; - default: - throw new ArgumentOutOfRangeException(nameof(type), type, null); - } + ElementalType.Omni => "全", + ElementalType.Cryo => "冰", + ElementalType.Hydro => "水", + ElementalType.Pyro => "火", + ElementalType.Electro => "雷", + ElementalType.Dendro => "草", + ElementalType.Anemo => "风", + ElementalType.Geo => "岩", + _ => throw new ArgumentOutOfRangeException(nameof(type), type, null), + }; } public static string ToLowerString(this ElementalType type) { return type.ToString().ToLower(); } - } + } } \ No newline at end of file diff --git a/BetterGenshinImpact/GameTask/AutoGeniusInvokation/Model/RollPhaseDice.cs b/BetterGenshinImpact/GameTask/AutoGeniusInvokation/Model/RollPhaseDice.cs index 984f825d..513c9322 100644 --- a/BetterGenshinImpact/GameTask/AutoGeniusInvokation/Model/RollPhaseDice.cs +++ b/BetterGenshinImpact/GameTask/AutoGeniusInvokation/Model/RollPhaseDice.cs @@ -13,7 +13,7 @@ namespace BetterGenshinImpact.GameTask.AutoGeniusInvokation.Model /// 元素类型 /// public ElementalType Type { get; set; } - + /// /// 中心点位置 /// diff --git a/BetterGenshinImpact/GameTask/AutoGeniusInvokation/Model/RoundStrategy.cs b/BetterGenshinImpact/GameTask/AutoGeniusInvokation/Model/RoundStrategy.cs index 24c4ed44..a1494fc1 100644 --- a/BetterGenshinImpact/GameTask/AutoGeniusInvokation/Model/RoundStrategy.cs +++ b/BetterGenshinImpact/GameTask/AutoGeniusInvokation/Model/RoundStrategy.cs @@ -6,19 +6,19 @@ namespace BetterGenshinImpact.GameTask.AutoGeniusInvokation.Model; [Obsolete] public class RoundStrategy { - public List RawCommandList { get; set; } = new List(); + public List RawCommandList { get; set; } = []; - public List ActionCommands { get; set; } = new List(); + public List ActionCommands { get; set; } = []; public List MaybeNeedElement(Duel duel) { - List result = new List(); + List result = []; for (int i = 0; i < ActionCommands.Count; i++) { - if (ActionCommands[i].Action == ActionEnum.SwitchLater - && i != ActionCommands.Count-1 - && ActionCommands[i+1].Action == ActionEnum.UseSkill) + if (ActionCommands[i].Action == ActionEnum.SwitchLater + && i != ActionCommands.Count - 1 + && ActionCommands[i + 1].Action == ActionEnum.UseSkill) { result.Add(duel.Characters[ActionCommands[i].TargetIndex].Element); } diff --git a/BetterGenshinImpact/GameTask/AutoGeniusInvokation/ScriptParser.cs b/BetterGenshinImpact/GameTask/AutoGeniusInvokation/ScriptParser.cs index dba5580a..9a696d95 100644 --- a/BetterGenshinImpact/GameTask/AutoGeniusInvokation/ScriptParser.cs +++ b/BetterGenshinImpact/GameTask/AutoGeniusInvokation/ScriptParser.cs @@ -1,12 +1,12 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text.RegularExpressions; -using System.Windows.Forms; -using BetterGenshinImpact.GameTask.AutoFight.Config; +using BetterGenshinImpact.GameTask.AutoFight.Config; using BetterGenshinImpact.GameTask.AutoGeniusInvokation.Config; using BetterGenshinImpact.GameTask.AutoGeniusInvokation.Model; +using BetterGenshinImpact.Helpers; using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Windows.Forms; namespace BetterGenshinImpact.GameTask.AutoGeniusInvokation; @@ -16,7 +16,7 @@ public class ScriptParser public static Duel Parse(string script) { - var lines = script.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None); + var lines = script.Split(["\r\n", "\r", "\n"], StringSplitOptions.None); var result = new List(); foreach (var line in lines) { @@ -29,7 +29,7 @@ public class ScriptParser public static Duel Parse(List lines) { - Duel duel = new Duel(); + Duel duel = new(); string stage = ""; int i = 0; @@ -38,7 +38,7 @@ public class ScriptParser for (i = 0; i < lines.Count; i++) { var line = lines[i]; - if (line.Contains(":")) + if (line.Contains(':')) { stage = line; continue; @@ -58,7 +58,7 @@ public class ScriptParser { MyAssert(duel.Characters[3] != null, "角色未定义"); - string[] actionParts = line.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries); + string[] actionParts = line.Split(" ", StringSplitOptions.RemoveEmptyEntries); MyAssert(actionParts.Length == 3, "策略中的行动命令解析错误"); MyAssert(actionParts[1] == "使用", "策略中的行动命令解析错误"); @@ -79,7 +79,7 @@ public class ScriptParser MyAssert(j <= 3, "策略中的行动命令解析错误:角色名称无法从角色定义中匹配到"); - int skillNum = int.Parse(Regex.Replace(actionParts[2], @"[^0-9]+", "")); + int skillNum = int.Parse(RegexHelper.ExcludeNumberRegex().Replace(actionParts[2], "")); MyAssert(skillNum < 5, "策略中的行动命令解析错误:技能编号错误"); actionCommand.TargetIndex = skillNum; duel.ActionCommandQueue.Add(actionCommand); @@ -96,7 +96,7 @@ public class ScriptParser { MyLogger.LogError($"解析脚本错误,行号:{i + 1},错误信息:{ex}"); MessageBox.Show($"解析脚本错误,行号:{i + 1},错误信息:{ex}", "策略解析失败", MessageBoxButtons.OK, MessageBoxIcon.Error); - return null; + return default!; } return duel; @@ -117,14 +117,14 @@ public class ScriptParser var characterAndSkill = line.Split('{'); var parts = characterAndSkill[0].Split('='); - character.Index = int.Parse(Regex.Replace(parts[0], @"[^0-9]+", "")); + character.Index = int.Parse(RegexHelper.ExcludeNumberRegex().Replace(parts[0], "")); MyAssert(character.Index >= 1 && character.Index <= 3, "角色序号必须在1-3之间"); - if (parts[1].Contains("|")) + if (parts[1].Contains('|')) { var nameAndElement = parts[1].Split('|'); character.Name = nameAndElement[0]; - character.Element = nameAndElement[1].Substring(0, 1).ChineseToElementalType(); + character.Element = nameAndElement[1][..1].ChineseToElementalType(); // 技能 string skillStr = characterAndSkill[1].Replace("}", ""); @@ -136,7 +136,7 @@ public class ScriptParser skills[skill.Index] = skill; } - character.Skills = skills.ToArray(); + character.Skills = [.. skills]; } else { @@ -172,16 +172,16 @@ public class ScriptParser { var skill = new Skill(); var parts = oneSkillStr.Split('='); - skill.Index = short.Parse(Regex.Replace(parts[0], @"[^0-9]+", "")); + skill.Index = short.Parse(RegexHelper.ExcludeNumberRegex().Replace(parts[0], "")); MyAssert(skill.Index >= 1 && skill.Index <= 5, "技能序号必须在1-5之间"); var costStr = parts[1]; var costParts = costStr.Split('+'); - skill.SpecificElementCost = int.Parse(costParts[0].Substring(0, 1)); + skill.SpecificElementCost = int.Parse(costParts[0][..1]); skill.Type = costParts[0].Substring(1, 1).ChineseToElementalType(); // 杂色骰子在+号右边 if (costParts.Length > 1) { - skill.AnyElementCost = int.Parse(costParts[1].Substring(0, 1)); + skill.AnyElementCost = int.Parse(costParts[1][..1]); } skill.AllCost = skill.SpecificElementCost + skill.AnyElementCost; diff --git a/BetterGenshinImpact/GameTask/AutoMusicGame/AutoMusicGameParam.cs b/BetterGenshinImpact/GameTask/AutoMusicGame/AutoMusicGameParam.cs index 120a0143..41b0fcaf 100644 --- a/BetterGenshinImpact/GameTask/AutoMusicGame/AutoMusicGameParam.cs +++ b/BetterGenshinImpact/GameTask/AutoMusicGame/AutoMusicGameParam.cs @@ -1,5 +1,5 @@ -using System.Threading; -using BetterGenshinImpact.GameTask.Model; +using BetterGenshinImpact.GameTask.Model; +using System.Threading; namespace BetterGenshinImpact.GameTask.AutoMusicGame; diff --git a/BetterGenshinImpact/GameTask/AutoPick/AutoPickTrigger.cs b/BetterGenshinImpact/GameTask/AutoPick/AutoPickTrigger.cs index 49238218..45a4591e 100644 --- a/BetterGenshinImpact/GameTask/AutoPick/AutoPickTrigger.cs +++ b/BetterGenshinImpact/GameTask/AutoPick/AutoPickTrigger.cs @@ -1,7 +1,9 @@ using BetterGenshinImpact.Core.Config; +using BetterGenshinImpact.Core.Recognition; using BetterGenshinImpact.Core.Recognition.OCR; using BetterGenshinImpact.Core.Recognition.ONNX.SVTR; using BetterGenshinImpact.Core.Recognition.OpenCv; +using BetterGenshinImpact.Core.Script.Dependence.Model.TimerConfig; using BetterGenshinImpact.Core.Simulator; using BetterGenshinImpact.GameTask.AutoPick.Assets; using BetterGenshinImpact.Helpers; @@ -14,14 +16,11 @@ using System.Diagnostics; using System.Text.Json; using System.Text.RegularExpressions; using System.Windows.Forms; -using BetterGenshinImpact.Core.Recognition; using Vanara.PInvoke; -using System.Windows.Input; -using BetterGenshinImpact.Core.Script.Dependence.Model.TimerConfig; namespace BetterGenshinImpact.GameTask.AutoPick; -public class AutoPickTrigger : ITaskTrigger +public partial class AutoPickTrigger : ITaskTrigger { private readonly ILogger _logger = App.GetLogger(); private readonly ITextInference _pickTextInference = TextInferenceFactory.Pick; @@ -36,12 +35,12 @@ public class AutoPickTrigger : ITaskTrigger /// /// 拾取黑名单 /// - private List _blackList = new(); + private List _blackList = []; /// /// 拾取白名单 /// - private List _whiteList = new(); + private List _whiteList = []; // 自定义拾取按键 private string _pickKeyName = "F"; @@ -200,7 +199,7 @@ public class AutoPickTrigger : ITaskTrigger speedTimer.Record("文字识别"); if (!string.IsNullOrEmpty(text)) { - text = Regex.Replace(text, @"^[\p{P} ]+|[\p{P} ]+$", ""); + text = PunctuationAndSpacesRegex().Replace(text, ""); // 唯一一个动态拾取项,特殊处理,不拾取 if (text.Contains("生长时间")) { @@ -273,4 +272,7 @@ public class AutoPickTrigger : ITaskTrigger _lastText = text; _prevClickFrameIndex = content.FrameIndex; } + + [GeneratedRegex(@"^[\p{P} ]+|[\p{P} ]+$")] + private static partial Regex PunctuationAndSpacesRegex(); } diff --git a/BetterGenshinImpact/GameTask/AutoSkip/Assets/HangoutConfig.cs b/BetterGenshinImpact/GameTask/AutoSkip/Assets/HangoutConfig.cs index 133605fc..8ab7294d 100644 --- a/BetterGenshinImpact/GameTask/AutoSkip/Assets/HangoutConfig.cs +++ b/BetterGenshinImpact/GameTask/AutoSkip/Assets/HangoutConfig.cs @@ -1,10 +1,10 @@ -using System; +using BetterGenshinImpact.Core.Config; using BetterGenshinImpact.Model; +using BetterGenshinImpact.Service; +using System; using System.Collections.Generic; using System.IO; using System.Text.Json; -using BetterGenshinImpact.Core.Config; -using BetterGenshinImpact.Service; namespace BetterGenshinImpact.GameTask.AutoSkip.Assets; diff --git a/BetterGenshinImpact/GameTask/AutoSkip/AutoSkipTrigger.cs b/BetterGenshinImpact/GameTask/AutoSkip/AutoSkipTrigger.cs index 6ef48227..df2ebc8b 100644 --- a/BetterGenshinImpact/GameTask/AutoSkip/AutoSkipTrigger.cs +++ b/BetterGenshinImpact/GameTask/AutoSkip/AutoSkipTrigger.cs @@ -29,7 +29,7 @@ namespace BetterGenshinImpact.GameTask.AutoSkip; /// /// 自动剧情有选项点击 /// -public class AutoSkipTrigger : ITaskTrigger +public partial class AutoSkipTrigger : ITaskTrigger { private readonly ILogger _logger = App.GetLogger(); @@ -47,17 +47,17 @@ public class AutoSkipTrigger : ITaskTrigger /// /// 不自动点击的选项,优先级低于橙色文字点击 /// - private List _defaultPauseList = new(); + private List _defaultPauseList = []; /// /// 不自动点击的选项 /// - private List _pauseList = new(); + private List _pauseList = []; /// /// 优先自动点击的选项 /// - private List _selectList = new(); + private List _selectList = []; private PostMessageSimulator? _postMessageSimulator; @@ -78,7 +78,7 @@ public class AutoSkipTrigger : ITaskTrigger var defaultPauseListJson = Global.ReadAllTextIfExist(@"User\AutoSkip\default_pause_options.json"); if (!string.IsNullOrEmpty(defaultPauseListJson)) { - _defaultPauseList = JsonSerializer.Deserialize>(defaultPauseListJson, ConfigService.JsonOptions) ?? new List(); + _defaultPauseList = JsonSerializer.Deserialize>(defaultPauseListJson, ConfigService.JsonOptions) ?? []; } } catch (Exception e) @@ -92,7 +92,7 @@ public class AutoSkipTrigger : ITaskTrigger var pauseListJson = Global.ReadAllTextIfExist(@"User\AutoSkip\pause_options.json"); if (!string.IsNullOrEmpty(pauseListJson)) { - _pauseList = JsonSerializer.Deserialize>(pauseListJson, ConfigService.JsonOptions) ?? new List(); + _pauseList = JsonSerializer.Deserialize>(pauseListJson, ConfigService.JsonOptions) ?? []; } } catch (Exception e) @@ -106,7 +106,7 @@ public class AutoSkipTrigger : ITaskTrigger var selectListJson = Global.ReadAllTextIfExist(@"User\AutoSkip\select_options.json"); if (!string.IsNullOrEmpty(selectListJson)) { - _selectList = JsonSerializer.Deserialize>(selectListJson, ConfigService.JsonOptions) ?? new List(); + _selectList = JsonSerializer.Deserialize>(selectListJson, ConfigService.JsonOptions) ?? []; } } catch (Exception e) @@ -390,7 +390,8 @@ public class AutoSkipTrigger : ITaskTrigger }); } - private readonly Regex _enOrNumRegex = new(@"^[a-zA-Z0-9]+$"); + [GeneratedRegex(@"^[a-zA-Z0-9]+$")] + private static partial Regex EnOrNumRegex(); /// /// 新的对话选项选择 @@ -420,7 +421,7 @@ public class AutoSkipTrigger : ITaskTrigger if (chatOptionResultList.Count > 0) { // 第一个元素就是最下面的 - chatOptionResultList = chatOptionResultList.OrderByDescending(r => r.Y).ToList(); + chatOptionResultList = [.. chatOptionResultList.OrderByDescending(r => r.Y)]; // 通过最下面的气泡框来文字识别 var lowest = chatOptionResultList[0]; @@ -438,11 +439,11 @@ public class AutoSkipTrigger : ITaskTrigger // 删除为空的结果 和 纯英文的结果 var rs = new List(); // 按照y坐标排序 - ocrResList = ocrResList.OrderBy(r => r.Y).ToList(); + ocrResList = [.. ocrResList.OrderBy(r => r.Y)]; for (var i = 0; i < ocrResList.Count; i++) { var item = ocrResList[i]; - if (string.IsNullOrEmpty(item.Text) || (item.Text.Length < 5 && _enOrNumRegex.IsMatch(item.Text))) + if (string.IsNullOrEmpty(item.Text) || (item.Text.Length < 5 && EnOrNumRegex().IsMatch(item.Text))) { continue; } diff --git a/BetterGenshinImpact/GameTask/AutoSkip/AutoTrackTask.cs b/BetterGenshinImpact/GameTask/AutoSkip/AutoTrackTask.cs index 20ad7f2e..2c1d73ee 100644 --- a/BetterGenshinImpact/GameTask/AutoSkip/AutoTrackTask.cs +++ b/BetterGenshinImpact/GameTask/AutoSkip/AutoTrackTask.cs @@ -4,25 +4,23 @@ using BetterGenshinImpact.Core.Recognition.OpenCv; using BetterGenshinImpact.Core.Simulator; using BetterGenshinImpact.GameTask.AutoGeniusInvokation.Exception; using BetterGenshinImpact.GameTask.AutoSkip.Model; +using BetterGenshinImpact.GameTask.Common; +using BetterGenshinImpact.GameTask.Common.BgiVision; using BetterGenshinImpact.GameTask.Common.Element.Assets; using BetterGenshinImpact.GameTask.Model; +using BetterGenshinImpact.GameTask.Model.Area; using BetterGenshinImpact.GameTask.QuickTeleport.Assets; using BetterGenshinImpact.Helpers; -using BetterGenshinImpact.Service.Notification; using BetterGenshinImpact.View.Drawable; +using BetterGenshinImpact.ViewModel.Pages; using Microsoft.Extensions.Logging; using OpenCvSharp; using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; -using BetterGenshinImpact.GameTask.Common; -using BetterGenshinImpact.GameTask.Common.BgiVision; -using BetterGenshinImpact.GameTask.Model.Area; -using BetterGenshinImpact.ViewModel.Pages; using Vanara.PInvoke; using static BetterGenshinImpact.GameTask.Common.TaskControl; -using WinRT; namespace BetterGenshinImpact.GameTask.AutoSkip; @@ -285,7 +283,7 @@ public class AutoTrackTask(AutoTrackParam param) : BaseIndependentTask foreach (var textRa in textRaList) { - if (textRa.Text.Length < 8 && (textRa.Text.Contains("m") || textRa.Text.Contains("M"))) + if (textRa.Text.Length < 8 && textRa.Text.Contains('m', StringComparison.OrdinalIgnoreCase)) { _missionDistanceRect = textRa.ConvertSelfPositionToGameCaptureRegion(); return StringUtils.TryExtractPositiveInt(textRa.Text); diff --git a/BetterGenshinImpact/GameTask/AutoSkip/ExpeditionTask.cs b/BetterGenshinImpact/GameTask/AutoSkip/ExpeditionTask.cs index 50f45666..4a4751ce 100644 --- a/BetterGenshinImpact/GameTask/AutoSkip/ExpeditionTask.cs +++ b/BetterGenshinImpact/GameTask/AutoSkip/ExpeditionTask.cs @@ -4,7 +4,6 @@ using BetterGenshinImpact.GameTask.Common; using BetterGenshinImpact.View.Drawable; using Microsoft.Extensions.Logging; using OpenCvSharp; -using OpenCvSharp.Extensions; using Sdcb.PaddleOCR; using System; using System.Collections.Generic; @@ -23,7 +22,7 @@ namespace BetterGenshinImpact.GameTask.AutoSkip; [Obsolete] public class ExpeditionTask { - private static readonly List ExpeditionCharacterList = new(); + private static readonly List ExpeditionCharacterList = []; private int _expeditionCount = 0; @@ -129,12 +128,7 @@ public class ExpeditionTask var cards = GetCharacterCards(result); if (cards.Count > 0) { - var card = cards.FirstOrDefault(c => c.Idle && c.Name != null && ExpeditionCharacterList.Contains(c.Name)); - if (card == null) - { - card = cards.First(c => c.Idle); - } - + var card = cards.FirstOrDefault(c => c.Idle && c.Name != null && ExpeditionCharacterList.Contains(c.Name)) ?? cards.First(c => c.Idle); var rect = card.Rects.First(); using var ra = content.CaptureRectArea.Derive(rect); @@ -158,9 +152,12 @@ public class ExpeditionTask var captureRect = TaskContext.Instance().SystemInfo.CaptureAreaRect; var assetScale = TaskContext.Instance().SystemInfo.AssetScale; - var ocrResultRects = result.Regions.Select(x => x.ToOcrResultRect()).ToList(); - ocrResultRects = ocrResultRects.Where(r => r.Rect.X + r.Rect.Width < captureRect.Width / 2) - .OrderBy(r => r.Rect.Y).ThenBy(r => r.Rect.X).ToList(); + var ocrResultRects = result.Regions + .Select(x => x.ToOcrResultRect()) + .Where(r => r.Rect.X + r.Rect.Width < captureRect.Width / 2) + .OrderBy(r => r.Rect.Y) + .ThenBy(r => r.Rect.X) + .ToList(); var cards = new List(); foreach (var ocrResultRect in ocrResultRects) diff --git a/BetterGenshinImpact/GameTask/AutoSkip/Model/AutoTrackParam.cs b/BetterGenshinImpact/GameTask/AutoSkip/Model/AutoTrackParam.cs index 36bdeca4..3effef35 100644 --- a/BetterGenshinImpact/GameTask/AutoSkip/Model/AutoTrackParam.cs +++ b/BetterGenshinImpact/GameTask/AutoSkip/Model/AutoTrackParam.cs @@ -1,5 +1,5 @@ -using System.Threading; -using BetterGenshinImpact.GameTask.Model; +using BetterGenshinImpact.GameTask.Model; +using System.Threading; namespace BetterGenshinImpact.GameTask.AutoSkip.Model; diff --git a/BetterGenshinImpact/GameTask/AutoSkip/Model/ExpeditionCharacterCard.cs b/BetterGenshinImpact/GameTask/AutoSkip/Model/ExpeditionCharacterCard.cs index 51e62b0a..8e19525d 100644 --- a/BetterGenshinImpact/GameTask/AutoSkip/Model/ExpeditionCharacterCard.cs +++ b/BetterGenshinImpact/GameTask/AutoSkip/Model/ExpeditionCharacterCard.cs @@ -12,7 +12,7 @@ public class ExpeditionCharacterCard public string? Addition { get; set; } - public List Rects { get; set; } = new(); + public List Rects { get; set; } = []; //public ExpeditionCharacterCard(string name,string addition, bool idle) //{ diff --git a/BetterGenshinImpact/GameTask/AutoTrackPath/AutoTrackPathParam.cs b/BetterGenshinImpact/GameTask/AutoTrackPath/AutoTrackPathParam.cs index 17ce5fed..fde6b6bc 100644 --- a/BetterGenshinImpact/GameTask/AutoTrackPath/AutoTrackPathParam.cs +++ b/BetterGenshinImpact/GameTask/AutoTrackPath/AutoTrackPathParam.cs @@ -1,5 +1,5 @@ -using System.Threading; -using BetterGenshinImpact.GameTask.Model; +using BetterGenshinImpact.GameTask.Model; +using System.Threading; namespace BetterGenshinImpact.GameTask.AutoTrackPath; diff --git a/BetterGenshinImpact/GameTask/AutoTrackPath/AutoTrackPathTask.cs b/BetterGenshinImpact/GameTask/AutoTrackPath/AutoTrackPathTask.cs index 71356806..b0bf7f4f 100644 --- a/BetterGenshinImpact/GameTask/AutoTrackPath/AutoTrackPathTask.cs +++ b/BetterGenshinImpact/GameTask/AutoTrackPath/AutoTrackPathTask.cs @@ -1,16 +1,15 @@ using BetterGenshinImpact.Core.Config; -using BetterGenshinImpact.Core.Recognition; -using BetterGenshinImpact.Core.Recognition.OpenCv; using BetterGenshinImpact.Core.Simulator; using BetterGenshinImpact.GameTask.AutoGeniusInvokation.Exception; using BetterGenshinImpact.GameTask.AutoTrackPath.Model; using BetterGenshinImpact.GameTask.Common; +using BetterGenshinImpact.GameTask.Common.BgiVision; using BetterGenshinImpact.GameTask.Common.Element.Assets; using BetterGenshinImpact.GameTask.Common.Map; using BetterGenshinImpact.GameTask.Model.Area; using BetterGenshinImpact.GameTask.Model.Enum; -using BetterGenshinImpact.GameTask.QuickTeleport.Assets; using BetterGenshinImpact.Helpers; +using BetterGenshinImpact.Helpers.Extensions; using BetterGenshinImpact.Service; using BetterGenshinImpact.View.Drawable; using BetterGenshinImpact.ViewModel.Pages; @@ -21,16 +20,11 @@ using System.Collections.Generic; using System.Diagnostics; using System.Drawing; using System.IO; -using System.Linq; using System.Text.Json; using System.Threading; using System.Threading.Tasks; -using BetterGenshinImpact.GameTask.Common.BgiVision; -using BetterGenshinImpact.Helpers.Extensions; using Vanara.PInvoke; using static BetterGenshinImpact.GameTask.Common.TaskControl; -using static Vanara.PInvoke.Gdi32; -using Point = OpenCvSharp.Point; namespace BetterGenshinImpact.GameTask.AutoTrackPath; @@ -122,11 +116,7 @@ public class AutoTrackPathTask NewRetry.Do((Action)(() => { var ra = TaskControl.CaptureToRectArea(); - var miniMapMat = GetMiniMapMat(ra); - if (miniMapMat == null) - { - throw new RetryException("等待传送完成"); - } + var miniMapMat = GetMiniMapMat(ra) ?? throw new RetryException("等待传送完成"); }), TimeSpan.FromSeconds(1), 100); Logger.LogInformation("传送完成"); Sleep(1000); @@ -218,11 +208,7 @@ public class AutoTrackPathTask while (!_taskParam.Cts.IsCancellationRequested) { var ra = CaptureToRectArea(); - var miniMapMat = GetMiniMapMat(ra); - if (miniMapMat == null) - { - throw new InvalidOperationException("当前不在主界面"); - } + var miniMapMat = GetMiniMapMat(ra) ?? throw new InvalidOperationException("当前不在主界面"); // 注意游戏坐标系的角度是顺时针的 var currMapImageAvatarPos = EntireMap.Instance.GetMiniMapPositionByFeatureMatch(miniMapMat); @@ -356,12 +342,7 @@ public class AutoTrackPathTask public int GetCharacterOrientationAngle() { var ra = CaptureToRectArea(); - var miniMapMat = GetMiniMapMat(ra); - if (miniMapMat == null) - { - throw new InvalidOperationException("当前不在主界面"); - } - + var miniMapMat = GetMiniMapMat(ra) ?? throw new InvalidOperationException("当前不在主界面"); var angle = CharacterOrientation.Compute(miniMapMat); Logger.LogInformation("当前角度:{Angle}", angle); // CameraOrientation.DrawDirection(ra, angle); diff --git a/BetterGenshinImpact/GameTask/AutoTrackPath/Model/GiPath.cs b/BetterGenshinImpact/GameTask/AutoTrackPath/Model/GiPath.cs index 37c5b634..1a2f5170 100644 --- a/BetterGenshinImpact/GameTask/AutoTrackPath/Model/GiPath.cs +++ b/BetterGenshinImpact/GameTask/AutoTrackPath/Model/GiPath.cs @@ -1,15 +1,15 @@ -using System; +using BetterGenshinImpact.Helpers; +using OpenCvSharp; +using System; using System.Collections.Generic; using System.Diagnostics; -using BetterGenshinImpact.Helpers; -using OpenCvSharp; namespace BetterGenshinImpact.GameTask.AutoTrackPath.Model; [Serializable] public class GiPath { - public List WayPointList { get; set; } = new(); + public List WayPointList { get; set; } = []; public void AddPoint(Point2f point) { diff --git a/BetterGenshinImpact/GameTask/AutoTrackPath/Model/GiPathPoint.cs b/BetterGenshinImpact/GameTask/AutoTrackPath/Model/GiPathPoint.cs index e4f13e9c..7a2fdd0f 100644 --- a/BetterGenshinImpact/GameTask/AutoTrackPath/Model/GiPathPoint.cs +++ b/BetterGenshinImpact/GameTask/AutoTrackPath/Model/GiPathPoint.cs @@ -1,7 +1,6 @@ -using System; -using BetterGenshinImpact.Core.Recognition.OpenCv; -using BetterGenshinImpact.GameTask.Common.Map; +using BetterGenshinImpact.GameTask.Common.Map; using OpenCvSharp; +using System; namespace BetterGenshinImpact.GameTask.AutoTrackPath.Model; diff --git a/BetterGenshinImpact/GameTask/AutoTrackPath/PathPointRecorder.cs b/BetterGenshinImpact/GameTask/AutoTrackPath/PathPointRecorder.cs index 7a3e55e0..dedd4d7d 100644 --- a/BetterGenshinImpact/GameTask/AutoTrackPath/PathPointRecorder.cs +++ b/BetterGenshinImpact/GameTask/AutoTrackPath/PathPointRecorder.cs @@ -1,10 +1,4 @@ -using System; -using System.Diagnostics; -using System.IO; -using System.Text.Json; -using System.Threading; -using System.Threading.Tasks; -using BetterGenshinImpact.Core.Config; +using BetterGenshinImpact.Core.Config; using BetterGenshinImpact.Core.Recognition.OpenCv; using BetterGenshinImpact.GameTask.AutoGeniusInvokation.Exception; using BetterGenshinImpact.GameTask.AutoTrackPath.Model; @@ -16,6 +10,12 @@ using BetterGenshinImpact.Model; using BetterGenshinImpact.Service; using Microsoft.Extensions.Logging; using OpenCvSharp; +using System; +using System.Diagnostics; +using System.IO; +using System.Text.Json; +using System.Threading; +using System.Threading.Tasks; using static BetterGenshinImpact.GameTask.Common.TaskControl; namespace BetterGenshinImpact.GameTask.AutoTrackPath; diff --git a/BetterGenshinImpact/GameTask/AutoTrackPath/TpTask.cs b/BetterGenshinImpact/GameTask/AutoTrackPath/TpTask.cs index dfbedb79..d15fe0c1 100644 --- a/BetterGenshinImpact/GameTask/AutoTrackPath/TpTask.cs +++ b/BetterGenshinImpact/GameTask/AutoTrackPath/TpTask.cs @@ -6,6 +6,7 @@ using BetterGenshinImpact.GameTask.Common.Element.Assets; using BetterGenshinImpact.GameTask.Common.Map; using BetterGenshinImpact.GameTask.Model.Area; using BetterGenshinImpact.GameTask.QuickTeleport.Assets; +using BetterGenshinImpact.Helpers.Extensions; using Microsoft.Extensions.Logging; using OpenCvSharp; using System; @@ -13,7 +14,6 @@ using System.Diagnostics; using System.Linq; using System.Threading; using System.Threading.Tasks; -using BetterGenshinImpact.Helpers.Extensions; using Vanara.PInvoke; using static BetterGenshinImpact.GameTask.Common.TaskControl; @@ -24,8 +24,6 @@ namespace BetterGenshinImpact.GameTask.AutoTrackPath; /// public class TpTask(CancellationTokenSource cts) { - private static readonly Random _rd = new Random(); - private readonly QuickTeleportAssets _assets = QuickTeleportAssets.Instance; /// @@ -145,7 +143,7 @@ public class TpTask(CancellationTokenSource cts) public async Task MouseMoveMapX(int dx) { var moveUnit = dx > 0 ? 20 : -20; - GameCaptureRegion.GameRegionMove((rect, _) => (rect.Width / 2d + _rd.Next(-rect.Width / 6, rect.Width / 6), rect.Height / 2d + _rd.Next(-rect.Height / 6, rect.Height / 6))); + GameCaptureRegion.GameRegionMove((rect, _) => (rect.Width / 2d + Random.Shared.Next(-rect.Width / 6, rect.Width / 6), rect.Height / 2d + Random.Shared.Next(-rect.Height / 6, rect.Height / 6))); Simulation.SendInput.Mouse.LeftButtonDown(); await Delay(200, cts); for (var i = 0; i < dx / moveUnit; i++) @@ -160,7 +158,7 @@ public class TpTask(CancellationTokenSource cts) public async Task MouseMoveMapY(int dy) { var moveUnit = dy > 0 ? 20 : -20; - GameCaptureRegion.GameRegionMove((rect, _) => (rect.Width / 2d + _rd.Next(-rect.Width / 6, rect.Width / 6), rect.Height / 2d + _rd.Next(-rect.Height / 6, rect.Height / 6))); + GameCaptureRegion.GameRegionMove((rect, _) => (rect.Width / 2d + Random.Shared.Next(-rect.Width / 6, rect.Width / 6), rect.Height / 2d + Random.Shared.Next(-rect.Height / 6, rect.Height / 6))); Simulation.SendInput.Mouse.LeftButtonDown(); await Delay(200, cts); // 原神地图在小范围内移动是无效的,所以先随便移动一下,所以肯定少移动一次 @@ -365,7 +363,7 @@ public class TpTask(CancellationTokenSource cts) // 按高度排序 if (rResultList.Count > 0) { - rResultList = rResultList.OrderBy(x => x.Y).ToList(); + rResultList = [.. rResultList.OrderBy(x => x.Y)]; // 点击最高的 foreach (var iconRect in rResultList) { diff --git a/BetterGenshinImpact/GameTask/AutoWood/Assets/AutoWoodAssets.cs b/BetterGenshinImpact/GameTask/AutoWood/Assets/AutoWoodAssets.cs index a7047c99..36b927bf 100644 --- a/BetterGenshinImpact/GameTask/AutoWood/Assets/AutoWoodAssets.cs +++ b/BetterGenshinImpact/GameTask/AutoWood/Assets/AutoWoodAssets.cs @@ -16,7 +16,7 @@ public class AutoWoodAssets : BaseAssets // 木头数量 public Rect WoodCountUpperRect; - + private AutoWoodAssets() { diff --git a/BetterGenshinImpact/GameTask/AutoWood/AutoWoodTask.cs b/BetterGenshinImpact/GameTask/AutoWood/AutoWoodTask.cs index 74ccec21..ca49915a 100644 --- a/BetterGenshinImpact/GameTask/AutoWood/AutoWoodTask.cs +++ b/BetterGenshinImpact/GameTask/AutoWood/AutoWoodTask.cs @@ -151,8 +151,8 @@ public partial class AutoWoodTask private bool _firstWoodOcr = true; private string _firstWoodOcrText = ""; - private readonly Dictionary _woodMetricsDict = new(); - private readonly Dictionary _woodNotPrintDict = new(); + private readonly Dictionary _woodMetricsDict = []; + private readonly Dictionary _woodNotPrintDict = []; // from:https://api-static.mihoyo.com/common/blackboard/ys_obc/v1/home/content/list?app_sn=ys_obc&channel_id=13 private static readonly List ExistWoods = diff --git a/BetterGenshinImpact/GameTask/AutoWood/WoodTaskParam.cs b/BetterGenshinImpact/GameTask/AutoWood/WoodTaskParam.cs index 9666a548..f9dad4a9 100644 --- a/BetterGenshinImpact/GameTask/AutoWood/WoodTaskParam.cs +++ b/BetterGenshinImpact/GameTask/AutoWood/WoodTaskParam.cs @@ -1,6 +1,5 @@ -using System; +using BetterGenshinImpact.GameTask.Model; using System.Threading; -using BetterGenshinImpact.GameTask.Model; namespace BetterGenshinImpact.GameTask.AutoWood; diff --git a/BetterGenshinImpact/GameTask/Common/BgiVision/BvSimpleOperation.cs b/BetterGenshinImpact/GameTask/Common/BgiVision/BvSimpleOperation.cs index 0d68661e..d64ef49e 100644 --- a/BetterGenshinImpact/GameTask/Common/BgiVision/BvSimpleOperation.cs +++ b/BetterGenshinImpact/GameTask/Common/BgiVision/BvSimpleOperation.cs @@ -1,5 +1,4 @@ using BetterGenshinImpact.GameTask.Common.Element.Assets; -using BetterGenshinImpact.GameTask.Model; using BetterGenshinImpact.GameTask.Model.Area; namespace BetterGenshinImpact.GameTask.Common.BgiVision; diff --git a/BetterGenshinImpact/GameTask/Common/Map/BigMap.cs b/BetterGenshinImpact/GameTask/Common/Map/BigMap.cs index dfdc92c0..ef3ca258 100644 --- a/BetterGenshinImpact/GameTask/Common/Map/BigMap.cs +++ b/BetterGenshinImpact/GameTask/Common/Map/BigMap.cs @@ -1,11 +1,9 @@ -using System; -using System.Diagnostics; -using BetterGenshinImpact.Core.Recognition.OpenCv; +using BetterGenshinImpact.Core.Recognition.OpenCv; using BetterGenshinImpact.Core.Recognition.OpenCv.FeatureMatch; using BetterGenshinImpact.GameTask.Common.Element.Assets; -using BetterGenshinImpact.Helpers.Extensions; using BetterGenshinImpact.Model; using OpenCvSharp; +using System.Diagnostics; namespace BetterGenshinImpact.GameTask.Common.Map; diff --git a/BetterGenshinImpact/GameTask/Common/Map/CameraOrientation.cs b/BetterGenshinImpact/GameTask/Common/Map/CameraOrientation.cs index 3a7ca15e..f625da6c 100644 --- a/BetterGenshinImpact/GameTask/Common/Map/CameraOrientation.cs +++ b/BetterGenshinImpact/GameTask/Common/Map/CameraOrientation.cs @@ -104,17 +104,14 @@ public class CameraOrientation // }; // VisionContext.Instance().DrawContent.PutLine("camera", line); - if (pen == null) - { - pen = new Pen(Color.Yellow, 1); - } + pen ??= new Pen(Color.Yellow, 1); region.DrawLine(center.X, center.Y, (int)x1, (int)y1, name, pen); } static List FindPeaks(float[] data) { - List peakIndices = new List(); + List peakIndices = []; for (int i = 1; i < data.Length - 1; i++) { diff --git a/BetterGenshinImpact/GameTask/Common/Map/EntireMap.cs b/BetterGenshinImpact/GameTask/Common/Map/EntireMap.cs index 8e9912cd..0d52671e 100644 --- a/BetterGenshinImpact/GameTask/Common/Map/EntireMap.cs +++ b/BetterGenshinImpact/GameTask/Common/Map/EntireMap.cs @@ -1,14 +1,9 @@ -using BetterGenshinImpact.Core.Recognition.OpenCv; -using BetterGenshinImpact.Core.Recognition.OpenCv.FeatureMatch; -using BetterGenshinImpact.GameTask.Common.Element.Assets; +using BetterGenshinImpact.Core.Recognition.OpenCv.FeatureMatch; +using BetterGenshinImpact.Helpers.Extensions; using BetterGenshinImpact.Model; -using CommunityToolkit.Mvvm.Messaging; -using CommunityToolkit.Mvvm.Messaging.Messages; using OpenCvSharp; using System; using System.Diagnostics; -using BetterGenshinImpact.Helpers.Extensions; -using Point = OpenCvSharp.Point; using Size = OpenCvSharp.Size; namespace BetterGenshinImpact.GameTask.Common.Map; @@ -19,7 +14,7 @@ public class EntireMap : Singleton public static readonly Size TemplateSize = new(240, 135); // 对无用部分进行裁剪(左160,上80,下96) - public static readonly Rect TemplateSizeRoi = new Rect(20, 10, TemplateSize.Width - 20, TemplateSize.Height - 22); + public static readonly Rect TemplateSizeRoi = new(20, 10, TemplateSize.Width - 20, TemplateSize.Height - 22); /// /// 主要地图缩小1024的模板 diff --git a/BetterGenshinImpact/GameTask/Common/NewRetry.cs b/BetterGenshinImpact/GameTask/Common/NewRetry.cs index 316110b2..113c61f3 100644 --- a/BetterGenshinImpact/GameTask/Common/NewRetry.cs +++ b/BetterGenshinImpact/GameTask/Common/NewRetry.cs @@ -1,8 +1,8 @@ -using System; +using BetterGenshinImpact.GameTask.AutoGeniusInvokation.Exception; +using System; using System.Collections.Generic; using System.Linq; using System.Threading; -using BetterGenshinImpact.GameTask.AutoGeniusInvokation.Exception; namespace BetterGenshinImpact.GameTask.Common; diff --git a/BetterGenshinImpact/GameTask/Common/TaskControl.cs b/BetterGenshinImpact/GameTask/Common/TaskControl.cs index 0fb5de20..f45fd0af 100644 --- a/BetterGenshinImpact/GameTask/Common/TaskControl.cs +++ b/BetterGenshinImpact/GameTask/Common/TaskControl.cs @@ -1,12 +1,11 @@ using BetterGenshinImpact.GameTask.AutoGeniusInvokation.Exception; -using BetterGenshinImpact.GameTask.Model; +using BetterGenshinImpact.GameTask.Model.Area; using Fischless.GameCapture; using Microsoft.Extensions.Logging; using System; using System.Drawing; using System.Threading; using System.Threading.Tasks; -using BetterGenshinImpact.GameTask.Model.Area; namespace BetterGenshinImpact.GameTask.Common; diff --git a/BetterGenshinImpact/GameTask/Common/YoloManager.cs b/BetterGenshinImpact/GameTask/Common/YoloManager.cs index b33a90ec..fdf2400e 100644 --- a/BetterGenshinImpact/GameTask/Common/YoloManager.cs +++ b/BetterGenshinImpact/GameTask/Common/YoloManager.cs @@ -1,9 +1,4 @@ -using BetterGenshinImpact.Core.Config; -using BetterGenshinImpact.Model; -using Compunet.YoloV8; -using System; - -namespace BetterGenshinImpact.GameTask.Common; +namespace BetterGenshinImpact.GameTask.Common; // [Obsolete] // public class YoloManager : Singleton, IDisposable diff --git a/BetterGenshinImpact/GameTask/GameTaskManager.cs b/BetterGenshinImpact/GameTask/GameTaskManager.cs index 3806e52a..b0328f70 100644 --- a/BetterGenshinImpact/GameTask/GameTaskManager.cs +++ b/BetterGenshinImpact/GameTask/GameTaskManager.cs @@ -1,11 +1,5 @@ using BetterGenshinImpact.Core.Config; using BetterGenshinImpact.Core.Recognition.OpenCv; -using CommunityToolkit.Mvvm.Messaging.Messages; -using CommunityToolkit.Mvvm.Messaging; -using OpenCvSharp; -using System.Collections.Generic; -using System.IO; -using System.Linq; using BetterGenshinImpact.Core.Script.Dependence.Model.TimerConfig; using BetterGenshinImpact.GameTask.AutoFight.Assets; using BetterGenshinImpact.GameTask.AutoFishing.Assets; @@ -20,7 +14,13 @@ using BetterGenshinImpact.GameTask.Placeholder; using BetterGenshinImpact.GameTask.QuickSereniteaPot.Assets; using BetterGenshinImpact.GameTask.QuickTeleport.Assets; using BetterGenshinImpact.View.Drawable; +using CommunityToolkit.Mvvm.Messaging; +using CommunityToolkit.Mvvm.Messaging.Messages; +using OpenCvSharp; using System.Collections.Concurrent; +using System.Collections.Generic; +using System.IO; +using System.Linq; namespace BetterGenshinImpact.GameTask; @@ -63,7 +63,7 @@ internal class GameTaskManager loadedTriggers.ForEach(i => i.IsEnabled = true); } - loadedTriggers = loadedTriggers.OrderByDescending(i => i.Priority).ToList(); + loadedTriggers = [.. loadedTriggers.OrderByDescending(i => i.Priority)]; return loadedTriggers; } diff --git a/BetterGenshinImpact/GameTask/Macro/QuickEnhanceArtifactMacro.cs b/BetterGenshinImpact/GameTask/Macro/QuickEnhanceArtifactMacro.cs index 19f3a4b4..27886eea 100644 --- a/BetterGenshinImpact/GameTask/Macro/QuickEnhanceArtifactMacro.cs +++ b/BetterGenshinImpact/GameTask/Macro/QuickEnhanceArtifactMacro.cs @@ -1,5 +1,4 @@ using BetterGenshinImpact.GameTask.Model.Area; -using BetterGenshinImpact.Helpers; using System.Threading; using System.Windows; diff --git a/BetterGenshinImpact/GameTask/Model/Area/Converter/ConvertRes.cs b/BetterGenshinImpact/GameTask/Model/Area/Converter/ConvertRes.cs index 6b5a8de9..f69a823e 100644 --- a/BetterGenshinImpact/GameTask/Model/Area/Converter/ConvertRes.cs +++ b/BetterGenshinImpact/GameTask/Model/Area/Converter/ConvertRes.cs @@ -1,5 +1,5 @@ -using System; -using OpenCvSharp; +using OpenCvSharp; +using System; namespace BetterGenshinImpact.GameTask.Model.Area.Converter; diff --git a/BetterGenshinImpact/GameTask/Model/Area/Region.cs b/BetterGenshinImpact/GameTask/Model/Area/Region.cs index f7f7ba04..85a1457e 100644 --- a/BetterGenshinImpact/GameTask/Model/Area/Region.cs +++ b/BetterGenshinImpact/GameTask/Model/Area/Region.cs @@ -2,7 +2,6 @@ using BetterGenshinImpact.View.Drawable; using OpenCvSharp; using System; -using System.Collections.Generic; using System.Diagnostics; using System.Drawing; using System.Threading; diff --git a/BetterGenshinImpact/GameTask/Model/BaseAssets.cs b/BetterGenshinImpact/GameTask/Model/BaseAssets.cs index 8caf5d84..bddb9acd 100644 --- a/BetterGenshinImpact/GameTask/Model/BaseAssets.cs +++ b/BetterGenshinImpact/GameTask/Model/BaseAssets.cs @@ -1,6 +1,5 @@ using BetterGenshinImpact.Model; using OpenCvSharp; -using System.Threading; namespace BetterGenshinImpact.GameTask.Model; diff --git a/BetterGenshinImpact/GameTask/Model/BaseIndependentTask.cs b/BetterGenshinImpact/GameTask/Model/BaseIndependentTask.cs index 65939d70..395a08e7 100644 --- a/BetterGenshinImpact/GameTask/Model/BaseIndependentTask.cs +++ b/BetterGenshinImpact/GameTask/Model/BaseIndependentTask.cs @@ -1,5 +1,4 @@ -using BetterGenshinImpact.Helpers; -using Vanara.PInvoke; +using Vanara.PInvoke; namespace BetterGenshinImpact.GameTask.Model; diff --git a/BetterGenshinImpact/GameTask/Model/BaseTaskParam.cs b/BetterGenshinImpact/GameTask/Model/BaseTaskParam.cs index d9bf9c7c..85ba0b1f 100644 --- a/BetterGenshinImpact/GameTask/Model/BaseTaskParam.cs +++ b/BetterGenshinImpact/GameTask/Model/BaseTaskParam.cs @@ -1,5 +1,5 @@ -using System.Threading; -using BetterGenshinImpact.GameTask.Model.Enum; +using BetterGenshinImpact.GameTask.Model.Enum; +using System.Threading; namespace BetterGenshinImpact.GameTask.Model; diff --git a/BetterGenshinImpact/GameTask/Model/SystemInfo.cs b/BetterGenshinImpact/GameTask/Model/SystemInfo.cs index 56a2100f..5dbd06ab 100644 --- a/BetterGenshinImpact/GameTask/Model/SystemInfo.cs +++ b/BetterGenshinImpact/GameTask/Model/SystemInfo.cs @@ -1,8 +1,8 @@ using BetterGenshinImpact.GameTask.Model.Area; using BetterGenshinImpact.Helpers; +using OpenCvSharp; using System; using System.Diagnostics; -using OpenCvSharp; using Vanara.PInvoke; using Size = System.Drawing.Size; diff --git a/BetterGenshinImpact/GameTask/Model/TaskRunnerParam.cs b/BetterGenshinImpact/GameTask/Model/TaskRunnerParam.cs index 8f64a98a..685847c1 100644 --- a/BetterGenshinImpact/GameTask/Model/TaskRunnerParam.cs +++ b/BetterGenshinImpact/GameTask/Model/TaskRunnerParam.cs @@ -1,5 +1,5 @@ -using System.Threading; -using BetterGenshinImpact.GameTask.Model.Enum; +using BetterGenshinImpact.GameTask.Model.Enum; +using System.Threading; namespace BetterGenshinImpact.GameTask.Model; diff --git a/BetterGenshinImpact/GameTask/Placeholder/PlaceholderTrigger.cs b/BetterGenshinImpact/GameTask/Placeholder/PlaceholderTrigger.cs index 72f94881..1d105ed0 100644 --- a/BetterGenshinImpact/GameTask/Placeholder/PlaceholderTrigger.cs +++ b/BetterGenshinImpact/GameTask/Placeholder/PlaceholderTrigger.cs @@ -1,16 +1,8 @@ -using BetterGenshinImpact.Core.Recognition.OpenCv; -using BetterGenshinImpact.GameTask.Common.Map; -using BetterGenshinImpact.View.Drawable; -using OpenCvSharp; +using OpenCvSharp; using System; using System.Collections.Generic; using System.Drawing; using System.Linq; -using BetterGenshinImpact.Core.Config; -using BetterGenshinImpact.GameTask.Common.BgiVision; -using BetterGenshinImpact.GameTask.Common.Element.Assets; -using CommunityToolkit.Mvvm.Messaging; -using CommunityToolkit.Mvvm.Messaging.Messages; using Point = OpenCvSharp.Point; using Size = OpenCvSharp.Size; @@ -313,7 +305,7 @@ public class TestTrigger : ITaskTrigger static List FindPeaks(float[] data) { - List peakIndices = new List(); + List peakIndices = []; for (int i = 1; i < data.Length - 1; i++) { diff --git a/BetterGenshinImpact/GameTask/QuickForge/QuickForgeTask.cs b/BetterGenshinImpact/GameTask/QuickForge/QuickForgeTask.cs index 98080547..bf79e621 100644 --- a/BetterGenshinImpact/GameTask/QuickForge/QuickForgeTask.cs +++ b/BetterGenshinImpact/GameTask/QuickForge/QuickForgeTask.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BetterGenshinImpact.GameTask.QuickForge +namespace BetterGenshinImpact.GameTask.QuickForge { internal class QuickForgeTask { diff --git a/BetterGenshinImpact/GameTask/QuickTeleport/Assets/QuickTeleportAssets.cs b/BetterGenshinImpact/GameTask/QuickTeleport/Assets/QuickTeleportAssets.cs index e30caaa3..03975a2b 100644 --- a/BetterGenshinImpact/GameTask/QuickTeleport/Assets/QuickTeleportAssets.cs +++ b/BetterGenshinImpact/GameTask/QuickTeleport/Assets/QuickTeleportAssets.cs @@ -25,8 +25,8 @@ public class QuickTeleportAssets : BaseAssets (int)(100 * AssetScale), (int)(50 * AssetScale), CaptureRect.Height - (int)(200 * AssetScale)); - MapChooseIconRoList = new List - { + MapChooseIconRoList = + [ BuildMapChooseIconRo("TeleportWaypoint.png"), BuildMapChooseIconRo("StatueOfTheSeven.png"), BuildMapChooseIconRo("Domain.png"), @@ -34,7 +34,7 @@ public class QuickTeleportAssets : BaseAssets BuildMapChooseIconRo("PortableWaypoint.png"), BuildMapChooseIconRo("Mansion.png"), BuildMapChooseIconRo("SubSpaceWaypoint.png"), - }; + ]; MapChooseIconGreyMatList = MapChooseIconRoList.ConvertAll(x => x.TemplateImageGreyMat ?? new Mat()); // 传送按钮宽泛的识别区域 diff --git a/BetterGenshinImpact/GameTask/QuickTeleport/QuickTeleportTrigger.cs b/BetterGenshinImpact/GameTask/QuickTeleport/QuickTeleportTrigger.cs index 1a5f4544..e8514d7c 100644 --- a/BetterGenshinImpact/GameTask/QuickTeleport/QuickTeleportTrigger.cs +++ b/BetterGenshinImpact/GameTask/QuickTeleport/QuickTeleportTrigger.cs @@ -1,16 +1,15 @@ -using BetterGenshinImpact.Core.Recognition.OCR; +using BetterGenshinImpact.Core.Config; +using BetterGenshinImpact.Core.Recognition; using BetterGenshinImpact.Core.Recognition.OpenCv; using BetterGenshinImpact.GameTask.Common; +using BetterGenshinImpact.GameTask.Model.Area; using BetterGenshinImpact.GameTask.QuickTeleport.Assets; +using BetterGenshinImpact.Model; using Microsoft.Extensions.Logging; using OpenCvSharp; using System; using System.Linq; -using BetterGenshinImpact.Core.Config; -using BetterGenshinImpact.Model; using System.Windows.Forms; -using BetterGenshinImpact.Core.Recognition; -using BetterGenshinImpact.GameTask.Model.Area; namespace BetterGenshinImpact.GameTask.QuickTeleport; @@ -129,7 +128,7 @@ internal class QuickTeleportTrigger : ITaskTrigger // 按高度排序 if (rResultList.Count > 0) { - rResultList = rResultList.OrderBy(x => x.Y).ToList(); + rResultList = [.. rResultList.OrderBy(x => x.Y)]; // 点击最高的 foreach (var iconRect in rResultList) { diff --git a/BetterGenshinImpact/GameTask/SystemControl.cs b/BetterGenshinImpact/GameTask/SystemControl.cs index f5e570e0..ad6564fe 100644 --- a/BetterGenshinImpact/GameTask/SystemControl.cs +++ b/BetterGenshinImpact/GameTask/SystemControl.cs @@ -1,7 +1,6 @@ using System; using System.Diagnostics; using System.IO; -using System.Linq; using System.Threading.Tasks; using Vanara.PInvoke; @@ -62,7 +61,7 @@ public class SystemControl foreach (var name in names) { var pros = Process.GetProcessesByName(name); - if (pros.Any()) + if (pros.Length is not 0) { return pros[0].MainWindowHandle; } diff --git a/BetterGenshinImpact/GameTask/TaskContext.cs b/BetterGenshinImpact/GameTask/TaskContext.cs index de302237..1f4ea76e 100644 --- a/BetterGenshinImpact/GameTask/TaskContext.cs +++ b/BetterGenshinImpact/GameTask/TaskContext.cs @@ -1,11 +1,11 @@ using BetterGenshinImpact.Core.Config; +using BetterGenshinImpact.Core.Simulator; using BetterGenshinImpact.GameTask.Model; using BetterGenshinImpact.Genshin.Settings; using BetterGenshinImpact.Helpers; using BetterGenshinImpact.Service; using System; using System.Threading; -using BetterGenshinImpact.Core.Simulator; namespace BetterGenshinImpact.GameTask { diff --git a/BetterGenshinImpact/GameTask/TaskTriggerDispatcher.cs b/BetterGenshinImpact/GameTask/TaskTriggerDispatcher.cs index 43657d76..41d89013 100644 --- a/BetterGenshinImpact/GameTask/TaskTriggerDispatcher.cs +++ b/BetterGenshinImpact/GameTask/TaskTriggerDispatcher.cs @@ -2,10 +2,15 @@ using BetterGenshinImpact.GameTask.AutoDomain; using BetterGenshinImpact.GameTask.AutoFight; using BetterGenshinImpact.GameTask.AutoGeniusInvokation; +using BetterGenshinImpact.GameTask.AutoMusicGame; +using BetterGenshinImpact.GameTask.AutoSkip; +using BetterGenshinImpact.GameTask.AutoSkip.Model; +using BetterGenshinImpact.GameTask.AutoTrackPath; using BetterGenshinImpact.GameTask.AutoWood; +using BetterGenshinImpact.GameTask.Common; using BetterGenshinImpact.GameTask.Model; +using BetterGenshinImpact.GameTask.Model.Area; using BetterGenshinImpact.GameTask.Model.Enum; -using BetterGenshinImpact.Genshin.Settings; using BetterGenshinImpact.Helpers; using BetterGenshinImpact.View; using Fischless.GameCapture; @@ -21,13 +26,7 @@ using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks; -using BetterGenshinImpact.GameTask.AutoSkip; -using BetterGenshinImpact.GameTask.AutoSkip.Model; using Vanara.PInvoke; -using BetterGenshinImpact.GameTask.AutoMusicGame; -using BetterGenshinImpact.GameTask.AutoTrackPath; -using BetterGenshinImpact.GameTask.Common; -using BetterGenshinImpact.GameTask.Model.Area; namespace BetterGenshinImpact.GameTask { @@ -65,9 +64,9 @@ namespace BetterGenshinImpact.GameTask private static readonly object _bitmapLocker = new(); private static readonly object _triggerListLocker = new(); - public event EventHandler UiTaskStopTickEvent; + public event EventHandler? UiTaskStopTickEvent; - public event EventHandler UiTaskStartTickEvent; + public event EventHandler? UiTaskStartTickEvent; public TaskTriggerDispatcher() { @@ -229,7 +228,10 @@ namespace BetterGenshinImpact.GameTask } } - public void Dispose() => Stop(); + public void Dispose() + { + Stop(); + } public void Tick(object? sender, EventArgs e) { @@ -256,7 +258,7 @@ namespace BetterGenshinImpact.GameTask _logger.LogInformation("游戏已退出,BetterGI 自动停止截图器"); } - UiTaskStopTickEvent.Invoke(sender, e); + UiTaskStopTickEvent?.Invoke(sender, e); maskWindow.Invoke(maskWindow.Hide); return; } @@ -270,7 +272,7 @@ namespace BetterGenshinImpact.GameTask if (TaskContext.Instance().SystemInfo.GameProcess.HasExited) { _logger.LogInformation("游戏已退出,BetterGI 自动停止截图器"); - UiTaskStopTickEvent.Invoke(sender, e); + UiTaskStopTickEvent?.Invoke(sender, e); return; } @@ -426,8 +428,8 @@ namespace BetterGenshinImpact.GameTask && !SizeIsZero(_gameRect) && !SizeIsZero(currentRect)) { _logger.LogError("► 游戏窗口大小发生变化 {W}x{H}->{CW}x{CH}, 自动重启截图器中...", _gameRect.Width, _gameRect.Height, currentRect.Width, currentRect.Height); - UiTaskStopTickEvent.Invoke(null, EventArgs.Empty); - UiTaskStartTickEvent.Invoke(null, EventArgs.Empty); + UiTaskStopTickEvent?.Invoke(null, EventArgs.Empty); + UiTaskStartTickEvent?.Invoke(null, EventArgs.Empty); _logger.LogInformation("► 游戏窗口大小发生变化,截图器重启完成!"); } diff --git a/BetterGenshinImpact/GameTask/UseActiveCode/UseActiveCodeTask.cs b/BetterGenshinImpact/GameTask/UseActiveCode/UseActiveCodeTask.cs index 0b7830fd..9f813fa9 100644 --- a/BetterGenshinImpact/GameTask/UseActiveCode/UseActiveCodeTask.cs +++ b/BetterGenshinImpact/GameTask/UseActiveCode/UseActiveCodeTask.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BetterGenshinImpact.GameTask.UseActiveCode +namespace BetterGenshinImpact.GameTask.UseActiveCode { internal class UseActiveCodeTask { diff --git a/BetterGenshinImpact/Genshin/Paths/GameExePath.cs b/BetterGenshinImpact/Genshin/Paths/GameExePath.cs index f3e2f626..15a0c8a9 100644 --- a/BetterGenshinImpact/Genshin/Paths/GameExePath.cs +++ b/BetterGenshinImpact/Genshin/Paths/GameExePath.cs @@ -1,26 +1,29 @@ -using System; +using BetterGenshinImpact.GameTask.Common; +using Microsoft.Extensions.Logging; using Microsoft.Win32; +using System; +using System.Collections.Frozen; using System.IO; using System.Linq; using System.Text.RegularExpressions; -using BetterGenshinImpact.GameTask.Common; -using Microsoft.Extensions.Logging; namespace BetterGenshinImpact.Genshin.Paths; -internal class GameExePath +internal partial class GameExePath { + public static readonly FrozenSet GameRegistryPaths = FrozenSet.ToFrozenSet( + [ + @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\原神", + @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Genshin Impact", + // @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\云·原神", + ]); + /// /// 游戏路径(云原神除外) /// public static string? GetWithoutCloud() { - return new[] - { - @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\原神", - @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Genshin Impact", - // @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\云·原神", - }.Select(regKey => GetGameExePathFromRegistry(regKey, false)).FirstOrDefault(exePath => !string.IsNullOrEmpty(exePath)); + return GameRegistryPaths.Select(regKey => GetGameExePathFromRegistry(regKey, false)).FirstOrDefault(exePath => !string.IsNullOrEmpty(exePath)); } /// @@ -49,8 +52,8 @@ internal class GameExePath if (File.Exists(configPath)) { var str = File.ReadAllText(configPath); - var installPath = Regex.Match(str, @"game_install_path=(.+)").Groups[1].Value.Trim(); - var exeName = Regex.Match(str, @"game_start_name=(.+)").Groups[1].Value.Trim(); + var installPath = GameInstallPathRegex().Match(str).Groups[1].Value.Trim(); + var exeName = GameStartNameRegex().Match(str).Groups[1].Value.Trim(); var exePath = Path.GetFullPath(exeName, installPath); if (File.Exists(exePath)) { @@ -66,4 +69,10 @@ internal class GameExePath return null; } + + [GeneratedRegex(@"game_install_path=(.+)")] + private static partial Regex GameInstallPathRegex(); + + [GeneratedRegex(@"game_start_name=(.+)")] + private static partial Regex GameStartNameRegex(); } diff --git a/BetterGenshinImpact/Genshin/Settings/SettingsContainer.cs b/BetterGenshinImpact/Genshin/Settings/SettingsContainer.cs index a10b8969..0f149252 100644 --- a/BetterGenshinImpact/Genshin/Settings/SettingsContainer.cs +++ b/BetterGenshinImpact/Genshin/Settings/SettingsContainer.cs @@ -1,11 +1,11 @@ -using Microsoft.Win32; +using BetterGenshinImpact.GameTask.Common; +using Microsoft.Extensions.Logging; +using Microsoft.Win32; using System; using System.Diagnostics; using System.Runtime.InteropServices; using System.Text.Json; using System.Text.Json.Serialization; -using BetterGenshinImpact.GameTask.Common; -using Microsoft.Extensions.Logging; namespace BetterGenshinImpact.Genshin.Settings; diff --git a/BetterGenshinImpact/Helpers/Crud/JsonCrudHelper.cs b/BetterGenshinImpact/Helpers/Crud/JsonCrudHelper.cs index 930ef1df..e17ec8f2 100644 --- a/BetterGenshinImpact/Helpers/Crud/JsonCrudHelper.cs +++ b/BetterGenshinImpact/Helpers/Crud/JsonCrudHelper.cs @@ -1,5 +1,4 @@ using BetterGenshinImpact.Service; -using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Collections.Specialized; @@ -83,7 +82,7 @@ public class JsonCrudHelper : ICrudHelper where T : class { if (!File.Exists(_filePath)) { - return new ObservableCollection(); + return []; } var json = File.ReadAllText(_filePath); diff --git a/BetterGenshinImpact/Helpers/Extensions/BitmapExtension.cs b/BetterGenshinImpact/Helpers/Extensions/BitmapExtension.cs index 6a134194..81896c80 100644 --- a/BetterGenshinImpact/Helpers/Extensions/BitmapExtension.cs +++ b/BetterGenshinImpact/Helpers/Extensions/BitmapExtension.cs @@ -1,8 +1,7 @@ -using System.Drawing; -using System.Drawing.Imaging; +using OpenCvSharp; +using System.Drawing; using System.IO; using System.Windows.Media.Imaging; -using OpenCvSharp; namespace BetterGenshinImpact.Helpers.Extensions { diff --git a/BetterGenshinImpact/Helpers/Extensions/ClickExtension.cs b/BetterGenshinImpact/Helpers/Extensions/ClickExtension.cs index 8a91d2b9..48bd0e3e 100644 --- a/BetterGenshinImpact/Helpers/Extensions/ClickExtension.cs +++ b/BetterGenshinImpact/Helpers/Extensions/ClickExtension.cs @@ -1,7 +1,6 @@ using BetterGenshinImpact.Core.Simulator; -using OpenCvSharp; -using System; using Fischless.WindowsInput; +using OpenCvSharp; namespace BetterGenshinImpact.Helpers.Extensions; diff --git a/BetterGenshinImpact/Helpers/Extensions/PointExtension.cs b/BetterGenshinImpact/Helpers/Extensions/PointExtension.cs index b8fe83e5..c96df1fb 100644 --- a/BetterGenshinImpact/Helpers/Extensions/PointExtension.cs +++ b/BetterGenshinImpact/Helpers/Extensions/PointExtension.cs @@ -1,5 +1,5 @@ -using System; -using OpenCvSharp; +using OpenCvSharp; +using System; namespace BetterGenshinImpact.Helpers.Extensions; diff --git a/BetterGenshinImpact/Helpers/Extensions/RectExtension.cs b/BetterGenshinImpact/Helpers/Extensions/RectExtension.cs index cd980990..451772e1 100644 --- a/BetterGenshinImpact/Helpers/Extensions/RectExtension.cs +++ b/BetterGenshinImpact/Helpers/Extensions/RectExtension.cs @@ -1,5 +1,4 @@ -using System.Windows.Media.Media3D; -using OpenCvSharp; +using OpenCvSharp; namespace BetterGenshinImpact.Helpers.Extensions; diff --git a/BetterGenshinImpact/Helpers/Extensions/TaskExtension.cs b/BetterGenshinImpact/Helpers/Extensions/TaskExtension.cs new file mode 100644 index 00000000..d95e8e7b --- /dev/null +++ b/BetterGenshinImpact/Helpers/Extensions/TaskExtension.cs @@ -0,0 +1,32 @@ +using System; +using System.Threading.Tasks; + +namespace BetterGenshinImpact.Helpers.Extensions; + +internal static class TaskExtension +{ + public static async void SafeForget(this Task task) + { + try + { + await task.ConfigureAwait(false); + } + catch (OperationCanceledException) + { + + } +#if DEBUG + catch (Exception) + { + if (System.Diagnostics.Debugger.IsAttached) + { + System.Diagnostics.Debugger.Break(); + } + } +#else + catch + { + } +#endif + } +} diff --git a/BetterGenshinImpact/Helpers/MathHelper.cs b/BetterGenshinImpact/Helpers/MathHelper.cs index 5f75c712..c8167321 100644 --- a/BetterGenshinImpact/Helpers/MathHelper.cs +++ b/BetterGenshinImpact/Helpers/MathHelper.cs @@ -1,5 +1,5 @@ -using System; -using OpenCvSharp; +using OpenCvSharp; +using System; namespace BetterGenshinImpact.Helpers; diff --git a/BetterGenshinImpact/Helpers/PrimaryScreen.cs b/BetterGenshinImpact/Helpers/PrimaryScreen.cs index b2a1258e..5729f83b 100644 --- a/BetterGenshinImpact/Helpers/PrimaryScreen.cs +++ b/BetterGenshinImpact/Helpers/PrimaryScreen.cs @@ -1,7 +1,7 @@ using System; using System.Drawing; -using static Vanara.PInvoke.Gdi32; using Vanara.PInvoke; +using static Vanara.PInvoke.Gdi32; namespace BetterGenshinImpact.Helpers { diff --git a/BetterGenshinImpact/Helpers/RegexHelper.cs b/BetterGenshinImpact/Helpers/RegexHelper.cs new file mode 100644 index 00000000..9e536315 --- /dev/null +++ b/BetterGenshinImpact/Helpers/RegexHelper.cs @@ -0,0 +1,12 @@ +using System.Text.RegularExpressions; + +namespace BetterGenshinImpact.Helpers; + +internal static partial class RegexHelper +{ + [GeneratedRegex(@"[^0-9]+")] + public static partial Regex ExcludeNumberRegex(); + + [GeneratedRegex(@"^[0-9]+$")] + public static partial Regex FullNumberRegex(); +} diff --git a/BetterGenshinImpact/Helpers/ResourceHelper.cs b/BetterGenshinImpact/Helpers/ResourceHelper.cs index 66b82443..1ddfa3f3 100644 --- a/BetterGenshinImpact/Helpers/ResourceHelper.cs +++ b/BetterGenshinImpact/Helpers/ResourceHelper.cs @@ -33,11 +33,7 @@ internal static class ResourceHelper public static string GetString(string uriString, Encoding encoding = null!) { Uri uri = new(uriString); - StreamResourceInfo? info = Application.GetResourceStream(uri); - if (info == null) - { - throw new FileNotFoundException($"Resource not found: {uriString}"); - } + StreamResourceInfo? info = Application.GetResourceStream(uri) ?? throw new FileNotFoundException($"Resource not found: {uriString}"); using StreamReader stream = new(info.Stream, encoding ?? Encoding.UTF8); return stream.ReadToEnd(); } diff --git a/BetterGenshinImpact/Helpers/RuntimeHelper.cs b/BetterGenshinImpact/Helpers/RuntimeHelper.cs index 6e9fd47f..b5e2f908 100644 --- a/BetterGenshinImpact/Helpers/RuntimeHelper.cs +++ b/BetterGenshinImpact/Helpers/RuntimeHelper.cs @@ -165,7 +165,7 @@ internal static class RuntimeExtension public static IHostBuilder CheckIntegration(this IHostBuilder app) { - RuntimeHelper.CheckIntegration(); + RuntimeHelper.CheckIntegration(); return app; } } diff --git a/BetterGenshinImpact/Helpers/SpeedTimer.cs b/BetterGenshinImpact/Helpers/SpeedTimer.cs index 521fb42f..73ccc25e 100644 --- a/BetterGenshinImpact/Helpers/SpeedTimer.cs +++ b/BetterGenshinImpact/Helpers/SpeedTimer.cs @@ -8,7 +8,7 @@ public class SpeedTimer { private readonly Stopwatch _stopwatch; - private readonly Dictionary _timeRecordDic = new(); + private readonly Dictionary _timeRecordDic = []; public SpeedTimer() @@ -30,7 +30,7 @@ public class SpeedTimer { // if (pair.Value.TotalMilliseconds > 0.1) // { - msg += $"{pair.Key}:{pair.Value.TotalMilliseconds}ms,"; + msg += $"{pair.Key}:{pair.Value.TotalMilliseconds}ms,"; // } } diff --git a/BetterGenshinImpact/Helpers/StringUtils.cs b/BetterGenshinImpact/Helpers/StringUtils.cs index 831e33cc..4b8d9127 100644 --- a/BetterGenshinImpact/Helpers/StringUtils.cs +++ b/BetterGenshinImpact/Helpers/StringUtils.cs @@ -3,7 +3,7 @@ using System.Text.RegularExpressions; namespace BetterGenshinImpact.Helpers; -public class StringUtils +public partial class StringUtils { /// /// 删除所有空字符串 @@ -45,7 +45,7 @@ public class StringUtils return false; } - return Regex.IsMatch(str, @"[\u4e00-\u9fa5]"); + return ChineseRegex().IsMatch(str); } /// @@ -92,7 +92,7 @@ public class StringUtils try { - text = Regex.Replace(text, @"[^0-9]+", ""); + text = RegexHelper.ExcludeNumberRegex().Replace(text, ""); return int.Parse(text); } catch @@ -100,4 +100,7 @@ public class StringUtils return -1; } } + + [GeneratedRegex(@"[\u4e00-\u9fa5]")] + private static partial Regex ChineseRegex(); } diff --git a/BetterGenshinImpact/Helpers/UIDispatcherHelper.cs b/BetterGenshinImpact/Helpers/UIDispatcherHelper.cs index cb80418f..49b02ac9 100644 --- a/BetterGenshinImpact/Helpers/UIDispatcherHelper.cs +++ b/BetterGenshinImpact/Helpers/UIDispatcherHelper.cs @@ -1,8 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows; namespace BetterGenshinImpact.Helpers; @@ -13,27 +9,27 @@ public static class UIDispatcherHelper public static void Invoke(Action callback, params object[] args) { - _ = Application.Current?.Dispatcher.Invoke(callback, args); + _ = Application.Current.Dispatcher.Invoke(callback, args); } public static void Invoke(Action callback) { - _ = Application.Current?.Dispatcher.Invoke(callback, MainWindow); + _ = Application.Current.Dispatcher.Invoke(callback, MainWindow); } - public static T? Invoke(Func func) + public static T Invoke(Func func) where T : class { - return Application.Current?.Dispatcher.Invoke(func); + return Application.Current.Dispatcher.Invoke(func); } public static void BeginInvoke(Action callback, params object[] args) { - _ = Application.Current?.Dispatcher.BeginInvoke(callback, args); + _ = Application.Current.Dispatcher.BeginInvoke(callback, args); } public static void BeginInvoke(Action callback) { - _ = Application.Current?.Dispatcher.BeginInvoke(callback, MainWindow); + _ = Application.Current.Dispatcher.BeginInvoke(callback, MainWindow); } } \ No newline at end of file diff --git a/BetterGenshinImpact/Helpers/UrlProtocolHelper.cs b/BetterGenshinImpact/Helpers/UrlProtocolHelper.cs index 6bbc5e5c..6f3f0659 100644 --- a/BetterGenshinImpact/Helpers/UrlProtocolHelper.cs +++ b/BetterGenshinImpact/Helpers/UrlProtocolHelper.cs @@ -5,7 +5,7 @@ using System.Threading.Tasks; namespace BetterGenshinImpact.Helpers; -internal static class UrlProtocolHelper +internal static partial class UrlProtocolHelper { public const string ProtocolRootKey = @"HKEY_CLASSES_ROOT\"; public const string ProtocolUserKey = @"HKEY_CURRENT_USER\" + ProtocolUserSubKey; @@ -110,8 +110,7 @@ internal static class UrlProtocolHelper if (keyCommand?.GetValue(string.Empty) is string pathRegistered) { - Regex regex = new("\"(?[\\s\\S]*?)\" \"%1\""); - Match match = regex.Match(pathRegistered); + Match match = ExecutableRegex().Match(pathRegistered); if (match.Success && match.Groups["exe"]?.Value is string exe) { @@ -193,4 +192,7 @@ internal static class UrlProtocolHelper Launch(param); }); } + + [GeneratedRegex("\"(?[\\s\\S]*?)\" \"%1\"")] + private static partial Regex ExecutableRegex(); } diff --git a/BetterGenshinImpact/Markup/ServiceLocatorExtension.cs b/BetterGenshinImpact/Markup/ServiceLocatorExtension.cs index 473f21dd..7f66c575 100644 --- a/BetterGenshinImpact/Markup/ServiceLocatorExtension.cs +++ b/BetterGenshinImpact/Markup/ServiceLocatorExtension.cs @@ -14,7 +14,7 @@ public class ServiceLocatorExtension : MarkupExtension public override object ProvideValue(IServiceProvider serviceProvider) { - _ = Type ?? throw new ArgumentNullException(nameof(Type)); + ArgumentNullException.ThrowIfNull(Type); return App.GetService(Type)!; } } diff --git a/BetterGenshinImpact/Model/KeyMouseScriptItem.cs b/BetterGenshinImpact/Model/KeyMouseScriptItem.cs index 55385ef9..7e4dcfc4 100644 --- a/BetterGenshinImpact/Model/KeyMouseScriptItem.cs +++ b/BetterGenshinImpact/Model/KeyMouseScriptItem.cs @@ -1,5 +1,5 @@ -using System; -using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.ComponentModel; +using System; namespace BetterGenshinImpact.Model; diff --git a/BetterGenshinImpact/Model/KeyboardHook.cs b/BetterGenshinImpact/Model/KeyboardHook.cs index 8822d197..9021255b 100644 --- a/BetterGenshinImpact/Model/KeyboardHook.cs +++ b/BetterGenshinImpact/Model/KeyboardHook.cs @@ -10,7 +10,7 @@ namespace BetterGenshinImpact.Model; public class KeyboardHook { - public static Dictionary AllKeyboardHooks = new(); + public static Dictionary AllKeyboardHooks = []; public event EventHandler? KeyPressedEvent = null; diff --git a/BetterGenshinImpact/Model/MaskButton.cs b/BetterGenshinImpact/Model/MaskButton.cs index 56ec7926..23abb108 100644 --- a/BetterGenshinImpact/Model/MaskButton.cs +++ b/BetterGenshinImpact/Model/MaskButton.cs @@ -1,12 +1,7 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using BetterGenshinImpact.GameTask; -using BetterGenshinImpact.Helpers; +using BetterGenshinImpact.GameTask; using CommunityToolkit.Mvvm.Input; using OpenCvSharp; +using System; namespace BetterGenshinImpact.Model { diff --git a/BetterGenshinImpact/Model/MouseHook.cs b/BetterGenshinImpact/Model/MouseHook.cs index 617b0491..f9b336ec 100644 --- a/BetterGenshinImpact/Model/MouseHook.cs +++ b/BetterGenshinImpact/Model/MouseHook.cs @@ -1,17 +1,17 @@ -using Fischless.HotkeyCapture; +using BetterGenshinImpact.GameTask; +using Fischless.HotkeyCapture; using Gma.System.MouseKeyHook; using System; using System.Collections.Generic; using System.Threading.Tasks; using System.Windows.Forms; -using BetterGenshinImpact.GameTask; using Vanara.PInvoke; namespace BetterGenshinImpact.Model; public class MouseHook { - public static Dictionary AllMouseHooks = new(); + public static Dictionary AllMouseHooks = []; public event EventHandler? MousePressed = null; diff --git a/BetterGenshinImpact/Model/StatusItem.cs b/BetterGenshinImpact/Model/StatusItem.cs index 4a66aa8d..b2336940 100644 --- a/BetterGenshinImpact/Model/StatusItem.cs +++ b/BetterGenshinImpact/Model/StatusItem.cs @@ -1,5 +1,6 @@ -using System.ComponentModel; -using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.ComponentModel; +using System; +using System.ComponentModel; namespace BetterGenshinImpact.Model { @@ -23,7 +24,11 @@ namespace BetterGenshinImpact.Model private bool GetSourceValue() { - return (bool)_sourceObject.GetType().GetProperty(_propertyName).GetValue(_sourceObject); + var property = _sourceObject.GetType().GetProperty(_propertyName); + ArgumentNullException.ThrowIfNull(property); + var value = property.GetValue(_sourceObject); + ArgumentNullException.ThrowIfNull(value); + return (bool)value; } diff --git a/BetterGenshinImpact/Service/ApplicationHostService.cs b/BetterGenshinImpact/Service/ApplicationHostService.cs index 1d1d5180..d940c241 100644 --- a/BetterGenshinImpact/Service/ApplicationHostService.cs +++ b/BetterGenshinImpact/Service/ApplicationHostService.cs @@ -1,11 +1,11 @@ using BetterGenshinImpact.View; +using BetterGenshinImpact.View.Pages; +using Microsoft.Extensions.Hosting; using System; using System.Linq; using System.Threading; using System.Threading.Tasks; using System.Windows; -using BetterGenshinImpact.View.Pages; -using Microsoft.Extensions.Hosting; using Wpf.Ui; namespace BetterGenshinImpact.Service; diff --git a/BetterGenshinImpact/Service/Interface/IConfigService.cs b/BetterGenshinImpact/Service/Interface/IConfigService.cs index e5a27926..724c7dd9 100644 --- a/BetterGenshinImpact/Service/Interface/IConfigService.cs +++ b/BetterGenshinImpact/Service/Interface/IConfigService.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using BetterGenshinImpact.Core.Config; +using BetterGenshinImpact.Core.Config; namespace BetterGenshinImpact.Service.Interface { diff --git a/BetterGenshinImpact/Service/Notification/Builder/TaskNotificationBuilder.cs b/BetterGenshinImpact/Service/Notification/Builder/TaskNotificationBuilder.cs index 4ae5c290..7eb48277 100644 --- a/BetterGenshinImpact/Service/Notification/Builder/TaskNotificationBuilder.cs +++ b/BetterGenshinImpact/Service/Notification/Builder/TaskNotificationBuilder.cs @@ -1,6 +1,6 @@ -using System.Drawing; -using BetterGenshinImpact.Service.Notification.Model; +using BetterGenshinImpact.Service.Notification.Model; using BetterGenshinImpact.Service.Notification.Model.Enum; +using System.Drawing; namespace BetterGenshinImpact.Service.Notification.Builder; diff --git a/BetterGenshinImpact/Service/Notification/Model/LifecycleNotificationData.cs b/BetterGenshinImpact/Service/Notification/Model/LifecycleNotificationData.cs index 6e94dcab..84c20a98 100644 --- a/BetterGenshinImpact/Service/Notification/Model/LifecycleNotificationData.cs +++ b/BetterGenshinImpact/Service/Notification/Model/LifecycleNotificationData.cs @@ -1,5 +1,5 @@ -using System.Text.Json.Serialization; -using BetterGenshinImpact.Service.Notification.Model.Enum; +using BetterGenshinImpact.Service.Notification.Model.Enum; +using System.Text.Json.Serialization; namespace BetterGenshinImpact.Service.Notification.Model; diff --git a/BetterGenshinImpact/Service/Notification/NotificationConfig.cs b/BetterGenshinImpact/Service/Notification/NotificationConfig.cs index df202285..280b62de 100644 --- a/BetterGenshinImpact/Service/Notification/NotificationConfig.cs +++ b/BetterGenshinImpact/Service/Notification/NotificationConfig.cs @@ -1,5 +1,5 @@ -using System; -using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.ComponentModel; +using System; namespace BetterGenshinImpact.Service.Notification; diff --git a/BetterGenshinImpact/Service/Notification/NotificationHelper.cs b/BetterGenshinImpact/Service/Notification/NotificationHelper.cs index 88cccb12..11b07598 100644 --- a/BetterGenshinImpact/Service/Notification/NotificationHelper.cs +++ b/BetterGenshinImpact/Service/Notification/NotificationHelper.cs @@ -1,8 +1,8 @@ -using System; -using System.Drawing; -using BetterGenshinImpact.GameTask.Common; +using BetterGenshinImpact.GameTask.Common; using BetterGenshinImpact.Service.Notification.Builder; using BetterGenshinImpact.Service.Notification.Model; +using System; +using System.Drawing; namespace BetterGenshinImpact.Service.Notification; diff --git a/BetterGenshinImpact/Service/Notification/NotificationService.cs b/BetterGenshinImpact/Service/Notification/NotificationService.cs index f55e0742..94da9bd1 100644 --- a/BetterGenshinImpact/Service/Notification/NotificationService.cs +++ b/BetterGenshinImpact/Service/Notification/NotificationService.cs @@ -1,16 +1,16 @@ -using System; -using System.Net.Http; -using System.Text; -using System.Threading.Tasks; -using BetterGenshinImpact.Core.Config; +using BetterGenshinImpact.Core.Config; using BetterGenshinImpact.Service.Interface; using BetterGenshinImpact.Service.Notification.Model; using BetterGenshinImpact.Service.Notifier; using BetterGenshinImpact.Service.Notifier.Exception; using BetterGenshinImpact.Service.Notifier.Interface; -using System.Text.Json; using Microsoft.Extensions.Hosting; +using System; +using System.Net.Http; +using System.Text; +using System.Text.Json; using System.Threading; +using System.Threading.Tasks; namespace BetterGenshinImpact.Service.Notification; @@ -49,7 +49,7 @@ public class NotificationService : IHostedService return Task.CompletedTask; } - private HttpContent TransformData(INotificationData notificationData) + private StringContent TransformData(INotificationData notificationData) { // using object type here so it serializes the interface correctly var serializedData = JsonSerializer.Serialize(notificationData, new JsonSerializerOptions diff --git a/BetterGenshinImpact/Service/Notifier/NotifierManager.cs b/BetterGenshinImpact/Service/Notifier/NotifierManager.cs index f9a438e4..cf8e632f 100644 --- a/BetterGenshinImpact/Service/Notifier/NotifierManager.cs +++ b/BetterGenshinImpact/Service/Notifier/NotifierManager.cs @@ -1,10 +1,10 @@ -using System.Collections.Generic; +using BetterGenshinImpact.Service.Notifier.Interface; +using Microsoft.Extensions.Logging; +using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Net.Http; using System.Threading.Tasks; -using BetterGenshinImpact.Service.Notifier.Interface; -using Microsoft.Extensions.Logging; namespace BetterGenshinImpact.Service.Notifier; diff --git a/BetterGenshinImpact/Service/Notifier/WebhookNotifier.cs b/BetterGenshinImpact/Service/Notifier/WebhookNotifier.cs index 5075fa91..07331f91 100644 --- a/BetterGenshinImpact/Service/Notifier/WebhookNotifier.cs +++ b/BetterGenshinImpact/Service/Notifier/WebhookNotifier.cs @@ -1,7 +1,7 @@ -using System.Net.Http; -using System.Threading.Tasks; +using BetterGenshinImpact.Service.Notifier.Exception; using BetterGenshinImpact.Service.Notifier.Interface; -using BetterGenshinImpact.Service.Notifier.Exception; +using System.Net.Http; +using System.Threading.Tasks; namespace BetterGenshinImpact.Service.Notifier; diff --git a/BetterGenshinImpact/Service/PageService.cs b/BetterGenshinImpact/Service/PageService.cs index 47b4d000..3aed2475 100644 --- a/BetterGenshinImpact/Service/PageService.cs +++ b/BetterGenshinImpact/Service/PageService.cs @@ -1,5 +1,5 @@ -using System.Windows; -using System; +using System; +using System.Windows; using Wpf.Ui; namespace BetterGenshinImpact.Service; diff --git a/BetterGenshinImpact/View/CaptureTestWindow.xaml.cs b/BetterGenshinImpact/View/CaptureTestWindow.xaml.cs index 627f3e63..9c383d16 100644 --- a/BetterGenshinImpact/View/CaptureTestWindow.xaml.cs +++ b/BetterGenshinImpact/View/CaptureTestWindow.xaml.cs @@ -1,11 +1,11 @@ -using BetterGenshinImpact.Helpers.Extensions; +using BetterGenshinImpact.GameTask; +using BetterGenshinImpact.Helpers.Extensions; +using Fischless.GameCapture; using System; using System.Collections.Generic; using System.Diagnostics; using System.Windows; using System.Windows.Media; -using BetterGenshinImpact.GameTask; -using Fischless.GameCapture; namespace BetterGenshinImpact.View { diff --git a/BetterGenshinImpact/View/Controls/CodeEditor/CodeBox.cs b/BetterGenshinImpact/View/Controls/CodeEditor/CodeBox.cs index 0290ea07..865fc4d7 100644 --- a/BetterGenshinImpact/View/Controls/CodeEditor/CodeBox.cs +++ b/BetterGenshinImpact/View/Controls/CodeEditor/CodeBox.cs @@ -1,7 +1,7 @@ -using System.Windows; +using ICSharpCode.AvalonEdit; +using System.Windows; using System.Windows.Controls; using System.Windows.Media; -using ICSharpCode.AvalonEdit; namespace BetterGenshinImpact.View.Controls.CodeEditor; diff --git a/BetterGenshinImpact/View/Controls/CodeEditor/JsonCodeBox.cs b/BetterGenshinImpact/View/Controls/CodeEditor/JsonCodeBox.cs index d0812fe7..674ba92c 100644 --- a/BetterGenshinImpact/View/Controls/CodeEditor/JsonCodeBox.cs +++ b/BetterGenshinImpact/View/Controls/CodeEditor/JsonCodeBox.cs @@ -1,8 +1,8 @@ -using System.IO; -using System.Xml; -using BetterGenshinImpact.Helpers; +using BetterGenshinImpact.Helpers; using ICSharpCode.AvalonEdit.Highlighting; using ICSharpCode.AvalonEdit.Highlighting.Xshd; +using System.IO; +using System.Xml; namespace BetterGenshinImpact.View.Controls.CodeEditor; @@ -20,7 +20,7 @@ public class JsonCodeBox : CodeBox using XmlReader reader = new XmlTextReader(s); luaHighlighting = HighlightingLoader.Load(reader, HighlightingManager.Instance); - HighlightingManager.Instance.RegisterHighlighting("Json", new string[] { ".json" }, luaHighlighting); + HighlightingManager.Instance.RegisterHighlighting("Json", [".json"], luaHighlighting); SyntaxHighlighting = HighlightingManager.Instance.GetDefinition("Json"); } } diff --git a/BetterGenshinImpact/View/Controls/Draggable/DesignerItemDecorator.cs b/BetterGenshinImpact/View/Controls/Draggable/DesignerItemDecorator.cs index 76d32b37..431121e0 100644 --- a/BetterGenshinImpact/View/Controls/Draggable/DesignerItemDecorator.cs +++ b/BetterGenshinImpact/View/Controls/Draggable/DesignerItemDecorator.cs @@ -1,7 +1,7 @@ -using System.Windows; +using BetterGenshinImpact.View.Controls.Adorners; +using System.Windows; using System.Windows.Controls; using System.Windows.Documents; -using BetterGenshinImpact.View.Controls.Adorners; namespace BetterGenshinImpact.View.Controls; diff --git a/BetterGenshinImpact/View/Controls/Draggable/ResizeThumb.cs b/BetterGenshinImpact/View/Controls/Draggable/ResizeThumb.cs index dc2a7d7e..191ddc3a 100644 --- a/BetterGenshinImpact/View/Controls/Draggable/ResizeThumb.cs +++ b/BetterGenshinImpact/View/Controls/Draggable/ResizeThumb.cs @@ -1,10 +1,10 @@ -using System; +using BetterGenshinImpact.View.Controls.Adorners; +using System; using System.Windows; using System.Windows.Controls; using System.Windows.Controls.Primitives; using System.Windows.Documents; using System.Windows.Media; -using BetterGenshinImpact.View.Controls.Adorners; namespace BetterGenshinImpact.View.Controls; diff --git a/BetterGenshinImpact/View/Controls/HotKey/HotKeyTextBox.cs b/BetterGenshinImpact/View/Controls/HotKey/HotKeyTextBox.cs index 07e76b82..4be6ea11 100644 --- a/BetterGenshinImpact/View/Controls/HotKey/HotKeyTextBox.cs +++ b/BetterGenshinImpact/View/Controls/HotKey/HotKeyTextBox.cs @@ -1,6 +1,6 @@ -using System.Windows; +using BetterGenshinImpact.Model; +using System.Windows; using System.Windows.Input; -using BetterGenshinImpact.Model; using KeyEventArgs = System.Windows.Input.KeyEventArgs; using TextBox = Wpf.Ui.Controls.TextBox; diff --git a/BetterGenshinImpact/View/Controls/Webview/WebpagePanel.cs b/BetterGenshinImpact/View/Controls/Webview/WebpagePanel.cs index d42fba29..95d5b837 100644 --- a/BetterGenshinImpact/View/Controls/Webview/WebpagePanel.cs +++ b/BetterGenshinImpact/View/Controls/Webview/WebpagePanel.cs @@ -127,7 +127,7 @@ public class WebpagePanel : UserControl _webView = null!; } - private object CreateDownloadButton() + private Button CreateDownloadButton() { var button = new Button { diff --git a/BetterGenshinImpact/View/Converters/BooleanToVisibilityRevertConverter.cs b/BetterGenshinImpact/View/Converters/BooleanToVisibilityRevertConverter.cs index 4e8ab1d3..4b90e5bb 100644 --- a/BetterGenshinImpact/View/Converters/BooleanToVisibilityRevertConverter.cs +++ b/BetterGenshinImpact/View/Converters/BooleanToVisibilityRevertConverter.cs @@ -4,7 +4,7 @@ using System.Windows.Data; namespace BetterGenshinImpact.View.Converters; -[ValueConversion(typeof(bool),typeof(Visibility))] +[ValueConversion(typeof(bool), typeof(Visibility))] public sealed class BooleanToVisibilityRevertConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) diff --git a/BetterGenshinImpact/View/Drawable/DrawContent.cs b/BetterGenshinImpact/View/Drawable/DrawContent.cs index 2c7e9753..8769f9f2 100644 --- a/BetterGenshinImpact/View/Drawable/DrawContent.cs +++ b/BetterGenshinImpact/View/Drawable/DrawContent.cs @@ -30,7 +30,7 @@ public class DrawContent } } - RectList[key] = new List { newRect }; + RectList[key] = [newRect]; MaskWindow.Instance().Refresh(); } @@ -91,7 +91,7 @@ public class DrawContent } } - LineList[key] = new List { newLine }; + LineList[key] = [newLine]; MaskWindow.Instance().Refresh(); } diff --git a/BetterGenshinImpact/View/Drawable/RectDrawable.cs b/BetterGenshinImpact/View/Drawable/RectDrawable.cs index 02aabc53..8b2fae92 100644 --- a/BetterGenshinImpact/View/Drawable/RectDrawable.cs +++ b/BetterGenshinImpact/View/Drawable/RectDrawable.cs @@ -1,9 +1,8 @@ -using System; +using BetterGenshinImpact.Core.Recognition.OpenCv; +using BetterGenshinImpact.GameTask; +using System; using System.Drawing; using System.Windows; -using BetterGenshinImpact.Core.Recognition.OpenCv; -using BetterGenshinImpact.GameTask; -using BetterGenshinImpact.Helpers; namespace BetterGenshinImpact.View.Drawable { diff --git a/BetterGenshinImpact/View/Drawable/VisionContext.cs b/BetterGenshinImpact/View/Drawable/VisionContext.cs index 066acbff..9cd86925 100644 --- a/BetterGenshinImpact/View/Drawable/VisionContext.cs +++ b/BetterGenshinImpact/View/Drawable/VisionContext.cs @@ -1,6 +1,4 @@ -using Microsoft.Extensions.Logging; - -namespace BetterGenshinImpact.View.Drawable +namespace BetterGenshinImpact.View.Drawable { /// /// Vision 上下文 diff --git a/BetterGenshinImpact/View/MainWindow.xaml.cs b/BetterGenshinImpact/View/MainWindow.xaml.cs index 4893057f..ab3ad2c6 100644 --- a/BetterGenshinImpact/View/MainWindow.xaml.cs +++ b/BetterGenshinImpact/View/MainWindow.xaml.cs @@ -1,6 +1,5 @@ using BetterGenshinImpact.Helpers.DpiAwareness; using BetterGenshinImpact.ViewModel; -using BetterGenshinImpact.ViewModel.Pages; using Microsoft.Extensions.Logging; using System; using System.Windows; diff --git a/BetterGenshinImpact/View/MaskWindow.xaml.cs b/BetterGenshinImpact/View/MaskWindow.xaml.cs index 5dc84f63..c9991605 100644 --- a/BetterGenshinImpact/View/MaskWindow.xaml.cs +++ b/BetterGenshinImpact/View/MaskWindow.xaml.cs @@ -1,14 +1,16 @@ -using BetterGenshinImpact.Core.Recognition.OpenCv; +using BetterGenshinImpact.Core.Config; +using BetterGenshinImpact.Core.Recognition.OpenCv; using BetterGenshinImpact.GameTask; +using BetterGenshinImpact.Genshin.Settings; using BetterGenshinImpact.Helpers; using BetterGenshinImpact.Helpers.DpiAwareness; using BetterGenshinImpact.View.Drawable; using CommunityToolkit.Mvvm.Messaging; using CommunityToolkit.Mvvm.Messaging.Messages; +using Microsoft.Extensions.Logging; using Serilog.Sinks.RichTextBox.Abstraction; using System; using System.Diagnostics; -using PresentMonFps; using System.Globalization; using System.Linq; using System.Windows; @@ -19,10 +21,6 @@ using System.Windows.Media; using System.Windows.Threading; using Vanara.PInvoke; using FontFamily = System.Windows.Media.FontFamily; -using BetterGenshinImpact.ViewModel; -using Microsoft.Extensions.Logging; -using BetterGenshinImpact.Genshin.Settings; -using BetterGenshinImpact.Core.Config; namespace BetterGenshinImpact.View; diff --git a/BetterGenshinImpact/View/Pages/CommonSettingsPage.xaml.cs b/BetterGenshinImpact/View/Pages/CommonSettingsPage.xaml.cs index 5361afc2..1365d6c8 100644 --- a/BetterGenshinImpact/View/Pages/CommonSettingsPage.xaml.cs +++ b/BetterGenshinImpact/View/Pages/CommonSettingsPage.xaml.cs @@ -1,18 +1,5 @@ using BetterGenshinImpact.ViewModel.Pages; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; namespace BetterGenshinImpact.View.Pages { diff --git a/BetterGenshinImpact/View/Pages/HomePage.xaml.cs b/BetterGenshinImpact/View/Pages/HomePage.xaml.cs index eccb3c24..025bd0dd 100644 --- a/BetterGenshinImpact/View/Pages/HomePage.xaml.cs +++ b/BetterGenshinImpact/View/Pages/HomePage.xaml.cs @@ -1,18 +1,4 @@ -using BetterGenshinImpact.ViewModel; -using BetterGenshinImpact.ViewModel.Pages; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Shapes; +using BetterGenshinImpact.ViewModel.Pages; namespace BetterGenshinImpact.View.Pages { diff --git a/BetterGenshinImpact/View/Pages/MacroSettingsPage.xaml.cs b/BetterGenshinImpact/View/Pages/MacroSettingsPage.xaml.cs index 86c83b86..c0a1e285 100644 --- a/BetterGenshinImpact/View/Pages/MacroSettingsPage.xaml.cs +++ b/BetterGenshinImpact/View/Pages/MacroSettingsPage.xaml.cs @@ -1,18 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; +using BetterGenshinImpact.ViewModel.Pages; using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; -using BetterGenshinImpact.ViewModel.Pages; namespace BetterGenshinImpact.View.Pages; diff --git a/BetterGenshinImpact/View/Pages/NotificationSettingsPage.xaml.cs b/BetterGenshinImpact/View/Pages/NotificationSettingsPage.xaml.cs index 1ee988b1..96a99436 100644 --- a/BetterGenshinImpact/View/Pages/NotificationSettingsPage.xaml.cs +++ b/BetterGenshinImpact/View/Pages/NotificationSettingsPage.xaml.cs @@ -1,5 +1,5 @@ -using System.Windows.Controls; -using BetterGenshinImpact.ViewModel.Pages; +using BetterGenshinImpact.ViewModel.Pages; +using System.Windows.Controls; namespace BetterGenshinImpact.View.Pages { diff --git a/BetterGenshinImpact/View/Pages/TaskSettingsPage.xaml.cs b/BetterGenshinImpact/View/Pages/TaskSettingsPage.xaml.cs index 19da5fe7..306726e7 100644 --- a/BetterGenshinImpact/View/Pages/TaskSettingsPage.xaml.cs +++ b/BetterGenshinImpact/View/Pages/TaskSettingsPage.xaml.cs @@ -1,18 +1,5 @@ using BetterGenshinImpact.ViewModel.Pages; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; namespace BetterGenshinImpact.View.Pages; diff --git a/BetterGenshinImpact/View/Pages/TriggerSettingsPage.xaml.cs b/BetterGenshinImpact/View/Pages/TriggerSettingsPage.xaml.cs index 51789c94..a58ecb15 100644 --- a/BetterGenshinImpact/View/Pages/TriggerSettingsPage.xaml.cs +++ b/BetterGenshinImpact/View/Pages/TriggerSettingsPage.xaml.cs @@ -1,17 +1,4 @@ using BetterGenshinImpact.ViewModel.Pages; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Shapes; namespace BetterGenshinImpact.View.Pages; diff --git a/BetterGenshinImpact/View/PickerWindow.xaml.cs b/BetterGenshinImpact/View/PickerWindow.xaml.cs index 28171a67..8a6c1686 100644 --- a/BetterGenshinImpact/View/PickerWindow.xaml.cs +++ b/BetterGenshinImpact/View/PickerWindow.xaml.cs @@ -15,7 +15,7 @@ namespace BetterGenshinImpact.View /// public partial class PickerWindow : Window { - private readonly string[] _ignoreProcesses = { "applicationframehost", "shellexperiencehost", "systemsettings", "winstore.app", "searchui" }; + private static readonly string[] _ignoreProcesses = ["applicationframehost", "shellexperiencehost", "systemsettings", "winstore.app", "searchui"]; public PickerWindow() { @@ -48,7 +48,7 @@ namespace BetterGenshinImpact.View // ignore untitled windows var title = new StringBuilder(1024); - User32.GetWindowText(hWnd, title, title.Capacity); + _ = User32.GetWindowText(hWnd, title, title.Capacity); if (string.IsNullOrWhiteSpace(title.ToString())) return true; @@ -56,7 +56,7 @@ namespace BetterGenshinImpact.View if (wih.Handle == hWnd) return true; - User32.GetWindowThreadProcessId(hWnd, out var processId); + _ = User32.GetWindowThreadProcessId(hWnd, out var processId); // ignore by process name var process = Process.GetProcessById((int)processId); diff --git a/BetterGenshinImpact/View/Windows/JsonMonoDialog.xaml.cs b/BetterGenshinImpact/View/Windows/JsonMonoDialog.xaml.cs index 45682d89..34169cff 100644 --- a/BetterGenshinImpact/View/Windows/JsonMonoDialog.xaml.cs +++ b/BetterGenshinImpact/View/Windows/JsonMonoDialog.xaml.cs @@ -3,8 +3,6 @@ using System; using System.Windows; using System.Windows.Media; using Wpf.Ui.Controls; -using CommunityToolkit.Mvvm.Messaging.Messages; -using CommunityToolkit.Mvvm.Messaging; namespace BetterGenshinImpact.View.Windows; diff --git a/BetterGenshinImpact/View/Windows/MapViewer.xaml.cs b/BetterGenshinImpact/View/Windows/MapViewer.xaml.cs index 5da01f4c..384326b2 100644 --- a/BetterGenshinImpact/View/Windows/MapViewer.xaml.cs +++ b/BetterGenshinImpact/View/Windows/MapViewer.xaml.cs @@ -1,5 +1,4 @@ using BetterGenshinImpact.ViewModel.Windows; -using System.Windows; namespace BetterGenshinImpact.View.Windows; diff --git a/BetterGenshinImpact/View/Windows/PromptDialog.xaml.cs b/BetterGenshinImpact/View/Windows/PromptDialog.xaml.cs index 83cabbe8..782aea0f 100644 --- a/BetterGenshinImpact/View/Windows/PromptDialog.xaml.cs +++ b/BetterGenshinImpact/View/Windows/PromptDialog.xaml.cs @@ -1,5 +1,4 @@ -using System.Drawing; -using System.Windows; +using System.Windows; using System.Windows.Controls; namespace BetterGenshinImpact.View.Windows; diff --git a/BetterGenshinImpact/ViewModel/NotifyIconViewModel.cs b/BetterGenshinImpact/ViewModel/NotifyIconViewModel.cs index 098efae5..0e87a9cd 100644 --- a/BetterGenshinImpact/ViewModel/NotifyIconViewModel.cs +++ b/BetterGenshinImpact/ViewModel/NotifyIconViewModel.cs @@ -1,25 +1,18 @@ using BetterGenshinImpact.Helpers; -using BetterGenshinImpact.Model; using BetterGenshinImpact.Service.Interface; using BetterGenshinImpact.View.Controls.Webview; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; -using Microsoft.Web.WebView2.Core; using Newtonsoft.Json; using System; -using System.Collections; using System.Collections.Generic; -using System.IO; using System.Net; using System.Net.Http; -using System.Net.Http.Json; using System.Text; using System.Threading.Tasks; using System.Windows; -using System.Windows.Controls; using System.Windows.Interop; using Vanara.PInvoke; -using Windows.Media.Protection.PlayReady; namespace BetterGenshinImpact.ViewModel; diff --git a/BetterGenshinImpact/ViewModel/Pages/CommonSettingsPageViewModel.cs b/BetterGenshinImpact/ViewModel/Pages/CommonSettingsPageViewModel.cs index 4220b3e5..b8d608f1 100644 --- a/BetterGenshinImpact/ViewModel/Pages/CommonSettingsPageViewModel.cs +++ b/BetterGenshinImpact/ViewModel/Pages/CommonSettingsPageViewModel.cs @@ -1,18 +1,17 @@ -using System.Diagnostics; -using BetterGenshinImpact.Core.Config; -using BetterGenshinImpact.Service.Interface; -using CommunityToolkit.Mvvm.ComponentModel; -using CommunityToolkit.Mvvm.Input; -using CommunityToolkit.Mvvm.Messaging.Messages; -using CommunityToolkit.Mvvm.Messaging; -using Wpf.Ui.Controls; -using BetterGenshinImpact.View.Pages; -using Wpf.Ui; -using System; -using System.IO; +using BetterGenshinImpact.Core.Config; using BetterGenshinImpact.GameTask; using BetterGenshinImpact.GameTask.Model.Enum; +using BetterGenshinImpact.Service.Interface; +using BetterGenshinImpact.View.Pages; using BetterGenshinImpact.View.Windows; +using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; +using CommunityToolkit.Mvvm.Messaging; +using CommunityToolkit.Mvvm.Messaging.Messages; +using System.Diagnostics; +using System.IO; +using Wpf.Ui; +using Wpf.Ui.Controls; namespace BetterGenshinImpact.ViewModel.Pages; diff --git a/BetterGenshinImpact/ViewModel/Pages/DispatcherPageViewModel.cs b/BetterGenshinImpact/ViewModel/Pages/DispatcherPageViewModel.cs index c009fc3b..12174681 100644 --- a/BetterGenshinImpact/ViewModel/Pages/DispatcherPageViewModel.cs +++ b/BetterGenshinImpact/ViewModel/Pages/DispatcherPageViewModel.cs @@ -1,20 +1,8 @@ -using BetterGenshinImpact.Core.Config; -using BetterGenshinImpact.Core.Recorder; -using BetterGenshinImpact.GameTask; -using BetterGenshinImpact.Model; -using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Diagnostics; -using System.IO; -using System.Linq; -using System.Threading.Tasks; using Wpf.Ui; using Wpf.Ui.Controls; -using MessageBox = System.Windows.MessageBox; namespace BetterGenshinImpact.ViewModel.Pages; diff --git a/BetterGenshinImpact/ViewModel/Pages/HotKeyPageViewModel.cs b/BetterGenshinImpact/ViewModel/Pages/HotKeyPageViewModel.cs index 89bfe65b..a0cbd014 100644 --- a/BetterGenshinImpact/ViewModel/Pages/HotKeyPageViewModel.cs +++ b/BetterGenshinImpact/ViewModel/Pages/HotKeyPageViewModel.cs @@ -1,39 +1,29 @@ using BetterGenshinImpact.Core.Config; +using BetterGenshinImpact.Core.Recorder; +using BetterGenshinImpact.Core.Script; using BetterGenshinImpact.GameTask; -using BetterGenshinImpact.GameTask.Macro; -using BetterGenshinImpact.Service.Interface; -using CommunityToolkit.Mvvm.ComponentModel; -using System.Collections.ObjectModel; -using System.Diagnostics; -using System.Reflection; -using System.Threading; -using BetterGenshinImpact.Core.Simulator; using BetterGenshinImpact.GameTask.AutoFight; using BetterGenshinImpact.GameTask.AutoTrackPath; using BetterGenshinImpact.GameTask.Common; using BetterGenshinImpact.GameTask.Common.BgiVision; -using BetterGenshinImpact.GameTask.Model.Area; -using BetterGenshinImpact.Helpers.Extensions; -using Microsoft.Extensions.Logging; -using HotKeySettingModel = BetterGenshinImpact.Model.HotKeySettingModel; -using CommunityToolkit.Mvvm.Messaging.Messages; -using CommunityToolkit.Mvvm.Messaging; +using BetterGenshinImpact.GameTask.Macro; using BetterGenshinImpact.GameTask.QucikBuy; using BetterGenshinImpact.GameTask.QuickSereniteaPot; using BetterGenshinImpact.Helpers; +using BetterGenshinImpact.Helpers.Extensions; using BetterGenshinImpact.Model; +using BetterGenshinImpact.Service.Interface; +using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Messaging; +using CommunityToolkit.Mvvm.Messaging.Messages; +using Microsoft.Extensions.Logging; +using System.Collections.ObjectModel; +using System.Diagnostics; +using System.Reflection; +using System.Threading; using Vanara.PInvoke; -using BetterGenshinImpact.GameTask.Model.Enum; using static Vanara.PInvoke.User32; -using System.Runtime.InteropServices; -using System; -using System.Threading.Tasks; -using System.Windows.Forms; -using System.Windows.Input; -using BetterGenshinImpact.Core.Monitor; -using BetterGenshinImpact.Core.Recorder; -using BetterGenshinImpact.Core.Script; -using Cursors = System.Windows.Input.Cursors; +using HotKeySettingModel = BetterGenshinImpact.Model.HotKeySettingModel; namespace BetterGenshinImpact.ViewModel.Pages; @@ -44,7 +34,7 @@ public partial class HotKeyPageViewModel : ObservableObject, IViewModel public AllConfig Config { get; set; } [ObservableProperty] - private ObservableCollection _hotKeySettingModels = new(); + private ObservableCollection _hotKeySettingModels = []; public HotKeyPageViewModel(IConfigService configService, ILogger logger, TaskSettingsPageViewModel taskSettingsPageViewModel) { @@ -381,7 +371,8 @@ public partial class HotKeyPageViewModel : ObservableObject, IViewModel "停止当前脚本任务", nameof(Config.HotKeyConfig.CancelTaskHotkey), Config.HotKeyConfig.CancelTaskHotkey, - Config.HotKeyConfig.CancelTaskHotkeyType, async (_, _) => + Config.HotKeyConfig.CancelTaskHotkeyType, + (_, _) => { CancellationContext.Instance.Cancel(); } diff --git a/BetterGenshinImpact/ViewModel/Pages/KeyMouseRecordPageViewModel.cs b/BetterGenshinImpact/ViewModel/Pages/KeyMouseRecordPageViewModel.cs index 76f5ee96..dd635efd 100644 --- a/BetterGenshinImpact/ViewModel/Pages/KeyMouseRecordPageViewModel.cs +++ b/BetterGenshinImpact/ViewModel/Pages/KeyMouseRecordPageViewModel.cs @@ -13,7 +13,6 @@ using System.Collections.ObjectModel; using System.Diagnostics; using System.IO; using System.Linq; -using System.Threading; using System.Threading.Tasks; using Wpf.Ui; using Wpf.Ui.Controls; @@ -42,8 +41,9 @@ public partial class KeyMouseRecordPageViewModel : ObservableObject, INavigation private void InitScriptListViewData() { _scriptItems.Clear(); - var fileInfos = LoadScriptFiles(scriptPath); - fileInfos = fileInfos.OrderByDescending(f => f.CreationTime).ToList(); + var fileInfos = LoadScriptFiles(scriptPath) + .OrderByDescending(f => f.CreationTime) + .ToList(); foreach (var f in fileInfos) { _scriptItems.Add(new KeyMouseScriptItem @@ -159,7 +159,7 @@ public partial class KeyMouseRecordPageViewModel : ObservableObject, INavigation TimeSpan.FromSeconds(2) ); } - catch (Exception e) + catch (Exception) { _snackbarService.Show( "删除失败", diff --git a/BetterGenshinImpact/ViewModel/Pages/MacroSettingsPageViewModel.cs b/BetterGenshinImpact/ViewModel/Pages/MacroSettingsPageViewModel.cs index 6c1c5c1f..9c25f94a 100644 --- a/BetterGenshinImpact/ViewModel/Pages/MacroSettingsPageViewModel.cs +++ b/BetterGenshinImpact/ViewModel/Pages/MacroSettingsPageViewModel.cs @@ -6,7 +6,6 @@ using BetterGenshinImpact.View.Windows; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using System.Diagnostics; -using System.Windows.Input; using Wpf.Ui; using Wpf.Ui.Controls; diff --git a/BetterGenshinImpact/ViewModel/Pages/NotificationSettingsPageViewModel.cs b/BetterGenshinImpact/ViewModel/Pages/NotificationSettingsPageViewModel.cs index 325843a8..5172f721 100644 --- a/BetterGenshinImpact/ViewModel/Pages/NotificationSettingsPageViewModel.cs +++ b/BetterGenshinImpact/ViewModel/Pages/NotificationSettingsPageViewModel.cs @@ -1,10 +1,10 @@ -using System.Threading.Tasks; -using BetterGenshinImpact.Core.Config; +using BetterGenshinImpact.Core.Config; using BetterGenshinImpact.Service.Interface; using BetterGenshinImpact.Service.Notification; using BetterGenshinImpact.Service.Notifier; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; +using System.Threading.Tasks; namespace BetterGenshinImpact.ViewModel.Pages; diff --git a/BetterGenshinImpact/ViewModel/Pages/ScriptControlViewModel.cs b/BetterGenshinImpact/ViewModel/Pages/ScriptControlViewModel.cs index 3e99455f..938e762d 100644 --- a/BetterGenshinImpact/ViewModel/Pages/ScriptControlViewModel.cs +++ b/BetterGenshinImpact/ViewModel/Pages/ScriptControlViewModel.cs @@ -1,6 +1,8 @@ using BetterGenshinImpact.Core.Config; using BetterGenshinImpact.Core.Script.Group; using BetterGenshinImpact.Core.Script.Project; +using BetterGenshinImpact.GameTask; +using BetterGenshinImpact.GameTask.Model.Enum; using BetterGenshinImpact.View.Windows; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; @@ -12,15 +14,11 @@ using System.Collections.Specialized; using System.Diagnostics; using System.IO; using System.Linq; +using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Windows.Controls; -using BetterGenshinImpact.Core.Recorder; -using BetterGenshinImpact.Core.Script; -using BetterGenshinImpact.GameTask; -using BetterGenshinImpact.GameTask.Model.Enum; using Wpf.Ui; using Wpf.Ui.Controls; -using System.Text.RegularExpressions; namespace BetterGenshinImpact.ViewModel.Pages; @@ -253,7 +251,7 @@ public partial class ScriptControlViewModel : ObservableObject, INavigationAware ScriptGroups.Clear(); var files = Directory.GetFiles(ScriptGroupPath, "*.json"); - List groups = new(); + List groups = []; foreach (var file in files) { try @@ -410,7 +408,9 @@ public partial class ScriptControlViewModel : ObservableObject, INavigationAware private bool HasTimerOperation(IEnumerable codeList) { - var regex = new Regex(@"^(?!\s*\/\/)\s*dispatcher\.\s*addTimer", RegexOptions.Multiline); - return codeList.Any(code => regex.IsMatch(code)); + return codeList.Any(code => DispatcherAddTimerRegex().IsMatch(code)); } + + [GeneratedRegex(@"^(?!\s*\/\/)\s*dispatcher\.\s*addTimer", RegexOptions.Multiline)] + private static partial Regex DispatcherAddTimerRegex(); } diff --git a/BetterGenshinImpact/ViewModel/Pages/TaskSettingsPageViewModel.cs b/BetterGenshinImpact/ViewModel/Pages/TaskSettingsPageViewModel.cs index f7dd4399..4765022e 100644 --- a/BetterGenshinImpact/ViewModel/Pages/TaskSettingsPageViewModel.cs +++ b/BetterGenshinImpact/ViewModel/Pages/TaskSettingsPageViewModel.cs @@ -1,24 +1,24 @@ -using System; -using BetterGenshinImpact.Core.Config; +using BetterGenshinImpact.Core.Config; using BetterGenshinImpact.GameTask; using BetterGenshinImpact.GameTask.AutoDomain; using BetterGenshinImpact.GameTask.AutoFight; using BetterGenshinImpact.GameTask.AutoGeniusInvokation; +using BetterGenshinImpact.GameTask.AutoMusicGame; using BetterGenshinImpact.GameTask.AutoSkip.Model; +using BetterGenshinImpact.GameTask.AutoTrackPath; using BetterGenshinImpact.GameTask.AutoWood; using BetterGenshinImpact.GameTask.Model; using BetterGenshinImpact.Service.Interface; using BetterGenshinImpact.View.Pages; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; +using System; using System.Diagnostics; using System.IO; using System.Threading; using Wpf.Ui; using Wpf.Ui.Controls; using MessageBox = System.Windows.MessageBox; -using BetterGenshinImpact.GameTask.AutoMusicGame; -using BetterGenshinImpact.GameTask.AutoTrackPath; namespace BetterGenshinImpact.ViewModel.Pages; @@ -69,7 +69,7 @@ public partial class TaskSettingsPageViewModel : ObservableObject, INavigationAw if (files[i].EndsWith(".txt")) { var strategyName = files[i].Replace(folder, "").Replace(".txt", ""); - if (strategyName.StartsWith(@"\")) + if (strategyName.StartsWith('\\')) { strategyName = strategyName[1..]; } diff --git a/BetterGenshinImpact/ViewModel/Windows/AutoPickBlackListViewModel.cs b/BetterGenshinImpact/ViewModel/Windows/AutoPickBlackListViewModel.cs index f0948bab..eca58980 100644 --- a/BetterGenshinImpact/ViewModel/Windows/AutoPickBlackListViewModel.cs +++ b/BetterGenshinImpact/ViewModel/Windows/AutoPickBlackListViewModel.cs @@ -13,7 +13,7 @@ public class AutoPickBlackListViewModel : FormViewModel var blackListJson = Global.ReadAllTextIfExist(@"User\pick_black_lists.json"); if (!string.IsNullOrEmpty(blackListJson)) { - var blackList = JsonSerializer.Deserialize>(blackListJson) ?? new List(); + var blackList = JsonSerializer.Deserialize>(blackListJson) ?? []; AddRange(blackList); } } diff --git a/BetterGenshinImpact/ViewModel/Windows/AutoPickWhiteListViewModel.cs b/BetterGenshinImpact/ViewModel/Windows/AutoPickWhiteListViewModel.cs index a45aedce..f0706373 100644 --- a/BetterGenshinImpact/ViewModel/Windows/AutoPickWhiteListViewModel.cs +++ b/BetterGenshinImpact/ViewModel/Windows/AutoPickWhiteListViewModel.cs @@ -13,7 +13,7 @@ public class AutoPickWhiteListViewModel : FormViewModel var blackListJson = Global.ReadAllTextIfExist(@"User\pick_white_lists.json"); if (!string.IsNullOrEmpty(blackListJson)) { - var blackList = JsonSerializer.Deserialize>(blackListJson) ?? new List(); + var blackList = JsonSerializer.Deserialize>(blackListJson) ?? []; AddRange(blackList); } } diff --git a/BetterGenshinImpact/ViewModel/Windows/FormViewModel.cs b/BetterGenshinImpact/ViewModel/Windows/FormViewModel.cs index 971c7f80..527d6123 100644 --- a/BetterGenshinImpact/ViewModel/Windows/FormViewModel.cs +++ b/BetterGenshinImpact/ViewModel/Windows/FormViewModel.cs @@ -11,7 +11,7 @@ public abstract partial class FormViewModel : ObservableObject protected FormViewModel() { - _list = new(); + _list = []; } public void AddRange(List itemList) diff --git a/BetterGenshinImpact/ViewModel/Windows/JsonMonoViewModel.cs b/BetterGenshinImpact/ViewModel/Windows/JsonMonoViewModel.cs index f4622ac3..bbd24caf 100644 --- a/BetterGenshinImpact/ViewModel/Windows/JsonMonoViewModel.cs +++ b/BetterGenshinImpact/ViewModel/Windows/JsonMonoViewModel.cs @@ -5,7 +5,6 @@ using BetterGenshinImpact.View.Windows; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using System; -using System.Collections.Generic; using System.Linq; using System.Text.Json; using System.Windows; diff --git a/BetterGenshinImpact/ViewModel/Windows/MapViewerViewModel.cs b/BetterGenshinImpact/ViewModel/Windows/MapViewerViewModel.cs index e23433d3..e0adab84 100644 --- a/BetterGenshinImpact/ViewModel/Windows/MapViewerViewModel.cs +++ b/BetterGenshinImpact/ViewModel/Windows/MapViewerViewModel.cs @@ -1,9 +1,8 @@ -using System; -using System.Windows; -using BetterGenshinImpact.Core.Config; +using BetterGenshinImpact.Core.Config; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Messaging; using CommunityToolkit.Mvvm.Messaging.Messages; +using System.Windows; namespace BetterGenshinImpact.ViewModel.Windows; diff --git a/Fischless.GameCapture/DwmSharedSurface/Helpers/NativeMethods.cs b/Fischless.GameCapture/DwmSharedSurface/Helpers/NativeMethods.cs index c0fe0a89..adfc4e44 100644 --- a/Fischless.GameCapture/DwmSharedSurface/Helpers/NativeMethods.cs +++ b/Fischless.GameCapture/DwmSharedSurface/Helpers/NativeMethods.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.InteropServices; -using System.Text; -using System.Threading.Tasks; +using System.Runtime.InteropServices; using Vanara.PInvoke; namespace Fischless.GameCapture.DwmSharedSurface.Helpers; diff --git a/Fischless.GameCapture/Graphics/Helpers/Direct3D11Helper.cs b/Fischless.GameCapture/Graphics/Helpers/Direct3D11Helper.cs index e312f8a6..6a831f30 100644 --- a/Fischless.GameCapture/Graphics/Helpers/Direct3D11Helper.cs +++ b/Fischless.GameCapture/Graphics/Helpers/Direct3D11Helper.cs @@ -1,11 +1,9 @@ -using System.Diagnostics.CodeAnalysis; -using System.Runtime.InteropServices; +using System.Runtime.InteropServices; using Windows.Graphics.DirectX.Direct3D11; using WinRT; namespace Fischless.GameCapture.Graphics.Helpers; -[SuppressMessage("CodeQuality", "IDE0052:")] public static class Direct3D11Helper { internal static Guid IInspectable = new("AF86E2E0-B12D-4c6a-9C5A-D7AA65101E90"); @@ -59,7 +57,7 @@ public static class Direct3D11Helper public static IDirect3DDevice CreateDirect3DDeviceFromSharpDXDevice(SharpDX.Direct3D11.Device d3dDevice) { - IDirect3DDevice device = null; + IDirect3DDevice device = default!; // Acquire the DXGI interface for the Direct3D device. using (var dxgiDevice = d3dDevice.QueryInterface()) @@ -79,7 +77,7 @@ public static class Direct3D11Helper public static IDirect3DSurface CreateDirect3DSurfaceFromSharpDXTexture(SharpDX.Direct3D11.Texture2D texture) { - IDirect3DSurface surface = null; + IDirect3DSurface surface = default!; // Acquire the DXGI interface for the Direct3D surface. using (var dxgiSurface = texture.QueryInterface()) diff --git a/Fischless.GameCapture/Graphics/Helpers/Texture2DExtensions.cs b/Fischless.GameCapture/Graphics/Helpers/Texture2DExtensions.cs index 4301a7c1..0feca9c5 100644 --- a/Fischless.GameCapture/Graphics/Helpers/Texture2DExtensions.cs +++ b/Fischless.GameCapture/Graphics/Helpers/Texture2DExtensions.cs @@ -1,10 +1,9 @@ -using System.Diagnostics; -using System.Drawing.Imaging; -using Windows.Graphics.Capture; -using SharpDX; +using SharpDX; using SharpDX.Direct3D11; using SharpDX.DXGI; -using Windows.Devices.HumanInterfaceDevice; +using System.Diagnostics; +using System.Drawing.Imaging; +using Windows.Graphics.Capture; namespace Fischless.GameCapture.Graphics.Helpers; diff --git a/Fischless.GameCapture/Graphics/Helpers/WinRT.cs b/Fischless.GameCapture/Graphics/Helpers/WinRT.cs index 42df33f4..09d1395b 100644 --- a/Fischless.GameCapture/Graphics/Helpers/WinRT.cs +++ b/Fischless.GameCapture/Graphics/Helpers/WinRT.cs @@ -43,7 +43,7 @@ internal class Platform /// internal static class WinrtModule { - private static readonly Dictionary> Cache = new(); + private static readonly Dictionary> Cache = []; public static ObjectReference GetActivationFactory(string runtimeClassId) { diff --git a/Fischless.KeyboardCapture/KeyboardHook.cs b/Fischless.KeyboardCapture/KeyboardHook.cs index ce668573..a38c3e0f 100644 --- a/Fischless.KeyboardCapture/KeyboardHook.cs +++ b/Fischless.KeyboardCapture/KeyboardHook.cs @@ -30,7 +30,7 @@ public sealed class KeyboardHook : IDisposable if (hook.IsNull) { hookProc = KeyboardHookProc; - hook = User32.SetWindowsHookEx(User32.HookType.WH_KEYBOARD_LL, hookProc, Kernel32.GetModuleHandle(Process.GetCurrentProcess().MainModule.ModuleName), 0); + hook = User32.SetWindowsHookEx(User32.HookType.WH_KEYBOARD_LL, hookProc, Kernel32.GetModuleHandle(Process.GetCurrentProcess().MainModule!.ModuleName), 0); User32.SetWindowsHookEx(User32.HookType.WH_KEYBOARD_LL, hookProc, IntPtr.Zero, (int)Kernel32.GetCurrentThreadId()); diff --git a/Fischless.KeyboardCapture/KeyboardItem.cs b/Fischless.KeyboardCapture/KeyboardItem.cs index 14eb64d2..5279c063 100644 --- a/Fischless.KeyboardCapture/KeyboardItem.cs +++ b/Fischless.KeyboardCapture/KeyboardItem.cs @@ -4,9 +4,9 @@ public record struct KeyboardItem { public DateTime DateTime; public KeyboardKeys KeyCode; - public string Key; + public string? Key; - public KeyboardItem(DateTime dateTime, KeyboardKeys keyCode, string? key = null) + public KeyboardItem(DateTime dateTime, KeyboardKeys keyCode, string? key = default) { DateTime = dateTime; KeyCode = keyCode; diff --git a/Fischless.KeyboardCapture/KeyboardResult.cs b/Fischless.KeyboardCapture/KeyboardResult.cs index 27de5585..617caabd 100644 --- a/Fischless.KeyboardCapture/KeyboardResult.cs +++ b/Fischless.KeyboardCapture/KeyboardResult.cs @@ -71,5 +71,5 @@ public sealed class KeyboardResult return Key; } - public static implicit operator string(KeyboardResult result) => result?.ToString(); + public static implicit operator string(KeyboardResult result) => result.ToString(); } diff --git a/Fischless.WindowsInput/KeyboardSimulator.cs b/Fischless.WindowsInput/KeyboardSimulator.cs index e4c2642c..80b15416 100644 --- a/Fischless.WindowsInput/KeyboardSimulator.cs +++ b/Fischless.WindowsInput/KeyboardSimulator.cs @@ -120,31 +120,31 @@ public class KeyboardSimulator : IKeyboardSimulator public IKeyboardSimulator ModifiedKeyStroke(User32.VK modifierKeyCode, User32.VK keyCode) { - ModifiedKeyStroke(new User32.VK[] - { + ModifiedKeyStroke( + [ modifierKeyCode, - }, new User32.VK[] - { + ], + [ keyCode, - }); + ]); return this; } public IKeyboardSimulator ModifiedKeyStroke(IEnumerable modifierKeyCodes, User32.VK keyCode) { - ModifiedKeyStroke(modifierKeyCodes, new User32.VK[] - { + ModifiedKeyStroke(modifierKeyCodes, + [ keyCode - }); + ]); return this; } public IKeyboardSimulator ModifiedKeyStroke(User32.VK modifierKey, IEnumerable keyCodes) { - ModifiedKeyStroke(new User32.VK[] - { + ModifiedKeyStroke( + [ modifierKey - }, keyCodes); + ], keyCodes); return this; } diff --git a/Vision.WindowCapture/BitBlt/BitBltCapture.cs b/Vision.WindowCapture/BitBlt/BitBltCapture.cs index 6f03d2a7..45cae4b4 100644 --- a/Vision.WindowCapture/BitBlt/BitBltCapture.cs +++ b/Vision.WindowCapture/BitBlt/BitBltCapture.cs @@ -39,8 +39,8 @@ namespace Vision.WindowCapture.BitBlt Windows.Win32.PInvoke.BitBlt(hdcDest, 0, 0, width, height, hdcSrc, 0, 0, ROP_CODE.SRCCOPY); SelectObject(hdcDest, hOld); DeleteDC(hdcDest); - ReleaseDC(_hWnd, hdcSrc); - + _ = ReleaseDC(_hWnd, hdcSrc); + var bitmap = Image.FromHbitmap(hBitmap); DeleteObject(hBitmap); return bitmap; diff --git a/Vision.WindowCapture/CaptureModeExtensions.cs b/Vision.WindowCapture/CaptureModeExtensions.cs index 602329c7..814e99f9 100644 --- a/Vision.WindowCapture/CaptureModeExtensions.cs +++ b/Vision.WindowCapture/CaptureModeExtensions.cs @@ -4,6 +4,6 @@ public static class CaptureModeExtensions { public static CaptureModeEnum ToCaptureMode(this string modeName) { - return (CaptureModeEnum) Enum.Parse(typeof(CaptureModeEnum), modeName); + return (CaptureModeEnum)Enum.Parse(typeof(CaptureModeEnum), modeName); } } diff --git a/Vision.WindowCapture/GraphicsCapture/GraphicsCapture.cs b/Vision.WindowCapture/GraphicsCapture/GraphicsCapture.cs index 266d923d..c38a715d 100644 --- a/Vision.WindowCapture/GraphicsCapture/GraphicsCapture.cs +++ b/Vision.WindowCapture/GraphicsCapture/GraphicsCapture.cs @@ -49,7 +49,7 @@ public class GraphicsCapture : IWindowCapture _captureSession.IsBorderRequired = false; _captureSession.IsCursorCaptureEnabled = false; } - + _captureSession.StartCapture(); IsCapturing = true; } diff --git a/Vision.WindowCapture/GraphicsCapture/Helpers/CaptureHelper.cs b/Vision.WindowCapture/GraphicsCapture/Helpers/CaptureHelper.cs index 2612b0e0..a7de2774 100644 --- a/Vision.WindowCapture/GraphicsCapture/Helpers/CaptureHelper.cs +++ b/Vision.WindowCapture/GraphicsCapture/Helpers/CaptureHelper.cs @@ -37,7 +37,7 @@ public static class CaptureHelper InitializeWithWindow.Initialize(picker, hwnd); } - [return:MaybeNull] + [return: MaybeNull] public static unsafe GraphicsCaptureItem CreateItemForWindow(HWND hwnd) { return GraphicsCaptureItem.TryCreateFromWindowId(*(WindowId*)&hwnd); diff --git a/Vision.WindowCapture/GraphicsCapture/Helpers/Direct3D11Helper.cs b/Vision.WindowCapture/GraphicsCapture/Helpers/Direct3D11Helper.cs index d63984e3..adb55f99 100644 --- a/Vision.WindowCapture/GraphicsCapture/Helpers/Direct3D11Helper.cs +++ b/Vision.WindowCapture/GraphicsCapture/Helpers/Direct3D11Helper.cs @@ -44,8 +44,6 @@ public static class Direct3D11Helper public static unsafe IDirect3DDevice? CreateDirect3DDevice() { - ID3D11Device? d3d11Device; - HRESULT hr = D3D11CreateDevice( default, D3D_DRIVER_TYPE.D3D_DRIVER_TYPE_HARDWARE, @@ -54,7 +52,7 @@ public static class Direct3D11Helper default, 0, D3D11_SDK_VERSION, - out d3d11Device, + out ID3D11Device? d3d11Device, default, out _); diff --git a/Vision.WindowCapture/IWindowCapture.cs b/Vision.WindowCapture/IWindowCapture.cs index 97b15369..c9d54d4a 100644 --- a/Vision.WindowCapture/IWindowCapture.cs +++ b/Vision.WindowCapture/IWindowCapture.cs @@ -6,7 +6,7 @@ namespace Vision.WindowCapture; public interface IWindowCapture { bool IsCapturing { get; } - + Task StartAsync(HWND hWnd); Bitmap? Capture(); diff --git a/Vision.WindowCapture/WindowCaptureFactory.cs b/Vision.WindowCapture/WindowCaptureFactory.cs index ba344089..0a00146e 100644 --- a/Vision.WindowCapture/WindowCaptureFactory.cs +++ b/Vision.WindowCapture/WindowCaptureFactory.cs @@ -10,14 +10,11 @@ public class WindowCaptureFactory public static IWindowCapture Create(CaptureModeEnum mode) { - switch (mode) + return mode switch { - case CaptureModeEnum.BitBlt: - return new BitBlt.BitBltCapture(); - case CaptureModeEnum.WindowsGraphicsCapture: - return new GraphicsCapture.GraphicsCapture(); - default: - throw new ArgumentOutOfRangeException(nameof(mode), mode, null); - } + CaptureModeEnum.BitBlt => new BitBlt.BitBltCapture(), + CaptureModeEnum.WindowsGraphicsCapture => new GraphicsCapture.GraphicsCapture(), + _ => throw new ArgumentOutOfRangeException(nameof(mode), mode, null), + }; } }