Decompiled source of MassFarming v1.11.0

MassFarming.dll

Decompiled a month 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 UnityEngine;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("MassFarming")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MassFarming")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e1da477d-c14c-4355-be8f-c043e789791a")]
[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 MassFarming;

[BepInPlugin("xeio.MassFarming", "MassFarming", "1.11")]
public class MassFarming : BaseUnityPlugin
{
	public static ConfigEntry<KeyboardShortcut> MassActionHotkey { get; private set; }

	public static ConfigEntry<KeyboardShortcut> ControllerPickupHotkey { get; private set; }

	public static ConfigEntry<float> MassInteractRange { get; private set; }

	public static ConfigEntry<int> PlantGridWidth { get; private set; }

	public static ConfigEntry<int> PlantGridLength { get; private set; }

	public static ConfigEntry<bool> IgnoreStamina { get; private set; }

	public static ConfigEntry<bool> IgnoreDurability { get; private set; }

	public static ConfigEntry<bool> GridAnchorWidth { get; private set; }

	public static ConfigEntry<bool> GridAnchorLength { get; private set; }

	public void Awake()
	{
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		MassActionHotkey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Hotkeys", "MassActionHotkey", new KeyboardShortcut((KeyCode)304, Array.Empty<KeyCode>()), "Mass activation hotkey for multi-pickup/multi-plant.");
		ControllerPickupHotkey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Hotkeys", "ControllerPickupHotkey", new KeyboardShortcut((KeyCode)334, Array.Empty<KeyCode>()), "Mass activation hotkey for multi-pickup/multi-plant for controller.");
		MassInteractRange = ((BaseUnityPlugin)this).Config.Bind<float>("Pickup", "MassInteractRange", 5f, "Range of auto-pickup.");
		PlantGridWidth = ((BaseUnityPlugin)this).Config.Bind<int>("PlantGrid", "PlantGridWidth", 5, "Grid width of auto-plant. Recommend odd-number, default is '5' so (5x5).");
		PlantGridLength = ((BaseUnityPlugin)this).Config.Bind<int>("PlantGrid", "PlantGridLength", 5, "Grid length of auto-plant. Recommend odd-number, default is '5' so (5x5).");
		IgnoreStamina = ((BaseUnityPlugin)this).Config.Bind<bool>("Plant", "IgnoreStamina", false, "Ignore stamina requirements when planting extra rows.");
		IgnoreDurability = ((BaseUnityPlugin)this).Config.Bind<bool>("Plant", "IgnoreDurability", false, "Ignore durability when planting extra rows.");
		GridAnchorWidth = ((BaseUnityPlugin)this).Config.Bind<bool>("PlantGrid", "GridAnchorWidth", true, "Planting grid anchor point (width). Default is 'enabled' so the grid will extend left and right from the crosshairs. Disable to set the anchor to the side of the grid. Disable both anchors to set to corner.");
		GridAnchorLength = ((BaseUnityPlugin)this).Config.Bind<bool>("PlantGrid", "GridAnchorLength", true, "Planting grid anchor point (length). Default is 'enabled' so the grid will extend forward and backward from the crosshairs. Disable to set the anchor to the side of the grid. Disable both anchors to set to corner.");
		Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
	}
}
[HarmonyPatch]
public static class MassPickup
{
	private static FieldInfo m_interactMaskField = AccessTools.Field(typeof(Player), "m_interactMask");

	private static MethodInfo _ExtractMethod = AccessTools.Method(typeof(Beehive), "Extract", (Type[])null, (Type[])null);

	[HarmonyPatch(typeof(Player), "Interact")]
	public static void Prefix(Player __instance, GameObject go, bool hold, bool alt)
	{
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: 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_0073: 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_016d: Unknown result type (might be due to invalid IL or missing references)
		if (((Character)__instance).InAttack() || ((Character)__instance).InDodge() || hold)
		{
			return;
		}
		KeyboardShortcut value = MassFarming.ControllerPickupHotkey.Value;
		if (!Input.GetKey(((KeyboardShortcut)(ref value)).MainKey))
		{
			value = MassFarming.MassActionHotkey.Value;
			if (!Input.GetKey(((KeyboardShortcut)(ref value)).MainKey))
			{
				return;
			}
		}
		Interactable componentInParent = go.GetComponentInParent<Interactable>();
		Pickable val = (Pickable)(object)((componentInParent is Pickable) ? componentInParent : null);
		Collider[] array;
		if (val != null)
		{
			int num = (int)m_interactMaskField.GetValue(__instance);
			array = Physics.OverlapSphere(go.transform.position, MassFarming.MassInteractRange.Value, num);
			foreach (Collider obj in array)
			{
				object obj2;
				if (obj == null)
				{
					obj2 = null;
				}
				else
				{
					GameObject gameObject = ((Component)obj).gameObject;
					obj2 = ((gameObject != null) ? gameObject.GetComponentInParent<Pickable>() : null);
				}
				Pickable val2 = (Pickable)obj2;
				if (val2 != null && (Object)(object)val2 != (Object)(object)val && ((Object)val2.m_itemPrefab).name == ((Object)val.m_itemPrefab).name)
				{
					val2.Interact((Humanoid)(object)__instance, false, alt);
				}
			}
			return;
		}
		Beehive val3 = (Beehive)(object)((componentInParent is Beehive) ? componentInParent : null);
		if (val3 == null)
		{
			return;
		}
		int num2 = (int)m_interactMaskField.GetValue(__instance);
		array = Physics.OverlapSphere(go.transform.position, MassFarming.MassInteractRange.Value, num2);
		foreach (Collider obj3 in array)
		{
			object obj4;
			if (obj3 == null)
			{
				obj4 = null;
			}
			else
			{
				GameObject gameObject2 = ((Component)obj3).gameObject;
				obj4 = ((gameObject2 != null) ? gameObject2.GetComponentInParent<Beehive>() : null);
			}
			Beehive val4 = (Beehive)obj4;
			if (val4 != null && (Object)(object)val4 != (Object)(object)val3 && PrivateArea.CheckAccess(((Component)val4).transform.position, 0f, true, false))
			{
				_ExtractMethod.Invoke(val4, null);
			}
		}
	}
}
[HarmonyPatch]
public static class MassPlant
{
	private static readonly FieldInfo m_noPlacementCostField = AccessTools.Field(typeof(Player), "m_noPlacementCost");

	private static readonly FieldInfo m_placementGhostField = AccessTools.Field(typeof(Player), "m_placementGhost");

	private static readonly FieldInfo m_buildPiecesField = AccessTools.Field(typeof(Player), "m_buildPieces");

	private static readonly MethodInfo _GetRightItemMethod = AccessTools.Method(typeof(Humanoid), "GetRightItem", (Type[])null, (Type[])null);

	private static Vector3 placedPosition;

	private static Quaternion placedRotation;

	private static Piece placedPiece;

	private static bool placeSuccessful = false;

	private static int? massFarmingRotation = null;

	private static readonly int _plantSpaceMask = LayerMask.GetMask(new string[5] { "Default", "static_solid", "Default_small", "piece", "piece_nonsolid" });

	private static GameObject[] _placementGhosts = (GameObject[])(object)new GameObject[1];

	private static Piece _fakeResourcePiece;

	private static bool IsHotKeyPressed
	{
		get
		{
			//IL_0005: 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)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			KeyboardShortcut value = MassFarming.ControllerPickupHotkey.Value;
			if (!Input.GetKey(((KeyboardShortcut)(ref value)).MainKey))
			{
				value = MassFarming.MassActionHotkey.Value;
				return Input.GetKey(((KeyboardShortcut)(ref value)).MainKey);
			}
			return true;
		}
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(Player), "TryPlacePiece")]
	public static void TryPlacePiecePrefix(int ___m_placeRotation)
	{
		if (IsHotKeyPressed)
		{
			int? num = massFarmingRotation;
			if (!num.HasValue)
			{
				massFarmingRotation = ___m_placeRotation;
			}
		}
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(Player), "TryPlacePiece")]
	public static void TryPlacePiecePostfix(Player __instance, ref bool __result, Piece piece, ref int ___m_placeRotation)
	{
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		placeSuccessful = __result;
		if (__result)
		{
			GameObject val = (GameObject)m_placementGhostField.GetValue(__instance);
			placedPosition = val.transform.position;
			placedRotation = val.transform.rotation;
			placedPiece = piece;
		}
		if (IsHotKeyPressed)
		{
			___m_placeRotation = massFarmingRotation.Value;
		}
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(Player), "UpdatePlacement")]
	public static void UpdatePlacementPrefix(bool takeInput, float dt, ref int ___m_placeRotation)
	{
		placeSuccessful = false;
		if (IsHotKeyPressed && massFarmingRotation.HasValue)
		{
			___m_placeRotation = massFarmingRotation.Value;
		}
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(Player), "UpdatePlacement")]
	public static void UpdatePlacementPostfix(Player __instance, bool takeInput, float dt, int ___m_placeRotation)
	{
		//IL_003b: 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_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_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0117: Unknown result type (might be due to invalid IL or missing references)
		//IL_0136: Unknown result type (might be due to invalid IL or missing references)
		//IL_0137: 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_016d: Unknown result type (might be due to invalid IL or missing references)
		if (IsHotKeyPressed)
		{
			massFarmingRotation = ___m_placeRotation;
		}
		if (!placeSuccessful)
		{
			return;
		}
		Plant component = ((Component)placedPiece).gameObject.GetComponent<Plant>();
		if (!Object.op_Implicit((Object)(object)component) || !IsHotKeyPressed)
		{
			return;
		}
		Heightmap val = Heightmap.FindHeightmap(placedPosition);
		if (!Object.op_Implicit((Object)(object)val))
		{
			return;
		}
		foreach (Vector3 item in BuildPlantingGridPositions(placedPosition, component, placedRotation))
		{
			if ((placedPiece.m_cultivatedGroundOnly && !val.IsCultivated(item)) || placedPosition == item)
			{
				continue;
			}
			object? obj = _GetRightItemMethod.Invoke(__instance, Array.Empty<object>());
			ItemData val2 = (ItemData)((obj is ItemData) ? obj : null);
			if (val2 == null)
			{
				continue;
			}
			if (!MassFarming.IgnoreStamina.Value && !((Character)__instance).HaveStamina(val2.m_shared.m_attack.m_attackStamina))
			{
				Hud.instance.StaminaBarUppgradeFlash();
				break;
			}
			if (!(bool)m_noPlacementCostField.GetValue(__instance) && !__instance.HaveRequirements(placedPiece, (RequirementMode)0))
			{
				break;
			}
			if (!HasGrowSpace(item, ((Component)placedPiece).gameObject))
			{
				continue;
			}
			GameObject val3 = Object.Instantiate<GameObject>(((Component)placedPiece).gameObject, item, placedRotation);
			Piece component2 = val3.GetComponent<Piece>();
			if (Object.op_Implicit((Object)(object)component2))
			{
				component2.SetCreator(__instance.GetPlayerID());
			}
			placedPiece.m_placeEffect.Create(item, placedRotation, val3.transform, 1f, -1);
			Game.instance.IncrementPlayerStat((PlayerStatType)2, 1f);
			__instance.ConsumeResources(placedPiece.m_resources, 0, -1, 1);
			if (!MassFarming.IgnoreStamina.Value)
			{
				((Character)__instance).UseStamina(val2.m_shared.m_attack.m_attackStamina);
			}
			if (!MassFarming.IgnoreDurability.Value && val2.m_shared.m_useDurability)
			{
				val2.m_durability -= val2.m_shared.m_useDurabilityDrain;
				if (val2.m_durability <= 0f)
				{
					break;
				}
			}
		}
	}

	private static List<Vector3> BuildPlantingGridPositions(Vector3 originPos, Plant placedPlant, Quaternion rotation)
	{
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: 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_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: 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_004d: 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_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: 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_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_0093: Unknown result type (might be due to invalid IL or missing references)
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: 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_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
		float num = placedPlant.m_growRadius * 2f;
		List<Vector3> list = new List<Vector3>(MassFarming.PlantGridWidth.Value * MassFarming.PlantGridLength.Value);
		Vector3 val = rotation * Vector3.left * num;
		Vector3 val2 = rotation * Vector3.forward * num;
		Vector3 val3 = originPos;
		if (MassFarming.GridAnchorLength.Value)
		{
			val3 -= val2 * (float)(MassFarming.PlantGridLength.Value / 2);
		}
		if (MassFarming.GridAnchorWidth.Value)
		{
			val3 -= val * (float)(MassFarming.PlantGridWidth.Value / 2);
		}
		for (int i = 0; i < MassFarming.PlantGridLength.Value; i++)
		{
			Vector3 val4 = val3;
			for (int j = 0; j < MassFarming.PlantGridWidth.Value; j++)
			{
				val4.y = ZoneSystem.instance.GetGroundHeight(val4);
				list.Add(val4);
				val4 += val;
			}
			val3 += val2;
		}
		return list;
	}

	private static bool HasGrowSpace(Vector3 newPos, GameObject go)
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		Plant component = go.GetComponent<Plant>();
		if (component != null)
		{
			return Physics.OverlapSphere(newPos, component.m_growRadius, _plantSpaceMask).Length == 0;
		}
		return true;
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(Player), "SetupPlacementGhost")]
	public static void SetupPlacementGhostPrefix(Player __instance, int ___m_placeRotation)
	{
		if (IsHotKeyPressed)
		{
			int? num = massFarmingRotation;
			if (!num.HasValue)
			{
				massFarmingRotation = ___m_placeRotation;
			}
		}
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(Player), "SetupPlacementGhost")]
	public static void SetupPlacementGhostPostfix(Player __instance, ref int ___m_placeRotation)
	{
		if (IsHotKeyPressed && massFarmingRotation.HasValue)
		{
			___m_placeRotation = massFarmingRotation.Value;
		}
		DestroyGhosts();
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(Player), "UpdatePlacementGhost")]
	public static void UpdatePlacementGhostPostfix(Player __instance, bool flashGuardStone)
	{
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Expected O, but got Unknown
		//IL_002d: 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_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: 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_0050: 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)
		//IL_0121: 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_0145: Unknown result type (might be due to invalid IL or missing references)
		//IL_014a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0152: Unknown result type (might be due to invalid IL or missing references)
		//IL_0157: 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_01b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = (GameObject)m_placementGhostField.GetValue(__instance);
		if (!Object.op_Implicit((Object)(object)val) || !val.activeSelf)
		{
			SetGhostsActive(active: false);
			return;
		}
		KeyboardShortcut value = MassFarming.ControllerPickupHotkey.Value;
		if (!Input.GetKey(((KeyboardShortcut)(ref value)).MainKey))
		{
			value = MassFarming.MassActionHotkey.Value;
			if (!Input.GetKey(((KeyboardShortcut)(ref value)).MainKey))
			{
				SetGhostsActive(active: false);
				return;
			}
		}
		Plant component = val.GetComponent<Plant>();
		if (!Object.op_Implicit((Object)(object)component))
		{
			SetGhostsActive(active: false);
			return;
		}
		if (!EnsureGhostsBuilt(__instance))
		{
			SetGhostsActive(active: false);
			return;
		}
		Requirement val2 = ((IEnumerable<Requirement>)val.GetComponent<Piece>().m_resources).FirstOrDefault((Func<Requirement, bool>)((Requirement r) => Object.op_Implicit((Object)(object)r.m_resItem) && r.m_amount > 0));
		_fakeResourcePiece.m_resources[0].m_resItem = val2.m_resItem;
		_fakeResourcePiece.m_resources[0].m_amount = val2.m_amount;
		float num = __instance.GetStamina();
		object? obj = _GetRightItemMethod.Invoke(__instance, Array.Empty<object>());
		ItemData val3 = (ItemData)((obj is ItemData) ? obj : null);
		if (val3 == null)
		{
			return;
		}
		Heightmap val4 = Heightmap.FindHeightmap(val.transform.position);
		List<Vector3> list = BuildPlantingGridPositions(val.transform.position, component, val.transform.rotation);
		for (int i = 0; i < _placementGhosts.Length; i++)
		{
			Vector3 val5 = list[i];
			if (val.transform.position == val5)
			{
				_placementGhosts[i].SetActive(false);
				continue;
			}
			Requirement obj2 = _fakeResourcePiece.m_resources[0];
			obj2.m_amount += val2.m_amount;
			_placementGhosts[i].transform.position = val5;
			_placementGhosts[i].transform.rotation = val.transform.rotation;
			_placementGhosts[i].SetActive(true);
			bool invalidPlacementHeightlight = false;
			if (val.GetComponent<Piece>().m_cultivatedGroundOnly && !val4.IsCultivated(val5))
			{
				invalidPlacementHeightlight = true;
			}
			else if (!HasGrowSpace(val5, val.gameObject))
			{
				invalidPlacementHeightlight = true;
			}
			else if (!MassFarming.IgnoreStamina.Value && num < val3.m_shared.m_attack.m_attackStamina)
			{
				Hud.instance.StaminaBarUppgradeFlash();
				invalidPlacementHeightlight = true;
			}
			else if (!(bool)m_noPlacementCostField.GetValue(__instance) && !__instance.HaveRequirements(_fakeResourcePiece, (RequirementMode)0))
			{
				invalidPlacementHeightlight = true;
			}
			num -= val3.m_shared.m_attack.m_attackStamina;
			_placementGhosts[i].GetComponent<Piece>().SetInvalidPlacementHeightlight(invalidPlacementHeightlight);
		}
	}

	private static bool EnsureGhostsBuilt(Player player)
	{
		//IL_00da: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e0: Expected O, but got Unknown
		int num = MassFarming.PlantGridWidth.Value * MassFarming.PlantGridLength.Value;
		if (!Object.op_Implicit((Object)(object)_placementGhosts[0]) || _placementGhosts.Length != num)
		{
			DestroyGhosts();
			if (_placementGhosts.Length != num)
			{
				_placementGhosts = (GameObject[])(object)new GameObject[num];
			}
			object? value = m_buildPiecesField.GetValue(player);
			PieceTable val = (PieceTable)((value is PieceTable) ? value : null);
			if (val != null)
			{
				GameObject selectedPrefab = val.GetSelectedPrefab();
				if (selectedPrefab != null)
				{
					if (selectedPrefab.GetComponent<Piece>().m_repairPiece)
					{
						return false;
					}
					for (int i = 0; i < _placementGhosts.Length; i++)
					{
						_placementGhosts[i] = SetupMyGhost(player, selectedPrefab);
					}
					goto IL_00a1;
				}
			}
			return false;
		}
		goto IL_00a1;
		IL_00a1:
		if (!Object.op_Implicit((Object)(object)_fakeResourcePiece))
		{
			_fakeResourcePiece = _placementGhosts[0].GetComponent<Piece>();
			_fakeResourcePiece.m_dlc = string.Empty;
			_fakeResourcePiece.m_resources = (Requirement[])(object)new Requirement[1]
			{
				new Requirement()
			};
		}
		return true;
	}

	private static void DestroyGhosts()
	{
		for (int i = 0; i < _placementGhosts.Length; i++)
		{
			if (Object.op_Implicit((Object)(object)_placementGhosts[i]))
			{
				Object.Destroy((Object)(object)_placementGhosts[i]);
				_placementGhosts[i] = null;
			}
		}
		_fakeResourcePiece = null;
	}

	private static void SetGhostsActive(bool active)
	{
		GameObject[] placementGhosts = _placementGhosts;
		foreach (GameObject obj in placementGhosts)
		{
			if (obj != null)
			{
				obj.SetActive(active);
			}
		}
	}

	private static GameObject SetupMyGhost(Player player, GameObject prefab)
	{
		//IL_0166: Unknown result type (might be due to invalid IL or missing references)
		//IL_016d: Expected O, but got Unknown
		ZNetView.m_forceDisableInit = true;
		GameObject val = Object.Instantiate<GameObject>(prefab);
		ZNetView.m_forceDisableInit = false;
		((Object)val).name = ((Object)prefab).name;
		Joint[] componentsInChildren = val.GetComponentsInChildren<Joint>();
		for (int i = 0; i < componentsInChildren.Length; i++)
		{
			Object.Destroy((Object)(object)componentsInChildren[i]);
		}
		Rigidbody[] componentsInChildren2 = val.GetComponentsInChildren<Rigidbody>();
		for (int i = 0; i < componentsInChildren2.Length; i++)
		{
			Object.Destroy((Object)(object)componentsInChildren2[i]);
		}
		int layer = LayerMask.NameToLayer("ghost");
		Transform[] componentsInChildren3 = val.GetComponentsInChildren<Transform>();
		for (int i = 0; i < componentsInChildren3.Length; i++)
		{
			((Component)componentsInChildren3[i]).gameObject.layer = layer;
		}
		TerrainModifier[] componentsInChildren4 = val.GetComponentsInChildren<TerrainModifier>();
		for (int i = 0; i < componentsInChildren4.Length; i++)
		{
			Object.Destroy((Object)(object)componentsInChildren4[i]);
		}
		GuidePoint[] componentsInChildren5 = val.GetComponentsInChildren<GuidePoint>();
		for (int i = 0; i < componentsInChildren5.Length; i++)
		{
			Object.Destroy((Object)(object)componentsInChildren5[i]);
		}
		Light[] componentsInChildren6 = val.GetComponentsInChildren<Light>();
		for (int i = 0; i < componentsInChildren6.Length; i++)
		{
			Object.Destroy((Object)(object)componentsInChildren6[i]);
		}
		Transform val2 = val.transform.Find("_GhostOnly");
		if (Object.op_Implicit((Object)(object)val2))
		{
			((Component)val2).gameObject.SetActive(true);
		}
		MeshRenderer[] componentsInChildren7 = val.GetComponentsInChildren<MeshRenderer>();
		foreach (MeshRenderer val3 in componentsInChildren7)
		{
			if (!((Object)(object)((Renderer)val3).sharedMaterial == (Object)null))
			{
				Material[] sharedMaterials = ((Renderer)val3).sharedMaterials;
				for (int j = 0; j < sharedMaterials.Length; j++)
				{
					Material val4 = new Material(sharedMaterials[j]);
					val4.SetFloat("_RippleDistance", 0f);
					val4.SetFloat("_ValueNoise", 0f);
					sharedMaterials[j] = val4;
				}
				((Renderer)val3).sharedMaterials = sharedMaterials;
				((Renderer)val3).shadowCastingMode = (ShadowCastingMode)0;
			}
		}
		return val;
	}
}