protected internal override void CallOn(HacknetPlugin plugin, MemberInfo targettedInfo) { if (targettedInfo.DeclaringType != plugin.GetType()) { throw new InvalidOperationException($"Pathfinder.Meta.Load.PortAttribute is only valid in a class derived from BepInEx.Hacknet.HacknetPlugin"); } object portRecord = null; switch (targettedInfo) { case PropertyInfo propertyInfo: if (propertyInfo.PropertyType != typeof(PortRecord)) { throw new InvalidOperationException($"Property {propertyInfo.Name}'s type does not derive from Pathfinder.Port.PortRecord"); } portRecord = propertyInfo.GetGetMethod()?.Invoke(plugin, null); break; case FieldInfo fieldInfo: if (fieldInfo.FieldType != typeof(PortRecord)) { throw new InvalidOperationException($"Field {fieldInfo.Name}'s type does not derive from Pathfinder.Port.PortRecord"); } portRecord = fieldInfo.GetValue(plugin); break; } if (portRecord == null) { throw new InvalidOperationException($"PortRecord not set to a default value, PortRecord should be set before HacknetPlugin.Load() is called"); } PortManager.RegisterPortInternal((PortRecord)portRecord, targettedInfo.Module.Assembly); }
public static void ReadAttributesFor(HacknetPlugin plugin) { var pluginType = plugin.GetType(); if (pluginType.GetCustomAttribute <IgnorePluginAttribute>() != null) { return; } ReadAttributesOnType(plugin, pluginType); foreach (var type in pluginType.Assembly.GetTypes()) { if (type == pluginType) { continue; } ReadAttributesOnType(plugin, type); } }
protected internal override void CallOn(HacknetPlugin plugin, MemberInfo targettedInfo) { if (Tag == null) { Tag = plugin.GetOptionsTag(); if (Tag == null) { throw new InvalidOperationException($"Could not find Pathfinder.Meta.Load.OptionsTabAttribute for {targettedInfo.DeclaringType.FullName}"); } } if (targettedInfo.DeclaringType != plugin.GetType()) { throw new InvalidOperationException($"Pathfinder.Meta.Load.OptionAttribute is only valid in a class derived from BepInEx.Hacknet.HacknetPlugin"); } Option option = null; switch (targettedInfo) { case PropertyInfo propertyInfo: if (!propertyInfo.PropertyType.IsSubclassOf(typeof(Option))) { throw new InvalidOperationException($"Property {propertyInfo.Name}'s type does not derive from Pathfinder.Options.Option"); } option = (Option)(propertyInfo.GetGetMethod()?.Invoke(plugin, null)); break; case FieldInfo fieldInfo: if (!fieldInfo.FieldType.IsSubclassOf(typeof(Option))) { throw new InvalidOperationException($"Field {fieldInfo.Name}'s type does not derive from Pathfinder.Options.Option"); } option = (Option)fieldInfo.GetValue(plugin); break; } if (option == null) { throw new InvalidOperationException($"Option not set to a default value, Option members should be set before HacknetPlugin.Load() is called"); } OptionsManager.AddOption(Tag, option); }
private static void OnPluginUnload(ref HacknetPlugin __instance) { var evt = new UnloadEvent(); EventManager <UnloadEvent> .InvokeAssembly(__instance.GetType().Assembly, evt); }
internal static void OnPluginUnload(ref HacknetPlugin __instance) => Event.EventManager.InvokeOnPluginUnload(__instance.GetType().Assembly);