Browse Source

Added a way for plugins to get a logger

refactor
Anairkoen Schno 6 years ago
parent
commit
cd112d8cf4
4 changed files with 54 additions and 6 deletions
  1. +1
    -0
      IllusionInjector/IllusionInjector.csproj
  2. +32
    -5
      IllusionInjector/PluginManager.cs
  3. +20
    -0
      IllusionInjector/Utilities/Extensions.cs
  4. +1
    -1
      IllusionInjector/obj/Debug/IllusionInjector.csproj.CoreCompileInputs.cache

+ 1
- 0
IllusionInjector/IllusionInjector.csproj View File

@ -82,6 +82,7 @@
<Compile Include="Updating\ModsaberML\Updater.cs" />
<Compile Include="Updating\Old\ModUpdater.cs" />
<Compile Include="Updating\Old\UpdateScript.cs" />
<Compile Include="Utilities\Extensions.cs" />
<Compile Include="Utilities\LoneFunctions.cs" />
<Compile Include="Utilities\SimpleJson.cs" />
<Compile Include="Utilities\SteamCheck.cs" />


+ 32
- 5
IllusionInjector/PluginManager.cs View File

@ -1,4 +1,5 @@
using IllusionInjector.Logging;
using IllusionInjector.Utilities;
using IllusionPlugin;
using IllusionPlugin.BeatSaber;
using System;
@ -11,6 +12,7 @@ using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using LoggerBase = IllusionPlugin.Logging.Logger;
namespace IllusionInjector
{
@ -182,12 +184,37 @@ namespace IllusionInjector
IBeatSaberPlugin bsPlugin = OptionalGetPlugin<IBeatSaberPlugin>(t);
if (bsPlugin != null)
{
bsPlugins.Add(new BSPluginMeta
try
{
Plugin = bsPlugin,
Filename = file,
ModsaberInfo = bsPlugin.ModInfo
});
var init = t.GetMethod("Init", BindingFlags.Instance | BindingFlags.Public);
if (init != null)
{
var initArgs = new List<object>();
var initParams = init.GetParameters();
foreach (var param in initParams)
{
var ptype = param.ParameterType;
if (ptype.IsAssignableFrom(typeof(LoggerBase)))
initArgs.Add(new StandardLogger(bsPlugin.Name));
else
initArgs.Add(ptype.GetDefault());
}
init.Invoke(bsPlugin, initArgs.ToArray());
}
bsPlugins.Add(new BSPluginMeta
{
Plugin = bsPlugin,
Filename = file,
ModsaberInfo = bsPlugin.ModInfo
});
}
catch (AmbiguousMatchException)
{
Logger.log.Error($"Only one Init allowed per plugin");
}
}
else
{


+ 20
- 0
IllusionInjector/Utilities/Extensions.cs View File

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace IllusionInjector.Utilities
{
public static class Extensions
{
public static object GetDefault(this Type type)
{
if (type.IsValueType)
{
return Activator.CreateInstance(type);
}
return null;
}
}
}

+ 1
- 1
IllusionInjector/obj/Debug/IllusionInjector.csproj.CoreCompileInputs.cache View File

@ -1 +1 @@
53986b9c1e3d7933198e1551a3ec82914a34cbb2
4fc156f3cea4b1f659732d784ceeb2b98e58bc07

Loading…
Cancel
Save