Ver Fonte

Revert "Rename attributes to a more modern naming scheme, and add shims"

This reverts commit 648d8ed8080229e6535562e38933e9dad2378bac.
Bepis há 5 anos atrás
pai
commit
cce2d32db0

+ 8 - 8
BepInEx/Bootstrap/Chainloader.cs

@@ -124,7 +124,7 @@ namespace BepInEx.Bootstrap
 
 		private static Regex allowedGuidRegex { get; } = new Regex(@"^[a-zA-Z0-9\._\-]+$");
 
-		internal static PluginInfo ToPluginInfo(TypeDefinition type)
+		public static PluginInfo ToPluginInfo(TypeDefinition type)
 		{
 			if (type.IsInterface || type.IsAbstract)
 				return null;
@@ -134,13 +134,13 @@ namespace BepInEx.Bootstrap
 				if (!type.IsSubtypeOf(typeof(BaseUnityPlugin)))
 					return null;
 			}
-			catch (AssemblyResolutionException ex)
+			catch (AssemblyResolutionException)
 			{
 				// Can happen if this type inherits a type from an assembly that can't be found. Safe to assume it's not a plugin.
 				return null;
 			}
 
-			var metadata = PluginMetadata.FromCecilType(type);
+			var metadata = BepInPlugin.FromCecilType(type);
 
 			// Perform checks that will prevent the plugin from being loaded in ALL cases
 			if (metadata == null)
@@ -167,9 +167,9 @@ namespace BepInEx.Bootstrap
 				return null;
 			}
 
