public static PluginInfo ToPluginInfo(TypeDefinition type) { if (type.IsInterface || type.IsAbstract) { return(null); } try { if (!type.IsSubtypeOf(typeof(BaseUnityPlugin))) { return(null); } } 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 = BepInPlugin.FromCecilType(type); // Perform checks that will prevent the plugin from being loaded in ALL cases if (metadata == null) { Logger.LogWarning($"Skipping over type [{type.FullName}] as no metadata attribute is specified"); return(null); } if (string.IsNullOrEmpty(metadata.GUID) || !allowedGuidRegex.IsMatch(metadata.GUID)) { Logger.LogWarning($"Skipping type [{type.FullName}] because its GUID [{metadata.GUID}] is of an illegal format."); return(null); } if (metadata.Version == null) { Logger.LogWarning($"Skipping type [{type.FullName}] because its version is invalid."); return(null); } if (metadata.Name == null) { Logger.LogWarning($"Skipping type [{type.FullName}] because its name is null."); return(null); } var filters = BepInProcess.FromCecilType(type); var dependencies = BepInDependency.FromCecilType(type); var incompatibilities = BepInIncompatibility.FromCecilType(type); return(new PluginInfo { Metadata = metadata, Processes = filters, Dependencies = dependencies, Incompatibilities = incompatibilities, TypeName = type.FullName }); }
public static PluginInfo ToPluginInfo(TypeDefinition type) { if (type.IsInterface || type.IsAbstract || !type.IsSubtypeOf(typeof(BaseUnityPlugin))) { return(null); } var metadata = BepInPlugin.FromCecilType(type); // Perform checks that will prevent the plugin from being loaded in ALL cases if (metadata == null) { Logger.LogWarning($"Skipping over type [{type.FullName}] as no metadata attribute is specified"); return(null); } if (string.IsNullOrEmpty(metadata.GUID) || !allowedGuidRegex.IsMatch(metadata.GUID)) { Logger.LogWarning($"Skipping type [{type.FullName}] because its GUID [{metadata.GUID}] is of an illegal format."); return(null); } if (metadata.Version == null) { Logger.LogWarning($"Skipping type [{type.FullName}] because its version is invalid."); return(null); } if (metadata.Name == null) { Logger.LogWarning($"Skipping type [{type.FullName}] because its name is null."); return(null); } var filters = BepInProcess.FromCecilType(type); var dependencies = BepInDependency.FromCecilType(type); return(new PluginInfo { Metadata = metadata, Processes = filters, Dependencies = dependencies, TypeName = type.FullName }); }