Skip to content

Commit

Permalink
Merge pull request #344 from BUTR/dev
Browse files Browse the repository at this point in the history
v2.8.7
  • Loading branch information
Aragas authored Jul 6, 2023
2 parents f165c69 + 442f7ed commit 0d840f6
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 57 deletions.
2 changes: 1 addition & 1 deletion build/common.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<!--Development Variables-->
<PropertyGroup>
<!--Module Version-->
<Version>2.8.6</Version>
<Version>2.8.7</Version>
<!--Harmony Version-->
<HarmonyVersion>2.2.2</HarmonyVersion>
<HarmonyExtensionsVersion>3.2.0.77</HarmonyExtensionsVersion>
Expand Down
5 changes: 5 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
---------------------------------------------------------------------------------------------------
Version: 2.8.7
Game Versions: v1.0.0,v1.0.1,v1.0.2,v1.0.3,v1.1.0,v1.1.1,v1.1.2,v1.1.3,v1.1.4,v1.1.5,v1.2.0
* Small performance improvement
* Moved AutoGen catching to BLSE
---------------------------------------------------------------------------------------------------
Version: 2.8.6
Game Versions: v1.0.0,v1.0.1,v1.0.2,v1.0.3,v1.1.0,v1.1.1,v1.1.2,v1.1.3,v1.1.4,v1.1.5,v1.2.0
* Disabled AutoGen catch, seem to have a more severe performance impact than expected
Expand Down
25 changes: 5 additions & 20 deletions src/Bannerlord.ButterLib/ExceptionHandler/BEWPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
Expand Down Expand Up @@ -55,11 +54,13 @@ internal record ExceptionIdentifier(Type Type, string? StackTrace, string Messag

private static void Finalizer(Exception? __exception)
{
if (ExceptionHandlerSubSystem.Instance?.DisableWhenDebuggerIsAttached == true && IsDebuggerAttached())
return;

if (__exception is not null)
{
if (ExceptionHandlerSubSystem.Instance?.DisableWhenDebuggerIsAttached == true && IsDebuggerAttached())
return;

ExceptionReporter.Show(__exception);
}
}

internal static void Enable(Harmony harmony)
Expand Down Expand Up @@ -94,14 +95,6 @@ internal static void Enable(Harmony harmony)
transpiler: AccessTools2.Method(typeof(BEWPatch), nameof(BlankTranspiler)));
}

internal static void EnableAutoGenCatch(Harmony harmony)
{
var callbacksGeneratedTypes = AccessTools2.AllAssemblies().SelectMany(x => x.GetTypes().Where(y => y.Name.EndsWith("CallbacksGenerated")));
var callbackGeneratedMethods = callbacksGeneratedTypes.SelectMany(AccessTools.GetDeclaredMethods);
foreach (var method in callbackGeneratedMethods.Where(x => x.GetCustomAttributesData().Any(y => y.AttributeType.Name == "MonoPInvokeCallbackAttribute")))
harmony.Patch(method, finalizer: new HarmonyMethod(FinalizerMethod, before: BEW));
}

internal static void Disable(Harmony harmony)
{
harmony.Unpatch(ManagedApplicationTickMethod, FinalizerMethod);
Expand All @@ -111,14 +104,6 @@ internal static void Disable(Harmony harmony)
harmony.Unpatch(MissionTickMethod, FinalizerMethod);
}

internal static void DisableAutoGenCatch(Harmony harmony)
{
var callbacksGeneratedTypes = AccessTools2.AllAssemblies().SelectMany(x => x.GetTypes().Where(y => y.Name.EndsWith("CallbacksGenerated")));
var callbackGeneratedMethods = callbacksGeneratedTypes.SelectMany(AccessTools.GetDeclaredMethods);
foreach (var method in callbackGeneratedMethods.Where(x => x.GetCustomAttributesData().Any(y => y.AttributeType.Name == "MonoPInvokeCallbackAttribute")))
harmony.Unpatch(method, FinalizerMethod);
}

[MethodImpl(MethodImplOptions.NoInlining)]
private static IEnumerable<CodeInstruction> BlankTranspiler(IEnumerable<CodeInstruction> instructions) => instructions;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Bannerlord.ButterLib/ExceptionHandler/CrashReport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private static IEnumerable<StacktraceEntry> GetAllInvolvedModules(Exception ex)
}
}

static ModuleInfoExtended? GetModuleInfoIfMod(MethodBase? method) => method?.DeclaringType is not null
static ModuleInfoExtended? GetModuleInfoIfMod(MethodBase? method) => method?.DeclaringType is { Assembly.IsDynamic: false }
? ModuleInfoHelper.GetModuleByType(method.DeclaringType)
: null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,47 +51,13 @@ private set
}
}

private bool _catchAutoGenExceptions = false;
public bool CatchAutoGenExceptions
{
get => _catchAutoGenExceptions;
private set
{
if (_catchAutoGenExceptions != value)
{
_catchAutoGenExceptions = value;

if (_catchAutoGenExceptions)
{
if (IsEnabled)
{
//BEWPatch.Disable(Harmony);
//BEWPatch.EnableAutoGenCatch(Harmony);
}
}
else
{
if (IsEnabled)
{
//BEWPatch.Enable(Harmony);
//BEWPatch.DisableAutoGenCatch(Harmony);
}
}
}
}
}

/// <inheritdoc />
public IReadOnlyCollection<SubSystemSettingsDeclaration<ExceptionHandlerSubSystem>> Declarations { get; } = new SubSystemSettingsDeclaration<ExceptionHandlerSubSystem>[]
{
new SubSystemSettingsPropertyBool<ExceptionHandlerSubSystem>(
"{=B7bfrDNzIk} Disable when Debugger is Attached",
"{=r3ktQzFMRz} Stops the Exception Handler when a debugger is attached.",
x => x.DisableWhenDebuggerIsAttached),
new SubSystemSettingsPropertyBool<ExceptionHandlerSubSystem>(
"{=jorWb502pD} Catch AutoGenerated Code Exceptions (Lower Performance) (DISABLED)",
"{=ji1brrsEZz} Catch every Native->Managed call. Should catch every exception not catched the standard way. Might decrease the overall performance a bit.",
x => x.CatchAutoGenExceptions),
};


Expand All @@ -110,7 +76,6 @@ public void Enable()
if (!_wasButrLoaderInterceptorCalled)
{
BEWPatch.Enable(Harmony);
//BEWPatch.EnableAutoGenCatch(Harmony);
}
}

Expand Down

0 comments on commit 0d840f6

Please sign in to comment.