// Support harvesting of spring onions with scythe private void Crop_harvest_support_spring_onion(LocalBuilder var_vector) { if (config.HarvestMode.SpringOnion == HarvestModeEnum.HAND) { return; } // Note: the branch // if (this.forageCrop) // refers mainly to the crop spring union. InstructionMatcher addItemToInventoryBool = Instructions.Callvirt(typeof(Farmer), nameof(Farmer.addItemToInventoryBool), typeof(Item), typeof(bool)); if (helper.ModRegistry.IsLoaded("spacechase0.MoreRings")) { try { addItemToInventoryBool = InstructionMatcher.AnyOf( addItemToInventoryBool, Instructions.Callvirt(AccessTools.TypeByName("MoreRings.Patches.CropPatcher"), "Farmer_AddItemToInventoryBool", typeof(Farmer), typeof(Item), typeof(bool)) ); } catch (Exception e) { Monitor.Log("The More Rings mod was loaded, but MoreRings.Patches.CropPatcher.Farmer_AddItemToInventoryBool(...) was not found."); LogException(e, LogLevel.Warn); } } // Find the lines: InstructionRange AddItem; AddItem = FindCode( // if (Game1.player.addItemToInventoryBool (@object, false)) { Instructions.Call_get(typeof(Game1), nameof(Game1.player)), InstructionMatcher.AnyOf( // @object OpCodes.Ldloc_0, OpCodes.Ldloc_1 ), OpCodes.Ldc_I4_0, addItemToInventoryBool, OpCodes.Brfalse ); var ldarg_0 = Instructions.Ldarg_0(); var Ldloc_object = AddItem[1]; var tail = AttachLabel(AddItem.FindNext( OpCodes.Ldarg_0, Instructions.Ldfld(typeof(Crop), nameof(Crop.regrowAfterHarvest)) )[0]); // Insert check for harvesting with scythe and act accordingly. AddItem.ReplaceJump(0, ldarg_0); AddItem.Prepend( // if (this.harvestMethod != 0) { ldarg_0, Instructions.Ldfld(typeof(Crop), nameof(Crop.harvestMethod)), Instructions.Call_get(typeof(NetInt), nameof(NetInt.Value)), Instructions.Brfalse(AttachLabel(AddItem[0])), // Game1.createItemDebris (@object, vector, -1, null, -1) Ldloc_object, // @object Instructions.Ldloc_S(var_vector), // vector Instructions.Ldc_I4_M1(), // -1 Instructions.Ldnull(), // null Instructions.Ldc_I4_M1(), // -1 Instructions.Call(typeof(Game1), nameof(Game1.createItemDebris), typeof(Item), typeof(Vector2), typeof(int), typeof(GameLocation), typeof(int)), Instructions.Pop(), // For SDV 1.4 // Jump to tail Instructions.Br(tail) ); }