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 VargheimFarming v1.1.2
VargheimFarming.dll
Decompiled 11 hours agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using Microsoft.CodeAnalysis; using UnityEngine; using VargheimProfessions; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyVersion("0.0.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace VargheimFarming { [BepInPlugin("digi.vargheim.farming", "VargheimFarming", "1.1.2")] [BepInDependency("digi.vargheim.professions", "0.4.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class Plugin : BaseUnityPlugin { [HarmonyPatch] internal static class Patches { [HarmonyPatch(typeof(Piece), "SetCreator")] [HarmonyPostfix] private static void Planted(Piece __instance) { //IL_0044: Unknown result type (might be due to invalid IL or missing references) try { if ((Object)(object)((Component)__instance).GetComponent<Plant>() == (Object)null) { return; } ZDO val = Zdo((Component)(object)__instance); if (val != null) { if (Api.HasPerk("Farming", HardyLevel.Value)) { val.Set("vp_hardy", true); } if (NearTotem(((Component)__instance).transform.position)) { val.Set("vp_fertile", true); } } } catch { } } [HarmonyPatch(typeof(Plant), "Grow")] [HarmonyPostfix] private static void Grown(Plant __instance, GameObject __result) { try { ZDO val = Zdo((Component)(object)__instance); ZDO val2 = (((Object)(object)__result != (Object)null) ? Zdo((Component)(object)__result.transform) : null); if (val != null && val2 != null && val.GetBool("vp_hardy", false)) { val2.Set("vp_hardy", true); } } catch { } } [HarmonyPatch(typeof(Plant), "GetGrowTime")] [HarmonyPostfix] private static void GrowTime(Plant __instance, ref float __result) { try { ZDO val = Zdo((Component)(object)__instance); if (val != null && val.GetBool("vp_fertile", false)) { __result *= 1f - FertileSpeed.Value; } } catch { } } [HarmonyPatch(typeof(Plant), "UpdateHealth")] [HarmonyPostfix] private static void Health(Plant __instance, ref Status ___m_status) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) try { if (((int)___m_status == 3 || (int)___m_status == 7 || (int)___m_status == 6) && InGreenhouse(((Component)__instance).transform.position)) { ___m_status = (Status)0; } } catch { } } [HarmonyPatch(typeof(Player), "UpdatePlacementGhost")] [HarmonyPostfix] private static void Ghost(Player __instance, ref PlacementStatus ___m_placementStatus, GameObject ___m_placementGhost) { //IL_0022: Unknown result type (might be due to invalid IL or missing references) try { if ((int)___m_placementStatus == 8 && (Object)(object)___m_placementGhost != (Object)null && (Object)(object)___m_placementGhost.GetComponent<Plant>() != (Object)null && InGreenhouse(___m_placementGhost.transform.position)) { ___m_placementStatus = (PlacementStatus)0; Traverse.Create((object)__instance).Method("SetPlacementGhostValid", new Type[1] { typeof(bool) }, (object[])null).GetValue(new object[1] { true }); } } catch { } } [HarmonyPatch(typeof(Pickable), "Interact")] [HarmonyPostfix] private static void Picked(Pickable __instance, Humanoid character, bool __result) { try { Player val = (Player)(object)((character is Player) ? character : null); if (__result && (Object)(object)val != (Object)null && (Object)(object)val == (Object)(object)Player.m_localPlayer) { AfterPick(__instance, val); } } catch { } } } public const string Guid = "digi.vargheim.farming"; public const string Version = "1.1.2"; internal const string Produce = "VP_FarmProduce"; internal static ConfigEntry<int> ProduceLevel; internal static ConfigEntry<int> ProduceAmount; internal static ConfigEntry<string> ProduceRecipe; private const string Prof = "Farming"; internal const string Totem = "VP_FertilityTotem"; internal const string Lamp = "VP_GrowLamp"; internal static ConfigEntry<int> WildLevel; internal static ConfigEntry<int> HardyLevel; internal static ConfigEntry<int> SeedLevel; internal static ConfigEntry<int> FertileLevel; internal static ConfigEntry<int> GreenLevel; internal static ConfigEntry<float> WildRange; internal static ConfigEntry<float> CropSeedChance; internal static ConfigEntry<float> WildSeedChance; internal static ConfigEntry<float> FertileRange; internal static ConfigEntry<float> FertileSpeed; internal static ConfigEntry<float> GreenRange; internal static ConfigEntry<string> WildItems; internal static ConfigEntry<string> WildSeeds; internal static ConfigEntry<string> TotemRecipe; internal static ConfigEntry<string> LampRecipe; internal static HashSet<string> WildSet = new HashSet<string>(StringComparer.Ordinal); internal static Plugin Instance; private static readonly List<Vector3> s_lamps = new List<Vector3>(); private static readonly List<Vector3> s_totems = new List<Vector3>(); private static float s_nextScan; private static Dictionary<string, string> s_cropSeed; private static bool s_massPicking; private void Awake() { //IL_0415: Unknown result type (might be due to invalid IL or missing references) //IL_041b: Expected O, but got Unknown //IL_044d: Unknown result type (might be due to invalid IL or missing references) //IL_0453: Expected O, but got Unknown //IL_0461: Unknown result type (might be due to invalid IL or missing references) //IL_0467: Expected O, but got Unknown //IL_047d: Unknown result type (might be due to invalid IL or missing references) //IL_0483: Expected O, but got Unknown //IL_0491: Unknown result type (might be due to invalid IL or missing references) //IL_0497: Expected O, but got Unknown //IL_04f1: Unknown result type (might be due to invalid IL or missing references) //IL_04f7: Expected O, but got Unknown //IL_0560: Unknown result type (might be due to invalid IL or missing references) //IL_0566: Expected O, but got Unknown //IL_0598: Unknown result type (might be due to invalid IL or missing references) //IL_059e: Expected O, but got Unknown //IL_05a8: Unknown result type (might be due to invalid IL or missing references) //IL_05ae: Expected O, but got Unknown Instance = this; WildLevel = ((BaseUnityPlugin)this).Config.Bind<int>("Perks", "WildHarvestLevel", 35, "Wild harvest level."); WildRange = ((BaseUnityPlugin)this).Config.Bind<float>("Perks", "WildHarvestRange", 5f, "Wild harvest: picking one wild plant picks all of the same kind within this range."); WildItems = ((BaseUnityPlugin)this).Config.Bind<string>("Perks", "WildHarvestItems", "Raspberry,Blueberries,Cloudberry,Mushroom,MushroomYellow,MushroomBlue,Thistle,Dandelion,MushroomJotunPuffs,MushroomMagecap,Fiddleheadfern,MushroomSmokePuff,Vineberry", "Items that count as wild plants."); ProduceLevel = ((BaseUnityPlugin)this).Config.Bind<int>("Perks", "FarmProduceLevel", 35, "Farm produce: level to make Farm Produce, which cooks need for modded dishes."); ProduceRecipe = ((BaseUnityPlugin)this).Config.Bind<string>("Perks", "FarmProduceRecipe", "Carrot:3,Raspberry:4,Dandelion:2", "Materials for Farm Produce (at a workbench)."); ProduceAmount = ((BaseUnityPlugin)this).Config.Bind<int>("Perks", "FarmProduceAmount", 4, "Farm Produce per craft."); Content.AddItem("Carrot", "VP_FarmProduce", "Farm Produce", "A basket of fresh-picked farm vegetables. Cooks need it for modded dishes. Only a farmer can put it together.", (Action<SharedData>)delegate(SharedData s) { //IL_0020: Unknown result type (might be due to invalid IL or missing references) s.m_weight = 0.5f; s.m_maxStackSize = 50; s.m_food = 0f; s.m_itemType = (ItemType)1; }); Content.AddRecipe("VP_FarmProduce", "piece_workbench", 1, Math.Max(1, ProduceAmount.Value), ProduceRecipe.Value, "Farming", ProduceLevel.Value); HardyLevel = ((BaseUnityPlugin)this).Config.Bind<int>("Perks", "HardyCropsLevel", 40, "Hardy crops: crops a farmer of this level plants survive winter."); SeedLevel = ((BaseUnityPlugin)this).Config.Bind<int>("Perks", "SeedSaverLevel", 60, "Seed saver level."); CropSeedChance = ((BaseUnityPlugin)this).Config.Bind<float>("Perks", "SeedSaverCropChance", 0.2f, "Seed saver: chance of an extra seed when harvesting a crop."); WildSeedChance = ((BaseUnityPlugin)this).Config.Bind<float>("Perks", "SeedSaverWildChance", 0.15f, "Seed saver: chance of a seed when picking a wild plant."); WildSeeds = ((BaseUnityPlugin)this).Config.Bind<string>("Perks", "SeedSaverWildSeeds", "CarrotSeeds,TurnipSeeds,OnionSeeds", "Seeds found on wild plants (one at random)."); FertileLevel = ((BaseUnityPlugin)this).Config.Bind<int>("Perks", "FertileSoilLevel", 75, "Fertile soil: level to build a Fertility Totem."); FertileRange = ((BaseUnityPlugin)this).Config.Bind<float>("Perks", "FertileSoilRange", 15f, "Fertile soil: crops planted within this range of a Fertility Totem grow faster."); FertileSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("Perks", "FertileSoilSpeedup", 0.2f, "Fertile soil: grow this much faster."); TotemRecipe = ((BaseUnityPlugin)this).Config.Bind<string>("Perks", "FertilityTotemRecipe", "FineWood:6,Honey:5,Resin:5", "Materials for a Fertility Totem."); GreenLevel = ((BaseUnityPlugin)this).Config.Bind<int>("Perks", "GreenhouseLevel", 100, "Greenhouse: level to build a Grow Lamp."); GreenRange = ((BaseUnityPlugin)this).Config.Bind<float>("Perks", "GreenhouseRange", 12f, "Greenhouse: anything planted within this range of a Grow Lamp ignores seasons and biome rules."); LampRecipe = ((BaseUnityPlugin)this).Config.Bind<string>("Perks", "GrowLampRecipe", "FineWood:10,Crystal:4,SurtlingCore:2", "Materials for a Grow Lamp."); WildSet = new HashSet<string>(WildItems.Value.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries), StringComparer.Ordinal); Content.AddPiece("piece_banner01", "VP_FertilityTotem", "Fertility Totem", "Crops anyone plants within " + FertileRange.Value + " m grow " + Mathf.RoundToInt(FertileSpeed.Value * 100f) + "% faster.", "Hammer", TotemRecipe.Value, "Farming", FertileLevel.Value, (Action<GameObject>)null); Content.AddPiece("piece_groundtorch_green", "VP_GrowLamp", "Grow Lamp", "The heart of a greenhouse. Anything planted within " + GreenRange.Value + " m ignores seasons and biome rules.", "Hammer", LampRecipe.Value, "Farming", GreenLevel.Value, (Action<GameObject>)null); Api.RegisterLadder("Farming", "VargheimFarming 1.1.2", "Modded crops (RtDOcean, CookingAdditions, PlantEverything) are planted by farmers, by tier. Smoothbrain Farming: up to x3 grow speed and x2 yield at 100. Mass planting is a farmer perk; everyone else plants one at a time.", (Perk[])(object)new Perk[8] { new Perk(25, "Rows", "Plant and harvest in rows (Smoothbrain Farming)."), new Perk(WildLevel.Value, "Wild harvest", "Picking a wild berry, mushroom or thistle picks every one of that kind within " + WildRange.Value + " m."), new Perk(10, "Tier produce", "Make the Farmer's tier material at a workbench, one per biome from that biome's crops (Farm Produce at 10, Thistle Bundle at 25, Turnip Mash at 35 ...). Cooks need it for every modded dish of that tier, Mystics for magic gear."), new Perk(HardyLevel.Value, "Hardy crops", "Crops you plant survive winter."), new Perk(50, "Any biome", "Plant crops outside their home biome (Smoothbrain Farming)."), new Perk(SeedLevel.Value, "Seed saver", Mathf.RoundToInt(CropSeedChance.Value * 100f) + "% chance of an extra seed when harvesting crops; " + Mathf.RoundToInt(WildSeedChance.Value * 100f) + "% chance of carrot, turnip or onion seeds from wild plants."), new Perk(FertileLevel.Value, "Fertile soil", "Build a Fertility Totem: crops anyone plants within " + FertileRange.Value + " m grow " + Mathf.RoundToInt(FertileSpeed.Value * 100f) + "% faster."), new Perk(GreenLevel.Value, "Greenhouse", "Build a Grow Lamp: anything planted within " + GreenRange.Value + " m ignores seasons and biome rules, for anyone.") }); Harmony val = new Harmony("digi.vargheim.farming"); val.PatchAll(typeof(Patches)); try { PatchSeasons(val); } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("Seasons hooks skipped: " + ex.Message)); } ((BaseUnityPlugin)this).Logger.LogInfo((object)"VargheimFarming 1.1.2 loaded."); } internal static string PrefabName(GameObject go) { string name = ((Object)go).name; int num = name.IndexOf("(Clone)", StringComparison.Ordinal); return ((num >= 0) ? name.Substring(0, num) : name).Trim(); } internal static ZDO Zdo(Component c) { ZNetView val = (((Object)(object)c != (Object)null) ? c.GetComponent<ZNetView>() : null); if (!((Object)(object)val != (Object)null) || !val.IsValid()) { return null; } return val.GetZDO(); } private static void Scan() { //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Unknown result type (might be due to invalid IL or missing references) if (Time.time < s_nextScan) { return; } s_nextScan = Time.time + 5f; s_lamps.Clear(); s_totems.Clear(); foreach (WearNTear allInstance in WearNTear.GetAllInstances()) { if (!((Object)(object)allInstance == (Object)null)) { string name = ((Object)((Component)allInstance).gameObject).name; if (name.StartsWith("VP_GrowLamp", StringComparison.Ordinal)) { s_lamps.Add(((Component)allInstance).transform.position); } else if (name.StartsWith("VP_FertilityTotem", StringComparison.Ordinal)) { s_totems.Add(((Component)allInstance).transform.position); } } } } internal static bool InGreenhouse(Vector3 pos) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) Scan(); foreach (Vector3 s_lamp in s_lamps) { if (Vector3.Distance(s_lamp, pos) <= GreenRange.Value) { return true; } } return false; } internal static bool NearTotem(Vector3 pos) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) Scan(); foreach (Vector3 s_totem in s_totems) { if (Vector3.Distance(s_totem, pos) <= FertileRange.Value) { return true; } } return false; } internal static Dictionary<string, string> CropSeeds() { if (s_cropSeed != null || (Object)(object)ObjectDB.instance == (Object)null) { return s_cropSeed ?? new Dictionary<string, string>(); } s_cropSeed = new Dictionary<string, string>(StringComparer.Ordinal); foreach (GameObject item in ObjectDB.instance.m_items) { ItemDrop val = (((Object)(object)item != (Object)null) ? item.GetComponent<ItemDrop>() : null); PieceTable val2 = (((Object)(object)val != (Object)null) ? val.m_itemData.m_shared.m_buildPieces : null); if ((Object)(object)val2 == (Object)null) { continue; } foreach (GameObject piece in val2.m_pieces) { Plant val3 = (((Object)(object)piece != (Object)null) ? piece.GetComponent<Plant>() : null); Piece val4 = (((Object)(object)piece != (Object)null) ? piece.GetComponent<Piece>() : null); if ((Object)(object)val3 == (Object)null || (Object)(object)val4 == (Object)null || val4.m_resources == null || val4.m_resources.Length == 0 || (Object)(object)val4.m_resources[0].m_resItem == (Object)null || val3.m_grownPrefabs == null) { continue; } GameObject[] grownPrefabs = val3.m_grownPrefabs; foreach (GameObject val5 in grownPrefabs) { if ((Object)(object)val5 != (Object)null && (Object)(object)val5.GetComponent<Pickable>() != (Object)null) { s_cropSeed[((Object)val5).name] = ((Object)((Component)val4.m_resources[0].m_resItem).gameObject).name; } } } } return s_cropSeed; } private static void Spawn(string item, Vector3 pos) { //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) GameObject val = (((Object)(object)ObjectDB.instance != (Object)null) ? ObjectDB.instance.GetItemPrefab(item) : null); if ((Object)(object)val != (Object)null) { Object.Instantiate<GameObject>(val, pos + Vector3.up * 0.6f, Quaternion.identity); } } internal static void AfterPick(Pickable pk, Player p) { //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0124: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_01b8: Unknown result type (might be due to invalid IL or missing references) //IL_01c3: Unknown result type (might be due to invalid IL or missing references) string key = PrefabName(((Component)pk).gameObject); string text = (((Object)(object)pk.m_itemPrefab != (Object)null) ? ((Object)pk.m_itemPrefab).name : ""); string value; bool flag = CropSeeds().TryGetValue(key, out value); bool flag2 = !flag && WildSet.Contains(text); if (Api.HasPerk("Farming", SeedLevel.Value)) { if (flag && Random.value < CropSeedChance.Value) { Spawn(value, ((Component)pk).transform.position); } else if (flag2 && Random.value < WildSeedChance.Value) { string[] array = WildSeeds.Value.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries); if (array.Length != 0) { Spawn(array[Random.Range(0, array.Length)].Trim(), ((Component)pk).transform.position); } } } if (!flag2 || s_massPicking || !Api.HasPerk("Farming", WildLevel.Value)) { return; } s_massPicking = true; try { HashSet<int> hashSet = new HashSet<int>(); Collider[] array2 = Physics.OverlapSphere(((Component)pk).transform.position, WildRange.Value, -1, (QueryTriggerInteraction)2); foreach (Collider val in array2) { Pickable val2 = (((Object)(object)val != (Object)null) ? ((Component)val).GetComponentInParent<Pickable>() : null); if (!((Object)(object)val2 == (Object)null) && hashSet.Add(((Object)val2).GetInstanceID()) && !((Object)(object)val2 == (Object)(object)pk) && !((Object)(object)val2.m_itemPrefab == (Object)null) && !(((Object)val2.m_itemPrefab).name != text) && val2.CanBePicked() && !(Vector3.Distance(((Component)val2).transform.position, ((Component)pk).transform.position) > WildRange.Value)) { val2.Interact((Humanoid)(object)p, false, false); } } } finally { s_massPicking = false; } } private static void PatchSeasons(Harmony h) { //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Expected O, but got Unknown //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Expected O, but got Unknown //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Expected O, but got Unknown Type type = AccessTools.TypeByName("Seasons.ControlledComponentsExtentions"); if (!(type == null)) { MethodInfo methodInfo = AccessTools.Method(type, "ShouldSurviveWinter", (Type[])null, (Type[])null); MethodInfo methodInfo2 = AccessTools.Method(type, "ControlPlantGrowth", (Type[])null, (Type[])null); MethodInfo methodInfo3 = AccessTools.Method(type, "IsIgnored", (Type[])null, (Type[])null); if (methodInfo != null) { h.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(Plugin), "SurvivePostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } if (methodInfo2 != null) { h.Patch((MethodBase)methodInfo2, (HarmonyMethod)null, new HarmonyMethod(typeof(Plugin), "ControlPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } if (methodInfo3 != null) { h.Patch((MethodBase)methodInfo3, (HarmonyMethod)null, new HarmonyMethod(typeof(Plugin), "IgnoredPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } ((BaseUnityPlugin)Instance).Logger.LogInfo((object)("Seasons found: hardy crops / greenhouse hooks " + (methodInfo != null) + "/" + (methodInfo2 != null) + "/" + (methodInfo3 != null) + ".")); } } private static void SurvivePostfix(MonoBehaviour behaviour, ref bool __result) { //IL_002d: Unknown result type (might be due to invalid IL or missing references) try { if (!__result && !((Object)(object)behaviour == (Object)null)) { ZDO val = Zdo((Component)(object)behaviour); if ((val != null && val.GetBool("vp_hardy", false)) || InGreenhouse(((Component)behaviour).transform.position)) { __result = true; } } } catch { } } private static void ControlPostfix(MonoBehaviour behaviour, ref bool __result) { //IL_0013: Unknown result type (might be due to invalid IL or missing references) try { if (__result && (Object)(object)behaviour != (Object)null && InGreenhouse(((Component)behaviour).transform.position)) { __result = false; } } catch { } } private static void IgnoredPostfix(Pickable pickable, ref bool __result) { //IL_0013: Unknown result type (might be due to invalid IL or missing references) try { if (!__result && (Object)(object)pickable != (Object)null && InGreenhouse(((Component)pickable).transform.position)) { __result = true; } } catch { } } } }