private void SearchHotfixMethod() { Type[] types = HotfixAssembly.GetTypes(); for (int i = 0; i < types.Length; i++) { MethodInfo[] methods = types[i].GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); for (int j = 0; j < methods.Length; j++) { HotfixMethodAttribute att = methods[j].GetCustomAttribute <HotfixMethodAttribute>(); if (att != null) { HotfixMethodType methodType = GetHotfixMethodType(methods[j]); if (!FixedMethods[methodType].ContainsKey(att.TargetName)) { FixedMethods[methodType].Add(att.TargetName, methods[j]); } } } } if (FixedMethods[HotfixMethodType.Invalid].Count > 0) { foreach (var item in FixedMethods[HotfixMethodType.Invalid]) { Log.Error("发现无效的热修复方法:" + item.Value.Name); } FixedMethods[HotfixMethodType.Invalid].Clear(); } }
private Delegate FixMethod(HotfixMethodType methodType, string targetName, Type type) { if (!_module.IsEnableHotfix) { return(null); } if (FixedDelegates[methodType].ContainsKey(targetName)) { return(FixedDelegates[methodType][targetName]); } else { if (FixedMethods[methodType].ContainsKey(targetName)) { Delegate del = Delegate.CreateDelegate(type, FixedMethods[methodType][targetName]); FixedDelegates[methodType].Add(targetName, del); return(del); } else { return(null); } } }