コード例 #1
0
        public void RegisterEventHandler(AuroraType form, string event_name, MethodInfo handler, Func <Control, bool> predicate = null)
        {
            if (!handler.IsStatic)
            {
                LogError($"Event handler {handler.DeclaringType.Name}.{handler.Name} is not static.");

                return;
            }

            lock (EventHandlers)
            {
                var type = SignatureManager.Get(form);

                if (!EventHandlers.ContainsKey(type))
                {
                    EventHandlers.Add(type, new List <Tuple <string, MethodInfo, Func <Control, bool> > >());
                }

                EventHandlers[type].Add(new Tuple <string, MethodInfo, Func <Control, bool> >(event_name, handler, predicate));
            }
        }
コード例 #2
0
        protected override void Loaded(Harmony harmony)
        {
            Instance         = this;
            KnowledgeBase    = new KnowledgeBase(this);
            SignatureManager = new SignatureManager(this);
            UIManager        = new UIManager(this);

            foreach (var form in AuroraAssembly.GetTypes().Where(t => typeof(Form).IsAssignableFrom(t)))
            {
                try
                {
                    var ctor   = (MethodBase)form.GetMember(".ctor", AccessTools.all)[0];
                    var method = new HarmonyMethod(GetType().GetMethod("PostfixFormConstructor", AccessTools.all));
                    harmony.Patch(ctor, null, method);
                }
                catch (Exception e)
                {
                    LogError($"Failed to patch Form constructor {form.Name}, exception: {e}");
                }
            }
        }