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.

528 lines
26 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Reflection;
  7. using System.Runtime.InteropServices;
  8. using System.Text;
  9. using IPA.Config;
  10. using IPA.Old;
  11. using IPA.Utilities;
  12. using Mono.Cecil;
  13. using UnityEngine;
  14. using Logger = IPA.Logging.Logger;
  15. using System.Threading.Tasks;
  16. using IPA.Utilities.Async;
  17. using IPA.Loader.Features;
  18. #if NET4
  19. using TaskEx = System.Threading.Tasks.Task;
  20. using TaskEx6 = System.Threading.Tasks.Task;
  21. using Task = System.Threading.Tasks.Task;
  22. #endif
  23. #if NET3
  24. using Net3_Proxy;
  25. using Path = Net3_Proxy.Path;
  26. using File = Net3_Proxy.File;
  27. using Directory = Net3_Proxy.Directory;
  28. using Array = Net3_Proxy.Array;
  29. #endif
  30. namespace IPA.Loader
  31. {
  32. /// <summary>
  33. /// The manager class for all plugins.
  34. /// </summary>
  35. public static class PluginManager
  36. {
  37. #pragma warning disable CS0618 // Type or member is obsolete (IPlugin)
  38. private static List<PluginExecutor> _bsPlugins;
  39. internal static IEnumerable<PluginExecutor> BSMetas => _bsPlugins;
  40. /// <summary>
  41. /// Gets info about the enabled plugin with the specified name.
  42. /// </summary>
  43. /// <param name="name">the name of the plugin to get (must be an exact match)</param>
  44. /// <returns>the plugin metadata for the requested plugin or <see langword="null"/> if it doesn't exist or is disabled</returns>
  45. public static PluginMetadata GetPlugin(string name)
  46. => BSMetas.Select(p => p.Metadata).FirstOrDefault(p => p.Name == name);
  47. /// <summary>
  48. /// Gets info about the enabled plugin with the specified ID.
  49. /// </summary>
  50. /// <param name="name">the ID name of the plugin to get (must be an exact match)</param>
  51. /// <returns>the plugin metadata for the requested plugin or <see langword="null"/> if it doesn't exist or is disabled</returns>
  52. public static PluginMetadata GetPluginFromId(string name)
  53. => BSMetas.Select(p => p.Metadata).FirstOrDefault(p => p.Id == name);
  54. /// <summary>
  55. /// Gets a disabled plugin's metadata by its name.
  56. /// </summary>
  57. /// <param name="name">the name of the disabled plugin to get</param>
  58. /// <returns>the metadata for the corresponding plugin</returns>
  59. public static PluginMetadata GetDisabledPlugin(string name) =>
  60. DisabledPlugins.FirstOrDefault(p => p.Name == name);
  61. /// <summary>
  62. /// Gets a disabled plugin's metadata by its ID.
  63. /// </summary>
  64. /// <param name="name">the ID of the disabled plugin to get</param>
  65. /// <returns>the metadata for the corresponding plugin</returns>
  66. public static PluginMetadata GetDisabledPluginFromId(string name) =>
  67. DisabledPlugins.FirstOrDefault(p => p.Id == name);
  68. /// <summary>
  69. /// Creates a new transaction for mod enabling and disabling mods simultaneously.
  70. /// </summary>
  71. /// <returns>a new <see cref="StateTransitionTransaction"/> that captures the current state of loaded mods</returns>
  72. public static StateTransitionTransaction PluginStateTransaction()
  73. => new StateTransitionTransaction(EnabledPlugins, DisabledPlugins);
  74. private static readonly object commitTransactionLockObject = new object();
  75. internal static Task CommitTransaction(StateTransitionTransaction transaction)
  76. {
  77. if (!transaction.HasStateChanged) return TaskEx.WhenAll();
  78. if (!UnityGame.OnMainThread)
  79. {
  80. var transactionCopy = transaction.Clone();
  81. transaction.Dispose();
  82. return UnityMainThreadTaskScheduler.Factory.StartNew(() => CommitTransaction(transactionCopy)).Unwrap();
  83. }
  84. lock (commitTransactionLockObject)
  85. {
  86. if (transaction.CurrentlyEnabled.Except(EnabledPlugins)
  87. .Concat(EnabledPlugins.Except(transaction.CurrentlyEnabled)).Any()
  88. || transaction.CurrentlyDisabled.Except(DisabledPlugins)
  89. .Concat(DisabledPlugins.Except(transaction.CurrentlyDisabled)).Any())
  90. { // ensure that the transaction's base state reflects the current state, otherwise throw
  91. transaction.Dispose();
  92. throw new InvalidOperationException("Transaction no longer resembles the current state of plugins");
  93. }
  94. var toEnable = transaction.ToEnable;
  95. var toDisable = transaction.ToDisable;
  96. transaction.Dispose();
  97. using var disabledChangeTransaction = DisabledConfig.Instance.ChangeTransaction();
  98. {
  99. // first enable the mods that need to be
  100. void DeTree(List<PluginMetadata> into, IEnumerable<PluginMetadata> tree)
  101. {
  102. foreach (var st in tree)
  103. if (toEnable.Contains(st) && !into.Contains(st))
  104. {
  105. DeTree(into, st.Dependencies);
  106. into.Add(st);
  107. }
  108. }
  109. var enableOrder = new List<PluginMetadata>();
  110. DeTree(enableOrder, toEnable);
  111. foreach (var meta in enableOrder)
  112. {
  113. var executor = runtimeDisabledPlugins.FirstOrDefault(e => e.Metadata == meta);
  114. if (meta.RuntimeOptions == RuntimeOptions.DynamicInit)
  115. {
  116. if (executor != null)
  117. runtimeDisabledPlugins.Remove(executor);
  118. else
  119. executor = PluginLoader.InitPlugin(meta, EnabledPlugins);
  120. if (executor == null) continue; // couldn't initialize, skip to next
  121. }
  122. PluginLoader.DisabledPlugins.Remove(meta);
  123. DisabledConfig.Instance.DisabledModIds.Remove(meta.Id ?? meta.Name);
  124. PluginEnabled?.Invoke(meta, meta.RuntimeOptions != RuntimeOptions.DynamicInit);
  125. if (meta.RuntimeOptions == RuntimeOptions.DynamicInit)
  126. {
  127. _bsPlugins.Add(executor);
  128. try
  129. {
  130. executor.Enable();
  131. }
  132. catch (Exception e)
  133. {
  134. Logger.loader.Error($"Error while enabling {meta.Id}:");
  135. Logger.loader.Error(e);
  136. // this should still be considered enabled, hence its position
  137. }
  138. }
  139. }
  140. }
  141. var result = TaskEx.WhenAll();
  142. {
  143. // then disable the mods that need to be
  144. static DisableExecutor MakeDisableExec(PluginExecutor e)
  145. => new DisableExecutor
  146. {
  147. Executor = e,
  148. Dependents = BSMetas.Where(f => f.Metadata.Dependencies.Contains(e.Metadata)).Select(MakeDisableExec)
  149. };
  150. var disableExecs = toDisable.Select(m => BSMetas.FirstOrDefault(e => e.Metadata == m)).NonNull().ToArray(); // eagerly evaluate once
  151. foreach (var exec in disableExecs)
  152. {
  153. PluginLoader.DisabledPlugins.Add(exec.Metadata);
  154. DisabledConfig.Instance.DisabledModIds.Add(exec.Metadata.Id ?? exec.Metadata.Name);
  155. if (exec.Metadata.RuntimeOptions == RuntimeOptions.DynamicInit)
  156. {
  157. runtimeDisabledPlugins.Add(exec);
  158. _bsPlugins.Remove(exec);
  159. }
  160. PluginDisabled?.Invoke(exec.Metadata, exec.Metadata.RuntimeOptions != RuntimeOptions.DynamicInit);
  161. }
  162. var disableStructure = disableExecs.Select(MakeDisableExec);
  163. static Task Disable(DisableExecutor exec, Dictionary<PluginExecutor, Task> alreadyDisabled)
  164. {
  165. if (alreadyDisabled.TryGetValue(exec.Executor, out var task))
  166. return task;
  167. else
  168. {
  169. if (exec.Executor.Metadata.RuntimeOptions != RuntimeOptions.DynamicInit)
  170. return TaskEx6.FromException(new CannotRuntimeDisableException(exec.Executor.Metadata));
  171. var res = TaskEx.WhenAll(exec.Dependents.Select(d => Disable(d, alreadyDisabled)))
  172. .ContinueWith(t =>
  173. {
  174. if (t.IsFaulted) {
  175. return TaskEx.WhenAll(t, TaskEx6.FromException(
  176. new CannotRuntimeDisableException(exec.Executor.Metadata, "Dependents cannot be disabled for plugin")));
  177. }
  178. return exec.Executor.Disable()
  179. .ContinueWith(t =>
  180. {
  181. foreach (var feature in exec.Executor.Metadata.Features)
  182. {
  183. try {
  184. feature.AfterDisable(exec.Executor.Metadata);
  185. }
  186. catch (Exception e)
  187. {
  188. Logger.loader.Critical($"Feature errored in {nameof(Feature.AfterDisable)}: {e}");
  189. }
  190. }
  191. }, UnityMainThreadTaskScheduler.Default);
  192. }, UnityMainThreadTaskScheduler.Default).Unwrap();
  193. // We do not want to call the disable method if a dependent couldn't be disabled
  194. // By scheduling on a UnityMainThreadScheduler, we ensure that Disable() is always called on the Unity main thread
  195. alreadyDisabled.Add(exec.Executor, res);
  196. return res;
  197. }
  198. }
  199. var disabled = new Dictionary<PluginExecutor, Task>();
  200. result = TaskEx.WhenAll(disableStructure.Select(d => Disable(d, disabled)));
  201. }
  202. OnAnyPluginsStateChanged?.Invoke(result, toEnable, toDisable);
  203. // if there are any that are capable of enabling/disabling at runtime, run event handler
  204. if (toEnable.Concat(toDisable).Any(m => m.RuntimeOptions == RuntimeOptions.DynamicInit))
  205. OnPluginsStateChanged?.Invoke(result);
  206. //DisabledConfig.Instance.Changed();
  207. // changed is handled by transaction
  208. return result;
  209. }
  210. }
  211. private struct DisableExecutor
  212. {
  213. public PluginExecutor Executor;
  214. public IEnumerable<DisableExecutor> Dependents;
  215. }
  216. /// <summary>
  217. /// Checks if a given plugin is disabled.
  218. /// </summary>
  219. /// <param name="meta">the plugin to check</param>
  220. /// <returns><see langword="true"/> if the plugin is disabled, <see langword="false"/> otherwise.</returns>
  221. public static bool IsDisabled(PluginMetadata meta) => DisabledPlugins.Contains(meta);
  222. /// <summary>
  223. /// Checks if a given plugin is enabled.
  224. /// </summary>
  225. /// <param name="meta">the plugin to check</param>
  226. /// <returns><see langword="true"/> if the plugin is enabled, <see langword="false"/> otherwise.</returns>
  227. public static bool IsEnabled(PluginMetadata meta) => BSMetas.Any(p => p.Metadata == meta);
  228. /// <summary>
  229. /// An invoker for the <see cref="PluginEnabled"/> event.
  230. /// </summary>
  231. /// <param name="plugin">the plugin that was enabled</param>
  232. /// <param name="needsRestart">whether it needs a restart to take effect</param>
  233. public delegate void PluginEnableDelegate(PluginMetadata plugin, bool needsRestart);
  234. /// <summary>
  235. /// An invoker for the <see cref="PluginDisabled"/> event.
  236. /// </summary>
  237. /// <param name="plugin">the plugin that was disabled</param>
  238. /// <param name="needsRestart">whether it needs a restart to take effect</param>
  239. public delegate void PluginDisableDelegate(PluginMetadata plugin, bool needsRestart);
  240. /// <summary>
  241. /// A delegate representing a state change event for any plugin.
  242. /// </summary>
  243. /// <param name="changeTask">the <see cref="Task"/> representing the change</param>
  244. /// <param name="enabled">the plugins that were enabled in the change</param>
  245. /// <param name="disabled">the plugins that were disabled in the change</param>
  246. public delegate void OnAnyPluginsStateChangedDelegate(Task changeTask, IEnumerable<PluginMetadata> enabled, IEnumerable<PluginMetadata> disabled);
  247. /// <summary>
  248. /// Called whenever a plugin is enabled, before the plugin in question is enabled.
  249. /// </summary>
  250. public static event PluginEnableDelegate PluginEnabled;
  251. /// <summary>
  252. /// Called whenever a plugin is disabled, before the plugin in question is enabled.
  253. /// </summary>
  254. public static event PluginDisableDelegate PluginDisabled;
  255. /// <summary>
  256. /// Called whenever any plugins have their state changed at runtime with the <see cref="Task"/> representing that state change.
  257. /// </summary>
  258. /// <remarks>
  259. /// Note that this is called on the Unity main thread, and cannot therefore block, as the <see cref="Task"/>
  260. /// provided represents operations that also run on the Unity main thread.
  261. /// </remarks>
  262. public static event Action<Task> OnPluginsStateChanged;
  263. /// <summary>
  264. /// Called whenever any plugins, regardless of whether or not their change occurs during runtime, have their state changed.
  265. /// </summary>
  266. /// <remarks>
  267. /// Note that this is called on the Unity main thread, and cannot therefore block, as the <see cref="Task"/>
  268. /// provided represents operations that also run on the Unity main thread.
  269. /// </remarks>
  270. public static event OnAnyPluginsStateChangedDelegate OnAnyPluginsStateChanged;
  271. /// <summary>
  272. /// Gets a list of all enabled BSIPA plugins. Use <see cref="EnabledPlugins"/> instead of this.
  273. /// </summary>
  274. /// <value>a collection of all enabled plugins as <see cref="PluginMetadata"/>s</value>
  275. [Obsolete("This is an old name that no longer accurately represents its value. Use EnabledPlugins instead.")]
  276. public static IEnumerable<PluginMetadata> AllPlugins => EnabledPlugins;
  277. /// <summary>
  278. /// Gets a collection of all enabled plugins, as represented by <see cref="PluginMetadata"/>.
  279. /// </summary>
  280. /// <value>a collection of all enabled plugins</value>
  281. public static IEnumerable<PluginMetadata> EnabledPlugins => BSMetas.Select(p => p.Metadata);
  282. /// <summary>
  283. /// Gets a list of disabled BSIPA plugins.
  284. /// </summary>
  285. /// <value>a collection of all disabled plugins as <see cref="PluginMetadata"/></value>
  286. public static IEnumerable<PluginMetadata> DisabledPlugins => PluginLoader.DisabledPlugins;
  287. private static readonly HashSet<PluginExecutor> runtimeDisabledPlugins = new HashSet<PluginExecutor>();
  288. /// <summary>
  289. /// Gets a read-only dictionary of an ignored plugin to the reason it was ignored, as an <see cref="IgnoreReason"/>.
  290. /// </summary>
  291. /// <value>a dictionary of <see cref="PluginMetadata"/> to <see cref="IgnoreReason"/> of ignored plugins</value>
  292. public static IReadOnlyDictionary<PluginMetadata, IgnoreReason> IgnoredPlugins => PluginLoader.ignoredPlugins;
  293. /// <summary>
  294. /// An <see cref="IEnumerable{T}"/> of old IPA plugins.
  295. /// </summary>
  296. /// <value>all legacy plugin instances</value>
  297. [Obsolete("This exists only to provide support for legacy IPA plugins based on the IPlugin interface.")]
  298. public static IEnumerable<Old.IPlugin> Plugins => _ipaPlugins;
  299. private static List<Old.IPlugin> _ipaPlugins;
  300. internal static IConfigProvider SelfConfigProvider { get; set; }
  301. internal static void Load()
  302. {
  303. string pluginDirectory = UnityGame.PluginsPath;
  304. // Process.GetCurrentProcess().MainModule crashes the game and Assembly.GetEntryAssembly() is NULL,
  305. // so we need to resort to P/Invoke
  306. string exeName = Path.GetFileNameWithoutExtension(AppInfo.StartupPath);
  307. _bsPlugins = new List<PluginExecutor>();
  308. _ipaPlugins = new List<Old.IPlugin>();
  309. if (!Directory.Exists(pluginDirectory)) return;
  310. // initialize BSIPA plugins first
  311. _bsPlugins.AddRange(PluginLoader.LoadPlugins());
  312. var metadataPaths = PluginLoader.PluginsMetadata.Select(m => m.File.FullName).ToList();
  313. var ignoredPaths = PluginLoader.ignoredPlugins.Select(m => m.Key.File.FullName)
  314. .Concat(PluginLoader.ignoredPlugins.SelectMany(m => m.Key.AssociatedFiles.Select(f => f.FullName))).ToList();
  315. var disabledPaths = DisabledPlugins.Select(m => m.File.FullName).ToList();
  316. //Copy plugins to .cache
  317. string[] originalPlugins = Directory.GetFiles(pluginDirectory, "*.dll");
  318. string cacheDir = Path.Combine(pluginDirectory, ".cache");
  319. bool exists = Directory.Exists(cacheDir);
  320. if (exists)
  321. {
  322. foreach (string plugin in Directory.GetFiles(cacheDir, "*"))
  323. File.Delete(plugin);
  324. }
  325. foreach (string s in originalPlugins)
  326. {
  327. if (metadataPaths.Contains(s)) continue;
  328. if (ignoredPaths.Contains(s)) continue;
  329. if (disabledPaths.Contains(s)) continue;
  330. if (!exists)
  331. {
  332. Directory.CreateDirectory(cacheDir);
  333. exists = true;
  334. }
  335. string pluginCopy = Path.Combine(cacheDir, Path.GetFileName(s));
  336. #region Fix assemblies for refactor
  337. var module = ModuleDefinition.ReadModule(Path.Combine(pluginDirectory, s));
  338. foreach (var @ref in module.AssemblyReferences)
  339. { // fix assembly references
  340. if (@ref.Name == "IllusionPlugin" || @ref.Name == "IllusionInjector")
  341. {
  342. @ref.Name = "IPA.Loader";
  343. }
  344. }
  345. foreach (var @ref in module.GetTypeReferences())
  346. { // fix type references
  347. if (@ref.FullName == "IllusionPlugin.IPlugin") @ref.Namespace = "IPA.Old"; //@ref.Name = "";
  348. if (@ref.FullName == "IllusionPlugin.IEnhancedPlugin") @ref.Namespace = "IPA.Old"; //@ref.Name = "";
  349. if (@ref.FullName == "IllusionPlugin.IniFile") @ref.Namespace = "IPA.Config"; //@ref.Name = "";
  350. if (@ref.FullName == "IllusionPlugin.IModPrefs") @ref.Namespace = "IPA.Config"; //@ref.Name = "";
  351. if (@ref.FullName == "IllusionPlugin.ModPrefs") @ref.Namespace = "IPA.Config"; //@ref.Name = "";
  352. if (@ref.FullName == "IllusionPlugin.Utils.ReflectionUtil") @ref.Namespace = "IPA.Utilities"; //@ref.Name = "";
  353. if (@ref.FullName == "IllusionPlugin.Logging.Logger") @ref.Namespace = "IPA.Logging"; //@ref.Name = "";
  354. if (@ref.FullName == "IllusionPlugin.Logging.LogPrinter") @ref.Namespace = "IPA.Logging"; //@ref.Name = "";
  355. if (@ref.FullName == "IllusionInjector.PluginManager") @ref.Namespace = "IPA.Loader"; //@ref.Name = "";
  356. if (@ref.FullName == "IllusionInjector.PluginComponent") @ref.Namespace = "IPA.Loader"; //@ref.Name = "";
  357. if (@ref.FullName == "IllusionInjector.CompositeBSPlugin") @ref.Namespace = "IPA.Loader.Composite"; //@ref.Name = "";
  358. if (@ref.FullName == "IllusionInjector.CompositeIPAPlugin") @ref.Namespace = "IPA.Loader.Composite"; //@ref.Name = "";
  359. if (@ref.FullName == "IllusionInjector.Logging.UnityLogInterceptor") @ref.Namespace = "IPA.Logging"; //@ref.Name = "";
  360. if (@ref.FullName == "IllusionInjector.Logging.StandardLogger") @ref.Namespace = "IPA.Logging"; //@ref.Name = "";
  361. if (@ref.FullName == "IllusionInjector.Updating.SelfPlugin") @ref.Namespace = "IPA.Updating"; //@ref.Name = "";
  362. if (@ref.FullName == "IllusionInjector.Updating.Backup.BackupUnit") @ref.Namespace = "IPA.Updating.Backup"; //@ref.Name = "";
  363. if (@ref.Namespace == "IllusionInjector.Utilities") @ref.Namespace = "IPA.Utilities"; //@ref.Name = "";
  364. if (@ref.Namespace == "IllusionInjector.Logging.Printers") @ref.Namespace = "IPA.Logging.Printers"; //@ref.Name = "";
  365. }
  366. module.Write(pluginCopy);
  367. #endregion
  368. }
  369. //Load copied plugins
  370. if (exists)
  371. {
  372. string[] copiedPlugins = Directory.GetFiles(cacheDir, "*.dll");
  373. foreach (string s in copiedPlugins)
  374. {
  375. var result = LoadPluginsFromFile(s);
  376. if (result == null) continue;
  377. _ipaPlugins.AddRange(result.NonNull());
  378. }
  379. }
  380. Logger.log.Info(exeName);
  381. Logger.log.Info($"Running on Unity {Application.unityVersion}");
  382. Logger.log.Info($"Game version {UnityGame.GameVersion}");
  383. Logger.log.Info("-----------------------------");
  384. Logger.log.Info($"Loading plugins from {Utils.GetRelativePath(pluginDirectory, Environment.CurrentDirectory)} and found {_bsPlugins.Count + _ipaPlugins.Count}");
  385. Logger.log.Info("-----------------------------");
  386. foreach (var plugin in _bsPlugins)
  387. {
  388. Logger.log.Info($"{plugin.Metadata.Name} ({plugin.Metadata.Id}): {plugin.Metadata.Version}");
  389. }
  390. Logger.log.Info("-----------------------------");
  391. foreach (var plugin in _ipaPlugins)
  392. {
  393. Logger.log.Info($"{plugin.Name}: {plugin.Version}");
  394. }
  395. Logger.log.Info("-----------------------------");
  396. }
  397. private static IEnumerable<Old.IPlugin> LoadPluginsFromFile(string file)
  398. {
  399. var ipaPlugins = new List<Old.IPlugin>();
  400. if (!File.Exists(file) || !file.EndsWith(".dll", true, null))
  401. return ipaPlugins;
  402. T OptionalGetPlugin<T>(Type t) where T : class
  403. {
  404. if (t.FindInterfaces((t, o) => t == (o as Type), typeof(T)).Length > 0)
  405. {
  406. try
  407. {
  408. T pluginInstance = Activator.CreateInstance(t) as T;
  409. return pluginInstance;
  410. }
  411. catch (Exception e)
  412. {
  413. Logger.loader.Error($"Could not load plugin {t.FullName} in {Path.GetFileName(file)}! {e}");
  414. }
  415. }
  416. return null;
  417. }
  418. try
  419. {
  420. Assembly assembly = Assembly.LoadFrom(file);
  421. foreach (Type t in assembly.GetTypes())
  422. {
  423. var ipaPlugin = OptionalGetPlugin<Old.IPlugin>(t);
  424. if (ipaPlugin != null)
  425. {
  426. ipaPlugins.Add(ipaPlugin);
  427. }
  428. }
  429. }
  430. catch (ReflectionTypeLoadException e)
  431. {
  432. Logger.loader.Error($"Could not load the following types from {Path.GetFileName(file)}:");
  433. Logger.loader.Error($" {string.Join("\n ", e.LoaderExceptions?.Select(e1 => e1?.Message).StrJP() ?? Array.Empty<string>())}");
  434. }
  435. catch (Exception e)
  436. {
  437. Logger.loader.Error($"Could not load {Path.GetFileName(file)}!");
  438. Logger.loader.Error(e);
  439. }
  440. return ipaPlugins;
  441. }
  442. internal static class AppInfo
  443. {
  444. [DllImport("kernel32.dll", CharSet = CharSet.Unicode, ExactSpelling = false)]
  445. private static extern int GetModuleFileName(HandleRef hModule, StringBuilder buffer, int length);
  446. private static HandleRef NullHandleRef = new HandleRef(null, IntPtr.Zero);
  447. public static string StartupPath
  448. {
  449. get
  450. {
  451. StringBuilder stringBuilder = new StringBuilder(260);
  452. GetModuleFileName(NullHandleRef, stringBuilder, stringBuilder.Capacity);
  453. return stringBuilder.ToString();
  454. }
  455. }
  456. }
  457. #pragma warning restore CS0618 // Type or member is obsolete (IPlugin)
  458. }
  459. }