Example #1
0
        public void Init(object gameInstance)
        {
            mutex = new Mutex(true, appName, out bool createdNew);

            if (!createdNew)
            {
                return;
            }

            Game = (SpaceEngineersGame)gameInstance;

            process    = Process.GetCurrentProcess();
            mainthread = Thread.CurrentThread;

            RecorderApplicationthread = new Thread(StartApplication);
            RecorderApplicationthread.IsBackground = true;
            RecorderApplicationthread.Start();
            CommunicationThreadVideo = new Thread(ModCommunicationVideo);
            CommunicationThreadVideo.IsBackground = true;
            CommunicationThreadVideo.Start();
            CommunicationThreadAudio = new Thread(ModCommunicationAudio);
            CommunicationThreadAudio.IsBackground = true;
            CommunicationThreadAudio.Start();
            //MyLog.Default.WriteLine(gameInstance.ToString());
        }
Example #2
0
        /// <summary>
        /// Manually initializes definitions and other stuff we need to load the DS config serializer.
        /// Touch this and die.
        /// </summary>
        private static void InitSandbox()
        {
            FileSystem.InitMyFileSystem();

            //Infinario should be disabled on DS
            MyFakes.ENABLE_INFINARIO = false;

            MyLog.Default        = MySandboxGame.Log;
            MySandboxGame.Config = new MyConfig("SpaceEngineers.cfg");
            MySandboxGame.Config.Load();
            SpaceEngineersGame.SetupPerGameSettings();
            SpaceEngineersGame.SetupBasicGameInfo();

            //all this is basically copied from the MySandboxGame ctor
            //manually initializing this stuff prevents Steam from detecting SESE as an instance of the game
            MyPlugins.RegisterGameAssemblyFile(MyPerGameSettings.GameModAssembly);
            if (MyPerGameSettings.GameModBaseObjBuildersAssembly != null)
            {
                MyPlugins.RegisterBaseGameObjectBuildersAssemblyFile(MyPerGameSettings.GameModBaseObjBuildersAssembly);
            }
            MyPlugins.RegisterGameObjectBuildersAssemblyFile(MyPerGameSettings.GameModObjBuildersAssembly);
            MyPlugins.RegisterSandboxAssemblyFile(MyPerGameSettings.SandboxAssembly);
            MyPlugins.RegisterSandboxGameAssemblyFile(MyPerGameSettings.SandboxGameAssembly);
            MyPlugins.RegisterFromArgs(null);
            MyPlugins.Load();
            MyGlobalTypeMetadata.Static.Init();
            MyDefinitionManager.Static.PreloadDefinitions();
            MyDefinitionManager.Static.PrepareBaseDefinitions();
            MyDefinitionManager.Static.LoadScenarios();
            //MyTutorialHelper.Init();
            System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(typeof(MyObjectBuilder_Base).TypeHandle);
        }
Example #3
0
        public virtual void Init()
        {
            Debug.Assert(!_init, "Torch instance is already initialized.");

            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

            SpaceEngineersGame.SetupBasicGameInfo();
            SpaceEngineersGame.SetupPerGameSettings();
            TorchVersion = Assembly.GetEntryAssembly().GetName().Version;
            GameVersion  = new Version(new MyVersion(MyPerGameSettings.BasicGameInfo.GameVersion.Value).FormattedText.ToString().Replace("_", "."));
            var verInfo = $"Torch {TorchVersion}, SE {GameVersion}";

            Console.Title = verInfo;
#if DEBUG
            Log.Info("DEBUG");
#else
            Log.Info("RELEASE");
#endif
            Log.Info(verInfo);
            Log.Info($"Executing assembly: {Assembly.GetEntryAssembly().FullName}");
            Log.Info($"Executing directory: {AppDomain.CurrentDomain.BaseDirectory}");

            MySession.OnLoading    += () => SessionLoading?.Invoke();
            MySession.AfterLoading += () => SessionLoaded?.Invoke();
            MySession.OnUnloading  += () => SessionUnloading?.Invoke();
            MySession.OnUnloaded   += () => SessionUnloaded?.Invoke();
            InitUpdater();

            _init = true;
        }
        public SpaceEngineersCore()
        {
            var    contentPath  = ToolboxUpdater.GetApplicationContentPath();
            string userDataPath = SpaceEngineersConsts.BaseLocalPath.DataPath;

            MyFileSystem.Reset();
            MyFileSystem.Init(contentPath, userDataPath);

            MyLog.Default        = MySandboxGame.Log;
            MySandboxGame.Config = new MyConfig("SpaceEngineers.cfg"); // TODO: Is specific to SE, not configurable to ME.
            MySandboxGame.Config.Load();

            MyFileSystem.InitUserSpecific(null);

            SpaceEngineersGame.SetupPerGameSettings();

            VRageRender.MyRenderProxy.Initialize(new MyNullRender());
            // We create a whole instance of MySandboxGame!
            MySandboxGame gameTemp = new MySandboxGame(null);

            // creating MySandboxGame will reset the CurrentUICulture, so I have to reapply it.
            Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfoByIetfLanguageTag(GlobalSettings.Default.LanguageCode);
            SpaceEngineersApi.LoadLocalization();

            _stockDefinitions = new SpaceEngineersResources();
            _stockDefinitions.LoadDefinitions();
            _manageDeleteVoxelList = new List <string>();
        }
