private void Load() { this.handlers = new Dictionary <ushort, List <IMHandler> >(); this.messageOpcode = new Dictionary <Type, MessageAttribute>(); Assembly[] assemblies = Game.EntityEventManager.GetAssemblies(); foreach (Assembly assembly in assemblies) { Type[] types = assembly.GetTypes(); foreach (Type type in types) { object[] attrs = type.GetCustomAttributes(typeof(MessageAttribute), false); if (attrs.Length == 0) { continue; } MessageAttribute messageAttribute = (MessageAttribute)attrs[0]; this.messageOpcode[type] = messageAttribute; } } foreach (Assembly assembly in assemblies) { Type[] types = assembly.GetTypes(); foreach (Type type in types) { object[] attrs = type.GetCustomAttributes(typeof(MessageHandlerAttribute), false); if (attrs.Length == 0) { continue; } MessageHandlerAttribute messageHandlerAttribute = (MessageHandlerAttribute)attrs[0]; if (!messageHandlerAttribute.Type.Is(this.AppType)) { continue; } object obj = Activator.CreateInstance(type); IMHandler imHandler = obj as IMHandler; if (imHandler == null) { throw new Exception($"message handler not inherit AMEvent or AMRpcEvent abstract class: {obj.GetType().FullName}"); } Type messageType = imHandler.GetMessageType(); ushort opcode = this.GetOpcode(messageType); List <IMHandler> list; if (!this.handlers.TryGetValue(opcode, out list)) { list = new List <IMHandler>(); this.handlers.Add(opcode, list); } list.Add(imHandler); } } }
private void Load() { this.handlers = new Dictionary <ushort, List <IInstanceMethod> >(); this.opcodeTypes = new DoubleMap <ushort, Type>(); Type[] monoTypes = DllHelper.GetMonoTypes(); foreach (Type monoType in monoTypes) { object[] attrs = monoType.GetCustomAttributes(typeof(MessageAttribute), false); if (attrs.Length == 0) { continue; } MessageAttribute messageAttribute = attrs[0] as MessageAttribute; if (messageAttribute == null) { continue; } this.opcodeTypes.Add(messageAttribute.Opcode, monoType); } #if ILRuntime Type[] types = DllHelper.GetHotfixTypes(); #else Type[] types = DllHelper.GetMonoTypes(); #endif foreach (Type type in types) { object[] attrs = type.GetCustomAttributes(typeof(MessageHandlerAttribute), false); if (attrs.Length == 0) { continue; } MessageHandlerAttribute messageHandlerAttribute = (MessageHandlerAttribute)attrs[0]; #if ILRuntime IInstanceMethod method = new ILInstanceMethod(type, "Handle"); #else IInstanceMethod method = new MonoInstanceMethod(type, "Handle"); #endif if (!this.handlers.ContainsKey(messageHandlerAttribute.Opcode)) { this.handlers.Add(messageHandlerAttribute.Opcode, new List <IInstanceMethod>()); } this.handlers[messageHandlerAttribute.Opcode].Add(method); } }
public void Load() { handlers = new Dictionary <Opcode, List <IMessageMethod> >(); Type[] types = DllHelper.GetMonoTypes(); foreach (Type type in types) { object[] attrs = type.GetCustomAttributes(typeof(MessageHandlerAttribute), false); if (attrs.Length == 0) { continue; } MessageHandlerAttribute messageHandlerAttribute = (MessageHandlerAttribute)attrs[0]; IMHandler iMHandler = (IMHandler)Activator.CreateInstance(type); if (!this.handlers.ContainsKey((Opcode)messageHandlerAttribute.Opcode)) { this.handlers.Add((Opcode)messageHandlerAttribute.Opcode, new List <IMessageMethod>()); } this.handlers[(Opcode)messageHandlerAttribute.Opcode].Add(new IMessageMonoMethod(iMHandler)); } // hotfix dll Type[] hotfixTypes = DllHelper.GetHotfixTypes(); foreach (Type type in hotfixTypes) { object[] attrs = type.GetCustomAttributes(typeof(MessageHandlerAttribute), false); if (attrs.Length == 0) { continue; } MessageHandlerAttribute messageHandlerAttribute = (MessageHandlerAttribute)attrs[0]; #if ILRuntime IMessageMethod iMessageMethod = new IMessageILMethod(type, "Handle"); #else IMHandler iMHandler = (IMHandler)Activator.CreateInstance(type); IMessageMethod iMessageMethod = new IMessageMonoMethod(iMHandler); #endif if (!this.handlers.ContainsKey((Opcode)messageHandlerAttribute.Opcode)) { this.handlers.Add((Opcode)messageHandlerAttribute.Opcode, new List <IMessageMethod>()); } this.handlers[(Opcode)messageHandlerAttribute.Opcode].Add(iMessageMethod); } }
public void Load() { handlers = new Dictionary <ushort, List <IMHandler> >(); Type[] types = DllHelper.GetMonoTypes(); foreach (Type type in types) { object[] attrs = type.GetCustomAttributes(typeof(MessageHandlerAttribute), false); if (attrs.Length == 0) { continue; } MessageHandlerAttribute messageHandlerAttribute = (MessageHandlerAttribute)attrs[0]; IMHandler iMHandler = (IMHandler)Activator.CreateInstance(type); if (!this.handlers.ContainsKey(messageHandlerAttribute.Opcode)) { this.handlers.Add(messageHandlerAttribute.Opcode, new List <IMHandler>()); } this.handlers[messageHandlerAttribute.Opcode].Add(iMHandler); } }
public void Load() { AppType appType = this.Parent.GetComponent <StartConfigComponent>().StartConfig.AppType; this.handlers = new Dictionary <Type, List <IMHandler> >(); Type[] types = DllHelper.GetMonoTypes(); foreach (Type type in types) { object[] attrs = type.GetCustomAttributes(typeof(MessageHandlerAttribute), false); if (attrs.Length == 0) { continue; } MessageHandlerAttribute messageHandlerAttribute = (MessageHandlerAttribute)attrs[0]; if (!messageHandlerAttribute.Type.Is(appType)) { continue; } object obj = Activator.CreateInstance(type); IMHandler imHandler = obj as IMHandler; if (imHandler == null) { throw new Exception($"message handler not inherit AMEvent or AMRpcEvent abstract class: {obj.GetType().FullName}"); } Type messageType = imHandler.GetMessageType(); if (!this.handlers.TryGetValue(messageType, out List <IMHandler> list)) { list = new List <IMHandler>(); this.handlers.Add(messageType, list); } list.Add(imHandler); } }