Example #1
0
        private void Reset( )
        {
            SteamReset( );

            /*
             * if (MyAPIGateway.Session != null)
             * {
             *      MyAPIGateway.Session.UnloadDataComponents();
             *      MyAPIGateway.Session.UnloadMultiplayer();
             *      MyAPIGateway.Session.Unload();
             * }
             */

            try
            {
                MyPlugins.Unload( );
            }
            catch { }

            MyAudio.Static.UnloadData( );
            MyAudio.UnloadData( );
            MyFileSystem.Reset( );

            InputReset( );

            PhysicsReset( );
        }
Example #2
0
        public static void Run <T>(string[] args) where T : MyObjectBuilder_SessionSettings, new()
        {
            if (DedicatedServer.ProcessArgs(args))
            {
                return;
            }


            if (Environment.UserInteractive)
            {
                MyPlugins.RegisterGameAssemblyFile(MyPerGameSettings.GameModAssembly);
                MyPlugins.RegisterSandboxAssemblyFile(MyPerGameSettings.SandboxAssembly);
                MyPlugins.RegisterSandboxGameAssemblyFile(MyPerGameSettings.SandboxGameAssembly);
                MyPlugins.RegisterFromArgs(args);
                MyPlugins.Load();
                ShowWindow(GetConsoleWindow(), SW_HIDE);
                MyConfigurator.Start <T>();
                MyPlugins.Unload();
                return;
            }
            else
            {
                MyServiceBase.Run(new WindowsService());
                return;
            }
        }
Example #3
0
        public static void Run <T>(string[] args) where T : MyObjectBuilder_SessionSettings, new()
        {
            if (DedicatedServer.ProcessArgs(args))
            {
                return;
            }


            if (Environment.UserInteractive)
            {
                MyPlugins.RegisterGameAssemblyFile(MyPerGameSettings.GameModAssembly);
                MyPlugins.RegisterGameObjectBuildersAssemblyFile(MyPerGameSettings.GameModObjBuildersAssembly);
                MyPlugins.RegisterSandboxAssemblyFile(MyPerGameSettings.SandboxAssembly);
                MyPlugins.RegisterSandboxGameAssemblyFile(MyPerGameSettings.SandboxGameAssembly);
                MyPlugins.RegisterFromArgs(args);
                MyPlugins.Load();
                bool resultRegisterAssemblies = MyObjectBuilderType.RegisterAssemblies();
                Debug.Assert(resultRegisterAssemblies, "Registering object builders types from assemblies failed.");
                resultRegisterAssemblies = MyObjectBuilderSerializer.RegisterAssembliesAndLoadSerializers();
                Debug.Assert(resultRegisterAssemblies, "Registering object builders serializers from assemblies failed.");
                ShowWindow(GetConsoleWindow(), SW_HIDE);
                MyConfigurator.Start <T>();
                MyPlugins.Unload();
                return;
            }
            else
            {
                MyServiceBase.Run(new WindowsService());
                return;
            }
        }
Example #4
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 #5
0
        public override void Init()
        {
            base.Init();

            Log.Info($"Init server '{Config.InstanceName}' at '{Config.InstancePath}'");

            MyFakes.ENABLE_INFINARIO                = false;
            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               = 244850;
            MyFinalBuildConstants.APP_VERSION       = MyPerGameSettings.BasicGameInfo.GameVersion;

            MyPlugins.RegisterGameAssemblyFile(MyPerGameSettings.GameModAssembly);
            MyPlugins.RegisterGameObjectBuildersAssemblyFile(MyPerGameSettings.GameModObjBuildersAssembly);
            MyPlugins.RegisterSandboxAssemblyFile(MyPerGameSettings.SandboxAssembly);
            MyPlugins.RegisterSandboxGameAssemblyFile(MyPerGameSettings.SandboxGameAssembly);
            MyPlugins.Load();

            MyGlobalTypeMetadata.Static.Init();
            MyInitializer.InvokeBeforeRun(
                MyPerServerSettings.AppId,
                MyPerServerSettings.GameDSName,
                InstancePath, DedicatedServer.AddDateToLog);
        }
