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.

533 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. DisabledConfig.Instance.DisabledModIds.Remove(meta.Id ?? meta.Name);
  123. PluginEnabled?.Invoke(meta, meta.RuntimeOptions != RuntimeOptions.DynamicInit);
  124. if (meta.RuntimeOptions == RuntimeOptions.DynamicInit)
  125. {
  126. // it should only be marked as not disabled if it actually was
  127. PluginLoader.DisabledPlugins.Remove(meta);
  128. _bsPlugins.Add(executor);
  129. try
  130. {
  131. executor.Enable();
  132. }
  133. catch (Exception e)
  134. {
  135. Logger.loader.Error($"Error while enabling {meta.Id}:");
  136. Logger.loader.Error(e);
  137. // this should still be considered enabled, hence its position
  138. }
  139. }
  140. }
  141. }
  142. var result = TaskEx.WhenAll();
  143. {
  144. // then disable the mods that need to be
  145. static DisableExecutor MakeDisableExec(PluginExecutor e)
  146. => new DisableExecutor
  147. {
  148. Executor = e,
  149. Dependents = BSMetas.Where(f => f.Metadata.Dependencies.Contains(e.Metadata)).Select(MakeDisableExec)
  150. };
  151. var disableExecs = toDisable.Select(m => BSMetas.FirstOrDefault(e => e.Metadata == m)).NonNull().ToArray(); // eagerly evaluate once
  152. foreach (var exec in disableExecs)
  153. {
  154. DisabledConfig.Instance.DisabledModIds.Add(exec.Metadata.Id ?? exec.Metadata.Name);
  155. if (exec.Metadata.RuntimeOptions == RuntimeOptions.DynamicInit)
  156. {
  157. // it should only be marked as disabled if it was actually fully disabled
  158. PluginLoader.DisabledPlugins.Add(exec.Metadata);
  159. runtimeDisabledPlugins.Add(exec);
  160. _bsPlugins.Remove(exec);
  161. }
  162. PluginDisabled?.Invoke(exec.Metadata, exec.Metadata.RuntimeOptions != RuntimeOptions.DynamicInit);
  163. }
  164. var disableStructure = disableExecs.Select(MakeDisableExec);
  165. static Task Disable(DisableExecutor exec, Dictionary<PluginExecutor, Task> alreadyDisabled)
  166. {
  167. if (alreadyDisabled.TryGetValue(exec.Executor, out var task))
  168. return task;
  169. else
  170. {
  171. if (exec.Executor.Metadata.RuntimeOptions != RuntimeOptions.DynamicInit)
  172. return TaskEx6.FromException(new CannotRuntimeDisableException(exec.Executor.Metadata));
  173. var res = TaskEx.WhenAll(exec.Dependents.Select(d => Disable(d, alreadyDisabled)))
  174. .ContinueWith(t =>
  175. {
  176. if (t.IsFaulted) {
  177. return TaskEx.WhenAll(t, TaskEx6.FromException(
  178. new CannotRuntimeDisableException(exec.Executor.Metadata, "Dependents cannot be disabled for plugin")));
  179. }
  180. return exec.Executor.Disable()
  181. .ContinueWith(t =>
  182. {
  183. foreach (var feature in exec.Executor.Metadata.Features)
  184. {
  185. try {
  186. feature.AfterDisable(exec.Executor.Metadata);
  187. }
  188. catch (Exception e)
  189. {
  190. Logger.loader.Critical($"Feature errored in {nameof(Feature.AfterDisable)}: {e}");
  191. }
  192. }
  193. }, UnityMainThreadTaskScheduler.Default);
  194. }, UnityMainThreadTaskScheduler.Default).Unwrap();
  195. // We do not want to call the disable method if a dependent couldn't be disabled
  196. // By scheduling on a UnityMainThreadScheduler, we ensure that Disable() is always called on the Unity main thread
  197. alreadyDisabled.Add(exec.Executor, res);
  198. return res;
  199. }
  200. }
  201. var disabled = new Dictionary<PluginExecutor, Task>();
  202. result = TaskEx.WhenAll(disableStructure.Select(d => Disable(d, disabled)));
  203. }
  204. OnAnyPluginsStateChanged?.Invoke(result, toEnable, toDisable);
  205. // if there are any that are capable of enabling/disabling at runtime, run event handler
  206. if (toEnable.Concat(toDisable).Any(m => m.RuntimeOptions == RuntimeOptions.DynamicInit))
  207. OnPluginsStateChanged?.Invoke(result);
  208. //DisabledConfig.Instance.Changed();
  209. // changed is handled by transaction
  210. return result;
  211. }
  212. }
  213. private struct DisableExecutor
  214. {
  215. public PluginExecutor Executor;
  216. public IEnumerable<DisableExecutor> Dependents;
  217. }
  218. /// <summary>
  219. /// Checks if a given plugin is disabled.
  220. /// </summary>
  221. /// <param name="meta">the plugin to check</param>
  222. /// <returns><see langword="true"/> if the plugin is disabled, <see langword="false"/> otherwise.</returns>
  223. public static bool IsDisabled(PluginMetadata meta) => DisabledPlugins.Contains(meta);
  224. /// <summary>
  225. /// Checks if a given plugin is enabled.
  226. /// </summary>
  227. /// <param name="meta">the plugin to check</param>
  228. /// <returns><see langword="true"/> if the plugin is enabled, <see langword="false"/> otherwise.</returns>
  229. public static bool IsEnabled(PluginMetadata meta) => BSMetas.Any(p => p.Metadata == meta);
  230. /// <summary>
  231. /// An invoker for the <see cref="PluginEnabled"/> event.
  232. /// </summary>
  233. /// <param name="plugin">the plugin that was enabled</param>
  234. /// <param name="needsRestart">whether it needs a restart to take effect</param>
  235. public delegate void PluginEnableDelegate(PluginMetadata plugin, bool needsRestart);
  236. /// <summary>
  237. /// An invoker for the <see cref="PluginDisabled"/> event.
  238. /// </summary>
  239. /// <param name="plugin">the plugin that was disabled</param>
  240. /// <param name="needsRestart">whether it needs a restart to take effect</param>
  241. public delegate void PluginDisableDelegate(PluginMetadata plugin, bool needsRestart);
  242. /// <summary>
  243. /// A delegate representing a state change event for any plugin.
  244. /// </summary>
  245. /// <param name="changeTask">the <see cref="Task"/> representing the change</param>
  246. /// <param name="enabled">the plugins that were enabled in the change</param>
  247. /// <param name="disabled">the plugins that were disabled in the change</param>
  248. public delegate void OnAnyPluginsStateChangedDelegate(Task changeTask, IEnumerable<PluginMetadata> enabled, IEnumerable<PluginMetadata> disabled);
  249. /// <summary>
  250. /// Called whenever a plugin is enabled, before the plugin in question is enabled.
  251. /// </summary>
  252. public static event PluginEnableDelegate PluginEnabled;
  253. /// <summary>
  254. /// Called whenever a plugin is disabled, before the plugin in question is enabled.
  255. /// </summary>
  256. public static event PluginDisableDelegate PluginDisabled;
  257. /// <summary>
  258. /// Called whenever any plugins have their state changed at runtime with the <see cref="Task"/> representing that state change.
  259. /// </summary>
  260. /// <remarks>
  261. /// Note that this is called on the Unity main thread, and cannot therefore block, as the <see cref="Task"/>
  262. /// provided represents operations that also run on the Unity main thread.
  263. /// </remarks>
  264. public static event Action<Task> OnPluginsStateChanged;
  265. /// <summary>
  266. /// Called whenever any plugins, regardless of whether or not their change occurs during runtime, have their state changed.
  267. /// </summary>
  268. /// <remarks>
  269. /// Note that this is called on the Unity main thread, and cannot therefore block, as the <see cref="Task"/>
  270. /// provided represents operations that also run on the Unity main thread.
  271. /// </remarks>
  272. public static event OnAnyPluginsStateChangedDelegate OnAnyPluginsStateChanged;
  273. /// <summary>
  274. /// Gets a list of all enabled BSIPA plugins. Use <see cref="EnabledPlugins"/> instead of this.
  275. /// </summary>
  276. /// <value>a collection of all enabled plugins as <see cref="PluginMetadata"/>s</value>
  277. [Obsolete("This is an old name that no longer accurately represents its value. Use EnabledPlugins instead.")]
  278. public static IEnumerable<PluginMetadata> AllPlugins => EnabledPlugins;
  279. /// <summary>
  280. /// Gets a collection of all enabled plugins, as represented by <see cref="PluginMetadata"/>.
  281. /// </summary>
  282. /// <value>a collection of all enabled plugins</value>
  283. public static IEnumerable<PluginMetadata> EnabledPlugins => BSMetas.Select(p => p.Metadata);
  284. /// <summary>
  285. /// Gets a list of disabled BSIPA plugins.
  286. /// </summary>
  287. /// <value>a collection of all disabled plugins as <see cref="PluginMetadata"/></value>
  288. public static IEnumerable<PluginMetadata> DisabledPlugins => PluginLoader.DisabledPlugins;
  289. private static readonly HashSet<PluginExecutor> runtimeDisabledPlugins = new HashSet<PluginExecutor>();
  290. /// <summary>
  291. /// Gets a read-only dictionary of an ignored plugin to the reason it was ignored, as an <see cref="IgnoreReason"/>.
  292. /// </summary>
  293. /// <value>a dictionary of <see cref="PluginMetadata"/> to <see cref="IgnoreReason"/> of ignored plugins</value>
  294. public static IReadOnlyDictionary<PluginMetadata, IgnoreReason> IgnoredPlugins => PluginLoader.ignoredPlugins;
  295. /// <summary>
  296. /// An <see cref="IEnumerable{T}"/> of old IPA plugins.
  297. /// </summary>
  298. /// <value>all legacy plugin instances</value>
  299. [Obsolete("This exists only to provide support for legacy IPA plugins based on the IPlugin interface.")]
  300. public static IEnumerable<Old.IPlugin> Plugins => _ipaPlugins;
  301. private static List<Old.IPlugin> _ipaPlugins;
  302. internal static IConfigProvider SelfConfigProvider { get; set; }
  303. internal static void Load()
  304. {
  305. string pluginDirectory = UnityGame.PluginsPath;
  306. // Process.GetCurrentProcess().MainModule crashes the game and Assembly.GetEntryAssembly() is NULL,
  307. // so we need to resort to P/Invoke
  308. string exeName = Path.GetFileNameWithoutExtension(AppInfo.StartupPath);
  309. _bsPlugins = new List<PluginExecutor>();
  310. _ipaPlugins = new List<Old.IPlugin>();
  311. if (!Directory.Exists(pluginDirectory)) return;
  312. // initialize BSIPA plugins first
  313. _bsPlugins.AddRange(PluginLoader.LoadPlugins());
  314. var metadataPaths = PluginLoader.PluginsMetadata.Select(m => m.File.FullName).ToList();
  315. var ignoredPaths = PluginLoader.ignoredPlugins.Select(m => m.Key.File.FullName)
  316. .Concat(PluginLoader.ignoredPlugins.SelectMany(m => m.Key.AssociatedFiles.Select(f => f.FullName))).ToList();
  317. var disabledPaths = DisabledPlugins.Select(m => m.File.FullName).ToList();
  318. //Copy plugins to .cache
  319. string[] originalPlugins = Directory.GetFiles(pluginDirectory, "*.dll");
  320. string cacheDir = Path.Combine(pluginDirectory, ".cache");
  321. bool exists = Directory.Exists(cacheDir);
  322. if (exists)
  323. {
  324. foreach (string plugin in Directory.GetFiles(cacheDir, "*"))
  325. File.Delete(plugin);
  326. }
  327. foreach (string s in originalPlugins)
  328. {
  329. if (metadataPaths.Contains(s)) continue;
  330. if (ignoredPaths.Contains(s)) continue;
  331. if (disabledPaths.Contains(s)) continue;
  332. if (!exists)
  333. {
  334. Directory.CreateDirectory(cacheDir);
  335. exists = true;
  336. }
  337. string pluginCopy = Path.Combine(cacheDir, Path.GetFileName(s));
  338. #region Fix assemblies for refactor
  339. var module = ModuleDefinition.ReadModule(Path.Combine(pluginDirectory, s));
  340. foreach (var @ref in module.AssemblyReferences)
  341. { // fix assembly references
  342. if (@ref.Name == "IllusionPlugin" || @ref.Name == "IllusionInjector")
  343. {
  344. @ref.Name = "IPA.Loader";
  345. }
  346. }
  347. foreach (var @ref in module.GetTypeReferences())
  348. { // fix type references
  349. if (@ref.FullName == "IllusionPlugin.IPlugin") @ref.Namespace = "IPA.Old"; //@ref.Name = "";
  350. if (@ref.FullName == "IllusionPlugin.IEnhancedPlugin") @ref.Namespace = "IPA.Old"; //@ref.Name = "";
  351. if (@ref.FullName == "IllusionPlugin.IniFile") @ref.Namespace = "IPA.Config"; //@ref.Name = "";
  352. if (@ref.FullName == "IllusionPlugin.IModPrefs") @ref.Namespace = "IPA.Config"; //@ref.Name = "";
  353. if (@ref.FullName == "IllusionPlugin.ModPrefs") @ref.Namespace = "IPA.Config"; //@ref.Name = "";
  354. if (@ref.FullName == "IllusionPlugin.Utils.ReflectionUtil") @ref.Namespace = "IPA.Utilities"; //@ref.Name = "";
  355. if (@ref.FullName == "IllusionPlugin.Logging.Logger") @ref.Namespace = "IPA.Logging"; //@ref.Name = "";
  356. if (@ref.FullName == "IllusionPlugin.Logging.LogPrinter") @ref.Namespace = "IPA.Logging"; //@ref.Name = "";
  357. if (@ref.FullName == "IllusionInjector.PluginManager") @ref.Namespace = "IPA.Loader"; //@ref.Name = "";
  358. if (@ref.FullName == "IllusionInjector.PluginComponent") @ref.Namespace = "IPA.Loader"; //@ref.Name = "";
  359. if (@ref.FullName == "IllusionInjector.CompositeBSPlugin") @ref.Namespace = "IPA.Loader.Composite"; //@ref.Name = "";
  360. if (@ref.FullName == "IllusionInjector.CompositeIPAPlugin") @ref.Namespace = "IPA.Loader.Composite"; //@ref.Name = "";
  361. if (@ref.FullName == "IllusionInjector.Logging.UnityLogInterceptor") @ref.Namespace = "IPA.Logging"; //@ref.Name = "";
  362. if (@ref.FullName == "IllusionInjector.Logging.StandardLogger") @ref.Namespace = "IPA.Logging"; //@ref.Name = "";
  363. if (@ref.FullName == "IllusionInjector.Updating.SelfPlugin") @ref.Namespace = "IPA.Updating"; //@ref.Name = "";
  364. if (@ref.FullName == "IllusionInjector.Updating.Backup.BackupUnit") @ref.Namespace = "IPA.Updating.Backup"; //@ref.Name = "";
  365. if (@ref.Namespace == "IllusionInjector.Utilities") @ref.Namespace = "IPA.Utilities"; //@ref.Name = "";
  366. if (@ref.Namespace == "IllusionInjector.Logging.Printers") @ref.Namespace = "IPA.Logging.Printers"; //@ref.Name = "";
  367. }
  368. module.Write(pluginCopy);
  369. #endregion
  370. }
  371. //Load copied plugins
  372. if (exists)
  373. {
  374. string[] copiedPlugins = Directory.GetFiles(cacheDir, "*.dll");
  375. foreach (string s in copiedPlugins)
  376. {
  377. var result = LoadPluginsFromFile(s);
  378. if (result == null) continue;
  379. _ipaPlugins.AddRange(result.NonNull());
  380. }
  381. }
  382. Logger.log.Info(exeName);
  383. Logger.log.Info($"Running on Unity {Application.unityVersion}");
  384. Logger.log.Info($"Game version {UnityGame.GameVersion}");
  385. Logger.log.Info("-----------------------------");
  386. Logger.log.Info($"Loading plugins from {Utils.GetRelativePath(pluginDirectory, Environment.CurrentDirectory)} and found {_bsPlugins.Count + _ipaPlugins.Count}");
  387. Logger.log.Info("-----------------------------");
  388. foreach (var plugin in _bsPlugins)
  389. {
  390. Logger.log.Info($"{plugin.Metadata.Name} ({plugin.Metadata.Id}): {plugin.Metadata.Version}");
  391. }
  392. Logger.log.Info("-----------------------------");
  393. if (_ipaPlugins.Count > 0)
  394. {
  395. foreach (var plugin in _ipaPlugins)
  396. {
  397. Logger.log.Info($"{plugin.Name}: {plugin.Version}");
  398. }
  399. Logger.log.Info("-----------------------------");
  400. }
  401. }
  402. private static IEnumerable<Old.IPlugin> LoadPluginsFromFile(string file)
  403. {
  404. var ipaPlugins = new List<Old.IPlugin>();
  405. if (!File.Exists(file) || !file.EndsWith(".dll", true, null))
  406. return ipaPlugins;
  407. T OptionalGetPlugin<T>(Type t) where T : class
  408. {
  409. if (t.FindInterfaces((t, o) => t == (o as Type), typeof(T)).Length > 0)
  410. {
  411. try
  412. {
  413. T pluginInstance = Activator.CreateInstance(t) as T;
  414. return pluginInstance;
  415. }
  416. catch (Exception e)
  417. {
  418. Logger.loader.Error($"Could not load plugin {t.FullName} in {Path.GetFileName(file)}! {e}");
  419. }
  420. }
  421. return null;
  422. }
  423. try
  424. {
  425. Assembly assembly = Assembly.LoadFrom(file);
  426. foreach (Type t in assembly.GetTypes())
  427. {
  428. var ipaPlugin = OptionalGetPlugin<Old.IPlugin>(t);
  429. if (ipaPlugin != null)
  430. {
  431. ipaPlugins.Add(ipaPlugin);
  432. }
  433. }
  434. }
  435. catch (ReflectionTypeLoadException e)
  436. {
  437. Logger.loader.Error($"Could not load the following types from {Path.GetFileName(file)}:");
  438. Logger.loader.Error($" {string.Join("\n ", e.LoaderExceptions?.Select(e1 => e1?.Message).StrJP() ?? Array.Empty<string>())}");
  439. }
  440. catch (Exception e)
  441. {
  442. Logger.loader.Error($"Could not load {Path.GetFileName(file)}!");
  443. Logger.loader.Error(e);
  444. }
  445. return ipaPlugins;
  446. }
  447. internal static class AppInfo
  448. {
  449. [DllImport("kernel32.dll", CharSet = CharSet.Unicode, ExactSpelling = false)]
  450. private static extern int GetModuleFileName(HandleRef hModule, StringBuilder buffer, int length);
  451. private static HandleRef NullHandleRef = new HandleRef(null, IntPtr.Zero);
  452. public static string StartupPath
  453. {
  454. get
  455. {
  456. StringBuilder stringBuilder = new StringBuilder(260);
  457. GetModuleFileName(NullHandleRef, stringBuilder, stringBuilder.Capacity);
  458. return stringBuilder.ToString();
  459. }
  460. }
  461. }
  462. #pragma warning restore CS0618 // Type or member is obsolete (IPlugin)
  463. }
  464. }