diff --git a/Dalamud/Dalamud.cs b/Dalamud/Dalamud.cs index 73914d2a7..c38594771 100644 --- a/Dalamud/Dalamud.cs +++ b/Dalamud/Dalamud.cs @@ -1,7 +1,9 @@ using System; +using System.Diagnostics; using System.IO; using System.Linq; using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; @@ -97,6 +99,19 @@ internal sealed class Dalamud : IServiceType /// Gets location of stored assets. /// internal DirectoryInfo AssetDirectory => new(Service.Get().AssetDirectory!); + + /// + /// Signal to the crash handler process that we should restart the game. + /// + public static void RestartGame() + { + [DllImport("kernel32.dll")] + [return: MarshalAs(UnmanagedType.Bool)] + static extern void RaiseException(uint dwExceptionCode, uint dwExceptionFlags, uint nNumberOfArguments, IntPtr lpArguments); + + RaiseException(0x12345678, 0, 0, IntPtr.Zero); + Process.GetCurrentProcess().Kill(); + } /// /// Queue an unload of Dalamud when it gets the chance. diff --git a/Dalamud/Interface/Internal/DalamudCommands.cs b/Dalamud/Interface/Internal/DalamudCommands.cs index dfcccf79d..307f79436 100644 --- a/Dalamud/Interface/Internal/DalamudCommands.cs +++ b/Dalamud/Interface/Internal/DalamudCommands.cs @@ -29,13 +29,19 @@ internal class DalamudCommands : IServiceType HelpMessage = Loc.Localize("DalamudUnloadHelp", "Unloads XIVLauncher in-game addon."), ShowInHelp = false, }); - + commandManager.AddHandler("/xlkill", new CommandInfo(this.OnKillCommand) { HelpMessage = "Kill the game.", ShowInHelp = false, }); + commandManager.AddHandler("/xlrestart", new CommandInfo(this.OnRestartCommand) + { + HelpMessage = "Restart the game.", + ShowInHelp = false, + }); + commandManager.AddHandler("/xlhelp", new CommandInfo(this.OnHelpCommand) { HelpMessage = Loc.Localize("DalamudCmdInfoHelp", "Shows list of commands available. If an argument is provided, shows help for that command."), @@ -147,12 +153,17 @@ internal class DalamudCommands : IServiceType Service.Get().Print("Unloading..."); Service.Get().Unload(); } - + private void OnKillCommand(string command, string arguments) { Process.GetCurrentProcess().Kill(); } + private void OnRestartCommand(string command, string arguments) + { + Dalamud.RestartGame(); + } + private void OnHelpCommand(string command, string arguments) { var chatGui = Service.Get(); diff --git a/Dalamud/Interface/Internal/DalamudInterface.cs b/Dalamud/Interface/Internal/DalamudInterface.cs index 75c3b2b03..ca7cbe287 100644 --- a/Dalamud/Interface/Internal/DalamudInterface.cs +++ b/Dalamud/Interface/Internal/DalamudInterface.cs @@ -717,12 +717,7 @@ internal class DalamudInterface : IDisposable, IServiceType if (ImGui.MenuItem("Restart game")) { - [DllImport("kernel32.dll")] - [return: MarshalAs(UnmanagedType.Bool)] - static extern void RaiseException(uint dwExceptionCode, uint dwExceptionFlags, uint nNumberOfArguments, IntPtr lpArguments); - - RaiseException(0x12345678, 0, 0, IntPtr.Zero); - Process.GetCurrentProcess().Kill(); + Dalamud.RestartGame(); } if (ImGui.MenuItem("Kill game"))