add more exception handler options to dev menu

This commit is contained in:
marzent 2024-02-10 13:03:11 +01:00
parent be965f8dd1
commit df65d59f8b
2 changed files with 54 additions and 12 deletions

View file

@ -117,6 +117,14 @@ internal sealed class Dalamud : IServiceType
}
});
}
this.DefaultExceptionFilter = NativeFunctions.SetUnhandledExceptionFilter(nint.Zero);
NativeFunctions.SetUnhandledExceptionFilter(this.DefaultExceptionFilter);
Log.Debug($"SE default exception filter at {this.DefaultExceptionFilter.ToInt64():X}");
var debugSig = "40 55 53 56 48 8D AC 24 ?? ?? ?? ?? B8 ?? ?? ?? ?? E8 ?? ?? ?? ?? 48 2B E0 48 8B 05 ?? ?? ?? ?? 48 33 C4 48 89 85 ?? ?? ?? ?? 48 83 3D ?? ?? ?? ?? ??";
this.DebugExceptionFilter = Service<TargetSigScanner>.Get().ScanText(debugSig);
Log.Debug($"SE debug exception filter at {this.DebugExceptionFilter.ToInt64():X}");
}
/// <summary>
@ -129,6 +137,16 @@ internal sealed class Dalamud : IServiceType
/// </summary>
internal DirectoryInfo AssetDirectory => new(this.StartInfo.AssetDirectory!);
/// <summary>
/// Gets the in-game default exception filter.
/// </summary>
private nint DefaultExceptionFilter { get; }
/// <summary>
/// Gets the in-game debug exception filter.
/// </summary>
private nint DebugExceptionFilter { get; }
/// <summary>
/// Signal to the crash handler process that we should restart the game.
/// </summary>
@ -191,16 +209,30 @@ internal sealed class Dalamud : IServiceType
}
/// <summary>
/// Replace the built-in exception handler with a debug one.
/// Replace the current exception handler with the default one.
/// </summary>
internal void ReplaceExceptionHandler()
{
var releaseSig = "40 55 53 56 48 8D AC 24 ?? ?? ?? ?? B8 ?? ?? ?? ?? E8 ?? ?? ?? ?? 48 2B E0 48 8B 05 ?? ?? ?? ?? 48 33 C4 48 89 85 ?? ?? ?? ?? 48 83 3D ?? ?? ?? ?? ??";
var releaseFilter = Service<TargetSigScanner>.Get().ScanText(releaseSig);
Log.Debug($"SE debug filter at {releaseFilter.ToInt64():X}");
internal void UseDefaultExceptionHandler() =>
this.SetExceptionHandler(this.DefaultExceptionFilter);
var oldFilter = NativeFunctions.SetUnhandledExceptionFilter(releaseFilter);
Log.Debug("Reset ExceptionFilter, old: {0}", oldFilter);
/// <summary>
/// Replace the current exception handler with a debug one.
/// </summary>
internal void UseDebugExceptionHandler() =>
this.SetExceptionHandler(this.DebugExceptionFilter);
/// <summary>
/// Disable the current exception handler.
/// </summary>
internal void UseNoExceptionHandler() =>
this.SetExceptionHandler(nint.Zero);
/// <summary>
/// Helper function to set the exception handler.
/// </summary>
private void SetExceptionHandler(nint newFilter)
{
var oldFilter = NativeFunctions.SetUnhandledExceptionFilter(newFilter);
Log.Debug("Set ExceptionFilter to {0}, old: {1}", newFilter, oldFilter);
}
private void SetupClientStructsResolver(DirectoryInfo cacheDir)

View file

@ -863,9 +863,19 @@ internal class DalamudInterface : IDisposable, IServiceType
if (ImGui.BeginMenu("Game"))
{
if (ImGui.MenuItem("Replace ExceptionHandler"))
if (ImGui.MenuItem("Use in-game default ExceptionHandler"))
{
this.dalamud.ReplaceExceptionHandler();
this.dalamud.UseDefaultExceptionHandler();
}
if (ImGui.MenuItem("Use in-game debug ExceptionHandler"))
{
this.dalamud.UseDebugExceptionHandler();
}
if (ImGui.MenuItem("Disable in-game ExceptionHandler"))
{
this.dalamud.UseNoExceptionHandler();
}
ImGui.EndMenu();