using System;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using UnityEngine;
namespace BepInEx
{
///
/// The base plugin type that is used by the BepInEx plugin loader.
///
public abstract class BaseUnityPlugin : MonoBehaviour
{
///
/// Information about this plugin as it was loaded.
///
public PluginInfo Info { get; }
///
/// Logger instance tied to this plugin.
///
protected ManualLogSource Logger { get; }
///
/// Default config file tied to this plugin. The config file will not be created until
/// any settings are added and changed, or is called.
///
public ConfigFile Config { get; }
///
/// Create a new instance of a plugin and all of its tied in objects.
///
/// BepInPlugin attribute is missing.
protected BaseUnityPlugin()
{
var metadata = MetadataHelper.GetMetadata(this);
if(metadata == null)
throw new InvalidOperationException("Can't create an instance of " + GetType().FullName + " because it inherits from BaseUnityPlugin and the BepInPlugin attribute is missing.");
if (Chainloader.PluginInfos.TryGetValue(metadata.GUID, out var info))
Info = info;
else
{
Info = new PluginInfo
{
Metadata = metadata,
Instance = this,
Dependencies = MetadataHelper.GetDependencies(GetType()),
Processes = MetadataHelper.GetAttributes(GetType()),
Location = GetType().Assembly.Location
};
}
Logger = Logging.Logger.CreateLogSource(metadata.Name);
Config = new ConfigFile(Utility.CombinePaths(Paths.ConfigPath, metadata.GUID + ".cfg"), false, metadata);
}
}
}