Example #6
0
        public void Initialize()
        {
            try
            {
                if (GlobalOptions.PluginsEnabled == false)
                {
                    Log.Info("Plugins are globally disabled - exiting PluginControl.Initialize()");
                    return;
                }
                Log.Info("Plugins are globally enabled - entering PluginControl.Initialize()");

                string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Plugins");
                if (!Directory.Exists("Plugins"))
                {
                    Log.Warn("Directory " + path + " not found. No Plugins will be available.");
                    MyPlugins = new List <IPlugin>();
                    return;
                }
                myDirectoryCatalog = new DirectoryCatalog(path: path, searchPattern: "*.dll");

                catalog = new AggregateCatalog();
                Log.Info("Searching for dlls in path " + myDirectoryCatalog?.FullPath);
                catalog.Catalogs.Add(myDirectoryCatalog);
                container = new CompositionContainer(catalog);
                //Fill the imports of this object
                StartWatch();
                container.ComposeParts(this);

                Log.Info("Plugins found: " + MyPlugins.Count());
                Log.Info("Plugins active: " + MyActivePlugins.Count());
                foreach (var plugin in MyActivePlugins)
                {
                    try
                    {
                        Log.Info("Initializing Plugin " + plugin.ToString());
                        plugin.CustomInitialize(Program.MainForm);
                        plugin.SetIsUnitTest(Utils.IsUnitTest);
                    }
                    catch (Exception e)
                    {
                        Log.Error(e);
                    }
                }
                Log.Info("Initializing Plugins finished.");
            }
            catch (System.Security.SecurityException e)
            {
                string msg = "Well, the Plugin wanted to do something that requires Admin rights. Let's just ignore this: " + Environment.NewLine + Environment.NewLine;
                msg += e.ToString();
                Log.Warn(e, msg);
            }
            catch (Exception e)
            {
                Log.Fatal(e);
                throw;
            }
        }
Example #7
0
        private static void RegisterPlugins()
        {
            MyPlugins.RegisterGameAssemblyFile("SpaceEngineers.Game.dll");
            MyPlugins.RegisterGameObjectBuildersAssemblyFile("SpaceEngineers.ObjectBuilders.dll");
            MyPlugins.RegisterSandboxAssemblyFile("Sandbox.Common.dll");
            MyPlugins.RegisterSandboxGameAssemblyFile("Sandbox.Game.dll");
            MyPlugins.Load();

            MyObjectBuilderType.RegisterAssemblies();
            MyObjectBuilderSerializer.RegisterAssembliesAndLoadSerializers();
        }
Example #8
0
        public SpaceEngineersCore()
        {
            var path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            MyPlugins.RegisterGameObjectBuildersAssemblyFile(Path.Combine(path, "SpaceEngineers.ObjectBuilders.dll"));
            MyPlugins.RegisterSandboxAssemblyFile(Path.Combine(path, "Sandbox.Common.dll"));

            SpaceEngineersApi.LoadLocalization();
            _stockDefinitions = new SpaceEngineersResources();
            _stockDefinitions.LoadDefinitions();
            _manageDeleteVoxelList = new List <string>();
        }
Example #9
0
        public SpaceEngineersCore()
        {
            //SpaceEngineersGame.SetupPerGameSettings(); // not required currently.
            var path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            //MyPlugins.RegisterGameAssemblyFile(Path.Combine(path, "SpaceEngineers.Game.dll")); // not required currently.
            MyPlugins.RegisterGameObjectBuildersAssemblyFile(Path.Combine(path, "SpaceEngineers.ObjectBuilders.dll"));
            MyPlugins.RegisterSandboxAssemblyFile(Path.Combine(path, "Sandbox.Common.dll"));
            //MyPlugins.RegisterSandboxGameAssemblyFile(Path.Combine(path, "Sandbox.Game.dll")); // not required currently.

            MyObjectBuilderType.RegisterAssemblies();
            MyObjectBuilderSerializer.RegisterAssembliesAndLoadSerializers();

            SpaceEngineersApi.LoadLocalization();
            _stockDefinitions = new SpaceEngineersResources();
            _stockDefinitions.LoadDefinitions();
            _manageDeleteVoxelList = new List <string>();
        }
