BaseUnityPlugin.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using BepInEx.Bootstrap;
  2. using BepInEx.Configuration;
  3. using BepInEx.Logging;
  4. using UnityEngine;
  5. namespace BepInEx
  6. {
  7. /// <summary>
  8. /// The base plugin type that is used by the BepInEx plugin loader.
  9. /// </summary>
  10. public abstract class BaseUnityPlugin : MonoBehaviour
  11. {
  12. /// <summary>
  13. /// Information about this plugin as it was loaded.
  14. /// </summary>
  15. public PluginInfo Info { get; }
  16. /// <summary>
  17. /// Logger instance tied to this plugin.
  18. /// </summary>
  19. protected ManualLogSource Logger { get; }
  20. /// <summary>
  21. /// Default config file tied to this plugin. The config file will not be created until
  22. /// any settings are added and changed, or <see cref="ConfigFile.Save"/> is called.
  23. /// </summary>
  24. protected ConfigFile Config { get; }
  25. /// <summary>
  26. /// Create a new instance of a plugin and all of its tied in objects.
  27. /// </summary>
  28. protected BaseUnityPlugin()
  29. {
  30. var metadata = MetadataHelper.GetMetadata(this);
  31. if (Chainloader.PluginInfos.TryGetValue(metadata.GUID, out var info))
  32. Info = info;
  33. else
  34. {
  35. Info = new PluginInfo
  36. {
  37. Metadata = metadata,
  38. Instance = this,
  39. Dependencies = MetadataHelper.GetDependencies(GetType()),
  40. Processes = MetadataHelper.GetAttributes<BepInProcess>(GetType()),
  41. Location = GetType().Assembly.Location
  42. };
  43. }
  44. Logger = Logging.Logger.CreateLogSource(metadata.Name);
  45. Config = new ConfigFile(Utility.CombinePaths(Paths.ConfigPath, metadata.GUID + ".cfg"), false, metadata);
  46. }
  47. }
  48. }