Esempio n. 1
0
        public void UpdateClip()
        {
            //GR: Catch exception when closing. Happens on synchronized rendering
            try
            {
                MySandboxGame.GameWindowHandle = Handle;
            }
            catch (ObjectDisposedException)
            {
                MySandboxGame.ExitThreadSafe();
                return;
            }
            // TODO: OP! Some old implementation, try finding something more safe
            Control c = Control.FromHandle(WinApi.GetForegroundWindow());

            bool isActive = false;

            if (c != null)
            {
                isActive = !c.TopLevelControl.InvokeRequired &&
                           Handle == c.TopLevelControl.Handle;
            }

            isActive = isActive && (m_captureMouse || !m_isCursorVisible);

            if (isActive)
            {
                SetClip();
            }
            else
            {
                ClearClip();
            }
        }
Esempio n. 2
0
 protected void CheckLowMemSwitchToLow()
 {
     if (MySandboxGame.Config.LowMemSwitchToLow != MyConfig.LowMemSwitch.TRIGGERED)
     {
         return;
     }
     MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(MyMessageBoxStyleEnum.Error, MyMessageBoxButtonsType.YES_NO, messageCaption : MyTexts.Get(MyCommonTexts.MessageBoxCaptionError), messageText : MyTexts.Get(MySpaceTexts.LowMemSwitchToLowQuestion), okButtonText : null, cancelButtonText : null, yesButtonText : null, noButtonText : null, callback : delegate(MyGuiScreenMessageBox.ResultEnum result)
     {
         if (result == MyGuiScreenMessageBox.ResultEnum.YES)
         {
             MySandboxGame.Config.LowMemSwitchToLow = MyConfig.LowMemSwitch.ARMED;
             MySandboxGame.Config.SetToLowQuality();
             MySandboxGame.Config.Save();
             if (MySpaceAnalytics.Instance != null)
             {
                 MySpaceAnalytics.Instance.ReportSessionEnd("Exit to Windows");
             }
             MyScreenManager.CloseAllScreensNowExcept(null, isUnloading: true);
             MySandboxGame.ExitThreadSafe();
         }
         else
         {
             MySandboxGame.Config.LowMemSwitchToLow = MyConfig.LowMemSwitch.USER_SAID_NO;
             MySandboxGame.Config.Save();
         }
     }));
 }
Esempio n. 3
0
 protected void CheckLowMemSwitchToLow()
 {
     if (MySandboxGame.Config.LowMemSwitchToLow == MyConfig.LowMemSwitch.TRIGGERED)
     {
         MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                    callback : delegate(MyGuiScreenMessageBox.ResultEnum result)
         {
             if (result == MyGuiScreenMessageBox.ResultEnum.YES)
             {
                 MySandboxGame.Config.LowMemSwitchToLow = MyConfig.LowMemSwitch.ARMED;
                 MySandboxGame.Config.SetToLowQuality();
                 MySandboxGame.Config.Save();
                 // Exit game
                 {
                     MyAnalyticsTracker.SendGameEnd("Exit to Windows", MySandboxGame.TotalTimeInMilliseconds / 1000);
                     MyScreenManager.CloseAllScreensNowExcept(null);
                     MySandboxGame.ExitThreadSafe();
                 }
             }
             else
             {
                 MySandboxGame.Config.LowMemSwitchToLow = MyConfig.LowMemSwitch.USER_SAID_NO;
                 MySandboxGame.Config.Save();
             };
         },
                                    messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError),
                                    messageText: MyTexts.Get(MySpaceTexts.LowMemSwitchToLowQuestion),
                                    buttonType: MyMessageBoxButtonsType.YES_NO));
     }
 }
 public void ExitCallback(MyGuiScreenMessageBox.ResultEnum callbackReturn)
 {
     if (callbackReturn == MyGuiScreenMessageBox.ResultEnum.YES)
     {
         MyScreenManager.CloseAllScreensNowExcept(null);
         MySandboxGame.ExitThreadSafe();
     }
 }