Example #10
0
        private static void RegisterPlugins()
        {
            MyPlugins.RegisterGameAssemblyFile("SpaceEngineers.Game.dll");
            MyPlugins.RegisterGameObjectBuildersAssemblyFile("SpaceEngineers.ObjectBuilders.dll");
            MyPlugins.RegisterSandboxAssemblyFile("Sandbox.Common.dll");
            MyPlugins.RegisterSandboxGameAssemblyFile("Sandbox.Game.dll");
#if DEBUG
            try
            {
                MyPlugins.Load();
            }
            catch (ReflectionTypeLoadException ex)
            {
                MyLog.Default.WriteLine(ex);
                throw;
            }
#else
            MyPlugins.Load();
#endif

            // No longer at available.
            //MyObjectBuilderType.RegisterAssemblies();
            //MyObjectBuilderSerializer.RegisterAssembliesAndLoadSerializers();
        }
Example #11
0
        public void Initialize()
        {
            try
            {
                RegisterChummerProtocol();
                if (GlobalOptions.PluginsEnabled == false)
                {
                    Log.Info("Plugins are globally disabled - exiting PluginControl.Initialize()");
                    return;
                }
                Log.Info("Plugins are globally enabled - entering PluginControl.Initialize()");

                string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Plugins");
                if (!Directory.Exists(path))
                {
                    string msg = "Directory " + path + " not found. No Plugins will be available.";
                    MyPlugins = new List <IPlugin>();
                    throw new ArgumentException(msg);
                }
                catalog = new AggregateCatalog();

                var plugindirectories = Directory.GetDirectories(path);
                if (!plugindirectories.Any())
                {
                    throw new ArgumentException("No Plugin-Subdirectories in " + path + " !");
                }

                foreach (var plugindir in plugindirectories)
                {
                    Log.Trace("Searching in " + plugindir + " for plugin.txt or dlls containing the interface.");
                    //search for a textfile, that tells me what dll to parse
                    string infofile = Path.Combine(plugindir, "plugin.txt");
                    if (File.Exists(infofile))
                    {
                        Log.Trace(infofile + " found: parsing it!");

                        System.IO.StreamReader file =
                            new System.IO.StreamReader(infofile);
                        string line;
                        while ((line = file.ReadLine()) != null)
                        {
                            string plugindll = Path.Combine(plugindir, line);
                            Log.Trace(infofile + " containes line: " + plugindll + " - trying to find it...");
                            if (File.Exists(plugindll))
                            {
                                FileInfo fi = new FileInfo(plugindll);
                                myDirectoryCatalog = new DirectoryCatalog(path: plugindir, searchPattern: fi.Name);
                                Log.Info("Searching for plugin-interface in dll: " + plugindll);
                                catalog.Catalogs.Add(myDirectoryCatalog);
                            }
                            else
                            {
                                Log.Warn("Could not find dll from " + infofile + ": " + plugindll); myDirectoryCatalog = new DirectoryCatalog(path: plugindir, searchPattern: "*.dll");
                                myDirectoryCatalog = new DirectoryCatalog(path: plugindir, searchPattern: "*.dll");
                                Log.Info("Searching for dlls in path " + myDirectoryCatalog?.FullPath);
                                catalog.Catalogs.Add(myDirectoryCatalog);
                            }
                        }
                        file.Close();
                    }
                    else
                    {
                        myDirectoryCatalog = new DirectoryCatalog(path: plugindir, searchPattern: "*.dll");
                        Log.Info("Searching for dlls in path " + myDirectoryCatalog?.FullPath);
                        catalog.Catalogs.Add(myDirectoryCatalog);
                    }
                }

                container = new CompositionContainer(catalog);

                //Fill the imports of this object
                StartWatch();
                container.ComposeParts(this);

                Log.Info("Plugins found: " + MyPlugins.Count());
                if (!MyPlugins.Any())
                {
                    throw new ArgumentException("No plugins found in " + path + ".");
                }
                Log.Info("Plugins active: " + MyActivePlugins.Count());
                foreach (var plugin in MyActivePlugins)
                {
                    try
                    {
                        Log.Info("Initializing Plugin " + plugin.ToString());
                        plugin.SetIsUnitTest(Utils.IsUnitTest);
                        plugin.CustomInitialize(Program.MainForm);
                    }
                    catch (ApplicationException e)
                    {
                        throw;
                    }
                    catch (Exception e)
                    {
                        Log.Error(e);
                    }
                }
                Log.Info("Initializing Plugins finished.");
            }
            catch (System.Security.SecurityException e)
            {
                string msg = "Well, the Plugin wanted to do something that requires Admin rights. Let's just ignore this: " + Environment.NewLine + Environment.NewLine;
                msg += e.ToString();
                Log.Warn(e, msg);
            }
            catch (Exception e)
            {
                if (e is ApplicationException)
                {
                    throw;
                }
                Log.Fatal(e);
                throw;
            }
        }
