diff --git a/Core/AddonComponent/BuffStatus.cs b/Core/AddonComponent/BuffStatus.cs index 533e0279..06ae97f9 100644 --- a/Core/AddonComponent/BuffStatus.cs +++ b/Core/AddonComponent/BuffStatus.cs @@ -43,7 +43,7 @@ public void Update(IAddonDataProvider reader) public bool Mark_of_the_Wild() => v[Mask._10]; public bool Thorns() => v[Mask._11]; - [Names(new[] { "Tiger's Fury" })] + [Names(["Tiger's Fury"])] public bool Tigers_Fury() => v[Mask._12]; public bool Prowl() => v[Mask._13]; public bool Rejuvenation() => v[Mask._14]; @@ -74,11 +74,11 @@ public void Update(IAddonDataProvider reader) public bool Divine_Shield() => v[Mask._23]; // Mage - [Names(new[] { + [Names([ "Frost Armor", "Ice Armor", "Molten Armor", - "Mage Armor" })] + "Mage Armor"])] public bool Frost_Armor() => v[Mask._10]; public bool Arcane_Intellect() => v[Mask._11]; public bool Ice_Barrier() => v[Mask._12]; @@ -97,9 +97,9 @@ public void Update(IAddonDataProvider reader) public bool Bloodrage() => v[Mask._11]; // Warlock - [Names(new[] { + [Names([ "Demon Skin", - "Demon Armor" })] + "Demon Armor"])] public bool Demon_Skin() => v[Mask._10]; //Skin and Armor public bool Soul_Link() => v[Mask._11]; public bool Soulstone_Resurrection() => v[Mask._12]; @@ -112,9 +112,9 @@ public void Update(IAddonDataProvider reader) // Shaman public bool Lightning_Shield() => v[Mask._10]; public bool Water_Shield() => v[Mask._11]; - [Names(new[] { + [Names([ "Shamanistic Focus", - "Focused" })] + "Focused"])] public bool Shamanistic_Focus() => v[Mask._12]; public bool Stoneskin() => v[Mask._13]; @@ -135,7 +135,7 @@ public void Update(IAddonDataProvider reader) public bool Horn_of_Winter() => v[Mask._11]; public bool Icebound_Fortitude() => v[Mask._12]; public bool Path_of_Frost() => v[Mask._13]; - [Names(new[] { "Anti-Magic Shell" })] + [Names(["Anti-Magic Shell"])] public bool Anti_Magic_Shell() => v[Mask._14]; public bool Army_of_the_Dead() => v[Mask._15]; public bool Vampiric_Blood() => v[Mask._16]; diff --git a/Core/AddonComponent/TargetDebuffStatus.cs b/Core/AddonComponent/TargetDebuffStatus.cs index b805d815..80b5ab0a 100644 --- a/Core/AddonComponent/TargetDebuffStatus.cs +++ b/Core/AddonComponent/TargetDebuffStatus.cs @@ -21,7 +21,7 @@ public override string ToString() } // Priest - [Names(new[] { "Shadow Word: Pain" })] + [Names(["Shadow Word: Pain"])] public bool Shadow_Word_Pain() => v[Mask._0]; // Druid @@ -53,13 +53,13 @@ public override string ToString() public bool Charge_Stun() => v[Mask._3]; // Warlock - [Names(new[] { + [Names([ "Curse of Weakness", "Curse of Elements", "Curse of Recklessness", "Curse of Shadow", "Curse of Agony", - "Curse of" })] + "Curse of"])] public bool Curse_of() => v[Mask._0]; public bool Corruption() => v[Mask._1]; public bool Immolate() => v[Mask._2]; @@ -67,7 +67,7 @@ public override string ToString() // Hunter public bool Serpent_Sting() => v[Mask._0]; - [Names(new[] { "Hunter's Mark" })] + [Names(["Hunter's Mark"])] public bool Hunters_Mark() => v[Mask._1]; public bool Viper_Sting() => v[Mask._2]; public bool Explosive_Shot() => v[Mask._3]; diff --git a/Core/Configurator/AddonConfigurator.cs b/Core/Configurator/AddonConfigurator.cs index 48d0676d..53ef2086 100644 --- a/Core/Configurator/AddonConfigurator.cs +++ b/Core/Configurator/AddonConfigurator.cs @@ -8,7 +8,7 @@ namespace Core; -public sealed class AddonConfigurator +public sealed partial class AddonConfigurator { private readonly ILogger logger; private readonly WowProcess process; @@ -56,7 +56,7 @@ public bool Validate() // this will appear in the lua code so // special character not allowed // also numbers not allowed - Config.Title = Regex.Replace(Config.Title, @"[^\u0000-\u007F]+", string.Empty); + Config.Title = RegexTitle().Replace(Config.Title, string.Empty); Config.Title = new string(Config.Title.Where(char.IsLetter).ToArray()); Config.Title = Config.Title.Trim() @@ -197,7 +197,7 @@ private void EditMainLua() .Replace("dc", Config.Command) .Replace("DC", Config.Command); - Regex cellSizeRegex = new(@"^local CELL_SIZE = (?[0-9]+)", RegexOptions.Multiline); + Regex cellSizeRegex = RegexCellSize(); text = text.Replace(cellSizeRegex, "SIZE", Config.CellSize); File.WriteAllText(mainLuaPath, text); @@ -313,7 +313,7 @@ public bool UpdateAvailable() return null; string begin = "## Version: "; - var line = File + string? line = File .ReadLines(tocPath) .SkipWhile(line => !line.StartsWith(begin)) .FirstOrDefault(); @@ -321,4 +321,10 @@ public bool UpdateAvailable() string? versionStr = line?.Split(begin)[1]; return Version.TryParse(versionStr, out Version? version) ? version : null; } + + [GeneratedRegex(@"[^\u0000-\u007F]+")] + private static partial Regex RegexTitle(); + + [GeneratedRegex(@"^local CELL_SIZE = (?[0-9]+)", RegexOptions.Multiline)] + private static partial Regex RegexCellSize(); } \ No newline at end of file diff --git a/Core/Goals/GoapGoal.cs b/Core/Goals/GoapGoal.cs index f36b71fe..b5b14f0b 100644 --- a/Core/Goals/GoapGoal.cs +++ b/Core/Goals/GoapGoal.cs @@ -6,7 +6,7 @@ namespace Core.Goals; -public abstract class GoapGoal +public abstract partial class GoapGoal { public Dictionary Preconditions { get; } = new(); public Dictionary Effects { get; } = new(); @@ -33,7 +33,7 @@ protected set protected GoapGoal(string name) { - string output = Regex.Replace(name.Replace("Goal", ""), @"\p{Lu}", m => " " + m.Value.ToUpperInvariant()); + string output = RegexGoalName().Replace(name.Replace("Goal", ""), m => " " + m.Value.ToUpperInvariant()); DisplayName = Name = string.Concat(output[0].ToString().ToUpper(), output.AsSpan(1)); } @@ -58,4 +58,7 @@ protected void AddEffect(GoapKey key, bool value) { Effects[key] = value; } + + [GeneratedRegex(@"\p{Lu}")] + private static partial Regex RegexGoalName(); } \ No newline at end of file diff --git a/Core/Requirement/RequirementFactory.cs b/Core/Requirement/RequirementFactory.cs index af815f7f..d81bad11 100644 --- a/Core/Requirement/RequirementFactory.cs +++ b/Core/Requirement/RequirementFactory.cs @@ -682,7 +682,7 @@ public Requirement CreateRequirement(string requirement) return r; } - if (!boolVariables.ContainsKey(requirement)) + if (!boolVariables.TryGetValue(requirement, out Func? value)) { LogUnknown(logger, requirement, string.Join(", ", boolVariables.Keys)); return new Requirement @@ -694,7 +694,7 @@ public Requirement CreateRequirement(string requirement) string s() => requirement; Requirement req = new() { - HasRequirement = boolVariables[requirement], + HasRequirement = value, LogMessage = s }; diff --git a/Core/Session/LocalGrindSessionDAO.cs b/Core/Session/LocalGrindSessionDAO.cs index 41f99be5..492032d8 100644 --- a/Core/Session/LocalGrindSessionDAO.cs +++ b/Core/Session/LocalGrindSessionDAO.cs @@ -28,7 +28,7 @@ public IEnumerable Load() .OrderByDescending(grindingSession => grindingSession.SessionStart) .ToList(); - if (sessions.Any()) + if (sessions.Count != 0) { int[] expList = ExperienceProvider.Get(dataConfig); foreach (GrindSession? s in sessions) diff --git a/CoreTests/Program.cs b/CoreTests/Program.cs index d8b2f123..cb4e5dfc 100644 --- a/CoreTests/Program.cs +++ b/CoreTests/Program.cs @@ -42,11 +42,11 @@ public static void Main() }); // its expected to have at least 2 DataFrame - DataFrame[] mockFrames = new DataFrame[2] - { + DataFrame[] mockFrames = + [ new DataFrame(0, 0, 0), new DataFrame(1, 0, 0), - }; + ]; cts = new CancellationTokenSource(); process = new(cts); @@ -83,6 +83,8 @@ private static void Test_NPCNameFinder() Log.Logger.Information($"running {count} samples..."); + screen.Enabled = true; + while (i < count) { if (LogOverallTimes) @@ -97,6 +99,8 @@ private static void Test_NPCNameFinder() Thread.Sleep(4); } + screen.Enabled = false; + if (LogOverallTimes) { Log.Logger.Information($"overall | sample: {count:D4} | avg: {sample.Average():F2} | min: {sample.Min():F2} | max: {sample.Max():000.000} | total: {sample.Sum():F2}"); diff --git a/Game/Input/WowProcessInput.cs b/Game/Input/WowProcessInput.cs index b166b995..5d75a107 100644 --- a/Game/Input/WowProcessInput.cs +++ b/Game/Input/WowProcessInput.cs @@ -21,7 +21,7 @@ public sealed partial class WowProcessInput : IMouseInput private readonly WowProcess process; private readonly InputWindowsNative nativeInput; - private readonly IInput simulatorInput; + private readonly InputSimulator simulatorInput; private readonly BitArray keysDown; @@ -39,8 +39,8 @@ public WowProcessInput(ILogger logger, CancellationTokenSource keysDown = new((int)ConsoleKey.OemClear); - nativeInput = new InputWindowsNative(process, cts, InputDuration.FastPress); - simulatorInput = new InputSimulator(process, cts, InputDuration.FastPress); + nativeInput = new(process, cts, InputDuration.FastPress); + simulatorInput = new(process, cts, InputDuration.FastPress); } public void Reset() diff --git a/PPather/Graph/GraphChunk.cs b/PPather/Graph/GraphChunk.cs index 028b12ad..ed065320 100644 --- a/PPather/Graph/GraphChunk.cs +++ b/PPather/Graph/GraphChunk.cs @@ -158,7 +158,7 @@ public bool Load() { long timestamp = Stopwatch.GetTimestamp(); - using Stream stream = File.OpenRead(filePath); + using FileStream stream = File.OpenRead(filePath); using BinaryReader br = new(stream); if (br.ReadUInt32() != FILE_MAGIC) @@ -221,7 +221,7 @@ public void Save() try { - using Stream stream = File.Create(filePath); + using FileStream stream = File.Create(filePath); using BinaryWriter bw = new(stream); bw.Write(FILE_MAGIC);