Decompiled source of YourThirsty v3.1.3

YourThirsty.dll

Decompiled 3 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.UI;
using YourThirsty;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
internal class Barrel : MonoBehaviour, Interactable, Hoverable
{
	private const string ZDO_Water = "YT_BarrelWater";

	private const string ZDO_Dirty = "YT_BarrelDirty";

	private ZNetView m_nview;

	private Coroutine _fillRoutine;

	public int MaxWater => ConfigManager.BarrelCapacity.Value;

	private void Awake()
	{
		m_nview = ((Component)this).GetComponent<ZNetView>();
	}

	public int GetStoredWater()
	{
		if ((Object)(object)m_nview == (Object)null || !m_nview.IsValid())
		{
			return 0;
		}
		return m_nview.GetZDO().GetInt("YT_BarrelWater", 0);
	}

	private void SetStoredWater(int amount)
	{
		if (!((Object)(object)m_nview == (Object)null) && m_nview.IsValid())
		{
			m_nview.GetZDO().Set("YT_BarrelWater", Mathf.Clamp(amount, 0, MaxWater));
		}
	}

	public bool IsDirty()
	{
		if ((Object)(object)m_nview == (Object)null || !m_nview.IsValid())
		{
			return false;
		}
		return m_nview.GetZDO().GetBool("YT_BarrelDirty", false);
	}

	private void SetDirty(bool dirty)
	{
		if (!((Object)(object)m_nview == (Object)null) && m_nview.IsValid())
		{
			m_nview.GetZDO().Set("YT_BarrelDirty", dirty);
		}
	}

	public int AddWater(int amount, bool dirty = false)
	{
		int storedWater = GetStoredWater();
		int num = MaxWater - storedWater;
		int num2 = Mathf.Min(amount, num);
		if (num2 > 0)
		{
			SetStoredWater(storedWater + num2);
			if (dirty)
			{
				SetDirty(dirty: true);
			}
		}
		return num2;
	}

	public int AddWater(float amount)
	{
		return AddWater(Mathf.FloorToInt(amount));
	}

	public int TakeWater(int amount)
	{
		int storedWater = GetStoredWater();
		int num = Mathf.Min(amount, storedWater);
		if (num > 0)
		{
			SetStoredWater(storedWater - num);
			if (GetStoredWater() <= 0)
			{
				SetDirty(dirty: false);
			}
		}
		return num;
	}

	public bool Interact(Humanoid user, bool hold, bool alt)
	{
		if (hold)
		{
			return false;
		}
		if (_fillRoutine != null || DrinkSystem.IsBusy)
		{
			return false;
		}
		Player val = (Player)(object)((user is Player) ? user : null);
		if (!Object.op_Implicit((Object)(object)val))
		{
			return false;
		}
		ItemData equippedBucket = BucketItem.GetEquippedBucket(val);
		if (equippedBucket != null && !BucketItem.IsEmpty(equippedBucket) && !BucketItem.IsBoiling(equippedBucket))
		{
			if (MaxWater - GetStoredWater() <= 0)
			{
				((Character)val).Message((MessageType)2, "Barrel is full.", 0, (Sprite)null, false);
				return false;
			}
			_fillRoutine = ((MonoBehaviour)this).StartCoroutine(PourBucketRoutine(val, equippedBucket));
			return true;
		}
		if (ItemManager.CanFill(val, dirty: false, out var state))
		{
			if (GetStoredWater() > 0)
			{
				bool dirty = IsDirty();
				int amount = state.MaxAmount - state.CurrentAmount;
				if (TakeWater(amount) > 0)
				{
					ItemManager.Fill(val, dirty);
					SFXManager.PlayRefill(val);
					((Character)val).Message((MessageType)2, $"Filled from barrel ({GetStoredWater()}/{MaxWater}).", 0, (Sprite)null, false);
					return true;
				}
			}
			((Character)val).Message((MessageType)2, "Barrel is empty.", 0, (Sprite)null, false);
			return false;
		}
		if (ItemManager.CanFillFromInventory(val, dirty: false, out var state2))
		{
			if (GetStoredWater() > 0)
			{
				bool dirty2 = IsDirty();
				int amount2 = state2.MaxAmount - state2.CurrentAmount;
				if (TakeWater(amount2) > 0)
				{
					ItemManager.FillFromInventory(val, dirty2);
					SFXManager.PlayRefill(val);
					((Character)val).Message((MessageType)2, $"Filled from barrel ({GetStoredWater()}/{MaxWater}).", 0, (Sprite)null, false);
					return true;
				}
			}
			((Character)val).Message((MessageType)2, "Barrel is empty.", 0, (Sprite)null, false);
			return false;
		}
		((Character)val).Message((MessageType)2, "You need a Water Bucket to pour, or a Waterskin/Horn to fill.", 0, (Sprite)null, false);
		return false;
	}

	private IEnumerator PourBucketRoutine(Player player, ItemData bucket)
	{
		try
		{
			float timer = 0f;
			bool bucketDirty = BucketItem.IsDirtyWater(bucket);
			int totalWater = BucketItem.GetWater(bucket);
			SFXManager.PlayRefill(player);
			while (timer < 5f)
			{
				if (!((Object)(object)player == (Object)null) && !((Character)player).IsDead() && !((Character)player).IsSwimming())
				{
					Vector3 velocity = ((Character)player).GetVelocity();
					if (!(((Vector3)(ref velocity)).magnitude > 2f))
					{
						timer += Time.deltaTime;
						UIManager.SetFillProgress(timer / 5f);
						yield return null;
						continue;
					}
				}
				float num = timer / 5f;
				if (num > 0.05f)
				{
					int num2 = Mathf.Max(1, Mathf.FloorToInt((float)totalWater * num));
					int num3 = MaxWater - GetStoredWater();
					int num4 = Mathf.Min(num2, num3);
					if (num4 > 0)
					{
						AddWater(num4, bucketDirty);
						BucketItem.SetWater(bucket, totalWater - num4);
						if (totalWater - num4 <= 0)
						{
							BucketItem.SetDirty(bucket, dirty: false);
						}
					}
				}
				UIManager.HideFillBar();
				yield break;
			}
			int num5 = MaxWater - GetStoredWater();
			int num6 = Mathf.Min(totalWater, num5);
			if (num6 > 0)
			{
				AddWater(num6, bucketDirty);
				BucketItem.SetWater(bucket, totalWater - num6);
				if (totalWater - num6 <= 0)
				{
					BucketItem.SetDirty(bucket, dirty: false);
				}
			}
			UIManager.HideFillBar();
			SFXManager.PlayRefill(player);
			((Character)player).Message((MessageType)2, $"Poured water into barrel ({GetStoredWater()}/{MaxWater})", 0, (Sprite)null, false);
		}
		finally
		{
			_fillRoutine = null;
		}
	}

	public bool StartPourBucket(Player player, ItemData bucket)
	{
		if (_fillRoutine != null || DrinkSystem.IsBusy)
		{
			((Character)player).Message((MessageType)2, "Busy — wait for current action to finish.", 0, (Sprite)null, false);
			return false;
		}
		if (MaxWater - GetStoredWater() <= 0)
		{
			((Character)player).Message((MessageType)2, "Barrel is full.", 0, (Sprite)null, false);
			return false;
		}
		_fillRoutine = ((MonoBehaviour)this).StartCoroutine(PourBucketRoutine(player, bucket));
		return true;
	}

	public bool StartPourContainer(Player player, ContainerState state)
	{
		if (_fillRoutine != null || DrinkSystem.IsBusy)
		{
			((Character)player).Message((MessageType)2, "Busy — wait for current action to finish.", 0, (Sprite)null, false);
			return false;
		}
		if (MaxWater - GetStoredWater() <= 0)
		{
			((Character)player).Message((MessageType)2, "Barrel is full.", 0, (Sprite)null, false);
			return false;
		}
		if (state == null || state.CurrentAmount <= 0)
		{
			return false;
		}
		_fillRoutine = ((MonoBehaviour)this).StartCoroutine(PourContainerRoutine(player, state));
		return true;
	}

	private IEnumerator PourContainerRoutine(Player player, ContainerState state)
	{
		try
		{
			float timer = 0f;
			bool containerDirty = state.IsDirty;
			int totalWater = state.CurrentAmount;
			SFXManager.PlayRefill(player);
			while (timer < 4f)
			{
				if (!((Object)(object)player == (Object)null) && !((Character)player).IsDead() && !((Character)player).IsSwimming())
				{
					Vector3 velocity = ((Character)player).GetVelocity();
					if (!(((Vector3)(ref velocity)).magnitude > 2f))
					{
						timer += Time.deltaTime;
						UIManager.SetFillProgress(timer / 4f);
						yield return null;
						continue;
					}
				}
				float num = timer / 4f;
				if (num > 0.05f)
				{
					int num2 = Mathf.Max(1, Mathf.FloorToInt((float)totalWater * num));
					int num3 = MaxWater - GetStoredWater();
					int num4 = Mathf.Min(num2, num3);
					if (num4 > 0)
					{
						AddWater(num4, containerDirty);
						state.CurrentAmount = totalWater - num4;
						ItemManager.SaveContainerState(player, state);
					}
				}
				UIManager.HideFillBar();
				yield break;
			}
			int num5 = MaxWater - GetStoredWater();
			int num6 = Mathf.Min(totalWater, num5);
			if (num6 > 0)
			{
				AddWater(num6, containerDirty);
				state.CurrentAmount = totalWater - num6;
				ItemManager.SaveContainerState(player, state);
			}
			UIManager.HideFillBar();
			SFXManager.PlayRefill(player);
			((Character)player).Message((MessageType)2, $"Poured water into barrel ({GetStoredWater()}/{MaxWater})", 0, (Sprite)null, false);
		}
		finally
		{
			_fillRoutine = null;
		}
	}

	public bool UseItem(Humanoid user, ItemData item)
	{
		return false;
	}

	public string GetHoverText()
	{
		int storedWater = GetStoredWater();
		string text = $"Rain Barrel ({storedWater}/{MaxWater})";
		Player localPlayer = Player.m_localPlayer;
		if ((Object)(object)localPlayer == (Object)null)
		{
			return text;
		}
		ItemData equippedBucket = BucketItem.GetEquippedBucket(localPlayer);
		if (equippedBucket != null && !BucketItem.IsEmpty(equippedBucket) && !BucketItem.IsBoiling(equippedBucket))
		{
			return text + "\n<color=yellow>[G]</color> Fill Barrel";
		}
		bool flag = false;
		bool flag2 = false;
		bool flag3 = false;
		if (ItemManager.CanFill(localPlayer, dirty: false, out var state))
		{
			flag = true;
			flag3 = true;
		}
		if (ItemManager.CanDrinkFromContainer(localPlayer, out state))
		{
			flag = true;
			flag2 = true;
		}
		if (flag)
		{
			if (storedWater > 0 && flag3)
			{
				text += "\n<color=yellow>[E]</color> Fill Container";
			}
			if (flag2)
			{
				text += "\n<color=yellow>[G]</color> Fill Barrel";
			}
		}
		return text;
	}

	public string GetHoverName()
	{
		return "Rain Barrel";
	}

	public float GetHoverOffset()
	{
		return 0f;
	}
}
internal class BoilingBucketPiece : MonoBehaviour, Interactable, Hoverable
{
	private const string ZDO_CoolStart = "YT_CoolStart";

	private const string ZDO_CoolActive = "YT_CoolActive";

	private ZNetView m_nview;

	private void Awake()
	{
		m_nview = ((Component)this).GetComponent<ZNetView>();
		if ((Object)(object)m_nview != (Object)null && m_nview.IsValid() && !m_nview.GetZDO().GetBool("YT_CoolActive", false))
		{
			StartCooling();
		}
	}

	public float GetTimeRemaining()
	{
		if ((Object)(object)m_nview == (Object)null || !m_nview.IsValid())
		{
			return 0f;
		}
		long num = m_nview.GetZDO().GetLong("YT_CoolStart", 0L);
		if (num <= 0)
		{
			return 0f;
		}
		float num2 = (float)((double)(ZNet.instance.GetTime().Ticks - num) / 10000000.0);
		float value = ConfigManager.CoolDurationSeconds.Value;
		return Mathf.Max(0f, value - num2);
	}

	public bool IsCooled()
	{
		if ((Object)(object)m_nview == (Object)null || !m_nview.IsValid())
		{
			return false;
		}
		if (!m_nview.GetZDO().GetBool("YT_CoolActive", false))
		{
			return false;
		}
		return GetTimeRemaining() <= 0f;
	}

	private void StartCooling()
	{
		if (!((Object)(object)m_nview == (Object)null) && m_nview.IsValid())
		{
			long ticks = ZNet.instance.GetTime().Ticks;
			m_nview.GetZDO().Set("YT_CoolStart", ticks);
			m_nview.GetZDO().Set("YT_CoolActive", true);
		}
	}

