From b3c9f5bdd4f4b8b595bba0b158b6beb1ecc10ac4 Mon Sep 17 00:00:00 2001 From: Refringe Date: Thu, 14 Nov 2024 10:01:55 -0500 Subject: [PATCH 1/4] Resolves Warning CS0109 A class declaration included the new keyword even though the declaration does not override an existing declaration in a base class. The new keyword can be deleted. --- Common.Models/Output/Equipment.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Common.Models/Output/Equipment.cs b/Common.Models/Output/Equipment.cs index f6d5411..61f0035 100644 --- a/Common.Models/Output/Equipment.cs +++ b/Common.Models/Output/Equipment.cs @@ -69,7 +69,7 @@ namespace Common.Models.Output public Dictionary TacticalVest { get; set; } public Dictionary Pockets { get; set; } public Dictionary Backpack { get; set; } - public new Dictionary SecuredContainer { get; set; } - public new Dictionary SpecialLoot { get; set; } + public Dictionary SecuredContainer { get; set; } + public Dictionary SpecialLoot { get; set; } } } -- 2.47.1 From 3faeb80e55ce4bf10c3071b959f03ccac12f94b4 Mon Sep 17 00:00:00 2001 From: Refringe Date: Thu, 14 Nov 2024 11:31:22 -0500 Subject: [PATCH 2/4] Resolves Warning HAA0601 Value type to reference type conversion causes boxing at call site, and unboxing at the callee-site. Resolves by explicitly converting value to string before including it in a log message string. --- Generator/BotParser.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Generator/BotParser.cs b/Generator/BotParser.cs index 3843470..a300a92 100644 --- a/Generator/BotParser.cs +++ b/Generator/BotParser.cs @@ -33,7 +33,7 @@ public static class BotParser DiskHelpers.CreateDirIfDoesntExist(dumpPath); var botFiles = Directory.GetFiles(dumpPath, "*.json", SearchOption.TopDirectoryOnly); - LoggingHelpers.LogToConsole($"{botFiles.Length} bot dump files found"); + LoggingHelpers.LogToConsole($"{botFiles.Length.ToString()} bot dump files found"); // Store a list of parsed bots so we don't parse the same bot twice int totalDupeCount = 0; @@ -42,7 +42,7 @@ public static class BotParser foreach (var filePath in botFiles) { i++; - if (i % 100 == 0) Console.WriteLine($"Processing file {i}"); + if (i % 100 == 0) Console.WriteLine($"Processing file {i.ToString()}"); ProcessBotFileSync(baseBots, filePath, parsedBotIds, totalDupeCount); } @@ -69,7 +69,7 @@ public static class BotParser } stopwatch.Stop(); - LoggingHelpers.LogToConsole($"{totalDupeCount} dupes were ignored. Took {LoggingHelpers.LogTimeTaken(stopwatch.Elapsed.TotalSeconds)} seconds"); + LoggingHelpers.LogToConsole($"{totalDupeCount.ToString()} dupes were ignored. Took {LoggingHelpers.LogTimeTaken(stopwatch.Elapsed.TotalSeconds)} seconds"); return baseBots.ToList(); } @@ -137,7 +137,7 @@ public static class BotParser DiskHelpers.CreateDirIfDoesntExist(dumpPath); var botFiles = Directory.GetFiles(dumpPath, "*.json", SearchOption.TopDirectoryOnly); - LoggingHelpers.LogToConsole($"{botFiles.Length} bot dump files found"); + LoggingHelpers.LogToConsole($"{botFiles.Length.ToString()} bot dump files found"); // key = bot type // Store bots keyed against their ID so we never get duplicates @@ -153,9 +153,9 @@ public static class BotParser await Task.WhenAll(tasks.ToArray()); stopwatch.Stop(); - LoggingHelpers.LogToConsole($"Cleaned and Parsed: {parsedBotsDict.Count} bots. {totalDupeCount} dupes were ignored. Took {LoggingHelpers.LogTimeTaken(stopwatch.Elapsed.TotalSeconds)} seconds"); return [.. parsedBotsDict.Values]; + LoggingHelpers.LogToConsole($"Cleaned and Parsed: {parsedBotsDict.Count.ToString()} bots. {totalDupeCount.ToString()} dupes were ignored. Took {LoggingHelpers.LogTimeTaken(stopwatch.Elapsed.TotalSeconds)} seconds"); } private static async Task ProcessBotFile( @@ -235,8 +235,8 @@ public static class BotParser if (jItemsToReplace != null && jItemsToReplace.Any()) { - LoggingHelpers.LogToConsole($"file {fileName} has {jItemsToReplace.Count()} json issues, cleaning up.", ConsoleColor.Yellow); foreach (var item in jItemsToReplace) + LoggingHelpers.LogToConsole($"file {fileName} has {jItemsToReplace.Count().ToString()} json issues, cleaning up.", ConsoleColor.Yellow); { var obj = new { x = 1, y = 0, r = 0 }; item.Replace(JToken.FromObject(obj)); -- 2.47.1 From f965d476a12b7e05e62b4c3c439c61935781559e Mon Sep 17 00:00:00 2001 From: Refringe Date: Thu, 14 Nov 2024 12:38:03 -0500 Subject: [PATCH 3/4] Micro-optimizations to Remove Additional Warnings - Reduce LINQ overhead by replacing SingleOrDefault and filtering logic with manual iteration. - Use HashSet and case-insensitive comparisons for faster lookups. Both of these changes resolve a number of HAA0401 warnings: Possible allocation of reference type enumerator; non-ValueType enumerator may result in a heap allocation. --- Generator/BotParser.cs | 54 +++++++++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 16 deletions(-) diff --git a/Generator/BotParser.cs b/Generator/BotParser.cs index a300a92..5875c20 100644 --- a/Generator/BotParser.cs +++ b/Generator/BotParser.cs @@ -42,7 +42,7 @@ public static class BotParser foreach (var filePath in botFiles) { i++; - if (i % 100 == 0) Console.WriteLine($"Processing file {i.ToString()}"); + if (i % 500 == 0) Console.WriteLine($"Processing file {i.ToString()}"); ProcessBotFileSync(baseBots, filePath, parsedBotIds, totalDupeCount); } @@ -84,15 +84,14 @@ public static class BotParser int dupeCount = 0; - List bots = []; + List bots = new List(); try { // Parse the bots inside the json file using (var reader = new StreamReader(filePath)) { var deSerialisedObject = JsonSerializer.Deserialize(reader.ReadToEnd(), serialiserOptions); - - foreach (var botData in deSerialisedObject.data) + foreach (var botData in deSerialisedObject.data.ToList()) { // Bot fucks up something, never allow it in if (botData._id == "6483938c53cc9087c70eae86") @@ -101,10 +100,22 @@ public static class BotParser continue; } - var baseBot = baseBots.SingleOrDefault(bot => bot.botType.ToString().Equals(botData.Info.Settings.Role, StringComparison.OrdinalIgnoreCase)); + var role = botData.Info.Settings.Role; + var botType = Enum.Parse(role, true); + + Bot baseBot = null; + foreach (var bot in baseBots) + { + if (bot.botType == botType) + { + baseBot = bot; + break; + } + } + if (baseBot == null) { - //Console.WriteLine($"Skipping {botData._id} due to unknown role {botData.Info.Settings.Role}"); + Console.WriteLine($"Skipping {botData._id} due to unknown role {botData.Info.Settings.Role}"); continue; } @@ -121,7 +132,7 @@ public static class BotParser } } } - catch (Exception ex) + catch (Exception) { Console.WriteLine($"File parse fucked up: {filePath}"); throw; @@ -142,7 +153,7 @@ public static class BotParser // key = bot type // Store bots keyed against their ID so we never get duplicates var parsedBotsDict = new ConcurrentDictionary(); - + int totalDupeCount = 0; var tasks = new List(); foreach (var filePath in botFiles) @@ -152,10 +163,10 @@ public static class BotParser await Task.WhenAll(tasks.ToArray()); stopwatch.Stop(); - - return [.. parsedBotsDict.Values]; LoggingHelpers.LogToConsole($"Cleaned and Parsed: {parsedBotsDict.Count.ToString()} bots. {totalDupeCount.ToString()} dupes were ignored. Took {LoggingHelpers.LogTimeTaken(stopwatch.Elapsed.TotalSeconds)} seconds"); + + return parsedBotsDict.Values.ToList(); } private static async Task ProcessBotFile( @@ -168,17 +179,27 @@ public static class BotParser int dupeCount = 0; - List bots = []; + List bots = new List(); try { // Parse the bots inside the json file - using (var reader = new StreamReader(filePath)) + using var reader = new StreamReader(filePath); + var deSerialisedObject = await JsonSerializer.DeserializeAsync(reader.BaseStream, serialiserOptions); + + var botTypesLower = new HashSet(botTypes, StringComparer.OrdinalIgnoreCase); + var filteredBots = new List(); + foreach (var botData in deSerialisedObject.data.ToList()) { - var deSerialisedObject = JsonSerializer.Deserialize(reader.ReadToEnd(), serialiserOptions); - bots.AddRange(deSerialisedObject.data.Where(botData => botTypes.Contains(botData.Info.Settings.Role.ToLower()))); + var roleLower = botData.Info.Settings.Role.ToLower(); + if (botTypesLower.Contains(roleLower)) + { + filteredBots.Add(botData); + } } + + bots.AddRange(filteredBots); } - catch (Exception ex) + catch (Exception) { Console.WriteLine($"File parse fucked up: {filePath}"); throw; @@ -235,8 +256,9 @@ public static class BotParser if (jItemsToReplace != null && jItemsToReplace.Any()) { - foreach (var item in jItemsToReplace) LoggingHelpers.LogToConsole($"file {fileName} has {jItemsToReplace.Count().ToString()} json issues, cleaning up.", ConsoleColor.Yellow); + var jItemsToReplaceList = jItemsToReplace.ToList(); + foreach (var item in jItemsToReplaceList) { var obj = new { x = 1, y = 0, r = 0 }; item.Replace(JToken.FromObject(obj)); -- 2.47.1 From 29bec68dec5399e7b4e9c012554e982c95e7a216 Mon Sep 17 00:00:00 2001 From: Refringe Date: Thu, 14 Nov 2024 12:44:58 -0500 Subject: [PATCH 4/4] Updates PMCGenerator .NET Target & JSON Package Version .NET 9 Newtonsoft.Json v13.0.3 --- PMCGenerator/PMCGenerator.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PMCGenerator/PMCGenerator.csproj b/PMCGenerator/PMCGenerator.csproj index 34bca22..63b185c 100644 --- a/PMCGenerator/PMCGenerator.csproj +++ b/PMCGenerator/PMCGenerator.csproj @@ -2,11 +2,11 @@ Exe - net6.0 + net9.0 - + -- 2.47.1