diff --git a/Torch.API/Managers/IPluginManager.cs b/Torch.API/Managers/IPluginManager.cs
index 2a2ee08..46cf0f6 100644
--- a/Torch.API/Managers/IPluginManager.cs
+++ b/Torch.API/Managers/IPluginManager.cs
@@ -14,6 +14,9 @@ namespace Torch.API.Managers
///
/// Fired when plugins are loaded.
///
+ ///
+ /// Fired when plugins are loaded and immediately if subscribed after the plugins are loaded.
+ ///
event Action> PluginsLoaded;
///
diff --git a/Torch.Server/TorchServer.cs b/Torch.Server/TorchServer.cs
index bcd3491..5e2ae81 100644
--- a/Torch.Server/TorchServer.cs
+++ b/Torch.Server/TorchServer.cs
@@ -58,7 +58,9 @@ namespace Torch.Server
AddManager(new EntityControlManager(this));
AddManager(new RemoteAPIManager(this));
-
+ var sessionManager = Managers.GetManager();
+ sessionManager.AddFactory(_ => new MultiplayerManagerDedicated(this));
+ sessionManager.SessionStateChanged += OnSessionStateChanged;
// Needs to be done at some point after MyVRageWindows.Init
// where the debug listeners are registered
@@ -128,10 +130,6 @@ namespace Torch.Server
{
Log.Info("Initializing server");
base.Init();
- var sessionManager = Managers.GetManager();
- sessionManager.AddFactory(x => new MultiplayerManagerDedicated(this));
- sessionManager.SessionStateChanged += OnSessionStateChanged;
-
GetManager().LoadInstance(InstancePath);
CanRun = true;
Initialized?.Invoke(this);
diff --git a/Torch/Plugins/PluginManager.cs b/Torch/Plugins/PluginManager.cs
index dac0377..d90e6cd 100644
--- a/Torch/Plugins/PluginManager.cs
+++ b/Torch/Plugins/PluginManager.cs
@@ -52,8 +52,40 @@ namespace Torch.Managers
///
public IReadOnlyDictionary Plugins => _plugins.AsReadOnlyObservable();
- public event Action> PluginsLoaded;
-
+ private Action> _pluginsLoaded;
+ private bool _loaded;
+
+ public event Action> PluginsLoaded
+ {
+ add
+ {
+ var action = _pluginsLoaded;
+ Action> action2;
+ do
+ {
+ action2 = action;
+ var action3 = (Action>)Delegate.Combine(action2, value);
+ action = Interlocked.CompareExchange(ref _pluginsLoaded, action3, action2);
+ }
+ while (action != action2);
+
+ if (_loaded)
+ value(_plugins.Values.AsReadOnly());
+ }
+ remove
+ {
+ var action = _pluginsLoaded;
+ Action> action2;
+ do
+ {
+ action2 = action;
+ var action3 = (Action>)Delegate.Remove(action2, value);
+ action = Interlocked.CompareExchange(ref _pluginsLoaded, action3, action2);
+ }
+ while (action != action2);
+ }
+ }
+
public PluginManager(ITorchBase torchInstance) : base(torchInstance)
{
if (!Directory.Exists(PluginDir))
@@ -145,7 +177,8 @@ namespace Torch.Managers
plugin.Init(Torch);
}
_log.Info($"Loaded {_plugins.Count} plugins.");
- PluginsLoaded?.Invoke(_plugins.Values.AsReadOnly());
+ _loaded = true;
+ _pluginsLoaded?.Invoke(_plugins.Values.AsReadOnly());
return;
}
@@ -220,7 +253,8 @@ namespace Torch.Managers
plugin.Init(Torch);
}
_log.Info($"Loaded {_plugins.Count} plugins.");
- PluginsLoaded?.Invoke(_plugins.Values.AsReadOnly());
+ _loaded = true;
+ _pluginsLoaded?.Invoke(_plugins.Values.AsReadOnly());
}
//debug flag is set when the user asks us to run with a specific plugin for plugin development debug
diff --git a/Torch/Session/TorchSessionManager.cs b/Torch/Session/TorchSessionManager.cs
index 09b4b96..5e082f3 100644
--- a/Torch/Session/TorchSessionManager.cs
+++ b/Torch/Session/TorchSessionManager.cs
@@ -49,8 +49,6 @@ namespace Torch.Session
public TorchSessionManager(ITorchBase torchInstance) : base(torchInstance)
{
_overrideMods = new Dictionary();
- if (Torch.Config.UgcServiceType == UGCServiceType.Steam)
- _overrideMods.Add(ModCommunication.MOD_ID, ModItemUtils.Create(ModCommunication.MOD_ID));
}
///
@@ -193,6 +191,8 @@ namespace Torch.Session
MySession.AfterLoading += SessionLoaded;
MySession.OnUnloading += SessionUnloading;
MySession.OnUnloaded += SessionUnloaded;
+ if (Torch.Config.UgcServiceType == UGCServiceType.Steam)
+ _overrideMods.Add(ModCommunication.MOD_ID, ModItemUtils.Create(ModCommunication.MOD_ID));
}
diff --git a/Torch/TorchBase.cs b/Torch/TorchBase.cs
index c72603a..3a75ce0 100644
--- a/Torch/TorchBase.cs
+++ b/Torch/TorchBase.cs
@@ -116,6 +116,12 @@ namespace Torch
Plugins = new PluginManager(this);
#pragma warning restore CS0618
+ var sessionManager = new TorchSessionManager(this);
+ sessionManager.AddFactory(_ => Sync.IsServer ? new ChatManagerServer(this) : new ChatManagerClient(this));
+ sessionManager.AddFactory(_ => Sync.IsServer ? new CommandManager(this) : null);
+ sessionManager.AddFactory(_ => new EntityManager(this));
+
+ Managers.AddManager(sessionManager);
Managers.AddManager(new PatchManager(this));
Managers.AddManager(new FilesystemManager(this));
Managers.AddManager(new UpdateManager(this));
@@ -283,15 +289,6 @@ namespace Torch
Game = new VRageGame(this, TweakGameSettings, SteamAppName, SteamAppId, InstancePath, RunArgs);
if (!Game.WaitFor(VRageGame.GameState.Stopped))
Log.Warn("Failed to wait for game to be initialized");
-
- 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.Attach();
_init = true;