	public bool Interact(Humanoid user, bool hold, bool alt)
	{
		if (hold)
		{
			return false;
		}
		Player val = (Player)(object)((user is Player) ? user : null);
		if (!Object.op_Implicit((Object)(object)val))
		{
			return false;
		}
		if (!IsCooled())
		{
			int num = Mathf.CeilToInt(GetTimeRemaining());
			((Character)val).Message((MessageType)2, $"Water is still cooling... {num}s", 0, (Sprite)null, false);
			return false;
		}
		GameObject bucket = PrefabLoader.Bucket;
		if ((Object)(object)bucket == (Object)null)
		{
			((Character)val).Message((MessageType)2, "Error: bucket prefab missing.", 0, (Sprite)null, false);
			return false;
		}
		ItemDrop component = bucket.GetComponent<ItemDrop>();
		if ((Object)(object)component == (Object)null || component.m_itemData == null)
		{
			return false;
		}
		ItemData val2 = ((Humanoid)val).GetInventory().AddItem(((Object)bucket).name, 1, component.m_itemData.m_quality, component.m_itemData.m_variant, 0L, "", false, false);
		if (val2 == null)
		{
			((Character)val).Message((MessageType)2, "Inventory full!", 0, (Sprite)null, false);
			return false;
		}
		BucketItem.SetWater(val2, BucketItem.Capacity);
		BucketItem.SetDirty(val2, dirty: false);
		BucketItem.SetBoiling(val2, boiling: false);
		SFXManager.PlayRefill(val);
		((Character)val).Message((MessageType)2, "Collected purified clean water!", 0, (Sprite)null, false);
		if ((Object)(object)m_nview != (Object)null && m_nview.IsValid())
		{
			WearNTear component2 = ((Component)this).GetComponent<WearNTear>();
			if ((Object)(object)component2 != (Object)null)
			{
				component2.Remove(false);
			}
			else
			{
				ZNetScene.instance.Destroy(((Component)this).gameObject);
			}
		}
		return true;
	}

	public bool UseItem(Humanoid user, ItemData item)
	{
		return false;
	}

	public string GetHoverText()
	{
		if (IsCooled())
		{
			return "<color=yellow>[E]</color> Collect Purified Water";
		}
		float timeRemaining = GetTimeRemaining();
		int num = Mathf.FloorToInt(timeRemaining / 60f);
		int num2 = Mathf.FloorToInt(timeRemaining % 60f);
		string text = ((num > 0) ? $"{num}:{num2:D2}" : $"{num2}s");
		return "<color=#AAAAAA>Cooling... " + text + "</color>";
	}

	public string GetHoverName()
	{
		return "Boiling Water Bucket";
	}

	public float GetHoverOffset()
	{
		return 0f;
	}
}
internal class CauldronBoiling : MonoBehaviour
{
	private const string ZDO_BoilStart = "YT_BoilStart";

	private const string ZDO_BoilActive = "YT_BoilActive";

	private ZNetView m_nview;

	private void Awake()
	{
		m_nview = ((Component)this).GetComponent<ZNetView>();
	}

	private bool EnsureNView()
	{
		if ((Object)(object)m_nview == (Object)null)
		{
			m_nview = ((Component)this).GetComponent<ZNetView>();
		}
		if ((Object)(object)m_nview != (Object)null)
		{
			return m_nview.IsValid();
		}
		return false;
	}

	public bool IsBoilActive()
	{
		if (!EnsureNView())
		{
			return false;
		}
		ZDO zDO = m_nview.GetZDO();
		if (zDO == null)
		{
			return false;
		}
		return zDO.GetBool("YT_BoilActive", false);
	}

	public bool IsReady()
	{
		if (!IsBoilActive())
		{
			return false;
		}
		return GetTimeRemaining() <= 0f;
	}

	public float GetTimeRemaining()
	{
		if (!EnsureNView())
		{
			return 0f;
		}
		ZDO zDO = m_nview.GetZDO();
		if (zDO == null)
		{
			return 0f;
		}
		long num = zDO.GetLong("YT_BoilStart", 0L);
		if (num <= 0)
		{
			return 0f;
		}
		if ((Object)(object)ZNet.instance == (Object)null)
		{
			return 0f;
		}
		float num2 = (float)((double)(ZNet.instance.GetTime().Ticks - num) / 10000000.0);
		float value = ConfigManager.BoilDurationSeconds.Value;
		return Mathf.Max(0f, value - num2);
	}

	public bool StartBoil()
	{
		if (!EnsureNView())
		{
			YourThirstyPlugin.Log.LogWarning((object)"CauldronBoiling.StartBoil: m_nview null/invalid — boil NOT started.");
			return false;
		}
		ZDO zDO = m_nview.GetZDO();
		if (zDO == null)
		{
			YourThirstyPlugin.Log.LogWarning((object)"CauldronBoiling.StartBoil: ZDO is null — boil NOT started.");
			return false;
		}
		if ((Object)(object)ZNet.instance == (Object)null)
		{
			YourThirstyPlugin.Log.LogWarning((object)"CauldronBoiling.StartBoil: ZNet.instance is null — boil NOT started.");
			return false;
		}
		long ticks = ZNet.instance.GetTime().Ticks;
		zDO.Set("YT_BoilStart", ticks);
		zDO.Set("YT_BoilActive", true);
		YourThirstyPlugin.Log.LogInfo((object)string.Format("CauldronBoiling.StartBoil: Boil started at ticks={0}, BoilActive={1}", ticks, zDO.GetBool("YT_BoilActive", false)));
		return true;
	}

	public void ResetBoil()
	{
		if (EnsureNView())
		{
			ZDO zDO = m_nview.GetZDO();
			if (zDO != null)
			{
				zDO.Set("YT_BoilActive", false);
				zDO.Set("YT_BoilStart", 0L);
			}
		}
	}
}
internal static class Horn
{
	internal static bool Use(Player player, ItemData item)
	{
		if (ItemManager.CanDrinkFromContainer(player, out var _))
		{
			DrinkSystem.TryDrink();
			return true;
		}
		SFXManager.PlayEmpty(player);
		return true;
	}
}
[HarmonyPatch(typeof(Player), "Update")]
internal static class PlayerPatch
{
	private static SE_Stats _seBucketSlow;

	private static bool _penaltyActive;

	private static float _checkTimer;

	private const float CheckInterval = 0.5f;

	[HarmonyPostfix]
	private static void Postfix(Player __instance)
	{
		if ((Object)(object)__instance != (Object)(object)Player.m_localPlayer)
		{
			return;
		}
		_checkTimer -= Time.deltaTime;
		if (!(_checkTimer > 0f))
		{
			_checkTimer = 0.5f;
			ItemData nonEmptyBucketInInventory = BucketItem.GetNonEmptyBucketInInventory(__instance);
			bool flag = nonEmptyBucketInInventory != null && BucketItem.IsFull(nonEmptyBucketInInventory);
			if (flag && !_penaltyActive)
			{
				EnsureStatusEffect();
				((Character)__instance).GetSEMan().AddStatusEffect((StatusEffect)(object)_seBucketSlow, false, 0, 0f, (short)(-1));
				_penaltyActive = true;
			}
			else if (!flag && _penaltyActive)
			{
				((Character)__instance).GetSEMan().RemoveStatusEffect((StatusEffect)(object)_seBucketSlow, false);
				_penaltyActive = false;
			}
		}
	}

	private static void EnsureStatusEffect()
	{
		if (!((Object)(object)_seBucketSlow != (Object)null))
		{
			_seBucketSlow = ScriptableObject.CreateInstance<SE_Stats>();
			((Object)_seBucketSlow).name = "SE_YT_BucketSlow";
			((StatusEffect)_seBucketSlow).m_name = "Carrying Water";
			((StatusEffect)_seBucketSlow).m_tooltip = "Heavy Water Bucket slows you down";
			((StatusEffect)_seBucketSlow).m_ttl = 0f;
			_seBucketSlow.m_speedModifier = (0f - ConfigManager.BucketSpeedPenalty.Value) / 10f;
		}
	}
}
[HarmonyPatch(typeof(Player), "OnSpawned")]
internal static class PlayerSpawnedPatch
{
	[HarmonyPostfix]
	private static void Postfix(Player __instance)
	{
		if (!((Object)(object)__instance != (Object)(object)Player.m_localPlayer))
		{
			YourThirstyPlugin.Log.LogInfo((object)"PlayerSpawnedPatch: Player spawned — refreshing piece requirements.");
			ItemRegistration.RefreshPieceRequirements();
		}
	}
}
internal static class Waterskin
{
	internal static bool Use(Player player, ItemData item)
	{
		if (ItemManager.CanDrinkFromContainer(player, out var _))
		{
			DrinkSystem.TryDrink();
			return true;
		}
		SFXManager.PlayEmpty(player);
		return true;
	}
}
internal class Well : MonoBehaviour, Interactable, Hoverable
{
	private const string ZDO_Water = "YT_WellWater";

	private ZNetView m_nview;

	public int MaxWater => 999;

	private void Awake()
	{
		m_nview = ((Component)this).GetComponent<ZNetView>();
	}

	private void Start()
	{
		if ((Object)(object)m_nview != (Object)null && m_nview.IsValid() && m_nview.IsOwner() && m_nview.GetZDO().GetInt("YT_WellWater", -1) < 0)
		{
			m_nview.GetZDO().Set("YT_WellWater", MaxWater);
		}
	}

	public int GetStoredWater()
	{
		if ((Object)(object)m_nview == (Object)null || !m_nview.IsValid())
		{
			return 0;
		}
		return Mathf.Clamp(m_nview.GetZDO().GetInt("YT_WellWater", MaxWater), 0, MaxWater);
	}

	private void SetStoredWater(int amount)
	{
		if (!((Object)(object)m_nview == (Object)null) && m_nview.IsValid())
		{
			m_nview.GetZDO().Set("YT_WellWater", Mathf.Clamp(amount, 0, MaxWater));
		}
	}

	public bool Interact(Humanoid user, bool hold, bool alt)
	{
		if (hold)
		{
			return false;
		}
		Player val = (Player)(object)((user is Player) ? user : null);
		if (!Object.op_Implicit((Object)(object)val))
		{
			return false;
		}
		ItemData equippedBucket = BucketItem.GetEquippedBucket(val);
		if (equippedBucket != null && !BucketItem.IsFull(equippedBucket))
		{
			int num = BucketItem.Capacity - BucketItem.CurrentWater(equippedBucket);
			BucketItem.SetWater(equippedBucket, BucketItem.CurrentWater(equippedBucket) + num);
			SFXManager.PlayRefill(val);
			((Character)val).Message((MessageType)2, "Water Bucket filled with clean water.", 0, (Sprite)null, false);
			return true;
		}
		if (ItemManager.CanFill(val, dirty: false, out var _))
		{
			ItemManager.Fill(val, dirty: false);
			SFXManager.PlayRefill(val);
			((Character)val).Message((MessageType)2, "Filled with clean water from the well.", 0, (Sprite)null, false);
			return true;
		}
		((Character)val).Message((MessageType)2, "Equip a Water Bucket or container to fill from the well.", 0, (Sprite)null, false);
		return false;
	}

	public bool UseItem(Humanoid user, ItemData item)
	{
		return false;
	}

	public string GetHoverText()
	{
		return "<color=yellow>[E]</color> Well (Always Full)";
	}

	public string GetHoverName()
	{
		return "Well";
	}

	public float GetHoverOffset()
	{
		return 0f;
	}
}
namespace YourThirsty
{
	internal static class AnimationManager
	{
		public static void Init()
		{
			PlayerAnimationInjector.Init();
			YourThirstyPlugin.Log.LogInfo((object)"AnimationManager: initialized.");
		}

		public static void PrepareDrink(Player player, PlayerAnimationInjector.DrinkAnimMode mode)
		{
			PlayerAnimationInjector.PlayDrinkAnimation(player, mode);
		}
	}
	internal static class BiomeWaterQuality
	{
		private class BiomeState
		{
			public bool IsGood;

			public float Timer;

			public (float, float)[] Brackets;

			public BiomeState((float, float)[] brackets)
			{
				Brackets = brackets;
				IsGood = true;
				Timer = PickDuration(brackets);
			}
		}

		private static readonly (float min, float max)[] BlackForestBrackets = new(float, float)[4]
		{
			(180f, 300f),
			(360f, 480f),
			(600f, 720f),
			(900f, 900f)
		};

		private static readonly (float min, float max)[] PlainsBrackets = new(float, float)[4]
		{
			(120f, 240f),
			(300f, 420f),
			(480f, 600f),
			(720f, 900f)
		};

		private static readonly (float min, float max)[] MistlandsBrackets = new(float, float)[4]
		{
			(300f, 480f),
			(600f, 840f),
			(900f, 1200f),
			(1500f, 1800f)
		};

		private static readonly Dictionary<Biome, BiomeState> _states = new Dictionary<Biome, BiomeState>();

		private static bool _initialized;

		public static void Init()
		{
			_states.Clear();
			_states[(Biome)8] = new BiomeState(BlackForestBrackets);
			_states[(Biome)16] = new BiomeState(PlainsBrackets);
			_states[(Biome)512] = new BiomeState(MistlandsBrackets);
			_initialized = true;
			YourThirstyPlugin.Log.LogInfo((object)"BiomeWaterQuality: initialized (BlackForest, Plains, Mistlands cycling).");
		}

