internal static void Run() { /* * The kernel32 functions seem to completely block the game's draw thread. * We can reduce interruptions to the game's drawing by executing the kernel calls as fast as possible. * Therefore, the below line actually (very noticably) boosts the performance of both DarkSoulsScripting AND Dark Souls! */ Thread.CurrentThread.Priority = ThreadPriority.Highest; if (Hook.DARKSOULS.TryAttachToDarkSouls(out string error)) { Hook.Init(); Finalizer = new SafetyFinalizerHandler(); CleanExitThread = new Thread(new ThreadStart(DoCleanExitWait)) { IsBackground = true }; CleanExitThread.Start(); CodeHooks.InitAll(); } else { //if (MessageBox.Show(error + "\n\nWould you like to proceed anyways?", "Failed to attach to Dark Souls", MessageBoxButton.YesNo, MessageBoxImage.Warning) != MessageBoxResult.Yes) //{ // if (System.Windows.Application.Current != null) //WPF // System.Windows.Application.Current.Shutdown(); // else if (System.Windows.Forms.Application.MessageLoop) //WinForms // System.Windows.Forms.Application.Exit(); // else //Console application // Environment.Exit(1); // Application.Current.Shutdown(1); // return; //} Console.Error.WriteLine(">>>>>>>>>>>>>>>> ERROR: " + error); Hook.Cleanup(); } }
private static void CleanExit() { CodeHooks.CleanupAll(); Hook.Cleanup(); }