コード例 #1
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();
            }
        }
コード例 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <exception cref="InvalidOperationException">Thrown if a TorchBase instance already exists.</exception>
        protected TorchBase(ITorchConfig config)
        {
            RegisterCoreAssembly(GetType().Assembly);
            if (Instance != null)
            {
                throw new InvalidOperationException("A TorchBase instance already exists.");
            }

            Instance = this;
            Config   = config;

            var versionString = Assembly.GetEntryAssembly()
                                .GetCustomAttribute <AssemblyInformationalVersionAttribute>()
                                .InformationalVersion;

            if (!InformationalVersion.TryParse(versionString, out InformationalVersion version))
            {
                throw new TypeLoadException("Unable to parse the Torch version from the assembly.");
            }

            TorchVersion = version;

            RunArgs = new string[0];

            Managers = new DependencyManager();

            Plugins = new PluginManager(this);

            var sessionManager = new TorchSessionManager(this);

            sessionManager.AddFactory((x) => Sync.IsServer ? new ChatManagerServer(this) : new ChatManagerClient(this));
            sessionManager.AddFactory((x) => Sync.IsServer ? new CommandManager(this) : null);
            sessionManager.AddFactory((x) => new EntityManager(this));

            Managers.AddManager(sessionManager);
            Managers.AddManager(new PatchManager(this));
            Managers.AddManager(new FilesystemManager(this));
            Managers.AddManager(new UpdateManager(this));
            Managers.AddManager(new EventManager(this));
            Managers.AddManager(Plugins);
            TorchAPI.Instance = this;

            GameStateChanged += (game, state) =>
            {
                if (state == TorchGameState.Created)
                {
                    // If the attached assemblies change (MySandboxGame.ctor => MySandboxGame.ParseArgs => MyPlugins.RegisterFromArgs)
                    // attach assemblies to object factories again.
                    ObjectFactoryInitPatch.ForceRegisterAssemblies();
                    // safe to commit here; all important static ctors have run
                    PatchManager.CommitInternal();
                }
            };

            sessionManager.SessionStateChanged += (session, state) =>
            {
                switch (state)
                {
                case TorchSessionState.Loading:
                    SessionLoading?.Invoke();
                    break;

                case TorchSessionState.Loaded:
                    SessionLoaded?.Invoke();
                    break;

                case TorchSessionState.Unloading:
                    SessionUnloading?.Invoke();
                    break;

                case TorchSessionState.Unloaded:
                    SessionUnloaded?.Invoke();
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(state), state, null);
                }
            };
        }