public void PatchAll(Type type) { CollectionExtensions.Do(type.GetMethods(BindingFlags.Static | BindingFlags.Public), delegate(MethodInfo method) { var harmonyMethods = method.GetHarmonyMethods(); if (harmonyMethods != null && harmonyMethods.Any()) { var original = HarmonyMethod.Merge(harmonyMethods); HarmonyMethod prefix = null; HarmonyMethod transpiler = null; HarmonyMethod postfix = null; if (method.GetCustomAttributes(true).Any(x => x is HarmonyPrefix)) { prefix = new HarmonyMethod(method); } if (method.GetCustomAttributes(true).Any(x => x is HarmonyTranspiler)) { transpiler = new HarmonyMethod(method); } if (method.GetCustomAttributes(true).Any(x => x is HarmonyPostfix)) { postfix = new HarmonyMethod(method); } new PatchProcessor(this, original, prefix, postfix, transpiler).Patch(); } }); }
public Dictionary <string, Version> VersionInfo(out Version currentVersion) { currentVersion = typeof(HarmonyInstance).Assembly.GetName().Version; var assemblies = new Dictionary <string, Assembly>(); CollectionExtensions.Do(GetPatchedMethods(), method => { var info = HarmonySharedState.GetPatchInfo(method); info.prefixes.Do(fix => assemblies[fix.owner] = fix.patch.DeclaringType.Assembly); info.postfixes.Do(fix => assemblies[fix.owner] = fix.patch.DeclaringType.Assembly); info.transpilers.Do(fix => assemblies[fix.owner] = fix.patch.DeclaringType.Assembly); }); var result = new Dictionary <string, Version>(); assemblies.Do(info => { var assemblyName = info.Value.GetReferencedAssemblies().FirstOrDefault(a => a.FullName.StartsWith("0Harmony, Version")); if (assemblyName != null) { result[info.Key] = assemblyName.Version; } }); return(result); }