Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of Farmland v1.2.3
Farmland.dll
Decompiled 3 days agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using ConditionalConfigSync; using HarmonyLib; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyTitle("Farmland")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Crystal")] [assembly: AssemblyProduct("Farmland")] [assembly: AssemblyCopyright("Copyright © 2026 Crystal Ferrai")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("af35011c-e111-4c38-9a7c-d50c6d83d322")] [assembly: AssemblyFileVersion("1.2.3.0")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyVersion("1.2.3.0")] namespace Farmland; [BepInPlugin("dev.crystal.farmland", "Farmland", "1.2.3.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInProcess("valheim.exe")] [BepInProcess("valheim_server.exe")] public class FarmlandPlugin : BaseUnityPlugin { [HarmonyPatch(typeof(Player))] private static class Player_Patches { [HarmonyPatch("UpdatePlacementGhost")] [HarmonyTranspiler] private static IEnumerable<CodeInstruction> UpdatePlacementGhost_Transpiler(IEnumerable<CodeInstruction> instructions) { bool found = false; foreach (CodeInstruction instruction in instructions) { if (instruction.opcode == OpCodes.Ldc_R4 && (float)instruction.operand == 0.25f) { if (found) { Debug.LogWarning((object)"[Farmland] Found multiple possible candidates for vegetation threshold in Player.UpdatePlacementGhost. Mod may need to be updated."); } found = true; yield return new CodeInstruction(OpCodes.Ldc_R4, (object)VegetationThreshold.Value); } else { yield return instruction; } } } } [HarmonyPatch(typeof(TerrainComp))] private static class TerrainComp_Patches { private enum TranspilerState { Searching, Updating, Labeling, Finishing } [HarmonyPatch("PaintCleared")] [HarmonyTranspiler] private static IEnumerable<CodeInstruction> PaintCleared_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator) { Label label1 = generator.DefineLabel(); MethodInfo findHeightMap = typeof(Heightmap).GetMethod("FindHeightmap", BindingFlags.Static | BindingFlags.Public, null, new Type[1] { typeof(Vector3) }, null); MethodInfo getBiome = typeof(Heightmap).GetMethod("GetBiome", BindingFlags.Instance | BindingFlags.Public); FieldInfo paintTypeField = typeof(Settings).GetField("m_paintType"); LocalBuilder isAshlands = generator.DeclareLocal(typeof(bool)); isAshlands.SetLocalSymInfo("isAshlands"); yield return new CodeInstruction(OpCodes.Ldarg_1, (object)null); yield return new CodeInstruction(OpCodes.Call, (object)findHeightMap); yield return new CodeInstruction(OpCodes.Ldarg_1, (object)null); yield return new CodeInstruction(OpCodes.Ldc_R4, (object)0.02f); yield return new CodeInstruction(OpCodes.Ldc_I4_0, (object)null); yield return new CodeInstruction(OpCodes.Callvirt, (object)getBiome); yield return new CodeInstruction(OpCodes.Ldc_I4_S, (object)32); yield return new CodeInstruction(OpCodes.Ceq, (object)null); yield return new CodeInstruction(OpCodes.Stloc, (object)isAshlands.LocalIndex); TranspilerState state = TranspilerState.Searching; foreach (CodeInstruction instruction in instructions) { switch (state) { case TranspilerState.Searching: if (instruction.opcode == OpCodes.Ldfld && (FieldInfo)instruction.operand == typeof(Color).GetField("a")) { state = TranspilerState.Updating; } yield return instruction; break; case TranspilerState.Updating: if (instruction.opcode == OpCodes.Stloc_S) { yield return instruction; yield return new CodeInstruction(OpCodes.Ldloc, (object)isAshlands.LocalIndex); yield return new CodeInstruction(OpCodes.Brtrue, (object)label1); yield return new CodeInstruction(OpCodes.Ldloc_S, instruction.operand); yield return new CodeInstruction(OpCodes.Ldc_R4, (object)0.25f); yield return new CodeInstruction(OpCodes.Bge_Un_S, (object)label1); yield return new CodeInstruction(OpCodes.Ldarg_3, (object)null); yield return new CodeInstruction(OpCodes.Ldfld, (object)paintTypeField); yield return new CodeInstruction(OpCodes.Ldc_I4_1, (object)null); yield return new CodeInstruction(OpCodes.Bne_Un_S, (object)label1); yield return new CodeInstruction(OpCodes.Ldc_R4, (object)0.25f); yield return new CodeInstruction(OpCodes.Stloc_S, instruction.operand); state = TranspilerState.Labeling; } else { yield return instruction; state = TranspilerState.Searching; } break; case TranspilerState.Labeling: instruction.labels.Add(label1); yield return instruction; state = TranspilerState.Finishing; break; case TranspilerState.Finishing: yield return instruction; break; } } if (state != TranspilerState.Finishing) { throw new InvalidOperationException("[Farmland] Unable to patch code. This may be due to a game update that the mod has not yet updated for. Details: Invalid patch state"); } } } public const string ModId = "dev.crystal.farmland"; public const string ModName = "Farmland"; public const string ModVersion = "1.2.3.0"; internal static readonly ConfigSync ConfigSync = new ConfigSync("dev.crystal.farmland") { DisplayName = "Farmland", CurrentVersion = "1.2.3.0", MinimumRequiredVersion = "1.2.3.0", ModRequired = true, ModRequirementMode = (ModRequirementMode)1 }; public static ConfigEntry<float> VegetationThreshold; private static Harmony sPlayerHarmony; private static Harmony sTerrainCompHarmony; private void Awake() { //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Expected O, but got Unknown //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Expected O, but got Unknown VegetationThreshold = ((BaseUnityPlugin)this).Config.Bind<float>("Land", "VegetationThreshold", 0f, "The amount of vegetation land must support to allow cultivation. Lower values provide more farmable land. Range 0.0 to 1.0. Game default 0.25. Mod default 0.0. [The value will be enforced on a server.]"); VegetationThreshold.SettingChanged += VegetationThreshold_SettingChanged; ((ConditionalConfigSync)ConfigSync).AddConfigEntry<float>(VegetationThreshold, (ConfigSyncMode)0); ClampConfig(); sPlayerHarmony = new Harmony("dev.crystal.farmland_Player"); sPlayerHarmony.PatchAll(typeof(Player_Patches)); sTerrainCompHarmony = new Harmony("dev.crystal.farmland_TerrainComp"); sTerrainCompHarmony.PatchAll(typeof(TerrainComp_Patches)); } private void OnDestroy() { sPlayerHarmony.UnpatchSelf(); sTerrainCompHarmony.UnpatchSelf(); } private static void ClampConfig() { if (VegetationThreshold.Value < 0f) { VegetationThreshold.Value = 0f; } if (VegetationThreshold.Value > 1f) { VegetationThreshold.Value = 1f; } } private void VegetationThreshold_SettingChanged(object sender, EventArgs e) { ClampConfig(); sPlayerHarmony.UnpatchSelf(); sPlayerHarmony.PatchAll(typeof(Player_Patches)); } }