예제 #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);
        }
예제 #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);
            }
        }
예제 #3
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);
        }