Decompiled source of Watering Can v1.2.0

plugins/WateringCan.dll

Decompiled 5 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using PEAKLib.Core;
using PEAKLib.Items.UnityEditor;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine;
using Zorro.Core;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("WateringCan")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.2.0.0")]
[assembly: AssemblyInformationalVersion("1.2.0+3e05835ae86058a1c070a46a1ec86710a06e55b2")]
[assembly: AssemblyProduct("WateringCan")]
[assembly: AssemblyTitle("Watering Can")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.2.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace WateringCan
{
	[HarmonyPatch(typeof(Character), "Awake")]
	public class CharacterAwakePatch
	{
		public static void Postfix(Character __instance)
		{
			if ((Object)(object)((Component)__instance).gameObject.GetComponent<WateringCan_CustomMethods>() == (Object)null)
			{
				Plugin.Log.LogInfo((object)("Adding CustomMethods.cs to " + __instance.characterName + "'s character."));
				((Component)__instance).gameObject.AddComponent<WateringCan_CustomMethods>();
			}
		}
	}
	[HarmonyPatch(typeof(ItemCooking), "FinishCookingImpl")]
	public class FinishCookingImplPatch
	{
		public static void Postfix(ItemCooking __instance)
		{
			WateringCanItem component = ((Component)__instance).GetComponent<WateringCanItem>();
			if (!((Object)(object)component == (Object)null))
			{
				component.VaporizeWater();
			}
		}
	}
	[HarmonyPatch(typeof(RunManager), "StartRun")]
	public static class StartRunPatch
	{
		private static void Postfix()
		{
			Plugin.bushGrowthProgress.Clear();
			Plugin.stalkLength.Clear();
		}
	}
	[HarmonyPatch(typeof(Character), "RPCEndGame")]
	public static class RPCEndGamePatch
	{
		private static void Postfix()
		{
			Plugin.bushGrowthProgress.Clear();
			Plugin.stalkLength.Clear();
		}
	}
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("WateringCan", "Watering Can", "1.2.0")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ModDefinition modDefinition = null;

		internal static ConfigEntry<bool> showWateringSphere = null;

		private static Dictionary<string, Shader> _peakShaders = null;

		public static SFX_Instance SFXICannotGrow = null;

		public static Dictionary<GameObject, int> bushGrowthProgress = new Dictionary<GameObject, int>();

		public static Dictionary<Transform, float> stalkLength = new Dictionary<Transform, float>();

		public const string Id = "WateringCan";

		internal static ManualLogSource Log { get; private set; } = null;

		internal static Dictionary<string, Shader> PeakShaders
		{
			get
			{
				if (_peakShaders == null)
				{
					List<string> list = new List<string> { "SmokeParticle" };
					_peakShaders = new Dictionary<string, Shader>();
					foreach (string item in list)
					{
						Shader val = Shader.Find(item);
						if (!((Object)(object)val == (Object)null))
						{
							_peakShaders[item] = val;
						}
					}
				}
				return _peakShaders;
			}
		}

		public static string Name => "Watering Can";

		public static string Version => "1.2.0";

		private void Awake()
		{
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fa: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			modDefinition = ModDefinition.GetOrCreate(((BaseUnityPlugin)this).Info.Metadata);
			Log.LogInfo((object)"Plugin Watering Can is loaded!");
			showWateringSphere = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "Show Watering Sphere", false, "If true, allows to toggle the visibility of the watering sphere.");
			BundleLoader.LoadBundleAndContentsWithName((BaseUnityPlugin)(object)this, "watering_can_bundle.peakbundle", (Action<PeakBundle>)delegate(PeakBundle bundle)
			{
				UnityItemContent val2 = bundle.LoadAsset<UnityItemContent>("Watering_Can");
				WateringCanItem wateringCanItem = ((Component)val2.Item).gameObject.AddComponent<WateringCanItem>();
				((Component)val2.Item).gameObject.AddComponent<WateringCanVFX>();
				GameObject val3 = bundle.LoadAsset<GameObject>("VFX_Leaves");
				NetworkPrefabManager.RegisterNetworkPrefab(modDefinition, val3);
				GameObject val4 = bundle.LoadAsset<GameObject>("VFX_Palms");
				NetworkPrefabManager.RegisterNetworkPrefab(modDefinition, val4);
				GameObject val5 = bundle.LoadAsset<GameObject>("VFX_Snow");
				NetworkPrefabManager.RegisterNetworkPrefab(modDefinition, val5);
				ParticleSystemRenderer component = ((Component)val5.GetComponent<ParticleSystem>()).GetComponent<ParticleSystemRenderer>();
				((Renderer)component).material = Resources.FindObjectsOfTypeAll<Material>().ToList().Find((Material m) => ((Object)m).name == "Snowflake softy");
				((Renderer)component).material.shader = PeakShaders["SmokeParticle"];
				GameObject val6 = bundle.LoadAsset<GameObject>("VFX_Thorns");
				NetworkPrefabManager.RegisterNetworkPrefab(modDefinition, val6);
				GameObject val7 = bundle.LoadAsset<GameObject>("VFX_Vine");
				NetworkPrefabManager.RegisterNetworkPrefab(modDefinition, val7);
				SFXICannotGrow = bundle.LoadAsset<SFX_Instance>("SFXI_CannotGrow");
			});
			LocalizedText.mainTable["NAME_WATERING CAN"] = new List<string>(13)
			{
				"WATERING CAN", "ARROSOIR", "ANNAFFIATOIO", "GIEẞKANNE", "REGADERA", "REGADERA", "REGADOR", "ЛЕЙКА", "ЛІЙКА", "喷壶",
				"噴壺", "じょうろ", "물뿌리개", "KONEWKA", "SULAMA KABI"
			};
			LocalizedText.mainTable["POUR WATER"] = new List<string>(13)
			{
				"pour water", "verser de l'eau", "versare acqua", "wasser gießen", "verter agua", "verter agua", "despeje água", "налить воду", "налити воду", "倒水",
				"倒水", "水を注ぎ", "물을 붓다", "wlać wodę", "su dökmek"
			};
			Harmony val = new Harmony("com.github.DaxxPurpura.WateringCan");
			val.PatchAll();
		}
	}
	public class WateringCanItem : ItemComponent
	{
		public const float INITIAL_POUR_COST = 0f;

		public const float TOTAL_POUR_TIME = 10f;

		public bool pouring;

		public float interactionRadius = 1f;

		public LayerMask INTERACTION_LAYERS = LayerMask.op_Implicit(LayerMask.GetMask(new string[4] { "Map", "Terrain", "Character", "Default" }));

		public Transform overlapSphereDefault;

		public Transform overlapSphereUp;

		public Vector3 overlapSpherePos;

		public bool isOverlapSphereVisible;

		public const float SELF_WATER_ANGLE = 0.8f;

		public StormVisual rainVisual;

		public const float RAIN_REFILL_AMOUNT = 0.05f;

		public GameObject[] waterZones;

		public GameObject[] heatZones;

		public const float WATER_POOLS_RADIUS = 4.5f;

		public const float WATER_POOLS_Y_THRESHOLD = 0.9f;

		public const int FRUIT_GROW_TIME = 23;

		public const float MAX_STALK_LENGTH = 30f;

		public float stalkGrowTick;

		public const float STALK_GROW_AMOUNT = 1f;

		public const float STALK_WIDTH_AMOUNT = 0.03f;

		public const float COOL_OFF_PLAYER_AMOUNT = 0.025f;

		public const float COOL_OFF_PLAYER_COOLDOWN = 0.25f;

		[SerializeField]
		public float water;

		public float generalTick;

		public override void Awake()
		{
			((ItemComponent)this).Awake();
			Item item = base.item;
			item.OnPrimaryStarted = (Action)Delegate.Combine(item.OnPrimaryStarted, new Action(StartPour));
			Item item2 = base.item;
			item2.OnPrimaryCancelled = (Action)Delegate.Combine(item2.OnPrimaryCancelled, new Action(CancelPour));
			overlapSphereDefault = ((Component)this).transform.Find("Overlap_Sphere_Default");
			overlapSphereUp = ((Component)this).transform.Find("Overlap_Sphere_Up");
			((Component)((Component)this).transform.Find("Sphere")).gameObject.SetActive(isOverlapSphereVisible);
			GameObject val = GameObject.FindGameObjectWithTag("Rain");
			if ((Object)(object)val != (Object)null)
			{
				rainVisual = val.GetComponent<StormVisual>();
			}
			waterZones = (from gameObject in Object.FindObjectsByType<GameObject>((FindObjectsSortMode)0)
				where ((Object)gameObject).name.Contains("WaterZone") && ((Object)gameObject).name != "WaterZoneBase" && gameObject.activeInHierarchy
				select gameObject).ToArray();
			heatZones = (from gameObject in Object.FindObjectsByType<GameObject>((FindObjectsSortMode)0)
				where ((Object)gameObject).name == "heat zone" && gameObject.activeInHierarchy
				select gameObject).ToArray();
		}

		public void OnDestroy()
		{
			Item item = base.item;
			item.OnPrimaryHeld = (Action)Delegate.Remove(item.OnPrimaryHeld, new Action(StartPour));
			Item item2 = base.item;
			item2.OnPrimaryCancelled = (Action)Delegate.Remove(item2.OnPrimaryCancelled, new Action(CancelPour));
		}

		public override void OnInstanceDataSet()
		{
			if (((ItemComponent)this).HasData((DataEntryKey)10))
			{
				water = ((ItemComponent)this).GetData<FloatItemData>((DataEntryKey)10).Value;
				base.item.SetUseRemainingPercentage(water / 10f);
			}
			else if (((MonoBehaviourPun)this).photonView.IsMine)
			{
				water = 10f;
				base.item.SetUseRemainingPercentage(1f);
			}
		}

		public void Update()
		{
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			generalTick -= Time.deltaTime;
			UpdatePour();
			if (generalTick <= 0f)
			{
				if (water != 10f)
				{
					CheckRefillWater();
				}
				generalTick = 0.1f;
			}
			if (Plugin.showWateringSphere.Value && Input.GetKeyDown((KeyCode)111))
			{
				isOverlapSphereVisible = !isOverlapSphereVisible;
				((Component)((Component)this).transform.Find("Sphere")).gameObject.SetActive(isOverlapSphereVisible);
				Plugin.Log.LogInfo((object)"Watering sphere toggled");
			}
			overlapSpherePos = overlapSphereDefault.position;
			if (overlapSphereDefault.position.y - ((Component)this).transform.position.y > 0.8f)
			{
				overlapSpherePos = overlapSphereUp.position;
			}
			if (isOverlapSphereVisible)
			{
				((Component)this).transform.Find("Sphere").position = overlapSpherePos;
			}
		}

		public void UpdatePour()
		{
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			if (!pouring || !((MonoBehaviourPun)this).photonView.IsMine)
			{
				return;
			}
			water -= Time.deltaTime;
			if (water <= 0f)
			{
				water = 0f;
				CancelPour();
			}
			else if (generalTick <= 0f)
			{
				Collider[] array = Physics.OverlapSphere(overlapSpherePos, interactionRadius, LayerMask.op_Implicit(INTERACTION_LAYERS));
				Collider[] array2 = array;
				foreach (Collider val in array2)
				{
					if (!((Object)(object)((Component)val).transform == (Object)(object)((Component)this).transform) && !((Component)val).transform.IsChildOf(((Component)this).transform))
					{
						WaterInteraction(((Component)val).gameObject);
					}
				}
			}
			((ItemComponent)this).GetData<FloatItemData>((DataEntryKey)10).Value = water;
			base.item.SetUseRemainingPercentage(water / 10f);
		}

		public void WaterInteraction(GameObject target)
		{
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Invalid comparison between Unknown and I4
			if (((Object)target).name.Contains("berrybush ") && target.gameObject.layer == 21)
			{
				GrowFruitOnBush(target);
			}
			else if ((((Object)target).name.Contains("Mesh") || ((Object)target).name.Contains("Ice_DeadTree") || ((Object)target).name.Contains("Cactus")) && target.gameObject.layer == 21 && Object.op_Implicit((Object)(object)((Component)target.transform.parent).GetComponent<BerryBush>()))
			{
				GrowFruitOnBush(((Component)target.transform.parent).gameObject);
			}
			else if (((Object)target).name == "Stalk" && target.gameObject.layer == 20)
			{
				GrowMagicBean(target.transform.parent);
			}
			else if (((Object)target).name == "RigCollider" && target.gameObject.layer == 10)
			{
				GameObject gameObject = ((Component)target.transform.root).gameObject;
				if (!(gameObject.GetComponent<CharacterAfflictions>().GetCurrentStatus((STATUSTYPE)8) <= 0f) && !(gameObject.GetComponent<WateringCan_CustomMethods>().coolOffCooldown > 0f))
				{
					((MonoBehaviourPun)this).photonView.RPC("RPC_CoolOffPlayer", (RpcTarget)0, new object[1] { PunExtensions.GetPhotonView(gameObject) });
				}
			}
			else if (((Object)target.transform.root).name.Contains("Dynamite") && ((ItemComponent)((Component)target.transform.root).gameObject.GetComponent<Dynamite>()).GetData<BoolItemData>((DataEntryKey)3).Value)
			{
				((MonoBehaviourPun)this).photonView.RPC("RPC_AnRPCToAddAnRPCLol", (RpcTarget)0, new object[1] { PunExtensions.GetPhotonView(((Component)target.transform.root).gameObject) });
			}
			else if (Object.op_Implicit((Object)(object)((Component)target.transform.parent).GetComponent<Campfire>()) && (int)((Component)target.transform.parent).GetComponent<Campfire>().state == 1)
			{
				((Component)target.transform.parent).GetComponent<PhotonView>().RPC("Extinguish_Rpc", (RpcTarget)3, Array.Empty<object>());
			}
		}

		public void GrowFruitOnBush(GameObject bush)
		{
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			if (Plugin.bushGrowthProgress == null)
			{
				return;
			}
			Dictionary<GameObject, int> bushGrowthProgress = Plugin.bushGrowthProgress;
			BerryBush component = bush.GetComponent<BerryBush>();
			if (!bushGrowthProgress.ContainsKey(bush))
			{
				Plugin.bushGrowthProgress[bush] = 0;
				Transform val = FindFreeSpawnSpot(((Spawner)component).GetSpawnSpots());
				if ((Object)(object)val == (Object)null)
				{
					if ((Object)(object)bush.GetComponent<WateringCan_ShakeFeedback>() == (Object)null)
					{
						bush.AddComponent<WateringCan_ShakeFeedback>();
					}
					bush.GetComponent<WateringCan_ShakeFeedback>().Shake();
					Plugin.bushGrowthProgress.Remove(bush);
					Plugin.Log.LogInfo((object)"No free spawn spots");
					return;
				}
			}
			Plugin.Log.LogInfo((object)$"Growing fruit in {((Object)bush).name} ({bushGrowthProgress[bush] * 100 / 23}%)");
			if (bushGrowthProgress[bush] < 23)
			{
				Plugin.bushGrowthProgress[bush]++;
			}
			if (bushGrowthProgress[bush] >= 23)
			{
				Plugin.bushGrowthProgress.Remove(bush);
				Transform val2 = FindFreeSpawnSpot(((Spawner)component).GetSpawnSpots());
				if ((Object)(object)val2 == (Object)null)
				{
					Plugin.Log.LogInfo((object)"No free spawn spots");
					return;
				}
				GameObject randomItem = LootData.GetRandomItem(((Spawner)component).GetSpawnPool(), false);
				((MonoBehaviourPun)Character.localCharacter).photonView.RPC("RPC_InstantiateFruit", (RpcTarget)2, new object[3]
				{
					((Object)randomItem).name,
					val2.position,
					((Object)bush).name
				});
			}
		}

		public Transform? FindFreeSpawnSpot(List<Transform> spawnSpots)
		{
			List<Transform> list = new List<Transform>(spawnSpots);
			for (int num = list.Count - 1; num > 0; num--)
			{
				int num2 = Random.Range(0, num + 1);
				List<Transform> list2 = list;
				int index = num;
				int index2 = num2;
				Transform value = list[num2];
				Transform value2 = list[num];
				list2[index] = value;
				list[index2] = value2;
			}
			foreach (Transform item in list)
			{
				if (IsSpawnSpotFree(item))
				{
					return item;
				}
			}
			return null;
		}

		public bool IsSpawnSpotFree(Transform spot)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			Collider[] array = Physics.OverlapSphere(spot.position, 0.1f);
			Collider[] array2 = array;
			foreach (Collider val in array2)
			{
				if (!((Component)val).transform.IsChildOf(spot.root) && !val.isTrigger)
				{
					return false;
				}
			}
			return true;
		}

		public void GrowMagicBean(Transform vine)
		{
			if (!Object.op_Implicit((Object)(object)((ItemComponent)this).holderCharacter))
			{
				return;
			}
			Dictionary<Transform, float> stalkLength = Plugin.stalkLength;
			if (!stalkLength.ContainsKey(vine))
			{
				Plugin.stalkLength[vine] = GetVineDistance(vine);
			}
			float maxLength = ((Component)vine).GetComponentInParent<MagicBeanVine>().maxLength;
			if (maxLength < stalkLength[vine])
			{
				stalkGrowTick -= Time.deltaTime;
				if (!(stalkGrowTick > 0f))
				{
					if (maxLength + 1f >= stalkLength[vine])
					{
						((Component)vine).GetComponentInParent<MagicBeanVine>().maxLength = stalkLength[vine];
						MagicBeanVine componentInParent = ((Component)vine).GetComponentInParent<MagicBeanVine>();
						componentInParent.maxWidth += 0.03f;
						((Component)vine).GetComponentInParent<MagicBeanVine>().Grow();
						Plugin.Log.LogInfo((object)$"Vine growing to {((Component)vine).GetComponentInParent<MagicBeanVine>().maxLength}. Max length reached!");
						Plugin.stalkLength.Remove(vine);
					}
					else
					{
						MagicBeanVine componentInParent2 = ((Component)vine).GetComponentInParent<MagicBeanVine>();
						componentInParent2.maxLength += 1f;
						MagicBeanVine componentInParent3 = ((Component)vine).GetComponentInParent<MagicBeanVine>();
						componentInParent3.maxWidth += 0.03f;
						((Component)vine).GetComponentInParent<MagicBeanVine>().Grow();
						Plugin.Log.LogInfo((object)$"Vine growing to {((Component)vine).GetComponentInParent<MagicBeanVine>().maxLength}");
						stalkGrowTick = 0.05f;
					}
				}
			}
			else
			{
				if ((Object)(object)((Component)vine).GetComponent<WateringCan_ShakeFeedback>() == (Object)null)
				{
					((Component)vine).gameObject.AddComponent<WateringCan_ShakeFeedback>();
				}
				((Component)vine).GetComponent<WateringCan_ShakeFeedback>().Shake();
				Plugin.stalkLength.Remove(vine);
				Plugin.Log.LogInfo((object)"Vine can't increase in length!");
			}
		}

		public float GetVineDistance(Transform vine)
		{
			//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_0018: 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_0027: 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)
			RaycastHit[] array = (RaycastHit[])(object)new RaycastHit[128];
			int num = HelperFunctions.LineCheckAll(vine.position, vine.position + vine.up * 30f, (LayerType)1, array, 0f, (QueryTriggerInteraction)1);
			float num2 = 30f;
			for (int i = 0; i < num; i++)
			{
				RaycastHit val = array[i];
				if (Object.op_Implicit((Object)(object)((RaycastHit)(ref val)).collider) && ((RaycastHit)(ref val)).distance > 0.7f && ((RaycastHit)(ref val)).distance < num2)
				{
					num2 = ((RaycastHit)(ref val)).distance;
				}
			}
			return num2;
		}

		public void CheckRefillWater()
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: 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)
			GameObject[] array = waterZones;
			foreach (GameObject val in array)
			{
				if (((Bounds)(ref val.GetComponent<WaterZone>().zoneBounds)).Contains(((Component)this).transform.position - Vector3.up * 0.2f))
				{
					RefillWaterFull();
					return;
				}
			}
			if (IsWaterPoolNear())
			{
				RefillWaterFull();
			}
			else if (IsRaining() && water < 10f)
			{
				water += 0.05f;
				((ItemComponent)this).GetData<FloatItemData>((DataEntryKey)10).Value = water;
				base.item.SetUseRemainingPercentage(water / 10f);
				Plugin.Log.LogInfo((object)$"Slowly refilling Watering Can! ({Math.Round(water * 10f)}%)");
			}
		}

		public bool IsWaterPoolNear()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Invalid comparison between Unknown and I4
			//IL_0031: 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)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)Singleton<MapHandler>.Instance == (Object)null || (int)Singleton<MapHandler>.Instance.GetCurrentSegment() != 2)
			{
				return false;
			}
			GameObject[] array = heatZones;
			foreach (GameObject val in array)
			{
				if (Vector3.Distance(((Component)this).transform.position, val.transform.position) <= 4.5f)
				{
					float num = ((Component)this).transform.position.y - val.transform.position.y;
					if (num >= -0.9f && num <= 0.9f)
					{
						return true;
					}
				}
			}
			return false;
		}

		public void RefillWaterFull()
		{
			water = 10f;
			((ItemComponent)this).GetData<FloatItemData>((DataEntryKey)10).Value = water;
			base.item.SetUseRemainingPercentage(1f);
			Plugin.Log.LogInfo((object)"Refilling Watering Can!");
		}

		public bool IsRaining()
		{
			if ((Object)(object)rainVisual == (Object)null)
			{
				return false;
			}
			if (rainVisual.observedPlayerInWindZone)
			{
				return true;
			}
			return false;
		}

		private void OnTriggerEnter(Collider collider)
		{
			if (water != 10f && ((Object)((Component)collider).transform.parent.parent).name.Contains("Waterfall_Spline"))
			{
				RefillWaterFull();
			}
		}

		public void StartPour()
		{
			if (water >= 0f)
			{
				water -= 0f;
				pouring = true;
				base.item.SetUseRemainingPercentage(water / 10f);
			}
			else
			{
				water = 0f;
				pouring = true;
				base.item.SetUseRemainingPercentage(water / 10f);
			}
		}

		public void CancelPour()
		{
			pouring = false;
		}

		[PunRPC]
		public void RPC_CoolOffPlayer(PhotonView characterView)
		{
			Player owner = characterView.Owner;
			if (owner != null)
			{
				if (owner.IsLocal)
				{
					Character.localCharacter.refs.afflictions.SubtractStatus((STATUSTYPE)8, 0.025f, false, false);
				}
				((Component)((Component)characterView).transform.root).gameObject.GetComponent<WateringCan_CustomMethods>().coolOffCooldown = 0.25f;
				Plugin.Log.LogInfo((object)("Cooling off " + owner.NickName));
			}
		}

		[PunRPC]
		public void RPC_AnRPCToAddAnRPCLol(PhotonView dynamiteView)
		{
			GameObject gameObject = ((Component)((Component)dynamiteView).transform.root).gameObject;
			if ((Object)(object)gameObject.GetComponent<WateringCan_SetFlareUnlitRPC>() == (Object)null)
			{
				gameObject.AddComponent<WateringCan_SetFlareUnlitRPC>();
			}
			dynamiteView.RPC("SetFlareUnlitRPC", (RpcTarget)0, Array.Empty<object>());
		}

		public void VaporizeWater()
		{
			water = 0f;
			((ItemComponent)this).GetData<FloatItemData>((DataEntryKey)10).Value = 0f;
			base.item.SetUseRemainingPercentage(0f);
			Plugin.Log.LogInfo((object)"Vaporizing water!");
		}
	}
	public class WateringCanVFX : MonoBehaviourPun
	{
		public Item item;

		public bool isPouring;

		public bool audioStarted;

		public AudioSource audioSource;

		public ParticleSystem particle;

		public GameObject waterLevel;

		public const float MIN_WATER_LEVEL_POS = 0.000425f;

		public const float MAX_WATER_LEVEL_POS = 0.0056f;

		public const float VOLUME = 0.1f;

		public WateringCanItem wateringCanItem;

		public void Start()
		{
			item = ((Component)this).GetComponent<Item>();
			audioSource = ((Component)((Component)this).transform.Find("Audio_Source")).GetComponent<AudioSource>();
			particle = ((Component)((Component)this).transform.Find("Water_VFX")).GetComponent<ParticleSystem>();
			waterLevel = ((Component)((Component)this).transform.Find("watering_can_B").Find("Water_Level")).gameObject;
			wateringCanItem = ((Component)this).GetComponent<WateringCanItem>();
		}

		public void Update()
		{
			//IL_003d: 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_005d: Unknown result type (might be due to invalid IL or missing references)
			UpdatePouringWater();
			float num = Mathf.Lerp(0.000425f, 0.0056f, wateringCanItem.water / 10f);
			waterLevel.transform.localPosition = new Vector3(waterLevel.transform.localPosition.x, num, waterLevel.transform.localPosition.z);
			if (isPouring && !audioStarted)
			{
				audioSource.Play();
				audioSource.volume = 0f;
				audioStarted = true;
			}
			if (isPouring)
			{
				audioSource.volume = Mathf.Lerp(audioSource.volume, 0.1f, 10f * Time.deltaTime);
			}
			if (!isPouring)
			{
				audioSource.volume = Mathf.Lerp(audioSource.volume, 0f, 10f * Time.deltaTime);
				if (audioSource.volume <= 0.01f)
				{
					audioSource.Stop();
				}
			}
			if (!isPouring && audioStarted)
			{
				audioStarted = false;
			}
		}

		public void UpdatePouringWater()
		{
			if (!((MonoBehaviourPun)this).photonView.IsMine || !Object.op_Implicit((Object)(object)wateringCanItem))
			{
				return;
			}
			bool flag = wateringCanItem.pouring;
			if (wateringCanItem.water <= 0f)
			{
				flag = false;
			}
			if (flag != isPouring)
			{
				if (flag)
				{
					((MonoBehaviourPun)this).photonView.RPC("RPC_StartPouringWater", (RpcTarget)0, Array.Empty<object>());
				}
				else
				{
					((MonoBehaviourPun)this).photonView.RPC("RPC_EndPouringWater", (RpcTarget)0, Array.Empty<object>());
				}
				isPouring = flag;
			}
		}

		[PunRPC]
		public void RPC_StartPouringWater()
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			isPouring = true;
			if (Object.op_Implicit((Object)(object)particle))
			{
				if (!particle.isPlaying)
				{
					particle.Play();
				}
				EmissionModule emission = particle.emission;
				((EmissionModule)(ref emission)).enabled = true;
			}
		}

		[PunRPC]
		public void RPC_EndPouringWater()
		{
			//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)
			isPouring = false;
			if (Object.op_Implicit((Object)(object)particle))
			{
				EmissionModule emission = particle.emission;
				((EmissionModule)(ref emission)).enabled = false;
			}
		}
	}
	public class WateringCan_CustomMethods : MonoBehaviourPun
	{
		public float coolOffCooldown;

		public void Update()
		{
			if (coolOffCooldown > 0f)
			{
				coolOffCooldown -= Time.deltaTime;
			}
		}

		[PunRPC]
		public void RPC_InstantiateFruit(string fruitName, Vector3 spawnSpot, string bushName)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: 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_0044: 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_00ad: 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_00eb: 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_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = PhotonNetwork.InstantiateItemRoom(fruitName, spawnSpot, Quaternion.identity, true);
			val.GetComponent<PhotonView>().RPC("SetKinematicRPC", (RpcTarget)3, new object[3]
			{
				true,
				val.transform.position,
				val.transform.rotation
			});
			((MonoBehaviourPun)this).photonView.RPC("RPC_AddGrowFruitComponent", (RpcTarget)0, new object[1] { val.GetComponent<PhotonView>() });
			if (bushName.Contains("berrybush ") || bushName.Contains("Jungle_Willow"))
			{
				NetworkPrefabManager.SpawnNetworkPrefab(Plugin.modDefinition.Id + ":VFX_Leaves", val.transform.position, Quaternion.identity, (byte)0, (object[])null);
			}
			else if (bushName.Contains("Jungle_PalmTree"))
			{
				NetworkPrefabManager.SpawnNetworkPrefab(Plugin.modDefinition.Id + ":VFX_Palms", val.transform.position, Quaternion.identity, (byte)0, (object[])null);
			}
			else if (bushName.Contains("Ice_DeadTree"))
			{
				NetworkPrefabManager.SpawnNetworkPrefab(Plugin.modDefinition.Id + ":VFX_Snow", val.transform.position, Quaternion.identity, (byte)0, (object[])null);
			}
			else if (bushName.Contains("Cactus"))
			{
				NetworkPrefabManager.SpawnNetworkPrefab(Plugin.modDefinition.Id + ":VFX_Thorns", val.transform.position, Quaternion.identity, (byte)0, (object[])null);
			}
			Plugin.Log.LogInfo((object)(fruitName + " instantiated!"));
		}

		[PunRPC]
		public void RPC_AddGrowFruitComponent(PhotonView fruitPhotonView)
		{
			GameObject gameObject = ((Component)fruitPhotonView).gameObject;
			if ((Object)(object)gameObject.GetComponent<WateringCan_GrowFruit>() == (Object)null)
			{
				gameObject.AddComponent<WateringCan_GrowFruit>();
			}
		}
	}
	public class WateringCan_GrowFruit : MonoBehaviour
	{
		public void Start()
		{
			((MonoBehaviour)this).StartCoroutine(GrowCoroutine());
		}

		public IEnumerator GrowCoroutine()
		{
			float current = 0f;
			float duration = 0.5f;
			while (current < duration)
			{
				current += Time.deltaTime;
				float num = Mathf.Clamp01(current / duration);
				float num2 = 1f - Mathf.Pow(1f - num, 3f);
				((Component)this).transform.localScale = Vector3.one * num2;
				yield return null;
			}
			((Component)this).transform.localScale = Vector3.one;
		}
	}
	public class WateringCan_SetFlareUnlitRPC : ItemComponent
	{
		public void Start()
		{
			Dynamite component = ((Component)this).GetComponent<Dynamite>();
			component.lightFuseRadius = 0f;
			((ItemComponent)component).GetData<BoolItemData>((DataEntryKey)3).Value = false;
			((Component)component.sparks).gameObject.SetActive(false);
			((Component)component.sparksPhotosensitive).gameObject.SetActive(false);
		}

		public override void OnInstanceDataSet()
		{
		}

		[PunRPC]
		public void SetFlareUnlitRPC()
		{
			Dynamite component = ((Component)this).GetComponent<Dynamite>();
			((ItemComponent)component).GetData<BoolItemData>((DataEntryKey)3).Value = false;
			((ItemComponent)component).GetData<FloatItemData>((DataEntryKey)10, (Func<FloatItemData>)component.SetupDefaultFuel).Value = component.startingFuseTime;
			component.lightFuseRadius = 0f;
			((Component)component.sparks).gameObject.SetActive(false);
			((Component)component.sparksPhotosensitive).gameObject.SetActive(false);
			GameObject[] array = (from val2 in Object.FindObjectsByType<GameObject>((FindObjectsSortMode)0)
				where ((Object)val2).name.Contains("VFX_DynamiteSmoke")
				select val2).ToArray();
			GameObject[] array2 = array;
			foreach (GameObject val in array2)
			{
				TrackNetworkedObject component2 = val.GetComponent<TrackNetworkedObject>();
				if ((Object)(object)component2 != (Object)null && (Object)(object)component2.trackedObject != (Object)null && (Object)(object)component2.trackedObject == (Object)(object)component.trackable)
				{
					val.GetComponent<ParticleSystem>().Stop();
					val.GetComponent<AudioLoop>().volume = 0f;
					GameObject gameObject = ((Component)val.transform.Find("end")).gameObject;
					gameObject.GetComponent<SFX_PlayOneShot>().afterPlayAction = DestroySmoke(val);
					gameObject.SetActive(true);
				}
			}
			Plugin.Log.LogInfo((object)"Putting off dynamite!");
		}

		public Action? DestroySmoke(GameObject smoke)
		{
			Object.Destroy((Object)(object)smoke);
			return null;
		}
	}
	public class WateringCan_ShakeFeedback : MonoBehaviourPun
	{
		private const float STRENGTH = 0.125f;

		private float duration;

		private float interval;

		private float xPosition;

		private float zPosition;

		private Dictionary<MeshRenderer, Vector3> originalLocalPos = new Dictionary<MeshRenderer, Vector3>();

		private bool isShaking;

		public void Awake()
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			MeshRenderer[] componentsInChildren = ((Component)this).GetComponentsInChildren<MeshRenderer>();
			foreach (MeshRenderer val in componentsInChildren)
			{
				Plugin.Log.LogInfo((object)1);
				originalLocalPos[val] = ((Component)val).transform.localPosition;
			}
		}

		public void Shake()
		{
			if (!isShaking)
			{
				duration = 1f;
				interval = 0.05f;
				do
				{
					xPosition = 0.125f * (float)Random.Range(-1, 1);
					zPosition = 0.125f * (float)Random.Range(-1, 1);
				}
				while (xPosition == 0f && zPosition == 0f);
				((MonoBehaviour)this).StartCoroutine(ShakeCoroutine());
			}
		}

		public IEnumerator ShakeCoroutine()
		{
			isShaking = true;
			SFX_Player.instance.PlaySFX(Plugin.SFXICannotGrow, ((Component)this).transform.position, (Transform)null, (SFX_Settings)null, 1f, false);
			while (duration > 0f)
			{
				duration -= Time.deltaTime;
				interval -= Time.deltaTime;
				if (interval <= 0f)
				{
					interval = 0.05f;
					xPosition = 0f - xPosition;
					zPosition = 0f - zPosition;
				}
				foreach (KeyValuePair<MeshRenderer, Vector3> originalLocalPo in originalLocalPos)
				{
					((Component)originalLocalPo.Key).transform.localPosition = new Vector3(originalLocalPo.Value.x + xPosition * duration, originalLocalPo.Value.y, originalLocalPo.Value.z + zPosition * duration);
				}
				yield return null;
			}
			foreach (KeyValuePair<MeshRenderer, Vector3> originalLocalPo2 in originalLocalPos)
			{
				((Component)originalLocalPo2.Key).transform.localPosition = originalLocalPo2.Value;
			}
			isShaking = false;
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}