|
|
@ -7,10 +7,7 @@ using System.Reflection; |
|
|
|
using System.Runtime.InteropServices; |
|
|
|
using System.Text; |
|
|
|
using IPA.Config; |
|
|
|
using IPA.Config.ConfigProviders; |
|
|
|
using IPA.Logging; |
|
|
|
using IPA.Old; |
|
|
|
using IPA.Updating; |
|
|
|
using IPA.Utilities; |
|
|
|
using Mono.Cecil; |
|
|
|
using UnityEngine; |
|
|
@ -62,7 +59,7 @@ namespace IPA.Loader |
|
|
|
/// <returns>the plugin info for the requested plugin or null</returns>
|
|
|
|
public static PluginInfo GetPlugin(string name) |
|
|
|
{ |
|
|
|
return BSMetas.FirstOrDefault(p => p.Plugin.Name == name); |
|
|
|
return BSMetas.FirstOrDefault(p => p.Metadata.Name == name); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
@ -168,7 +165,7 @@ namespace IPA.Loader |
|
|
|
#endregion
|
|
|
|
} |
|
|
|
|
|
|
|
var selfPlugin = new PluginInfo |
|
|
|
/*var selfPlugin = new PluginInfo |
|
|
|
{ |
|
|
|
Filename = Path.Combine(BeatSaber.InstallPath, "IPA.exe"), |
|
|
|
Plugin = SelfPlugin.Instance |
|
|
@ -184,16 +181,16 @@ namespace IPA.Loader |
|
|
|
}; |
|
|
|
selfPlugin.Metadata.File = new FileInfo(Path.Combine(BeatSaber.InstallPath, "IPA.exe")); |
|
|
|
|
|
|
|
_bsPlugins.Add(selfPlugin); |
|
|
|
_bsPlugins.Add(selfPlugin);*/ |
|
|
|
|
|
|
|
//Load copied plugins
|
|
|
|
string[] copiedPlugins = Directory.GetFiles(cacheDir, "*.dll"); |
|
|
|
foreach (string s in copiedPlugins) |
|
|
|
{ |
|
|
|
var result = LoadPluginsFromFile(s); |
|
|
|
_bsPlugins.AddRange(result.Item1); |
|
|
|
_ipaPlugins.AddRange(result.Item2); |
|
|
|
} |
|
|
|
_bsPlugins.AddRange(PluginLoader.LoadPlugins()); |
|
|
|
|
|
|
|
Logger.log.Info(exeName); |
|
|
|
Logger.log.Info($"Running on Unity {Application.unityVersion}"); |
|
|
@ -203,7 +200,7 @@ namespace IPA.Loader |
|
|
|
Logger.log.Info("-----------------------------"); |
|
|
|
foreach (var plugin in _bsPlugins) |
|
|
|
{ |
|
|
|
Logger.log.Info($"{plugin.Plugin.Name}: {plugin.Plugin.Version}"); |
|
|
|
Logger.log.Info($"{plugin.Metadata.Name}: {plugin.Metadata.Version}"); |
|
|
|
} |
|
|
|
Logger.log.Info("-----------------------------"); |
|
|
|
foreach (var plugin in _ipaPlugins) |
|
|
@ -215,11 +212,10 @@ namespace IPA.Loader |
|
|
|
|
|
|
|
private static Tuple<IEnumerable<PluginInfo>, IEnumerable<IPlugin>> LoadPluginsFromFile(string file) |
|
|
|
{ |
|
|
|
List<PluginInfo> bsPlugins = new List<PluginInfo>(); |
|
|
|
List<IPlugin> ipaPlugins = new List<IPlugin>(); |
|
|
|
|
|
|
|
if (!File.Exists(file) || !file.EndsWith(".dll", true, null)) |
|
|
|
return new Tuple<IEnumerable<PluginInfo>, IEnumerable<IPlugin>>(bsPlugins, ipaPlugins); |
|
|
|
return new Tuple<IEnumerable<PluginInfo>, IEnumerable<IPlugin>>(null, ipaPlugins); |
|
|
|
|
|
|
|
T OptionalGetPlugin<T>(Type t) where T : class |
|
|
|
{ |
|
|
@ -250,74 +246,15 @@ namespace IPA.Loader |
|
|
|
|
|
|
|
try |
|
|
|
{ |
|
|
|
|
|
|
|
Assembly assembly = Assembly.LoadFrom(file); |
|
|
|
|
|
|
|
foreach (Type t in assembly.GetTypes()) |
|
|
|
{ |
|
|
|
IBeatSaberPlugin bsPlugin = OptionalGetPlugin<IBeatSaberPlugin>(t); |
|
|
|
if (bsPlugin != null) |
|
|
|
{ |
|
|
|
try |
|
|
|
{ |
|
|
|
var init = t.GetMethod("Init", BindingFlags.Instance | BindingFlags.Public); |
|
|
|
if (init != null) |
|
|
|
{ |
|
|
|
var initArgs = new List<object>(); |
|
|
|
var initParams = init.GetParameters(); |
|
|
|
|
|
|
|
Logger modLogger = null; |
|
|
|
IModPrefs modPrefs = null; |
|
|
|
IConfigProvider cfgProvider = null; |
|
|
|
|
|
|
|
foreach (var param in initParams) |
|
|
|
{ |
|
|
|
var ptype = param.ParameterType; |
|
|
|
if (ptype.IsAssignableFrom(typeof(Logger))) { |
|
|
|
if (modLogger == null) modLogger = new StandardLogger(bsPlugin.Name); |
|
|
|
initArgs.Add(modLogger); |
|
|
|
} |
|
|
|
else if (ptype.IsAssignableFrom(typeof(IModPrefs))) |
|
|
|
{ |
|
|
|
if (modPrefs == null) modPrefs = new ModPrefs(bsPlugin); |
|
|
|
initArgs.Add(modPrefs); |
|
|
|
} |
|
|
|
else if (ptype.IsAssignableFrom(typeof(IConfigProvider))) |
|
|
|
{ |
|
|
|
if (cfgProvider == null) |
|
|
|
{ |
|
|
|
cfgProvider = new JsonConfigProvider { Filename = Path.Combine("UserData", $"{bsPlugin.Name}") }; |
|
|
|
//configProviders.Add(new KeyValuePair<IConfigProvider, Ref<DateTime>>(cfgProvider, new Ref<DateTime>(cfgProvider.LastModified)));
|
|
|
|
cfgProvider.Load(); |
|
|
|
} |
|
|
|
initArgs.Add(cfgProvider); |
|
|
|
} |
|
|
|
else |
|
|
|
initArgs.Add(ptype.GetDefault()); |
|
|
|
} |
|
|
|
|
|
|
|
init.Invoke(bsPlugin, initArgs.ToArray()); |
|
|
|
} |
|
|
|
|
|
|
|
bsPlugins.Add(new PluginInfo |
|
|
|
{ |
|
|
|
Plugin = bsPlugin, |
|
|
|
Filename = file.Replace("\\.cache", ""), // quick and dirty fix
|
|
|
|
//ModSaberInfo = bsPlugin.ModInfo
|
|
|
|
}); |
|
|
|
} |
|
|
|
catch (AmbiguousMatchException) |
|
|
|
{ |
|
|
|
Logger.loader.Error("Only one Init allowed per plugin"); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
|
|
|
|
IPlugin ipaPlugin = OptionalGetPlugin<IPlugin>(t); |
|
|
|
if (ipaPlugin != null) |
|
|
|
{ |
|
|
|
IPlugin ipaPlugin = OptionalGetPlugin<IPlugin>(t); |
|
|
|
if (ipaPlugin != null) |
|
|
|
{ |
|
|
|
ipaPlugins.Add(ipaPlugin); |
|
|
|
} |
|
|
|
ipaPlugins.Add(ipaPlugin); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -327,7 +264,7 @@ namespace IPA.Loader |
|
|
|
Logger.loader.Error($"Could not load {Path.GetFileName(file)}! {e}"); |
|
|
|
} |
|
|
|
|
|
|
|
return new Tuple<IEnumerable<PluginInfo>, IEnumerable<IPlugin>>(bsPlugins, ipaPlugins); |
|
|
|
return new Tuple<IEnumerable<PluginInfo>, IEnumerable<IPlugin>>(null, ipaPlugins); |
|
|
|
} |
|
|
|
|
|
|
|
internal class AppInfo |
|
|
|