A stable modding interface between Techblox and mods https://mod.exmods.org/
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.

48 lines
1.2KB

  1. using System;
  2. using BepInEx.Bootstrap;
  3. namespace TechbloxModdingAPI.Utility
  4. {
  5. /// <summary>
  6. /// Simple plugin interaction operations
  7. /// </summary>
  8. public static class Dependency
  9. {
  10. /// <summary>
  11. /// Find a plugin by name
  12. /// </summary>
  13. /// <returns>The plugin.</returns>
  14. /// <param name="name">The plugin's name.</param>
  15. public static BepInEx.PluginInfo GetPlugin(string name)
  16. {
  17. foreach(var plugin in Chainloader.PluginInfos.Values)
  18. {
  19. if (plugin.Metadata.Name == name)
  20. {
  21. return plugin;
  22. }
  23. }
  24. return null;
  25. }
  26. /// <summary>
  27. /// Gets the plugin version.
  28. /// This gives priority to the plugin's Version string but falls back to the Assembly's version
  29. /// </summary>
  30. /// <returns>The plugin's version.</returns>
  31. /// <param name="name">The plugin's name.</param>
  32. public static Version GetPluginVersion(string name)
  33. {
  34. var plugin = GetPlugin(name);
  35. if (plugin != null) {
  36. try
  37. {
  38. return plugin.Metadata.Version;
  39. } catch (Exception e) when (e is ArgumentException or FormatException or OverflowException) {}
  40. return plugin.GetType().Assembly.GetName().Version;
  41. }
  42. return null;
  43. }
  44. }
  45. }