Esempio n. 5
0
 internal static void ServerConsoleOnInput(string input)
 {
     //if (!string.IsNullOrEmpty(input)) ConsoleManager.Instance.ExecuteCommand(input);
     if (input.ToLower().Equals("quit") || input.ToLower().Equals("shutdown"))
     {
         MySandboxGame.ExitThreadSafe();
     }
 }
Esempio n. 6
0
        private void OnLogoutProgressClosed()
        {
            MySandboxGame.Log.WriteLine("Application closed by user");
            MyAnalyticsTracker.SendGameEnd("Exit to Windows", MySandboxGame.TotalTimeInMilliseconds / 1000);
            MyScreenManager.CloseAllScreensNowExcept(null);

            //  Exit application
            MySandboxGame.ExitThreadSafe();
        }
Esempio n. 7
0
        private void DoRestart()
        {
            // Tell SE to shut down
            //Wrapper.GameAction( ()=>MySandboxGame.Static.Exit(  ) );
            //MySandboxGame.Static.Exit(  );
            //Thread.Sleep( 5000 );

            Essentials.Log.Info("Stopping server");

            //cache for console output while we're waiting
            StringBuilder sb  = new StringBuilder();
            TextWriter    tw  = new StringWriter(sb);
            TextWriter    tmp = Console.Out;

            //hijack the console so we can listen for the server stopped message
            Console.SetOut(tw);

            //ask the server nicely to stop
            MySandboxGame.ExitThreadSafe();

            DateTime waitStart = DateTime.Now;

            while (true)
            {
                if (sb.ToString().Contains("Server stopped, press any key to close this window"))
                {
                    break;
                }

                Thread.Sleep(100);

                //the server didn't listen, so kill it forcefully
                if (DateTime.Now - waitStart > TimeSpan.FromMinutes(5))
                {
                    Essentials.Log.Warn("Server failed to shut down correctly!");
                    break;
                }
            }

            //return control back to the console and write the cached log back
            Console.SetOut(tmp);
            Console.Write(sb);

            // If we're not a service, restart with a .bat otherwise just exit and let the service be restarted
            if (Environment.UserInteractive)
            {
                string restartText = "%windir%/system32/timeout /t 30\r\n";
                restartText += String.Format("cd /d \"{0}\"\r\n", Path.GetDirectoryName(Application.ExecutablePath));
                restartText += PluginSettings.Instance.RestartAddedProcesses + "\r\n";
                restartText += Path.GetFileName(Application.ExecutablePath) + " " + Server.Instance.CommandLineArgs.Args + "\r\n";

                File.WriteAllText("RestartApp.bat", restartText);
                Process.Start("RestartApp.bat");
            }

            Environment.Exit(1);
        }
Esempio n. 8
0
        public void StopServer( )
        {
            if (!_isServerRunning)
            {
                return;
            }

            ApplicationLog.BaseLog.Info("Stopping server");

            //cache for console output while we're waiting
            StringBuilder sb  = new StringBuilder();
            TextWriter    tw  = new StringWriter(sb);
            TextWriter    tmp = Console.Out;

            //hijack the console so we can listen for the server stopped message
            Console.SetOut(tw);

            //ask the server nicely to stop
            MySandboxGame.ExitThreadSafe();

            _pluginMainLoop.Stop( );
            _autosaveTimer.Stop( );
            _pluginManager.Shutdown( );

            DateTime waitStart = DateTime.Now;

            while (true)
            {
                if (sb.ToString().Contains("Server stopped, press any key to close this window"))
                {
                    break;
                }

                Thread.Sleep(100);

                //the server didn't listen, so kill it forcefully
                if (DateTime.Now - waitStart > TimeSpan.FromMinutes(5))
                {
                    ApplicationLog.BaseLog.Warn("Server failed to shut down correctly!");
                    break;
                }
            }

            //return control back to the console and write the cached log back
            Console.SetOut(tmp);
            Console.Write(sb);

            //_runServerThread.Interrupt();
            //_dedicatedServerWrapper.StopServer();
            //_runServerThread.Abort();
            //_runServerThread.Interrupt( );

            _isServerRunning = false;

            ApplicationLog.BaseLog.Info("Server has been stopped");
        }