Example #5
0
        /// <inheritdoc />
        public virtual void Init()
        {
            Debug.Assert(!_init, "Torch instance is already initialized.");
            SpaceEngineersGame.SetupBasicGameInfo();
            SpaceEngineersGame.SetupPerGameSettings();

            TorchVersion = Assembly.GetEntryAssembly().GetName().Version;
            GameVersion  = new Version(new MyVersion(MyPerGameSettings.BasicGameInfo.GameVersion.Value).FormattedText.ToString().Replace("_", "."));
            var verInfo = $"{Config.InstanceName} - Torch {TorchVersion}, SE {GameVersion}";

            try { Console.Title = verInfo; }
            catch {
                ///Running as service
            }

#if DEBUG
            Log.Info("DEBUG");
#else
            Log.Info("RELEASE");
#endif
            Log.Info(verInfo);
            Log.Info($"Executing assembly: {Assembly.GetEntryAssembly().FullName}");
            Log.Info($"Executing directory: {AppDomain.CurrentDomain.BaseDirectory}");

            MySession.OnLoading    += OnSessionLoading;
            MySession.AfterLoading += OnSessionLoaded;
            MySession.OnUnloading  += OnSessionUnloading;
            MySession.OnUnloaded   += OnSessionUnloaded;
            RegisterVRagePlugin();
            Managers.Attach();
            _init = true;
        }
Example #6
0
        /// <summary>
        /// Public Constructor for WindowsServiceInstaller.
        /// - Put all of your Initialization code here.
        /// </summary>
        public WindowsServiceInstaller()
        {
            SpaceEngineersGame.SetupBasicGameInfo();
            SpaceEngineersGame.SetupPerGameSettings();

            ServiceProcessInstaller serviceProcessInstaller =
                new ServiceProcessInstaller();

            m_serviceInstaller = new ServiceInstaller();

            //# Service Account Information
            serviceProcessInstaller.Account  = ServiceAccount.LocalSystem;
            serviceProcessInstaller.Username = null;
            serviceProcessInstaller.Password = null;



            m_serviceInstaller.DisplayName = MyPerServerSettings.GameName + " dedicated server";
            //# This must be identical to the WindowsService.ServiceBase name
            //# set in the constructor of WindowsService.cs
            m_serviceInstaller.ServiceName = m_serviceInstaller.DisplayName;
            m_serviceInstaller.Description = MyPerServerSettings.GameDSDescription;

            this.Installers.Add(m_serviceInstaller);

            //# Service Information
            m_serviceInstaller.StartType = ServiceStartMode.Automatic;
            this.Installers.Add(serviceProcessInstaller);
        }
Example #7
0
        static void Main(string[] args)
        {
            SpaceEngineersGame.SetupBasicGameInfo();
            SpaceEngineersGame.SetupPerGameSettings();

            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.";

            MySessionComponentExtDebug.ForceDisable = true;

            MyPerServerSettings.AppId = 244850;

            ConfigForm <MyObjectBuilder_SessionSettings> .LogoImage      = SpaceEngineersDedicated.Properties.Resources.SpaceEngineersDSLogo;
            ConfigForm <MyObjectBuilder_SessionSettings> .GameAttributes = Game.SpaceEngineers;
            ConfigForm <MyObjectBuilder_SessionSettings> .OnReset        = delegate
            {
                SpaceEngineersGame.SetupBasicGameInfo();
                SpaceEngineersGame.SetupPerGameSettings();
            };
            MyFinalBuildConstants.APP_VERSION = MyPerGameSettings.BasicGameInfo.GameVersion;

            DedicatedServer.Run <MyObjectBuilder_SessionSettings>(args);
        }
