예제 #1
0
파일: VRageGame.cs 프로젝트: szczepix/Torch
        private void Create()
        {
            bool dedicated = true;

            Environment.SetEnvironmentVariable("SteamAppId", _appSteamId.ToString());
            SpaceEngineersGame.SetupBasicGameInfo();
            SpaceEngineersGame.SetupPerGameSettings();
            MyFinalBuildConstants.APP_VERSION       = MyPerGameSettings.BasicGameInfo.GameVersion;
            MySessionComponentExtDebug.ForceDisable = true;
            MyPerGameSettings.SendLogToKeen         = false;
            // SpaceEngineersGame.SetupAnalytics();

            //not implemented by keen.. removed in cross-play update
            //MyVRage.Platform.InitScripting(MyVRageScripting.Create());
            _ = MyVRage.Platform.Scripting;

            MyFileSystem.ExePath = Path.GetDirectoryName(typeof(SpaceEngineersGame).Assembly.Location);

            _tweakGameSettings();

            MyFileSystem.Reset();
            MyInitializer.InvokeBeforeRun(_appSteamId, _appName, _userDataPath);

            _log.Info("Loading Dedicated Config");
            // object created in SpaceEngineersGame.SetupPerGameSettings()
            MySandboxGame.ConfigDedicated.Load();
            MyPlatformGameSettings.CONSOLE_COMPATIBLE = MySandboxGame.ConfigDedicated.ConsoleCompatibility;

            //Type.GetType("VRage.Steam.MySteamService, VRage.Steam").GetProperty("IsActive").GetSetMethod(true).Invoke(service, new object[] {SteamAPI.Init()});
            _log.Info("Initializing network services");

            var isEos = TorchBase.Instance.Config.UgcServiceType == UGCServiceType.EOS;

            if (isEos)
            {
                _log.Info("Running on Epic Online Services.");
                _log.Warn("Steam workshop will not work with current settings. Some functions might not work properly!");
            }

            var aggregator = new MyServerDiscoveryAggregator();

            MyServiceManager.Instance.AddService <IMyServerDiscovery>(aggregator);

            IMyGameService service;

            if (isEos)
            {
                service = MyEOSService.Create();

                MyEOSService.InitNetworking(dedicated,
                                            "Space Engineers",
                                            service,
                                            "xyza7891A4WeGrpP85BTlBa3BSfUEABN",
                                            "ZdHZVevSVfIajebTnTmh5MVi3KPHflszD9hJB7mRkgg",
                                            "24b1cd652a18461fa9b3d533ac8d6b5b",
                                            "1958fe26c66d4151a327ec162e4d49c8",
                                            "07c169b3b641401496d352cad1c905d6",
                                            "https://retail.epicgames.com/",
                                            MyEOSService.CreatePlatform(),
                                            MySandboxGame.ConfigDedicated.VerboseNetworkLogging,
                                            Enumerable.Empty <string>(),
                                            aggregator,
                                            MyMultiplayer.Channels);

                var mockingInventory = new MyMockingInventory(service);
                MyServiceManager.Instance.AddService <IMyInventoryService>(mockingInventory);
            }
            else
            {
                service = MySteamGameService.Create(dedicated, _appSteamId);
                MyGameService.WorkshopService.AddAggregate(MySteamUgcService.Create(_appSteamId, service));
                MySteamGameService.InitNetworking(dedicated,
                                                  service,
                                                  "Space Engineers",
                                                  aggregator);
            }

            MyServiceManager.Instance.AddService(service);

            MyGameService.WorkshopService.AddAggregate(MyModIoService.Create(service, "spaceengineers", "264",
                                                                             "1fb4489996a5e8ffc6ec1135f9985b5b", "331", "f2b64abe55452252b030c48adc0c1f0e",
                                                                             MyPlatformGameSettings.UGC_TEST_ENVIRONMENT, true));

            if (!isEos && !MyGameService.HasGameServer)
            {
                _log.Warn("Network service is not running! Please reinstall dedicated server.");
                return;
            }

            _log.Info("Initializing services");
            MyServiceManager.Instance.AddService <IMyMicrophoneService>(new MyNullMicrophone());

            MyNetworkMonitor.Init();

            _log.Info("Services initialized");
            MySandboxGame.InitMultithreading();
            // MyInitializer.InitCheckSum();


            // Hook into the VRage plugin system for updates.
            _getVRagePluginList().Add(_torch);

            if (!MySandboxGame.IsReloading)
            {
                MyFileSystem.InitUserSpecific(dedicated ? null : MyGameService.UserId.ToString());
            }
            MySandboxGame.IsReloading = dedicated;

            // render init
            {
                IMyRender renderer = null;
                if (dedicated)
                {
                    renderer = new MyNullRender();
                }
                else
                {
                    MyPerformanceSettings preset = MyGuiScreenOptionsGraphics.GetPreset(MyRenderPresetEnum.NORMAL);
                    MyRenderProxy.Settings.User = MyVideoSettingsManager.GetGraphicsSettingsFromConfig(ref preset, false)
                                                  .PerformanceSettings.RenderSettings;
                    MyStringId graphicsRenderer = MySandboxGame.Config.GraphicsRenderer;
                    if (graphicsRenderer == MySandboxGame.DirectX11RendererKey)
                    {
                        renderer = new MyDX11Render(new MyRenderSettings?(MyRenderProxy.Settings));
                        if (!renderer.IsSupported)
                        {
                            MySandboxGame.Log.WriteLine(
                                "DirectX 11 renderer not supported. No renderer to revert back to.");
                            renderer = null;
                        }
                    }
                    if (renderer == null)
                    {
                        throw new MyRenderException(
                                  "The current version of the game requires a Dx11 card. \\n For more information please see : http://blog.marekrosa.org/2016/02/space-engineers-news-full-source-code_26.html",
                                  MyRenderExceptionEnum.GpuNotSupported);
                    }
                    MySandboxGame.Config.GraphicsRenderer = graphicsRenderer;
                }
                MyRenderProxy.Initialize(renderer);
                MyRenderProfiler.SetAutocommit(false);
                //This broke services?
                //MyRenderProfiler.InitMemoryHack("MainEntryPoint");
            }

            // Loads object builder serializers. Intuitive, right?
            _log.Info("Setting up serializers");
            MyPlugins.RegisterGameAssemblyFile(MyPerGameSettings.GameModAssembly);
            if (MyPerGameSettings.GameModBaseObjBuildersAssembly != null)
            {
                MyPlugins.RegisterBaseGameObjectBuildersAssemblyFile(MyPerGameSettings.GameModBaseObjBuildersAssembly);
            }
            MyPlugins.RegisterGameObjectBuildersAssemblyFile(MyPerGameSettings.GameModObjBuildersAssembly);
            MyPlugins.RegisterSandboxAssemblyFile(MyPerGameSettings.SandboxAssembly);
            MyPlugins.RegisterSandboxGameAssemblyFile(MyPerGameSettings.SandboxGameAssembly);
            //typeof(MySandboxGame).GetMethod("Preallocate", BindingFlags.Static | BindingFlags.NonPublic).Invoke(null, null);
            MyGlobalTypeMetadata.Static.Init(false);
        }
