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; }
/// <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); } }; }
private void OnSessionLoading() { SessionLoading?.Invoke(); MySession.Static.OnReady += OnSessionReady; }
private void OnSessionLoading() { Log.Debug("Session loading"); SessionLoading?.Invoke(); }