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.
|
- using System;
- using BepInEx.Bootstrap;
-
- namespace TechbloxModdingAPI.Utility
- {
- /// <summary>
- /// Simple plugin interaction operations
- /// </summary>
- public static class Dependency
- {
- /// <summary>
- /// Find a plugin by name
- /// </summary>
- /// <returns>The plugin.</returns>
- /// <param name="name">The plugin's name.</param>
- public static BepInEx.PluginInfo GetPlugin(string name)
- {
- foreach(var plugin in Chainloader.PluginInfos.Values)
- {
- if (plugin.Metadata.Name == name)
- {
- return plugin;
- }
- }
- return null;
- }
-
- /// <summary>
- /// Gets the plugin version.
- /// This gives priority to the plugin's Version string but falls back to the Assembly's version
- /// </summary>
- /// <returns>The plugin's version.</returns>
- /// <param name="name">The plugin's name.</param>
- public static Version GetPluginVersion(string name)
- {
- var plugin = GetPlugin(name);
- if (plugin != null) {
- try
- {
- return plugin.Metadata.Version;
- } catch (Exception e) when (e is ArgumentException or FormatException or OverflowException) {}
- return plugin.GetType().Assembly.GetName().Version;
- }
- return null;
- }
- }
- }
|