public static IEnumerable <CodeInstruction> ReplaceModOptionsButton(this IEnumerable <CodeInstruction> instructions) { patched = false; var expectedButtonMethod = AccessTools.Method(typeof(Listing_Standard), "ButtonText", new[] { typeof(string), typeof(string) }); if (expectedButtonMethod == null || expectedButtonMethod.ReturnType != typeof(bool)) { HugsLibController.Logger.Error("Failed to reflect required method for transpiler: " + Environment.StackTrace); } var labelFound = false; foreach (var instruction in instructions) { if (expectedButtonMethod != null && !patched) { // find the right button by its untranslated label if (instruction.opcode == OpCodes.Ldstr && instruction.operand as string == ButtonLabelToKill) { labelFound = true; } else if (labelFound && instruction.opcode == OpCodes.Callvirt && expectedButtonMethod.Equals(instruction.operand)) { // replace the button call with out own method instruction.operand = ((ModSettingsButtonReplacementMethod)((_this, label, highlightTag) => { OptionsDialogInjection.DrawModSettingsButton(_this); return(false); })).Method; patched = true; } } yield return(instruction); } }
private static bool DrawReplacementButton(Listing_Standard _this, string label, string highlightTag) { OptionsDialogInjection.DrawModSettingsButton(_this); return(false); }