Example #12
0
        static void Main(string[] args)
        {
            MyPlugins.Load();

            var asyncInput = ReadConsoleAsync();

            Console.CancelKeyPress += delegate(object sender, ConsoleCancelEventArgs eventArgs)
            {
                eventArgs.Cancel = true;
                IsRunning        = false;
            };

            m_client = new MyRakNetClient((ulong)m_port);

            for (int i = 0; i < 10; i++)
            {
                switch (m_client.Startup(m_port))
                {
                case StartupResultEnum.SOCKET_PORT_ALREADY_IN_USE:
                    m_port++;
                    break;

                default:
                    break;
                }
            }

            new MyRakNetSyncLayer().LoadData(m_client, typeof(Program).Assembly);

            //MySyncedClass mySyncedObject = new MySyncedClass();
            //MySyncedFloatSNorm F = new MySyncedFloatSNorm();
            //mySyncedObject.Add(F);
            //MySyncedInt I = new MySyncedInt();
            //mySyncedObject.Add(I);

            //MySyncedClass myInnerSyncedObject = new MySyncedClass();
            //MySyncedVector3 V3 = new MySyncedVector3();
            //mySyncedObject.Add(V3);
            //mySyncedObject.Add(myInnerSyncedObject);
            //MyRakNetSyncLayer.RegisterSynced(mySyncedObject);

            MyRakNetSyncLayer.Static.OnEntityCreated   += Static_OnEntityCreated;
            MyRakNetSyncLayer.Static.OnEntityDestroyed += Static_OnEntityDestroyed;

            RegisterEvents(m_client);
            var result = m_client.Connect("127.0.0.1", 27025);

            while (IsRunning)
            {
                if (asyncInput.IsCompleted)
                {
                    var cmd = asyncInput.Result;
                    if (!String.IsNullOrEmpty(cmd))
                    {
                        if (cmd == "quit")
                        {
                            IsRunning = false;
                        }
                        else
                        {
                            m_client.SendChatMessage(cmd);
                        }
                    }
                    asyncInput = ReadConsoleAsync();
                }

                m_client.Update();

                if (foo != null)
                {
                    if (lastD != foo.Position.Get().X)
                    {
                        for (int i = 0; i < (foo.Position.Get().X + 1) / 2 * 115; i++)
                        {
                            Console.Out.Write("|");
                        }
                        Console.Out.WriteLine();
                        lastD = foo.Position.Get().X;
                    }

                    if (lastStr != foo.Name.Get())
                    {
                        Console.WriteLine(foo.Name.Get());
                        lastStr = foo.Name.Get();
                    }
                }

                //if (lastF != F)
                //{
                //    for (int i = 0; i < (F + 1) / 2 * 115; i++)
                //    {
                //        Console.Out.Write("|");
                //    }
                //    Console.Out.WriteLine();
                //    lastF = F;
                //}

                //if (lastI != I)
                //{
                //    for (int i = 0; i < I % 116; i++)
                //    {
                //        Console.Out.Write("-");
                //    }
                //    Console.Out.WriteLine();
                //    lastI = I;
                //}

                Thread.Sleep(16);
            }
            m_client.Dispose();
            MyRakNetSyncLayer.Static.UnloadData();
            MyPlugins.Unload();
        }
