/// <summary>Create a patch processor from an annotated class</summary> /// <param name="type">The class</param> /// public PatchProcessor ProcessorForAnnotatedClass(Type type) { var parentMethodInfos = HarmonyMethodExtensions.GetFromType(type); if (parentMethodInfos != null && parentMethodInfos.Any()) { var info = HarmonyMethod.Merge(parentMethodInfos); return(new PatchProcessor(this, type, info)); } return(null); }
/// <summary>Creates an empty patch class processor</summary> /// <param name="instance">The Harmony instance</param> /// <param name="type">The class to process</param> /// public PatchClassProcessor(Harmony instance, Type type) { if (instance == null) { throw new ArgumentNullException(nameof(instance)); } if (type == null) { throw new ArgumentNullException(nameof(type)); } this.instance = instance; containerType = type; var harmonyAttributes = HarmonyMethodExtensions.GetFromType(type); if (harmonyAttributes == null || harmonyAttributes.Count == 0) { return; } containerAttributes = HarmonyMethod.Merge(harmonyAttributes); if (containerAttributes.methodType == null) // MethodType default is Normal { containerAttributes.methodType = MethodType.Normal; } auxilaryMethods = new Dictionary <Type, MethodInfo>(); foreach (var auxType in auxilaryTypes) { var method = PatchTools.GetPatchMethod(containerType, auxType.FullName); if (method != null) { auxilaryMethods[auxType] = method; } } patchMethods = PatchTools.GetPatchMethods(containerType); foreach (var patchMethod in patchMethods) { var method = patchMethod.info.method; patchMethod.info = containerAttributes.Merge(patchMethod.info); patchMethod.info.method = method; } }