diff --git a/Dalamud/Dalamud.cs b/Dalamud/Dalamud.cs index 67dbe85b6..6a9332b9d 100644 --- a/Dalamud/Dalamud.cs +++ b/Dalamud/Dalamud.cs @@ -5,6 +5,7 @@ using System.IO; using System.Linq; using System.Net; using System.Reflection; +using System.Runtime.InteropServices; using System.Text; using System.Threading; using System.Threading.Tasks; @@ -154,6 +155,10 @@ namespace Dalamud { } public void Start() { +#if DEBUG + ReplaceExceptionHandler(); +#endif + this.Framework.Enable(); this.ClientState.Enable(); } @@ -194,7 +199,7 @@ namespace Dalamud { this.SigScanner.Dispose(); } - #region Interface +#region Interface private bool isImguiDrawDemoWindow = false; @@ -269,6 +274,9 @@ namespace Dalamud { { Process.GetCurrentProcess().Kill(); } + if (ImGui.MenuItem("Cause AccessViolation")) { + var a = Marshal.ReadByte(IntPtr.Zero); + } ImGui.Separator(); ImGui.MenuItem(this.assemblyVersion, false); ImGui.MenuItem(this.StartInfo.GameVersion, false); @@ -276,6 +284,14 @@ namespace Dalamud { ImGui.EndMenu(); } + if (ImGui.BeginMenu("Game")) { + if (ImGui.MenuItem("Replace ExceptionHandler")) { + ReplaceExceptionHandler(); + } + + ImGui.EndMenu(); + } + if (ImGui.BeginMenu("Plugins")) { if (ImGui.MenuItem("Open Plugin installer")) @@ -396,7 +412,16 @@ namespace Dalamud { } } - #endregion + private void ReplaceExceptionHandler() { + var semd = this.SigScanner.ScanText( + "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 ?? ?? ?? ?? ??"); + Log.Debug($"SE debug filter at {semd.ToInt64():X}"); + + var oldFilter = NativeFunctions.SetUnhandledExceptionFilter(semd); + Log.Debug("Reset ExceptionFilter, old: {0}", oldFilter); + } + +#endregion private void SetupCommands() { CommandManager.AddHandler("/xldclose", new CommandInfo(OnUnloadCommand) { diff --git a/Dalamud/NativeFunctions.cs b/Dalamud/NativeFunctions.cs index 37988eb48..bf81170d1 100644 --- a/Dalamud/NativeFunctions.cs +++ b/Dalamud/NativeFunctions.cs @@ -56,6 +56,15 @@ namespace Dalamud FLASHW_TIMERNOFG = 12 } + [Flags] + public enum ErrorModes : uint + { + SYSTEM_DEFAULT = 0x0, + SEM_FAILCRITICALERRORS = 0x0001, + SEM_NOALIGNMENTFAULTEXCEPT = 0x0004, + SEM_NOGPFAULTERRORBOX = 0x0002, + SEM_NOOPENFILEERRORBOX = 0x8000 + } #endregion @@ -109,5 +118,14 @@ namespace Dalamud [DllImport("kernel32", SetLastError = true, CharSet = CharSet.Ansi)] public static extern IntPtr LoadLibrary([MarshalAs(UnmanagedType.LPStr)]string lpFileName); + + [DllImport("kernel32.dll")] + public static extern IntPtr SetUnhandledExceptionFilter(IntPtr lpTopLevelExceptionFilter); + + [DllImport("kernel32.dll")] + public static extern ErrorModes SetErrorMode(ErrorModes uMode); + + [DllImport("kernel32.dll", SetLastError = true)] + public static extern bool DebugActiveProcess(uint dwProcessId); } }