diff --git a/src/BUTR.CrashReport.Bannerlord.Parser/CrashReportParser.cs b/src/BUTR.CrashReport.Bannerlord.Parser/CrashReportParser.cs index 8b6bcfb..e8a7d6d 100644 --- a/src/BUTR.CrashReport.Bannerlord.Parser/CrashReportParser.cs +++ b/src/BUTR.CrashReport.Bannerlord.Parser/CrashReportParser.cs @@ -58,7 +58,7 @@ private static IList GetEnhancedStacktrace(ReadOnl node = enhancedStacktraceDoc.DocumentNode; } - return node.SelectSingleNode("descendant::div[@id=\"enhanced-stacktrace\"]/ul")?.ChildNodes.Where(cn => cn.Name == "li").Select(ParseEnhancedStacktrace).ToArray() ?? Array.Empty(); + return node.SelectSingleNode("descendant::div[@id=\"enhanced-stacktrace\"]/ul")?.ChildNodes.Where(cn => cn.Name == "li").Select(ParseEnhancedStacktrace).ToArray() ?? []; } private static HtmlDocument Create(ref string content) @@ -220,12 +220,12 @@ private static CrashReportModel ParseLegacyHtmlInternal(byte version, HtmlDocume var node = document.DocumentNode; var id = node.SelectSingleNode("descendant::report")?.Attributes?["id"]?.Value ?? string.Empty; var gameVersion = node.SelectSingleNode("descendant::game")?.Attributes?["version"]?.Value ?? string.Empty; - var installedModules = node.SelectSingleNode("descendant::div[@id=\"installed-modules\"]/ul")?.ChildNodes.Where(cn => cn.Name == "li").Select(x => ParseModule(version, x)).DistinctBy(x => x.Id).ToArray() ?? Array.Empty(); + var installedModules = node.SelectSingleNode("descendant::div[@id=\"installed-modules\"]/ul")?.ChildNodes.Where(cn => cn.Name == "li").Select(x => ParseModule(version, x)).DistinctBy(x => x.Id).ToArray() ?? []; var exception = ParseExceptions(node.SelectSingleNode("descendant::div[@id=\"exception\"]"), installedModules); - var involvedModules = node.SelectSingleNode("descendant::div[@id=\"involved-modules\"]/ul")?.ChildNodes.Where(cn => cn.Name == "li").SelectMany(ParseInvolvedModule).ToArray() ?? Array.Empty(); + var involvedModules = node.SelectSingleNode("descendant::div[@id=\"involved-modules\"]/ul")?.ChildNodes.Where(cn => cn.Name == "li").SelectMany(ParseInvolvedModule).ToArray() ?? []; var enhancedStacktrace = GetEnhancedStacktrace(content.AsSpan(), version, node); - var assemblies = node.SelectSingleNode("descendant::div[@id=\"assemblies\"]/ul")?.ChildNodes.Where(cn => cn.Name == "li").Select(x => ParseAssembly(x, installedModules)).ToArray() ?? Array.Empty(); + var assemblies = node.SelectSingleNode("descendant::div[@id=\"assemblies\"]/ul")?.ChildNodes.Where(cn => cn.Name == "li").Select(x => ParseAssembly(x, installedModules)).ToArray() ?? []; var harmonyPatches = node.SelectSingleNode("descendant::div[@id=\"harmony-patches\"]/ul").ChildNodes.Where(cn => cn.Name == "li").Select(ParseHarmonyPatch).ToArray(); var launcherType = node.SelectSingleNode("descendant::launcher")?.Attributes?["type"]?.Value ?? string.Empty; var launcherVersion = node.SelectSingleNode("descendant::launcher")?.Attributes?["version"]?.Value ?? string.Empty; @@ -452,7 +452,7 @@ private static EnhancedStacktraceFrameModel ParseEnhancedStacktrace(HtmlNode nod AdditionalMetadata = executingMethod.AdditionalMetadata, }, OriginalMethod = null, - PatchMethods = methods.Count == 1 ? Array.Empty() : methods.Take(methods.Count - 1).ToArray(), + PatchMethods = methods.Count == 1 ? [] : methods.Take(methods.Count - 1).ToArray(), MethodFromStackframeIssue = false, AdditionalMetadata = Array.Empty(), }; @@ -517,17 +517,17 @@ static HarmonyPatchModel ParsePatch(HtmlNode node, HarmonyPatchType type) Namespace = split.FirstOrDefault(x => x.StartsWith("Namespace: "))?.Split(':')[1] ?? string.Empty, Index = split.FirstOrDefault(x => x.StartsWith("Index: "))?.Split(':')[1] is { } strIndex && int.TryParse(strIndex, out var index) ? index : 0, Priority = split.FirstOrDefault(x => x.StartsWith("Priority: "))?.Split(':')[1] is { } strPriority && int.TryParse(strPriority, out var piority) ? piority : 400, - Before = split.FirstOrDefault(x => x.StartsWith("Before: "))?.Split(':')[1].Split(',') ?? Array.Empty(), - After = split.FirstOrDefault(x => x.StartsWith("After: "))?.Split(':')[1].Split(',') ?? Array.Empty(), + Before = split.FirstOrDefault(x => x.StartsWith("Before: "))?.Split(':')[1].Split(',') ?? [], + After = split.FirstOrDefault(x => x.StartsWith("After: "))?.Split(':')[1].Split(',') ?? [], AdditionalMetadata = Array.Empty(), }; } var originalMethodFullName = node.ChildNodes.Skip(0).First().InnerText.Trim('\n'); - var prefixes = node.ChildNodes.FirstOrDefault(x => x.InnerText?.Contains("Prefixes") == true)?.SelectSingleNode("descendant::ul/li")?.ChildNodes.Select(x => ParsePatch(x, HarmonyPatchType.Prefix)).ToArray() ?? Array.Empty(); - var postfixes = node.ChildNodes.FirstOrDefault(x => x.InnerText?.Contains("Postfixes") == true)?.SelectSingleNode("descendant::ul/li")?.ChildNodes.Select(x => ParsePatch(x, HarmonyPatchType.Postfix)).ToArray() ?? Array.Empty(); - var transpilers = node.ChildNodes.FirstOrDefault(x => x.InnerText?.Contains("Transpilers") == true)?.SelectSingleNode("descendant::ul/li")?.ChildNodes.Select(x => ParsePatch(x, HarmonyPatchType.Transpiler)).ToArray() ?? Array.Empty(); - var finalizers = node.ChildNodes.FirstOrDefault(x => x.InnerText?.Contains("Finalizers") == true)?.SelectSingleNode("descendant::ul/li")?.ChildNodes.Select(x => ParsePatch(x, HarmonyPatchType.Finalizer)).ToArray() ?? Array.Empty(); + var prefixes = node.ChildNodes.FirstOrDefault(x => x.InnerText?.Contains("Prefixes") == true)?.SelectSingleNode("descendant::ul/li")?.ChildNodes.Select(x => ParsePatch(x, HarmonyPatchType.Prefix)).ToArray() ?? []; + var postfixes = node.ChildNodes.FirstOrDefault(x => x.InnerText?.Contains("Postfixes") == true)?.SelectSingleNode("descendant::ul/li")?.ChildNodes.Select(x => ParsePatch(x, HarmonyPatchType.Postfix)).ToArray() ?? []; + var transpilers = node.ChildNodes.FirstOrDefault(x => x.InnerText?.Contains("Transpilers") == true)?.SelectSingleNode("descendant::ul/li")?.ChildNodes.Select(x => ParsePatch(x, HarmonyPatchType.Transpiler)).ToArray() ?? []; + var finalizers = node.ChildNodes.FirstOrDefault(x => x.InnerText?.Contains("Finalizers") == true)?.SelectSingleNode("descendant::ul/li")?.ChildNodes.Select(x => ParsePatch(x, HarmonyPatchType.Finalizer)).ToArray() ?? []; var harmonyPatchModel = new HarmonyPatchesModel { OriginalMethodName = originalMethodFullName.Split('.').Last(), diff --git a/src/BUTR.CrashReport.Bannerlord.Tool/Program.cs b/src/BUTR.CrashReport.Bannerlord.Tool/Program.cs index e8d0dae..dba2829 100644 --- a/src/BUTR.CrashReport.Bannerlord.Tool/Program.cs +++ b/src/BUTR.CrashReport.Bannerlord.Tool/Program.cs @@ -64,7 +64,7 @@ public static async Task Main(string[] args) { Converters = { new JsonStringEnumConverter() } })!; - var logs = logsStream is not null ? JsonSerializer.Deserialize(logsStream)! : Array.Empty(); + var logs = logsStream is not null ? JsonSerializer.Deserialize(logsStream)! : []; var html = CrashReportHtml.AddData(CrashReportHtml.Build(crashReport, logs), crashReportJson, minidump, saveFile, screenshot); diff --git a/src/BUTR.CrashReport.Decompilers/Utils/MethodDecompiler.AsmResolver.cs b/src/BUTR.CrashReport.Decompilers/Utils/MethodDecompiler.AsmResolver.cs index cfe5c94..e620ac2 100644 --- a/src/BUTR.CrashReport.Decompilers/Utils/MethodDecompiler.AsmResolver.cs +++ b/src/BUTR.CrashReport.Decompilers/Utils/MethodDecompiler.AsmResolver.cs @@ -47,13 +47,13 @@ private static bool TryGetMethodDefinition(MethodBase method, [NotNullWhen(true) /// public static string[] DecompileILCode(MethodBase? method) { - static string[] ToLines(CilInstructionCollection? instructions) => instructions?.Select(x => x.ToString()).ToArray() ?? Array.Empty(); + static string[] ToLines(CilInstructionCollection? instructions) => instructions?.Select(x => x.ToString()).ToArray() ?? []; - if (method is null) return Array.Empty(); + if (method is null) return []; try { - if (!TryCopyMethod(method, out var stream, out var methodHandle)) return Array.Empty(); + if (!TryCopyMethod(method, out var stream, out var methodHandle)) return []; using var _ = stream; using var ms = stream as MemoryStream ?? new MemoryStream(); @@ -70,7 +70,7 @@ public static string[] DecompileILCode(MethodBase? method) try { - if (!TryGetMethodDefinition(method, out _, out var methodDefinition)) return Array.Empty(); + if (!TryGetMethodDefinition(method, out _, out var methodDefinition)) return []; return ToLines(methodDefinition.CilMethodBody?.Instructions); } @@ -79,6 +79,6 @@ public static string[] DecompileILCode(MethodBase? method) Trace.TraceError(e.ToString()); } - return Array.Empty(); + return []; } } \ No newline at end of file diff --git a/src/BUTR.CrashReport.Decompilers/Utils/MethodDecompiler.ILSpy.cs b/src/BUTR.CrashReport.Decompilers/Utils/MethodDecompiler.ILSpy.cs index f5a0448..3f71141 100644 --- a/src/BUTR.CrashReport.Decompilers/Utils/MethodDecompiler.ILSpy.cs +++ b/src/BUTR.CrashReport.Decompilers/Utils/MethodDecompiler.ILSpy.cs @@ -22,11 +22,11 @@ partial class MethodDecompiler /// public static string[] DecompileILCodeExtended(MethodBase? method) { - if (method is null) return Array.Empty(); + if (method is null) return []; try { - if (!TryCopyMethod(method, out var stream, out var methodHandle)) return Array.Empty(); + if (!TryCopyMethod(method, out var stream, out var methodHandle)) return []; using var _ = stream; using var peFile = new PEFile("Assembly", stream); @@ -42,7 +42,7 @@ public static string[] DecompileILCodeExtended(MethodBase? method) Trace.TraceError(e.ToString()); } - return Array.Empty(); + return []; } /// @@ -50,11 +50,11 @@ public static string[] DecompileILCodeExtended(MethodBase? method) /// public static string[] DecompileILWithCSharpCode(MethodBase? method) { - if (method is null) return Array.Empty(); + if (method is null) return []; try { - if (!TryCopyMethod(method, out var stream, out var methodHandle)) return Array.Empty(); + if (!TryCopyMethod(method, out var stream, out var methodHandle)) return []; using var _ = stream; using var peFile = new PEFile("Assembly", stream); @@ -70,7 +70,7 @@ public static string[] DecompileILWithCSharpCode(MethodBase? method) Trace.TraceError(e.ToString()); } - return Array.Empty(); + return []; } /// @@ -78,11 +78,11 @@ public static string[] DecompileILWithCSharpCode(MethodBase? method) /// public static string[] DecompileCSharpCode(MethodBase? method) { - if (method is null) return Array.Empty(); + if (method is null) return []; try { - if (!TryCopyMethod(method, out var stream, out var methodHandle)) return Array.Empty(); + if (!TryCopyMethod(method, out var stream, out var methodHandle)) return []; using var _ = stream; using var peFile = new PEFile("Assembly", stream); @@ -108,6 +108,6 @@ public static string[] DecompileCSharpCode(MethodBase? method) Trace.TraceError(e.ToString()); } - return Array.Empty(); + return []; } } \ No newline at end of file diff --git a/src/BUTR.CrashReport.Decompilers/Utils/MethodDecompiler.Iced.cs b/src/BUTR.CrashReport.Decompilers/Utils/MethodDecompiler.Iced.cs index 329444e..7062007 100644 --- a/src/BUTR.CrashReport.Decompilers/Utils/MethodDecompiler.Iced.cs +++ b/src/BUTR.CrashReport.Decompilers/Utils/MethodDecompiler.Iced.cs @@ -51,8 +51,8 @@ static IEnumerable GetLines(IntPtr nativeCodePtr, int nativeILOffset) } } - if (nativeCodePtr == IntPtr.Zero) return Array.Empty(); - if (nativeILOffset == StackFrame.OFFSET_UNKNOWN) return Array.Empty(); + if (nativeCodePtr == IntPtr.Zero) return []; + if (nativeILOffset == StackFrame.OFFSET_UNKNOWN) return []; try { @@ -63,6 +63,6 @@ static IEnumerable GetLines(IntPtr nativeCodePtr, int nativeILOffset) Trace.TraceError(e.ToString()); } - return Array.Empty(); + return []; } } \ No newline at end of file diff --git a/src/BUTR.CrashReport.Decompilers/Utils/ReferenceImporter.cs b/src/BUTR.CrashReport.Decompilers/Utils/ReferenceImporter.cs index 1bb23a4..8ef92b8 100644 --- a/src/BUTR.CrashReport.Decompilers/Utils/ReferenceImporter.cs +++ b/src/BUTR.CrashReport.Decompilers/Utils/ReferenceImporter.cs @@ -81,6 +81,6 @@ public static Dictionary GetImpor Trace.TraceError(e.ToString()); } - return Array.Empty(); + return []; }); } \ No newline at end of file diff --git a/src/BUTR.CrashReport.Models/MethodHarmonyPatch.cs b/src/BUTR.CrashReport.Models/MethodHarmonyPatch.cs deleted file mode 100644 index f1896f7..0000000 --- a/src/BUTR.CrashReport.Models/MethodHarmonyPatch.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System.Diagnostics.CodeAnalysis; - -namespace BUTR.CrashReport.Models; - -/// -/// Represents a Harmony patch method. -/// -public sealed record MethodHarmonyPatch : MethodSimple -{ - /// - /// The type of the patch. - /// - public required HarmonyPatchType PatchType { get; set; } - - /// - /// Main constructor - /// - public MethodHarmonyPatch() { } - - /// - /// The copy constructor - /// - [SetsRequiredMembers] - public MethodHarmonyPatch(MethodSimple methodSimple, HarmonyPatchType patchType) - { - AssemblyId = methodSimple.AssemblyId; - ModuleId = methodSimple.ModuleId; - LoaderPluginId = methodSimple.LoaderPluginId; - MethodDeclaredTypeName = methodSimple.MethodDeclaredTypeName; - MethodName = methodSimple.MethodName; - MethodFullDescription = methodSimple.MethodFullDescription; - MethodParameters = methodSimple.MethodParameters; - ILInstructions = methodSimple.ILInstructions; - CSharpILMixedInstructions = methodSimple.CSharpILMixedInstructions; - CSharpInstructions = methodSimple.CSharpInstructions; - AdditionalMetadata = methodSimple.AdditionalMetadata; - PatchType = patchType; - } - - /// - public bool Equals(MethodHarmonyPatch? other) - { - if (ReferenceEquals(null, other)) return false; - if (ReferenceEquals(this, other)) return true; - return base.Equals(other) && PatchType == other.PatchType; - } - - /// - public override int GetHashCode() - { - unchecked - { - return (base.GetHashCode() * 397) ^ (int) PatchType; - } - } -} \ No newline at end of file diff --git a/src/BUTR.CrashReport.Models/Utils/AssemblyUtils.cs b/src/BUTR.CrashReport.Models/Utils/AssemblyUtils.cs index fd37984..2858e18 100644 --- a/src/BUTR.CrashReport.Models/Utils/AssemblyUtils.cs +++ b/src/BUTR.CrashReport.Models/Utils/AssemblyUtils.cs @@ -14,5 +14,5 @@ public static class AssemblyUtils /// The public key token. /// The public key token as string. public static string PublicKeyAsString(byte[]? publicKeyToken) => - string.Join(string.Empty, Array.ConvertAll(publicKeyToken ?? new byte[0], x => x.ToString("x2", CultureInfo.InvariantCulture))); + string.Join(string.Empty, Array.ConvertAll(publicKeyToken ?? [], x => x.ToString("x2", CultureInfo.InvariantCulture))); } \ No newline at end of file diff --git a/src/BUTR.CrashReport.Renderer.Html/CrashReportHtml.Html.cs b/src/BUTR.CrashReport.Renderer.Html/CrashReportHtml.Html.cs index bf66c71..1faf918 100644 --- a/src/BUTR.CrashReport.Renderer.Html/CrashReportHtml.Html.cs +++ b/src/BUTR.CrashReport.Renderer.Html/CrashReportHtml.Html.cs @@ -322,4 +322,4 @@ private static string ContainerCode(string id, string name, string content, stri """; #pragma warning disable format // @formatter:on -} +} \ No newline at end of file diff --git a/src/BUTR.CrashReport.Renderer.Html/CrashReportHtml.cs b/src/BUTR.CrashReport.Renderer.Html/CrashReportHtml.cs index 53bfa8d..21c4e33 100644 --- a/src/BUTR.CrashReport.Renderer.Html/CrashReportHtml.cs +++ b/src/BUTR.CrashReport.Renderer.Html/CrashReportHtml.cs @@ -168,10 +168,10 @@ private static string GetEnhancedStacktraceHtml(CrashReportModel crashReport) var id03 = random.Next(); var moduleId = method.ModuleId ?? "UNKNOWN"; var pluginId = method.LoaderPluginId ?? "UNKNOWN"; - var harmonyPatch = method as MethodHarmonyPatch; + var harmonyPatchType = method.AdditionalMetadata.FirstOrDefault(x => x.Key == "HarmonyPatchType"); sbMain.Append("
  • ") - .Append("Type: ").Append(harmonyPatch is not null ? "Harmony" : "UNKNOWN").Append("
    ") - .AppendIf(harmonyPatch is not null, sb => sb.Append("Patch Type: ").Append(harmonyPatch!.PatchType.ToString()).Append("
    ")) + .Append("Type: ").Append(harmonyPatchType is not null ? "Harmony" : "UNKNOWN").Append("
    ") + .AppendIf(harmonyPatchType is not null, sb => sb.Append("Patch Type: ").Append(harmonyPatchType!.Value).Append("
    ")) .AppendIf(moduleId != "UNKNOWN", sb => sb.Append("Module Id: ").Append("").Append(moduleId).Append("").Append("
    ")) .AppendIf(pluginId != "UNKNOWN", sb => sb.Append("Plugin Id: ").Append("").Append(pluginId).Append("").Append("
    ")) .Append("Method: ").Append(method.MethodFullDescription.EscapeGenerics()).Append("
    ") @@ -239,7 +239,7 @@ private static void AddInvolvedModules(CrashReportModel crashReport, StringBuild .Append("
      "); foreach (var method in stacktrace.PatchMethods) { - var harmonyPatch = method as MethodHarmonyPatch; + var harmonyPatchType = method.AdditionalMetadata.FirstOrDefault(x => x.Key == "HarmonyPatchType"); // Ignore blank transpilers used to force the jitter to skip inlining if (method.MethodName == "BlankTranspiler") continue; @@ -248,7 +248,7 @@ private static void AddInvolvedModules(CrashReportModel crashReport, StringBuild .AppendIf(moduleId2 == "UNKNOWN", sb => sb.Append("Module Id: ").Append(moduleId2).Append("
      ")) .AppendIf(moduleId2 != "UNKNOWN", sb => sb.Append("Module Id: ").Append("").Append(moduleId2).Append("").Append("
      ")) .Append("Method: ").Append(method.MethodFullDescription.EscapeGenerics()).Append("
      ") - .AppendIf(harmonyPatch is not null, sb => sb.Append("Harmony Patch Type: ").Append(harmonyPatch!.PatchType).Append("
      ")) + .AppendIf(harmonyPatchType is not null, sb => sb.Append("Harmony Patch Type: ").Append(harmonyPatchType!.Value).Append("
      ")) .Append(""); } sbMain.Append("
    "); @@ -283,7 +283,7 @@ private static void AddInvolvedPlugins(CrashReportModel crashReport, StringBuild .Append("
      "); foreach (var method in stacktrace.PatchMethods) { - var harmonyPatch = method as MethodHarmonyPatch; + var harmonyPatchType = method.AdditionalMetadata.FirstOrDefault(x => x.Key == "HarmonyPatchType"); // Ignore blank transpilers used to force the jitter to skip inlining if (method.MethodName == "BlankTranspiler") continue; @@ -292,7 +292,7 @@ private static void AddInvolvedPlugins(CrashReportModel crashReport, StringBuild .AppendIf(pluginId2 == "UNKNOWN", sb => sb.Append("Plugin Id: ").Append(pluginId2).Append("
      ")) .AppendIf(pluginId2 != "UNKNOWN", sb => sb.Append("Plugin Id: ").Append("").Append(pluginId2).Append("").Append("
      ")) .Append("Method: ").Append(method.MethodFullDescription.EscapeGenerics()).Append("
      ") - .AppendIf(harmonyPatch is not null, sb => sb.Append("Harmony Patch Type: ").Append(harmonyPatch!.PatchType).Append("
      ")) + .AppendIf(harmonyPatchType is not null, sb => sb.Append("Harmony Patch Type: ").Append(harmonyPatchType!.Value).Append("
      ")) .Append(""); } sbMain.Append("
    "); @@ -653,4 +653,4 @@ private static string GetLogFilesHtml(IEnumerable files) sb.Append(""); return sb.ToString(); } -} +} \ No newline at end of file diff --git a/src/BUTR.CrashReport.Renderer.Html/Extensions/StringBuilderExtensions.cs b/src/BUTR.CrashReport.Renderer.Html/Extensions/StringBuilderExtensions.cs index 8e3bfce..177f438 100644 --- a/src/BUTR.CrashReport.Renderer.Html/Extensions/StringBuilderExtensions.cs +++ b/src/BUTR.CrashReport.Renderer.Html/Extensions/StringBuilderExtensions.cs @@ -43,6 +43,6 @@ public static StringBuilder AppendJoinIf(this StringBuilder builder, bool condit public static StringBuilder AppendLineIf(this StringBuilder builder, bool condition, string value) => condition ? builder.AppendLine(value) : builder; public static StringBuilder AppendIf(this StringBuilder builder, bool condition, Func lambda) => condition ? lambda(builder) : builder; - + public static StringBuilder AppendSb(this StringBuilder builder, Func lambda) => lambda(builder); } \ No newline at end of file diff --git a/src/BUTR.CrashReport.Renderer.ImGui/CrashReportImGui.cs b/src/BUTR.CrashReport.Renderer.ImGui/CrashReportImGui.cs index c0cd6e7..320acf6 100644 --- a/src/BUTR.CrashReport.Renderer.ImGui/CrashReportImGui.cs +++ b/src/BUTR.CrashReport.Renderer.ImGui/CrashReportImGui.cs @@ -48,7 +48,7 @@ public static void ShowAndWait(CrashReportModel crashReportModel, IList crashReportRendererUtilities.GetNativeLibrariesFolderPath().Select(x => Path.Combine(x, path))]; - + var window = Window.Create(WindowOptions.Default with { Title = $"{crashReportModel.Metadata.GameName} Crash Report", diff --git a/src/BUTR.CrashReport.Renderer.ImGui/Renderer/ImGuiRenderer.2.Exception.cs b/src/BUTR.CrashReport.Renderer.ImGui/Renderer/ImGuiRenderer.2.Exception.cs index 63be4ca..20710ae 100644 --- a/src/BUTR.CrashReport.Renderer.ImGui/Renderer/ImGuiRenderer.2.Exception.cs +++ b/src/BUTR.CrashReport.Renderer.ImGui/Renderer/ImGuiRenderer.2.Exception.cs @@ -9,10 +9,10 @@ namespace BUTR.CrashReport.Renderer.ImGui.Renderer; partial class ImGuiRenderer { - private byte[][] _exceptionsUtf8 = Array.Empty(); - private EnhancedStacktraceFrameModel?[] _stacktracesUtf8 = Array.Empty(); - private byte[][] _levelInputIdUtf8 = Array.Empty(); - private int[] _callstackLineCount = Array.Empty(); + private byte[][] _exceptionsUtf8 = []; + private EnhancedStacktraceFrameModel?[] _stacktracesUtf8 = []; + private byte[][] _levelInputIdUtf8 = []; + private int[] _callstackLineCount = []; private void InitializeExceptionRecursively() { diff --git a/src/BUTR.CrashReport.Renderer.ImGui/Renderer/ImGuiRenderer.3.EnhancedStacktrace.cs b/src/BUTR.CrashReport.Renderer.ImGui/Renderer/ImGuiRenderer.3.EnhancedStacktrace.cs index 3be6bee..5307a3b 100644 --- a/src/BUTR.CrashReport.Renderer.ImGui/Renderer/ImGuiRenderer.3.EnhancedStacktrace.cs +++ b/src/BUTR.CrashReport.Renderer.ImGui/Renderer/ImGuiRenderer.3.EnhancedStacktrace.cs @@ -1,6 +1,9 @@ using BUTR.CrashReport.Models; +using BUTR.CrashReport.Renderer.ImGui.Extensions; using BUTR.CrashReport.Renderer.ImGui.UnsafeUtils; +using HonkPerf.NET.RefLinq; + using ImGuiNET; using System.Collections.Generic; @@ -176,19 +179,18 @@ private void RenderEnhancedStacktrace() var moduleId2 = method.ModuleId ?? "UNKNOWN"; var pluginId2 = method.LoaderPluginId ?? "UNKNOWN"; - var harmonyPatch = method as MethodHarmonyPatch; + var harmonyPatchType = method.AdditionalMetadata.ToRefLinq().Where(x => x.Key == "HarmonyPatchType").FirstOrDefault(); if (moduleId2 != "UNKNOWN") _imgui.RenderId("Module Id:\0"u8, moduleId2); if (pluginId2 != "UNKNOWN") _imgui.RenderId("Plugin Id:\0"u8, pluginId2); _imgui.TextSameLine("Type: \0"u8); - _imgui.Text(harmonyPatch is not null ? "Harmony\0"u8 : "UNKNOWN\0"u8); + _imgui.Text(harmonyPatchType is not null ? "Harmony\0"u8 : "UNKNOWN\0"u8); - if (harmonyPatch is not null) + if (harmonyPatchType is not null) { - var harmonyPatchType = Clamp(harmonyPatch.PatchType, HarmonyPatchType.Prefix, HarmonyPatchType.Transpiler); _imgui.TextSameLine("Patch Type: \0"u8); - _imgui.Text(_harmonyPatchTypeNames[harmonyPatchType]); + _imgui.Text(harmonyPatchType.Value); } RenderCode(method); diff --git a/src/BUTR.CrashReport.Renderer.ImGui/Renderer/ImGuiRenderer.4.InvolvedModulesAndPlugins.cs b/src/BUTR.CrashReport.Renderer.ImGui/Renderer/ImGuiRenderer.4.InvolvedModulesAndPlugins.cs index 81fb71b..858b911 100644 --- a/src/BUTR.CrashReport.Renderer.ImGui/Renderer/ImGuiRenderer.4.InvolvedModulesAndPlugins.cs +++ b/src/BUTR.CrashReport.Renderer.ImGui/Renderer/ImGuiRenderer.4.InvolvedModulesAndPlugins.cs @@ -1,4 +1,7 @@ using BUTR.CrashReport.Models; +using BUTR.CrashReport.Renderer.ImGui.Extensions; + +using HonkPerf.NET.RefLinq; using ImGuiNET; @@ -10,17 +13,8 @@ namespace BUTR.CrashReport.Renderer.ImGui.Renderer; partial class ImGuiRenderer { - private static readonly byte[][] _harmonyPatchTypeNames = - [ - [], - "Prefix\0"u8.ToArray(), // Prefix - "Postfix\0"u8.ToArray(), // Postfix - "Transpiler\0"u8.ToArray(), // Transpiler - "Finalizer\0"u8.ToArray(), // Finalizer - ]; - - private KeyValuePair[] _enhancedStacktraceGroupedByModuleId = Array.Empty>(); - private KeyValuePair[] _enhancedStacktraceGroupedByLoaderPluginIdId = Array.Empty>(); + private KeyValuePair[] _enhancedStacktraceGroupedByModuleId = []; + private KeyValuePair[] _enhancedStacktraceGroupedByLoaderPluginIdId = []; private void InitializeInvolved() { @@ -65,7 +59,7 @@ private void RenderInvolvedModules() for (var k = 0; k < stacktrace.PatchMethods.Count; k++) { var method = stacktrace.PatchMethods[k]; - var harmonyPatch = method as MethodHarmonyPatch; + var harmonyPatchType = method.AdditionalMetadata.ToRefLinq().Where(x => x.Key == "HarmonyPatchType").FirstOrDefault(); // Ignore blank transpilers used to force the jitter to skip inlining if (method.MethodName == "BlankTranspiler") continue; @@ -74,11 +68,10 @@ private void RenderInvolvedModules() if (moduleId2 == "UNKNOWN") _imgui.RenderId("Module Id:\0"u8, kv.Key); _imgui.TextSameLine("Method: \0"u8); _imgui.Text(method.MethodFullDescription); - if (harmonyPatch is not null) + if (harmonyPatchType is not null) { - var harmonyPatchType = Clamp(harmonyPatch.PatchType, HarmonyPatchType.Prefix, HarmonyPatchType.Transpiler); _imgui.TextSameLine("Harmony Patch Type: }\0"u8); - _imgui.Text(_harmonyPatchTypeNames[harmonyPatchType]); + _imgui.Text(harmonyPatchType.Value); } } @@ -124,7 +117,7 @@ private void RenderInvolvedPlugins() for (var k = 0; k < stacktrace.PatchMethods.Count; k++) { var method = stacktrace.PatchMethods[k]; - var harmonyPatch = method as MethodHarmonyPatch; + var harmonyPatchType = method.AdditionalMetadata.ToRefLinq().Where(x => x.Key == "HarmonyPatchType").FirstOrDefault(); // Ignore blank transpilers used to force the jitter to skip inlining if (method.MethodName == "BlankTranspiler") continue; @@ -133,11 +126,10 @@ private void RenderInvolvedPlugins() if (pluginId2 == "UNKNOWN") _imgui.RenderId("Plugin Id:\0"u8, kv.Key); _imgui.TextSameLine("Method: \0"u8); _imgui.Text(method.MethodFullDescription); - if (harmonyPatch is not null) + if (harmonyPatchType is not null) { - var harmonyPatchType = Clamp(harmonyPatch.PatchType, HarmonyPatchType.Prefix, HarmonyPatchType.Transpiler); _imgui.TextSameLine("Harmony Patch Type: \0"u8); - _imgui.Text(_harmonyPatchTypeNames[harmonyPatchType]); + _imgui.Text(harmonyPatchType.Value); } } diff --git a/src/BUTR.CrashReport.Renderer.ImGui/Renderer/ImGuiRenderer.9.LogFiles.cs b/src/BUTR.CrashReport.Renderer.ImGui/Renderer/ImGuiRenderer.9.LogFiles.cs index dbe34a5..bfae2f8 100644 --- a/src/BUTR.CrashReport.Renderer.ImGui/Renderer/ImGuiRenderer.9.LogFiles.cs +++ b/src/BUTR.CrashReport.Renderer.ImGui/Renderer/ImGuiRenderer.9.LogFiles.cs @@ -22,7 +22,7 @@ partial class ImGuiRenderer "FTL\0"u8.ToArray(), // Fatal ]; - private int[] _logSourceMaxTypeLengths = Array.Empty(); + private int[] _logSourceMaxTypeLengths = []; private void InitializeLogFiles() { diff --git a/src/BUTR.CrashReport.Renderer.ImGui/Renderer/ImGuiRenderer.cs b/src/BUTR.CrashReport.Renderer.ImGui/Renderer/ImGuiRenderer.cs index c45f7be..60e4589 100644 --- a/src/BUTR.CrashReport.Renderer.ImGui/Renderer/ImGuiRenderer.cs +++ b/src/BUTR.CrashReport.Renderer.ImGui/Renderer/ImGuiRenderer.cs @@ -55,7 +55,7 @@ private static int Clamp(TEnum n, TEnum min, TEnum max) where TEnum : Enu private readonly ICrashReportRendererUtilities _crashReportRendererUtilities; private readonly Action _onClose; - private byte[] _loadedPluginsTitle = Array.Empty(); + private byte[] _loadedPluginsTitle = []; public ImGuiRenderer(CmGui imgui, CrashReportModel crashReport, IList logSources, ICrashReportRendererUtilities crashReportRendererUtilities, Action onClose) { diff --git a/src/BUTR.CrashReport.Renderer.ImGui/UnsafeUtils/UnsafeHelper.cs b/src/BUTR.CrashReport.Renderer.ImGui/UnsafeUtils/UnsafeHelper.cs index 040fe14..a055f87 100644 --- a/src/BUTR.CrashReport.Renderer.ImGui/UnsafeUtils/UnsafeHelper.cs +++ b/src/BUTR.CrashReport.Renderer.ImGui/UnsafeUtils/UnsafeHelper.cs @@ -103,7 +103,7 @@ public static int Utf16ToUtf8(ReadOnlySpan utf16, Span utf8) public static byte[] ToUtf8Array(string value) { if (string.IsNullOrEmpty(value)) - return Array.Empty(); + return []; var length = Encoding.UTF8.GetMaxByteCount(value.Length) + 1; var array = new byte[length]; diff --git a/src/BUTR.CrashReport/Interfaces/IHarmonyProvider.cs b/src/BUTR.CrashReport/Interfaces/IHarmonyProvider.cs index 57dc07e..e2db729 100644 --- a/src/BUTR.CrashReport/Interfaces/IHarmonyProvider.cs +++ b/src/BUTR.CrashReport/Interfaces/IHarmonyProvider.cs @@ -1,6 +1,6 @@ -using System; -using BUTR.CrashReport.Models; +using BUTR.CrashReport.Models; +using System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; diff --git a/src/BUTR.CrashReport/Utils/CrashReportModelUtils.cs b/src/BUTR.CrashReport/Utils/CrashReportModelUtils.cs index 60387b0..8d9c30b 100644 --- a/src/BUTR.CrashReport/Utils/CrashReportModelUtils.cs +++ b/src/BUTR.CrashReport/Utils/CrashReportModelUtils.cs @@ -72,7 +72,10 @@ public static List GetEnhancedStacktrace(CrashRepo }; methods.Add(patchMethod switch { - MethodEntryHarmony meh => new MethodHarmonyPatch(methodSimple, meh.Patch.Type), + MethodEntryHarmony meh => methodSimple with + { + AdditionalMetadata = methodSimple.AdditionalMetadata.Append(new MetadataModel { Key = "HarmonyPatchType", Value = meh.Patch.Type.ToString() }).ToArray() + }, _ => methodSimple }); } @@ -106,8 +109,8 @@ static bool IsProtected(AssemblyModel? assembly) => assembly is not null && MethodParameters = entry.Method.GetParameters().Select(x => x.ParameterType.FullName ?? string.Empty).ToArray(), NativeInstructions = entry.NativeInstructions, ILInstructions = entry.ILInstructions, - CSharpILMixedInstructions = skipDisassemblyForExecuting ? Array.Empty() : entry.CSharpILMixedInstructions, - CSharpInstructions = skipDisassemblyForExecuting ? Array.Empty() : entry.CSharpInstructions, + CSharpILMixedInstructions = skipDisassemblyForExecuting ? [] : entry.CSharpILMixedInstructions, + CSharpInstructions = skipDisassemblyForExecuting ? [] : entry.CSharpInstructions, AdditionalMetadata = Array.Empty(), }, OriginalMethod = entry.OriginalMethod is not null ? new() @@ -120,8 +123,8 @@ static bool IsProtected(AssemblyModel? assembly) => assembly is not null && MethodFullDescription = entry.OriginalMethod.Method.FullDescription(), MethodParameters = entry.OriginalMethod.Method.GetParameters().Select(x => x.ParameterType.FullName ?? string.Empty).ToArray(), ILInstructions = entry.OriginalMethod.ILInstructions, - CSharpILMixedInstructions = skipDisassemblyForOriginal ? Array.Empty() : entry.OriginalMethod.CSharpILMixedInstructions, - CSharpInstructions = skipDisassemblyForOriginal ? Array.Empty() : entry.OriginalMethod.CSharpInstructions, + CSharpILMixedInstructions = skipDisassemblyForOriginal ? [] : entry.OriginalMethod.CSharpILMixedInstructions, + CSharpInstructions = skipDisassemblyForOriginal ? [] : entry.OriginalMethod.CSharpInstructions, AdditionalMetadata = Array.Empty() } : null, PatchMethods = methods, @@ -262,11 +265,11 @@ static string CalculateMD5(string filename) Namespace = x.Namespace, Name = x.Name, FullName = x.FullName, - }).ToArray() : Array.Empty() - : Array.Empty(), + }).ToArray() : [] + : [], ImportedAssemblyReferences = (type & AssemblyModelType.System) == 0 ? assembly.GetReferencedAssemblies().Select(AssemblyImportedReferenceModelExtensions.Create).ToArray() - : Array.Empty(), + : [], AdditionalMetadata = Array.Empty(), }); }