public static string AllHarmonyPatchesDump() { StringBuilder sb = new StringBuilder(); sb.AppendLine("===[Harmony Patches]==="); void dumpPatchesInfo(string type, ReadOnlyCollection <Patch> patches) { // Sort patches by harmony execute priority var patchesSorted = patches.ToList().OrderByDescending(x => x.priority).ThenBy(x => x.index); foreach (var p in patchesSorted) { var m = p.PatchMethod; sb.AppendLine($" {type}:{m.ReturnType.Name} {m.GetMethodFullString()} [mod:{p.owner}, prior:{p.priority}, idx:{p.index}]"); foreach (var b in p.before) { sb.AppendLine($" before:{b}"); } foreach (var a in p.after) { sb.AppendLine($" after:{a}"); } } //if (patches.Count > 0) // sb.AppendLine(); } var patchesDic = HarmonyMain.GetPatches(null, false); foreach (var kv in patchesDic) { var patch = kv.Value; if (patch.Owners.Count >= 1) { sb.AppendLine($"{kv.Key.GetMethodFullString()}:(Owners:{patch.Owners.Count}, Prefixes:{patch.Prefixes.Count}, Postfixes:{patch.Postfixes.Count}, Transpilers:{patch.Transpilers.Count})"); dumpPatchesInfo("prefix", patch.Prefixes); dumpPatchesInfo("transpiler", patch.Transpilers); dumpPatchesInfo("postfix", patch.Postfixes); sb.AppendLine(); } } return(sb.ToString()); }
public static void ResetProfiler() { if (!CanUnpatch()) { return; } // Unpatch all foreach (var p in HarmonyMain.GetPatches(new[] { DubId }, false)) { DubInst.Unpatch(p.Key, HarmonyPatchType.All, DubId); } // ApplyPerfomancePatches beforeMainTabs_PatchMe.Invoke(null, null); foreach (var type in GenTypes.AllTypes.Where(x => x.GetAttr("PerformancePatch") != null)) { MethodInfo methodInfo = AccessTools.Method(type, "PerformancePatch"); methodInfo?.Invoke(null, null); } //ResetTabs if (dialogAnalyzer_mainTabs.GetValue(null) is IEnumerable list) { var enumerator = list.GetEnumerator(); while (enumerator.MoveNext()) { // clear dictionary var modes = profileTab_Modes.GetValue(enumerator.Current); modes.GetType().GetMethod("Clear").Invoke(modes, null); } } dialogAnalyzer_PatchedEverything.SetValue(null, false); analyzer_RequestStop.SetValue(null, true); Log.Warning($"Unpatched: {DubId}"); }