Example #8
0
        public SpaceEngineersCore()
        {
            var    contentPath  = ToolboxUpdater.GetApplicationContentPath();
            string userDataPath = SpaceEngineersConsts.BaseLocalPath.DataPath;

            MyFileSystem.Reset();
            MyFileSystem.Init(contentPath, userDataPath);

            MyLog.Default        = MySandboxGame.Log;
            MySandboxGame.Config = new MyConfig("SpaceEngineers.cfg"); // TODO: Is specific to SE, not configurable to ME.
            MySandboxGame.Config.Load();

            MyFileSystem.InitUserSpecific(null);

            SpaceEngineersGame.SetupPerGameSettings();

            VRageRender.MyRenderProxy.Initialize(new MyNullRender());
            // We create a whole instance of MySandboxGame!
            // If this is causing an exception, then there is a missing dependency.
            MySandboxGame gameTemp = new MySandboxGame(new string[] { "-skipintro" });

            // creating MySandboxGame will reset the CurrentUICulture, so I have to reapply it.
            Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfoByIetfLanguageTag(GlobalSettings.Default.LanguageCode);
            SpaceEngineersApi.LoadLocalization();
            MyStorageBase.UseStorageCache = false;

            #region MySession creation

            // Replace the private constructor on MySession, so we can create it without getting involed with Havok and other depdancies.
            var keenStart = typeof(Sandbox.Game.World.MySession).GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic, null, new Type[] { typeof(MySyncLayer), typeof(bool) }, null);
            var ourStart  = typeof(SEToolbox.Interop.MySession).GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic, null, new Type[] { typeof(MySyncLayer), typeof(bool) }, null);
            ReflectionUtil.ReplaceMethod(ourStart, keenStart);

            // Create an empty instance of MySession for use by low level code.
            Sandbox.Game.World.MySession mySession = ReflectionUtil.ConstructPrivateClass <Sandbox.Game.World.MySession>(new Type[0], new object[0]);
            ReflectionUtil.ConstructField(mySession, "m_sessionComponents"); // Required as the above code doesn't populate it during ctor of MySession.
            mySession.Settings = new MyObjectBuilder_SessionSettings {
                EnableVoxelDestruction = true
            };

            VRage.MyVRage.Init(new ToolboxPlatform());

            // change for the Clone() method to use XML cloning instead of Protobuf because of issues with MyObjectBuilder_CubeGrid.Clone()
            ReflectionUtil.SetFieldValue(typeof(VRage.ObjectBuilders.MyObjectBuilderSerializer), "ENABLE_PROTOBUFFERS_CLONING", false);

            // Assign the instance back to the static.
            Sandbox.Game.World.MySession.Static = mySession;

            Sandbox.Game.GameSystems.MyHeightMapLoadingSystem.Static = new MyHeightMapLoadingSystem();
            Sandbox.Game.GameSystems.MyHeightMapLoadingSystem.Static.LoadData();

            #endregion

            _stockDefinitions = new SpaceEngineersResources();
            _stockDefinitions.LoadDefinitions();
            _manageDeleteVoxelList = new List <string>();
        }
Example #9
0
 public override void Start()
 {
     using (var spaceEngineersGame = new SpaceEngineersGame(_services, RunArgs))
     {
         Log.Info("Starting client");
         spaceEngineersGame.OnGameLoaded += SpaceEngineersGame_OnGameLoaded;
         spaceEngineersGame.Run();
     }
 }
Example #10
0
        private void Destroy()
        {
            _game.Dispose();
            _game = null;

            MyGameService.ShutDown();

            _getVRagePluginList().Remove(_torch);

            MyInitializer.InvokeAfterRun();
        }
Example #11
0
 public override void Start()
 {
     using (var spaceEngineersGame = new SpaceEngineersGame(RunArgs))
     {
         Log.Info("Starting client");
         OverrideMenus();
         spaceEngineersGame.OnGameLoaded += SpaceEngineersGame_OnGameLoaded;
         spaceEngineersGame.OnGameExit   += Dispose;
         spaceEngineersGame.Run(false, _startup.DisposeSplashScreen);
     }
 }
Example #12
0
        public override void Init()
        {
            Log.Info("Initializing Torch Client");
            base.Init();

            if (!File.Exists("steam_appid.txt"))
            {
                Directory.SetCurrentDirectory(Path.GetDirectoryName(typeof(VRage.FastResourceLock).Assembly.Location) + "\\..");
            }

            SpaceEngineersGame.SetupBasicGameInfo();
            _startup = new MyCommonProgramStartup(RunArgs);
            if (_startup.PerformReporting())
            {
                return;
            }

            _startup.PerformAutoconnect();
            if (!_startup.CheckSingleInstance())
            {
                return;
            }

            var appDataPath = _startup.GetAppDataPath();

            MyInitializer.InvokeBeforeRun(APP_ID, MyPerGameSettings.BasicGameInfo.ApplicationName, appDataPath);
            MyInitializer.InitCheckSum();
            if (!_startup.Check64Bit())
            {
                return;
            }

            _startup.DetectSharpDxLeaksBeforeRun();
            using (var mySteamService = new SteamService(Game.IsDedicated, APP_ID))
            {
                _renderer = null;
                SpaceEngineersGame.SetupPerGameSettings();

                OverrideMenus();

                InitializeRender();

                _services = new VRageGameServices(mySteamService);
                if (!Game.IsDedicated)
                {
                    MyFileSystem.InitUserSpecific(mySteamService.UserId.ToString());
                }
            }

            _startup.DetectSharpDxLeaksAfterRun();
            MyInitializer.InvokeAfterRun();
        }
