コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
 public static string GetOptionsTag(this HacknetPlugin plugin)
 {
     if (!OptionsTabAttribute.pluginToOptionsTag.TryGetValue(plugin, out var tag))
     {
         return(null);
     }
     return(tag);
 }
コード例 #4
0
        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);
            }
        }
コード例 #5
0
        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);
        }
コード例 #6
0
 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);
             }
         }
     }
 }
コード例 #7
0
 internal static void OnPluginUnload(ref HacknetPlugin __instance) => Event.EventManager.InvokeOnPluginUnload(__instance.GetType().Assembly);
コード例 #8
0
 protected internal override void CallOn(HacknetPlugin plugin, MemberInfo targettedInfo)
 {
     ExtensionInfoLoader.RegisterExecutor((Type)targettedInfo, Element, ParseOptions);
 }
コード例 #9
0
 public static bool HasOptionsTag(this HacknetPlugin plugin)
 {
     return(OptionsTabAttribute.pluginToOptionsTag.ContainsKey(plugin));
 }
コード例 #10
0
 protected internal override void CallOn(HacknetPlugin plugin, MemberInfo targettedInfo)
 {
     ExecutableManager.RegisterExecutable((Type)targettedInfo, XmlName);
 }
コード例 #11
0
        private static void OnPluginLoad(ref HacknetChainloader __instance, ref HacknetPlugin __result, Assembly pluginAssembly)
        {
            var evt = new LoadEvent();

            EventManager <LoadEvent> .InvokeAssembly(pluginAssembly, evt);
        }
コード例 #12
0
 protected internal override void CallOn(HacknetPlugin plugin, MemberInfo targettedInfo)
 {
     ConditionManager.RegisterCondition((Type)targettedInfo, XmlName);
 }
コード例 #13
0
 protected internal override void CallOn(HacknetPlugin plugin, MemberInfo targettedInfo)
 {
     AdministratorManager.RegisterAdministrator((Type)targettedInfo);
 }
コード例 #14
0
 protected internal override void CallOn(HacknetPlugin plugin, MemberInfo targettedInfo)
 {
     DaemonManager.RegisterDaemon((Type)targettedInfo);
 }
コード例 #15
0
 internal protected abstract void CallOn(HacknetPlugin plugin, MemberInfo targettedInfo);
コード例 #16
0
        private static void OnPluginUnload(ref HacknetPlugin __instance)
        {
            var evt = new UnloadEvent();

            EventManager <UnloadEvent> .InvokeAssembly(__instance.GetType().Assembly, evt);
        }
コード例 #17
0
 protected internal override void CallOn(HacknetPlugin plugin, MemberInfo targettedInfo)
 {
     pluginToOptionsTag.Add(plugin, Tag);
 }