public static async Task <bool> StartGame()
        {
            EnableDebug();

            StartInfo.FileName         = $"{Settings.PathToSkyrim}\\skse64_loader.exe";
            StartInfo.WorkingDirectory = $"{Settings.PathToSkyrim}";
            StartInfo.UseShellExecute  = false;
            StartInfo.CreateNoWindow   = true;
            StartInfo.Verb             = "runas";

            StartInfo.Domain = AppDomain.CurrentDomain.FriendlyName;

            GameProcess.StartInfo = StartInfo;

            Runing = true;
            GameProcess.Start();
            Logger.ReportMetricaEvent("StartedGame");

            int ParentPID = GameProcess.Id;

            await Task.Run(() => GameProcess.WaitForExit());

            foreach (var p in ProcessExtensions.FindChildrenProcesses(ParentPID))
            {
                GameProcess = p;
            }
            Microsoft.Win32.SafeHandles.SafeProcessHandle sh = GameProcess.SafeHandle;
            if (!GameProcess.HasExited)
            {
                await Task.Run(() => GameProcess.WaitForExit());
            }

            Logger.ReportMetricaEvent("ExitedGame");

            await Task.Delay(1000);

            await KillProcess();

            Runing = false;

            return(GameProcess.ExitCode != 0);
        }
예제 #2
0
        public static async Task <bool> StartGame()
        {
            EnableDebug();

            StartInfo.FileName         = $"{Settings.PathToSkyrim}\\skse64_loader.exe";
            StartInfo.WorkingDirectory = $"{Settings.PathToSkyrim}\\";
            StartInfo.Verb             = "runas";

            StartInfo.Domain = AppDomain.CurrentDomain.FriendlyName;

            GameProcess.StartInfo = StartInfo;

            Runing = true;
            GameProcess.Start();
            YandexMetrica.ReportEvent("StartedGame");

            int ParentPID = GameProcess.Id;

            await Task.Run(() => GameProcess.WaitForExit());

            foreach (var p in ProcessExtensions.FindChildrenProcesses(ParentPID))
            {
                GameProcess = p;
            }
            Microsoft.Win32.SafeHandles.SafeProcessHandle sh = GameProcess.SafeHandle;
            if (!GameProcess.HasExited)
            {
                await Task.Run(() => GameProcess.WaitForExit());
            }

            YandexMetrica.ReportEvent("ExitedGame");

            await Task.Delay(500);

            Process[] SkyrimPlatformCEFs = Process.GetProcessesByName("SkyrimPlatformCEF");
            for (int i = 0; i < SkyrimPlatformCEFs.Length; i++)
            {
                try
                {
                    int tr = 0;
                    do
                    {
                        SkyrimPlatformCEFs[i].Kill();
                        await Task.Delay(200);
                    }while (!SkyrimPlatformCEFs[i].HasExited && tr++ < 5);
                }
                catch (Win32Exception)
                {
                    if (Settings.ExperimentalFunctions == true)
                    {
                        try
                        {
                            if (!SkyrimPlatformCEFs[i].HasExited)
                            {
                                ProcessKiller.KillProcess((IntPtr)SkyrimPlatformCEFs[i].Id);
                            }
                        }
                        catch (Exception e)
                        {
                            Logger.Error("StartGame_Killer_SkyrimPlatformCEF", e);
                        }
                    }
                }
                catch (Exception e)
                {
                    Logger.Error("StartGame_KillSkyrimPlatformCEF", e);
                }
            }

            Runing = false;

            return(GameProcess.ExitCode != 0);
        }