Decompiled source of Lareins SmartFarm v1.0.0

plugins\Lareins_SmartFarm\Lareins_SmartFarm.dll

Decompiled 2 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Lareins_Core;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("Lareins_SmartFarm")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Lareins_SmartFarm")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("f4625933-b1e0-4f13-851b-2e159a6cea10")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Lareins_SmartFarm;

[BepInPlugin("com.lareins.smartfarm", "Lareins_SmartFarm", "1.4.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class SmartFarmPlugin : BaseUnityPlugin
{
	public const string ModGUID = "com.lareins.smartfarm";

	public const string ModName = "Lareins_SmartFarm";

	public const string ModVersion = "1.4.0";

	public static ConfigEntry<bool> ModAktif;

	public static ConfigEntry<bool> YabaniBitkiEkimiAktif;

	public static ConfigEntry<int> IzgaraBoyutu;

	public static ConfigEntry<int> HasatMenzili;

	public static ConfigEntry<int> HasatMiktari;

	public static ConfigEntry<int> YetismeSuresiDakika;

	private static readonly Dictionary<string, string> YabaniBitkiHaritasi = new Dictionary<string, string>
	{
		{ "Raspberry", "RaspberryBush" },
		{ "Blueberries", "BlueberryBush" },
		{ "Cloudberry", "CloudberryBush" },
		{ "Mushroom", "Pickable_Mushroom" },
		{ "MushroomYellow", "Pickable_Mushroom_yellow" },
		{ "MushroomBlue", "Pickable_Mushroom_blue" },
		{ "Dandelion", "Pickable_Dandelion" },
		{ "Thistle", "Pickable_Thistle" },
		{ "MushroomJotunPuffs", "Pickable_Mushroom_JotunPuffs" },
		{ "MushroomMagecap", "Pickable_Mushroom_Magecap" },
		{ "SmokePuff", "Pickable_SmokePuff" },
		{ "Fiddleheadfern", "Pickable_Fiddlehead" },
		{ "Carrot", "Pickable_Carrot" },
		{ "Turnip", "Pickable_Turnip" },
		{ "Onion", "Pickable_Onion" }
	};

	private static GameObject prefabHavuzu;

	private static readonly Dictionary<string, GameObject> olusturulanPrefablar = new Dictionary<string, GameObject>();

	private static bool topluEkimCalisiyor = false;

	private static bool topluHasatCalisiyor = false;

	private static readonly List<GameObject> sablonNoktalari = new List<GameObject>();

	private static Material sablonMateryal;

	private void Awake()
	{
		//IL_0152: Unknown result type (might be due to invalid IL or missing references)
		ModAktif = ((BaseUnityPlugin)this).Config.Bind<bool>("Genel", "ModAktif", true, "Izgara ekim, toplu hasat ve yabani bitki ekimini acar");
		YabaniBitkiEkimiAktif = ((BaseUnityPlugin)this).Config.Bind<bool>("Genel", "YabaniBitkiEkimiAktif", true, "Ahududu, yaban mersini, mantar vb. bitkilerin ekilmesini saglar");
		IzgaraBoyutu = ((BaseUnityPlugin)this).Config.Bind<int>("Ayarlar", "IzgaraBoyutu", 5, "Toplu ekim izgara boyutu (2 = 2x2 ... 10 = 10x10)");
		HasatMenzili = ((BaseUnityPlugin)this).Config.Bind<int>("Ayarlar", "HasatMenzili", 8, "Sol Shift + E ile toplu hasat yaricapi (3m - 20m)");
		HasatMiktari = ((BaseUnityPlugin)this).Config.Bind<int>("Ayarlar", "HasatMiktari", 3, "Ekilen yabani bitkilerden tek hasatta alinacak urun adedi (1 - 10)");
		YetismeSuresiDakika = ((BaseUnityPlugin)this).Config.Bind<int>("Ayarlar", "YetismeSuresiDakika", 45, "Ekilen yabani bitkilerin yetisme ve yenilenme suresi (dakika)");
		CorePlugin.AyarEkle("Akilli Ciftlik", "Mod Aktif", "Izgara ekim ve toplu hasat sistemini acar.", ModAktif);
		CorePlugin.AyarEkle("Akilli Ciftlik", "Yabani Bitki Ekimi", "Ahududu, yaban mersini, mantar vb. bitkileri ekmeyi acar.", YabaniBitkiEkimiAktif);
		CorePlugin.AyarEkle("Akilli Ciftlik", "Izgara Boyutu (2x2 - 10x10)", "Sol Shift ile toplu ekim boyutu (2 ile 10 arasi).", IzgaraBoyutu, 2, 10);
		CorePlugin.AyarEkle("Akilli Ciftlik", "Toplu Hasat Menzili (m)", "Sol Shift + E ile hasat edilecek alan yaricapi.", HasatMenzili, 3, 20);
		CorePlugin.AyarEkle("Akilli Ciftlik", "Hasat Miktari", "1 ekilen yabani bitkiden kac adet hasat edilecegi.", HasatMiktari, 1, 10);
		new Harmony("com.lareins.smartfarm").PatchAll(typeof(SmartFarmPlugin));
	}

	[HarmonyPatch(typeof(ZNetScene), "Awake")]
	[HarmonyPostfix]
	private static void SahneAcilisindaTarifEkle()
	{
		if (ModAktif.Value && YabaniBitkiEkimiAktif.Value)
		{
			YabaniBitkiTarifleriniYukle();
		}
	}

	[HarmonyPatch(typeof(Player), "SetLocalPlayer")]
	[HarmonyPostfix]
	private static void OyuncuYukleninceTarifEkle(Player __instance)
	{
		if (ModAktif.Value && YabaniBitkiEkimiAktif.Value)
		{
			YabaniBitkiTarifleriniYukle();
			if ((Object)(object)__instance != (Object)null)
			{
				Traverse.Create((object)__instance).Method("UpdateKnownRecipesList", Array.Empty<object>()).GetValue();
			}
		}
	}

	private static void YabaniBitkiTarifleriniYukle()
	{
		//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d3: Expected O, but got Unknown
		//IL_013c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0141: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fe: Expected O, but got Unknown
		if ((Object)(object)ObjectDB.instance == (Object)null || (Object)(object)ZNetScene.instance == (Object)null)
		{
			return;
		}
		GameObject itemPrefab = ObjectDB.instance.GetItemPrefab("Cultivator");
		if ((Object)(object)itemPrefab == (Object)null)
		{
			return;
		}
		PieceTable val = itemPrefab.GetComponent<ItemDrop>()?.m_itemData?.m_shared?.m_buildPieces;
		if ((Object)(object)val == (Object)null)
		{
			return;
		}
		val.m_pieces.RemoveAll((GameObject p) => (Object)(object)p == (Object)null);
		if ((Object)(object)prefabHavuzu == (Object)null)
		{
			prefabHavuzu = new GameObject("Lareins_SmartFarm_PrefabPool");
			prefabHavuzu.SetActive(false);
			((Object)prefabHavuzu).hideFlags = (HideFlags)61;
			Object.DontDestroyOnLoad((Object)(object)prefabHavuzu);
		}
		GameObject? obj = ((IEnumerable<GameObject>)val.m_pieces).FirstOrDefault((Func<GameObject, bool>)((GameObject p) => (Object)(object)p != (Object)null));
		Piece val2 = ((obj != null) ? obj.GetComponent<Piece>() : null);
		PieceCategory category = (PieceCategory)(((Object)(object)val2 != (Object)null) ? ((int)val2.m_category) : 0);
		Dictionary<int, GameObject> value = Traverse.Create((object)ZNetScene.instance).Field("m_namedPrefabs").GetValue<Dictionary<int, GameObject>>();
		foreach (KeyValuePair<string, string> item in YabaniBitkiHaritasi)
		{
			string key = item.Key;
			string value2 = item.Value;
			string text = "Lareins_Plant_" + key;
			GameObject itemPrefab2 = ObjectDB.instance.GetItemPrefab(key);
			GameObject prefab = ZNetScene.instance.GetPrefab(value2);
			if ((Object)(object)itemPrefab2 == (Object)null || (Object)(object)prefab == (Object)null)
			{
				continue;
			}
			if (!olusturulanPrefablar.TryGetValue(text, out var value3) || (Object)(object)value3 == (Object)null)
			{
				value3 = Object.Instantiate<GameObject>(prefab, prefabHavuzu.transform);
				((Object)value3).name = text;
				((Object)value3).hideFlags = (HideFlags)61;
				ItemDrop component = itemPrefab2.GetComponent<ItemDrop>();
				Piece val3 = value3.GetComponent<Piece>();
				if ((Object)(object)val3 == (Object)null)
				{
					val3 = value3.AddComponent<Piece>();
				}
				val3.m_enabled = true;
				val3.m_name = component.m_itemData.m_shared.m_name;
				val3.m_description = $"{YetismeSuresiDakika.Value} dk icinde yetisir. Her hasatta {HasatMiktari.Value} adet verir ve tekrar buyur.";
				val3.m_icon = component.m_itemData.m_shared.m_icons.FirstOrDefault();
				val3.m_category = category;
				val3.m_cultivatedGroundOnly = false;
				val3.m_groundOnly = true;
				val3.m_canRotate = true;
				val3.m_resources = (Requirement[])(object)new Requirement[1]
				{
					new Requirement
					{
						m_resItem = component,
						m_amount = 1,
						m_recover = true
					}
				};
				olusturulanPrefablar[text] = value3;
			}
			if (!ZNetScene.instance.m_prefabs.Contains(value3))
			{
				ZNetScene.instance.m_prefabs.Add(value3);
			}
			if (value != null)
			{
				value[StringExtensionMethods.GetStableHashCode(text)] = value3;
			}
			if (!val.m_pieces.Contains(value3))
			{
				val.m_pieces.Add(value3);
			}
		}
	}

	[HarmonyPatch(typeof(Pickable), "Awake")]
	[HarmonyPostfix]
	private static void OzelBitkiBaslangic(Pickable __instance)
	{
		if (!ModAktif.Value || (Object)(object)__instance == (Object)null || (Object)(object)ZNet.instance == (Object)null)
		{
			return;
		}
		ZNetView component = ((Component)__instance).GetComponent<ZNetView>();
		if ((Object)(object)component == (Object)null || !component.IsValid() || (!((Object)__instance).name.StartsWith("Lareins_Plant_") && !component.GetZDO().GetBool("Lareins_TarlaBitkisi", false)))
		{
			return;
		}
		component.GetZDO().Set("Lareins_TarlaBitkisi", true);
		if (component.GetZDO().GetFloat("Lareins_EkimSaniye", -1f) == -1f)
		{
			component.ClaimOwnership();
			component.GetZDO().Set("Lareins_EkimSaniye", (float)ZNet.instance.GetTimeSeconds());
			component.GetZDO().Set("picked", true);
			if ((Object)(object)__instance.m_hideWhenPicked != (Object)null)
			{
				__instance.m_hideWhenPicked.SetActive(false);
			}
		}
	}

	[HarmonyPatch(typeof(Pickable), "UpdateRespawn")]
	[HarmonyPrefix]
	private static bool OzelBitkiBuyumeKontrol(Pickable __instance)
	{
		if (!ModAktif.Value || (Object)(object)__instance == (Object)null || (Object)(object)ZNet.instance == (Object)null)
		{
			return true;
		}
		ZNetView component = ((Component)__instance).GetComponent<ZNetView>();
		if ((Object)(object)component == (Object)null || !component.IsValid())
		{
			return true;
		}
		if (!component.GetZDO().GetBool("Lareins_TarlaBitkisi", false))
		{
			return true;
		}
		if (!component.GetZDO().GetBool("picked", false))
		{
			return false;
		}
		float num = component.GetZDO().GetFloat("Lareins_EkimSaniye", -1f);
		if (num == -1f)
		{
			return false;
		}
		double num2 = ZNet.instance.GetTimeSeconds() - (double)num;
		double num3 = (double)YetismeSuresiDakika.Value * 60.0;
		if (num2 >= num3)
		{
			component.ClaimOwnership();
			component.GetZDO().Set("picked", false);
			if ((Object)(object)__instance.m_hideWhenPicked != (Object)null)
			{
				__instance.m_hideWhenPicked.SetActive(true);
			}
		}
		return false;
	}

	[HarmonyPatch(typeof(Pickable), "Interact")]
	[HarmonyPrefix]
	private static bool OzelBitkiHasat(Pickable __instance, Humanoid character, bool repeat, ref bool __result)
	{
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0230: Unknown result type (might be due to invalid IL or missing references)
		//IL_0235: Unknown result type (might be due to invalid IL or missing references)
		//IL_0243: Unknown result type (might be due to invalid IL or missing references)
		//IL_0249: Unknown result type (might be due to invalid IL or missing references)
		//IL_0116: Unknown result type (might be due to invalid IL or missing references)
		//IL_011b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0125: Unknown result type (might be due to invalid IL or missing references)
		//IL_012a: Unknown result type (might be due to invalid IL or missing references)
		//IL_012f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0139: Unknown result type (might be due to invalid IL or missing references)
		//IL_013e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0143: Unknown result type (might be due to invalid IL or missing references)
		//IL_014b: Unknown result type (might be due to invalid IL or missing references)
		//IL_014d: Unknown result type (might be due to invalid IL or missing references)
		if (!ModAktif.Value || (Object)(object)__instance == (Object)null || (Object)(object)character == (Object)null)
		{
			return true;
		}
		if (!topluHasatCalisiyor && Input.GetKey((KeyCode)304) && !repeat)
		{
			topluHasatCalisiyor = true;
			try
			{
				TopluHasatYap(character, ((Component)__instance).transform.position);
			}
			finally
			{
				topluHasatCalisiyor = false;
			}
			__result = true;
			return false;
		}
		ZNetView component = ((Component)__instance).GetComponent<ZNetView>();
		if ((Object)(object)component == (Object)null || !component.IsValid() || !component.GetZDO().GetBool("Lareins_TarlaBitkisi", false))
		{
			return true;
		}
		if (component.GetZDO().GetBool("picked", false))
		{
			__result = false;
			return false;
		}
		component.ClaimOwnership();
		int value = HasatMiktari.Value;
		if ((Object)(object)__instance.m_itemPrefab != (Object)null)
		{
			for (int i = 0; i != value; i++)
			{
				Vector3 val = ((Component)__instance).transform.position + Vector3.up * 0.4f + Random.insideUnitSphere * 0.25f;
				GameObject val2 = Object.Instantiate<GameObject>(__instance.m_itemPrefab, val, Quaternion.identity);
				ItemDrop component2 = val2.GetComponent<ItemDrop>();
				if ((Object)(object)component2 != (Object)null)
				{
					Player val3 = (Player)(object)((character is Player) ? character : null);
					if (val3 != null && ((Humanoid)val3).GetInventory().CanAddItem(component2.m_itemData, -1))
					{
						((Humanoid)val3).GetInventory().AddItem(component2.m_itemData);
						ZNetScene.instance.Destroy(val2);
					}
				}
			}
		}
		component.GetZDO().Set("picked", true);
		component.GetZDO().Set("Lareins_EkimSaniye", (float)ZNet.instance.GetTimeSeconds());
		if ((Object)(object)__instance.m_hideWhenPicked != (Object)null)
		{
			__instance.m_hideWhenPicked.SetActive(false);
		}
		EffectList pickEffector = __instance.m_pickEffector;
		if (pickEffector != null)
		{
			pickEffector.Create(((Component)__instance).transform.position, Quaternion.identity, (Transform)null, 1f, -1, default(ZDOID));
		}
		__result = true;
		return false;
	}

	[HarmonyPatch(typeof(Pickable), "GetHoverText")]
	[HarmonyPostfix]
	private static void OzelBitkiEtiket(Pickable __instance, ref string __result)
	{
		if (!ModAktif.Value || (Object)(object)__instance == (Object)null || (Object)(object)ZNet.instance == (Object)null)
		{
			return;
		}
		ZNetView component = ((Component)__instance).GetComponent<ZNetView>();
		if ((Object)(object)component == (Object)null || !component.IsValid())
		{
			return;
		}
		if (component.GetZDO().GetBool("Lareins_TarlaBitkisi", false))
		{
			bool flag = component.GetZDO().GetBool("picked", false);
			string hoverName = __instance.GetHoverName();
			if (!flag)
			{
				__result = $"{hoverName} (Hasada Hazir - {HasatMiktari.Value}x)\n[E] Topla  |  [Sol Shift + E] Toplu Hasat";
				return;
			}
			float num = component.GetZDO().GetFloat("Lareins_EkimSaniye", 0f);
			double num2 = ZNet.instance.GetTimeSeconds() - (double)num;
			double num3 = (double)YetismeSuresiDakika.Value * 60.0;
			float num4 = Mathf.Clamp01((float)(num2 / num3)) * 100f;
			int num5 = Mathf.Max(0, Mathf.CeilToInt((float)(num3 - num2)));
			int num6 = num5 / 60;
			int num7 = num5 % 60;
			__result = $"{hoverName}\nYetisme Durumu: %{Mathf.FloorToInt(num4)} (Kalan Sure: {num6:00}:{num7:00})";
		}
		else
		{
			__result += "\n[Sol Shift + E] Alandaki Tum Ekinleri Topla";
		}
	}

	[HarmonyPatch(typeof(Plant), "GetHoverText")]
	[HarmonyPostfix]
	private static void NormalFidanEtiket(Plant __instance, ref string __result)
	{
		if (ModAktif.Value && !((Object)(object)__instance == (Object)null))
		{
			double value = Traverse.Create((object)__instance).Method("TimeSincePlanted", Array.Empty<object>()).GetValue<double>();
			float growTime = __instance.m_growTime;
			if (growTime > 0f)
			{
				float num = Mathf.Clamp01((float)(value / (double)growTime)) * 100f;
				int num2 = Mathf.Max(0, Mathf.CeilToInt(growTime - (float)value));
				int num3 = num2 / 60;
				int num4 = num2 % 60;
				__result += $"\nYetisme Durumu: %{Mathf.FloorToInt(num)} (Kalan Sure: {num3:00}:{num4:00})";
			}
		}
	}

	private void Update()
	{
		//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00df: Unknown result type (might be due to invalid IL or missing references)
		if (!ModAktif.Value || (Object)(object)Player.m_localPlayer == (Object)null || !Input.GetKey((KeyCode)304))
		{
			SablonuGizle();
			return;
		}
		GameObject value = Traverse.Create((object)Player.m_localPlayer).Field("m_placementGhost").GetValue<GameObject>();
		if ((Object)(object)value == (Object)null || !value.activeSelf)
		{
			SablonuGizle();
			return;
		}
		Piece component = value.GetComponent<Piece>();
		if ((Object)(object)component == (Object)null)
		{
			SablonuGizle();
			return;
		}
		Plant component2 = ((Component)component).GetComponent<Plant>();
		bool flag = ((Object)component).name.StartsWith("Lareins_Plant_");
		if ((Object)(object)component2 == (Object)null && !flag)
		{
			SablonuGizle();
		}
		else
		{
			SablonuGoster(value.transform.position, value.transform.rotation, component2, component);
		}
	}

	private static void SablonuGoster(Vector3 merkez, Quaternion rotasyon, Plant fidan, Piece piece)
	{
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Expected O, but got Unknown
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_010a: 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)
		//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01da: Unknown result type (might be due to invalid IL or missing references)
		//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0221: Unknown result type (might be due to invalid IL or missing references)
		//IL_0230: Unknown result type (might be due to invalid IL or missing references)
		//IL_0237: Unknown result type (might be due to invalid IL or missing references)
		//IL_025d: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_0289: Unknown result type (might be due to invalid IL or missing references)
		int num = Mathf.Clamp(IzgaraBoyutu.Value, 2, 10);
		int num2 = num * num;
		if ((Object)(object)sablonMateryal == (Object)null)
		{
			sablonMateryal = new Material(Shader.Find("Sprites/Default"));
			sablonMateryal.color = new Color(0.2f, 0.95f, 0.35f, 0.75f);
		}
		while (sablonNoktalari.Count != num2 && sablonNoktalari.Count > num2)
		{
			int index = sablonNoktalari.Count - 1;
			if ((Object)(object)sablonNoktalari[index] != (Object)null)
			{
				Object.Destroy((Object)(object)sablonNoktalari[index]);
			}
			sablonNoktalari.RemoveAt(index);
		}
		while (sablonNoktalari.Count != num2)
		{
			GameObject val = GameObject.CreatePrimitive((PrimitiveType)2);
			((Object)val).name = "Lareins_FarmGridMarker";
			Object.Destroy((Object)(object)val.GetComponent<Collider>());
			val.transform.localScale = new Vector3(0.32f, 0.03f, 0.32f);
			val.GetComponent<Renderer>().material = sablonMateryal;
			Object.DontDestroyOnLoad((Object)(object)val);
			sablonNoktalari.Add(val);
		}
		float num3 = (((Object)(object)fidan != (Object)null) ? Mathf.Max(0.85f, fidan.m_growRadius * 2.05f) : 1.15f);
		float num4 = 0f - (float)(num - 1) * 0.5f;
		int num5 = 0;
		float num8 = default(float);
		for (int i = 0; i != num; i++)
		{
			for (int j = 0; j != num; j++)
			{
				GameObject val2 = sablonNoktalari[num5++];
				float num6 = (num4 + (float)i) * num3;
				float num7 = (num4 + (float)j) * num3;
				Vector3 val3 = rotasyon * new Vector3(num6, 0f, num7);
				Vector3 val4 = merkez + val3;
				if ((Object)(object)ZoneSystem.instance != (Object)null && ZoneSystem.instance.GetGroundHeight(val4, ref num8))
				{
					val4.y = num8 + 0.04f;
				}
				bool flag = true;
				if (piece.m_cultivatedGroundOnly && (Object)(object)Heightmap.FindHeightmap(val4) != (Object)null && !Heightmap.FindHeightmap(val4).IsCultivated(val4))
				{
					flag = false;
				}
				val2.SetActive(true);
				val2.transform.position = val4;
				val2.GetComponent<Renderer>().material.color = (flag ? new Color(0.2f, 0.95f, 0.35f, 0.8f) : new Color(0.95f, 0.2f, 0.2f, 0.7f));
			}
		}
	}

	private static void SablonuGizle()
	{
		for (int i = 0; i != sablonNoktalari.Count; i++)
		{
			if ((Object)(object)sablonNoktalari[i] != (Object)null && sablonNoktalari[i].activeSelf)
			{
				sablonNoktalari[i].SetActive(false);
			}
		}
	}

	[HarmonyPatch(typeof(Player), "PlacePiece")]
	[HarmonyPostfix]
	private static void IzgaraTopluEkim(Player __instance, Piece piece)
	{
		//IL_00af: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0186: Unknown result type (might be due to invalid IL or missing references)
		//IL_0191: Unknown result type (might be due to invalid IL or missing references)
		//IL_0196: Unknown result type (might be due to invalid IL or missing references)
		//IL_019b: Unknown result type (might be due to invalid IL or missing references)
		//IL_019d: Unknown result type (might be due to invalid IL or missing references)
		//IL_019e: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_022c: Unknown result type (might be due to invalid IL or missing references)
		//IL_022e: Unknown result type (might be due to invalid IL or missing references)
		if (!ModAktif.Value || topluEkimCalisiyor || (Object)(object)__instance != (Object)(object)Player.m_localPlayer || (Object)(object)piece == (Object)null || !Input.GetKey((KeyCode)304))
		{
			return;
		}
		Plant component = ((Component)piece).GetComponent<Plant>();
		bool flag = ((Object)piece).name.StartsWith("Lareins_Plant_");
		if ((Object)(object)component == (Object)null && !flag)
		{
			return;
		}
		GameObject value = Traverse.Create((object)__instance).Field("m_placementGhost").GetValue<GameObject>();
		if ((Object)(object)value == (Object)null)
		{
			return;
		}
		Vector3 position = value.transform.position;
		Quaternion rotation = value.transform.rotation;
		int num = Mathf.Clamp(IzgaraBoyutu.Value, 2, 10);
		float num2 = (((Object)(object)component != (Object)null) ? Mathf.Max(0.85f, component.m_growRadius * 2.05f) : 1.15f);
		float num3 = 0f - (float)(num - 1) * 0.5f;
		topluEkimCalisiyor = true;
		try
		{
			float y = default(float);
			for (int i = 0; i != num; i++)
			{
				for (int j = 0; j != num; j++)
				{
					float num4 = (num3 + (float)i) * num2;
					float num5 = (num3 + (float)j) * num2;
					if (Mathf.Abs(num4) == 0f && Mathf.Abs(num5) == 0f)
					{
						continue;
					}
					if (!__instance.NoCostCheat() && !__instance.HaveRequirements(piece, (RequirementMode)0))
					{
						return;
					}
					Vector3 val = rotation * new Vector3(num4, 0f, num5);
					Vector3 val2 = position + val;
					if (ZoneSystem.instance.GetGroundHeight(val2, ref y))
					{
						val2.y = y;
					}
					if ((!piece.m_cultivatedGroundOnly || Heightmap.FindHeightmap(val2).IsCultivated(val2)) && !Physics.OverlapSphere(val2, num2 * 0.45f).Any((Collider c) => (Object)(object)((Component)c).GetComponentInParent<Plant>() != (Object)null || (Object)(object)((Component)c).GetComponentInParent<Pickable>() != (Object)null))
					{
						GameObject val3 = Object.Instantiate<GameObject>(((Component)piece).gameObject, val2, rotation);
						ZNetView component2 = val3.GetComponent<ZNetView>();
						if ((Object)(object)component2 != (Object)null && component2.IsValid())
						{
							component2.GetZDO().Set("creator", __instance.GetPlayerID());
						}
						if (!__instance.NoCostCheat())
						{
							__instance.ConsumeResources(piece.m_resources, 0, -1, 1);
						}
					}
				}
			}
		}
		finally
		{
			topluEkimCalisiyor = false;
		}
	}

	private static void TopluHasatYap(Humanoid karakter, Vector3 merkez)
	{
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		float num = HasatMenzili.Value;
		Pickable[] array = Object.FindObjectsByType<Pickable>((FindObjectsSortMode)0);
		Pickable[] array2 = array;
		foreach (Pickable val in array2)
		{
			if (!((Object)(object)val == (Object)null) && !(Vector3.Distance(merkez, ((Component)val).transform.position) > num))
			{
				ZNetView component = ((Component)val).GetComponent<ZNetView>();
				if (!((Object)(object)component == (Object)null) && component.IsValid() && !component.GetZDO().GetBool("picked", false))
				{
					val.Interact(karakter, false, false);
				}
			}
		}
	}
}