Example #13
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);
        }
Example #14
0
        public MyMinerGame(ServiceContainer services)
        {
            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("MyMinerGame()::constructor");
            MyMwcLog.WriteLine("MyMinerGame.Constructor() - START");
            MyMwcLog.IncreaseIndent();

            Services = services;

            // we want check objectbuilders, prefab's configurations, gameplay constants and building specifications
            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("Checks");
            MyMwcObjectBuilder_Base.Check();
            MyPrefabConstants.Check();
            MyGameplayConstants.Check();
            MyBuildingSpecifications.Check();
            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("Preallocate");

            Preallocate();

            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("IsAdmin");
            WindowsIdentity  windowsIdentity  = WindowsIdentity.GetCurrent();
            WindowsPrincipal windowsPrincipal = new WindowsPrincipal(windowsIdentity);
            bool             IsAdmin          = windowsPrincipal.IsInRole(WindowsBuiltInRole.Administrator);

            MyMwcLog.WriteLine("IsAdmin " + IsAdmin.ToString());
            MyMwcLog.WriteLine("Game dir: " + GameDir);

            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("MyCustomGraphicsDeviceManagerDX");
#if !DEBUG
            try
            {
#endif

            this.Exiting      += MyMinerGame_Exiting;
            this.Activated    += MyMinerGame_OnActivated;
            this.Deactivated  += MyMinerGame_OnDeactivated;
            this.m_InvokeQueue = new ConcurrentQueue <Tuple <ManualResetEvent, Action> >();
            this.m_MainThread  = Thread.CurrentThread;

            GraphicsDeviceManager = new MyCustomGraphicsDeviceManagerDX(this);

            m_isGraphicsSupported = GraphicsDeviceManager.ChangeProfileSupport();
            m_isGraphicsSupported = true;

            if (m_isGraphicsSupported)
            {
                MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("MyVideoModeManager.HookEventHandlers");

                MyVideoModeManager.HookEventHandlers();

                //Content = new MyCustomContentManager(Services, ContentDir);
                //  Content = new SharpDX.Toolkit.Content.ContentManager(Services);

                RootDirectory      = Path.Combine(GameDir, "Content");
                RootDirectoryDebug = Path.GetFullPath(System.IO.Path.Combine(GameDir, "..\\..\\..\\Content"));

                RootDirectoryEffects = RootDirectory;

                Static = this;

                MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("InitNumberOfCores");
                InitNumberOfCores();

                MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("MyVideoModeManager.LogApplicationInformation");


                MyVideoModeManager.LogApplicationInformation();

                MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("MyVideoModeManager.LogInformation");

                MyVideoModeManager.LogInformation();

                MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("MyVideoModeManager.LogEnvironmentInformation");

                MyVideoModeManager.LogEnvironmentInformation();

                MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("MyPlugins.LoadContent");

                MyPlugins.LoadContent();

                MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("MyConfig.Load");

                MyConfig.Load();

                MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("MyMath.Init");

                MyMath.Init();

                MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("MyTextsWrapper.Init");

                MyTextsWrapper.Init();

                MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("MyDialoguesWrapper.Init");

                MyDialoguesWrapper.Init();

                //  If I don't set TargetElapsedTime, default value will be used, which is 60 times per second, and it will be more precise than if I calculate
                //  it like below - SO I MUST BE DOING THE WRONG CALCULATION !!!
                //  We use fixed timestep. Update() is called at this precise timesteps. If Update or Draw takes more time, Update will be called more time. Draw is called only after Update.
#if RENDER_PROFILING || GPU_PROFILING
                IsFixedTimeStep = false;
                MyMinerGame.GraphicsDeviceManager.SynchronizeWithVerticalRetrace = false;
#else
                IsFixedTimeStep = MyFakes.FIXED_TIMESTEP;
#endif
            }

            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("InitMultithreading");

            InitMultithreading();
#if !DEBUG
        }

        catch (Exception ex)
        {
            //  We are catching exceptions in constructor, because if error occures here, it app will start unloading
            //  so we skip to UnloadContent and there we will get another exception (because app wasn't really loaded when unload started)
            //  So we want original exception in log.
            MyMwcLog.WriteLine(ex);
            throw;
        }
#endif

            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();

            MyMwcLog.DecreaseIndent();
            MyMwcLog.WriteLine("MyMinerGame.Constructor() - END");
            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();
        }