Example #13
0
        public override void Init()
        {
            Directory.SetCurrentDirectory(Program.SpaceEngineersInstallAlias);
            MyFileSystem.ExePath = Path.Combine(Program.SpaceEngineersInstallAlias, Program.SpaceEngineersBinaries);
            Log.Info("Initializing Torch Client");
            base.Init();

            SpaceEngineersGame.SetupBasicGameInfo();
            _startup = new MyCommonProgramStartup(RunArgs);
            if (_startup.PerformReporting())
            {
                throw new InvalidOperationException("Torch client won't launch when started in error reporting mode");
            }

            _startup.PerformAutoconnect();
            if (!_startup.CheckSingleInstance())
            {
                throw new InvalidOperationException("Only one instance of Space Engineers can be running at a time.");
            }

            var appDataPath = _startup.GetAppDataPath();

            MyInitializer.InvokeBeforeRun(APP_ID, MyPerGameSettings.BasicGameInfo.ApplicationName, appDataPath);
            MyInitializer.InitCheckSum();
            _startup.InitSplashScreen();
            if (!_startup.Check64Bit())
            {
                throw new InvalidOperationException("Torch requires a 64bit operating system");
            }

            _startup.DetectSharpDxLeaksBeforeRun();
            var steamService = new SteamService(Game.IsDedicated, APP_ID);

            MyServiceManager.Instance.AddService <IMyGameService>(steamService);
            _renderer = null;
            SpaceEngineersGame.SetupPerGameSettings();
            // I'm sorry, but it's what Keen does in SpaceEngineers.MyProgram
#pragma warning disable 612
            SpaceEngineersGame.SetupRender();
#pragma warning restore 612
            InitializeRender();
            if (!_startup.CheckSteamRunning())
            {
                throw new InvalidOperationException("Space Engineers requires steam to be running");
            }

            if (!Game.IsDedicated)
            {
                MyFileSystem.InitUserSpecific(MyGameService.UserId.ToString());
            }
        }
Example #14
0
        private void DoStart()
        {
            _game = new SpaceEngineersGame(_runArgs);

            if (MySandboxGame.FatalErrorDuringInit)
            {
                throw new InvalidOperationException("Failed to start sandbox game: fatal error during init");
            }
            try
            {
                StateChange(GameState.Running);
                _game.Run();
            }
            finally
            {
                StateChange(GameState.Stopped);
            }
        }
Example #15
0
        /// <inheritdoc />
        public virtual void Init()
        {
            Debug.Assert(!_init, "Torch instance is already initialized.");
            SpaceEngineersGame.SetupBasicGameInfo();
            SpaceEngineersGame.SetupPerGameSettings();
            ObjectFactoryInitPatch.ForceRegisterAssemblies();

            Debug.Assert(MyPerGameSettings.BasicGameInfo.GameVersion != null, "MyPerGameSettings.BasicGameInfo.GameVersion != null");
            GameVersion = new MyVersion(MyPerGameSettings.BasicGameInfo.GameVersion.Value);

            try
            {
                Console.Title = $"{Config.InstanceName} - Torch {TorchVersion}, SE {GameVersion}";
            }
            catch
            {
                // Running without a console
            }

#if DEBUG
            Log.Info("DEBUG");
#else
            Log.Info("RELEASE");
#endif
            Log.Info($"Torch Version: {TorchVersion}");
            Log.Info($"Game Version: {GameVersion}");
            Log.Info($"Executing assembly: {Assembly.GetEntryAssembly().FullName}");
            Log.Info($"Executing directory: {AppDomain.CurrentDomain.BaseDirectory}");

            Managers.GetManager <PluginManager>().LoadPlugins();
            Game = new VRageGame(this, TweakGameSettings, SteamAppName, SteamAppId, Config.InstancePath, RunArgs);
            if (!Game.WaitFor(VRageGame.GameState.Stopped))
            {
                Log.Warn("Failed to wait for game to be initialized");
            }
            Managers.Attach();
            _init = true;

            if (GameState >= TorchGameState.Created && GameState < TorchGameState.Unloading)
            {
                // safe to commit here; all important static ctors have run
                PatchManager.CommitInternal();
            }
        }
Example #16
0
        private void DoStart()
        {
            _game = new SpaceEngineersGame(_runArgs);

            if (MySandboxGame.FatalErrorDuringInit)
            {
                _log.Warn("Failed to start sandbox game: fatal error during init");
                return;
            }
            try
            {
                StateChange(GameState.Running);
                _game.Run();
            }
            finally
            {
                StateChange(GameState.Stopped);
            }
        }
