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. try
  169. {
  170. var metadata = new PluginMetadata
  171. {
  172. File = new FileInfo(Path.Combine(BeatSaber.PluginsPath, plugin)),
  173. IsSelf = false
  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. }
  226. }
  227. IEnumerable<string> bareManifests = Directory.GetFiles(BeatSaber.PluginsPath, "*.json");
  228. bareManifests = bareManifests.Concat(Directory.GetFiles(BeatSaber.PluginsPath, "*.manifest"));
  229. foreach (var manifest in bareManifests)
  230. {
  231. try
  232. {
  233. var metadata = new PluginMetadata
  234. {
  235. File = new FileInfo(Path.Combine(BeatSaber.PluginsPath, manifest)),
  236. IsSelf = false,
  237. IsBare = true,
  238. };
  239. metadata.Manifest = JsonConvert.DeserializeObject<PluginManifest>(File.ReadAllText(manifest));
  240. Logger.loader.Debug($"Adding info for bare manifest {Path.GetFileName(manifest)}");
  241. PluginsMetadata.Add(metadata);
  242. }
  243. catch (Exception e)
  244. {
  245. Logger.loader.Error($"Could not load data for bare manifest {Path.GetFileName(manifest)}");
  246. Logger.loader.Error(e);
  247. }
  248. }
  249. foreach (var meta in PluginsMetadata)
  250. { // process description include
  251. var lines = meta.Manifest.Description.Split('\n');
  252. var m = embeddedTextDescriptionPattern.Match(lines[0]);
  253. if (m.Success)
  254. {
  255. if (meta.IsBare)
  256. {
  257. Logger.loader.Warn($"Bare manifest cannot specify description file");
  258. meta.Manifest.Description = string.Join("\n", lines.Skip(1).StrJP()); // ignore first line
  259. continue;
  260. }
  261. var name = m.Groups[1].Value;
  262. string description;
  263. if (!meta.IsSelf)
  264. {
  265. var resc = meta.PluginType.Module.Resources.Select(r => r as EmbeddedResource)
  266. .Where(r => r != null)
  267. .FirstOrDefault(r => r.Name == name);
  268. if (resc == null)
  269. {
  270. Logger.loader.Warn($"Could not find description file for plugin {meta.Name} ({name}); ignoring include");
  271. meta.Manifest.Description = string.Join("\n", lines.Skip(1).StrJP()); // ignore first line
  272. continue;
  273. }
  274. using (var reader = new StreamReader(resc.GetResourceStream()))
  275. description = reader.ReadToEnd();
  276. }
  277. else
  278. {
  279. using (var descriptionReader =
  280. new StreamReader(
  281. meta.Assembly.GetManifestResourceStream(name) ??
  282. throw new InvalidOperationException()))
  283. description = descriptionReader.ReadToEnd();
  284. }
  285. meta.Manifest.Description = description;
  286. }
  287. }
  288. }
  289. // keep track of these for the updater; it should still be able to update mods not loaded
  290. // TODO: add ignore reason
  291. internal static HashSet<PluginMetadata> ignoredPlugins = new HashSet<PluginMetadata>();
  292. internal static void Resolve()
  293. { // resolves duplicates and conflicts, etc
  294. PluginsMetadata.Sort((a, b) => b.Version.CompareTo(a.Version));
  295. var ids = new HashSet<string>();
  296. var ignore = new HashSet<PluginMetadata>();
  297. var resolved = new List<PluginMetadata>(PluginsMetadata.Count);
  298. foreach (var meta in PluginsMetadata)
  299. {
  300. if (meta.Id != null)
  301. {
  302. if (ids.Contains(meta.Id))
  303. {
  304. Logger.loader.Warn($"Found duplicates of {meta.Id}, using newest");
  305. ignore.Add(meta);
  306. ignoredPlugins.Add(meta);
  307. continue; // because of sorted order, hightest order will always be the first one
  308. }
  309. bool processedLater = false;
  310. foreach (var meta2 in PluginsMetadata)
  311. {
  312. if (ignore.Contains(meta2)) continue;
  313. if (meta == meta2)
  314. {
  315. processedLater = true;
  316. continue;
  317. }
  318. if (!meta2.Manifest.Conflicts.ContainsKey(meta.Id)) continue;
  319. var range = meta2.Manifest.Conflicts[meta.Id];
  320. if (!range.IsSatisfied(meta.Version)) continue;
  321. Logger.loader.Warn($"{meta.Id}@{meta.Version} conflicts with {meta2.Name}");
  322. if (processedLater)
  323. {
  324. Logger.loader.Warn($"Ignoring {meta2.Name}");
  325. ignore.Add(meta2);
  326. }
  327. else
  328. {
  329. Logger.loader.Warn($"Ignoring {meta.Name}");
  330. ignore.Add(meta);
  331. break;
  332. }
  333. }
  334. }
  335. if (ignore.Contains(meta))
  336. {
  337. ignoredPlugins.Add(meta);
  338. continue;
  339. }
  340. if (meta.Id != null)
  341. ids.Add(meta.Id);
  342. resolved.Add(meta);
  343. }
  344. PluginsMetadata = resolved;
  345. }
  346. private static void FilterDisabled()
  347. {
  348. var enabled = new List<PluginMetadata>(PluginsMetadata.Count);
  349. var disabled = DisabledConfig.Ref.Value.DisabledModIds;
  350. foreach (var meta in PluginsMetadata)
  351. {
  352. if (disabled.Contains(meta.Id ?? meta.Name))
  353. DisabledPlugins.Add(meta);
  354. else
  355. enabled.Add(meta);
  356. }
  357. PluginsMetadata = enabled;
  358. }
  359. internal static void ComputeLoadOrder()
  360. {
  361. #if DEBUG
  362. Logger.loader.Debug(string.Join(", ", PluginsMetadata.Select(p => p.ToString()).StrJP()));
  363. #endif
  364. bool InsertInto(HashSet<PluginMetadata> root, PluginMetadata meta, bool isRoot = false)
  365. { // this is slow, and hella recursive
  366. bool inserted = false;
  367. foreach (var sr in root)
  368. {
  369. inserted = inserted || InsertInto(sr.Dependencies, meta);
  370. if (meta.Id != null)
  371. if (sr.Manifest.Dependencies.ContainsKey(meta.Id) || sr.Manifest.LoadAfter.Contains(meta.Id))
  372. inserted = inserted || sr.Dependencies.Add(meta);
  373. if (sr.Id != null)
  374. if (meta.Manifest.LoadBefore.Contains(sr.Id))
  375. inserted = inserted || sr.Dependencies.Add(meta);
  376. }
  377. if (isRoot)
  378. {
  379. foreach (var sr in root)
  380. {
  381. InsertInto(meta.Dependencies, sr);
  382. if (sr.Id != null)
  383. if (meta.Manifest.Dependencies.ContainsKey(sr.Id) || meta.Manifest.LoadAfter.Contains(sr.Id))
  384. meta.Dependencies.Add(sr);
  385. if (meta.Id != null)
  386. if (sr.Manifest.LoadBefore.Contains(meta.Id))
  387. meta.Dependencies.Add(sr);
  388. }
  389. root.Add(meta);
  390. }
  391. return inserted;
  392. }
  393. var pluginTree = new HashSet<PluginMetadata>();
  394. foreach (var meta in PluginsMetadata)
  395. InsertInto(pluginTree, meta, true);
  396. void DeTree(List<PluginMetadata> into, HashSet<PluginMetadata> tree)
  397. {
  398. foreach (var st in tree)
  399. if (!into.Contains(st))
  400. {
  401. DeTree(into, st.Dependencies);
  402. into.Add(st);
  403. }
  404. }
  405. PluginsMetadata = new List<PluginMetadata>();
  406. DeTree(PluginsMetadata, pluginTree);
  407. #if DEBUG
  408. Logger.loader.Debug(string.Join(", ", PluginsMetadata.Select(p => p.ToString()).StrJP()));
  409. #endif
  410. }
  411. internal static void ResolveDependencies()
  412. {
  413. var metadata = new List<PluginMetadata>();
  414. var pluginsToLoad = new Dictionary<string, Version>();
  415. var disabledLookup = DisabledPlugins.Where(m => m.Id != null).ToDictionary(m => m.Id, m => m.Version);
  416. foreach (var meta in PluginsMetadata)
  417. {
  418. bool load = true;
  419. bool disable = false;
  420. foreach (var dep in meta.Manifest.Dependencies)
  421. {
  422. #if DEBUG
  423. Logger.loader.Debug($"Looking for dependency {dep.Key} with version range {dep.Value.Intersect(new SemVer.Range("*.*.*"))}");
  424. #endif
  425. if (pluginsToLoad.ContainsKey(dep.Key) && dep.Value.IsSatisfied(pluginsToLoad[dep.Key]))
  426. continue;
  427. load = false;
  428. if (disabledLookup.ContainsKey(dep.Key) && dep.Value.IsSatisfied(disabledLookup[dep.Key]))
  429. {
  430. disable = true;
  431. Logger.loader.Warn($"Dependency {dep.Key} was found, but disabled. Disabling {meta.Name} too.");
  432. }
  433. else
  434. Logger.loader.Warn($"{meta.Name} is missing dependency {dep.Key}@{dep.Value}");
  435. break;
  436. }
  437. if (load)
  438. {
  439. metadata.Add(meta);
  440. if (meta.Id != null)
  441. pluginsToLoad.Add(meta.Id, meta.Version);
  442. }
  443. else if (disable)
  444. {
  445. DisabledPlugins.Add(meta);
  446. DisabledConfig.Ref.Value.DisabledModIds.Add(meta.Id ?? meta.Name);
  447. }
  448. else
  449. ignoredPlugins.Add(meta);
  450. }
  451. PluginsMetadata = metadata;
  452. }
  453. internal static void InitFeatures()
  454. {
  455. var parsedFeatures = PluginsMetadata.Select(m =>
  456. Tuple.Create(m,
  457. m.Manifest.Features.Select(f =>
  458. Tuple.Create(f, Ref.Create<Feature.FeatureParse?>(null))
  459. ).ToList()
  460. )
  461. ).ToList();
  462. while (DefineFeature.NewFeature)
  463. {
  464. DefineFeature.NewFeature = false;
  465. foreach (var plugin in parsedFeatures)
  466. for (var i = 0; i < plugin.Item2.Count; i++)
  467. {
  468. var feature = plugin.Item2[i];
  469. var success = Feature.TryParseFeature(feature.Item1, plugin.Item1, out var featureObj,
  470. out var exception, out var valid, out var parsed, feature.Item2.Value);
  471. if (!success && !valid && featureObj == null && exception == null) // no feature of type found
  472. feature.Item2.Value = parsed;
  473. else if (success)
  474. {
  475. if (valid && featureObj.StoreOnPlugin)
  476. plugin.Item1.InternalFeatures.Add(featureObj);
  477. else if (!valid)
  478. Logger.features.Warn(
  479. $"Feature not valid on {plugin.Item1.Name}: {featureObj.InvalidMessage}");
  480. plugin.Item2.RemoveAt(i--);
  481. }
  482. else
  483. {
  484. Logger.features.Error($"Error parsing feature definition on {plugin.Item1.Name}");
  485. Logger.features.Error(exception);
  486. plugin.Item2.RemoveAt(i--);
  487. }
  488. }
  489. foreach (var plugin in PluginsMetadata)
  490. foreach (var feature in plugin.Features)
  491. feature.Evaluate();
  492. }
  493. foreach (var plugin in parsedFeatures)
  494. {
  495. if (plugin.Item2.Count <= 0) continue;
  496. Logger.features.Warn($"On plugin {plugin.Item1.Name}:");
  497. foreach (var feature in plugin.Item2)
  498. Logger.features.Warn($" Feature not found with name {feature.Item1}");
  499. }
  500. }
  501. internal static void ReleaseAll(bool full = false)
  502. {
  503. if (full)
  504. ignoredPlugins = new HashSet<PluginMetadata>();
  505. else
  506. {
  507. foreach (var m in PluginsMetadata)
  508. ignoredPlugins.Add(m);
  509. foreach (var m in ignoredPlugins)
  510. { // clean them up so we can still use the metadata for updates
  511. m.InternalFeatures.Clear();
  512. m.PluginType = null;
  513. m.Assembly = null;
  514. }
  515. }
  516. PluginsMetadata = new List<PluginMetadata>();
  517. DisabledPlugins = new List<PluginMetadata>();
  518. Feature.Reset();
  519. GC.Collect();
  520. }
  521. internal static void Load(PluginMetadata meta)
  522. {
  523. if (meta.Assembly == null && meta.PluginType != null)
  524. meta.Assembly = Assembly.LoadFrom(meta.File.FullName);
  525. }
  526. internal static PluginInfo InitPlugin(PluginMetadata meta)
  527. {
  528. if (meta.PluginType == null)
  529. return new PluginInfo()
  530. {
  531. Metadata = meta,
  532. Plugin = null
  533. };
  534. var info = new PluginInfo();
  535. if (meta.Manifest.GameVersion != BeatSaber.GameVersion)
  536. Logger.loader.Warn($"Mod {meta.Name} developed for game version {meta.Manifest.GameVersion}, so it may not work properly.");
  537. try
  538. {
  539. Load(meta);
  540. Feature denyingFeature = null;
  541. if (!meta.Features.All(f => (denyingFeature = f).BeforeLoad(meta)))
  542. {
  543. Logger.loader.Warn(
  544. $"Feature {denyingFeature?.GetType()} denied plugin {meta.Name} from loading! {denyingFeature?.InvalidMessage}");
  545. ignoredPlugins.Add(meta);
  546. return null;
  547. }
  548. var type = meta.Assembly.GetType(meta.PluginType.FullName);
  549. var instance = Activator.CreateInstance(type) as _IPlugin;
  550. info.Metadata = meta;
  551. info.Plugin = instance;
  552. var init = type.GetMethod("Init", BindingFlags.Instance | BindingFlags.Public);
  553. if (init != null)
  554. {
  555. denyingFeature = null;
  556. if (!meta.Features.All(f => (denyingFeature = f).BeforeInit(info)))
  557. {
  558. Logger.loader.Warn(
  559. $"Feature {denyingFeature?.GetType()} denied plugin {meta.Name} from initializing! {denyingFeature?.InvalidMessage}");
  560. ignoredPlugins.Add(meta);
  561. return null;
  562. }
  563. PluginInitInjector.Inject(init, info);
  564. }
  565. foreach (var feature in meta.Features)
  566. try
  567. {
  568. // TODO: remove need for cast
  569. feature.AfterInit(info, info.Plugin as IPlugin);
  570. }
  571. catch (Exception e)
  572. {
  573. Logger.loader.Critical($"Feature errored in {nameof(Feature.AfterInit)}: {e}");
  574. }
  575. if (instance is IPlugin newPlugin) // TODO: remove this check, all plugins should be IPlugin
  576. try // TODO: move this out to after all plugins have been inited
  577. {
  578. newPlugin.OnEnable();
  579. }
  580. catch (Exception e)
  581. {
  582. Logger.loader.Error($"Error occurred trying to enable {meta.Name}");
  583. Logger.loader.Error(e);
  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).Where(p => p != null).ToList();
  606. }
  607. }
  608. }