예제 #1
0
 private static void SuffixConstructor()
 {
     PatchManager.CommitInternal();
     if (TorchBase.Instance is TorchBase tb)
     {
         tb.GameState = TorchGameState.Created;
     }
 }
예제 #2
0
 static TorchBase()
 {
     ReflectedManager.Process(typeof(TorchBase).Assembly);
     ReflectedManager.Process(typeof(ITorchBase).Assembly);
     PatchManager.AddPatchShim(typeof(GameStatePatchShim));
     PatchManager.AddPatchShim(typeof(GameAnalyticsPatch));
     PatchManager.AddPatchShim(typeof(KeenLogPatch));
     PatchManager.CommitInternal();
     RegisterCoreAssembly(typeof(ITorchBase).Assembly);
     RegisterCoreAssembly(typeof(TorchBase).Assembly);
     RegisterCoreAssembly(Assembly.GetEntryAssembly());
 }
예제 #3
0
 static TorchBase()
 {
     ReflectedManager.Process(typeof(TorchBase).Assembly);
     ReflectedManager.Process(typeof(ITorchBase).Assembly);
     PatchManager.AddPatchShim(typeof(GameStatePatchShim));
     PatchManager.AddPatchShim(typeof(GameAnalyticsPatch));
     PatchManager.AddPatchShim(typeof(KeenLogPatch));
     PatchManager.CommitInternal();
     RegisterCoreAssembly(typeof(ITorchBase).Assembly);
     RegisterCoreAssembly(typeof(TorchBase).Assembly);
     RegisterCoreAssembly(Assembly.GetEntryAssembly());
     //exceptions in English, please
     Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
 }
예제 #4
0
 static TorchBase()
 {
     MyVRageWindows.Init("SpaceEngineersDedicated", MySandboxGame.Log, null, false);
     ReflectedManager.Process(typeof(TorchBase).Assembly);
     ReflectedManager.Process(typeof(ITorchBase).Assembly);
     PatchManager.AddPatchShim(typeof(GameStatePatchShim));
     PatchManager.AddPatchShim(typeof(GameAnalyticsPatch));
     PatchManager.AddPatchShim(typeof(KeenLogPatch));
     PatchManager.CommitInternal();
     RegisterCoreAssembly(typeof(ITorchBase).Assembly);
     RegisterCoreAssembly(typeof(TorchBase).Assembly);
     RegisterCoreAssembly(Assembly.GetEntryAssembly());
     //exceptions in English, please
     Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
 }
예제 #5
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();
            }
        }
예제 #6
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);
                }
            };
        }