Example #1
0
        /// <summary>
        /// Create a new instance of a plugin and all of its tied in objects.
        /// </summary>
        /// <exception cref="InvalidOperationException">BepInPlugin attribute is missing.</exception>
        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 <BepInProcess>(GetType()),
                    Location     = GetType().Assembly.Location
                };
            }

            Logger = Logging.Logger.CreateLogSource(metadata.Name);

            Config = new ConfigFile(Utility.CombinePaths(Paths.ConfigPath, metadata.GUID + ".cfg"), false, metadata);
        }
Example #2
0
        /// <summary>
        ///     Create a new instance of a plugin and all of its tied in objects.
        /// </summary>
        /// <exception cref="InvalidOperationException">BepInPlugin attribute is missing.</exception>
        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.");
            }

            Info = new PluginInfo
            {
                Metadata     = metadata,
                Instance     = this,
                Dependencies = MetadataHelper.GetDependencies(GetType()),
                Processes    = MetadataHelper.GetAttributes <BepInProcess>(GetType()),
                Location     = GetType().Assembly.Location
            };

            Logger = Logging.Logger.CreateLogSource(metadata.Name);

            if (this.GetType().GetCustomAttributes(typeof(BepInConfigType), true).FirstOrDefault() is BepInConfigType configTypeAttribute)
            {
                Config = (ConfigFile)Activator.CreateInstance(configTypeAttribute.ConfigFileType, new object[] { Utility.CombinePaths(Paths.ConfigPath, metadata.GUID + ".cfg"), false, metadata });
            }
            else
            {
                Config = new ConfigFile(Utility.CombinePaths(Paths.ConfigPath, metadata.GUID + ".cfg"), false, metadata);
            }
        }
Example #3
0
        protected BaseUnityPlugin()
        {
            var metadata = MetadataHelper.GetMetadata(this);

            Logger = Logging.Logger.CreateLogSource(metadata.Name);

            Config = new ConfigFile(Utility.CombinePaths(Paths.ConfigPath, metadata.GUID + ".cfg"), false);
        }
Example #4
0
        protected BaseUnityPlugin()
        {
            var metadata = MetadataHelper.GetMetadata(this);

            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 <BepInProcess>(GetType()),
                    Location     = GetType().Assembly.Location
                };
            }

            Logger = Logging.Logger.CreateLogSource(metadata.Name);

            Config = new ConfigFile(Utility.CombinePaths(Paths.ConfigPath, metadata.GUID + ".cfg"), false);
        }
Example #5
0
 public ConfigWrapper(string key, BaseUnityPlugin plugin, IConfigConverter <T> converter, T @default = default(T))
     : this(key, converter.ConvertFromString, converter.ConvertToString, @default)
 {
     Section = MetadataHelper.GetMetadata(plugin).GUID;
 }
Example #6
0
 public ConfigWrapper(string key, BaseUnityPlugin plugin, Func <string, T> strToObj, Func <T, string> objToStr, T @default = default(T))
     : this(key, strToObj, objToStr, @default)
 {
     Section = MetadataHelper.GetMetadata(plugin).GUID;
 }
Example #7
0
 public ConfigWrapper(string key, BaseUnityPlugin plugin, T @default = default(T))
     : this(key, @default)
 {
     Section = MetadataHelper.GetMetadata(plugin).GUID;
 }
Example #8
0
        protected BaseUnityPlugin()
        {
            var metadata = MetadataHelper.GetMetadata(this);

            Logger = Logging.Logger.CreateLogSource(metadata.Name);
        }
Example #9
0
 public static bool HasEntry(this BaseUnityPlugin plugin, string key)
 {
     return(HasEntry(key, MetadataHelper.GetMetadata(plugin).GUID));
 }
Example #10
0
 public static void SetEntry(this BaseUnityPlugin plugin, string key, string value)
 {
     SetEntry(key, value, MetadataHelper.GetMetadata(plugin).GUID);
 }
Example #11
0
 public static string GetEntry(this BaseUnityPlugin plugin, string key, string defaultValue = "")
 {
     return(GetEntry(key, defaultValue, MetadataHelper.GetMetadata(plugin).GUID));
 }