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 }); }
void ICacheable.Load(BinaryReader br) { TypeName = br.ReadString(); Location = br.ReadString(); Metadata = new BepInPlugin(br.ReadString(), br.ReadString(), br.ReadString()); var processListCount = br.ReadInt32(); var processList = new List <BepInProcess>(processListCount); for (var i = 0; i < processListCount; i++) { processList.Add(new BepInProcess(br.ReadString())); } Processes = processList; var depCount = br.ReadInt32(); var depList = new List <BepInDependency>(depCount); for (var i = 0; i < depCount; i++) { var dep = new BepInDependency(""); ((ICacheable)dep).Load(br); depList.Add(dep); } Dependencies = depList; var incCount = br.ReadInt32(); var incList = new List <BepInIncompatibility>(incCount); for (var i = 0; i < incCount; i++) { var inc = new BepInIncompatibility(""); ((ICacheable)inc).Load(br); incList.Add(inc); } Incompatibilities = incList; TargettedBepInExVersion = new Version(br.ReadString()); }