Decompiled source of FarmGrid v0.5.0

FarmGrid.dll

Decompiled 2 years ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using FarmGrid.Patches;
using HarmonyLib;
using Jotunn.Utils;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.7", FrameworkDisplayName = ".NET Framework 4.7")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 FarmGrid
{
	[BepInPlugin("BepIn.Sarcen.FarmGrid", "FarmGrid", "0.5.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	public class FarmGrid : BaseUnityPlugin
	{
		internal const string Author = "Sarcen";

		internal const string Name = "FarmGrid";

		internal const string Version = "0.5.0";

		internal const string BepInGUID = "BepIn.Sarcen.FarmGrid";

		internal const string HarmonyGUID = "Harmony.Sarcen.FarmGrid";

		internal static Harmony harmony;

		private ConfigEntry<float> plantSpacing;

		private ConfigEntry<int> farmGridSections;

		private ConfigEntry<float> farmGridYOffset;

		private ConfigEntry<Color> farmGridColor;

		private ConfigEntry<string> plantObjectMasks;

		private ConfigEntry<string> customPlants;

		private ConfigEntry<int> farmGridFixedRotation;

		private void Awake()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			harmony = new Harmony("Harmony.Sarcen.FarmGrid");
			harmony.PatchAll();
			farmGridFixedRotation = ((BaseUnityPlugin)this).Config.Bind<int>("FarmGrid", "farmGridFixedRotation", FarmGrid_Patch.farmGridFixedRotation, "Fixed rotation in degrees, 0 is no fixed rotation (if you want 0 to be the fixed rotation enter 360)");
			plantSpacing = ((BaseUnityPlugin)this).Config.Bind<float>("FarmGrid", "plantSpacing", FarmGrid_Patch.plantSpacing, "Amount of space between plants. This is extra spacing on top of the growthsize needed to grow.");
			farmGridSections = ((BaseUnityPlugin)this).Config.Bind<int>("FarmGrid", "farmGridSections", FarmGrid_Patch.farmGridSections, "Amount of grid sections (on either side of the main axis.)");
			farmGridYOffset = ((BaseUnityPlugin)this).Config.Bind<float>("FarmGrid", "farmGridYOffset", FarmGrid_Patch.farmGridYOffset, "Grid offset from the ground.");
			farmGridColor = ((BaseUnityPlugin)this).Config.Bind<Color>("FarmGrid", "farmGridColor", FarmGrid_Patch.farmGridColor, "Color of the grid.");
			plantObjectMasks = ((BaseUnityPlugin)this).Config.Bind<string>("FarmGrid", "plantObjectMasks", GeneralExtensions.Join<string>((IEnumerable<string>)FarmGrid_Patch.plantObjectMasks, (Func<string, string>)null, ", "), "Masks used by overlapping detection, if you add custom plants that are not in the normal category you may want to add more flags here.\nif you don't know what you are doing, don't touch this.\n\nUse this for Planting Plus:plantObjectMasks = piece,piece_nonsolid,item");
			customPlants = ((BaseUnityPlugin)this).Config.Bind<string>("FarmGrid", "customPlants", "", "Plants that are not actually plants (objects without a plant component), their name and size.\n\nUse this for Planting Plus:\ncustomPlants = RaspberryBush(Clone): 0.5, RaspberryBush: 0.5, BlueberryBush(Clone): 0.5, BlueberryBush: 0.5, Pickable_Mushroom_yellow(Clone): 0.5, Pickable_Mushroom_yellow: 0.5, Pickable_Mushroom_blue(Clone): 0.5, Pickable_Mushroom_blue: 0.5, CloudberryBush: 0.5, CloudberryBush(Clone): 0.5, Pickable_Thistle(Clone): 0.5, Pickable_Thistle: 0.5, Pickable_Dandelion(Clone): 0.5, Pickable_Dandelion: 0.5");
			farmGridFixedRotation.SettingChanged += FarmGridFixedRotation_SettingChanged;
			plantSpacing.SettingChanged += PlantSpacing_SettingChanged;
			farmGridSections.SettingChanged += FarmGridSections_SettingChanged;
			farmGridYOffset.SettingChanged += FarmGridYOffset_SettingChanged;
			farmGridColor.SettingChanged += FarmGridColor_SettingChanged;
			plantObjectMasks.SettingChanged += PlantObjectMasks_SettingChanged;
			customPlants.SettingChanged += CustomPlants_SettingChanged;
			SettingsChanged();
		}

		private void FarmGridFixedRotation_SettingChanged(object sender, EventArgs e)
		{
			FarmGrid_Patch.farmGridFixedRotation = farmGridFixedRotation.Value;
			FarmGrid_Patch.DestroyFarmGrid();
		}

		private void SettingsChanged()
		{
			FarmGridFixedRotation_SettingChanged(null, null);
			PlantSpacing_SettingChanged(null, null);
			FarmGridSections_SettingChanged(null, null);
			FarmGridYOffset_SettingChanged(null, null);
			FarmGridColor_SettingChanged(null, null);
			PlantObjectMasks_SettingChanged(null, null);
			CustomPlants_SettingChanged(null, null);
		}

		private void CustomPlants_SettingChanged(object sender, EventArgs e)
		{
			FarmGrid_Patch.customPlants.Clear();
			string[] array = customPlants.Value.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries);
			string[] array2 = array;
			foreach (string text in array2)
			{
				string[] array3 = text.Split(new string[1] { ":" }, StringSplitOptions.RemoveEmptyEntries);
				if (array3.Length == 2 && float.TryParse(array3[1].Trim(), NumberStyles.Float, CultureInfo.InvariantCulture, out var result))
				{
					FarmGrid_Patch.customPlants.Add(array3[0].Trim(), result);
				}
			}
			FarmGrid_Patch.DestroyFarmGrid();
		}

		private void PlantObjectMasks_SettingChanged(object sender, EventArgs e)
		{
			string[] array = plantObjectMasks.Value.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries);
			List<string> list = new List<string>();
			string[] array2 = array;
			foreach (string text in array2)
			{
				list.Add(text.Trim());
			}
			FarmGrid_Patch.plantObjectMasks = list;
			FarmGrid_Patch.DestroyFarmGrid();
		}

		private void FarmGridColor_SettingChanged(object sender, EventArgs e)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			FarmGrid_Patch.farmGridColor = farmGridColor.Value;
			FarmGrid_Patch.DestroyFarmGrid();
		}

		private void FarmGridYOffset_SettingChanged(object sender, EventArgs e)
		{
			FarmGrid_Patch.farmGridYOffset = farmGridYOffset.Value;
			FarmGrid_Patch.DestroyFarmGrid();
		}

		private void FarmGridSections_SettingChanged(object sender, EventArgs e)
		{
			FarmGrid_Patch.farmGridSections = farmGridSections.Value;
			FarmGrid_Patch.DestroyFarmGrid();
		}

		private void PlantSpacing_SettingChanged(object sender, EventArgs e)
		{
			FarmGrid_Patch.plantSpacing = plantSpacing.Value;
			FarmGrid_Patch.DestroyFarmGrid();
		}
	}
}
namespace FarmGrid.Patches
{
	public static class Vector3Ext
	{
		public static Vector3 xz(this Vector3 v)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			return new Vector3(v.x, 0f, v.z);
		}
	}
	[HarmonyPatch]
	internal class FarmGrid_Patch
	{
		private class PlantObject
		{
			public Vector3 position;

			public float growthSize;

			public PlantObject(Vector3 position, float growthSize)
			{
				//IL_0009: Unknown result type (might be due to invalid IL or missing references)
				//IL_000a: Unknown result type (might be due to invalid IL or missing references)
				this.position = position;
				this.growthSize = growthSize;
			}
		}

		public static float plantSpacing = 0.01f;

		public static int farmGridSections = 2;

		public static float farmGridYOffset = 0.2f;

		public static Color farmGridColor = new Color(0.8f, 0.8f, 0.8f, 0.2f);

		public static Dictionary<string, float> customPlants = new Dictionary<string, float>();

		public static List<string> plantObjectMasks = new List<string> { "piece", "piece_nonsolid" };

		private static Vector3 plantSnapPoint;

		private static GameObject[] farmGrid = null;

		private static bool farmGridVisible = false;

		private static Vector3 plantGhostPosition;

		private static Vector3 otherPlantCollider;

		private static List<PlantObject> otherPlantList;

		private static int plantObjectMask;

		private static Material lineMaterial;

		internal static int farmGridFixedRotation;

		[HarmonyPatch(typeof(Player), "UpdatePlacementGhost")]
		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> UpdatePlacementGhost(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Expected O, but got Unknown
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Expected O, but got Unknown
			List<CodeInstruction> list = instructions.ToList();
			int num = 0;
			bool flag = false;
			for (int i = 0; i < list.Count; i++)
			{
				if (list[i].opcode == OpCodes.Brtrue)
				{
					num = i;
				}
				if (CodeInstructionExtensions.Calls(list[i], AccessTools.Method(typeof(Player), "FindClosestSnapPoints", (Type[])null, (Type[])null)))
				{
					list.InsertRange(num + 1, (IEnumerable<CodeInstruction>)(object)new CodeInstruction[2]
					{
						new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(FarmGrid_Patch), "GetFarmSnapPoints", (Type[])null, (Type[])null)),
						new CodeInstruction(OpCodes.Brtrue, list[num].operand)
					});
					flag = true;
					break;
				}
			}
			if (!flag)
			{
				ZLog.LogWarning((object)"FarmGrid: Failed to patch UpdatePlacementGhost");
			}
			return list;
		}

		[HarmonyPatch(typeof(Player), "PlacePiece")]
		[HarmonyPrefix]
		private static bool PlacePiece(ref Player __instance, ref bool __result, Piece piece)
		{
			//IL_0017: 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)
			if (GetPlantObject(__instance.m_placementGhost.GetComponent<Collider>(), out var plantObject) && HasOverlappingPlants(plantObject.position, plantObject.growthSize))
			{
				__result = false;
				return false;
			}
			otherPlantCollider = Vector3.zero;
			return true;
		}

		[HarmonyPatch(typeof(Humanoid), "SetupVisEquipment")]
		[HarmonyPostfix]
		private static void SetupVisEquipment(ref Humanoid __instance)
		{
			if ((Object)(object)__instance == (Object)(object)Player.m_localPlayer && (!Object.op_Implicit((Object)(object)Player.m_localPlayer) || ((Humanoid)Player.m_localPlayer).m_rightItem == null || ((Humanoid)Player.m_localPlayer).m_rightItem.m_shared == null || ((Humanoid)Player.m_localPlayer).m_rightItem.m_shared.m_name != "$item_cultivator"))
			{
				HideFarmGrid();
			}
		}

		private static void DrawFarmGrid(Vector3 pos, Vector3 gridDir, float gridSize)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: 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_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: 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)
			if (farmGrid == null || (Object)(object)farmGrid[0] == (Object)null)
			{
				InitFarmGrid();
			}
			Vector3 val = default(Vector3);
			((Vector3)(ref val))..ctor(gridDir.z, gridDir.y, 0f - gridDir.x);
			for (int i = -farmGridSections; i <= farmGridSections; i++)
			{
				Vector3 val2 = pos + gridDir * (float)i * gridSize;
				GameObject val3 = farmGrid[i + farmGridSections];
				val3.transform.position = val2;
				LineRenderer component = val3.GetComponent<LineRenderer>();
				component.widthMultiplier = 0.015f;
				((Renderer)component).enabled = true;
				for (int j = -farmGridSections; j <= farmGridSections; j++)
				{
					Vector3 val4 = val2 + val * (float)j * gridSize;
					float groundHeight = GetGroundHeight(val4);
					val4.y = groundHeight + farmGridYOffset;
					component.SetPosition(j + farmGridSections, val4);
				}
			}
			for (int k = -farmGridSections; k <= farmGridSections; k++)
			{
				Vector3 val5 = pos + val * (float)k * gridSize;
				GameObject val6 = farmGrid[k + farmGridSections + (farmGridSections * 2 + 1)];
				val6.transform.position = val5;
				LineRenderer component2 = val6.GetComponent<LineRenderer>();
				component2.widthMultiplier = 0.015f;
				((Renderer)component2).enabled = true;
				for (int l = -farmGridSections; l <= farmGridSections; l++)
				{
					Vector3 val7 = val5 + gridDir * (float)l * gridSize;
					float groundHeight2 = GetGroundHeight(val7);
					val7.y = groundHeight2 + farmGridYOffset;
					component2.SetPosition(l + farmGridSections, val7);
				}
			}
			farmGridVisible = true;
		}

		private static float GetGroundHeight(Vector3 linePos)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: 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)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			float num = ZoneSystem.instance.GetGroundHeight(linePos);
			RaycastHit[] array = Physics.RaycastAll(linePos + Vector3.up, Vector3.down, 2f, Piece.s_pieceRayMask);
			RaycastHit[] array2 = array;
			for (int i = 0; i < array2.Length; i++)
			{
				RaycastHit val = array2[i];
				if (!Object.op_Implicit((Object)(object)((Component)((RaycastHit)(ref val)).collider).GetComponentInParent<Plant>()) && ((RaycastHit)(ref val)).point.y > num)
				{
					num = ((RaycastHit)(ref val)).point.y;
				}
			}
			return num;
		}

		public static void DestroyFarmGrid()
		{
			if (farmGrid == null)
			{
				return;
			}
			for (int i = 0; i < farmGrid.Length; i++)
			{
				if (Object.op_Implicit((Object)(object)farmGrid[i]))
				{
					Object.Destroy((Object)(object)farmGrid[i]);
				}
			}
			farmGrid = null;
		}

		private static void InitFarmGrid()
		{
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Expected O, but got Unknown
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)lineMaterial))
			{
				lineMaterial = Resources.FindObjectsOfTypeAll<Material>().First((Material k) => ((Object)k).name == "Default-Line");
			}
			farmGrid = (GameObject[])(object)new GameObject[(farmGridSections * 2 + 1) * 2];
			for (int i = 0; i < farmGrid.Length; i++)
			{
				GameObject val = new GameObject();
				LineRenderer val2 = val.AddComponent<LineRenderer>();
				((Renderer)val2).material = lineMaterial;
				val2.startColor = farmGridColor;
				val2.endColor = farmGridColor;
				val2.positionCount = farmGridSections * 2 + 1;
				farmGrid[i] = val;
			}
		}

		private static void HideFarmGrid()
		{
			if (farmGridVisible && farmGrid != null && (Object)(object)farmGrid[0] != (Object)null)
			{
				for (int i = 0; i < farmGrid.Length; i++)
				{
					LineRenderer component = farmGrid[i].GetComponent<LineRenderer>();
					((Renderer)component).enabled = false;
				}
				farmGridVisible = false;
			}
		}

		private static PlantObject GetGhostPlant()
		{
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			Player localPlayer = Player.m_localPlayer;
			Collider component = localPlayer.m_placementGhost.GetComponent<Collider>();
			if ((Object)(object)component != (Object)null && GetPlantObject(component, out var plantObject))
			{
				return plantObject;
			}
			if ((Object)(object)component == (Object)null)
			{
				Piece componentInParent = localPlayer.m_placementGhost.GetComponentInParent<Piece>();
				if ((Object)(object)componentInParent != (Object)null && customPlants.TryGetValue(((Object)componentInParent).name, out var value))
				{
					return new PlantObject(((Component)componentInParent).transform.position, value);
				}
			}
			return null;
		}

		private static bool GetFarmSnapPoints()
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: 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_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: 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_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: 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_01df: Unknown result type (might be due to invalid IL or missing references)
			//IL_0220: Unknown result type (might be due to invalid IL or missing references)
			//IL_0225: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: 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)
			//IL_0233: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_0256: Unknown result type (might be due to invalid IL or missing references)
			//IL_0261: Unknown result type (might be due to invalid IL or missing references)
			//IL_0266: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: 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)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0293: Unknown result type (might be due to invalid IL or missing references)
			//IL_0298: Unknown result type (might be due to invalid IL or missing references)
			//IL_029c: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0407: Unknown result type (might be due to invalid IL or missing references)
			//IL_040c: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_042b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0449: Unknown result type (might be due to invalid IL or missing references)
			//IL_0454: Unknown result type (might be due to invalid IL or missing references)
			//IL_0459: Unknown result type (might be due to invalid IL or missing references)
			//IL_0420: Unknown result type (might be due to invalid IL or missing references)
			//IL_0425: Unknown result type (might be due to invalid IL or missing references)
			//IL_0328: Unknown result type (might be due to invalid IL or missing references)
			//IL_032d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0332: Unknown result type (might be due to invalid IL or missing references)
			//IL_0339: Unknown result type (might be due to invalid IL or missing references)
			//IL_033e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0343: Unknown result type (might be due to invalid IL or missing references)
			//IL_0348: Unknown result type (might be due to invalid IL or missing references)
			//IL_034f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0354: Unknown result type (might be due to invalid IL or missing references)
			//IL_0359: Unknown result type (might be due to invalid IL or missing references)
			//IL_035d: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = Player.m_localPlayer?.m_placementGhost;
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			PlantObject plantGhost = GetGhostPlant();
			if (plantGhost != null)
			{
				if (plantGhostPosition == val.transform.position)
				{
					if (plantSnapPoint != Vector3.zero)
					{
						val.transform.position = plantSnapPoint;
					}
					return true;
				}
				plantSnapPoint = Vector3.zero;
				plantGhostPosition = plantGhost.position;
				List<PlantObject> otherPlants = GetOtherPlants(plantGhost.position, plantGhost.growthSize * 3.5f);
				otherPlants.OrderBy(delegate(PlantObject k)
				{
					//IL_0001: Unknown result type (might be due to invalid IL or missing references)
					//IL_000c: Unknown result type (might be due to invalid IL or missing references)
					//IL_0011: Unknown result type (might be due to invalid IL or missing references)
					//IL_0016: Unknown result type (might be due to invalid IL or missing references)
					Vector3 val6 = k.position - plantGhost.position;
					return ((Vector3)(ref val6)).sqrMagnitude;
				});
				PlantObject firstPlant = ((otherPlants.Count > 0) ? otherPlants[0] : null);
				if (otherPlants.Count >= 1)
				{
					if (!((Vector3)(ref otherPlantCollider)).Equals(otherPlants[0].position))
					{
						otherPlantCollider = otherPlants[0].position;
						otherPlantList = GetOtherPlants(otherPlants[0].position, plantGhost.growthSize * 4.5f);
						otherPlantList = otherPlantList.OrderBy(delegate(PlantObject k)
						{
							//IL_0001: Unknown result type (might be due to invalid IL or missing references)
							//IL_000c: Unknown result type (might be due to invalid IL or missing references)
							//IL_0011: Unknown result type (might be due to invalid IL or missing references)
							//IL_0016: Unknown result type (might be due to invalid IL or missing references)
							Vector3 val5 = k.position - firstPlant.position;
							return ((Vector3)(ref val5)).sqrMagnitude;
						}).ToList();
					}
					otherPlants = otherPlantList;
				}
				if (otherPlants.Count == 1)
				{
					Vector3 val2 = plantGhost.position.xz() - otherPlants[0].position.xz();
					((Vector3)(ref val2)).Normalize();
					float num = Mathf.Max(plantGhost.growthSize, otherPlants[0].growthSize) * 2f;
					float num2 = num + plantSpacing;
					plantSnapPoint = otherPlants[0].position + val2 * num2;
					float groundHeight = GetGroundHeight(plantSnapPoint);
					plantSnapPoint.y = groundHeight;
					val.transform.position = plantSnapPoint;
					DrawFarmGrid(plantSnapPoint, val2, num2);
					return true;
				}
				if (otherPlants.Count > 1)
				{
					Vector3 gridDir = GetGridDir(otherPlants, plantGhost);
					Vector3 val3 = default(Vector3);
					((Vector3)(ref val3))..ctor(gridDir.z, gridDir.y, 0f - gridDir.x);
					float num3 = Mathf.Max(Mathf.Max(otherPlants[1].growthSize, otherPlants[0].growthSize), plantGhost.growthSize) * 2f;
					float num4 = num3 + plantSpacing;
					List<Vector3> list = new List<Vector3>();
					for (int i = -2; i <= 2; i++)
					{
						for (int j = -2; j <= 2; j++)
						{
							if (i != 0 || j != 0)
							{
								Vector3 item = firstPlant.position + gridDir * (float)i * num4 + val3 * (float)j * num4;
								list.Add(item);
							}
						}
					}
					list = list.OrderBy(delegate(Vector3 k)
					{
						//IL_0000: Unknown result type (might be due to invalid IL or missing references)
						//IL_0007: Unknown result type (might be due to invalid IL or missing references)
						//IL_000c: Unknown result type (might be due to invalid IL or missing references)
						//IL_0011: Unknown result type (might be due to invalid IL or missing references)
						Vector3 val4 = k - plantGhost.position;
						return ((Vector3)(ref val4)).sqrMagnitude;
					}).ToList();
					plantSnapPoint = Vector3.zero;
					for (int l = 0; l < list.Count; l++)
					{
						if (!HasOverlappingPlants(list[l], plantGhost.growthSize))
						{
							plantSnapPoint = list[l];
							break;
						}
					}
					if (plantSnapPoint == Vector3.zero)
					{
						plantSnapPoint = list[0];
					}
					float groundHeight2 = GetGroundHeight(plantSnapPoint);
					plantSnapPoint.y = groundHeight2;
					val.transform.position = plantSnapPoint;
					DrawFarmGrid(plantSnapPoint, gridDir, num4);
					return true;
				}
				HideFarmGrid();
				return true;
			}
			HideFarmGrid();
			return false;
		}

		private static Vector3 GetGridDir(List<PlantObject> plantList, PlantObject plantGhost)
		{
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			Vector3 result = default(Vector3);
			if (farmGridFixedRotation != 0)
			{
				result.y = 0f;
				result.x = Mathf.Sin((float)farmGridFixedRotation * ((float)Math.PI / 180f));
				result.z = Mathf.Cos((float)farmGridFixedRotation * ((float)Math.PI / 180f));
				return ((Vector3)(ref result)).normalized;
			}
			for (int i = 0; i < plantList.Count - 1; i++)
			{
				for (int j = 1 + i; j < plantList.Count; j++)
				{
					result = plantList[i].position.xz() - plantList[j].position.xz();
					float num = Mathf.Max(Mathf.Max(plantList[i].growthSize, plantList[j].growthSize), plantGhost.growthSize) * 2f + plantSpacing;
					float magnitude = ((Vector3)(ref result)).magnitude;
					float num2 = Mathf.Floor(magnitude / (num - 0.01f));
					if (Mathf.Abs(magnitude - num2 * num) <= num2 * 0.01f)
					{
						((Vector3)(ref result)).Normalize();
						return result;
					}
				}
			}
			result = plantList[0].position.xz() - plantList[1].position.xz();
			((Vector3)(ref result)).Normalize();
			return result;
		}

		private static List<PlantObject> GetOtherPlants(Vector3 pos, float collisionRadius)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			List<PlantObject> list = new List<PlantObject>();
			if (plantObjectMask == 0)
			{
				plantObjectMask = LayerMask.GetMask(plantObjectMasks.ToArray());
			}
			int num = Physics.OverlapSphereNonAlloc(pos, collisionRadius, Piece.s_pieceColliders, plantObjectMask);
			for (int i = 0; i < num; i++)
			{
				if (GetPlantObject(Piece.s_pieceColliders[i], out var plantObject))
				{
					list.Add(plantObject);
				}
			}
			return list;
		}

		private static bool HasOverlappingPlants(Vector3 pos, float collisionRadius)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			if (plantObjectMask == 0)
			{
				plantObjectMask = LayerMask.GetMask(plantObjectMasks.ToArray());
			}
			int num = Physics.OverlapSphereNonAlloc(pos, collisionRadius, Piece.s_pieceColliders, plantObjectMask);
			for (int i = 0; i < num; i++)
			{
				if (GetPlantObject(Piece.s_pieceColliders[i], out var plantObject))
				{
					Vector3 val = pos - plantObject.position;
					if (((Vector3)(ref val)).magnitude <= collisionRadius + plantObject.growthSize)
					{
						return true;
					}
				}
			}
			return false;
		}

		private static bool GetPlantObject(Collider collider, out PlantObject plantObject)
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)collider == (Object)null)
			{
				plantObject = null;
				return false;
			}
			Plant componentInParent = ((Component)collider).GetComponentInParent<Plant>();
			if ((Object)(object)componentInParent != (Object)null)
			{
				if (!customPlants.TryGetValue(((Object)componentInParent).name, out var value))
				{
					value = componentInParent.m_growRadius;
				}
				plantObject = new PlantObject(((Component)collider).transform.position, value);
				return true;
			}
			Piece componentInParent2 = ((Component)collider).GetComponentInParent<Piece>();
			if ((Object)(object)componentInParent2 != (Object)null && customPlants.TryGetValue(((Object)componentInParent2).name, out var value2))
			{
				if (value2 == 0f)
				{
					value2 = collider.contactOffset;
				}
				plantObject = new PlantObject(((Component)collider).transform.position, value2);
				return true;
			}
			plantObject = null;
			return false;
		}
	}
}