public static IEnumerable <CodeInstruction> Transpiler(IEnumerable <CodeInstruction> instructions) { CodeMatcher matcher = new CodeMatcher(instructions) .End() .MatchBack(false, new CodeMatch(OpCodes.Ldarg_0), new CodeMatch(OpCodes.Ldflda, AccessTools.Field(typeof(BuildTool_BlueprintPaste), nameof(BuildTool_BlueprintPaste.cursorTarget)))); CodeMatcher matcher2 = matcher.Clone().MatchForward(false, new CodeMatch(OpCodes.Ldloc_S), new CodeMatch(OpCodes.Ldc_I4_S) , new CodeMatch(OpCodes.Stfld, AccessTools.Field(typeof(BuildPreview), nameof(BuildPreview.condition)))); object previewVariable = matcher2.Operand; matcher.Advance(1); while (matcher.Opcode != OpCodes.Stloc_S) { matcher.RemoveInstruction(); } matcher.InsertAndAdvance(new CodeInstruction(OpCodes.Ldloc_S, previewVariable)) .InsertAndAdvance(Transpilers.EmitDelegate <Func <BuildTool_BlueprintPaste, BuildPreview, Vector3> >((tool, preview) => preview.lpos.normalized * Mathf.Min(tool.planet.realRadius * 0.025f, 20f))); return(matcher.InstructionEnumeration()); }
public static IEnumerable <CodeInstruction> AddColors(IEnumerable <CodeInstruction> instructions) { CodeMatcher matcher = new CodeMatcher(instructions) .MatchForward(false, new CodeMatch(OpCodes.Ldloc_1), new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(BeltComponent), nameof(BeltComponent.speed))), new CodeMatch(OpCodes.Ldc_I4_1) ); CodeMatcher matcher2 = matcher.Clone(); matcher2.MatchForward(true, new CodeMatch(OpCodes.Ldloc_S), new CodeMatch(OpCodes.Stloc_S)); object arg = matcher2.Operand; matcher2.Advance(1); object label = matcher2.Operand; matcher.Advance(2) .InsertAndAdvance(new CodeInstruction(OpCodes.Ldloc_S, arg)) .SetInstruction(Transpilers.EmitDelegate <Func <int, int, int> >((speed, other) => { if (speed <= 1) { return(other); } if (speed <= 2) { other += 4; } else if (speed <= 5) { other += 8; } else if (speed <= 12) { other += 12; } return(other); })) .Advance(1) .InsertAndAdvance(new CodeInstruction(OpCodes.Stloc_S, arg)) .SetInstruction(new CodeInstruction(OpCodes.Br, label)); return(matcher.InstructionEnumeration()); }
public static IEnumerable <CodeInstruction> ShowLockedIconsUpdate(IEnumerable <CodeInstruction> instructions) { CodeMatcher matcher = new CodeMatcher(instructions) .MatchForward(false, new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(Proto), nameof(Proto.ID))), new CodeMatch(OpCodes.Stloc_S), new CodeMatch(OpCodes.Ldloc_0)) .MatchForward(false, new CodeMatch(OpCodes.Ldloc_3)) .Advance(1) .InsertAndAdvance(new CodeInstruction(OpCodes.Ldloc_2)) .InsertAndAdvance(new CodeInstruction(OpCodes.Ldarg_0)) .InsertAndAdvance(Transpilers.EmitDelegate <Func <bool, int, UIBuildMenu, bool> >((result, index, that) => { if (result) { return(true); } if (!GameMain.history.TechUnlocked(1001) || index == 9) { return(false); } that.isAnyCategoryUnlocked = true; return(true); })); matcher.MatchForward(false, new CodeMatch(OpCodes.Ldarg_0), new CodeMatch(OpCodes.Ldfld), new CodeMatch(OpCodes.Ldc_I4_1) ) .MatchForward(false, new CodeMatch(OpCodes.Callvirt, AccessTools.Method(typeof(GameHistoryData), nameof(GameHistoryData.ItemUnlocked)))); CodeMatcher matcher2 = matcher.Clone(); matcher2.MatchForward(false, new CodeMatch(OpCodes.Stfld, AccessTools.Field(typeof(UIButton), nameof(UIButton.highlighted)))) .Advance(1); Label label = (Label)matcher2.Operand; matcher.Advance(1) .InsertAndAdvance(new CodeInstruction(OpCodes.Pop)) .SetInstruction(new CodeInstruction(OpCodes.Br, label)); matcher.MatchForward(false, new CodeMatch(OpCodes.Ldfld), new CodeMatch(OpCodes.Callvirt, AccessTools.Method(typeof(Component), "get_gameObject")), new CodeMatch(OpCodes.Ldc_I4_0), new CodeMatch(OpCodes.Callvirt, AccessTools.Method(typeof(GameObject), nameof(GameObject.SetActive))) ) .Advance(5) .InsertAndAdvance(new CodeInstruction(OpCodes.Ldarg_0)) .InsertAndAdvance(new CodeInstruction(OpCodes.Ldloc_S, 9)) .InsertAndAdvance(Transpilers.EmitDelegate <Action <UIBuildMenu, int> >(ButtonLogic)); return(matcher.InstructionEnumeration()); }