Browse Source

Generate basic plugin info on plugins initialized outside chainloader

ghorsington 5 years ago
parent
commit
2bed848f1d
2 changed files with 18 additions and 9 deletions
  1. 8 8
      BepInEx/Contract/Attributes.cs
  2. 10 1
      BepInEx/Contract/BaseUnityPlugin.cs

+ 8 - 8
BepInEx/Contract/Attributes.cs

@@ -198,15 +198,15 @@ namespace BepInEx
 		public static IEnumerable<T> GetAttributes<T>(object plugin) where T : Attribute
 			=> GetAttributes<T>(plugin.GetType());
 
-		/// <summary>
-		/// Retrieves the dependencies of the specified plugin type.
-		/// </summary>
-		/// <param name="Plugin">The plugin type.</param>
-		/// <param name="AllPlugins">All currently loaded plugin types.</param>
-		/// <returns>A list of all plugin types that the specified plugin type depends upon.</returns>
-		public static IEnumerable<BepInDependency> GetDependencies(Type Plugin, IEnumerable<Type> AllPlugins)
+
+        /// <summary>
+        /// Retrieves the dependencies of the specified plugin type.
+        /// </summary>
+        /// <param name="Plugin">The plugin type.</param>
+        /// <returns>A list of all plugin types that the specified plugin type depends upon.</returns>
+        public static IEnumerable<BepInDependency> GetDependencies(Type plugin)
 		{
-			return Plugin.GetCustomAttributes(typeof(BepInDependency), true).Cast<BepInDependency>();
+			return plugin.GetCustomAttributes(typeof(BepInDependency), true).Cast<BepInDependency>();
 		}
 	}
 

+ 10 - 1
BepInEx/Contract/BaseUnityPlugin.cs

@@ -24,7 +24,16 @@ namespace BepInEx
 			if (Chainloader.PluginInfos.TryGetValue(metadata.GUID, out var info))
 				Info = info;
 			else
-				Logging.Logger.LogDebug($"Plugin [{metadata.GUID}] wasn't registered through chainloader! PluginInfo property will not be initialized.");
+			{
+				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);