static IEnumerable <CodeInstruction> Transpiler(IEnumerable <CodeInstruction> e, MethodBase original) { List <CodeInstruction> insts = new List <CodeInstruction>(e); CodeFinder finder = new CodeFinder(original, insts); int tradeMode = finder. Start(). Forward(OpCodes.Ldsfld, TradeModeIcon). Forward(OpCodes.Call, ButtonImageWithBG); insts.Insert( tradeMode + 2, new CodeInstruction(OpCodes.Call, ToggleGiftModeMethod), new CodeInstruction(OpCodes.Brtrue, insts[tradeMode + 1].operand) ); int giftMode = finder. Start(). Forward(OpCodes.Ldsfld, GiftModeIcon). Forward(OpCodes.Call, ButtonImageWithBG); insts.Insert( giftMode + 2, new CodeInstruction(OpCodes.Call, ToggleGiftModeMethod), new CodeInstruction(OpCodes.Brtrue, insts[giftMode + 1].operand) ); return(insts); }
static IEnumerable <CodeInstruction> Transpiler(IEnumerable <CodeInstruction> e, MethodBase original) { List <CodeInstruction> insts = (List <CodeInstruction>)e; int pos = new CodeFinder(original, insts).Forward(OpCodes.Call, GetStatValueAbstract); insts[pos + 1] = new CodeInstruction(OpCodes.Call, WorkToBuildMethod); return(insts); }
static IEnumerable <CodeInstruction> Transpiler(IEnumerable <CodeInstruction> e, MethodBase original) { byte thingToIgnore_Ldarg_S = (byte)original.GetParameters().FirstIndexOf(p => p.Name == "thingToIgnore"); if (thingToIgnore_Ldarg_S < 1) { Log.Error($"FAIL: {nameof(CanPlaceBlueprintAtPatch2)} can't find thingToIgnore"); return(e); } List <CodeInstruction> insts = e.ToList(); int loop1 = new CodeFinder(original, insts). Forward(OpCodes.Ldstr, "IdenticalThingExists"). Backward(OpCodes.Ldarg_S, thingToIgnore_Ldarg_S); insts.Insert( loop1 - 1, new CodeInstruction(OpCodes.Ldloc_S, insts[loop1 - 1].operand), new CodeInstruction(OpCodes.Call, CanPlaceBlueprintAtPatch.ShouldIgnore1Method), new CodeInstruction(OpCodes.Brtrue, insts[loop1 + 1].operand) ); int loop2 = new CodeFinder(original, insts). Forward(OpCodes.Ldstr, "InteractionSpotBlocked"). Backward(OpCodes.Ldarg_S, thingToIgnore_Ldarg_S); insts.Insert( loop2 - 3, new CodeInstruction(OpCodes.Ldloc_S, insts[loop2 - 3].operand), new CodeInstruction(OpCodes.Ldloc_S, insts[loop2 - 2].operand), new CodeInstruction(OpCodes.Callvirt, SpawnBuildingAsPossiblePatch.ThingListGet), new CodeInstruction(OpCodes.Call, CanPlaceBlueprintAtPatch.ShouldIgnore1Method), new CodeInstruction(OpCodes.Brtrue, insts[loop2 + 1].operand) ); int loop3 = new CodeFinder(original, insts). Forward(OpCodes.Ldstr, "WouldBlockInteractionSpot"). Backward(OpCodes.Ldarg_S, thingToIgnore_Ldarg_S); insts.Insert( loop3 - 1, new CodeInstruction(OpCodes.Ldloc_S, insts[loop3 - 1].operand), new CodeInstruction(OpCodes.Call, CanPlaceBlueprintAtPatch.ShouldIgnore1Method), new CodeInstruction(OpCodes.Brtrue, insts[loop3 + 1].operand) ); return(insts); }
// Replace TradeDeal.get_AllTradeables with TradingWindow.AllTradeables static IEnumerable <CodeInstruction> Transpiler(IEnumerable <CodeInstruction> e, MethodBase original) { List <CodeInstruction> insts = new List <CodeInstruction>(e); CodeFinder finder = new CodeFinder(original, insts); for (int i = 0; i < 2; i++) { int getAllTradeables = finder.Forward(OpCodes.Callvirt, AccessTools.Method(typeof(TradeDeal), "get_AllTradeables")); insts.RemoveRange(getAllTradeables - 1, 2); insts.Insert(getAllTradeables - 1, new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(TradingWindow), nameof(TradingWindow.AllTradeables)))); } return(insts); }
static IEnumerable <CodeInstruction> Transpiler(IEnumerable <CodeInstruction> e, MethodBase original) { List <CodeInstruction> insts = (List <CodeInstruction>)e; int loop1 = new CodeFinder(original, insts). Forward(OpCodes.Ldstr, "IdenticalThingExists"). Backward(OpCodes.Ldarg_S, (byte)5); insts.Insert( loop1 - 1, new CodeInstruction(OpCodes.Ldloc_S, 5), new CodeInstruction(OpCodes.Call, CanPlaceBlueprintAtPatch.ShouldIgnore1Method), new CodeInstruction(OpCodes.Brtrue, insts[loop1 + 2].operand) ); int loop2 = new CodeFinder(original, insts). Forward(OpCodes.Ldstr, "InteractionSpotBlocked"). Backward(OpCodes.Ldarg_S, (byte)5); insts.Insert( loop2 - 3, new CodeInstruction(OpCodes.Ldloc_S, 8), new CodeInstruction(OpCodes.Ldloc_S, 9), new CodeInstruction(OpCodes.Callvirt, SpawnBuildingAsPossiblePatch.ThingListGet), new CodeInstruction(OpCodes.Call, CanPlaceBlueprintAtPatch.ShouldIgnore1Method), new CodeInstruction(OpCodes.Brtrue, insts[loop2 + 2].operand) ); int loop3 = new CodeFinder(original, insts). Forward(OpCodes.Ldstr, "WouldBlockInteractionSpot"). Backward(OpCodes.Ldarg_S, (byte)5); insts.Insert( loop3 - 1, new CodeInstruction(OpCodes.Ldloc_S, 14), new CodeInstruction(OpCodes.Call, CanPlaceBlueprintAtPatch.ShouldIgnore1Method), new CodeInstruction(OpCodes.Brtrue, insts[loop3 + 2].operand) ); return(insts); }
static IEnumerable <CodeInstruction> Transpiler(ILGenerator gen, IEnumerable <CodeInstruction> e, MethodBase original) { List <CodeInstruction> insts = (List <CodeInstruction>)e; Label label = gen.DefineLabel(); var finder = new CodeFinder(original, insts); int pos = finder.Forward(OpCodes.Stloc_S, 5); insts.Insert( pos + 1, new CodeInstruction(OpCodes.Ldloc_S, 5), new CodeInstruction(OpCodes.Call, CanPlaceBlueprintAtPatch.ShouldIgnore1Method), new CodeInstruction(OpCodes.Brtrue, label) ); int ret = finder.Start().Forward(OpCodes.Ret); insts[ret + 1].labels.Add(label); return(insts); }