From 44e08cb1504843be88c2ef131f01b7aac0760384 Mon Sep 17 00:00:00 2001 From: Justin Webb Date: Fri, 5 Dec 2025 16:29:42 +0100 Subject: [PATCH 1/6] Fix automatic handling of required input_path argument. --- ServerCodeExciser/ServerCodeExciser.cs | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/ServerCodeExciser/ServerCodeExciser.cs b/ServerCodeExciser/ServerCodeExciser.cs index 7e2e5f4..80adf5e 100644 --- a/ServerCodeExciser/ServerCodeExciser.cs +++ b/ServerCodeExciser/ServerCodeExciser.cs @@ -61,19 +61,9 @@ public sealed class Settings : CommandSettings [Description("Ensure that all files can be analyzed without syntactic or lexicographical errors.")] public bool StrictMode { get; init; } - [CommandArgument(0, "[INPUT]")] + [CommandArgument(0, "")] [Description("The input folder to excise.")] - public string InputPath { get; init; } = string.Empty; - - public override ValidationResult Validate() - { - if (InputPath.Length <= 0) - { - return ValidationResult.Error("Must provide at least one input path!"); - } - - return base.Validate(); - } + public string? InputPath { get; init; } } class RootPaths @@ -113,7 +103,7 @@ public override int Execute([NotNull] CommandContext context, [NotNull] Settings return (int)EExciserReturnValues.InternalExcisionError; } } - else if(Directory.Exists(settings.InputPath)) + else if (Directory.Exists(settings.InputPath)) { parameters.InputPaths.Add(settings.InputPath); } @@ -152,14 +142,7 @@ public class ServerCodeExciser { public static int Main(string[] args) { - if (args.Length < 1) - { - Console.Error.WriteLine("You must provide an input path to read input files from as the first argument."); - return (int)EExciserReturnValues.BadInputPath; - } - - var app = new CommandApp(); - return app.Run(args); + return new CommandApp().Run(args); } } } From f0c90cb79ab049074b7f4cae2f62a3ada2de7b3c Mon Sep 17 00:00:00 2001 From: Justin Webb Date: Fri, 5 Dec 2025 16:32:42 +0100 Subject: [PATCH 2/6] Fix inconsistent namespace. --- ServerCodeExciser/ServerCodeExciser.cs | 2 +- ServerCodeExciser/ServerCodeExcisionProcessor.cs | 2 +- ServerCodeExciserTest/ExcisionIntegrationTests.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ServerCodeExciser/ServerCodeExciser.cs b/ServerCodeExciser/ServerCodeExciser.cs index 80adf5e..420097d 100644 --- a/ServerCodeExciser/ServerCodeExciser.cs +++ b/ServerCodeExciser/ServerCodeExciser.cs @@ -9,7 +9,7 @@ using System.Text.Json.Serialization; using UnrealAngelscriptServerCodeExcision; -namespace ServerCodeExcision +namespace ServerCodeExciser { internal sealed class ServerCodeExciserCommand : Command { diff --git a/ServerCodeExciser/ServerCodeExcisionProcessor.cs b/ServerCodeExciser/ServerCodeExcisionProcessor.cs index dddbc48..6fe2e6b 100644 --- a/ServerCodeExciser/ServerCodeExcisionProcessor.cs +++ b/ServerCodeExciser/ServerCodeExcisionProcessor.cs @@ -8,7 +8,7 @@ using System.Text; using System.Text.RegularExpressions; -namespace ServerCodeExcision +namespace ServerCodeExciser { public class ServerCodeExcisionParameters { diff --git a/ServerCodeExciserTest/ExcisionIntegrationTests.cs b/ServerCodeExciserTest/ExcisionIntegrationTests.cs index 6c8b00e..ea7a8e4 100644 --- a/ServerCodeExciserTest/ExcisionIntegrationTests.cs +++ b/ServerCodeExciserTest/ExcisionIntegrationTests.cs @@ -1,4 +1,4 @@ -using ServerCodeExcision; +using ServerCodeExciser; using ServerCodeExcisionCommon; using Spectre.Console; using System; From ab2739f0a4af994febec53b053c6ebd7c7a18daf Mon Sep 17 00:00:00 2001 From: Justin Webb Date: Fri, 5 Dec 2025 16:40:31 +0100 Subject: [PATCH 3/6] Fix --fullyexcise description. --- ServerCodeExciser/ServerCodeExciser.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ServerCodeExciser/ServerCodeExciser.cs b/ServerCodeExciser/ServerCodeExciser.cs index 420097d..97715f6 100644 --- a/ServerCodeExciser/ServerCodeExciser.cs +++ b/ServerCodeExciser/ServerCodeExciser.cs @@ -28,9 +28,9 @@ public sealed class Settings : CommandSettings [CommandOption("-f|--fullyexcise ")] [Description("If this switch is specified, the next argument should be a string containing regex entries." + - "If any of these regexes matches the relative path of any file to be processed, the entire file will be excised." + - "You can specify more than one entry by separating them with three pipes, eg: " + - "Characters /Paul/.*|||Weapons/Rife.as")] + "If any of these regexes matches the relative path of any file to be processed, the entire file will be excised." + + "You can specify more than one entry by separating them with three pipes, eg: " + + "Characters/Paul/.*|||Weapons/Rife.as")] public string? FullExcisionRegexString { get; init; } [CommandOption("-s|--dontskip")] From e89a1fefd495c059bdbd80de639236d4adaa9405 Mon Sep 17 00:00:00 2001 From: Justin Webb Date: Fri, 5 Dec 2025 16:40:52 +0100 Subject: [PATCH 4/6] Fix default excision ratio. --- ServerCodeExciser/ServerCodeExciser.cs | 7 ++----- ServerCodeExciser/ServerCodeExcisionProcessor.cs | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/ServerCodeExciser/ServerCodeExciser.cs b/ServerCodeExciser/ServerCodeExciser.cs index 97715f6..d566762 100644 --- a/ServerCodeExciser/ServerCodeExciser.cs +++ b/ServerCodeExciser/ServerCodeExciser.cs @@ -39,7 +39,7 @@ public sealed class Settings : CommandSettings [CommandOption("-m|--minratio")] [Description("Specify a ratio in percent as the next argument. If the excised % of code is less than this ratio, an error will be thrown. Good to detect catastrophic changes in excision performance.")] - public int? RequiredExcisionRatio { get; init; } = -1; + public int RequiredExcisionRatio { get; init; } = 0; [CommandOption("-t|--funcstats")] [Description("Outputs function stats instead of file stats. This is more accurate, but a lot slower, since it has to parse every file.")] @@ -84,10 +84,7 @@ public override int Execute([NotNull] CommandContext context, [NotNull] Settings parameters.StrictMode = settings.StrictMode; parameters.UseFunctionStats = settings.UseFunctionStats; parameters.DontSkip = settings.DontSkip; - if (settings.RequiredExcisionRatio.HasValue) - { - parameters.RequiredExcisionRatio = settings.RequiredExcisionRatio.Value / 100.0f; - } + parameters.RequiredExcisionRatio = settings.RequiredExcisionRatio / 100.0f; if (File.Exists(settings.InputPath)) { diff --git a/ServerCodeExciser/ServerCodeExcisionProcessor.cs b/ServerCodeExciser/ServerCodeExcisionProcessor.cs index 6fe2e6b..f4967f2 100644 --- a/ServerCodeExciser/ServerCodeExcisionProcessor.cs +++ b/ServerCodeExciser/ServerCodeExcisionProcessor.cs @@ -22,7 +22,7 @@ public class ServerCodeExcisionParameters public bool StrictMode { get; set; } = false; public bool UseFunctionStats { get; set; } = false; public bool DontSkip { get; set; } = false; - public float RequiredExcisionRatio { get; set; } = -1.0f; + public float RequiredExcisionRatio { get; set; } = 0.0f; public EExcisionLanguage ExcisionLanguage { get; set; } = EExcisionLanguage.Unknown; } From a185be32a871175c227ce9398fb6f23d90b01b9d Mon Sep 17 00:00:00 2001 From: Justin Webb Date: Fri, 5 Dec 2025 16:45:10 +0100 Subject: [PATCH 5/6] Fix string testing anti-pattern. --- ServerCodeExciser/ServerCodeExcisionProcessor.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ServerCodeExciser/ServerCodeExcisionProcessor.cs b/ServerCodeExciser/ServerCodeExcisionProcessor.cs index f4967f2..aa0d6d1 100644 --- a/ServerCodeExciser/ServerCodeExcisionProcessor.cs +++ b/ServerCodeExciser/ServerCodeExcisionProcessor.cs @@ -37,7 +37,7 @@ public ServerCodeExcisionProcessor(ServerCodeExcisionParameters parameters) _parameters = parameters; _functionExciseRegexes = new List(); - if (_parameters.ExciseAllFunctionsRegexString != "") + if (!string.IsNullOrEmpty(_parameters.ExciseAllFunctionsRegexString)) { var allFunctionExciseRegexStrings = _parameters.ExciseAllFunctionsRegexString.Split("|||"); foreach (var regexString in allFunctionExciseRegexStrings) @@ -48,7 +48,7 @@ public ServerCodeExcisionProcessor(ServerCodeExcisionParameters parameters) } _fullyExciseRegexes = new List(); - if (_parameters.FullExcisionRegexString != "") + if (!string.IsNullOrEmpty(_parameters.FullExcisionRegexString)) { var fullyExciseRegexStrings = _parameters.FullExcisionRegexString.Split("|||"); foreach (var regexString in fullyExciseRegexStrings) From add8734a8df7be17d2042d4604f359cc65336db0 Mon Sep 17 00:00:00 2001 From: Justin Webb Date: Mon, 8 Dec 2025 10:02:59 +0100 Subject: [PATCH 6/6] Add source-level excision time reporting. --- .../ServerCodeExcisionProcessor.cs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/ServerCodeExciser/ServerCodeExcisionProcessor.cs b/ServerCodeExciser/ServerCodeExcisionProcessor.cs index aa0d6d1..9236ea4 100644 --- a/ServerCodeExciser/ServerCodeExcisionProcessor.cs +++ b/ServerCodeExciser/ServerCodeExcisionProcessor.cs @@ -1,8 +1,8 @@ using Antlr4.Runtime; using ServerCodeExcisionCommon; using System; -using System.Collections; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Linq; using System.Text; @@ -61,7 +61,7 @@ public ServerCodeExcisionProcessor(ServerCodeExcisionParameters parameters) public EExciserReturnValues ExciseServerCode(string filePattern, IServerCodeExcisionLanguage excisionLanguage) { - var startTime = DateTime.UtcNow; + var globalStopwatch = Stopwatch.StartNew(); var globalStats = new ExcisionStats(); var options = new EnumerationOptions(); @@ -107,16 +107,19 @@ public EExciserReturnValues ExciseServerCode(string filePattern, IServerCodeExci try { + var stopwatch = Stopwatch.StartNew(); var stats = ProcessCodeFile(fileName, inputPath, excisionMode, excisionLanguage); + stopwatch.Stop(); + if (stats.CharactersExcised > 0) { System.Diagnostics.Debug.Assert(stats.TotalNrCharacters > 0, "Something is terribly wrong. We have excised characters, but no total characters..?"); var excisionRatio = (float)stats.CharactersExcised / (float)stats.TotalNrCharacters * 100.0f; - Console.WriteLine("Excised {0:0.00}% of server only code in file ({1}/{2}): {3}", excisionRatio, fileIdx + 1, allFiles.Length, fileName); + Console.WriteLine($"[{fileIdx + 1}/{allFiles.Length}] Excised {excisionRatio:0.00}% of server only code in file (took {stopwatch.Elapsed.TotalMilliseconds:0.0}ms): {fileName}"); } else { - Console.WriteLine("No server only code found in file ({0}/{1}): {2}", fileIdx + 1, allFiles.Length, fileName); + Console.WriteLine($"[{fileIdx + 1}/{allFiles.Length}] No server only code found in file: {fileName}"); } globalStats.CharactersExcised += stats.CharactersExcised; @@ -124,13 +127,13 @@ public EExciserReturnValues ExciseServerCode(string filePattern, IServerCodeExci } catch (Exception) { - Console.WriteLine("Failed to parse ({0}/{1}): {2}", fileIdx + 1, allFiles.Length, fileName); + Console.Error.WriteLine($"[{fileIdx + 1}/{allFiles.Length}] Failed to parse: {fileName}"); throw; } } } - var endTime = DateTime.UtcNow; + globalStopwatch.Stop(); // In verification mode error codes reverse the normal behavior of the exciser. // Modifications required -> error @@ -157,8 +160,7 @@ public EExciserReturnValues ExciseServerCode(string filePattern, IServerCodeExci Console.WriteLine("Excised {0:0.00}% ({1}/{2} characters) of server only code from the script files.", totalExcisionRatio, globalStats.CharactersExcised, globalStats.TotalNrCharacters); - var timeTaken = endTime - startTime; - Console.WriteLine("Excision took {0:0} hours, {1:0} minutes and {2:0.0} seconds.\n\n", timeTaken.Hours, timeTaken.Minutes, timeTaken.Seconds); + Console.WriteLine($"Excision took {globalStopwatch.Elapsed.TotalSeconds:0.0}s."); if (_parameters.RequiredExcisionRatio > 0.0f && totalExcisionRatio < _parameters.RequiredExcisionRatio) {