-			var filters = ProcessFilter.FromCecilType(type);
-			var dependencies = PluginDependency.FromCecilType(type);
-			var incompatibilities = PluginIncompatibility.FromCecilType(type);
+			var filters = BepInProcess.FromCecilType(type);
+			var dependencies = BepInDependency.FromCecilType(type);
+			var incompatibilities = BepInIncompatibility.FromCecilType(type);
 
 			return new PluginInfo
 			{
@@ -293,7 +293,7 @@ namespace BepInEx.Bootstrap
 						continue;
 
 					var dependsOnInvalidPlugin = false;
-					var missingDependencies = new List<PluginDependency>();
+					var missingDependencies = new List<BepInDependency>();
 					foreach (var dependency in pluginInfo.Dependencies)
 					{
 						// If the depenency wasn't already processed, it's missing altogether
@@ -301,7 +301,7 @@ namespace BepInEx.Bootstrap
 						if (!depenencyExists || pluginVersion < dependency.MinimumVersion)
 						{
 							// If the dependency is hard, collect it into a list to show
-							if ((dependency.Flags & PluginDependency.DependencyFlags.HardDependency) != 0)
+							if ((dependency.Flags & BepInDependency.DependencyFlags.HardDependency) != 0)
 								missingDependencies.Add(dependency);
 							continue;
 						}

+ 3 - 3
BepInEx/Configuration/ConfigFile.cs

@@ -14,7 +14,7 @@ namespace BepInEx.Configuration
 	/// </summary>
 	public class ConfigFile : IDictionary<ConfigDefinition, ConfigEntryBase>
 	{
-		private readonly PluginMetadata _ownerMetadata;
+		private readonly BepInPlugin _ownerMetadata;
 
 		internal static ConfigFile CoreConfig { get; } = new ConfigFile(Paths.BepInExConfigPath, true);
 
@@ -63,7 +63,7 @@ namespace BepInEx.Configuration
 		/// </summary>
 		public bool SaveOnConfigSet { get; set; } = true;
 
-		/// <inheritdoc cref="ConfigFile(string, bool, PluginMetadata)"/>
+		/// <inheritdoc cref="ConfigFile(string, bool, BepInPlugin)"/>
 		public ConfigFile(string configPath, bool saveOnInit) : this(configPath, saveOnInit, null) { }
 
 		/// <summary>
@@ -72,7 +72,7 @@ namespace BepInEx.Configuration
 		/// <param name="configPath">Full path to a file that contains settings. The file will be created as needed.</param>
 		/// <param name="saveOnInit">If the config file/directory doesn't exist, create it immediately.</param>
 		/// <param name="ownerMetadata">Information about the plugin that owns this setting file.</param>
-		public ConfigFile(string configPath, bool saveOnInit, PluginMetadata ownerMetadata)
+		public ConfigFile(string configPath, bool saveOnInit, BepInPlugin ownerMetadata)
 		{
 			_ownerMetadata = ownerMetadata;
 

+ 32 - 77
BepInEx/Contract/Attributes.cs

@@ -13,7 +13,7 @@ namespace BepInEx
 	/// This attribute denotes that a class is a plugin, and specifies the required metadata.
 	/// </summary>
 	[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
-	public class PluginMetadata : Attribute
+	public class BepInPlugin : Attribute
 	{
 		/// <summary>
 		/// The unique identifier of the plugin. Should not change between plugin versions.
@@ -35,7 +35,7 @@ namespace BepInEx
 		/// <param name="GUID">The unique identifier of the plugin. Should not change between plugin versions.</param>
 		/// <param name="Name">The user friendly name of the plugin. Is able to be changed between versions.</param>
 		/// <param name="Version">The specfic version of the plugin.</param>
-		public PluginMetadata(string GUID, string Name, string Version)
+		public BepInPlugin(string GUID, string Name, string Version)
 		{
 			this.GUID = GUID;
 			this.Name = Name;
@@ -50,15 +50,14 @@ namespace BepInEx
 			}
 		}
 
-		internal static PluginMetadata FromCecilType(TypeDefinition td)
+		internal static BepInPlugin FromCecilType(TypeDefinition td)
 		{
-			var attr = MetadataHelper.GetCustomAttributes<PluginMetadata>(td, false).FirstOrDefault()
-				 ?? MetadataHelper.GetCustomAttributes<BepInPlugin>(td, false).FirstOrDefault();
+			var attr = MetadataHelper.GetCustomAttributes<BepInPlugin>(td, false).FirstOrDefault();
 
 			if (attr == null)
 				return null;
 
-			return new PluginMetadata((string)attr.ConstructorArguments[0].Value, (string)attr.ConstructorArguments[1].Value, (string)attr.ConstructorArguments[2].Value);
+			return new BepInPlugin((string)attr.ConstructorArguments[0].Value, (string)attr.ConstructorArguments[1].Value, (string)attr.ConstructorArguments[2].Value);
 		}
 	}
 
@@ -66,7 +65,7 @@ namespace BepInEx
 	/// This attribute specifies any dependencies that this plugin has on other plugins.
 	/// </summary>
 	[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
-	public class PluginDependency : Attribute, ICacheable
+	public class BepInDependency : Attribute, ICacheable
 	{
 		public enum DependencyFlags
 		{
@@ -102,7 +101,7 @@ namespace BepInEx
 		/// </summary>
 		/// <param name="DependencyGUID">The GUID of the referenced plugin.</param>
 		/// <param name="Flags">The flags associated with this dependency definition.</param>
-		public PluginDependency(string DependencyGUID, DependencyFlags Flags = DependencyFlags.HardDependency)
+		public BepInDependency(string DependencyGUID, DependencyFlags Flags = DependencyFlags.HardDependency)
 		{
 			this.DependencyGUID = DependencyGUID;
 			this.Flags = Flags;
@@ -116,20 +115,20 @@ namespace BepInEx
 		/// <param name="DependencyGUID">The GUID of the referenced plugin.</param>
 		/// <param name="MinimumDependencyVersion">The minimum version of the referenced plugin.</param>
 		/// <remarks>When version is supplied the dependency is always treated as HardDependency</remarks>
-		public PluginDependency(string DependencyGUID, string MinimumDependencyVersion) : this(DependencyGUID)
+		public BepInDependency(string DependencyGUID, string MinimumDependencyVersion) : this(DependencyGUID)
 		{
 			MinimumVersion = new Version(MinimumDependencyVersion);
 		}
 
-		internal static IEnumerable<PluginDependency> FromCecilType(TypeDefinition td)
+		internal static IEnumerable<BepInDependency> FromCecilType(TypeDefinition td)
 		{
-			var attrs = MetadataHelper.GetCustomAttributes<PluginDependency>(td, true);
+			var attrs = MetadataHelper.GetCustomAttributes<BepInDependency>(td, true);
 			return attrs.Select(customAttribute =>
 			{
 				var dependencyGuid = (string)customAttribute.ConstructorArguments[0].Value;
 				var secondArg = customAttribute.ConstructorArguments[1].Value;
-				if (secondArg is string minVersion) return new PluginDependency(dependencyGuid, minVersion);
-				return new PluginDependency(dependencyGuid, (DependencyFlags)secondArg);
+				if (secondArg is string minVersion) return new BepInDependency(dependencyGuid, minVersion);
+				return new BepInDependency(dependencyGuid, (DependencyFlags)secondArg);
 			}).ToList();
 		}
 
@@ -152,7 +151,7 @@ namespace BepInEx
 	/// This attribute specifies other plugins that are incompatible with this plugin.
 	/// </summary>
 	[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
-	public class PluginIncompatibility : Attribute, ICacheable
+	public class BepInIncompatibility : Attribute, ICacheable
 	{
 		/// <summary>
 		/// The GUID of the referenced plugin.
@@ -164,18 +163,18 @@ namespace BepInEx
 		/// If the other plugin exists, this plugin will not be loaded and a warning will be shown.
 		/// </summary>
 		/// <param name="IncompatibilityGUID">The GUID of the referenced plugin.</param>
-		public PluginIncompatibility(string IncompatibilityGUID)
+		public BepInIncompatibility(string IncompatibilityGUID)
 		{
 			this.IncompatibilityGUID = IncompatibilityGUID;
 		}
 
-		internal static IEnumerable<PluginIncompatibility> FromCecilType(TypeDefinition td)
+		internal static IEnumerable<BepInIncompatibility> FromCecilType(TypeDefinition td)
 		{
-			var attrs = MetadataHelper.GetCustomAttributes<PluginIncompatibility>(td, true);
+			var attrs = MetadataHelper.GetCustomAttributes<BepInIncompatibility>(td, true);
 			return attrs.Select(customAttribute =>
 			{
 				var dependencyGuid = (string)customAttribute.ConstructorArguments[0].Value;
-				return new PluginIncompatibility(dependencyGuid);
+				return new BepInIncompatibility(dependencyGuid);
 			}).ToList();
 		}
 
@@ -194,7 +193,7 @@ namespace BepInEx
 	/// This attribute specifies which processes this plugin should be run for. Not specifying this attribute will load the plugin under every process.
 	/// </summary>
 	[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
-	public class ProcessFilter : Attribute
+	public class BepInProcess : Attribute
 	{
 		/// <summary>
 		/// The name of the process that this plugin will run under.
@@ -202,62 +201,20 @@ namespace BepInEx
 		public string ProcessName { get; protected set; }
 
 		/// <param name="ProcessName">The name of the process that this plugin will run under.</param>
-		public ProcessFilter(string ProcessName)
+		public BepInProcess(string ProcessName)
 		{
 			this.ProcessName = ProcessName;
 		}
 
-		internal static List<ProcessFilter> FromCecilType(TypeDefinition td)
+		internal static List<BepInProcess> FromCecilType(TypeDefinition td)
 		{
-			var attrs = MetadataHelper.GetCustomAttributes<ProcessFilter>(td, true);
-			return attrs.Select(customAttribute => new ProcessFilter((string)customAttribute.ConstructorArguments[0].Value)).ToList();
+			var attrs = MetadataHelper.GetCustomAttributes<BepInProcess>(td, true);
+			return attrs.Select(customAttribute => new BepInProcess((string)customAttribute.ConstructorArguments[0].Value)).ToList();
 		}
 	}
 
 	#endregion
 
-	#region Shims
-
-	[Obsolete("Use PluginMetadata instead")]
-	public class BepInPlugin : PluginMetadata
-	{
-		public BepInPlugin(string GUID, string Name, string Version) : base(GUID, Name, Version) { }
-	}
-
-	[Obsolete("Use PluginDependency instead")]
-	public class BepInDependency : PluginDependency
-	{
-		public enum DependencyFlags
-		{
-			/// <summary>
-			/// The plugin has a hard dependency on the referenced plugin, and will not run without it.
-			/// </summary>
-			HardDependency = 1,
-
-			/// <summary>
-			/// This plugin has a soft dependency on the referenced plugin, and is able to run without it.
-			/// </summary>
-			SoftDependency = 2,
-		}
-
-		public BepInDependency(string DependencyGUID, DependencyFlags Flags = DependencyFlags.HardDependency) : base(DependencyGUID, (PluginDependency.DependencyFlags)(int)Flags) { }
-		public BepInDependency(string DependencyGUID, string MinimumDependencyVersion) : base(DependencyGUID, MinimumDependencyVersion) { }
-	}
-
-	[Obsolete("Use PluginIncompatibility instead")]
-	public class BepInIncompatibility : PluginIncompatibility
-	{
-		public BepInIncompatibility(string IncompatibilityGUID) : base(IncompatibilityGUID) { }
-	}
-
-	[Obsolete("Use ProcessFilter instead")]
-	public class BepInProcess : ProcessFilter
-	{
-		public BepInProcess(string ProcessName) : base(ProcessName) { }
-	}
-
-	#endregion
-
 	#region MetadataHelper
 
 	/// <summary>
@@ -282,28 +239,26 @@ namespace BepInEx
 		}
 
 		/// <summary>
-		/// Retrieves the PluginMetadata metadata from a plugin type.
+		/// Retrieves the BepInPlugin metadata from a plugin type.
 		/// </summary>
 		/// <param name="pluginType">The plugin type.</param>
-		/// <returns>The PluginMetadata metadata of the plugin type.</returns>
-		public static PluginMetadata GetMetadata(Type pluginType)
+		/// <returns>The BepInPlugin metadata of the plugin type.</returns>
+		public static BepInPlugin GetMetadata(Type pluginType)
 		{
-			object[] attributes = pluginType.GetCustomAttributes(typeof(PluginMetadata), false)
-											.Concat(pluginType.GetCustomAttributes(typeof(BepInPlugin), false))
-											.ToArray();
+			object[] attributes = pluginType.GetCustomAttributes(typeof(BepInPlugin), false);
 
 			if (attributes.Length == 0)
 				return null;
 
-			return (PluginMetadata)attributes[0];
+			return (BepInPlugin)attributes[0];
 		}
 
 		/// <summary>
-		/// Retrieves the PluginMetadata metadata from a plugin instance.
+		/// Retrieves the BepInPlugin metadata from a plugin instance.
 		/// </summary>
 		/// <param name="plugin">The plugin instance.</param>
-		/// <returns>The PluginMetadata metadata of the plugin instance.</returns>
-		public static PluginMetadata GetMetadata(object plugin)
+		/// <returns>The BepInPlugin metadata of the plugin instance.</returns>
+		public static BepInPlugin GetMetadata(object plugin)
 			=> GetMetadata(plugin.GetType());
 
 		/// <summary>
@@ -331,9 +286,9 @@ namespace BepInEx
 		/// </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<PluginDependency> GetDependencies(Type plugin)
+		public static IEnumerable<BepInDependency> GetDependencies(Type plugin)
 		{
-			return plugin.GetCustomAttributes(typeof(PluginDependency), true).Cast<PluginDependency>();
+			return plugin.GetCustomAttributes(typeof(BepInDependency), true).Cast<BepInDependency>();
 		}
 	}
 

+ 3 - 3
BepInEx/Contract/BaseUnityPlugin.cs

@@ -29,12 +29,12 @@ namespace BepInEx
         /// <summary>
         /// Create a new instance of a plugin and all of its tied in objects.
         /// </summary>
-        /// <exception cref="InvalidOperationException">PluginMetadata attribute is missing.</exception>
+        /// <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 PluginMetadata attribute is missing.");
+				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;
@@ -45,7 +45,7 @@ namespace BepInEx
 					Metadata = metadata,
 					Instance = this,
 					Dependencies = MetadataHelper.GetDependencies(GetType()),
-					Processes = MetadataHelper.GetAttributes<ProcessFilter>(GetType()),
+					Processes = MetadataHelper.GetAttributes<BepInProcess>(GetType()),
 					Location = GetType().Assembly.Location
 				};
 			}

+ 11 - 11
BepInEx/Contract/PluginInfo.cs

@@ -7,13 +7,13 @@ namespace BepInEx
 {
 	public class PluginInfo : ICacheable
 	{
-		public PluginMetadata Metadata { get; internal set; }
+		public BepInPlugin Metadata { get; internal set; }
 
-		public IEnumerable<ProcessFilter> Processes { get; internal set; }
+		public IEnumerable<BepInProcess> Processes { get; internal set; }
 
-		public IEnumerable<PluginDependency> Dependencies { get; internal set; }
+		public IEnumerable<BepInDependency> Dependencies { get; internal set; }
 
-		public IEnumerable<PluginIncompatibility> Incompatibilities { get; internal set; }
+		public IEnumerable<BepInIncompatibility> Incompatibilities { get; internal set; }
 
 		public string Location { get; internal set; }
 
@@ -49,19 +49,19 @@ namespace BepInEx
 		{
 			TypeName = br.ReadString();
 
-			Metadata = new PluginMetadata(br.ReadString(), br.ReadString(), br.ReadString());
+			Metadata = new BepInPlugin(br.ReadString(), br.ReadString(), br.ReadString());
 
 			var processListCount = br.ReadInt32();
-			var processList = new List<ProcessFilter>(processListCount);
+			var processList = new List<BepInProcess>(processListCount);
 			for (int i = 0; i < processListCount; i++)
-				processList.Add(new ProcessFilter(br.ReadString()));
+				processList.Add(new BepInProcess(br.ReadString()));
 			Processes = processList;
 
 			var depCount = br.ReadInt32();
-			var depList = new List<PluginDependency>(depCount);
+			var depList = new List<BepInDependency>(depCount);
 			for (int i = 0; i < depCount; i++)
 			{
-				var dep = new PluginDependency("");
+				var dep = new BepInDependency("");
 				((ICacheable)dep).Load(br);
 				depList.Add(dep);
 			}
@@ -69,10 +69,10 @@ namespace BepInEx
 			Dependencies = depList;
 
 			var incCount = br.ReadInt32();
-			var incList = new List<PluginIncompatibility>(incCount);
+			var incList = new List<BepInIncompatibility>(incCount);
 			for (int i = 0; i < incCount; i++)
 			{
-				var inc = new PluginIncompatibility("");
+				var inc = new BepInIncompatibility("");
 				((ICacheable)inc).Load(br);
 				incList.Add(inc);
 			}