diff --git a/Torch.API/Plugins/ITorchPlugin.cs b/Torch.API/Plugins/ITorchPlugin.cs index 19abb56..3e8f9aa 100644 --- a/Torch.API/Plugins/ITorchPlugin.cs +++ b/Torch.API/Plugins/ITorchPlugin.cs @@ -9,18 +9,29 @@ namespace Torch.API.Plugins { public interface ITorchPlugin : IDisposable { + /// + /// A unique ID for the plugin. + /// Guid Id { get; } + + /// + /// The version of the plugin. + /// Version Version { get; } + + /// + /// The name of the plugin. + /// string Name { get; } /// - /// Called when the game is initialized. + /// This is called before the game loop is started. /// - /// + /// Torch instance void Init(ITorchBase torchBase); /// - /// Called after each game tick. Not thread safe, use invocation methods in . + /// This is called on the game thread after each tick. /// void Update(); } diff --git a/Torch.API/Plugins/IWpfPlugin.cs b/Torch.API/Plugins/IWpfPlugin.cs index 39dcca4..0fcc91d 100644 --- a/Torch.API/Plugins/IWpfPlugin.cs +++ b/Torch.API/Plugins/IWpfPlugin.cs @@ -11,7 +11,7 @@ namespace Torch.API.Plugins { /// /// Used by the server's WPF interface to load custom plugin controls. - /// Do not instantiate your plugin control outside of this method! It will throw an exception. + /// You must instantiate your plugin's control object here, otherwise it will not be owned by the correct thread for WPF. /// UserControl GetControl(); } diff --git a/Torch.Client/Properties/AssemblyInfo.cs b/Torch.Client/Properties/AssemblyInfo.cs index 6ea3094..cd9dab5 100644 --- a/Torch.Client/Properties/AssemblyInfo.cs +++ b/Torch.Client/Properties/AssemblyInfo.cs @@ -1,4 +1,4 @@ using System.Reflection; -[assembly: AssemblyVersion("1.0.167.670")] -[assembly: AssemblyFileVersion("1.0.167.670")] \ No newline at end of file +[assembly: AssemblyVersion("1.0.168.389")] +[assembly: AssemblyFileVersion("1.0.168.389")] \ No newline at end of file diff --git a/Torch.Server/Properties/AssemblyInfo.cs b/Torch.Server/Properties/AssemblyInfo.cs index 6ea3094..cd9dab5 100644 --- a/Torch.Server/Properties/AssemblyInfo.cs +++ b/Torch.Server/Properties/AssemblyInfo.cs @@ -1,4 +1,4 @@ using System.Reflection; -[assembly: AssemblyVersion("1.0.167.670")] -[assembly: AssemblyFileVersion("1.0.167.670")] \ No newline at end of file +[assembly: AssemblyVersion("1.0.168.389")] +[assembly: AssemblyFileVersion("1.0.168.389")] \ No newline at end of file diff --git a/Torch.Server/TorchServer.cs b/Torch.Server/TorchServer.cs index 1a86d80..d62e0ec 100644 --- a/Torch.Server/TorchServer.cs +++ b/Torch.Server/TorchServer.cs @@ -113,7 +113,7 @@ namespace Torch.Server MySandboxGame.Log.WriteLine("Environment.CurrentDirectory: " + Environment.CurrentDirectory); MySandboxGame.Log.WriteLine("MainAssembly.ProcessorArchitecture: " + Assembly.GetExecutingAssembly().GetArchitecture()); MySandboxGame.Log.WriteLine("ExecutingAssembly.ProcessorArchitecture: " + MyFileSystem.MainAssembly.GetArchitecture()); - MySandboxGame.Log.WriteLine("IntPtr.Size: " + IntPtr.Size.ToString()); + MySandboxGame.Log.WriteLine("IntPtr.Size: " + IntPtr.Size); MySandboxGame.Log.WriteLine("Default Culture: " + CultureInfo.CurrentCulture.Name); MySandboxGame.Log.WriteLine("Default UI Culture: " + CultureInfo.CurrentUICulture.Name); MySandboxGame.Log.WriteLine("IsAdmin: " + new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator)); @@ -150,6 +150,7 @@ namespace Torch.Server VRage.Service.ExitListenerSTA.OnExit += delegate { MySandboxGame.Static?.Exit(); }; + base.Start(); runInternal.Invoke(null, null); MySandboxGame.Log.Close(); diff --git a/Torch.Server/ViewModels/ConfigDedicatedViewModel.cs b/Torch.Server/ViewModels/ConfigDedicatedViewModel.cs index c9c7d54..7890a64 100644 --- a/Torch.Server/ViewModels/ConfigDedicatedViewModel.cs +++ b/Torch.Server/ViewModels/ConfigDedicatedViewModel.cs @@ -23,27 +23,26 @@ namespace Torch.Server.ViewModels { _config = configDedicated; SessionSettings = new SessionSettingsViewModel(_config.SessionSettings); - Administrators = string.Join("\r\n", _config.Administrators); - Banned = string.Join("\r\n", _config.Banned); - Mods = string.Join("\r\n", _config.Mods); + Administrators = string.Join(Environment.NewLine, _config.Administrators); + Banned = string.Join(Environment.NewLine, _config.Banned); + Mods = string.Join(Environment.NewLine, _config.Mods); } public void Save(string path = null) { + var newline = new [] {Environment.NewLine}; + _config.Administrators.Clear(); - foreach (var admin in Administrators.Split('\r', '\n')) - if (!string.IsNullOrEmpty(admin)) - _config.Administrators.Add(admin); + foreach (var admin in Administrators.Split(newline, StringSplitOptions.RemoveEmptyEntries)) + _config.Administrators.Add(admin); _config.Banned.Clear(); - foreach (var banned in Banned.Split('\r', '\n')) - if (!string.IsNullOrEmpty(banned)) - _config.Banned.Add(ulong.Parse(banned)); + foreach (var banned in Banned.Split(newline, StringSplitOptions.RemoveEmptyEntries)) + _config.Banned.Add(ulong.Parse(banned)); _config.Mods.Clear(); - foreach (var mod in Mods.Split('\r', '\n')) - if (!string.IsNullOrEmpty(mod)) - _config.Mods.Add(ulong.Parse(mod)); + foreach (var mod in Mods.Split(newline, StringSplitOptions.RemoveEmptyEntries)) + _config.Mods.Add(ulong.Parse(mod)); _config.Save(path); } diff --git a/Torch.Server/Views/ConfigControl.xaml.cs b/Torch.Server/Views/ConfigControl.xaml.cs index e1e68af..7f705df 100644 --- a/Torch.Server/Views/ConfigControl.xaml.cs +++ b/Torch.Server/Views/ConfigControl.xaml.cs @@ -52,13 +52,13 @@ namespace Torch.Server.Views Log.Info("Saved DS config."); try { - var checkpoint = MyLocalCache.LoadCheckpoint(_viewModel.LoadWorld, out _); - checkpoint.Settings = _viewModel.SessionSettings; + var checkpoint = MyLocalCache.LoadCheckpoint(Config.LoadWorld, out _); + checkpoint.Settings = Config.SessionSettings; checkpoint.Mods.Clear(); - foreach (var modId in _viewModel.Mods) + foreach (var modId in Config.Mods) checkpoint.Mods.Add(new MyObjectBuilder_Checkpoint.ModItem(modId)); - MyLocalCache.SaveCheckpoint(checkpoint, _viewModel.LoadWorld); + MyLocalCache.SaveCheckpoint(checkpoint, Config.LoadWorld); Log.Info("Saved world config."); } catch (Exception e) diff --git a/Torch/Managers/PluginManager.cs b/Torch/Managers/PluginManager.cs index 604f3b8..6d99dc5 100644 --- a/Torch/Managers/PluginManager.cs +++ b/Torch/Managers/PluginManager.cs @@ -118,6 +118,9 @@ namespace Torch.Managers { if (type.GetInterfaces().Contains(typeof(ITorchPlugin))) { + if (type.GetCustomAttribute() == null) + continue; + try { var plugin = (TorchPluginBase)Activator.CreateInstance(type); @@ -130,10 +133,9 @@ namespace Torch.Managers commands.RegisterPluginCommands(plugin); } - catch (Exception e) + catch { _log.Error($"Error loading plugin '{type.FullName}'"); - _log.Error(e); throw; } } diff --git a/Torch/TorchBase.cs b/Torch/TorchBase.cs index 6f202fb..db8f890 100644 --- a/Torch/TorchBase.cs +++ b/Torch/TorchBase.cs @@ -217,8 +217,12 @@ namespace Torch pluginList.Add(this); } - public abstract void Start(); - public abstract void Stop(); + public virtual void Start() + { + Plugins.Init(); + } + + public virtual void Stop() { } /// public virtual void Dispose() @@ -231,7 +235,6 @@ namespace Torch { Network.Init(); ChatManager.Instance.Init(); - Plugins.Init(); } /// diff --git a/Torch/TorchPluginBase.cs b/Torch/TorchPluginBase.cs index 1b80286..0bead82 100644 --- a/Torch/TorchPluginBase.cs +++ b/Torch/TorchPluginBase.cs @@ -47,6 +47,7 @@ namespace Torch } public virtual void Update() { } - public abstract void Dispose(); + + public virtual void Dispose() { } } }