예제 #2
0
        //  Main method
        static void Main(string[] args)
        {
#if XB1
            XB1Interface.XB1Interface.Init();
            MyAssembly.Init();
#endif
            SpaceEngineersGame.SetupBasicGameInfo();

            m_startup = new MyCommonProgramStartup(args);
            if (m_startup.PerformReporting())
            {
                return;
            }
            m_startup.PerformAutoconnect();
#if !XB1
            if (!m_startup.CheckSingleInstance())
            {
                return;
            }
#endif // !XB1
            var appDataPath = m_startup.GetAppDataPath();
            MyInitializer.InvokeBeforeRun(AppId, MyPerGameSettings.BasicGameInfo.ApplicationName, appDataPath);
            MyInitializer.InitCheckSum();
            m_startup.InitSplashScreen();
            if (!m_startup.Check64Bit())
            {
                return;
            }

            m_startup.DetectSharpDxLeaksBeforeRun();
            using (MySteamService steamService = new MySteamService(MySandboxGame.IsDedicated, AppId))
            {
                m_renderer = null;
                SpaceEngineersGame.SetupPerGameSettings();
                SpaceEngineersGame.SetupRender();

                try
                {
                    InitializeRender();
                }
                catch (MyRenderException ex)
                {
#if !XB1
                    MessageBox.Show(ex.Message);
#else // XB1
                    System.Diagnostics.Debug.Assert(false, "InitializeRender failed");
#endif // XB1
                    return;
                }

                VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("MyProgram.Init");

                VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("MySteam.Init()");
                if (!m_startup.CheckSteamRunning(steamService))
                {
                    return;
                }
                VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock();

                VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("new MySandboxGame()");

                VRageGameServices services = new VRageGameServices(steamService);

                if (!MySandboxGame.IsDedicated)
                {
                    MyFileSystem.InitUserSpecific(steamService.UserId.ToString());
                }

                using (SpaceEngineersGame game = new SpaceEngineersGame(services, args))
                {
                    VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock();
                    VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock();
                    game.Run(disposeSplashScreen: m_startup.DisposeSplashScreen);
                }
            }
            m_startup.DetectSharpDxLeaksAfterRun();

#if PROFILING
            MyPerformanceTimer.WriteToLog();
#endif
            MyInitializer.InvokeAfterRun();
        }
        public bool StartServer(string instanceName = "", string overridePath = "", bool useConsole = true)
        {
            try
            {
                Sandbox.Engine.Platform.Game.IsDedicated = true;
                MyFileSystem.Reset( );

                //Prepare the parameters
                bool     isUsingInstance = instanceName != string.Empty;
                object[] methodParams    =
                {
                    instanceName,
                    overridePath,
                    isUsingInstance,
                    useConsole
                };

                //Initialize config
                SpaceEngineersGame.SetupPerGameSettings();
                SpaceEngineersGame.SetupBasicGameInfo();
                if (MyFinalBuildConstants.APP_VERSION == null) //KEEN WHAT THE F**K
                {
                    MyFinalBuildConstants.APP_VERSION = MyPerGameSettings.BasicGameInfo.GameVersion;
                }
                MyPerGameSettings.SendLogToKeen       = DedicatedServer.SendLogToKeen;
                MyPerServerSettings.GameName          = MyPerGameSettings.GameName;
                MyPerServerSettings.GameNameSafe      = MyPerGameSettings.GameNameSafe;
                MyPerServerSettings.GameDSName        = MyPerServerSettings.GameNameSafe + "Dedicated";
                MyPerServerSettings.GameDSDescription = "Your place for space engineering, destruction and exploring.";
                MyPerServerSettings.AppId             = 0x3bc72;

                //Start the server
                MethodInfo dedicatedServerRunMainMethod = InternalType.GetMethod(DedicatedServerRunMainMethod, BindingFlags.Static | BindingFlags.NonPublic);
                dedicatedServerRunMainMethod.Invoke(null, methodParams);
                ApplicationLog.BaseLog.Info(MyLog.Default.GetFilePath());

                return(true);
            }

            /* these are all redundant
             *          catch ( Win32Exception ex )
             *          {
             *                  ApplicationLog.BaseLog.Error( ex );
             *
             *                  return false;
             *          }
             *          catch ( ExternalException ex )
             *          {
             *                  ApplicationLog.BaseLog.Error( ex );
             *
             *                  return false;
             *          }
             *          catch ( TargetInvocationException ex )
             *          {
             *  //Generally, we won't log this, since it will always be thrown on server stop.
             *  //if ( ExtenderOptions.IsDebugging )
             *      ApplicationLog.BaseLog.Error( ex );
             *  //ApplicationLog.BaseLog.Trace( ex );
             *
             *  return false;
             *          }
             */
            catch (Exception ex)
            {
                ApplicationLog.BaseLog.Error(ex);

                return(false);
            }

            /*
             * finally
             * {
             * _instance = null;
             * Reset();
             * if (_domain != null)
             * {
             *      AppDomain.Unload(_domain);
             * }
             *
             * GC.Collect();
             * GC.WaitForPendingFinalizers();
             * }
             */
        }
