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); }
protected internal override void CallOn(HacknetPlugin plugin, MemberInfo targettedInfo) { var methodInfo = (MethodInfo)targettedInfo; var commandAction = (Action <OS, string[]>)methodInfo.CreateDelegate(typeof(Action <OS, string[]>)); CommandManager.RegisterCommand(CommandName, commandAction, AddAutocomplete, CaseSensitive); }
public static string GetOptionsTag(this HacknetPlugin plugin) { if (!OptionsTabAttribute.pluginToOptionsTag.TryGetValue(plugin, out var tag)) { return(null); } return(tag); }
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 ReadAttributesOnType(HacknetPlugin plugin, Type type) { foreach (var attribute in type.GetCustomAttributes <BaseAttribute>()) { attribute.CallOn(plugin, type); } foreach (var member in type.GetMembers(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static)) { if (member.MemberType == MemberTypes.NestedType) { ReadAttributesOnType(plugin, (Type)member); } else { foreach (var attribute in member.GetCustomAttributes <BaseAttribute>()) { attribute.CallOn(plugin, member); } } } }
internal static void OnPluginUnload(ref HacknetPlugin __instance) => Event.EventManager.InvokeOnPluginUnload(__instance.GetType().Assembly);
protected internal override void CallOn(HacknetPlugin plugin, MemberInfo targettedInfo) { ExtensionInfoLoader.RegisterExecutor((Type)targettedInfo, Element, ParseOptions); }
public static bool HasOptionsTag(this HacknetPlugin plugin) { return(OptionsTabAttribute.pluginToOptionsTag.ContainsKey(plugin)); }
protected internal override void CallOn(HacknetPlugin plugin, MemberInfo targettedInfo) { ExecutableManager.RegisterExecutable((Type)targettedInfo, XmlName); }
private static void OnPluginLoad(ref HacknetChainloader __instance, ref HacknetPlugin __result, Assembly pluginAssembly) { var evt = new LoadEvent(); EventManager <LoadEvent> .InvokeAssembly(pluginAssembly, evt); }
protected internal override void CallOn(HacknetPlugin plugin, MemberInfo targettedInfo) { ConditionManager.RegisterCondition((Type)targettedInfo, XmlName); }
protected internal override void CallOn(HacknetPlugin plugin, MemberInfo targettedInfo) { AdministratorManager.RegisterAdministrator((Type)targettedInfo); }
protected internal override void CallOn(HacknetPlugin plugin, MemberInfo targettedInfo) { DaemonManager.RegisterDaemon((Type)targettedInfo); }
internal protected abstract void CallOn(HacknetPlugin plugin, MemberInfo targettedInfo);
private static void OnPluginUnload(ref HacknetPlugin __instance) { var evt = new UnloadEvent(); EventManager <UnloadEvent> .InvokeAssembly(__instance.GetType().Assembly, evt); }
protected internal override void CallOn(HacknetPlugin plugin, MemberInfo targettedInfo) { pluginToOptionsTag.Add(plugin, Tag); }