예제 #1
0
파일: CSPlugin.cs 프로젝트: Slut/Oxide.Core
        /// <summary>
        /// Initializes a new instance of the CSPlugin class
        /// </summary>
        public CSPlugin()
        {
            // Find all hooks in the plugin and any base classes derived from CSPlugin
            Type        type  = GetType();
            List <Type> types = new List <Type> {
                type
            };

            while (type != typeof(CSPlugin))
            {
                types.Add(type = type.BaseType);
            }

            // Add hooks implemented in base classes before user implemented methods
            for (int i = types.Count - 1; i >= 0; i--)
            {
                foreach (MethodInfo method in types[i].GetMethods(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance))
                {
                    object[] attr = method.GetCustomAttributes(typeof(HookMethodAttribute), true);
                    if (attr.Length < 1)
                    {
                        continue;
                    }

                    HookMethodAttribute hookmethod = attr[0] as HookMethodAttribute;
                    AddHookMethod(hookmethod?.Name, method);
                }
            }
        }
예제 #2
0
        public CSPlugin()
        {
            string      name;
            Type        type  = base.GetType();
            List <Type> types = new List <Type>()
            {
                type
            };

            while (type != typeof(CSPlugin))
            {
                Type baseType = type.BaseType;
                type = baseType;
                types.Add(baseType);
            }
            for (int i = types.Count - 1; i >= 0; i--)
            {
                MethodInfo[] methods = types[i].GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
                for (int j = 0; j < (int)methods.Length; j++)
                {
                    MethodInfo methodInfo       = methods[j];
                    object[]   customAttributes = methodInfo.GetCustomAttributes(typeof(HookMethodAttribute), true);
                    if ((int)customAttributes.Length >= 1)
                    {
                        HookMethodAttribute hookMethodAttribute = customAttributes[0] as HookMethodAttribute;
                        if (hookMethodAttribute != null)
                        {
                            name = hookMethodAttribute.Name;
                        }
                        else
                        {
                            name = null;
                        }
                        this.AddHookMethod(name, methodInfo);
                    }
                }
            }
        }