Example #1
0
        private void Load()
        {
            this.allEvents = new Dictionary <int, List <object> >();

            Type[] types = DllHelper.GetBaseTypes();
            foreach (Type type in types)
            {
                object[] attrs = type.GetCustomAttributes(typeof(EventAttribute), false);

                foreach (object attr in attrs)
                {
                    EventAttribute aEventAttribute = (EventAttribute)attr;

                    object obj = Activator.CreateInstance(type);
                    if (!this.allEvents.ContainsKey(aEventAttribute.Type))
                    {
                        this.allEvents.Add(aEventAttribute.Type, new List <object>());
                    }
                    this.allEvents[aEventAttribute.Type].Add(obj);
                }
            }
        }
Example #2
0
        private void Load()
        {
            this.allEvents = new Dictionary <int, List <IInstanceMethod> >();

            Type[] types = DllHelper.GetBaseTypes();
            foreach (Type type in types)
            {
                object[] attrs = type.GetCustomAttributes(typeof(EventAttribute), false);

                foreach (object attr in attrs)
                {
                    EventAttribute  aEventAttribute = (EventAttribute)attr;
                    IInstanceMethod method          = new MonoInstanceMethod(type, "Run");
                    if (!this.allEvents.ContainsKey(aEventAttribute.Type))
                    {
                        this.allEvents.Add(aEventAttribute.Type, new List <IInstanceMethod>());
                    }
                    this.allEvents[aEventAttribute.Type].Add(method);
                }
            }

            types = DllHelper.GetHotfixTypes();
            foreach (Type type in types)
            {
                object[] attrs = type.GetCustomAttributes(typeof(EventAttribute), false);

                foreach (object attr in attrs)
                {
                    EventAttribute  aEventAttribute = (EventAttribute)attr;
                    IInstanceMethod method          = new ILInstanceMethod(type, "Run");
                    if (!this.allEvents.ContainsKey(aEventAttribute.Type))
                    {
                        this.allEvents.Add(aEventAttribute.Type, new List <IInstanceMethod>());
                    }
                    this.allEvents[aEventAttribute.Type].Add(method);
                }
            }
        }
        public void LoadAssemblyInfo()
        {
            this.eventInfo           = new Dictionary <int, EntityTypeInfo>();
            this.typeToEntityEventId = new Dictionary <Type, int>();

            Type[]        types         = DllHelper.GetBaseTypes();
            List <string> allEntityType = Enum.GetNames(typeof(EntityEventType)).ToList();

            foreach (Type type in types)
            {
                object[] attrs = type.GetCustomAttributes(typeof(EntityEventAttribute), true);
                if (attrs.Length == 0)
                {
                    continue;
                }

                EntityEventAttribute entityEventAttribute = attrs[0] as EntityEventAttribute;

                int entityEventId = entityEventAttribute.ClassType;

                this.typeToEntityEventId[type] = entityEventId;

                if (!this.eventInfo.ContainsKey(entityEventId))
                {
                    this.eventInfo.Add(entityEventId, new EntityTypeInfo());
                }

                MethodInfo[] methodInfos = type.GetMethods(
                    BindingFlags.Instance | BindingFlags.Static | BindingFlags.InvokeMethod |
                    BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.DeclaredOnly);
                foreach (MethodInfo methodInfo in methodInfos)
                {
                    int n = methodInfo.GetParameters().Length;
                    if (methodInfo.IsStatic)
                    {
                        --n;
                    }

                    string sn = n > 0 ? $"{methodInfo.Name}{n}" : methodInfo.Name;
                    if (!allEntityType.Contains(sn))
                    {
                        continue;
                    }

                    EntityEventType t = EnumHelper.FromString <EntityEventType>(sn);
                    this.eventInfo[entityEventId].Add(t, new MonoCommonMethod(methodInfo));
                }
            }

#if !SERVER
            if (this.appDomain == null)
            {
                return;
            }

            IType[] ilTypes = this.appDomain.LoadedTypes.Values.ToArray();
            foreach (IType itype in ilTypes)
            {
                Type     type  = itype.ReflectionType;
                object[] attrs = type.GetCustomAttributes(typeof(EntityEventAttribute), true);
                if (attrs.Length == 0)
                {
                    continue;
                }

                EntityEventAttribute entityEventAttribute = attrs[0] as EntityEventAttribute;

                int entityEventId = entityEventAttribute.ClassType;

                if (!this.eventInfo.ContainsKey(entityEventId))
                {
                    this.eventInfo.Add(entityEventId, new EntityTypeInfo());
                }

                foreach (IMethod methodInfo in itype.GetMethods())
                {
                    int n = methodInfo.ParameterCount;
                    if (methodInfo.IsStatic)
                    {
                        --n;
                    }

                    string sn = n > 0 ? $"{methodInfo.Name}{n}" : methodInfo.Name;
                    if (!allEntityType.Contains(sn))
                    {
                        continue;
                    }

                    EntityEventType t = EnumHelper.FromString <EntityEventType>(sn);
                    this.eventInfo[entityEventId].Add(t, new ILCommonMethod(methodInfo, n));
                }
            }
#endif
        }