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> /// <summary>
@ -128,7 +136,17 @@ internal sealed class Dalamud : IServiceType
/// Gets location of stored assets. /// Gets location of stored assets.
/// </summary> /// </summary>
internal DirectoryInfo AssetDirectory => new(this.StartInfo.AssetDirectory!); 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> /// <summary>
/// Signal to the crash handler process that we should restart the game. /// Signal to the crash handler process that we should restart the game.
/// </summary> /// </summary>
@ -191,18 +209,32 @@ internal sealed class Dalamud : IServiceType
} }
/// <summary> /// <summary>
/// Replace the built-in exception handler with a debug one. /// Replace the current exception handler with the default one.
/// </summary> /// </summary>
internal void ReplaceExceptionHandler() internal void UseDefaultExceptionHandler() =>
{ this.SetExceptionHandler(this.DefaultExceptionFilter);
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}");
var oldFilter = NativeFunctions.SetUnhandledExceptionFilter(releaseFilter); /// <summary>
Log.Debug("Reset ExceptionFilter, old: {0}", oldFilter); /// 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) private void SetupClientStructsResolver(DirectoryInfo cacheDir)
{ {
using (Timings.Start("CS Resolver Init")) using (Timings.Start("CS Resolver Init"))

View file

@ -863,9 +863,19 @@ internal class DalamudInterface : IDisposable, IServiceType
if (ImGui.BeginMenu("Game")) 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(); ImGui.EndMenu();