Example #17
0
        public void Init()
        {
            SpaceEngineersGame.SetupBasicGameInfo();
            SpaceEngineersGame.SetupPerGameSettings();
            MyPerGameSettings.SendLogToKeen         = false;
            MyPerServerSettings.GameName            = MyPerGameSettings.GameName;
            MyPerServerSettings.GameNameSafe        = MyPerGameSettings.GameNameSafe;
            MyPerServerSettings.GameDSName          = MyPerServerSettings.GameNameSafe + "Dedicated";
            MyPerServerSettings.GameDSDescription   = "Your place for space engineering, destruction and exploring.";
            MySessionComponentExtDebug.ForceDisable = true;
            MyPerServerSettings.AppId = 244850u;
            ConfigForm <MyObjectBuilder_SessionSettings> .GameAttributes = Game.SpaceEngineers;
            ConfigForm <MyObjectBuilder_SessionSettings> .OnReset        = delegate
            {
                SpaceEngineersGame.SetupBasicGameInfo();
                SpaceEngineersGame.SetupPerGameSettings();
            };
            var gameVersion = MyPerGameSettings.BasicGameInfo.GameVersion;

            MyFinalBuildConstants.APP_VERSION = gameVersion ?? 0;
        }
        public static List <string> GetCommonInstanceList( )
        {
            if (string.IsNullOrEmpty(MyPerServerSettings.GameDSName))
            {
                SpaceEngineersGame.SetupPerGameSettings( );
            }

            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;

            string exeName = MyPerServerSettings.GameDSName + ".exe";

            BaseLog.Trace("Game path for service search: {0}", exeName);
            List <string> result = new List <string>( );

            try
            {
                foreach (ServiceController s in ServiceController.GetServices( ))
                {
                    string path = GetServiceInstallPath(s.ServiceName);
                    if (path.IndexOf(exeName, StringComparison.InvariantCultureIgnoreCase) != -1)
                    {
                        BaseLog.Trace("Adding {0} to instance list", s.ServiceName);
                        result.Add(s.ServiceName);
                    }
                }
            }
            catch (Win32Exception win32Exception)
            {
                BaseLog.Error("Could not get instance list. {0}", win32Exception);
            }
            return(result);
        }
Example #19
0
        static void Main(string[] args)
        {
            SpaceEngineersGame.SetupPerGameSettings();

            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 = 244850;

            ConfigForm <MyObjectBuilder_SessionSettings> .LogoImage      = SpaceEngineersDedicated.Properties.Resources.SpaceEngineersDSLogo;
            ConfigForm <MyObjectBuilder_SessionSettings> .GameAttributes = Game.SpaceEngineers;
            ConfigForm <MyObjectBuilder_SessionSettings> .OnReset        = delegate
            {
                SpaceEngineersGame.SetupPerGameSettings();
            };


            DedicatedServer.Run <MyObjectBuilder_SessionSettings>(args);
        }
Example #20
0
        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);
        }