Example #15
0
        static void Main(string[] args)
        {
            MyPlugins.Load();

            var asyncInput = ReadConsoleAsync();

            Console.CancelKeyPress += delegate(object sender, ConsoleCancelEventArgs eventArgs)
            {
                eventArgs.Cancel = true;
                IsRunning        = false;
            };

            m_server = new MyRakNetServer(0);

            m_server.Startup(32, 27025, null);

            new MyRakNetSyncLayer().LoadData(m_server, typeof(Program).Assembly);

            //MySyncedClass mySyncedObject = new MySyncedClass();
            //MySyncedFloatSNorm F = new MySyncedFloatSNorm();
            //mySyncedObject.Add(F);
            //MySyncedInt I = new MySyncedInt();
            //mySyncedObject.Add(I);

            //MySyncedClass myInnerSyncedObject = new MySyncedClass();
            //MySyncedVector3 V3 = new MySyncedVector3();
            //mySyncedObject.Add(V3);
            //mySyncedObject.Add(myInnerSyncedObject);
            //MyRakNetSyncLayer.RegisterSynced(mySyncedObject);

            RegisterEvents(m_server);

            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();

            Foo foo = null;

            bool sin = false;
            bool str = false;

            while (IsRunning)
            {
                if (asyncInput.IsCompleted)
                {
                    var cmd = asyncInput.Result;
                    if (!String.IsNullOrEmpty(cmd))
                    {
                        if (cmd == "quit")
                        {
                            IsRunning = false;
                        }
                        else if (cmd == "+")
                        {
                            foo          = new Foo();
                            foo.EntityID = 1;
                            MyRakNetSyncLayer.Replicate(foo, foo.EntityID);
                        }
                        else if (cmd == "-")
                        {
                            if (foo != null)
                            {
                                MyRakNetSyncLayer.Destroy(foo.EntityID);
                                foo = null;
                            }
                        }
                        else if (cmd == "sin")
                        {
                            if (foo != null)
                            {
                                sin = !sin;
                            }
                        }
                        else if (cmd == "str")
                        {
                            if (foo != null)
                            {
                                str = !str;
                            }
                        }
                        else
                        {
                            m_server.SendChatMessage(cmd);
                        }
                    }
                    asyncInput = ReadConsoleAsync();
                }

                if (foo != null)
                {
                    if (sin)
                    {
                        foo.Position.Set(new Vector3D(Math.Sin((double)stopWatch.ElapsedMilliseconds / 1000.0)));
                    }
                    if (str)
                    {
                        char c = (char)('a' + (byte)(stopWatch.ElapsedMilliseconds / 1000.0) % 26);
                        foo.Name.Set(String.Concat(Enumerable.Repeat(c, 100)));
                    }
                }

                //I.Set((int)(stopWatch.ElapsedMilliseconds / 1000.0));

                //F.Set((float)Math.Sin((double)stopWatch.ElapsedMilliseconds / 1000.0));
                //I.Set((int)(stopWatch.ElapsedMilliseconds/10));
                //V3.Set(new Vector3(F, F, F));

                MyRakNetSyncLayer.Static.Update();
                m_server.Update();

                //Console.Out.WriteLine(m_server.GetStatsToString());

                Thread.Sleep(16);
            }
            m_server.Dispose();
            MyRakNetSyncLayer.Static.UnloadData();
            MyPlugins.Unload();
        }
Example #16
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);
        }