diff --git a/src/BUTR.CrashReport.Bannerlord.Source/CrashReportCreatorHelper.cs b/src/BUTR.CrashReport.Bannerlord.Source/CrashReportCreatorHelper.cs index 7a8e234..20d3417 100644 --- a/src/BUTR.CrashReport.Bannerlord.Source/CrashReportCreatorHelper.cs +++ b/src/BUTR.CrashReport.Bannerlord.Source/CrashReportCreatorHelper.cs @@ -164,6 +164,8 @@ private OperatingSystemType GetOperatingSystemType() public virtual IEnumerable Assemblies() => AccessTools2.AllAssemblies(); + public IEnumerable TypesFromAssembly(Assembly assembly) => AccessTools.GetTypesFromAssembly(assembly); + public virtual IModuleInfo? GetAssemblyModule(CrashReportInfo crashReport, Assembly assembly) { try diff --git a/src/BUTR.CrashReport/CrashReportInfo.cs b/src/BUTR.CrashReport/CrashReportInfo.cs index d0aab42..dcc964d 100644 --- a/src/BUTR.CrashReport/CrashReportInfo.cs +++ b/src/BUTR.CrashReport/CrashReportInfo.cs @@ -164,7 +164,7 @@ private CrashReportInfo(Exception exception, Dictionary addition FullName = y.FullName }).ToArray()); - Stacktrace = CrashReportUtils.GetAllInvolvedModules(Exception, assemblies, moduleProvider, loaderPluginProvider, harmonyProvider).ToArray(); + Stacktrace = CrashReportUtils.GetAllInvolvedModules(Exception, assemblies, assemblyUtilities, moduleProvider, loaderPluginProvider, harmonyProvider).ToArray(); FilteredStacktrace = stacktraceFilter.Filter(Stacktrace).ToArray(); foreach (var originalMethod in harmonyProvider.GetAllPatchedMethods()) diff --git a/src/BUTR.CrashReport/Interfaces/IAssemblyUtilities.cs b/src/BUTR.CrashReport/Interfaces/IAssemblyUtilities.cs index e8f7aa4..028d566 100644 --- a/src/BUTR.CrashReport/Interfaces/IAssemblyUtilities.cs +++ b/src/BUTR.CrashReport/Interfaces/IAssemblyUtilities.cs @@ -1,4 +1,5 @@ -using BUTR.CrashReport.Models; +using System; +using BUTR.CrashReport.Models; using System.Collections.Generic; using System.Reflection; @@ -15,6 +16,11 @@ public interface IAssemblyUtilities /// IEnumerable Assemblies(); + /// + /// Provides the implementation for getting the types present in the assembly. + /// + IEnumerable TypesFromAssembly(Assembly assembly); + /// /// Gets the module for the assembly if there is one /// diff --git a/src/BUTR.CrashReport/Utils/CrashReportUtils.cs b/src/BUTR.CrashReport/Utils/CrashReportUtils.cs index 018c3a0..348b185 100644 --- a/src/BUTR.CrashReport/Utils/CrashReportUtils.cs +++ b/src/BUTR.CrashReport/Utils/CrashReportUtils.cs @@ -1,8 +1,6 @@ using BUTR.CrashReport.Interfaces; using BUTR.CrashReport.Models; -using HarmonyLib; - using System; using System.Collections.Generic; using System.Diagnostics; @@ -89,7 +87,7 @@ public void Deconstruct(out MethodBase? original, out MethodInfo? replacement, o /// /// Gets the module info if the method is from a mod. /// - public static IModuleInfo? GetModuleInfoIfMod(MethodBase? method, IEnumerable assemblies, IModuleProvider moduleProvider) + public static IModuleInfo? GetModuleInfoIfMod(MethodBase? method, IEnumerable assemblies, IAssemblyUtilities assemblyUtilities, IModuleProvider moduleProvider) { if (method is null) return null; @@ -113,7 +111,7 @@ public void Deconstruct(out MethodBase? original, out MethodInfo? replacement, o var fullMethodName = string.Join("", patchPostfix.Take(patchPostfix.Length - 1)); var foundMethod = assemblies.Where(x => !x.IsDynamic) - .SelectMany(AccessTools.GetTypesFromAssembly) + .SelectMany(assemblyUtilities.TypesFromAssembly) .Where(x => !x.IsAbstract) .Where(x => !string.IsNullOrEmpty(x.DeclaringType?.FullName) && fullMethodName.StartsWith(x.DeclaringType!.FullName)) .SelectMany(x => x.GetMethods()) @@ -132,7 +130,7 @@ public void Deconstruct(out MethodBase? original, out MethodInfo? replacement, o /// /// Gets the loader plugin if the method is from a mod. /// - public static ILoaderPluginInfo? GetLoaderPluginIfMod(MethodBase? method, IEnumerable assemblies, ILoaderPluginProvider loaderPluginProvider) + public static ILoaderPluginInfo? GetLoaderPluginIfMod(MethodBase? method, IEnumerable assemblies, IAssemblyUtilities assemblyUtilities, ILoaderPluginProvider loaderPluginProvider) { if (method is null) return null; @@ -156,7 +154,7 @@ public void Deconstruct(out MethodBase? original, out MethodInfo? replacement, o var fullMethodName = string.Join("", patchPostfix.Take(patchPostfix.Length - 1)); var foundMethod = assemblies.Where(x => !x.IsDynamic) - .SelectMany(AccessTools.GetTypesFromAssembly) + .SelectMany(assemblyUtilities.TypesFromAssembly) .Where(x => !x.IsAbstract) .Where(x => !string.IsNullOrEmpty(x.DeclaringType?.FullName) && fullMethodName.StartsWith(x.DeclaringType!.FullName)) .SelectMany(x => x.GetMethods()) @@ -229,12 +227,12 @@ public static StackframePatchData GetHarmonyData(StackFrame frame, IHarmonyProvi /// /// Gets all involved modules in the exception stacktrace. /// - public static IEnumerable GetAllInvolvedModules(Exception ex, ICollection assemblies, IModuleProvider moduleProvider, ILoaderPluginProvider loaderPluginProvider, IHarmonyProvider harmonyProvider) + public static IEnumerable GetAllInvolvedModules(Exception ex, ICollection assemblies, IAssemblyUtilities assemblyUtilities, IModuleProvider moduleProvider, ILoaderPluginProvider loaderPluginProvider, IHarmonyProvider harmonyProvider) { var inner = ex.InnerException; if (inner is not null) { - foreach (var modInfo in GetAllInvolvedModules(inner, assemblies, moduleProvider, loaderPluginProvider, harmonyProvider)) + foreach (var modInfo in GetAllInvolvedModules(inner, assemblies, assemblyUtilities, moduleProvider, loaderPluginProvider, harmonyProvider)) yield return modInfo; } @@ -254,15 +252,15 @@ public static IEnumerable GetAllInvolvedModules(Exception ex, I OriginalMethod = originalMethod is not null && originalMethod != executingMethod ? new() { Method = originalMethod, - ModuleInfo = GetModuleInfoIfMod(originalMethod, assemblies, moduleProvider), - LoaderPluginInfo = GetLoaderPluginIfMod(originalMethod, assemblies, loaderPluginProvider), + ModuleInfo = GetModuleInfoIfMod(originalMethod, assemblies, assemblyUtilities, moduleProvider), + LoaderPluginInfo = GetLoaderPluginIfMod(originalMethod, assemblies, assemblyUtilities, loaderPluginProvider), ILInstructions = DecompileILCode(originalMethod), CSharpILMixedInstructions = DecompileILWithCSharpCode(originalMethod), CSharpInstructions = DecompileCSharpCode(originalMethod), } : null, MethodFromStackframeIssue = methodFromStackframeIssue, - ModuleInfo = GetModuleInfoIfMod(executingMethod, assemblies, moduleProvider), - LoaderPluginInfo = GetLoaderPluginIfMod(executingMethod, assemblies, loaderPluginProvider), + ModuleInfo = GetModuleInfoIfMod(executingMethod, assemblies, assemblyUtilities, moduleProvider), + LoaderPluginInfo = GetLoaderPluginIfMod(executingMethod, assemblies, assemblyUtilities, loaderPluginProvider), ILOffset = ilOffset != StackFrame.OFFSET_UNKNOWN ? ilOffset : null, NativeOffset = nativeILOffset != StackFrame.OFFSET_UNKNOWN ? nativeILOffset : null, StackFrameDescription = frame.ToString(),