Esempio n. 9
0
 void MySession_AfterLoading()
 {
     GrabWhitelist(_commandLine);
     GrabTerminalActions(_commandLine);
     Task.Run(async() =>
     {
         await Task.Delay(TimeSpan.FromSeconds(5));
         MySandboxGame.ExitThreadSafe();
     });
 }
Esempio n. 10
0
 private void OnLogoutProgressClosed()
 {
     MySandboxGame.Config.ControllerDefaultOnStart = MyInput.Static.IsJoystickLastUsed;
     MySandboxGame.Config.Save();
     MySandboxGame.Log.WriteLine("Application closed by user");
     if (MySpaceAnalytics.Instance != null)
     {
         MySpaceAnalytics.Instance.ReportSessionEnd("Exit to Windows");
     }
     MyScreenManager.CloseAllScreensNowExcept(null);
     MySandboxGame.ExitThreadSafe();
 }
Esempio n. 11
0
 internal static void ServerConsoleOnInput(string input)
 {
     input = input.Trim();
     if (!string.IsNullOrEmpty(input))
     {
         // TODO: Handle command input
         if (input.ToLower().Equals("quit") || input.ToLower().Equals("shutdown"))
         {
             MySandboxGame.ExitThreadSafe();
         }
     }
 }
Esempio n. 12
0
        //  Sends input (keyboard/mouse) to screen which has focus (top-most)
        public void HandleInput()
        {
            ProfilerShort.Begin("MyGuiManager.HandleInput");
            try
            {
                if (MyInput.Static.IsAnyAltKeyPressed() && MyInput.Static.IsNewKeyPressed(MyKeys.F4))
                {
                    MyAnalyticsTracker.SendGameEnd("Alt+F4", MySandboxGame.TotalTimeInMilliseconds / 1000);

                    //  Exit application
                    MySandboxGame.ExitThreadSafe();
                    return;
                }

                //  Screenshot(s)
                if (MyInput.Static.IsNewGameControlPressed(MyControlsSpace.SCREENSHOT))
                {
                    MyGuiAudio.PlaySound(MyGuiSounds.HudMouseClick);
                    TakeScreenshot();
                }

                bool newPressf12 = MyInput.Static.IsNewKeyPressed(MyKeys.F12);
                bool newPressf2  = MyInput.Static.IsNewKeyPressed(MyKeys.F2);
                if ((newPressf2 || newPressf12) && MyInput.Static.IsAnyShiftKeyPressed() && MyInput.Static.IsAnyAltKeyPressed())
                {
                    if (MySession.Static != null && MySession.Static.CreativeMode)
                    {
                        if (newPressf12)
                        {
                            MyDebugDrawSettings.DEBUG_DRAW_PHYSICS = !MyDebugDrawSettings.DEBUG_DRAW_PHYSICS;
                            if (!m_shapeRenderingMessageBoxShown)
                            {
                                m_shapeRenderingMessageBoxShown = true;
                                AddScreen(MyGuiSandbox.CreateMessageBox(
                                              messageCaption: new StringBuilder("PHYSICS SHAPES"),
                                              messageText: new StringBuilder("Enabled physics shapes rendering. This feature is for modders only and is not part of the gameplay.")));
                            }
                        }
                    }
                    else
                    {
                        AddScreen(MyGuiSandbox.CreateMessageBox(
                                      messageCaption: new StringBuilder("MODDING HELPER KEYS"),
                                      messageText: new StringBuilder("Use of helper key combinations for modders is only allowed in creative mode.")));
                    }
                    return;
                }

                if (MyInput.Static.IsNewKeyPressed(MyKeys.H) && MyInput.Static.IsAnyCtrlKeyPressed())
                {
                    if (MyFakes.ENABLE_NETGRAPH)
                    {
                        MyHud.IsNetgraphVisible = !MyHud.IsNetgraphVisible;
                    }
                }

                if (MyInput.Static.IsNewKeyPressed(MyKeys.F11))
                {
                    if (MyInput.Static.IsAnyShiftKeyPressed() && !MyInput.Static.IsAnyCtrlKeyPressed())
                    {
                        SwitchTimingScreen();
                    }
                }

                if (MyFakes.ENABLE_MISSION_SCREEN && MyInput.Static.IsNewKeyPressed(MyKeys.U))
                {
                    MyScreenManager.AddScreen(new MyGuiScreenMission());
                }

                if (!MyInput.Static.ENABLE_DEVELOPER_KEYS && Sync.MultiplayerActive && m_currentDebugScreen is MyGuiScreenDebugOfficial)
                {
                    RemoveScreen(m_currentDebugScreen);
                    m_currentDebugScreen = null;
                }

                bool inputHandled = false;

                if (MySession.Static != null && MySession.Static.CreativeMode ||
                    MyInput.Static.ENABLE_DEVELOPER_KEYS)
                {
                    F12Handling();
                }

                if (MyInput.Static.ENABLE_DEVELOPER_KEYS)
                {
                    //  Statistics screen
                    if (MyInput.Static.IsNewKeyPressed(MyKeys.F11) && !MyInput.Static.IsAnyShiftKeyPressed() && MyInput.Static.IsAnyCtrlKeyPressed())
                    {
                        SwitchStatisticsScreen();
                    }

                    if (MyInput.Static.IsAnyShiftKeyPressed() && MyInput.Static.IsAnyAltKeyPressed() && MyInput.Static.IsAnyCtrlKeyPressed() &&
                        MyInput.Static.IsNewKeyPressed(MyKeys.Home))
                    {
                        throw new InvalidOperationException("Controlled crash");
                    }

                    // Forge GC to run
                    if (MyInput.Static.IsNewKeyPressed(MyKeys.Pause) && MyInput.Static.IsAnyShiftKeyPressed())
                    {
                        GC.Collect(GC.MaxGeneration);
                    }

                    if (MyInput.Static.IsAnyCtrlKeyPressed() && MyInput.Static.IsNewKeyPressed(MyKeys.F2))
                    {
                        //Reload textures
                        if (MyInput.Static.IsKeyPress(MyKeys.LeftShift))
                        {
                            MyDefinitionManager.Static.ReloadDecalMaterials();
                            VRageRender.MyRenderProxy.ReloadTextures();
                        }
                        else
                        if (MyInput.Static.IsKeyPress(MyKeys.LeftAlt))
                        {
                            VRageRender.MyRenderProxy.ReloadModels();
                        }
                        else
                        {
                            VRageRender.MyRenderProxy.ReloadEffects();
                        }
                    }

                    //WS size
                    if (MyInput.Static.IsNewKeyPressed(MyKeys.F3) && MyInput.Static.IsKeyPress(MyKeys.LeftShift))
                    {
#if !XB1
                        WinApi.SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle, -1, -1);
#endif // !XB1
                    }

                    inputHandled = HandleDebugInput();
                }

                if (!inputHandled)
                {
                    MyScreenManager.HandleInput();
                }
            }
            finally
            {
                ProfilerShort.End();
            }
        }
Esempio n. 13
0
 public override void Stop()
 {
     MySandboxGame.ExitThreadSafe();
 }
Esempio n. 14
0
 public static void ExitGame()
 {
     MyAnalyticsTracker.SendGameEnd("Exit to Windows", MySandboxGame.TotalTimeInMilliseconds / 1000);
     MyScreenManager.CloseAllScreensNowExcept(null);
     MySandboxGame.ExitThreadSafe();
 }
Esempio n. 15
0
 private static void Stop(string[] args)
 {
     MySandboxGame.Log.WriteLineAndConsole("Executing +stop command");
     MySandboxGame.ExitThreadSafe();
 }