Example #21
0
        public SpaceEngineersCore()
        {
            var    contentPath  = ToolboxUpdater.GetApplicationContentPath();
            string userDataPath = SpaceEngineersConsts.BaseLocalPath.DataPath;

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

            MyLog.Default = MySandboxGame.Log;
            SpaceEngineersGame.SetupBasicGameInfo();
            _startup = new MyCommonProgramStartup(new string[] { });

            //var appDataPath = _startup.GetAppDataPath();
            //MyInitializer.InvokeBeforeRun(AppId, MyPerGameSettings.BasicGameInfo.ApplicationName + "SEToolbox", appDataPath);
            //MyInitializer.InitCheckSum();

            MyFileSystem.Reset();
            MyFileSystem.Init(contentPath, userDataPath);

            // This will start the Steam Service, and Steam will think SE is running.
            // TODO: we don't want to be doing this all the while SEToolbox is running,
            // perhaps a once off during load to fetch of mods then disconnect/Dispose.
            _steamService = MySteamGameService.Create(MySandboxGame.IsDedicated, AppId);
            MyServiceManager.Instance.AddService(_steamService);

            IMyUGCService serviceInstance = MySteamUgcService.Create(AppId, _steamService);

            MyServiceManager.Instance.AddService(serviceInstance);

            MyFileSystem.InitUserSpecific(_steamService.UserId.ToString()); // This sets the save file/path to load games from.
            //MyFileSystem.InitUserSpecific(null);
            //SpaceEngineersWorkshop.MySteam.Dispose();

            MySandboxGame.Config = new MyConfig("SpaceEngineers.cfg"); // TODO: Is specific to SE, not configurable to ME.
            MySandboxGame.Config.Load();

            SpaceEngineersGame.SetupPerGameSettings();

            VRage.MyVRage.Init(new ToolboxPlatform());
            VRage.MyVRage.Platform.Init();

            MySandboxGame.InitMultithreading();

            VRageRender.MyRenderProxy.Initialize(new MyNullRender());

            // We create a whole instance of MySandboxGame!
            // If this is causing an exception, then there is a missing dependency.
            MySandboxGame gameTemp = new DerivedGame(new string[] { "-skipintro" });

            // creating MySandboxGame will reset the CurrentUICulture, so I have to reapply it.
            Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfoByIetfLanguageTag(GlobalSettings.Default.LanguageCode);
            SpaceEngineersApi.LoadLocalization();
            MyStorageBase.UseStorageCache = false;

            // Create an empty instance of MySession for use by low level code.
            var mySession = (Sandbox.Game.World.MySession)FormatterServices.GetUninitializedObject(typeof(Sandbox.Game.World.MySession));

            // Required as the above code doesn't populate it during ctor of MySession.
            ReflectionUtil.ConstructField(mySession, "m_creativeTools");
            ReflectionUtil.ConstructField(mySession, "m_sessionComponents");
            ReflectionUtil.ConstructField(mySession, "m_sessionComponentsForUpdate");

            mySession.Settings = new MyObjectBuilder_SessionSettings {
                EnableVoxelDestruction = true
            };

            // change for the Clone() method to use XML cloning instead of Protobuf because of issues with MyObjectBuilder_CubeGrid.Clone()
            ReflectionUtil.SetFieldValue(typeof(VRage.ObjectBuilders.MyObjectBuilderSerializer), "ENABLE_PROTOBUFFERS_CLONING", false);

            // Assign the instance back to the static.
            Sandbox.Game.World.MySession.Static = mySession;

            var heightMapLoadingSystem = new MyHeightMapLoadingSystem();

            mySession.RegisterComponent(heightMapLoadingSystem, heightMapLoadingSystem.UpdateOrder, heightMapLoadingSystem.Priority);
            heightMapLoadingSystem.LoadData();

            _stockDefinitions = new SpaceEngineersResources();
            _stockDefinitions.LoadDefinitions();
            _manageDeleteVoxelList = new List <string>();
        }
Example #22
0
        public bool LoadGame(string seBinPath, string userDataPath, string savePath)
        {
            if (!Directory.Exists(seBinPath))
            {
                return(false);
            }

            if (!Directory.Exists(savePath))
            {
                return(false);
            }

            if (!savePath.StartsWith(userDataPath, StringComparison.OrdinalIgnoreCase))
            {
                return(false);
            }

            string contentPath = Path.GetFullPath(Path.Combine(seBinPath, @"..\Content"));

            MyFileSystem.Reset();
            MyFileSystem.Init(contentPath, userDataPath);

            MyLog.Default        = MySandboxGame.Log;
            MySandboxGame.Config = new MyConfig("SpaceEngineers.cfg"); // TODO: Is specific to SE, not configurable to ME.
            MySandboxGame.Config.Load();

            MyFileSystem.InitUserSpecific(null);

            SpaceEngineersGame.SetupPerGameSettings();

            VRageRender.MyRenderProxy.Initialize(new MyNullRender());
            // We create a whole instance of MySandboxGame!
            // If this is causing an exception, then there is a missing dependency.
            MySandboxGame gameTemp = new MySandboxGame(null);

            #region Game Localization

            // creating MySandboxGame will reset the CurrentUICulture, so I have to reapply it.
            Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfoByIetfLanguageTag(GlobalSettings.Default.LanguageCode);

            var culture          = System.Threading.Thread.CurrentThread.CurrentUICulture;
            var languageTag      = culture.IetfLanguageTag;
            var localizationPath = Path.Combine(contentPath, @"Data\Localization");
            var codes            = languageTag.Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries);
            var maincode         = codes.Length > 0 ? codes[0] : null;
            var subcode          = codes.Length > 1 ? codes[1] : null;
            MyTexts.Clear();
            MyTexts.LoadTexts(localizationPath, maincode, subcode);

            #endregion

            MyStorageBase.UseStorageCache = false;

            #region MySession creation

            // Replace the private constructor on MySession, so we can create it without getting involed with Havok and other depdancies.
            var keenStart = typeof(Sandbox.Game.World.MySession).GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic, null, new Type[] { typeof(MySyncLayer), typeof(bool) }, null);
            var ourStart  = typeof(EconomyConfigurationEditor.Interop.MySession).GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic, null, new Type[] { typeof(MySyncLayer), typeof(bool) }, null);
            ReflectionUtil.ReplaceMethod(ourStart, keenStart);

            // Create an empty instance of MySession for use by low level code.
            Sandbox.Game.World.MySession mySession = ReflectionUtil.ConstructPrivateClass <Sandbox.Game.World.MySession>(new Type[0], new object[0]);
            ReflectionUtil.ConstructField(mySession, "m_sessionComponents"); // Required as the above code doesn't populate it during ctor of MySession.
            mySession.Settings = new MyObjectBuilder_SessionSettings {
                EnableVoxelDestruction = true
            };

            // Assign the instance back to the static.
            Sandbox.Game.World.MySession.Static = mySession;

            Sandbox.Game.GameSystems.MyHeightMapLoadingSystem.Static = new MyHeightMapLoadingSystem();
            Sandbox.Game.GameSystems.MyHeightMapLoadingSystem.Static.LoadData();

            #endregion

            #region Load Sandbox

            var filename = Path.Combine(savePath, SpaceEngineersConsts.SandBoxCheckpointFilename);

            MyObjectBuilder_Checkpoint checkpoint;
            string errorInformation;
            bool   compressedCheckpointFormat;
            bool   snapshot = false;
            bool   retVal   = SpaceEngineersApi.TryReadSpaceEngineersFile <MyObjectBuilder_Checkpoint>(filename, out checkpoint, out compressedCheckpointFormat, out errorInformation, snapshot);

            if (!retVal)
            {
                return(false);
            }

            #endregion

            MyDefinitionManager.Static.PrepareBaseDefinitions();
            MyDefinitionManager.Static.LoadData(checkpoint.Mods);
            var MaterialIndex = new Dictionary <string, byte>();

            return(true);
        }
