You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

710 lines
27 KiB

  1. using IPA.Config;
  2. using IPA.Loader.Features;
  3. using IPA.Logging;
  4. using IPA.Utilities;
  5. using Mono.Cecil;
  6. using Newtonsoft.Json;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.IO;
  10. using System.Linq;
  11. using System.Reflection;
  12. using System.Text.RegularExpressions;
  13. using System.Threading.Tasks;
  14. using Version = SemVer.Version;
  15. #if NET3
  16. using Net3_Proxy;
  17. using Path = Net3_Proxy.Path;
  18. using File = Net3_Proxy.File;
  19. using Directory = Net3_Proxy.Directory;
  20. #endif
  21. namespace IPA.Loader
  22. {
  23. /// <summary>
  24. /// A type to manage the loading of plugins.
  25. /// </summary>
  26. public class PluginLoader
  27. {
  28. internal static Task LoadTask() => Task.Factory.StartNew(() =>
  29. {
  30. YeetIfNeeded();
  31. LoadMetadata();
  32. Resolve();
  33. ComputeLoadOrder();
  34. FilterDisabled();
  35. ResolveDependencies();
  36. });
  37. /// <summary>
  38. /// A class which describes a loaded plugin.
  39. /// </summary>
  40. public class PluginMetadata
  41. {
  42. /// <summary>
  43. /// The assembly the plugin was loaded from.
  44. /// </summary>
  45. /// <value>the loaded Assembly that contains the plugin main type</value>
  46. public Assembly Assembly { get; internal set; }
  47. /// <summary>
  48. /// The TypeDefinition for the main type of the plugin.
  49. /// </summary>
  50. /// <value>the Cecil definition for the plugin main type</value>
  51. public TypeDefinition PluginType { get; internal set; }
  52. /// <summary>
  53. /// The human readable name of the plugin.
  54. /// </summary>
  55. /// <value>the name of the plugin</value>
  56. public string Name { get; internal set; }
  57. /// <summary>
  58. /// The BeatMods ID of the plugin, or null if it doesn't have one.
  59. /// </summary>
  60. /// <value>the updater ID of the plugin</value>
  61. public string Id { get; internal set; }
  62. /// <summary>
  63. /// The version of the plugin.
  64. /// </summary>
  65. /// <value>the version of the plugin</value>
  66. public Version Version { get; internal set; }
  67. /// <summary>
  68. /// The file the plugin was loaded from.
  69. /// </summary>
  70. /// <value>the file the plugin was loaded from</value>
  71. public FileInfo File { get; internal set; }
  72. // ReSharper disable once UnusedAutoPropertyAccessor.Global
  73. /// <summary>
  74. /// The features this plugin requests.
  75. /// </summary>
  76. /// <value>the list of features requested by the plugin</value>
  77. public IReadOnlyList<Feature> Features => InternalFeatures;
  78. internal readonly List<Feature> InternalFeatures = new List<Feature>();
  79. internal bool IsSelf;
  80. /// <summary>
  81. /// Whether or not this metadata object represents a bare manifest.
  82. /// </summary>
  83. /// <value><see langword="true"/> if it is bare, <see langword="false"/> otherwise</value>
  84. public bool IsBare { get; internal set; }
  85. private PluginManifest manifest;
  86. internal HashSet<PluginMetadata> Dependencies { get; } = new HashSet<PluginMetadata>();
  87. internal PluginManifest Manifest
  88. {
  89. get => manifest;
  90. set
  91. {
  92. manifest = value;
  93. Name = value.Name;
  94. Version = value.Version;
  95. Id = value.Id;
  96. }
  97. }
  98. /// <summary>
  99. /// Gets all of the metadata as a readable string.
  100. /// </summary>
  101. /// <returns>the readable printable metadata string</returns>
  102. public override string ToString() => $"{Name}({Id}@{Version})({PluginType?.FullName}) from '{Utils.GetRelativePath(File?.FullName, BeatSaber.InstallPath)}'";
  103. }
  104. /// <summary>
  105. /// A container object for all the data relating to a plugin.
  106. /// </summary>
  107. public class PluginInfo
  108. {
  109. internal IPlugin Plugin { get; set; }
  110. /// <summary>
  111. /// Metadata for the plugin.
  112. /// </summary>
  113. /// <value>the metadata for this plugin</value>
  114. public PluginMetadata Metadata { get; internal set; } = new PluginMetadata();
  115. }
  116. internal static void YeetIfNeeded()
  117. {
  118. string pluginDir = BeatSaber.PluginsPath;
  119. var gameVer = BeatSaber.GameVersion;
  120. var lastVerS = SelfConfig.LastGameVersion_;
  121. var lastVer = lastVerS != null ? new AlmostVersion(lastVerS, gameVer) : null;
  122. if (SelfConfig.YeetMods_ && lastVer != null && gameVer != lastVer)
  123. {
  124. var oldPluginsName = Path.Combine(BeatSaber.InstallPath, $"Old {lastVer} Plugins");
  125. var newPluginsName = Path.Combine(BeatSaber.InstallPath, $"Old {gameVer} Plugins");
  126. if (Directory.Exists(oldPluginsName))
  127. Directory.Delete(oldPluginsName, true);
  128. Directory.Move(pluginDir, oldPluginsName);
  129. if (Directory.Exists(newPluginsName))
  130. Directory.Move(newPluginsName, pluginDir);
  131. else
  132. Directory.CreateDirectory(pluginDir);
  133. }
  134. SelfConfig.SelfConfigRef.Value.LastGameVersion = gameVer.ToString();
  135. SelfConfig.LoaderConfig.Store(SelfConfig.SelfConfigRef.Value);
  136. }
  137. internal static List<PluginMetadata> PluginsMetadata = new List<PluginMetadata>();
  138. internal static List<PluginMetadata> DisabledPlugins = new List<PluginMetadata>();
  139. private static readonly Regex embeddedTextDescriptionPattern = new Regex(@"#!\[(.+)\]", RegexOptions.Compiled | RegexOptions.Singleline);
  140. internal static void LoadMetadata()
  141. {
  142. string[] plugins = Directory.GetFiles(BeatSaber.PluginsPath, "*.dll");
  143. try
  144. {
  145. var selfMeta = new PluginMetadata
  146. {
  147. Assembly = Assembly.GetExecutingAssembly(),
  148. File = new FileInfo(Path.Combine(BeatSaber.InstallPath, "IPA.exe")),
  149. PluginType = null,
  150. IsSelf = true
  151. };
  152. string manifest;
  153. using (var manifestReader =
  154. new StreamReader(
  155. selfMeta.Assembly.GetManifestResourceStream(typeof(PluginLoader), "manifest.json") ??
  156. throw new InvalidOperationException()))
  157. manifest = manifestReader.ReadToEnd();
  158. selfMeta.Manifest = JsonConvert.DeserializeObject<PluginManifest>(manifest);
  159. PluginsMetadata.Add(selfMeta);
  160. }
  161. catch (Exception e)
  162. {
  163. Logger.loader.Critical("Error loading own manifest");
  164. Logger.loader.Critical(e);
  165. }
  166. foreach (var plugin in plugins)
  167. {
  168. var metadata = new PluginMetadata
  169. {
  170. File = new FileInfo(Path.Combine(BeatSaber.PluginsPath, plugin)),
  171. IsSelf = false
  172. };
  173. try
  174. {
  175. var pluginModule = AssemblyDefinition.ReadAssembly(plugin, new ReaderParameters
  176. {
  177. ReadingMode = ReadingMode.Immediate,
  178. ReadWrite = false,
  179. AssemblyResolver = new CecilLibLoader()
  180. }).MainModule;
  181. string pluginNs = "";
  182. foreach (var resource in pluginModule.Resources)
  183. {
  184. const string manifestSuffix = ".manifest.json";
  185. if (!(resource is EmbeddedResource embedded) ||
  186. !embedded.Name.EndsWith(manifestSuffix)) continue;
  187. pluginNs = embedded.Name.Substring(0, embedded.Name.Length - manifestSuffix.Length);
  188. string manifest;
  189. using (var manifestReader = new StreamReader(embedded.GetResourceStream()))
  190. manifest = manifestReader.ReadToEnd();
  191. metadata.Manifest = JsonConvert.DeserializeObject<PluginManifest>(manifest);
  192. break;
  193. }
  194. if (metadata.Manifest == null)
  195. {
  196. #if DIRE_LOADER_WARNINGS
  197. Logger.loader.Error($"Could not find manifest.json for {Path.GetFileName(plugin)}");
  198. #else
  199. Logger.loader.Notice($"No manifest.json in {Path.GetFileName(plugin)}");
  200. #endif
  201. continue;
  202. }
  203. foreach (var type in pluginModule.Types)
  204. {
  205. if (type.Namespace != pluginNs) continue;
  206. // TODO: change this to just IPlugin
  207. if (type.HasInterface(typeof(IPlugin).FullName))
  208. {
  209. metadata.PluginType = type;
  210. break;
  211. }
  212. }
  213. if (metadata.PluginType == null)
  214. {
  215. Logger.loader.Error($"No plugin found in the manifest namespace ({pluginNs}) in {Path.GetFileName(plugin)}");
  216. continue;
  217. }
  218. Logger.loader.Debug($"Adding info for {Path.GetFileName(plugin)}");
  219. PluginsMetadata.Add(metadata);
  220. }
  221. catch (Exception e)
  222. {
  223. Logger.loader.Error($"Could not load data for plugin {Path.GetFileName(plugin)}");
  224. Logger.loader.Error(e);
  225. ignoredPlugins.Add(metadata);
  226. }
  227. }
  228. IEnumerable<string> bareManifests = Directory.GetFiles(BeatSaber.PluginsPath, "*.json");
  229. bareManifests = bareManifests.Concat(Directory.GetFiles(BeatSaber.PluginsPath, "*.manifest"));
  230. foreach (var manifest in bareManifests)
  231. {
  232. try
  233. {
  234. var metadata = new PluginMetadata
  235. {
  236. File = new FileInfo(Path.Combine(BeatSaber.PluginsPath, manifest)),
  237. IsSelf = false,
  238. IsBare = true,
  239. };
  240. metadata.Manifest = JsonConvert.DeserializeObject<PluginManifest>(File.ReadAllText(manifest));
  241. Logger.loader.Debug($"Adding info for bare manifest {Path.GetFileName(manifest)}");
  242. PluginsMetadata.Add(metadata);
  243. }
  244. catch (Exception e)
  245. {
  246. Logger.loader.Error($"Could not load data for bare manifest {Path.GetFileName(manifest)}");
  247. Logger.loader.Error(e);
  248. }
  249. }
  250. foreach (var meta in PluginsMetadata)
  251. { // process description include
  252. var lines = meta.Manifest.Description.Split('\n');
  253. var m = embeddedTextDescriptionPattern.Match(lines[0]);
  254. if (m.Success)
  255. {
  256. if (meta.IsBare)
  257. {
  258. Logger.loader.Warn($"Bare manifest cannot specify description file");
  259. meta.Manifest.Description = string.Join("\n", lines.Skip(1).StrJP()); // ignore first line
  260. continue;
  261. }
  262. var name = m.Groups[1].Value;
  263. string description;
  264. if (!meta.IsSelf)
  265. {
  266. var resc = meta.PluginType.Module.Resources.Select(r => r as EmbeddedResource)
  267. .NonNull()
  268. .FirstOrDefault(r => r.Name == name);
  269. if (resc == null)
  270. {
  271. Logger.loader.Warn($"Could not find description file for plugin {meta.Name} ({name}); ignoring include");
  272. meta.Manifest.Description = string.Join("\n", lines.Skip(1).StrJP()); // ignore first line
  273. continue;
  274. }
  275. using (var reader = new StreamReader(resc.GetResourceStream()))
  276. description = reader.ReadToEnd();
  277. }
  278. else
  279. {
  280. using (var descriptionReader =
  281. new StreamReader(
  282. meta.Assembly.GetManifestResourceStream(name) ??
  283. throw new InvalidOperationException()))
  284. description = descriptionReader.ReadToEnd();
  285. }
  286. meta.Manifest.Description = description;
  287. }
  288. }
  289. }
  290. // keep track of these for the updater; it should still be able to update mods not loaded
  291. // TODO: add ignore reason
  292. internal static HashSet<PluginMetadata> ignoredPlugins = new HashSet<PluginMetadata>();
  293. internal static void Resolve()
  294. { // resolves duplicates and conflicts, etc
  295. PluginsMetadata.Sort((a, b) => b.Version.CompareTo(a.Version));
  296. var ids = new HashSet<string>();
  297. var ignore = new HashSet<PluginMetadata>();
  298. var resolved = new List<PluginMetadata>(PluginsMetadata.Count);
  299. foreach (var meta in PluginsMetadata)
  300. {
  301. if (meta.Id != null)
  302. {
  303. if (ids.Contains(meta.Id))
  304. {
  305. Logger.loader.Warn($"Found duplicates of {meta.Id}, using newest");
  306. ignore.Add(meta);
  307. ignoredPlugins.Add(meta);
  308. continue; // because of sorted order, hightest order will always be the first one
  309. }
  310. bool processedLater = false;
  311. foreach (var meta2 in PluginsMetadata)
  312. {
  313. if (ignore.Contains(meta2)) continue;
  314. if (meta == meta2)
  315. {
  316. processedLater = true;
  317. continue;
  318. }
  319. if (!meta2.Manifest.Conflicts.ContainsKey(meta.Id)) continue;
  320. var range = meta2.Manifest.Conflicts[meta.Id];
  321. if (!range.IsSatisfied(meta.Version)) continue;
  322. Logger.loader.Warn($"{meta.Id}@{meta.Version} conflicts with {meta2.Name}");
  323. if (processedLater)
  324. {
  325. Logger.loader.Warn($"Ignoring {meta2.Name}");
  326. ignore.Add(meta2);
  327. }
  328. else
  329. {
  330. Logger.loader.Warn($"Ignoring {meta.Name}");
  331. ignore.Add(meta);
  332. break;
  333. }
  334. }
  335. }
  336. if (ignore.Contains(meta))
  337. {
  338. ignoredPlugins.Add(meta);
  339. continue;
  340. }
  341. if (meta.Id != null)
  342. ids.Add(meta.Id);
  343. resolved.Add(meta);
  344. }
  345. PluginsMetadata = resolved;
  346. }
  347. private static void FilterDisabled()
  348. {
  349. var enabled = new List<PluginMetadata>(PluginsMetadata.Count);
  350. var disabled = DisabledConfig.Ref.Value.DisabledModIds;
  351. foreach (var meta in PluginsMetadata)
  352. {
  353. if (disabled.Contains(meta.Id ?? meta.Name))
  354. DisabledPlugins.Add(meta);
  355. else
  356. enabled.Add(meta);
  357. }
  358. PluginsMetadata = enabled;
  359. }
  360. internal static void ComputeLoadOrder()
  361. {
  362. #if DEBUG
  363. Logger.loader.Debug(string.Join(", ", PluginsMetadata.Select(p => p.ToString()).StrJP()));
  364. #endif
  365. bool InsertInto(HashSet<PluginMetadata> root, PluginMetadata meta, bool isRoot = false)
  366. { // this is slow, and hella recursive
  367. bool inserted = false;
  368. foreach (var sr in root)
  369. {
  370. inserted = inserted || InsertInto(sr.Dependencies, meta);
  371. if (meta.Id != null)
  372. if (sr.Manifest.Dependencies.ContainsKey(meta.Id) || sr.Manifest.LoadAfter.Contains(meta.Id))
  373. inserted = inserted || sr.Dependencies.Add(meta);
  374. if (sr.Id != null)
  375. if (meta.Manifest.LoadBefore.Contains(sr.Id))
  376. inserted = inserted || sr.Dependencies.Add(meta);
  377. }
  378. if (isRoot)
  379. {
  380. foreach (var sr in root)
  381. {
  382. InsertInto(meta.Dependencies, sr);
  383. if (sr.Id != null)
  384. if (meta.Manifest.Dependencies.ContainsKey(sr.Id) || meta.Manifest.LoadAfter.Contains(sr.Id))
  385. meta.Dependencies.Add(sr);
  386. if (meta.Id != null)
  387. if (sr.Manifest.LoadBefore.Contains(meta.Id))
  388. meta.Dependencies.Add(sr);
  389. }
  390. root.Add(meta);
  391. }
  392. return inserted;
  393. }
  394. var pluginTree = new HashSet<PluginMetadata>();
  395. foreach (var meta in PluginsMetadata)
  396. InsertInto(pluginTree, meta, true);
  397. void DeTree(List<PluginMetadata> into, HashSet<PluginMetadata> tree)
  398. {
  399. foreach (var st in tree)
  400. if (!into.Contains(st))
  401. {
  402. DeTree(into, st.Dependencies);
  403. into.Add(st);
  404. }
  405. }
  406. PluginsMetadata = new List<PluginMetadata>();
  407. DeTree(PluginsMetadata, pluginTree);
  408. #if DEBUG
  409. Logger.loader.Debug(string.Join(", ", PluginsMetadata.Select(p => p.ToString()).StrJP()));
  410. #endif
  411. }
  412. internal static void ResolveDependencies()
  413. {
  414. var metadata = new List<PluginMetadata>();
  415. var pluginsToLoad = new Dictionary<string, Version>();
  416. var disabledLookup = DisabledPlugins.NonNull(m => m.Id).ToDictionary(m => m.Id, m => m.Version);
  417. foreach (var meta in PluginsMetadata)
  418. {
  419. bool load = true;
  420. bool disable = false;
  421. foreach (var dep in meta.Manifest.Dependencies)
  422. {
  423. #if DEBUG
  424. Logger.loader.Debug($"Looking for dependency {dep.Key} with version range {dep.Value.Intersect(new SemVer.Range("*.*.*"))}");
  425. #endif
  426. if (pluginsToLoad.ContainsKey(dep.Key) && dep.Value.IsSatisfied(pluginsToLoad[dep.Key]))
  427. continue;
  428. load = false;
  429. if (disabledLookup.ContainsKey(dep.Key) && dep.Value.IsSatisfied(disabledLookup[dep.Key]))
  430. {
  431. disable = true;
  432. Logger.loader.Warn($"Dependency {dep.Key} was found, but disabled. Disabling {meta.Name} too.");
  433. }
  434. else
  435. Logger.loader.Warn($"{meta.Name} is missing dependency {dep.Key}@{dep.Value}");
  436. break;
  437. }
  438. if (load)
  439. {
  440. metadata.Add(meta);
  441. if (meta.Id != null)
  442. pluginsToLoad.Add(meta.Id, meta.Version);
  443. }
  444. else if (disable)
  445. {
  446. DisabledPlugins.Add(meta);
  447. DisabledConfig.Ref.Value.DisabledModIds.Add(meta.Id ?? meta.Name);
  448. }
  449. else
  450. ignoredPlugins.Add(meta);
  451. }
  452. PluginsMetadata = metadata;
  453. }
  454. internal static void InitFeatures()
  455. {
  456. var parsedFeatures = PluginsMetadata.Select(m =>
  457. (metadata: m,
  458. features: m.Manifest.Features.Select(feature =>
  459. (feature, parsed: Ref.Create<Feature.FeatureParse?>(null))
  460. ).ToList()
  461. )
  462. ).ToList();
  463. while (DefineFeature.NewFeature)
  464. {
  465. DefineFeature.NewFeature = false;
  466. foreach (var (metadata, features) in parsedFeatures)
  467. for (var i = 0; i < features.Count; i++)
  468. {
  469. var feature = features[i];
  470. var success = Feature.TryParseFeature(feature.feature, metadata, out var featureObj,
  471. out var exception, out var valid, out var parsed, feature.parsed.Value);
  472. if (!success && !valid && featureObj == null && exception == null) // no feature of type found
  473. feature.parsed.Value = parsed;
  474. else if (success)
  475. {
  476. if (valid && featureObj.StoreOnPlugin)
  477. metadata.InternalFeatures.Add(featureObj);
  478. else if (!valid)
  479. Logger.features.Warn(
  480. $"Feature not valid on {metadata.Name}: {featureObj.InvalidMessage}");
  481. features.RemoveAt(i--);
  482. }
  483. else
  484. {
  485. Logger.features.Error($"Error parsing feature definition on {metadata.Name}");
  486. Logger.features.Error(exception);
  487. features.RemoveAt(i--);
  488. }
  489. }
  490. foreach (var plugin in PluginsMetadata)
  491. foreach (var feature in plugin.Features)
  492. feature.Evaluate();
  493. }
  494. foreach (var plugin in parsedFeatures)
  495. {
  496. if (plugin.features.Count <= 0) continue;
  497. Logger.features.Warn($"On plugin {plugin.metadata.Name}:");
  498. foreach (var feature in plugin.features)
  499. Logger.features.Warn($" Feature not found with name {feature.feature}");
  500. }
  501. }
  502. internal static void ReleaseAll(bool full = false)
  503. {
  504. if (full)
  505. ignoredPlugins = new HashSet<PluginMetadata>();
  506. else
  507. {
  508. foreach (var m in PluginsMetadata)
  509. ignoredPlugins.Add(m);
  510. foreach (var m in ignoredPlugins)
  511. { // clean them up so we can still use the metadata for updates
  512. m.InternalFeatures.Clear();
  513. m.PluginType = null;
  514. m.Assembly = null;
  515. }
  516. }
  517. PluginsMetadata = new List<PluginMetadata>();
  518. DisabledPlugins = new List<PluginMetadata>();
  519. Feature.Reset();
  520. GC.Collect();
  521. }
  522. internal static void Load(PluginMetadata meta)
  523. {
  524. if (meta.Assembly == null && meta.PluginType != null)
  525. meta.Assembly = Assembly.LoadFrom(meta.File.FullName);
  526. }
  527. internal static PluginInfo InitPlugin(PluginMetadata meta)
  528. {
  529. if (meta.PluginType == null)
  530. return new PluginInfo()
  531. {
  532. Metadata = meta,
  533. Plugin = null
  534. };
  535. var info = new PluginInfo();
  536. if (meta.Manifest.GameVersion != BeatSaber.GameVersion)
  537. Logger.loader.Warn($"Mod {meta.Name} developed for game version {meta.Manifest.GameVersion}, so it may not work properly.");
  538. try
  539. { // TODO: add dependency checking for when features prevent loading
  540. Load(meta);
  541. Feature denyingFeature = null;
  542. if (!meta.Features.All(f => (denyingFeature = f).BeforeLoad(meta)))
  543. {
  544. Logger.loader.Warn(
  545. $"Feature {denyingFeature?.GetType()} denied plugin {meta.Name} from loading! {denyingFeature?.InvalidMessage}");
  546. ignoredPlugins.Add(meta);
  547. return null;
  548. }
  549. var type = meta.Assembly.GetType(meta.PluginType.FullName);
  550. var instance = Activator.CreateInstance(type) as IPlugin;
  551. info.Metadata = meta;
  552. info.Plugin = instance;
  553. var init = type.GetMethod("Init", BindingFlags.Instance | BindingFlags.Public);
  554. if (init != null)
  555. {
  556. denyingFeature = null;
  557. if (!meta.Features.All(f => (denyingFeature = f).BeforeInit(info)))
  558. {
  559. Logger.loader.Warn(
  560. $"Feature {denyingFeature?.GetType()} denied plugin {meta.Name} from initializing! {denyingFeature?.InvalidMessage}");
  561. ignoredPlugins.Add(meta);
  562. return null;
  563. }
  564. PluginInitInjector.Inject(init, info);
  565. }
  566. foreach (var feature in meta.Features)
  567. try
  568. {
  569. feature.AfterInit(info, info.Plugin);
  570. }
  571. catch (Exception e)
  572. {
  573. Logger.loader.Critical($"Feature errored in {nameof(Feature.AfterInit)}: {e}");
  574. }
  575. try // TODO: move this out to after all plugins have been inited
  576. {
  577. instance.OnEnable();
  578. }
  579. catch (Exception e)
  580. {
  581. Logger.loader.Error($"Error occurred trying to enable {meta.Name}");
  582. Logger.loader.Error(e);
  583. return null; // is enable failure a full load failure?
  584. }
  585. }
  586. catch (AmbiguousMatchException)
  587. {
  588. Logger.loader.Error($"Only one Init allowed per plugin (ambiguous match in {meta.Name})");
  589. // not adding to ignoredPlugins here because this should only happen in a development context
  590. // if someone fucks this up on release thats on them
  591. return null;
  592. }
  593. catch (Exception e)
  594. {
  595. Logger.loader.Error($"Could not init plugin {meta.Name}: {e}");
  596. ignoredPlugins.Add(meta);
  597. return null;
  598. }
  599. return info;
  600. }
  601. internal static List<PluginInfo> LoadPlugins()
  602. {
  603. InitFeatures();
  604. DisabledPlugins.ForEach(Load); // make sure they get loaded into memory so their metadata and stuff can be read more easily
  605. return PluginsMetadata.Select(InitPlugin).NonNull().ToList();
  606. }
  607. }
  608. }