		public static void Update()
		{
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			if (!_initialized)
			{
				return;
			}
			float deltaTime = Time.deltaTime;
			foreach (KeyValuePair<Biome, BiomeState> state in _states)
			{
				BiomeState value = state.Value;
				value.Timer -= deltaTime;
				if (value.Timer <= 0f)
				{
					value.IsGood = !value.IsGood;
					value.Timer = PickDuration(value.Brackets);
					YourThirstyPlugin.Log.LogInfo((object)($"BiomeWaterQuality: {state.Key} water is now " + string.Format("{0} for {1:F0}s", value.IsGood ? "GOOD" : "BAD", value.Timer)));
				}
			}
		}

		public static bool IsBadWater(Biome biome)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			if (_states.TryGetValue(biome, out var value))
			{
				return !value.IsGood;
			}
			return false;
		}

		public static bool HasCycling(Biome biome)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			return _states.ContainsKey(biome);
		}

		private static float PickDuration((float min, float max)[] brackets)
		{
			int num = Random.Range(0, brackets.Length);
			return Random.Range(brackets[num].min, brackets[num].max);
		}
	}
	internal static class BucketItem
	{
		private const string Key_Water = "YT_BucketWater";

		private const string Key_Dirty = "YT_BucketDirty";

		private const string Key_Boiling = "YT_BucketBoiling";

		private const string Key_CoolStart = "YT_BucketCoolStart";

		private static readonly FieldRef<Humanoid, ItemData> _rightItemRef = AccessTools.FieldRefAccess<Humanoid, ItemData>("m_rightItem");

		public static int Capacity => ConfigManager.BucketCapacity.Value;

		public static int MaxWater => Capacity;

		public static int CurrentWater(ItemData item)
		{
			return GetWater(item);
		}

		public static ItemData GetEquippedBucket(Player player)
		{
			Inventory inventory = ((Humanoid)player).GetInventory();
			if (inventory == null)
			{
				return null;
			}
			ItemData val = _rightItemRef.Invoke((Humanoid)(object)player);
			foreach (ItemData allItem in inventory.GetAllItems())
			{
				if (allItem != null && allItem.m_shared != null && allItem.m_equipped && allItem == val && allItem.m_shared.m_name == "YourThirsty_WaterBucket")
				{
					return allItem;
				}
			}
			return null;
		}

		public static bool HasBucketInInventory(Player player)
		{
			Inventory inventory = ((Humanoid)player).GetInventory();
			if (inventory == null)
			{
				return false;
			}
			foreach (ItemData allItem in inventory.GetAllItems())
			{
				if (allItem != null && allItem.m_shared != null && allItem.m_shared.m_name == "YourThirsty_WaterBucket")
				{
					return true;
				}
			}
			return false;
		}

		public static int GetWater(ItemData item)
		{
			if (item == null || item.m_customData == null)
			{
				return 0;
			}
			if (item.m_customData.TryGetValue("YT_BucketWater", out var value))
			{
				int.TryParse(value, out var result);
				return result;
			}
			return 0;
		}

		public static void SetWater(ItemData item, int amount)
		{
			if (item != null)
			{
				if (item.m_customData == null)
				{
					item.m_customData = new Dictionary<string, string>();
				}
				item.m_customData["YT_BucketWater"] = Mathf.Clamp(amount, 0, Capacity).ToString();
			}
		}

		public static bool IsDirtyWater(ItemData item)
		{
			if (item == null || item.m_customData == null)
			{
				return false;
			}
			if (item.m_customData.TryGetValue("YT_BucketDirty", out var value))
			{
				return value == "1";
			}
			return false;
		}

		public static void SetDirty(ItemData item, bool dirty)
		{
			if (item != null)
			{
				if (item.m_customData == null)
				{
					item.m_customData = new Dictionary<string, string>();
				}
				item.m_customData["YT_BucketDirty"] = (dirty ? "1" : "0");
			}
		}

		public static bool IsBoiling(ItemData item)
		{
			if (item == null || item.m_customData == null)
			{
				return false;
			}
			if (item.m_customData.TryGetValue("YT_BucketBoiling", out var value))
			{
				return value == "1";
			}
			return false;
		}

		public static void SetBoiling(ItemData item, bool boiling)
		{
			if (item != null)
			{
				if (item.m_customData == null)
				{
					item.m_customData = new Dictionary<string, string>();
				}
				item.m_customData["YT_BucketBoiling"] = (boiling ? "1" : "0");
			}
		}

		public static bool HasBoilingBucket(Player player)
		{
			Inventory val = ((player != null) ? ((Humanoid)player).GetInventory() : null);
			if (val == null)
			{
				return false;
			}
			foreach (ItemData allItem in val.GetAllItems())
			{
				if (allItem != null && allItem.m_shared != null && allItem.m_shared.m_name == "YourThirsty_WaterBucket" && IsBoiling(allItem))
				{
					return true;
				}
			}
			return false;
		}

		public static bool ConsumeBoilingBucket(Player player)
		{
			Inventory val = ((player != null) ? ((Humanoid)player).GetInventory() : null);
			if (val == null)
			{
				return false;
			}
			foreach (ItemData allItem in val.GetAllItems())
			{
				if (allItem != null && allItem.m_shared != null && allItem.m_shared.m_name == "YourThirsty_WaterBucket" && IsBoiling(allItem))
				{
					val.RemoveItem(allItem);
					return true;
				}
			}
			return false;
		}

		public static bool IsFull(ItemData item)
		{
			return GetWater(item) >= Capacity;
		}

		public static bool IsEmpty(ItemData item)
		{
			return GetWater(item) <= 0;
		}

		public static void Fill(ItemData item, bool dirty)
		{
			SetWater(item, Capacity);
			SetDirty(item, dirty);
		}

		public static int Pour(ItemData item)
		{
			int water = GetWater(item);
			SetWater(item, 0);
			return water;
		}

		public static void Empty(ItemData item)
		{
			SetWater(item, 0);
			SetDirty(item, dirty: false);
			SetBoiling(item, boiling: false);
		}

		public static ItemData GetFirstBucketInInventory(Player player)
		{
			Inventory val = ((player != null) ? ((Humanoid)player).GetInventory() : null);
			if (val == null)
			{
				return null;
			}
			foreach (ItemData allItem in val.GetAllItems())
			{
				if (allItem != null && allItem.m_shared != null && allItem.m_shared.m_name == "YourThirsty_WaterBucket")
				{
					return allItem;
				}
			}
			return null;
		}

		public static ItemData GetNonEmptyBucketInInventory(Player player)
		{
			Inventory val = ((player != null) ? ((Humanoid)player).GetInventory() : null);
			if (val == null)
			{
				return null;
			}
			foreach (ItemData allItem in val.GetAllItems())
			{
				if (allItem != null && allItem.m_shared != null && allItem.m_shared.m_name == "YourThirsty_WaterBucket" && GetWater(allItem) > 0)
				{
					return allItem;
				}
			}
			return null;
		}

		public static long GetCoolStartTicks(ItemData item)
		{
			if (item == null || item.m_customData == null)
			{
				return 0L;
			}
			if (item.m_customData.TryGetValue("YT_BucketCoolStart", out var value))
			{
				long.TryParse(value, out var result);
				return result;
			}
			return 0L;
		}

		public static void StartInventoryCooling(ItemData item)
		{
			if (item != null)
			{
				if (item.m_customData == null)
				{
					item.m_customData = new Dictionary<string, string>();
				}
				long num = (((Object)(object)ZNet.instance != (Object)null) ? ZNet.instance.GetTime().Ticks : DateTime.UtcNow.Ticks);
				item.m_customData["YT_BucketCoolStart"] = num.ToString();
			}
		}

		public static float GetCoolTimeRemaining(ItemData item)
		{
			long coolStartTicks = GetCoolStartTicks(item);
			if (coolStartTicks <= 0)
			{
				return 0f;
			}
			float num = (float)((double)((((Object)(object)ZNet.instance != (Object)null) ? ZNet.instance.GetTime().Ticks : DateTime.UtcNow.Ticks) - coolStartTicks) / 10000000.0);
			float value = ConfigManager.CoolDurationSeconds.Value;
			return Mathf.Max(0f, value - num);
		}

		public static bool IsInventoryCooled(ItemData item)
		{
			if (!IsBoiling(item))
			{
				return false;
			}
			if (GetCoolStartTicks(item) <= 0)
			{
				return false;
			}
			return GetCoolTimeRemaining(item) <= 0f;
		}

		public static void FinishCooling(ItemData item)
		{
			if (item != null)
			{
				SetBoiling(item, boiling: false);
				SetDirty(item, dirty: false);
				if (item.m_customData != null)
				{
					item.m_customData.Remove("YT_BucketCoolStart");
				}
			}
		}
	}
	internal static class BuffManager
	{
		private static bool _wasThirsty;

		private static bool _wasCritical;

		private static SE_Stats _seHydrated;

		private static SE_Stats _seDirty;

		public static void Init()
		{
			_wasThirsty = false;
			_wasCritical = false;
			YourThirstyPlugin.Log.LogInfo((object)"BuffManager: initialized.");
		}

		private static void EnsureStatusEffects()
		{
			//IL_00c3: 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_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: 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)
			if ((Object)(object)_seHydrated != (Object)null)
			{
				return;
			}
			AssetBundle assetBundle = YourThirstyPlugin.AssetBundle;
			_seHydrated = ScriptableObject.CreateInstance<SE_Stats>();
			((Object)_seHydrated).name = "SE_YT_Hydrated";
			((StatusEffect)_seHydrated).m_name = "Hydrated";
			((StatusEffect)_seHydrated).m_tooltip = "Clean water — 20% slower stamina drain, +20% max stamina";
			((StatusEffect)_seHydrated).m_ttl = 160f;
			_seHydrated.m_runStaminaDrainModifier = -0.2f;
			_seHydrated.m_jumpStaminaUseModifier = -0.2f;
			_seHydrated.m_staminaRegenMultiplier = 1f;
			if ((Object)(object)assetBundle != (Object)null)
			{
				Texture2D val = assetBundle.LoadAsset<Texture2D>("Hydrated");
				if ((Object)(object)val != (Object)null)
				{
					((StatusEffect)_seHydrated).m_icon = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), Vector2.one * 0.5f);
				}
			}
			SE_Stats val2 = ScriptableObject.CreateInstance<SE_Stats>();
			((Object)val2).name = "SE_YT_DirtyWater";
			((StatusEffect)val2).m_name = "Dirty Water";
			((StatusEffect)val2).m_tooltip = "Contaminated water saps your strength";
			((StatusEffect)val2).m_ttl = 160f;
			val2.m_speedModifier = 0f - Mathf.Abs(ConfigManager.DirtyWaterSpeedPenalty.Value);
			if ((Object)(object)assetBundle != (Object)null)
			{
				Texture2D val3 = assetBundle.LoadAsset<Texture2D>("DirtyWater");
				if ((Object)(object)val3 != (Object)null)
				{
					((StatusEffect)val2).m_icon = Sprite.Create(val3, new Rect(0f, 0f, (float)((Texture)val3).width, (float)((Texture)val3).height), Vector2.one * 0.5f);
				}
			}
			_seDirty = val2;
		}

		public static void RemoveHydrated(Player player)
		{
			if ((Object)(object)player == (Object)null || (Object)(object)_seHydrated == (Object)null)
			{
				return;
			}
			try
			{
				((Character)player).GetSEMan().RemoveStatusEffect((StatusEffect)(object)_seHydrated, false);
			}
			catch
			{
			}
		}

		private static Transform FindBoneRecursive(Transform parent, string name)
		{
			if (((Object)parent).name == name)
			{
				return parent;
			}
			for (int i = 0; i < parent.childCount; i++)
			{
				Transform val = FindBoneRecursive(parent.GetChild(i), name);
				if ((Object)(object)val != (Object)null)
				{
					return val;
				}
			}
			return null;
		}

		public static void TriggerPuke(Player player)
		{
			//IL_0030: 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_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: 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_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: 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_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)player == (Object)null)
			{
				return;
			}
			YourThirstyPlugin.Log.LogInfo((object)"BuffManager: TriggerPuke called.");
			try
			{
				if ((Object)(object)ZNetScene.instance != (Object)null)
				{
					Transform val = ((Component)player).transform;
					Vector3 val2 = Vector3.up * 1.85f;
					Transform val3 = FindBoneRecursive(((Component)player).transform, "Head");
					if ((Object)(object)val3 != (Object)null)
					{
						val = val3;
						val2 = Vector3.forward * 0.15f;
					}
					string[] obj = new string[4] { "vfx_puke", "vfx_Puke", "fx_puke", "fx_Puke" };
					GameObject val4 = null;
					string[] array = obj;
					foreach (string text in array)
					{
						val4 = ZNetScene.instance.GetPrefab(text);
						if ((Object)(object)val4 != (Object)null)
						{
							Object.Instantiate<GameObject>(val4, val.position + val2, Quaternion.identity, val).transform.localPosition = val2;
							YourThirstyPlugin.Log.LogInfo((object)("BuffManager: " + text + " spawned and parented to player."));
							break;
						}
					}
					if ((Object)(object)val4 == (Object)null)
					{
						val4 = ZNetScene.instance.GetPrefab("vfx_Poisoned");
						if ((Object)(object)val4 != (Object)null)
						{
							Object.Instantiate<GameObject>(val4, val.position + val2, Quaternion.identity, val).transform.localPosition = val2;
							YourThirstyPlugin.Log.LogInfo((object)"BuffManager: vfx_Poisoned (fallback) spawned and parented to player.");
						}
						else
						{
							YourThirstyPlugin.Log.LogWarning((object)"BuffManager: No puke/poison VFX prefab found in ZNetScene.");
						}
					}
					array = new string[2] { "sfx_puke", "sfx_Puke" };
					foreach (string text2 in array)
					{
						GameObject prefab = ZNetScene.instance.GetPrefab(text2);
						if ((Object)(object)prefab != (Object)null)
						{
							Object.Instantiate<GameObject>(prefab, ((Component)player).transform.position, Quaternion.identity);
							YourThirstyPlugin.Log.LogInfo((object)("BuffManager: " + text2 + " played."));
							break;
						}
					}
				}
			}
			catch (Exception ex)
			{
				YourThirstyPlugin.Log.LogWarning((object)("BuffManager: Failed to spawn VFX: " + ex.Message));
			}
			try
			{
				ZSyncAnimation componentInChildren = ((Component)player).GetComponentInChildren<ZSyncAnimation>();
				if ((Object)(object)componentInChildren != (Object)null)
				{
					componentInChildren.SetBool("puke", true);
					YourThirstyPlugin.Log.LogInfo((object)"BuffManager: Set 'puke' bool=true on ZSyncAnimation.");
					((MonoBehaviour)CoroutineHost.Instance).StartCoroutine(ResetPukeBool(componentInChildren));
				}
				else
				{
					YourThirstyPlugin.Log.LogWarning((object)"BuffManager: ZSyncAnimation not found on player.");
				}
			}
			catch (Exception ex2)
			{
				YourThirstyPlugin.Log.LogWarning((object)("BuffManager: Failed to trigger puke animation: " + ex2.Message));
			}
			((Character)player).Message((MessageType)2, "<color=#44ff44>*Bleurgh!*</color> You vomit from the dirty water!", 0, (Sprite)null, false);
			try
			{
				List<Food> foods = player.GetFoods();
				if (foods != null && foods.Count > 0)
				{
					Food val5 = foods[0];
					foods.RemoveAt(0);
					YourThirstyPlugin.Log.LogInfo((object)("BuffManager: Removed food '" + val5.m_name + "' due to dirty water vomit"));
				}
			}
			catch (Exception ex3)
			{
				YourThirstyPlugin.Log.LogWarning((object)("BuffManager: Failed to remove food: " + ex3.Message));
			}
		}

		private static IEnumerator ResetPukeBool(ZSyncAnimation zanim)
		{
			yield return (object)new WaitForSeconds(3f);
			try
			{
				if ((Object)(object)zanim != (Object)null)
				{
					zanim.SetBool("puke", false);
				}
			}
			catch
			{
			}
		}

		public static void ApplyDrinkEffects(Player player, bool isDirty)
		{
			//IL_004a: 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_005a: 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_0232: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)player == (Object)null)
			{
				return;
			}
			EnsureStatusEffects();
			if (isDirty)
			{
				RemoveHydrated(player);
				TriggerPuke(player);
				float num = 0f - Mathf.Abs(ConfigManager.DirtyWaterSpeedPenalty.Value);
				float staminaRegenPenalty = 0f;
				float healthRegenPenalty = 0f;
				float num2 = 160f;
				Biome currentBiome = player.GetCurrentBiome();
				if (WaterSickness.HasProfile(currentBiome))
				{
					WaterSickness.RollPenalties(currentBiome, out staminaRegenPenalty, out healthRegenPenalty);
				}
				if ((Object)(object)_seDirty != (Object)null)
				{
					try
					{
						((Character)player).GetSEMan().RemoveStatusEffect((StatusEffect)(object)_seDirty, false);
					}
					catch
					{
					}
				}
				SE_Stats val = ScriptableObject.CreateInstance<SE_Stats>();
				((Object)val).name = "SE_YT_DirtyWater";
				((StatusEffect)val).m_name = "Dirty Water";
				((StatusEffect)val).m_ttl = num2;
				val.m_speedModifier = num;
				val.m_staminaRegenMultiplier = 1f - staminaRegenPenalty;
				val.m_healthRegenMultiplier = 1f - healthRegenPenalty;
				string text = "Contaminated water saps your strength\n";
				text += $"Movement: {num * 100f:F0}%\n";
				if (staminaRegenPenalty > 0f)
				{
					text += $"Stamina regen: -{staminaRegenPenalty * 100f:F0}%\n";
				}
				if (healthRegenPenalty > 0f)
				{
					text += $"Health regen: -{healthRegenPenalty * 100f:F0}%\n";
				}
				text += $"Duration: {num2:F0}s";
				((StatusEffect)val).m_tooltip = text;
				if ((Object)(object)YourThirstyPlugin.AssetBundle != (Object)null)
				{
					Texture2D val2 = YourThirstyPlugin.AssetBundle.LoadAsset<Texture2D>("DirtyWater");
					if ((Object)(object)val2 != (Object)null)
					{
						((StatusEffect)val).m_icon = Sprite.Create(val2, new Rect(0f, 0f, (float)((Texture)val2).width, (float)((Texture)val2).height), Vector2.one * 0.5f);
					}
				}
				((Character)player).GetSEMan().AddStatusEffect((StatusEffect)(object)val, false, 0, 0f, (short)(-1));
				_seDirty = val;
				ThirstSystem.ApplyDirtyPenalty();
				if (!WaterSickness.HasProfile(currentBiome))
				{
					float health = ((Character)player).GetHealth();
					((Character)player).SetHealth(Mathf.Max(health - 5f, 1f));
				}
				((Character)player).Message((MessageType)2, "<color=red>The dirty water makes you sick!</color>", 0, (Sprite)null, false);
				YourThirstyPlugin.Log.LogInfo((object)($"BuffManager: Applied Dirty Water — biome={currentBiome}, " + $"stam=-{staminaRegenPenalty:P0}, hp=-{healthRegenPenalty:P0}, " + $"speed={num:P0}, dur={num2:F0}s"));
				return;
			}
			if ((Object)(object)_seHydrated != (Object)null)
			{
				try
				{
					((Character)player).GetSEMan().RemoveStatusEffect((StatusEffect)(object)_seHydrated, false);
				}
				catch
				{
				}
				((Character)player).GetSEMan().AddStatusEffect((StatusEffect)(object)_seHydrated, false, 0, 0f, (short)(-1));
			}
			((Character)player).AddStamina(((Character)player).GetMaxStamina() * 0.2f);
			((Character)player).Message((MessageType)2, "Refreshing water! Stamina restored.", 0, (Sprite)null, false);
		}

		public static void UpdateThirstEffects(Player player, float thirst)
		{
			if (!((Object)(object)player == (Object)null))
			{
				if (thirst >= 60f && !_wasThirsty)
				{
					_wasThirsty = true;
					((Character)player).Message((MessageType)2, "Your thirsty", 0, (Sprite)null, false);
				}
				else if (thirst < 60f)
				{
					_wasThirsty = false;
				}
				if (thirst >= 90f && !_wasCritical)
				{
					_wasCritical = true;
					((Character)player).Message((MessageType)2, "<color=red>You are dying of thirst!</color>", 0, (Sprite)null, false);
				}
				else if (thirst < 90f)
				{
					_wasCritical = false;
				}
			}
		}
	}
	internal static class CauldronBoilHoverHelper
	{
		internal static void AppendBoilStatus(GameObject go, ref string result)
		{
			try
			{
				CauldronBoiling cauldronBoiling = go.GetComponent<CauldronBoiling>();
				if ((Object)(object)cauldronBoiling == (Object)null)
				{
					cauldronBoiling = go.AddComponent<CauldronBoiling>();
				}
				if (cauldronBoiling.IsBoilActive())
				{
					if (cauldronBoiling.IsReady())
					{
						result += "\n<color=#00FF00>Boiled water ready — use cauldron menu to collect</color>";
						return;
					}
					float timeRemaining = cauldronBoiling.GetTimeRemaining();
					int num = Mathf.FloorToInt(timeRemaining / 60f);
					int num2 = Mathf.FloorToInt(timeRemaining % 60f);
					result += $"\n<color=#AAAAAA>Boiling... {num}:{num2:D2}</color>";
				}
				else
				{
					result += "\n<color=#888888>Cauldron idle — use menu to boil water</color>";
				}
			}
			catch (Exception ex)
			{
				YourThirstyPlugin.Log.LogWarning((object)("CauldronHoverTextPatch: " + ex.Message));
			}
		}
	}
	internal static class CauldronCraftPatches
	{
		private static bool _applied;

		private static void CraftingStationHoverPostfix(CraftingStation __instance, ref string __result)
		{
			if (!((Object)(object)__instance == (Object)null) && ((Object)((Component)__instance).gameObject).name.StartsWith("piece_cauldron"))
			{
				CauldronBoilHoverHelper.AppendBoilStatus(((Component)__instance).gameObject, ref __result);
			}
		}

		private static void CraftingStationAwakePostfix(CraftingStation __instance)
		{
			if (!((Object)(object)__instance == (Object)null) && ((Object)((Component)__instance).gameObject).name.StartsWith("piece_cauldron") && (Object)(object)((Component)__instance).GetComponent<CauldronBoiling>() == (Object)null)
			{
				((Component)__instance).gameObject.AddComponent<CauldronBoiling>();
				YourThirstyPlugin.Log.LogInfo((object)("CauldronCraftPatches: Added CauldronBoiling to '" + ((Object)((Component)__instance).gameObject).name + "' via CraftingStation.Awake."));
			}
		}

		internal static void Apply(Harmony harmony)
		{
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Expected O, but got Unknown
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Expected O, but got Unknown
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Expected O, but got Unknown
			//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ca: Expected O, but got Unknown
			if (_applied)
			{
				return;
			}
			_applied = true;
			try
			{
				MethodInfo methodInfo = AccessTools.Method(typeof(CraftingStation), "Start", (Type[])null, (Type[])null) ?? AccessTools.Method(typeof(CraftingStation), "Awake", (Type[])null, (Type[])null) ?? AccessTools.Method(typeof(CraftingStation), "OnEnable", (Type[])null, (Type[])null);
				if (methodInfo != null)
				{
					harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(CauldronCraftPatches), "CraftingStationAwakePostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
					YourThirstyPlugin.Log.LogInfo((object)("CauldronCraftPatches: Patched CraftingStation." + methodInfo.Name + "."));
				}
			}
			catch (Exception arg)
			{
				YourThirstyPlugin.Log.LogError((object)$"CauldronCraftPatches: CraftingStation lifecycle patch failed: {arg}");
			}
			try
			{
				MethodInfo methodInfo2 = AccessTools.Method(typeof(CraftingStation), "GetHoverText", (Type[])null, (Type[])null);
				if (methodInfo2 != null)
				{
					harmony.Patch((MethodBase)methodInfo2, (HarmonyMethod)null, new HarmonyMethod(typeof(CauldronCraftPatches), "CraftingStationHoverPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
					YourThirstyPlugin.Log.LogInfo((object)"CauldronCraftPatches: Patched CraftingStation.GetHoverText.");
				}
			}
			catch (Exception arg2)
			{
				YourThirstyPlugin.Log.LogError((object)$"CauldronCraftPatches: GetHoverText patch failed: {arg2}");
			}
			try
			{
				MethodInfo methodInfo3 = AccessTools.Method(typeof(InventoryGui), "DoCrafting", new Type[1] { typeof(Player) }, (Type[])null);
				if (methodInfo3 == null)
				{
					methodInfo3 = AccessTools.Method(typeof(InventoryGui), "DoCrafting", (Type[])null, (Type[])null);
				}
				if (methodInfo3 != null)
				{
					harmony.Patch((MethodBase)methodInfo3, new HarmonyMethod(typeof(CauldronCraftPatches), "DoCraftingPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
					YourThirstyPlugin.Log.LogInfo((object)"CauldronCraftPatches: Patched InventoryGui.DoCrafting ✓");
				}
			}
			catch (Exception arg3)
			{
				YourThirstyPlugin.Log.LogError((object)$"CauldronCraftPatches: DoCrafting patch failed: {arg3}");
			}
			try
			{
				MethodInfo methodInfo4 = null;
				MethodInfo[] methods = typeof(Player).GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				foreach (MethodInfo methodInfo5 in methods)
				{
					if (methodInfo5.Name != "HaveRequirements")
					{
						continue;
					}
					ParameterInfo[] parameters = methodInfo5.GetParameters();
					if (parameters.Length >= 2 && parameters[0].ParameterType == typeof(Recipe))
					{
						methodInfo4 = methodInfo5;
						YourThirstyPlugin.Log.LogInfo((object)("CauldronCraftPatches: Found HaveRequirements(Recipe) — " + string.Format("{0} params: ({1})", parameters.Length, string.Join(", ", Array.ConvertAll(parameters, (ParameterInfo p) => p.ParameterType.Name + " " + p.Name)))));
						break;
					}
				}
				if (methodInfo4 != null)
				{
					harmony.Patch((MethodBase)methodInfo4, (HarmonyMethod)null, new HarmonyMethod(typeof(CauldronCraftPatches), "HaveRequirementsPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
					YourThirstyPlugin.Log.LogInfo((object)"CauldronCraftPatches: Patched Player.HaveRequirements(Recipe) ✓");
				}
				else
				{
					YourThirstyPlugin.Log.LogWarning((object)"CauldronCraftPatches: Player.HaveRequirements(Recipe) not found.");
				}
			}
			catch (Exception arg4)
			{
				YourThirstyPlugin.Log.LogError((object)$"CauldronCraftPatches: HaveRequirements(Recipe) patch failed: {arg4}");
			}
			YourThirstyPlugin.Log.LogInfo((object)"CauldronCraftPatches: Build patches are attribute-based in BuildPiecePatches.cs");
			try
			{
				YourThirstyPlugin.Log.LogInfo((object)"=== BUILD SYSTEM DIAGNOSTIC DUMP ===");
				BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;
				MethodInfo[] methods = typeof(Player).GetMethods(bindingAttr);
				foreach (MethodInfo methodInfo6 in methods)
				{
					string name = methodInfo6.Name;
					if (name.Contains("Place") || name.Contains("piece") || name.Contains("Piece") || name.Contains("Requirement") || name.Contains("Build") || name == "UpdatePlacement" || name == "SetupPlacementGhost")
					{
						ParameterInfo[] parameters2 = methodInfo6.GetParameters();
						string text = string.Join(", ", Array.ConvertAll(parameters2, (ParameterInfo p) => p.ParameterType.Name + " " + p.Name));
						YourThirstyPlugin.Log.LogInfo((object)("  Player." + name + "(" + text + ") → " + methodInfo6.ReturnType.Name + $" [Virtual={methodInfo6.IsVirtual}, Static={methodInfo6.IsStatic}]"));
					}
				}
				FieldInfo field = typeof(Player).GetField("m_noPlacementCost", bindingAttr);
				if (field != null)
				{
					YourThirstyPlugin.Log.LogInfo((object)$"  Player.m_noPlacementCost: Type={field.FieldType.Name}, IsStatic={field.IsStatic}");
				}
				else
				{
					YourThirstyPlugin.Log.LogWarning((object)"  Player.m_noPlacementCost: NOT FOUND");
				}
				YourThirstyPlugin.Log.LogInfo((object)"=== END BUILD SYSTEM DIAGNOSTIC DUMP ===");
			}
			catch (Exception arg5)
			{
				YourThirstyPlugin.Log.LogError((object)$"Diagnostic dump failed: {arg5}");
			}
		}

		private static bool DoCraftingPrefix(InventoryGui __instance, Player player)
		{
			try
			{
				if ((Object)(object)player == (Object)null)
				{
					player = Player.m_localPlayer;
				}
				if ((Object)(object)player == (Object)null)
				{
					YourThirstyPlugin.Log.LogWarning((object)"DoCraftingPrefix: No player available.");
					return true;
				}
				FieldInfo fieldInfo = AccessTools.Field(typeof(InventoryGui), "m_selectedRecipe");
				if (fieldInfo == null)
				{
					FieldInfo[] fields = typeof(InventoryGui).GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					foreach (FieldInfo fieldInfo2 in fields)
					{
						if (fieldInfo2.Name.IndexOf("recipe", StringComparison.OrdinalIgnoreCase) >= 0 || fieldInfo2.Name.IndexOf("selected", StringComparison.OrdinalIgnoreCase) >= 0)
						{
							YourThirstyPlugin.Log.LogInfo((object)("DoCraftingPrefix: InventoryGui field candidate: " + fieldInfo2.Name + " (" + fieldInfo2.FieldType.FullName + ")"));
						}
					}
					YourThirstyPlugin.Log.LogWarning((object)"DoCraftingPrefix: m_selectedRecipe field not found.");
					return true;
				}
				object value = fieldInfo.GetValue(__instance);
				Recipe val = null;
				Recipe val2 = (Recipe)((value is Recipe) ? value : null);
				if (val2 != null)
				{
					val = val2;
				}
				else if (value != null)
				{
					Type type = value.GetType();
					YourThirstyPlugin.Log.LogInfo((object)("DoCraftingPrefix: m_selectedRecipe type = " + type.FullName));
					BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
					FieldInfo field = type.GetField("Key");
					if (field != null)
					{
						object? value2 = field.GetValue(value);
						val = (Recipe)((value2 is Recipe) ? value2 : null);
					}
					if ((Object)(object)val == (Object)null)
					{
						PropertyInfo property = type.GetProperty("Key");
						if (property != null)
						{
							object? value3 = property.GetValue(value, null);
							val = (Recipe)((value3 is Recipe) ? value3 : null);
						}
					}
					if ((Object)(object)val == (Object)null)
					{
						FieldInfo field2 = type.GetField("Recipe", bindingAttr);
						if (field2 != null)
						{
							object? value4 = field2.GetValue(value);
							val = (Recipe)((value4 is Recipe) ? value4 : null);
						}
					}
					if ((Object)(object)val == (Object)null)
					{
						PropertyInfo property2 = type.GetProperty("Recipe", bindingAttr);
						if (property2 != null && property2.CanRead)
						{
							object? value5 = property2.GetValue(value, null);
							val = (Recipe)((value5 is Recipe) ? value5 : null);
						}
					}
					if ((Object)(object)val == (Object)null)
					{
						FieldInfo[] fields = type.GetFields(bindingAttr);
						foreach (FieldInfo fieldInfo3 in fields)
						{
							if (typeof(Recipe).IsAssignableFrom(fieldInfo3.FieldType))
							{
								object? value6 = fieldInfo3.GetValue(value);
								val = (Recipe)((value6 is Recipe) ? value6 : null);
								if ((Object)(object)val != (Object)null)
								{
									YourThirstyPlugin.Log.LogInfo((object)("DoCraftingPrefix: Found Recipe via field '" + fieldInfo3.Name + "'"));
									break;
								}
							}
						}
					}
					if ((Object)(object)val == (Object)null)
					{
						PropertyInfo[] properties = type.GetProperties(bindingAttr);
						foreach (PropertyInfo propertyInfo in properties)
						{
							if (typeof(Recipe).IsAssignableFrom(propertyInfo.PropertyType) && propertyInfo.CanRead)
							{
								object? value7 = propertyInfo.GetValue(value, null);
								val = (Recipe)((value7 is Recipe) ? value7 : null);
								if ((Object)(object)val != (Object)null)
								{
									YourThirstyPlugin.Log.LogInfo((object)("DoCraftingPrefix: Found Recipe via property '" + propertyInfo.Name + "'"));
									break;
								}
							}
						}
					}
					if ((Object)(object)val == (Object)null)
					{
						YourThirstyPlugin.Log.LogWarning((object)("DoCraftingPrefix: Could not extract Recipe from " + type.FullName + ". Members:"));
						FieldInfo[] fields = type.GetFields(bindingAttr);
						foreach (FieldInfo fieldInfo4 in fields)
						{
							YourThirstyPlugin.Log.LogWarning((object)("  field: " + fieldInfo4.Name + " (" + fieldInfo4.FieldType.FullName + ")"));
						}
						PropertyInfo[] properties = type.GetProperties(bindingAttr);
						foreach (PropertyInfo propertyInfo2 in properties)
						{
							YourThirstyPlugin.Log.LogWarning((object)("  prop: " + propertyInfo2.Name + " (" + propertyInfo2.PropertyType.FullName + ")"));
						}
					}
				}
				if ((Object)(object)val == (Object)null)
				{
					YourThirstyPlugin.Log.LogInfo((object)("DoCraftingPrefix: recipe is null (selectedObj type=" + (value?.GetType().FullName ?? "null") + ")"));
					return true;
				}
				ManualLogSource log = YourThirstyPlugin.Log;
				string[] obj = new string[5]
				{
					"DoCraftingPrefix: Crafting recipe '",
					((Object)val).name,
					"' (item=",
					null,
					null
				};
				ItemDrop item = val.m_item;
				obj[3] = ((item != null) ? ((Object)item).name : null) ?? "null";
				obj[4] = ")";
				log.LogInfo((object)string.Concat(obj));
				bool num = ((Object)val).name == "Recipe_BoilWater" || ((Object)(object)val.m_item != (Object)null && ((Object)val.m_item).name == "YT_BoilWater");
				bool flag = ((Object)val).name == "Recipe_CollectBoiledWater" || ((Object)(object)val.m_item != (Object)null && ((Object)val.m_item).name == "YT_CollectBoiledWater");
				if (num)
				{
					YourThirstyPlugin.Log.LogInfo((object)"DoCraftingPrefix: Intercepted Recipe_BoilWater.");
					HandleBoilWater(player);
					return false;
				}
				if (flag)
				{
					YourThirstyPlugin.Log.LogInfo((object)"DoCraftingPrefix: Intercepted Recipe_CollectBoiledWater.");
					HandleCollectBoiledWater(player);
					return false;
				}
			}
			catch (Exception ex)
			{
				YourThirstyPlugin.Log.LogWarning((object)("DoCraftingPrefix: " + ex.Message));
			}
			return true;
		}

		private static void HandleBoilWater(Player player)
		{
			ItemData val = FindBucketWithWater(player);
			if (val == null)
			{
				YourThirstyPlugin.Log.LogInfo((object)"HandleBoilWater: No bucket with water found.");
				((Character)player).Message((MessageType)2, "You need a Water Bucket with water.", 0, (Sprite)null, false);
				return;
			}
			YourThirstyPlugin.Log.LogInfo((object)$"HandleBoilWater: Found bucket '{val.m_shared?.m_name}' with {BucketItem.GetWater(val)} water.");
			CauldronBoiling currentCauldronBoiling = GetCurrentCauldronBoiling(player);
			if ((Object)(object)currentCauldronBoiling == (Object)null)
			{
				YourThirstyPlugin.Log.LogWarning((object)"HandleBoilWater: No cauldron found nearby.");
				((Character)player).Message((MessageType)2, "No cauldron found.", 0, (Sprite)null, false);
				return;
			}
			if (currentCauldronBoiling.IsBoilActive())
			{
				((Character)player).Message((MessageType)2, "Cauldron is already boiling.", 0, (Sprite)null, false);
				return;
			}
			YourThirstyPlugin.Log.LogInfo((object)"HandleBoilWater: Attempting to start boil...");
			if (!currentCauldronBoiling.StartBoil())
			{
				YourThirstyPlugin.Log.LogWarning((object)"HandleBoilWater: StartBoil failed — bucket NOT emptied.");
				((Character)player).Message((MessageType)2, "Failed to start boiling — try again.", 0, (Sprite)null, false);
				return;
			}
			BucketItem.Empty(val);
			SFXManager.PlayRefill(player);
			((Character)player).Message((MessageType)2, "Water placed in cauldron. Boiling...", 0, (Sprite)null, false);
			YourThirstyPlugin.Log.LogInfo((object)"HandleBoilWater: Boil started, bucket emptied.");
		}

		private static void HandleCollectBoiledWater(Player player)
		{
			CauldronBoiling currentCauldronBoiling = GetCurrentCauldronBoiling(player);
			if ((Object)(object)currentCauldronBoiling == (Object)null || !currentCauldronBoiling.IsReady())
			{
				((Character)player).Message((MessageType)2, "No boiled water ready.", 0, (Sprite)null, false);
				return;
			}
			ItemData val = FindEmptyBucket(player);
			if (val == null)
			{
				((Character)player).Message((MessageType)2, "You need an empty Water Bucket.", 0, (Sprite)null, false);
				return;
			}
			BucketItem.SetWater(val, BucketItem.Capacity);
			BucketItem.SetDirty(val, dirty: false);
			BucketItem.SetBoiling(val, boiling: true);
			currentCauldronBoiling.ResetBoil();
			SFXManager.PlayRefill(player);
			((Character)player).Message((MessageType)2, "Collected boiling water. Place it with the hammer to cool.", 0, (Sprite)null, false);
		}

		private static void HaveRequirementsPostfix(Player __instance, ref bool __result, Recipe __0, bool __1)
		{
			if ((Object)(object)__0 == (Object)null)
			{
				return;
			}
			bool flag = __1;
			try
			{
				if (((Object)__0).name == "Recipe_BoilWater")
				{
					CauldronBoiling currentCauldronBoiling = GetCurrentCauldronBoiling(__instance);
					if ((Object)(object)currentCauldronBoiling != (Object)null && currentCauldronBoiling.IsBoilActive())
					{
						__result = false;
					}
					else if (flag)
					{
						__result = BucketItem.HasBucketInInventory(__instance);
					}
					else if (FindBucketWithWater(__instance) == null)
					{
						__result = false;
					}
					else if ((Object)(object)currentCauldronBoiling == (Object)null)
					{
						__result = false;
					}
					else
					{
						__result = true;
					}
				}
				else if (((Object)__0).name == "Recipe_CollectBoiledWater")
				{
					CauldronBoiling currentCauldronBoiling2 = GetCurrentCauldronBoiling(__instance);
					if ((Object)(object)currentCauldronBoiling2 == (Object)null || !currentCauldronBoiling2.IsReady())
					{
						__result = false;
						return;
					}
					if (flag)
					{
						__result = true;
						return;
					}
					ItemData val = FindEmptyBucket(__instance);
					__result = val != null;
				}
			}
			catch (Exception ex)
			{
				YourThirstyPlugin.Log.LogWarning((object)("HaveRequirementsPostfix: " + ex.Message));
			}
		}

		private static ItemData FindBucketWithWater(Player player)
		{
			Inventory val = ((player != null) ? ((Humanoid)player).GetInventory() : null);
			if (val == null)
			{
				return null;
			}
			foreach (ItemData allItem in val.GetAllItems())
			{
				if (allItem?.m_shared != null && allItem.m_shared.m_name == "YourThirsty_WaterBucket" && BucketItem.GetWater(allItem) > 0 && !BucketItem.IsBoiling(allItem))
				{
					return allItem;
				}
			}
			return null;
		}

		private static ItemData FindEmptyBucket(Player player)
		{
			Inventory val = ((player != null) ? ((Humanoid)player).GetInventory() : null);
			if (val == null)
			{
				return null;
			}
			foreach (ItemData allItem in val.GetAllItems())
			{
				if (allItem?.m_shared != null && allItem.m_shared.m_name == "YourThirsty_WaterBucket" && BucketItem.IsEmpty(allItem))
				{
					return allItem;
				}
			}
			return null;
		}

		private static CauldronBoiling GetCurrentCauldronBoiling(Player player)
		{
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			CraftingStation currentCraftingStation = player.GetCurrentCraftingStation();
			if ((Object)(object)currentCraftingStation != (Object)null && ((Object)((Component)currentCraftingStation).gameObject).name.StartsWith("piece_cauldron"))
			{
				CauldronBoiling cauldronBoiling = ((Component)currentCraftingStation).GetComponent<CauldronBoiling>();
				if ((Object)(object)cauldronBoiling == (Object)null)
				{
					cauldronBoiling = ((Component)currentCraftingStation).gameObject.AddComponent<CauldronBoiling>();
				}
				return cauldronBoiling;
			}
			Collider[] array = Physics.OverlapSphere(((Component)player).transform.position, 5f);
			Collider[] array2 = array;
			foreach (Collider val in array2)
			{
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				GameObject gameObject = ((Component)val).gameObject;
				if (((Object)gameObject).name.StartsWith("piece_cauldron"))
				{
					CauldronBoiling cauldronBoiling2 = gameObject.GetComponent<CauldronBoiling>();
					if ((Object)(object)cauldronBoiling2 == (Object)null)
					{
						cauldronBoiling2 = gameObject.AddComponent<CauldronBoiling>();
					}
					return cauldronBoiling2;
				}
			}
			array2 = array;
			foreach (Collider val2 in array2)
			{
				if ((Object)(object)val2 == (Object)null)
				{
					continue;
				}
				CookingStation componentInParent = ((Component)val2).GetComponentInParent<CookingStation>();
				if ((Object)(object)componentInParent != (Object)null && ((Object)((Component)componentInParent).gameObject).name.StartsWith("piece_cauldron"))
				{
					CauldronBoiling cauldronBoiling3 = ((Component)componentInParent).GetComponent<CauldronBoiling>();
					if ((Object)(object)cauldronBoiling3 == (Object)null)
					{
						cauldronBoiling3 = ((Component)componentInParent).gameObject.AddComponent<CauldronBoiling>();
					}
					return cauldronBoiling3;
				}
			}
			return null;
		}
	}
	[HarmonyPatch(typeof(CookingStation), "GetHoverText")]
	internal static class CauldronHoverTextPatch
	{
		[HarmonyPostfix]
		private static void Postfix(CookingStation __instance, ref string __result)
		{
			if (!((Object)(object)__instance == (Object)null) && ((Object)((Component)__instance).gameObject).name.StartsWith("piece_cauldron"))
			{
				CauldronBoilHoverHelper.AppendBoilStatus(((Component)__instance).gameObject, ref __result);
			}
		}
	}
	[HarmonyPatch(typeof(CookingStation), "Awake")]
	internal static class CauldronPatch
	{
		[HarmonyPostfix]
		private static void Postfix(CookingStation __instance)
		{
			if (!((Object)(object)__instance == (Object)null) && ((Object)((Component)__instance).gameObject).name.StartsWith("piece_cauldron") && (Object)(object)((Component)__instance).GetComponent<CauldronBoiling>() == (Object)null)
			{
				((Component)__instance).gameObject.AddComponent<CauldronBoiling>();
				YourThirstyPlugin.Log.LogInfo((object)("CauldronPatch: Added CauldronBoiling to '" + ((Object)((Component)__instance).gameObject).name + "'."));
			}
		}
	}
	internal static class CleanWaterDetector
	{
		private const float WellDetectRadius = 5f;

		public static bool IsNearCleanSource(Player player)
		{
			if ((Object)(object)player == (Object)null)
			{
				return false;
			}
			if (IsNearWell(player))
			{
				return true;
			}
			if (!WaterSourceDetector.IsNearWater(player) && !WaterSourceDetector.IsLookingAtWater())
			{
				return false;
			}
			return WaterSourceDetector.IsCleanBiome(player);
		}

		private static bool IsNearWell(Player player)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			Collider[] array = Physics.OverlapSphere(((Component)player).transform.position, 5f, -5, (QueryTriggerInteraction)2);
			for (int i = 0; i < array.Length; i++)
			{
				if ((Object)(object)array[i] != (Object)null && (Object)(object)((Component)array[i]).GetComponentInParent<Well>() != (Object)null)
				{
					return true;
				}
			}
			return false;
		}
	}
	internal static class ConfigManager
	{
		public static ConfigEntry<DifficultyLevel> Difficulty;

		public static ConfigEntry<float> ThirstDurationMinutes;

		public static ConfigEntry<float> CleanHydrationAmount;

		public static ConfigEntry<float> DirtyHydrationAmount;

		public static ConfigEntry<float> DrinkDurationSeconds;

		public static ConfigEntry<float> HydratedDuration;

		public static ConfigEntry<float> SicknessDuration;

		public static ConfigEntry<float> DirtyWaterSpeedPenalty;

		public static ConfigEntry<int> WaterskinCapacity;

		public static ConfigEntry<int> HornCapacity;

		public static ConfigEntry<int> BucketCapacity;

		public static ConfigEntry<int> BarrelCapacity;

		public static ConfigEntry<float> BucketSpeedPenalty;

		public static ConfigEntry<float> BoilDurationSeconds;

		public static ConfigEntry<float> CoolDurationSeconds;

		public static void Init(ConfigFile config)
		{
			Difficulty = config.Bind<DifficultyLevel>("Difficulty", "DifficultyLevel", DifficultyLevel.Casual, "Easy = forgiving (slow thirst, big drinks, fast boil).\nCasual = balanced (normal thirst, moderate drinks).\nHard = punishing (fast thirst, small drinks, slow boil, harsh debuffs).\nCustom = use the manual values below without overwriting them.");
			ThirstDurationMinutes = config.Bind<float>("Thirst", "ThirstDurationMinutes", 35f, "Time in minutes to go from 0 to max thirst.");
			CleanHydrationAmount = config.Bind<float>("Thirst", "CleanHydrationAmount", 20f, "Thirst reduced per drink (20 = 20% hydration restored).");
			DirtyHydrationAmount = config.Bind<float>("Thirst", "DirtyHydrationAmount", 20f, "Thirst reduced per dirty water drink (20 = 20% hydration restored, before dirty penalty).");
			DrinkDurationSeconds = config.Bind<float>("Thirst", "DrinkDurationSeconds", 4f, "Duration of drink animation.");
			HydratedDuration = config.Bind<float>("Buffs", "HydratedDuration", 160f, "Duration in seconds of the Hydrated buff after drinking clean water (160 = 2m 40s).");
			SicknessDuration = config.Bind<float>("Buffs", "SicknessDuration", 160f, "Duration in seconds of the Dirty Water debuff from dirty water (160 = 2m 40s).");
			DirtyWaterSpeedPenalty = config.Bind<float>("Buffs", "DirtyWaterSpeedPenalty", 0.2f, "Movement speed reduction fraction when sick from dirty water (0.20 = 20%).");
			WaterskinCapacity = config.Bind<int>("Containers", "WaterskinCapacity", 5, "Units of water a waterskin holds.");
			HornCapacity = config.Bind<int>("Containers", "HornCapacity", 3, "Units of water a horn holds.");
			BucketCapacity = config.Bind<int>("Containers", "BucketCapacity", 6, "Units of water a bucket carries.");
			BarrelCapacity = config.Bind<int>("Containers", "BarrelCapacity", 12, "Units of water a barrel stores (12 = 2 full bucket pours).");
			BucketSpeedPenalty = config.Bind<float>("Containers", "BucketSpeedPenalty", 3f, "Movement speed reduction when carrying a full bucket.");
			BoilDurationSeconds = config.Bind<float>("Boiling", "BoilDurationSeconds", 150f, "Time in seconds for water to boil in the cauldron (150 = 2 min 30 sec).");
			CoolDurationSeconds = config.Bind<float>("Boiling", "CoolDurationSeconds", 60f, "Time in seconds for boiling water to cool after being placed (60 = 1 min).");
			ApplyDifficultyPreset();
		}

		public static void ApplyDifficultyPreset()
		{
			DifficultyLevel value = Difficulty.Value;
			switch (value)
			{
			case DifficultyLevel.Custom:
				return;
			case DifficultyLevel.Easy:
				ThirstDurationMinutes.Value = 45f;
				CleanHydrationAmount.Value = 25f;
				DirtyHydrationAmount.Value = 20f;
				DrinkDurationSeconds.Value = 3f;
				HydratedDuration.Value = 200f;
				SicknessDuration.Value = 90f;
				DirtyWaterSpeedPenalty.Value = 0.1f;
				WaterskinCapacity.Value = 6;
				HornCapacity.Value = 4;
				BucketCapacity.Value = 8;
				BarrelCapacity.Value = 16;
				BucketSpeedPenalty.Value = 2f;
				BoilDurationSeconds.Value = 90f;
				CoolDurationSeconds.Value = 30f;
				break;
			case DifficultyLevel.Casual:
				ThirstDurationMinutes.Value = 35f;
				CleanHydrationAmount.Value = 20f;
				DirtyHydrationAmount.Value = 20f;
				DrinkDurationSeconds.Value = 4f;
				HydratedDuration.Value = 160f;
				SicknessDuration.Value = 160f;
				DirtyWaterSpeedPenalty.Value = 0.2f;
				WaterskinCapacity.Value = 5;
				HornCapacity.Value = 3;
				BucketCapacity.Value = 6;
				BarrelCapacity.Value = 12;
				BucketSpeedPenalty.Value = 3f;
				BoilDurationSeconds.Value = 150f;
				CoolDurationSeconds.Value = 60f;
				break;
			case DifficultyLevel.Hard:
				ThirstDurationMinutes.Value = 22f;
				CleanHydrationAmount.Value = 15f;
				DirtyHydrationAmount.Value = 12f;
				DrinkDurationSeconds.Value = 5f;
				HydratedDuration.Value = 100f;
				SicknessDuration.Value = 240f;
				DirtyWaterSpeedPenalty.Value = 0.3f;
				WaterskinCapacity.Value = 3;
				HornCapacity.Value = 2;
				BucketCapacity.Value = 5;
				BarrelCapacity.Value = 10;
				BucketSpeedPenalty.Value = 4f;
				BoilDurationSeconds.Value = 210f;
				CoolDurationSeconds.Value = 90f;
				break;
			}
			YourThirstyPlugin.Log.LogInfo((object)$"ConfigManager: Applied '{value}' difficulty preset.");
		}
	}
	internal class ContainerState
	{
		public ItemData Item;

		public int CurrentAmount;

		public int MaxAmount;

		public bool IsDirty;

		public ContainerState(ItemData item, int max)
		{
			Item = item;
			MaxAmount = max;
			CurrentAmount = 0;
			IsDirty = false;
		}
	}
	internal class CoroutineHost : MonoBehaviour
	{
		private static CoroutineHost _instance;

		public static CoroutineHost Instance => EnsureExists();

		public static CoroutineHost EnsureExists()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			if ((Object)(object)_instance != (Object)null)
			{
				return _instance;
			}
			GameObject val = new GameObject("YourThirsty_CoroutineHost");
			Object.DontDestroyOnLoad((Object)val);
			_instance = val.AddComponent<CoroutineHost>();
			return _instance;
		}
	}
	internal enum DifficultyLevel
	{
		Easy,
		Casual,
		Hard,
		Custom
	}
	internal static class DrinkSystem
	{
		private static Coroutine _drinkRoutine;

		public static bool IsBusy => _drinkRoutine != null;

		public static void TryDrink()
		{
			Player localPlayer = Player.m_localPlayer;
			if (!((Object)(object)localPlayer == (Object)null) && !((Character)localPlayer).IsSwimming() && _drinkRoutine == null)
			{
				if (!ItemManager.CanDrinkFromContainer(localPlayer, out var state))
				{
					SFXManager.PlayEmpty(localPlayer);
					return;
				}
				bool isDirty = state.IsDirty;
				AnimationManager.PrepareDrink(localPlayer, PlayerAnimationInjector.DrinkAnimMode.ContainerDrink);
				_drinkRoutine = ((MonoBehaviour)CoroutineHost.Instance).StartCoroutine(ContainerDrinkRoutine(localPlayer, isDirty));
			}
		}

		public static void TryDrinkNatural()
		{
			Player localPlayer = Player.m_localPlayer;
			if (!((Object)(object)localPlayer == (Object)null) && !((Character)localPlayer).IsSwimming() && _drinkRoutine == null && WaterSourceDetector.CanInteractWithWater(localPlayer))
			{
				bool isDirty = WaterSourceDetector.IsDirtyWater(localPlayer);
				AnimationManager.PrepareDrink(localPlayer, PlayerAnimationInjector.DrinkAnimMode.NaturalWater);
				_drinkRoutine = ((MonoBehaviour)CoroutineHost.Instance).StartCoroutine(NaturalDrinkRoutine(localPlayer, isDirty));
			}
		}

		public static void TryFillEquipped(bool isDirty)
		{
			Player localPlayer = Player.m_localPlayer;
			if (!((Object)(object)localPlayer == (Object)null) && _drinkRoutine == null && ItemManager.CanFill(localPlayer, isDirty, out var _))
			{
				AnimationManager.PrepareDrink(localPlayer, PlayerAnimationInjector.DrinkAnimMode.ContainerRefill);
				_drinkRoutine = ((MonoBehaviour)CoroutineHost.Instance).StartCoroutine(FillEquippedRoutine(localPlayer, isDirty));
			}
		}

		private static IEnumerator NaturalDrinkRoutine(Player player, bool isDirty)
		{
			try
			{
				float timer = 0f;
				float duration = ConfigManager.DrinkDurationSeconds.Value;
				if (isDirty)
				{
					SFXManager.PlayDirty(player);
				}
				else
				{
					SFXManager.PlayDrink(player);
				}
				while (timer < duration)
				{
					if (!((Object)(object)player == (Object)null) && !((Character)player).IsDead() && !((Character)player).IsSwimming())
					{
						Vector3 velocity = ((Character)player).GetVelocity();
						if (!(((Vector3)(ref velocity)).magnitude > 2f) && WaterSourceDetector.IsNearWater(player))
						{
							timer += Time.deltaTime;
							UIManager.SetFillProgress(timer / duration);
							yield return null;
							continue;
						}
					}
					PlayerAnimationInjector.Stop();
					UIManager.HideFillBar();
					yield break;
				}
				UIManager.HideFillBar();
				ThirstSystem.ApplyDrink(isDirty ? ConfigManager.DirtyHydrationAmount.Value : ConfigManager.CleanHydrationAmount.Value, isDirty);
				BuffManager.ApplyDrinkEffects(player, isDirty);
				if (isDirty)
				{
					UIManager.FlashDirtyWater();
				}
			}
			finally
			{
				_drinkRoutine = null;
			}
		}

		private static IEnumerator ContainerDrinkRoutine(Player player, bool isDirty)
		{
			try
			{
				float timer = 0f;
				float duration = ConfigManager.DrinkDurationSeconds.Value;
				if (isDirty)
				{
					SFXManager.PlayDirty(player);
				}
				else
				{
					SFXManager.PlayDrink(player);
				}
				while (timer < duration)
				{
					if (!((Object)(object)player == (Object)null) && !((Character)player).IsDead() && !((Character)player).IsSwimming())
					{
						Vector3 velocity = ((Character)player).GetVelocity();
						if (!(((Vector3)(ref velocity)).magnitude > 2f))
						{
							timer += Time.deltaTime;
							UIManager.SetFillProgress(timer / duration);
							yield return null;
							continue;
						}
					}
					PlayerAnimationInjector.Stop();
					UIManager.HideFillBar();
					yield break;
				}
				UIManager.HideFillBar();
				ItemManager.Drink(player);
				ThirstSystem.ApplyDrink(isDirty ? ConfigManager.DirtyHydrationAmount.Value : ConfigManager.CleanHydrationAmount.Value, isDirty);
				BuffManager.ApplyDrinkEffects(player, isDirty);
				if (isDirty)
				{
					UIManager.FlashDirtyWater();
				}
			}
			finally
			{
				_drinkRoutine = null;
			}
		}

		private static IEnumerator FillEquippedRoutine(Player player, bool isDirty)
		{
			try
			{
				float timer = 0f;
				SFXManager.PlayRefill(player);
				while (timer < 4f)
				{
					if (!((Object)(object)player == (Object)null) && !((Character)player).IsDead() && !((Character)player).IsSwimming())
					{
						Vector3 velocity = ((Character)player).GetVelocity();
						if (!(((Vector3)(ref velocity)).magnitude > 2f))
						{
							timer += Time.deltaTime;
							UIManager.SetFillProgress(timer / 4f);
							yield return null;
							continue;
						}
					}
					float num = timer / 4f;
					if (num > 0.05f)
					{
						ItemManager.PartialFill(player, isDirty, num);
					}
					PlayerAnimationInjector.Stop();
					UIManager.HideFillBar();
					yield break;
				}
				ItemManager.Fill(player, isDirty);
				UIManager.HideFillBar();
			}
			finally
			{
				_drinkRoutine = null;
			}
		}

		public static void TryFillBucket(bool isDirty)
		{
			Player localPlayer = Player.m_localPlayer;
			if (!((Object)(object)localPlayer == (Object)null) && _drinkRoutine == null)
			{
				ItemData firstBucketInInventory = BucketItem.GetFirstBucketInInventory(localPlayer);
				if (firstBucketInInventory != null && !BucketItem.IsFull(firstBucketInInventory))
				{
					AnimationManager.PrepareDrink(localPlayer, PlayerAnimationInjector.DrinkAnimMode.ContainerRefill);
					_drinkRoutine = ((MonoBehaviour)CoroutineHost.Instance).StartCoroutine(FillBucketRoutine(localPlayer, firstBucketInInventory, isDirty));
				}
			}
		}

		private static IEnumerator FillBucketRoutine(Player player, ItemData bucket, bool isDirty)
		{
			try
			{
				float timer = 0f;
				SFXManager.PlayRefill(player);
				while (timer < 5f)
				{
					if (!((Object)(object)player == (Object)null) && !((Character)player).IsDead() && !((Character)player).IsSwimming())
					{
						Vector3 velocity = ((Character)player).GetVelocity();
						if (!(((Vector3)(ref velocity)).magnitude > 2f))
						{
							timer += Time.deltaTime;
							UIManager.SetFillProgress(timer / 5f);
							yield return null;
							continue;
						}
					}
					float num = timer / 5f;
					if (num > 0.05f)
					{
						int amount = Mathf.Max(1, Mathf.FloorToInt((float)BucketItem.Capacity * num));
						BucketItem.SetWater(bucket, amount);
						BucketItem.SetDirty(bucket, isDirty);
					}
					PlayerAnimationInjector.Stop();
					UIManager.HideFillBar();
					yield break;
				}
				BucketItem.Fill(bucket, isDirty);
				UIManager.HideFillBar();
			}
			finally
			{
				_drinkRoutine = null;
			}
		}

		public static void TryDrinkFromWell()
		{
			Player localPlayer = Player.m_localPlayer;
			if (!((Object)(object)localPlayer == (Object)null) && _drinkRoutine == null)
			{
				ThirstSystem.ApplyDrink(ConfigManager.CleanHydrationAmount.Value, dirty: false);
				SFXManager.PlayDrink(localPlayer);
			}
		}
	}
	internal class GroundLock : MonoBehaviour
	{
		private float _groundY;

		private Rigidbody _rb;

		public void Lock()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			_groundY = ((Component)this).transform.position.y;
			_rb = ((Component)this).GetComponent<Rigidbody>();
		}

		private void LateUpdate()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: 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_0026: 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_0038: 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)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: 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)
			Vector3 position = ((Component)this).transform.position;
			if (position.y > _groundY + 0.01f)
			{
				((Component)this).transform.position = new Vector3(position.x, _groundY, position.z);
			}
			if ((Object)(object)_rb != (Object)null)
			{
				Vector3 linearVelocity = _rb.linearVelocity;
				if (linearVelocity.y > 0.01f)
				{
					_rb.linearVelocity = new Vector3(linearVelocity.x, 0f, linearVelocity.z);
				}
			}
		}

		public void Unlock()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: 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_002b: 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)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			Vector3 position = ((Component)this).transform.position;
			if (Mathf.Abs(position.y - _groundY) > 0.01f)
			{
				((Component)this).transform.position = new Vector3(position.x, _groundY, position.z);
			}
			Object.Destroy((Object)(object)this);
		}
	}
	[HarmonyPatch]
	internal static class HaveRequirementsPiecePatch
	{
		[HarmonyTargetMethod]
		private static MethodBase TargetMethod()
		{
			MethodInfo[] methods = typeof(Player).GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			foreach (MethodInfo methodInfo in methods)
			{
				if (methodInfo.Name != "HaveRequirements")
				{
					continue;
				}
				ParameterInfo[] parameters = methodInfo.GetParameters();
				if (parameters.Length < 1 || !(parameters[0].ParameterType == typeof(Piece)))
				{
					continue;
				}
				ManualLogSource log = YourThirstyPlugin.Log;
				if (log != null)
				{
					log.LogInfo((object)("HaveRequirementsPiecePatch: TargetMethod resolved → " + methodInfo.DeclaringType.Name + "." + methodInfo.Name + "(" + string.Join(", ", Array.ConvertAll(parameters, (ParameterInfo p) => p.ParameterType.Name)) + ")"));
				}
				return methodInfo;
			}
			ManualLogSource log2 = YourThirstyPlugin.Log;
			if (log2 != null)
			{
				log2.LogError((object)"HaveRequirementsPiecePatch: TargetMethod FAILED — could not find HaveRequirements(Piece, ...)");
			}
			return null;
		}

		[HarmonyPostfix]
		private static void Postfix(Player __instance, ref bool __result, Piece __0)
		{
			try
			{
				if ((Object)(object)__0 == (Object)null)
				{
					return;
				}
				string text = PieceRequirementPatch.CleanName(((Object)((Component)__0).gameObject).name);
				if (PieceRequirementPatch.IsModPiece(text))
				{
					if (PieceRequirementPatch.IsDebugFree(__instance))
					{
						__result = true;
						return;
					}
					bool flag = PieceRequirementPatch.HasMaterials(__instance, text);
					YourThirstyPlugin.Log.LogInfo((object)$"[ATTR] HaveRequirements(Piece) POSTFIX: '{text}' native={__result} override={flag}");
					__result = flag;
				}
			}
			catch (Exception ex)
			{
				YourThirstyPlugin.Log.LogWarning((object)("HaveRequirementsPiecePatch: " + ex.Message));
			}
		}
	}
	[HarmonyPatch(typeof(Hud), "Update")]
	internal static class HudPatches
	{
		private static GameObject _thirstRoot;

		private static Text _thirstText;

		private static Image _thirstIcon;

		private static Sprite _spriteHydrated;

		private static Sprite _spriteThirsty;

		private static GameObject _hoverRoot;

		private static Text _hoverText;

		private static void Postfix(Hud __instance)
		{
			try
			{
				if (!((Object)(object)Player.m_localPlayer == (Object)null))
				{
					UpdateThirstHud(__instance);
					UpdateWaterHoverHud(__instance);
					UIManager.DrawFillBar();
				}
			}
			catch (Exception ex)
			{
				YourThirstyPlugin.Log.LogError((object)("HudPatches error: " + ex.Message));
			}
		}

		private static void UpdateThirstHud(Hud hud)
		{
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_thirstRoot == (Object)null)
			{
				CreateThirstHud(hud);
			}
			if ((Object)(object)_thirstRoot == (Object)null)
			{
				return;
			}
			float currentThirst = ThirstSystem.CurrentThirst;
			if ((Object)(object)_thirstText != (Object)null)
			{
				int num = Mathf.RoundToInt(100f - currentThirst);
				_thirstText.text = $"{num}%";
				if (currentThirst >= 80f)
				{
					((Graphic)_thirstText).color = Color.red;
				}
				else if (currentThirst >= 60f)
				{
					((Graphic)_thirstText).color = Color.yellow;
				}
				else
				{
					((Graphic)_thirstText).color = new Color(0.5f, 0.85f, 1f);
				}
			}
			if ((Object)(object)_thirstIcon != (Object)null)
			{
				_thirstIcon.sprite = ((currentThirst >= 60f) ? _spriteThirsty : _spriteHydrated);
			}
		}

		private static string GetContainerDrinkName(Player player)
		{
			if (ItemManager.CanDrinkFromContainer(player, out var state) && state != null && state.Item != null)
			{
				string text = state.Item.m_shared?.m_name;
				if (text == "YourThirsty_Waterskin")
				{
					return "Drink from Waterskin";
				}
				if (text == "YourThirsty_Horn")
				{
					return "Drink from Horn";
				}
			}
			return "Drink from Container";
		}

		private static void UpdateWaterHoverHud(Hud hud)
		{
			if ((Object)(object)_hoverRoot == (Object)null)
			{
				CreateHoverHud(hud);
			}
			if ((Object)(object)_hoverRoot == (Object)null)
			{
				return;
			}
			bool flag = UIManager.IsShowingDrinkWater();
			bool flag2 = UIManager.IsShowingRefillPrompt();
			bool flag3 = UIManager.IsShowingDrinkContainer();
			bool flag4 = UIManager.IsShowingEmptyContainer();
			bool flag5 = UIManager.IsShowingFillBucket();
			Player localPlayer = Player.m_localPlayer;
			if (flag || flag2 || flag3 || flag4 || flag5)
			{
				_hoverRoot.SetActive(true);
				if (!((Object)(object)_hoverText != (Object)null))
				{
					return;
				}
				string drinkKeyName = YourThirstyPlugin.DrinkKeyName;
				string refillKeyName = YourThirstyPlugin.RefillKeyName;
				string text = "";
				if (flag5)
				{
					text = text + "<color=yellow>[" + drinkKeyName + "]</color> Fill Bucket";
				}
				if (flag)
				{
					text = text + "<color=yellow>[" + drinkKeyName + "]</color> Drink";
				}
				if (flag2)
				{
					text = text + "<color=yellow>[" + drinkKeyName + "]</color> Refill";
				}
				if (flag4 && !flag && !flag2)
				{
					text = text + "<color=yellow>[" + drinkKeyName + "]</color> Empty Container";
				}
				if (flag3)
				{
					if (text.Length > 0)
					{
						text += "\n";
					}
					text = text + "<color=yellow>[" + refillKeyName + "]</color> " + GetContainerDrinkName(localPlayer);
				}
				_hoverText.text = text;
			}
			else
			{
				_hoverRoot.SetActive(false);
			}
		}

		private static void CreateThirstHud(Hud hud)
		{
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Expected O, but got Unknown
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_020e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: Unknown result type (might be due to invalid IL or missing references)
			//IL_0223: Unknown result type (might be due to invalid IL or missing references)
			//IL_0267: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: 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_0058: 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)
			//IL_00a3: 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_00b2: Unknown result type (might be due to invalid IL or missing references)
			GameObject rootObject = hud.m_rootObject;
			if ((Object)(object)rootObject == (Object)null)
			{
				return;
			}
			if ((Object)(object)YourThirstyPlugin.AssetBundle != (Object)null)
			{
				Texture2D val = YourThirstyPlugin.AssetBundle.LoadAsset<Texture2D>("Hydrated");
				if ((Object)(object)val != (Object)null)
				{
					_spriteHydrated = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), Vector2.one * 0.5f);
				}
				Texture2D val2 = YourThirstyPlugin.AssetBundle.LoadAsset<Texture2D>("Thirsty");
				if ((Object)(object)val2 != (Object)null)
				{
					_spriteThirsty = Sprite.Create(val2, new Rect(0f, 0f, (float)((Texture)val2).width, (float)((Texture)val2).height), Vector2.one * 0.5f);
				}
			}
			_thirstRoot = new GameObject("YT_ThirstHud");
			_thirstRoot.transform.SetParent(rootObject.transform, false);
			RectTransform obj = _thirstRoot.AddComponent<RectTransform>();
			obj.anchorMin = new Vector2(0.85f, 0.02f);
			obj.anchorMax = new Vector2(0.95f, 0.07f);
			obj.offsetMin = Vector2.zero;
			obj.offsetMax = Vector2.zero;
			if ((Object)(object)_spriteHydrated != (Object)null)
			{
				GameObject val3 = new GameObject("Icon");
				val3.transform.SetParent(_thirstRoot.transform, false);
				RectTransform obj2 = val3.AddComponent<RectTransform>();
				obj2.anchorMin = new Vector2(0f, 0f);
				obj2.anchorMax = new Vector2(0.3f, 1f);
				obj2.offsetMin = Vector2.zero;
				obj2.offsetMax = Vector2.zero;
				_thirstIcon = val3.AddComponent<Image>();
				_thirstIcon.sprite = _spriteHydrated;
				_thirstIcon.preserveAspect = true;
			}
			GameObject val4 = new GameObject("Text");
			val4.transform.SetParent(_thirstRoot.transform, false);
			RectTransform obj3 = val4.AddComponent<RectTransform>();
			obj3.anchorMin = new Vector2(0.35f, 0f);
			obj3.anchorMax = new Vector2(1f, 1f);
			obj3.offsetMin = Vector2.zero;
			obj3.offsetMax = Vector2.zero;
			_thirstText = val4.AddComponent<Text>();
			_thirstText.font = GetDefaultFont(hud);
			_thirstText.fontSize = 16;
			((Graphic)_thirstText).color = new Color(0.5f, 0.85f, 1f);
			_thirstText.text = "100%";
			YourThirstyPlugin.Log.LogInfo((object)"HudPatches: Thirst HUD created.");
		}

		private static Font GetDefaultFont(Hud hud)
		{
			Text componentInChildren = hud.m_rootObject.GetComponentInChildren<Text>(true);
			if ((Object)(object)componentInChildren != (Object)null && (Object)(object)componentInChildren.font != (Object)null)
			{
				return componentInChildren.font;
			}
			Font val = null;
			Font[] array = Resources.FindObjectsOfTypeAll<Font>();
			foreach (Font val2 in array)
			{
				if (!((Object)(object)val2 == (Object)null))
				{
					if (((Object)val2).name.StartsWith("AveriaSerifLibre-Bold", StringComparison.OrdinalIgnoreCase))
					{
						return val2;
					}
					if ((Object)(object)val == (Object)null && ((Object)val2).name.StartsWith("AveriaSerifLibre", StringComparison.OrdinalIgnoreCase))
					{
						val = val2;
					}
				}
			}
			if ((Object)(object)val != (Object)null)
			{
				return val;
			}
			string[] array2 = new string[2] { "LegacyRuntime.ttf", "Arial.ttf" };
			foreach (string text in array2)
			{
				try
				{
					val = Resources.GetBuiltinResource<Font>(text);
					if ((Object)(object)val != (Object)null)
					{
						return val;
					}
				}
				catch (ArgumentException)
				{
				}
			}
			return null;
		}

		private static void CreateHoverHud(Hud hud)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			GameObject rootObject = hud.m_rootObject;
			if (!((Object)(object)rootObject == (Object)null))
			{
				_hoverRoot = new GameObject("YT_WaterHover");
				_hoverRoot.transform.SetParent(rootObject.transform, false);
				_hoverRoot.SetActive(false);
				RectTransform obj = _hoverRoot.AddComponent<RectTransform>();
				obj.anchorMin = new Vector2(0.35f, 0.38f);
				obj.anchorMax = new Vector2(0.65f, 0.45f);
				obj.offsetMin = Vector2.zero;
				obj.offsetMax = Vector2.zero;
				_hoverText = _hoverRoot.AddComponent<Text>();
				_hoverText.font = GetDefaultFont(hud);
				_hoverText.fontSize = 16;
				_hoverText.alignment = (TextAnchor)4;
				_hoverText.supportRichText = true;
				((Graphic)_hoverText).color = Color.white;
				_hoverText.text = "";
				Outline obj2 = _hoverRoot.AddComponent<Outline>();
				((Shadow)obj2).effectColor = Color.black;
				((Shadow)obj2).effectDistance = new Vector2(1f, -1f);
				YourThirstyPlugin.Log.LogInfo((object)"HudPatches: Water hover HUD created.");
			}
		}
	}
	internal static class InteractionManager
	{
		public static void Init()
		{
		}

		public static void Update()
		{
		}
	}
	internal static class InventoryCoolingTicker
	{
		private static float _nextMessageTime;

		private const float MessageInterval = 10f;

		public static void Tick()
		{
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null)
			{
				return;
			}
			Inventory inventory = ((Humanoid)localPlayer).GetInventory();
			if (inventory == null)
			{
				return;
			}
			bool flag = false;
			bool flag2 = false;
			float num = float.MaxValue;
			foreach (ItemData allItem in inventory.GetAllItems())
			{
				if (allItem == null || allItem.m_shared == null || allItem.m_shared.m_name != "YourThirsty_WaterBucket" || !BucketItem.IsBoiling(allItem))
				{
					continue;
				}
				if (BucketItem.GetCoolStartTicks(allItem) <= 0)
				{
					BucketItem.StartInventoryCooling(allItem);
					YourThirstyPlugin.Log.LogInfo((object)"InventoryCoolingTicker: Started cooling for boiling bucket in inventory.");
				}
				if (BucketItem.IsInventoryCooled(allItem))
				{
					BucketItem.FinishCooling(allItem);
					flag = true;
					YourThirstyPlugin.Log.LogInfo((object)"InventoryCoolingTicker: Boiling bucket cooled → clean water.");
					continue;
				}
				flag2 = true;
				float coolTimeRemaining = BucketItem.GetCoolTimeRemaining(allItem);
				if (coolTimeRemaining < num)
				{
					num = coolTimeRemaining;
				}
			}
			if (flag)
			{
				((Character)localPlayer).Message((MessageType)2, "Boiled water has cooled — clean water ready!", 0, (Sprite)null, false);
				SFXManager.PlayRefill(localPlayer);
			}
			else if (flag2 && Time.time >= _nextMessageTime)
			{
				int num2 = Mathf.CeilToInt(num);
				((Character)localPlayer).Message((MessageType)1, $"Boiling water cooling... {num2}s", 0, (Sprite)null, false);
				_nextMessageTime = Time.time + 10f;
			}
		}
	}
	[HarmonyPatch(typeof(InventoryGrid), "UpdateGui")]
	internal static class InventoryWaterBarPatch
	{
		private static readonly Color WaterFill = new Color(0.2f, 0.7f, 1f, 0.85f);

		private static readonly Color BarOutline = new Color(0.4f, 0.7f, 0.9f, 0.5f);

		private static readonly Color BarBackground = new Color(0.1f, 0.1f, 0.15f, 0.7f);

		private static FieldInfo _elementsField;

		private static FieldInfo _inventoryField;

		private static FieldInfo _elementGoField;

		private static FieldInfo _widthField;

		private static bool _fieldsResolved;

		[HarmonyPostfix]
		private static void Postfix(InventoryGrid __instance)
		{
			//IL_02a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (!_fieldsResolved)
				{
					BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
					_elementsField = typeof(InventoryGrid).GetField("m_elements", bindingAttr);
					_inventoryField = typeof(InventoryGrid).GetField("m_inventory", bindingAttr);
					_widthField = typeof(InventoryGrid).GetField("m_width", bindingAttr);
					_fieldsResolved = true;
				}
				if (_elementsField == null || _inventoryField == null || _widthField == null)
				{
					return;
				}
				IList list = _elementsField.GetValue(__instance) as IList;
				object? value = _inventoryField.GetValue(__instance);
				Inventory val = (Inventory)((value is Inventory) ? value : null);
				if (list == null || val == null || list.Count == 0)
				{
					return;
				}
				if (_elementGoField == null && !(list[0] is Component))
				{
					BindingFlags bindingAttr2 = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
					_elementGoField = list[0].GetType().GetField("m_go", bindingAttr2);
					if (_elementGoField == null)
					{
						return;
					}
				}
				int num = (int)_widthField.GetValue(__instance);
				if (num <= 0)
				{
					return;
				}
				for (int i = 0; i < list.Count; i++)
				{
					object obj = list[i];
					if (obj == null)
					{
						continue;
					}
					Component val2 = (Component)((obj is Component) ? obj : null);
					GameObject val3 = (GameObject)((val2 != null) ? ((object)val2.gameObject) : ((object)/*isinst with value type is only supported in some contexts*/));
					if ((Object)(object)val3 == (Object)null)
					{
						continue;
					}
					int num2 = i % num;
					int num3 = i / num;
					ItemData itemAt = val.GetItemAt(num2, num3);
					int num4 = -1;
					int num5 = -1;
					if (itemAt?.m_shared != null)
					{
						switch (itemAt.m_shared.m_name)
						{
						case "YourThirsty_Waterskin":
							num5 = ConfigManager.WaterskinCapacity.Value;
							num4 = ReadContainerWater(itemAt);
							break;
						case "YourThirsty_Horn":
							num5 = ConfigManager.HornCapacity.Value;
							num4 = ReadContainerWater(itemAt);
							break;
						case "YourThirsty_WaterBucket":
							num5 = BucketItem.MaxWater;
							num4 = BucketItem.CurrentWater(itemAt);
							break;
						}
					}
					Transform val4 = val3.transform.Find("YT_WaterBar");
					if (num4 >= 0 && num5 > 0)
					{
						if ((Object)(object)val4 == (Object)null)
						{
							val4 = CreateBarUI(val3).transform;
						}
						((Component)val4).gameObject.SetActive(true);
						float num6 = (float)num4 / (float)num5;
						Transform obj2 =