예제 #1
0
        public CSharpPlugin()
        {
            timer = new PluginTimers(this);

            Type type = GetType();

            foreach (FieldInfo field in type.GetFields(BindingFlags.NonPublic | BindingFlags.Instance))
            {
                object[] reference_attributes = field.GetCustomAttributes(typeof(PluginReferenceAttribute), true);
                if (reference_attributes.Length > 0)
                {
                    PluginReferenceAttribute pluginReference = reference_attributes[0] as PluginReferenceAttribute;
                    pluginReferenceFields[pluginReference.Name ?? field.Name] = field;
                }
            }
            foreach (MethodInfo method in type.GetMethods(BindingFlags.NonPublic | BindingFlags.Instance))
            {
                object[] info_attributes = method.GetCustomAttributes(typeof(HookMethodAttribute), true);
                if (info_attributes.Length > 0)
                {
                    continue;
                }

                if (method.Name.Equals("OnFrame"))
                {
                    HookedOnFrame = true;
                }
                // Assume all private instance methods which are not explicitly hooked could be hooks
                if (method.DeclaringType.Name == type.Name)
                {
                    AddHookMethod(method.Name, method);
                }
            }
        }
예제 #2
0
        public CSharpPlugin()
        {
            int i;

            this.timer = new PluginTimers(this);
            Type type = base.GetType();

            FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.NonPublic);
            for (i = 0; i < (int)fields.Length; i++)
            {
                FieldInfo fieldInfo        = fields[i];
                object[]  customAttributes = fieldInfo.GetCustomAttributes(typeof(PluginReferenceAttribute), true);
                if (customAttributes.Length != 0)
                {
                    PluginReferenceAttribute pluginReferenceAttribute = customAttributes[0] as PluginReferenceAttribute;
                    this.pluginReferenceFields[pluginReferenceAttribute.Name ?? fieldInfo.Name] = fieldInfo;
                }
            }
            MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.NonPublic);
            for (i = 0; i < (int)methods.Length; i++)
            {
                MethodInfo methodInfo = methods[i];
                if (methodInfo.GetCustomAttributes(typeof(HookMethodAttribute), true).Length == 0)
                {
                    if (methodInfo.Name.Equals("OnFrame"))
                    {
                        this.HookedOnFrame = true;
                    }
                    if (methodInfo.DeclaringType.Name == type.Name)
                    {
                        base.AddHookMethod(methodInfo.Name, methodInfo);
                    }
                }
            }
        }