using HarmonyLib; using System.Collections.Generic; using System.Linq; using System.Reflection.Emit; using System.Text; using Vintagestory.API.Config; using Vintagestory.GameContent; using Vintagestory.API.Common; namespace SteadyGreenHouses.ModPatches { [HarmonyPatch] internal class Farmland : ModSystem { [HarmonyTranspiler] [HarmonyPatch(typeof(BlockEntityFarmland), "Update")] static IEnumerable Transpiler(IEnumerable instructions) { var codes = new List(instructions); for (int i = 0; i < codes.Count; i++) { // Locate the sequence: conds.Temperature += 5 if (codes[i].opcode == OpCodes.Ldfld && codes[i + 1].opcode == OpCodes.Ldc_R4 && (float)codes[i + 1].operand == 5f && codes[i + 2].opcode == OpCodes.Add) { // Replace it with conds.Temperature = 20f; codes[i + 1].operand = 20f; codes[i + 2].opcode = OpCodes.Nop; } } return codes.AsEnumerable(); } //WORKS [HarmonyPostfix] [HarmonyPatch(typeof(BlockEntityFarmland), "GetBlockInfo")] static void Postfix(StringBuilder dsc) { // Replace the '5' in the greenhouse temp bonus string string originalString = Lang.Get("greenhousetempbonus"); string modifiedString = originalString.Replace("5", "X"); // Modify the description if (dsc.ToString().Contains(originalString)) { dsc.Replace(originalString, modifiedString); } } } }