All checks were successful
Build / Compute Version (push) Successful in 5s
Build / Build Nuget package (CringeBootstrap.Abstractions) (push) Successful in 1m55s
Build / Build Nuget package (CringePlugins) (push) Successful in 2m24s
Build / Build Nuget package (NuGet) (push) Successful in 2m6s
Build / Build Nuget package (SharedCringe) (push) Successful in 2m47s
Build / Build Launcher (push) Successful in 3m45s
73 lines
1.6 KiB
C#
73 lines
1.6 KiB
C#
using NLog;
|
|
using VRage.Plugins;
|
|
|
|
namespace CringePlugins.Loader;
|
|
|
|
//todo: we should patch Mysanboxgame.Run to log init of actual plugin names instead of pluginwrapper
|
|
//also, maybe we could unload the plugin if there's an error?
|
|
internal sealed class PluginWrapper(string name, IPlugin plugin) : IHandleInputPlugin
|
|
{
|
|
public bool HasError => LastException != null;
|
|
public Exception? LastException { get; private set; } //todo: show exception when hovered in plugin menu?
|
|
|
|
private static readonly ILogger Log = LogManager.GetCurrentClassLogger();
|
|
|
|
public void Dispose()
|
|
{
|
|
try
|
|
{
|
|
plugin.Dispose();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Log.Error(e, "Error Disposing {Name}", name);
|
|
LastException = e;
|
|
}
|
|
}
|
|
|
|
public void HandleInput()
|
|
{
|
|
if (HasError || plugin is not IHandleInputPlugin input)
|
|
return;
|
|
|
|
try
|
|
{
|
|
input.HandleInput();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Log.Error(e, "Error Updating {Name}", name);
|
|
LastException = e;
|
|
}
|
|
}
|
|
|
|
public void Init(object gameInstance)
|
|
{
|
|
try
|
|
{
|
|
plugin.Init(gameInstance);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Log.Error(e, "Error Initializing {Name}", name);
|
|
LastException = e;
|
|
}
|
|
}
|
|
|
|
public void Update()
|
|
{
|
|
if (HasError)
|
|
return;
|
|
|
|
try
|
|
{
|
|
plugin.Update();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Log.Error(e, "Error Updating {Name}", name);
|
|
LastException = e;
|
|
}
|
|
}
|
|
}
|