From 6a710995701d578727455eb81016d22b05221189 Mon Sep 17 00:00:00 2001 From: r007 Date: Mon, 20 May 2024 15:03:16 +0200 Subject: [PATCH 1/6] default to emitting debug logs as they get filtered out on msbuild level --- NetcodePatcher.MSBuild.Tasks/NetcodePatchTask.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NetcodePatcher.MSBuild.Tasks/NetcodePatchTask.cs b/NetcodePatcher.MSBuild.Tasks/NetcodePatchTask.cs index 14d2b5d..bccaf65 100644 --- a/NetcodePatcher.MSBuild.Tasks/NetcodePatchTask.cs +++ b/NetcodePatcher.MSBuild.Tasks/NetcodePatchTask.cs @@ -34,7 +34,7 @@ public class NetcodePatchTask : Task public override bool Execute() { Serilog.Log.Logger = new LoggerConfiguration() - .MinimumLevel.Information() + .MinimumLevel.Debug() .WriteTo.MSBuildTask(this) .CreateLogger(); From c0941c4ef733deacbf7c34421923c427219be65f Mon Sep 17 00:00:00 2001 From: r007 Date: Mon, 20 May 2024 15:43:40 +0200 Subject: [PATCH 2/6] try to resolve shared dependency from path before deferring to system --- NetcodePatcher.Tools.Common/PatcherLoadContext.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/NetcodePatcher.Tools.Common/PatcherLoadContext.cs b/NetcodePatcher.Tools.Common/PatcherLoadContext.cs index bcb206f..d60bc0b 100644 --- a/NetcodePatcher.Tools.Common/PatcherLoadContext.cs +++ b/NetcodePatcher.Tools.Common/PatcherLoadContext.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Reflection; using System.Runtime.Loader; +using Serilog; namespace NetcodePatcher.Tools.Common; @@ -27,7 +28,19 @@ public PatcherLoadContext(string name, PatcherConfiguration configuration) : bas if (assemblyName.Name is null) return null; if (SharedDependencyAssemblyNames.Contains(assemblyName.Name)) - return Default.LoadFromAssemblyName(assemblyName); + { + string? sharedPath = ResolveAssemblyToPath(assemblyName); + if (sharedPath is null) + { + Log.Debug("Shared dependency {SharedName} not found in {CommonDir} or {SharedDir}, trying to load from system", assemblyName, _configuration.PatcherCommonAssemblyDir, _configuration.PatcherNetcodeSpecificAssemblyDir); + return Default.LoadFromAssemblyName(assemblyName); + } + else + { + Log.Debug("Shared Dependency {SharedName} loading from {Directory}", assemblyName, sharedPath); + return LoadFromAssemblyPath(sharedPath); + } + } string? assemblyPath = ResolveAssemblyToPath(assemblyName); if (assemblyPath is null) return null; From cc8e5f6584b1c3514f2fad6a5b15fab201c2423c Mon Sep 17 00:00:00 2001 From: r007 Date: Sat, 22 Jun 2024 18:32:46 +0200 Subject: [PATCH 3/6] remove redundant else block after early return --- NetcodePatcher.Tools.Common/PatcherLoadContext.cs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/NetcodePatcher.Tools.Common/PatcherLoadContext.cs b/NetcodePatcher.Tools.Common/PatcherLoadContext.cs index d60bc0b..5f8b202 100644 --- a/NetcodePatcher.Tools.Common/PatcherLoadContext.cs +++ b/NetcodePatcher.Tools.Common/PatcherLoadContext.cs @@ -35,11 +35,8 @@ public PatcherLoadContext(string name, PatcherConfiguration configuration) : bas Log.Debug("Shared dependency {SharedName} not found in {CommonDir} or {SharedDir}, trying to load from system", assemblyName, _configuration.PatcherCommonAssemblyDir, _configuration.PatcherNetcodeSpecificAssemblyDir); return Default.LoadFromAssemblyName(assemblyName); } - else - { - Log.Debug("Shared Dependency {SharedName} loading from {Directory}", assemblyName, sharedPath); - return LoadFromAssemblyPath(sharedPath); - } + Log.Debug("Shared Dependency {SharedName} loading from {Directory}", assemblyName, sharedPath); + return LoadFromAssemblyPath(sharedPath); } string? assemblyPath = ResolveAssemblyToPath(assemblyName); From eb1a77891d86f6a130a70cbd838279c9437fbee5 Mon Sep 17 00:00:00 2001 From: r007 Date: Sat, 22 Jun 2024 18:33:57 +0200 Subject: [PATCH 4/6] load shared assembly into Default AssemblyLoadContext --- NetcodePatcher.Tools.Common/PatcherLoadContext.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NetcodePatcher.Tools.Common/PatcherLoadContext.cs b/NetcodePatcher.Tools.Common/PatcherLoadContext.cs index 5f8b202..3e89798 100644 --- a/NetcodePatcher.Tools.Common/PatcherLoadContext.cs +++ b/NetcodePatcher.Tools.Common/PatcherLoadContext.cs @@ -36,7 +36,7 @@ public PatcherLoadContext(string name, PatcherConfiguration configuration) : bas return Default.LoadFromAssemblyName(assemblyName); } Log.Debug("Shared Dependency {SharedName} loading from {Directory}", assemblyName, sharedPath); - return LoadFromAssemblyPath(sharedPath); + return Default.LoadFromAssemblyPath(sharedPath); } string? assemblyPath = ResolveAssemblyToPath(assemblyName); From 9512f15e1219565b2dcb3e36ce7d198256bad489 Mon Sep 17 00:00:00 2001 From: r007 Date: Sat, 22 Jun 2024 19:33:23 +0200 Subject: [PATCH 5/6] exit early when there are no targets to patch --- NetcodePatcher.MSBuild.Tasks/NetcodePatchTask.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/NetcodePatcher.MSBuild.Tasks/NetcodePatchTask.cs b/NetcodePatcher.MSBuild.Tasks/NetcodePatchTask.cs index bccaf65..93c9e49 100644 --- a/NetcodePatcher.MSBuild.Tasks/NetcodePatchTask.cs +++ b/NetcodePatcher.MSBuild.Tasks/NetcodePatchTask.cs @@ -43,6 +43,12 @@ public override bool Execute() .InformationalVersion; Serilog.Log.Information("Initializing NetcodePatcher v{Version:l}", toolVersion); + if (Patch.Length < 1) + { + Serilog.Log.Information("No targets specified for Netcode patching. NetcodePatcher done."); + return true; + } + var noOverwrite = false; if (!string.IsNullOrEmpty(NoOverwrite)) { From 31788ba8162925994dd93e5489bf96617107cdc3 Mon Sep 17 00:00:00 2001 From: r007 Date: Sat, 22 Jun 2024 19:33:43 +0200 Subject: [PATCH 6/6] add a message for each file that is being processed --- NetcodePatcher.MSBuild.Tasks/NetcodePatchTask.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/NetcodePatcher.MSBuild.Tasks/NetcodePatchTask.cs b/NetcodePatcher.MSBuild.Tasks/NetcodePatchTask.cs index 93c9e49..3246341 100644 --- a/NetcodePatcher.MSBuild.Tasks/NetcodePatchTask.cs +++ b/NetcodePatcher.MSBuild.Tasks/NetcodePatchTask.cs @@ -99,6 +99,7 @@ void RunPatch(ITaskItem patchSpecifier) outputPath = Path.Combine(outputPath, noOverwrite ? $"{Path.GetFileNameWithoutExtension(pluginAssembly.Name)}_patched{Path.GetExtension(pluginAssembly.Name)}" : pluginAssembly.Name); } + Serilog.Log.Information("Processing : {input}", inputPath); patchMethod.Invoke(null, [inputPath, outputPath, ReferenceAssemblyPaths.Select(info => info.ItemSpec).ToArray()]); }