using System;
using BepInEx.Bootstrap;
namespace TechbloxModdingAPI.Utility
{
///
/// Simple plugin interaction operations
///
public static class Dependency
{
///
/// Find a plugin by name
///
/// The plugin.
/// The plugin's name.
public static BepInEx.PluginInfo GetPlugin(string name)
{
foreach(var plugin in Chainloader.PluginInfos.Values)
{
if (plugin.Metadata.Name == name)
{
return plugin;
}
}
return null;
}
///
/// Gets the plugin version.
/// This gives priority to the plugin's Version string but falls back to the Assembly's version
///
/// The plugin's version.
/// The plugin's name.
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;
}
}
}