예제 #4
0
        private void Create()
        {
            bool dedicated = Sandbox.Engine.Platform.Game.IsDedicated;

            Environment.SetEnvironmentVariable("SteamAppId", _appSteamId.ToString());
            var service = MySteamServiceWrapper.Init(dedicated, _appSteamId);

            MyServiceManager.Instance.AddService <IMyGameService>(service);
            var serviceInstance = MySteamUgcService.Create(_appSteamId, service);

            MyServiceManager.Instance.AddService <IMyUGCService>(serviceInstance);
            if (dedicated && !MyGameService.HasGameServer)
            {
                _log.Warn("Steam service is not running! Please reinstall dedicated server.");
                return;
            }

            SpaceEngineersGame.SetupBasicGameInfo();
            SpaceEngineersGame.SetupPerGameSettings();
            MyFinalBuildConstants.APP_VERSION       = MyPerGameSettings.BasicGameInfo.GameVersion;
            MySessionComponentExtDebug.ForceDisable = true;
            MyPerGameSettings.SendLogToKeen         = false;
            // SpaceEngineersGame.SetupAnalytics();

            MyFileSystem.ExePath = Path.GetDirectoryName(typeof(SpaceEngineersGame).Assembly.Location);

            _tweakGameSettings();

            MyFileSystem.Reset();
            MyInitializer.InvokeBeforeRun(_appSteamId, _appName, _userDataPath);
            MySandboxGame.InitMultithreading();
            // MyInitializer.InitCheckSum();


            // Hook into the VRage plugin system for updates.
            _getVRagePluginList().Add(_torch);

            if (!MySandboxGame.IsReloading)
            {
                MyFileSystem.InitUserSpecific(dedicated ? null : MyGameService.UserId.ToString());
            }
            MySandboxGame.IsReloading = dedicated;

            // render init
            {
                IMyRender renderer = null;
                if (dedicated)
                {
                    renderer = new MyNullRender();
                }
                else
                {
                    MyPerformanceSettings preset = MyGuiScreenOptionsGraphics.GetPreset(MyRenderPresetEnum.NORMAL);
                    MyRenderProxy.Settings.User = MyVideoSettingsManager.GetGraphicsSettingsFromConfig(ref preset, false)
                                                  .PerformanceSettings.RenderSettings;
                    MyStringId graphicsRenderer = MySandboxGame.Config.GraphicsRenderer;
                    if (graphicsRenderer == MySandboxGame.DirectX11RendererKey)
                    {
                        renderer = new MyDX11Render(new MyRenderSettings?(MyRenderProxy.Settings));
                        if (!renderer.IsSupported)
                        {
                            MySandboxGame.Log.WriteLine(
                                "DirectX 11 renderer not supported. No renderer to revert back to.");
                            renderer = null;
                        }
                    }
                    if (renderer == null)
                    {
                        throw new MyRenderException(
                                  "The current version of the game requires a Dx11 card. \\n For more information please see : http://blog.marekrosa.org/2016/02/space-engineers-news-full-source-code_26.html",
                                  MyRenderExceptionEnum.GpuNotSupported);
                    }
                    MySandboxGame.Config.GraphicsRenderer = graphicsRenderer;
                }
                MyRenderProxy.Initialize(renderer);
                MyRenderProfiler.SetAutocommit(false);
                //This broke services?
                //MyRenderProfiler.InitMemoryHack("MainEntryPoint");
            }

            // Loads object builder serializers. Intuitive, right?
            _log.Info("Setting up serializers");
            MyPlugins.RegisterGameAssemblyFile(MyPerGameSettings.GameModAssembly);
            if (MyPerGameSettings.GameModBaseObjBuildersAssembly != null)
            {
                MyPlugins.RegisterBaseGameObjectBuildersAssemblyFile(MyPerGameSettings.GameModBaseObjBuildersAssembly);
            }
            MyPlugins.RegisterGameObjectBuildersAssemblyFile(MyPerGameSettings.GameModObjBuildersAssembly);
            MyPlugins.RegisterSandboxAssemblyFile(MyPerGameSettings.SandboxAssembly);
            MyPlugins.RegisterSandboxGameAssemblyFile(MyPerGameSettings.SandboxGameAssembly);
            //typeof(MySandboxGame).GetMethod("Preallocate", BindingFlags.Static | BindingFlags.NonPublic).Invoke(null, null);
            MyGlobalTypeMetadata.Static.Init(false);
        }