Example #23
0
        public void Init(object gameInstance)
        {
            _commandLine = new CommandLine(Environment.CommandLine);

            Game = (SpaceEngineersGame)gameInstance;
        }
Example #24
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();
        }
Example #25
0
 public void Init(object gameInstance)
 {
     Debugger.Launch();
     Game = (SpaceEngineersGame)gameInstance;
     OnStarting();
 }
Example #26
0
        public SpaceEngineersCore()
        {
            var    contentPath  = ToolboxUpdater.GetApplicationContentPath();
            string userDataPath = SpaceEngineersConsts.BaseLocalPath.DataPath;

            MyFileSystem.Reset();
            MyFileSystem.Init(contentPath, userDataPath);

            MyLog.Default        = MySandboxGame.Log;
            MySandboxGame.Config = new MyConfig("SpaceEngineers.cfg"); // TODO: Is specific to SE, not configurable to ME.
            MySandboxGame.Config.Load();

            MyFileSystem.InitUserSpecific(null);

            MyFakes.ENABLE_INFINARIO = false;

            SpaceEngineersGame.SetupPerGameSettings();

            VRageRender.MyRenderProxy.Initialize(new MyNullRender());
            // We create a whole instance of MySandboxGame!
            MySandboxGame gameTemp = new MySandboxGame(null);

            // creating MySandboxGame will reset the CurrentUICulture, so I have to reapply it.
            Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfoByIetfLanguageTag(GlobalSettings.Default.LanguageCode);
            SpaceEngineersApi.LoadLocalization();
            MyStorageBase.UseStorageCache = false;

            try
            {
                // Replace the private constructor on MySession, so we can create it without getting involed with Havok and other depdancies.
                var keenStart = typeof(Sandbox.Game.World.MySession).GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic, null, new Type[] { typeof(MySyncLayer), typeof(bool) }, null);
                var ourStart  = typeof(SEToolbox.Interop.MySession).GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic, null, new Type[] { typeof(MySyncLayer), typeof(bool) }, null);
                ReflectionUtil.ReplaceMethod(ourStart, keenStart);


                // Create an empty instance of MySession for use by low level code.
                ConstructorInfo constructorInfo = typeof(Sandbox.Game.World.MySession).GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic, null, new Type[0], null);
                object          mySession       = constructorInfo.Invoke(new object[0]);

                // Assign the instance back to the static.
                Sandbox.Game.World.MySession.Static          = (Sandbox.Game.World.MySession)mySession;
                Sandbox.Game.World.MySession.Static.Settings = new MyObjectBuilder_SessionSettings {
                    EnableVoxelDestruction = true
                };
            }
            catch (Exception ex)
            {
                Debugger.Break();
            }

            try
            {
                Sandbox.Game.GameSystems.MyHeightMapLoadingSystem.Static = new MyHeightMapLoadingSystem();
                Sandbox.Game.GameSystems.MyHeightMapLoadingSystem.Static.LoadData();
            }
            catch (Exception ex)
            {
                Debugger.Break();
            }

            _stockDefinitions = new SpaceEngineersResources();
            _stockDefinitions.LoadDefinitions();
            _manageDeleteVoxelList = new List <string>();
        }
