Tweak plugin init, fix issue in mod config
This commit is contained in:
@@ -9,18 +9,29 @@ namespace Torch.API.Plugins
|
||||
{
|
||||
public interface ITorchPlugin : IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// A unique ID for the plugin.
|
||||
/// </summary>
|
||||
Guid Id { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The version of the plugin.
|
||||
/// </summary>
|
||||
Version Version { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The name of the plugin.
|
||||
/// </summary>
|
||||
string Name { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Called when the game is initialized.
|
||||
/// This is called before the game loop is started.
|
||||
/// </summary>
|
||||
/// <param name="torchBase"></param>
|
||||
/// <param name="torchBase">Torch instance</param>
|
||||
void Init(ITorchBase torchBase);
|
||||
|
||||
/// <summary>
|
||||
/// Called after each game tick. Not thread safe, use invocation methods in <see cref="ITorchBase"/>.
|
||||
/// This is called on the game thread after each tick.
|
||||
/// </summary>
|
||||
void Update();
|
||||
}
|
||||
|
@@ -11,7 +11,7 @@ namespace Torch.API.Plugins
|
||||
{
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
UserControl GetControl();
|
||||
}
|
||||
|
@@ -1,4 +1,4 @@
|
||||
using System.Reflection;
|
||||
|
||||
[assembly: AssemblyVersion("1.0.167.670")]
|
||||
[assembly: AssemblyFileVersion("1.0.167.670")]
|
||||
[assembly: AssemblyVersion("1.0.168.389")]
|
||||
[assembly: AssemblyFileVersion("1.0.168.389")]
|
@@ -1,4 +1,4 @@
|
||||
using System.Reflection;
|
||||
|
||||
[assembly: AssemblyVersion("1.0.167.670")]
|
||||
[assembly: AssemblyFileVersion("1.0.167.670")]
|
||||
[assembly: AssemblyVersion("1.0.168.389")]
|
||||
[assembly: AssemblyFileVersion("1.0.168.389")]
|
@@ -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();
|
||||
|
@@ -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);
|
||||
}
|
||||
|
@@ -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)
|
||||
|
@@ -118,6 +118,9 @@ namespace Torch.Managers
|
||||
{
|
||||
if (type.GetInterfaces().Contains(typeof(ITorchPlugin)))
|
||||
{
|
||||
if (type.GetCustomAttribute<PluginAttribute>() == 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;
|
||||
}
|
||||
}
|
||||
|
@@ -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() { }
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual void Dispose()
|
||||
@@ -231,7 +235,6 @@ namespace Torch
|
||||
{
|
||||
Network.Init();
|
||||
ChatManager.Instance.Init();
|
||||
Plugins.Init();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
@@ -47,6 +47,7 @@ namespace Torch
|
||||
}
|
||||
|
||||
public virtual void Update() { }
|
||||
public abstract void Dispose();
|
||||
|
||||
public virtual void Dispose() { }
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user