예제 #5
0
        // This is mostly copied from MyProgram.Main(), with UI stripped out.
        private static void InitSandbox(string instancepath)
        {
            MyFakes.ENABLE_INFINARIO = false;

            if (m_spacegame != null)
            {
                m_spacegame.Exit();
            }

            SpaceEngineersGame.SetupBasicGameInfo();
            m_startup = new MyCommonProgramStartup(new string[] { });

            var appDataPath = m_startup.GetAppDataPath();

            MyInitializer.InvokeBeforeRun(AppId_SE, MyPerGameSettings.BasicGameInfo.ApplicationName + "ModTool", appDataPath);
            MyInitializer.InitCheckSum();

            if (!m_startup.Check64Bit())
            {
                return;
            }

            m_steamService = new MySteamService(MySandboxGame.IsDedicated, AppId_SE);
            SpaceEngineersGame.SetupPerGameSettings();


            if (System.Diagnostics.Debugger.IsAttached)
            {
                m_startup.CheckSteamRunning(m_steamService);        // Just give the warning message box when debugging, ignore for release
            }
            VRageGameServices services = new VRageGameServices(m_steamService);

            if (!MySandboxGame.IsDedicated)
            {
                MyFileSystem.InitUserSpecific(m_steamService.UserId.ToString());
            }

            try
            {
                // NOTE: an assert may be thrown in debug, about missing Tutorials.sbx. Ignore it.
                m_spacegame = new SpaceEngineersGame(services, null);

                // Initializing the workshop means the categories are available
                var initWorkshopMethod = typeof(SpaceEngineersGame).GetMethod("InitSteamWorkshop", BindingFlags.NonPublic | BindingFlags.Instance);
                MyDebug.AssertDebug(initWorkshopMethod != null);

                if (initWorkshopMethod != null)
                {
                    var parameters = initWorkshopMethod.GetParameters();
                    MyDebug.AssertDebug(parameters.Count() == 0);
                }

                if (initWorkshopMethod != null)
                {
                    initWorkshopMethod.Invoke(m_spacegame, null);
                }
                else
                {
                    MySandboxGame.Log.WriteLineAndConsole(string.Format(Constants.ERROR_Reflection, "InitSteamWorkshop"));
                }
            }
            catch (Exception ex)
            {
                // This shouldn't fail, but don't stop even if it does
                MySandboxGame.Log.WriteLineAndConsole("An exception occured, ignoring: " + ex.Message);
            }
        }