Example #27
0
        static void RunInternal(string[] args)
        {
            using (MySteamService steamService = new MySteamService(MySandboxGame.IsDedicated, AppId))
            {
                IMyRender renderer = null;

                SpaceEngineersGame.SetupPerGameSettings();

                if (MySandboxGame.IsDedicated)
                {
                    renderer = new MyNullRender();
                }
                else if (MyFakes.ENABLE_DX11_RENDERER)
                {
                    var rendererId = MySandboxGame.Config.GraphicsRenderer;
                    if (rendererId == MySandboxGame.DirectX11RendererKey)
                    {
                        renderer = new MyDX11Render();
                        if (!renderer.IsSupported)
                        {
                            MySandboxGame.Log.WriteLine("DirectX 11 renderer not supported. Reverting to DirectX 9.");
                            renderer = null;
                        }
                    }

                    if (renderer == null)
                    {
                        renderer   = new MyDX9Render();
                        rendererId = MySandboxGame.DirectX9RendererKey;
                    }

                    MySandboxGame.Config.GraphicsRenderer = rendererId;
                }
                else
                {
                    renderer = new MyDX9Render();
                }

                MyFakes.ENABLE_PLANETS &= MySandboxGame.Config.GraphicsRenderer != MySandboxGame.DirectX9RendererKey;

                VRageRender.MyRenderProxy.Initialize(renderer);

                VRageRender.MyRenderProxy.IS_OFFICIAL = MyFinalBuildConstants.IS_OFFICIAL;
                VRageRender.MyRenderProxy.GetRenderProfiler().SetAutocommit(false);
                VRageRender.MyRenderProxy.GetRenderProfiler().InitMemoryHack("MainEntryPoint");
                VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("MyProgram.Init");
                VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("MySteam.Init()");

                if (!MySandboxGame.IsDedicated)
                {
                    if (steamService.IsActive)
                    {
                        steamService.SetNotificationPosition(MySteamService.NotificationPosition.TopLeft);

                        MySandboxGame.Log.WriteLineAndConsole("Steam.IsActive: " + steamService.IsActive);
                        MySandboxGame.Log.WriteLineAndConsole("Steam.IsOnline: " + steamService.IsOnline);
                        MySandboxGame.Log.WriteLineAndConsole("Steam.OwnsGame: " + steamService.OwnsGame);
                        MySandboxGame.Log.WriteLineAndConsole("Steam.UserId: " + steamService.UserId);
                        MySandboxGame.Log.WriteLineAndConsole("Steam.UserName: "******"[n/a]");
                        MySandboxGame.Log.WriteLineAndConsole("Steam.Branch: " + steamService.BranchName ?? "[n/a]");
                        MySandboxGame.Log.WriteLineAndConsole("Build date: " + MySandboxGame.BuildDateTime.ToString("yyyy-MM-dd hh:mm", CultureInfo.InvariantCulture));
                        MySandboxGame.Log.WriteLineAndConsole("Build version: " + MySandboxGame.BuildVersion.ToString());
                    }
                    else if (MyFinalBuildConstants.IS_OFFICIAL) //We dont need Steam only in VS
                    {
                        if (!(steamService.IsActive && steamService.OwnsGame))
                        {
                            if (MyFakes.ENABLE_RUN_WITHOUT_STEAM == false)
                            {
                                MessageBoxWrapper("Steam is not running!", "Please run this game from Steam." + Environment.NewLine + "(restart Steam if already running)");
                                return;
                            }
                        }
                    }
                    else
                    {
                        if (!(steamService.IsActive && steamService.OwnsGame))
                        {
                            if (MyFakes.ENABLE_RUN_WITHOUT_STEAM == false)
                            {
                                MessageBoxWrapper("Steam is not running!", "Game might be unstable when run without Steam!");
                            }
                        }
                    }
                }

                VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock();

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

                VRageGameServices services = new VRageGameServices(steamService);

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

                using (MySandboxGame game = new MySandboxGame(services, args))
                {
                    VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock();
                    VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock();
                    game.Run(disposeSplashScreen: DisposeSplashScreen);
                }
            }
        }
Example #28
0
        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();
                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();
             * }
             */
        }
Example #29
0
 public void Init(object gameInstance)
 {
     Game = (SpaceEngineersGame)gameInstance;
 }
Example #30
0
        private void Create()
        {
            bool dedicated = Sandbox.Engine.Platform.Game.IsDedicated;

            Environment.SetEnvironmentVariable("SteamAppId", _appSteamId.ToString());
            MyServiceManager.Instance.AddService <IMyGameService>(new MySteamService(dedicated, _appSteamId));
            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);
            // 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(MyRenderQualityEnum.NORMAL);
                    MyRenderProxy.Settings.User = MyVideoSettingsManager.GetGraphicsSettingsFromConfig(ref preset)
                                                  .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);
                MyRenderProxy.GetRenderProfiler().SetAutocommit(false);
                MyRenderProxy.GetRenderProfiler().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);
        }