Decompiled source of Sponge v1.10.18

Sponge.dll

Decompiled 5 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("0.0.0.0")]
[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;
		}
	}
}
namespace SpongeMod
{
	[BepInPlugin("alkin.Sponge", "Sponge", "1.10.18")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	public sealed class Plugin : BaseUnityPlugin
	{
		public const string ModGuid = "alkin.Sponge";

		public const string ModName = "Sponge";

		public const string ModVersion = "1.10.18";

		internal const string DryZonePrefabName = "SpongeDryZone";

		internal static Plugin Instance;

		internal static ConfigEntry<float> HarvestAmountMultiplier;

		internal static ConfigEntry<float> DryingTimeMultiplier;

		internal static ConfigEntry<float> AbsorptionSize;

		internal static ConfigEntry<float> PlacementDistance;

		internal static ConfigEntry<float> SpongeWeight;

		internal static ConfigEntry<bool> PlacementSnapping;

		internal static ConfigEntry<float> AboveWaterPlacementHeight;

		internal static ConfigEntry<float> HeldModelScale;

		internal static ConfigEntry<Vector3> HeldModelOffset;

		internal static ConfigEntry<bool> FollowWaterSurface;

		internal static ConfigEntry<string> DryPreviewColor;

		internal static ConfigEntry<string> RefillPreviewColor;

		internal static ConfigEntry<string> InvalidPreviewColor;

		internal static ConfigEntry<string> DryOverlayColor;

		internal static ConfigEntry<string> RefillOverlayColor;

		internal static ConfigEntry<string> InvalidOverlayColor;

		internal static ConfigEntry<string> DryAreaFillColor;

		internal static ConfigEntry<string> DryAreaOutlineColor;

		internal static ConfigEntry<string> WetAreaFillColor;

		internal static ConfigEntry<string> WetAreaOutlineColor;

		internal static ConfigEntry<string> DryPlacementFillColor;

		internal static ConfigEntry<string> WetPlacementFillColor;

		internal static ConfigEntry<float> DryHologramOpacity;

		internal static ConfigEntry<float> WetHologramOpacity;

		internal static ConfigEntry<bool> DryHologramBorders;

		internal static ConfigEntry<bool> WetHologramBorders;

		private const float SpongeModelScale = 0.25f;

		internal static GameObject WetSpongePrefab;

		internal static GameObject DriedSpongePrefab;

		internal static GameObject DryZonePrefab;

		internal static ManualLogSource Log;

		internal static string VanillaSpongePrefabName;

		private AssetBundle _assetBundle;

		private GameObject _wetSpongeModel;

		private GameObject _driedSpongeModel;

		private Sprite _wetSpongeIcon;

		private Sprite _driedSpongeIcon;

		private Harmony _harmony;

		internal static ButtonConfig SnapPrevious;

		internal static ButtonConfig SnapNext;

		private static readonly HashSet<string> InvalidColors = new HashSet<string>();

		private void Awake()
		{
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e6: Expected O, but got Unknown
			//IL_0319: Unknown result type (might be due to invalid IL or missing references)
			//IL_0323: Expected O, but got Unknown
			//IL_038e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0398: Expected O, but got Unknown
			Instance = this;
			HarvestAmountMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Harvesting", "HarvestAmountMultiplier", 1f, "Multiplier applied to the vanilla sponge harvest/drop amount.");
			DryingTimeMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Drying", "DryingTimeMultiplier", 1f, "Multiplier applied to a vanilla meat cooking time.");
			AbsorptionSize = ((BaseUnityPlugin)this).Config.Bind<float>("Absorption", "AbsorptionSize", 1f, "Side length in metres of the cubic dry volume created by one Dried Sponge. Default 1.0 = 1 metre. Existing loaded zones are resized to this value by their network owner.");
			PlacementDistance = ((BaseUnityPlugin)this).Config.Bind<float>("Absorption", "PlacementDistance", 0f, "0 follows the player build range; a positive value overrides it. No minimum distance from the player.");
			SpongeWeight = ((BaseUnityPlugin)this).Config.Bind<float>("Items", "Weight", 1f, "Weight of both Wet Sponge and Dried Sponge.");
			PlacementSnapping = ((BaseUnityPlugin)this).Config.Bind<bool>("Absorption", "Snapping", true, "Automatically snap Sponge dry areas to nearby existing dry-area edges.");
			AboveWaterPlacementHeight = ((BaseUnityPlugin)this).Config.Bind<float>("Absorption", "AboveWaterPlacementHeight", 4f, "Allow dry-zone placement this many metres above current water. Placement support only: animated water clipping requires a compatible shader.");
			HeldModelScale = ((BaseUnityPlugin)this).Config.Bind<float>("Visuals", "HeldModelScale", 0.12f, "Held sponge scale. Dropped sponge scale is unchanged. Restart after changing.");
			HeldModelOffset = ((BaseUnityPlugin)this).Config.Bind<Vector3>("Visuals", "HeldModelOffset", new Vector3(0f, 0f, 0.06f), "Local held-model offset in metres. Restart after changing.");
			FollowWaterSurface = ((BaseUnityPlugin)this).Config.Bind<bool>("Placement", "FollowWaterSurface", true, "Keep the top of surface placements at current water height. Hold Left Alt for free-height placement.");
			DryPreviewColor = BindHex("DryPreviewColor", "#1AFF33FF", "Valid drying preview edges");
			RefillPreviewColor = BindHex("RefillPreviewColor", "#268CFFFF", "Valid refill preview edges");
			InvalidPreviewColor = BindHex("InvalidPreviewColor", "#FF1A1AFF", "Invalid placement preview edges");
			DryOverlayColor = BindHex("DryOverlayColor", "#00FF00FF", "Drying outline drawn over water");
			RefillOverlayColor = BindHex("RefillOverlayColor", "#00FFFFFF", "Refill outline drawn over water");
			InvalidOverlayColor = BindHex("InvalidOverlayColor", "#FF0000FF", "Invalid outline drawn over water");
			DryAreaFillColor = BindHex("DryAreaFillColor", "#3380FF2E", "Existing dry-area translucent fill");
			DryAreaOutlineColor = BindHex("DryAreaOutlineColor", "#40A6FFCC", "Existing dry-area outline drawn over water");
			WetAreaFillColor = BindHex("WetAreaFillColor", "#3380FF2E", "Existing area fill while holding a Wet Sponge");
			WetAreaOutlineColor = BindHex("WetAreaOutlineColor", "#40A6FFCC", "Existing area border while holding a Wet Sponge");
			DryPlacementFillColor = BindHex("DryPlacementFillColor", "#1AFF332E", "Dry Sponge placement fill");
			WetPlacementFillColor = BindHex("WetPlacementFillColor", "#268CFF2E", "Wet Sponge refill placement fill");
			DryHologramOpacity = ((BaseUnityPlugin)this).Config.Bind<float>("Hologram Colors", "DryHologramOpacity", 1f, new ConfigDescription("Local Dry Sponge hologram opacity multiplier; 0 = invisible, 1 = hex alpha.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			WetHologramOpacity = ((BaseUnityPlugin)this).Config.Bind<float>("Hologram Colors", "WetHologramOpacity", 1f, new ConfigDescription("Local Wet Sponge hologram opacity multiplier; 0 = invisible, 1 = hex alpha.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			DryHologramBorders = ((BaseUnityPlugin)this).Config.Bind<bool>("Hologram Colors", "DryHologramBorders", true, "Local Dry Sponge hologram borders. Disabling keeps translucent fills visible.");
			WetHologramBorders = ((BaseUnityPlugin)this).Config.Bind<bool>("Hologram Colors", "WetHologramBorders", true, "Local Wet Sponge hologram borders. Disabling keeps translucent fills visible.");
			RegisterKeyHints();
			LoadAssets();
			PrefabManager.OnVanillaPrefabsAvailable += OnVanillaPrefabsAvailable;
			_harmony = new Harmony("alkin.Sponge");
			_harmony.PatchAll();
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			((Component)this).gameObject.AddComponent<SpongePlacementController>();
		}

		private ConfigEntry<string> BindHex(string key, string value, string description)
		{
			return ((BaseUnityPlugin)this).Config.Bind<string>("Hologram Colors", key, value, description + ". Hex #RRGGBB or #RRGGBBAA (AA = opacity). Changes apply live. Invalid values use the default.");
		}

		internal static Color ReadHex(ConfigEntry<string> entry, Color fallback)
		{
			//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_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			if (entry == null)
			{
				return fallback;
			}
			string text = entry.Value ?? "";
			string text2 = text.Trim();
			if (!text2.StartsWith("#"))
			{
				text2 = "#" + text2;
			}
			bool flag = text2.Length == 7 || text2.Length == 9;
			int num = 1;
			while (flag && num < text2.Length)
			{
				flag = Uri.IsHexDigit(text2[num]);
				num++;
			}
			Color result = default(Color);
			if (flag && ColorUtility.TryParseHtmlString(text2, ref result))
			{
				return result;
			}
			string item = ((ConfigEntryBase)entry).Definition.Key + ":" + text;
			if (InvalidColors.Add(item))
			{
				ManualLogSource log = Log;
				if (log != null)
				{
					log.LogWarning((object)("Invalid hologram color for " + ((ConfigEntryBase)entry).Definition.Key + ": '" + text + "'. Using default."));
				}
			}
			return fallback;
		}

		private void RegisterKeyHints()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Expected O, but got Unknown
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Expected O, but got Unknown
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: 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_00f3: Expected O, but got Unknown
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Expected O, but got Unknown
			SnapPrevious = new ButtonConfig
			{
				Name = "SpongeSnapPrevious",
				Key = (KeyCode)113,
				Hint = "Previous snap"
			};
			SnapNext = new ButtonConfig
			{
				Name = "SpongeSnapNext",
				Key = (KeyCode)101,
				Hint = "Next snap"
			};
			InputManager.Instance.AddButton("alkin.Sponge", SnapPrevious);
			InputManager.Instance.AddButton("alkin.Sponge", SnapNext);
			string[] array = new string[2] { "DriedSponge", "WetSponge" };
			foreach (string text in array)
			{
				KeyHintManager instance = KeyHintManager.Instance;
				KeyHintConfig val = new KeyHintConfig();
				val.Item = text;
				val.ButtonConfigs = (ButtonConfig[])(object)new ButtonConfig[4]
				{
					new ButtonConfig
					{
						Name = "Attack",
						Hint = ((text == "DriedSponge") ? "Dry area" : "Refill area")
					},
					SnapPrevious,
					SnapNext,
					new ButtonConfig
					{
						Name = "Scroll",
						Axis = "Mouse ScrollWheel",
						Hint = "Rotate"
					}
				};
				instance.AddKeyHint(val);
			}
		}

		private void LoadAssets()
		{
			string directoryName = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
			string text = Path.Combine(directoryName, "spongeassets");
			((BaseUnityPlugin)this).Logger.LogInfo((object)("AssetBundle path: " + text));
			if (!File.Exists(text))
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"spongeassets was not found next to the plugin DLL.");
				return;
			}
			_assetBundle = AssetBundle.LoadFromFile(text);
			if ((Object)(object)_assetBundle == (Object)null)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"AssetBundle.LoadFromFile(spongeassets) returned null.");
				return;
			}
			_wetSpongeModel = _assetBundle.LoadAsset<GameObject>("WetSpongeModel");
			_driedSpongeModel = _assetBundle.LoadAsset<GameObject>("DriedSpongeModel");
			_wetSpongeIcon = _assetBundle.LoadAsset<Sprite>("WetSpongeIcon");
			_driedSpongeIcon = _assetBundle.LoadAsset<Sprite>("DriedSpongeIcon");
			_wetSpongeIcon = LoadLoosePngIcon("WetSpongeIcon.png") ?? _wetSpongeIcon;
			_driedSpongeIcon = LoadLoosePngIcon("DriedSpongeIcon.png") ?? _driedSpongeIcon;
			((BaseUnityPlugin)this).Logger.LogInfo((object)$"Sponge assets: wetModel={(Object)(object)_wetSpongeModel != (Object)null}, driedModel={(Object)(object)_driedSpongeModel != (Object)null}, wetIcon={(Object)(object)_wetSpongeIcon != (Object)null}, driedIcon={(Object)(object)_driedSpongeIcon != (Object)null}");
		}

		private Sprite LoadLoosePngIcon(string fileName)
		{
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Expected O, but got Unknown
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Expected O, but got Unknown
			//IL_0239: Unknown result type (might be due to invalid IL or missing references)
			//IL_0248: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			string directoryName = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
			string text = Path.Combine(directoryName, "assets");
			string text2 = Path.Combine(text, fileName);
			if (!File.Exists(text2) && Directory.Exists(text))
			{
				string wanted = Path.GetFileNameWithoutExtension(fileName).Replace("_", "").Replace("-", "")
					.Replace(" ", "")
					.ToLowerInvariant();
				text2 = Directory.GetFiles(text, "*.png").FirstOrDefault((string path) => Path.GetFileNameWithoutExtension(path).Replace("_", "").Replace("-", "")
					.Replace(" ", "")
					.ToLowerInvariant() == wanted);
				if (text2 == null)
				{
					bool wet = wanted.Contains("wet");
					bool dry = wanted.Contains("dry");
					text2 = Directory.GetFiles(text, "*.png").FirstOrDefault(delegate(string path)
					{
						string text3 = Path.GetFileNameWithoutExtension(path).ToLowerInvariant();
						return text3.Contains("sponge") && ((wet && text3.Contains("wet")) || (dry && (text3.Contains("dry") || text3.Contains("dried"))));
					});
				}
			}
			if (string.IsNullOrEmpty(text2) || !File.Exists(text2))
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("No matching sponge icon PNG found for " + fileName + " in " + text));
				return null;
			}
			try
			{
				Bitmap val = new Bitmap(text2);
				try
				{
					int width = ((Image)val).Width;
					int height = ((Image)val).Height;
					Texture2D val2 = new Texture2D(width, height, (TextureFormat)4, false);
					Color32[] array = (Color32[])(object)new Color32[width * height];
					for (int num = 0; num < height; num++)
					{
						int num2 = height - 1 - num;
						for (int num3 = 0; num3 < width; num3++)
						{
							Color pixel = val.GetPixel(num3, num);
							array[num2 * width + num3] = new Color32(pixel.R, pixel.G, pixel.B, pixel.A);
						}
					}
					val2.SetPixels32(array);
					val2.Apply(false, false);
					((Object)val2).name = Path.GetFileNameWithoutExtension(fileName);
					((Texture)val2).wrapMode = (TextureWrapMode)1;
					((Texture)val2).filterMode = (FilterMode)1;
					return Sprite.Create(val2, new Rect(0f, 0f, (float)width, (float)height), new Vector2(0.5f, 0.5f), 100f);
				}
				finally
				{
					((IDisposable)val)?.Dispose();
				}
			}
			catch (Exception arg)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)$"Failed to load inventory icon '{text2}': {arg}");
				return null;
			}
		}

		private void OnDestroy()
		{
			PrefabManager.OnVanillaPrefabsAvailable -= OnVanillaPrefabsAvailable;
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			Instance = null;
		}

		private void OnVanillaPrefabsAvailable()
		{
			RegisterItems();
			RegisterDryZonePrefab();
			ConfigureVanillaSpongeHarvesting();
			ConfigureCooking();
			((MonoBehaviour)this).StartCoroutine(LogPostJotunnMaterialDiagnostics());
			PrefabManager.OnVanillaPrefabsAvailable -= OnVanillaPrefabsAvailable;
		}

		private IEnumerator LogPostJotunnMaterialDiagnostics()
		{
			yield return null;
			yield return (object)new WaitForEndOfFrame();
			LogMaterialDiagnostics("POST Jötunn resolution", WetSpongePrefab);
			LogMaterialDiagnostics("POST Jötunn resolution", DriedSpongePrefab);
		}

		private void LogMaterialDiagnostics(string stage, GameObject prefab)
		{
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)prefab == (Object)null)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)(stage + ": prefab is NULL."));
				return;
			}
			Renderer[] componentsInChildren = prefab.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val in componentsInChildren)
			{
				Material[] sharedMaterials = val.sharedMaterials;
				foreach (Material val2 in sharedMaterials)
				{
					if (!((Object)(object)val2 == (Object)null))
					{
						Shader shader = val2.shader;
						string text = (((Object)(object)shader != (Object)null) ? ((Object)shader).name : "<null>");
						string text2 = "<property absent>";
						if (val2.HasProperty("_MainTex"))
						{
							Texture texture = val2.GetTexture("_MainTex");
							text2 = (((Object)(object)texture != (Object)null) ? ((Object)texture).name : "<null>");
						}
						string text3 = "<property absent>";
						if (val2.HasProperty("_Color"))
						{
							text3 = ((object)val2.GetColor("_Color")/*cast due to .constrained prefix*/).ToString();
						}
						string text4 = "<property absent>";
						if (val2.HasProperty("_BumpMap"))
						{
							Texture texture2 = val2.GetTexture("_BumpMap");
							text4 = (((Object)(object)texture2 != (Object)null) ? ((Object)texture2).name : "<null>");
						}
						((BaseUnityPlugin)this).Logger.LogInfo((object)(((Object)prefab).name + " material diagnostic " + stage + ": renderer='" + ((Object)val).name + "', material='" + ((Object)val2).name + "', shader='" + text + "', mainTexture='" + (((Object)(object)val2.mainTexture != (Object)null) ? ((Object)val2.mainTexture).name : "<null>") + "', _MainTex='" + text2 + "', _Color='" + text3 + "', _BumpMap='" + text4 + "'."));
					}
				}
			}
		}

		private void RegisterItems()
		{
			GameObject val = FindFirstPrefab("Hammer");
			if ((Object)(object)val == (Object)null)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"Could not find vanilla Hammer equipment template.");
				return;
			}
			WetSpongePrefab = CloneItem(val, "WetSponge", "$item_wet_sponge", "$item_wet_sponge_desc", _wetSpongeModel, _wetSpongeIcon);
			DriedSpongePrefab = CloneItem(val, "DriedSponge", "$item_dried_sponge", "$item_dried_sponge_desc", _driedSpongeModel, _driedSpongeIcon);
			if ((Object)(object)DriedSpongePrefab.GetComponent<DroppedDriedSpongeBehaviour>() == (Object)null)
			{
				DriedSpongePrefab.AddComponent<DroppedDriedSpongeBehaviour>();
			}
			CustomLocalization localization = LocalizationManager.Instance.GetLocalization();
			string text = "English";
			localization.AddTranslation(ref text, new Dictionary<string, string>
			{
				{ "item_wet_sponge", "Wet Sponge" },
				{ "item_wet_sponge_desc", "A waterlogged sea sponge. Use it on a sponge-dried area to let the water return, or dry it over a fire." },
				{ "item_dried_sponge", "Dried Sponge" },
				{ "item_dried_sponge_desc", "A dried sea sponge. Use it to remove a small cube of water." }
			});
		}

		private GameObject CloneItem(GameObject source, string prefabName, string nameToken, string descToken, GameObject customModel, Sprite customIcon)
		{
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Expected O, but got Unknown
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Expected O, but got Unknown
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Expected O, but got Unknown
			GameObject val = PrefabManager.Instance.CreateClonedPrefab(prefabName, source);
			ItemDrop component = val.GetComponent<ItemDrop>();
			component.m_itemData.m_shared.m_name = nameToken;
			component.m_itemData.m_shared.m_description = descToken;
			component.m_itemData.m_shared.m_maxStackSize = 20;
			component.m_itemData.m_shared.m_maxQuality = 1;
			component.m_itemData.m_quality = 1;
			component.m_itemData.m_shared.m_weight = Mathf.Max(0f, SpongeWeight.Value);
			component.m_itemData.m_shared.m_itemType = (ItemType)19;
			component.m_itemData.m_shared.m_buildPieces = null;
			component.m_itemData.m_shared.m_useDurability = false;
			component.m_itemData.m_shared.m_attack = new Attack();
			component.m_itemData.m_shared.m_secondaryAttack = new Attack();
			if ((Object)(object)customIcon != (Object)null)
			{
				component.m_itemData.m_shared.m_icons = (Sprite[])(object)new Sprite[1] { customIcon };
				((BaseUnityPlugin)this).Logger.LogInfo((object)(prefabName + ": assigned icon '" + ((Object)customIcon).name + "'."));
			}
			else
			{
				component.m_itemData.m_shared.m_icons = Array.Empty<Sprite>();
				((BaseUnityPlugin)this).Logger.LogError((object)(prefabName + ": custom icon is NULL. Check BepInEx/LogOutput.log."));
			}
			ReplaceItemVisual(val, customModel);
			ItemManager.Instance.AddItem(new CustomItem(val, true));
			((BaseUnityPlugin)this).Logger.LogInfo((object)(prefabName + ": registered with Jötunn mock-reference resolution enabled."));
			Renderer[] componentsInChildren = val.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val2 in componentsInChildren)
			{
				Material[] sharedMaterials = val2.sharedMaterials;
				foreach (Material val3 in sharedMaterials)
				{
					if (!((Object)(object)val3 == (Object)null))
					{
						((BaseUnityPlugin)this).Logger.LogInfo((object)(prefabName + " material diagnostic BEFORE Jötunn resolution: renderer='" + ((Object)val2).name + "', material='" + ((Object)val3).name + "', shader='" + (((Object)(object)val3.shader != (Object)null) ? ((Object)val3.shader).name : "<null>") + "', texture='" + (((Object)(object)val3.mainTexture != (Object)null) ? ((Object)val3.mainTexture).name : "<null>") + "'."));
					}
				}
			}
			return val;
		}

		private void ReplaceItemVisual(GameObject itemPrefab, GameObject customModel)
		{
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)customModel == (Object)null)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("No custom model available for " + ((Object)itemPrefab).name + "; cloned visual retained."));
				return;
			}
			Renderer[] componentsInChildren = itemPrefab.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val in componentsInChildren)
			{
				val.enabled = false;
			}
			GameObject val2 = Object.Instantiate<GameObject>(customModel, itemPrefab.transform);
			((Object)val2).name = "SpongeVisual";
			val2.transform.localPosition = Vector3.zero;
			val2.transform.localRotation = Quaternion.identity;
			val2.transform.localScale = Vector3.one * 0.25f;
			Renderer[] componentsInChildren2 = val2.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val3 in componentsInChildren2)
			{
				val3.enabled = true;
			}
			Transform val4 = itemPrefab.transform.Find("attach");
			GameObject val5 = (GameObject)(((Object)(object)val4 != (Object)null) ? ((object)((Component)val4).gameObject) : ((object)new GameObject("attach")));
			if ((Object)(object)val4 == (Object)null)
			{
				val5.transform.SetParent(itemPrefab.transform, false);
			}
			Renderer[] componentsInChildren3 = val5.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val6 in componentsInChildren3)
			{
				val6.enabled = false;
			}
			GameObject val7 = Object.Instantiate<GameObject>(customModel, val5.transform);
			((Object)val7).name = "SpongeHandVisual";
			val7.transform.localPosition = HeldModelOffset.Value;
			val7.transform.localRotation = Quaternion.identity;
			val7.transform.localScale = Vector3.one * Mathf.Max(0.01f, HeldModelScale.Value);
			Renderer[] componentsInChildren4 = val7.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val8 in componentsInChildren4)
			{
				val8.enabled = true;
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)(((Object)itemPrefab).name + ": configured Tool + attach hand visual."));
		}

		private void RegisterDryZonePrefab()
		{
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Expected O, but got Unknown
			GameObject val = FindFirstPrefab("Beech_Stub", "Beech_small1", "Wood");
			if ((Object)(object)val == (Object)null || (Object)(object)val.GetComponent<ZNetView>() == (Object)null)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"Could not find a suitable networked vanilla prefab for SpongeDryZone.");
				return;
			}
			DryZonePrefab = PrefabManager.Instance.CreateClonedPrefab("SpongeDryZone", val);
			for (int num = DryZonePrefab.transform.childCount - 1; num >= 0; num--)
			{
				Object.DestroyImmediate((Object)(object)((Component)DryZonePrefab.transform.GetChild(num)).gameObject);
			}
			Component[] components = DryZonePrefab.GetComponents<Component>();
			foreach (Component val2 in components)
			{
				if (!(val2 is Transform) && !(val2 is ZNetView))
				{
					Object.DestroyImmediate((Object)(object)val2);
				}
			}
			ZNetView component = DryZonePrefab.GetComponent<ZNetView>();
			component.m_persistent = true;
			component.m_distant = false;
			component.m_syncInitialScale = false;
			DryZonePrefab.AddComponent<SpongeDryZone>();
			PrefabManager.Instance.AddPrefab(new CustomPrefab(DryZonePrefab, false));
			((BaseUnityPlugin)this).Logger.LogInfo((object)string.Format("Registered {0}: activeSelf={1}, hasZNetView={2}.", "SpongeDryZone", DryZonePrefab.activeSelf, (Object)(object)DryZonePrefab.GetComponent<ZNetView>() != (Object)null));
		}

		private void ConfigureVanillaSpongeHarvesting()
		{
			//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: 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)
			//IL_02e2: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)WetSpongePrefab == (Object)null)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)"Wet Sponge prefab is unavailable; RtDOcean marine sponges cannot be configured.");
				return;
			}
			int num = 0;
			for (int i = 1; i <= 11; i++)
			{
				string text = "Sponge" + i + "_RtD";
				GameObject prefab = PrefabManager.Instance.GetPrefab(text);
				if ((Object)(object)prefab == (Object)null)
				{
					continue;
				}
				Pickable val = prefab.GetComponent<Pickable>();
				if ((Object)(object)val == (Object)null)
				{
					val = prefab.AddComponent<Pickable>();
				}
				val.m_itemPrefab = WetSpongePrefab;
				Collider[] componentsInChildren = prefab.GetComponentsInChildren<Collider>(true);
				foreach (Collider val2 in componentsInChildren)
				{
					if ((Object)(object)val2 != (Object)null)
					{
						val2.enabled = false;
					}
				}
				Component[] componentsInChildren2 = prefab.GetComponentsInChildren<Component>(true);
				foreach (Component val3 in componentsInChildren2)
				{
					if (!((Object)(object)val3 == (Object)null) && !(val3 is Transform) && !(val3 is ZNetView) && !(val3 is Pickable))
					{
						string name = ((object)val3).GetType().Name;
						if (name.IndexOf("WearNTear", StringComparison.OrdinalIgnoreCase) >= 0 || name.IndexOf("Destruct", StringComparison.OrdinalIgnoreCase) >= 0 || name.IndexOf("MineRock", StringComparison.OrdinalIgnoreCase) >= 0)
						{
							Object.DestroyImmediate((Object)(object)val3);
						}
					}
				}
				BoxCollider val4 = prefab.AddComponent<BoxCollider>();
				((Collider)val4).isTrigger = true;
				val4.center = Vector3.zero;
				val4.size = Vector3.one * 1.5f;
				num++;
				((BaseUnityPlugin)this).Logger.LogInfo((object)("RtDOcean marine sponge '" + text + "' configured as non-solid hand-pickable -> 1x WetSponge."));
			}
			string[] names = new string[6] { "Sponge", "sponge", "OceanSponge", "ocean_sponge", "SeaSponge", "sea_sponge" };
			GameObject val5 = FindFirstPrefab(names);
			if ((Object)(object)val5 != (Object)null)
			{
				VanillaSpongePrefabName = ((Object)val5).name;
				Pickable component = val5.GetComponent<Pickable>();
				if ((Object)(object)component != (Object)null)
				{
					component.m_itemPrefab = WetSpongePrefab;
					num++;
				}
				else
				{
					DropOnDestroyed component2 = val5.GetComponent<DropOnDestroyed>();
					if ((Object)(object)component2 != (Object)null)
					{
						for (int l = 0; l < component2.m_dropWhenDestroyed.m_drops.Count; l++)
						{
							DropData val6 = component2.m_dropWhenDestroyed.m_drops[l];
							if (!((Object)(object)val6.m_item == (Object)null))
							{
								val6.m_item = WetSpongePrefab;
								component2.m_dropWhenDestroyed.m_drops[l] = val6;
							}
						}
						num++;
					}
				}
			}
			if (num == 0)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)"No RtDOcean marine sponge prefab was available when Sponge harvesting was configured.");
			}
			else
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)$"Configured {num} marine sponge prefab(s) to yield Wet Sponge.");
			}
		}

		private void ConfigureCooking()
		{
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Expected O, but got Unknown
			if ((Object)(object)WetSpongePrefab == (Object)null || (Object)(object)DriedSpongePrefab == (Object)null)
			{
				return;
			}
			GameObject val = FindFirstPrefab("piece_cookingstation", "piece_cookingstation_iron");
			CookingStation val2 = (((Object)(object)val != (Object)null) ? val.GetComponent<CookingStation>() : null);
			if ((Object)(object)val2 == (Object)null)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"Vanilla CookingStation was not found.");
				return;
			}
			ItemConversion val3 = FindVanillaMeatConversion(val2);
			if (val3 == null)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"Could not find a vanilla meat conversion to derive drying time from.");
				return;
			}
			float cookTime = val3.m_cookTime * Mathf.Max(0.01f, DryingTimeMultiplier.Value);
			val2.m_conversion.Add(new ItemConversion
			{
				m_from = WetSpongePrefab.GetComponent<ItemDrop>(),
				m_to = DriedSpongePrefab.GetComponent<ItemDrop>(),
				m_cookTime = cookTime
			});
		}

		private static ItemConversion FindVanillaMeatConversion(CookingStation station)
		{
			string[] array = new string[4] { "RawMeat", "DeerMeat", "NeckTail", "WolfMeat" };
			string[] array2 = array;
			foreach (string name in array2)
			{
				ItemConversion val = ((IEnumerable<ItemConversion>)station.m_conversion).FirstOrDefault((Func<ItemConversion, bool>)((ItemConversion x) => (Object)(object)x?.m_from != (Object)null && ((Object)((Component)x.m_from).gameObject).name == name));
				if (val != null)
				{
					return val;
				}
			}
			return ((IEnumerable<ItemConversion>)station.m_conversion).FirstOrDefault((Func<ItemConversion, bool>)((ItemConversion x) => x != null && (Object)(object)x.m_from != (Object)null && (Object)(object)x.m_to != (Object)null));
		}

		internal static GameObject FindFirstPrefab(params string[] names)
		{
			foreach (string text in names)
			{
				GameObject prefab = PrefabManager.Instance.GetPrefab(text);
				if ((Object)(object)prefab != (Object)null)
				{
					return prefab;
				}
			}
			return null;
		}
	}
	internal sealed class SpongeDryZone : MonoBehaviour
	{
		internal static readonly List<SpongeDryZone> Instances = new List<SpongeDryZone>();

		private const string ZdoSizeKey = "sponge_size";

		private const string ZdoYawKey = "sponge_yaw";

		private ZNetView _nview;

		private GameObject _waterMask;

		private GameObject _loweredWater;

		private Mesh _loweredWaterMesh;

		private bool _waterVisualsReady;

		private float _size = 1f;

		private float _nextSync;

		internal float Size => _size;

		internal Bounds Bounds
		{
			get
			{
				//IL_0007: 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)
				//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_0054: Unknown result type (might be due to invalid IL or missing references)
				//IL_0057: Unknown result type (might be due to invalid IL or missing references)
				float num = ((Component)this).transform.eulerAngles.y * ((float)Math.PI / 180f);
				float num2 = _size * (Mathf.Abs(Mathf.Cos(num)) + Mathf.Abs(Mathf.Sin(num)));
				return new Bounds(((Component)this).transform.position, new Vector3(num2, _size, num2));
			}
		}

		internal Vector3 ClosestPoint(Vector3 point)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//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_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: 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_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: 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_0070: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = Quaternion.Inverse(((Component)this).transform.rotation) * (point - ((Component)this).transform.position);
			Bounds val2 = new Bounds(Vector3.zero, Vector3.one * _size);
			Vector3 val3 = ((Bounds)(ref val2)).ClosestPoint(val);
			return ((Component)this).transform.position + ((Component)this).transform.rotation * val3;
		}

		internal bool ContainsFootprint(Vector3 point)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//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_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = Quaternion.Inverse(((Component)this).transform.rotation) * (point - ((Component)this).transform.position);
			float num = _size * 0.5f;
			return Mathf.Abs(val.x) <= num && Mathf.Abs(val.z) <= num;
		}

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

		private void OnEnable()
		{
			if (!Instances.Contains(this))
			{
				Instances.Add(this);
			}
			SpongeWaterVisuals.MarkDirty();
		}

		private void Start()
		{
			SyncFromZdo();
			BuildWaterMask();
			SpongeWaterVisuals.MarkDirty();
		}

		private void Update()
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			if (!(Time.time < _nextSync))
			{
				_nextSync = Time.time + 1f;
				float size = _size;
				Quaternion rotation = ((Component)this).transform.rotation;
				SyncFromZdo();
				if (!Mathf.Approximately(size, _size) || Quaternion.Angle(rotation, ((Component)this).transform.rotation) > 0.01f)
				{
					ApplyMaskScale();
					SpongeWaterVisuals.MarkDirty();
				}
			}
		}

		private void OnDisable()
		{
			Instances.Remove(this);
			SpongeWaterVisuals.MarkDirty();
		}

		private void OnDestroy()
		{
			Instances.Remove(this);
			if ((Object)(object)_loweredWaterMesh != (Object)null)
			{
				Object.Destroy((Object)(object)_loweredWaterMesh);
			}
			SpongeWaterVisuals.MarkDirty();
		}

		internal void Initialize(float size)
		{
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			_size = Mathf.Max(0.01f, size);
			if ((Object)(object)_nview == (Object)null)
			{
				_nview = ((Component)this).GetComponent<ZNetView>();
			}
			if ((Object)(object)_nview != (Object)null && _nview.IsValid())
			{
				_nview.ClaimOwnership();
				_nview.GetZDO().Set("sponge_size", _size);
				_nview.GetZDO().Set("sponge_yaw", ((Component)this).transform.eulerAngles.y);
			}
			ApplyMaskScale();
			SpongeWaterVisuals.MarkDirty();
		}

		private void SyncFromZdo()
		{
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_nview == (Object)null)
			{
				_nview = ((Component)this).GetComponent<ZNetView>();
			}
			if (!((Object)(object)_nview == (Object)null) && _nview.IsValid())
			{
				float num = Mathf.Max(0.01f, Plugin.AbsorptionSize.Value);
				if (_nview.IsOwner())
				{
					_nview.GetZDO().Set("sponge_size", num);
				}
				_size = Mathf.Max(0.01f, _nview.GetZDO().GetFloat("sponge_size", num));
				((Component)this).transform.rotation = Quaternion.Euler(0f, _nview.GetZDO().GetFloat("sponge_yaw", ((Component)this).transform.eulerAngles.y), 0f);
			}
		}

		private void BuildWaterMask()
		{
			_waterVisualsReady = false;
			SpongeWaterVisuals.MarkDirty();
			RefreshWaterVisuals();
		}

		private void ApplyMaskScale()
		{
			_waterVisualsReady = false;
			RefreshWaterVisuals();
		}

		internal void RefreshWaterVisuals()
		{
			_waterVisualsReady = true;
		}

		internal bool Contains(Vector3 point)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			Bounds val = new Bounds(Vector3.zero, Vector3.one * _size);
			return ((Bounds)(ref val)).Contains(Quaternion.Inverse(((Component)this).transform.rotation) * (point - ((Component)this).transform.position));
		}

		internal bool Raycast(Ray ray, float maxDistance, out float distance)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//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_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			distance = 0f;
			Quaternion val = Quaternion.Inverse(((Component)this).transform.rotation);
			Ray val2 = default(Ray);
			((Ray)(ref val2))..ctor(val * (((Ray)(ref ray)).origin - ((Component)this).transform.position), val * ((Ray)(ref ray)).direction);
			Bounds val3 = new Bounds(Vector3.zero, Vector3.one * _size);
			float num = default(float);
			if (!((Bounds)(ref val3)).IntersectRay(val2, ref num) || num > maxDistance)
			{
				return false;
			}
			distance = num;
			return true;
		}

		internal void DestroyNetworked()
		{
			if ((Object)(object)_nview == (Object)null)
			{
				_nview = ((Component)this).GetComponent<ZNetView>();
			}
			if ((Object)(object)_nview != (Object)null && _nview.IsValid())
			{
				_nview.ClaimOwnership();
			}
			if ((Object)(object)ZNetScene.instance != (Object)null)
			{
				ZNetScene.instance.Destroy(((Component)this).gameObject);
			}
			else
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
			}
		}
	}
	internal static class SpongeWaterVisuals
	{
		private sealed class SurfaceState
		{
			internal MeshFilter Filter;

			internal Mesh OriginalMesh;

			internal Mesh RuntimeMesh;

			internal Vector3[] OriginalVertices;
		}

		private static readonly Dictionary<int, SurfaceState> Surfaces = new Dictionary<int, SurfaceState>();

		private static bool _dirty = true;

		private static bool _initialized;

		private static float _nextDiscovery;

		internal static void MarkDirty()
		{
			_dirty = true;
		}

		internal static void Tick()
		{
			if (!_initialized)
			{
				_initialized = true;
				TrackWaterSurfaces();
				_dirty = true;
			}
			if (Time.unscaledTime >= _nextDiscovery)
			{
				_nextDiscovery = Time.unscaledTime + 2f;
				if (TrackWaterSurfaces())
				{
					_dirty = true;
				}
			}
			if (_dirty)
			{
				_dirty = false;
				bool flag = TrackWaterSurfaces();
				ApplyDeformation();
				ManualLogSource log = Plugin.Log;
				if (log != null)
				{
					log.LogDebug((object)$"Sponge water deformation rebuilt (newSurface={flag}, zones={SpongeDryZone.Instances.Count}).");
				}
			}
		}

		private static bool TrackWaterSurfaces()
		{
			bool result = false;
			WaterVolume[] array = Object.FindObjectsOfType<WaterVolume>();
			WaterVolume[] array2 = array;
			foreach (WaterVolume val in array2)
			{
				if ((Object)(object)val == (Object)null || (Object)(object)val.m_waterSurface == (Object)null)
				{
					continue;
				}
				MeshRenderer waterSurface = val.m_waterSurface;
				MeshFilter component = ((Component)waterSurface).GetComponent<MeshFilter>();
				if ((Object)(object)component == (Object)null || (Object)(object)component.sharedMesh == (Object)null)
				{
					continue;
				}
				int instanceID = ((Object)component).GetInstanceID();
				if (Surfaces.ContainsKey(instanceID))
				{
					continue;
				}
				Mesh sharedMesh = component.sharedMesh;
				if (!sharedMesh.isReadable)
				{
					ManualLogSource log = Plugin.Log;
					if (log != null)
					{
						log.LogWarning((object)("Water surface mesh '" + ((Object)sharedMesh).name + "' is not CPU-readable; cannot deform it."));
					}
					continue;
				}
				Mesh val2 = Object.Instantiate<Mesh>(sharedMesh);
				((Object)val2).name = ((Object)sharedMesh).name + "_SpongeRuntime";
				component.sharedMesh = val2;
				Surfaces[instanceID] = new SurfaceState
				{
					Filter = component,
					OriginalMesh = sharedMesh,
					RuntimeMesh = val2,
					OriginalVertices = val2.vertices
				};
				result = true;
				ManualLogSource log2 = Plugin.Log;
				if (log2 != null)
				{
					log2.LogInfo((object)("Tracking actual WaterVolume.m_waterSurface mesh '" + ((Object)sharedMesh).name + "': " + $"sourceVertices={sharedMesh.vertexCount}, runtimeVertices={val2.vertexCount}."));
				}
			}
			return result;
		}

		private static Mesh RefineNearZones(Mesh source, Transform transform)
		{
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Expected O, but got Unknown
			List<Vector3> vertices = new List<Vector3>(source.vertices);
			List<Vector3> normals = new List<Vector3>(source.normals);
			List<Vector4> tangents = new List<Vector4>(source.tangents);
			List<Color> colors = new List<Color>(source.colors);
			bool hasNormals = normals.Count == vertices.Count;
			bool hasTangents = tangents.Count == vertices.Count;
			bool hasColors = colors.Count == vertices.Count;
			List<Vector4>[] uv = new List<Vector4>[8];
			for (int i = 0; i < 8; i++)
			{
				uv[i] = new List<Vector4>();
				source.GetUVs(i, uv[i]);
			}
			int originalCount = vertices.Count;
			Dictionary<ulong, int> midpoints = new Dictionary<ulong, int>();
			SpongeDryZone[] worldZones = SpongeDryZone.Instances.Where((SpongeDryZone z) => (Object)(object)z != (Object)null && ((Behaviour)z).isActiveAndEnabled).ToArray();
			List<int>[] array = new List<int>[source.subMeshCount];
			for (int num = 0; num < array.Length; num++)
			{
				array[num] = new List<int>();
				int[] triangles = source.GetTriangles(num);
				for (int num2 = 0; num2 + 2 < triangles.Length; num2 += 3)
				{
					Refine(triangles[num2], triangles[num2 + 1], triangles[num2 + 2], 0, array[num]);
				}
			}
			Mesh val = new Mesh
			{
				name = ((Object)source).name + "_SpongeRefined"
			};
			if (vertices.Count > 65535)
			{
				val.indexFormat = (IndexFormat)1;
			}
			val.SetVertices(vertices);
			if (hasNormals)
			{
				val.SetNormals(normals);
			}
			if (hasTangents)
			{
				val.SetTangents(tangents);
			}
			if (hasColors)
			{
				val.SetColors(colors);
			}
			for (int num3 = 0; num3 < 8; num3++)
			{
				if (uv[num3].Count == vertices.Count)
				{
					val.SetUVs(num3, uv[num3]);
				}
			}
			val.subMeshCount = array.Length;
			for (int num4 = 0; num4 < array.Length; num4++)
			{
				val.SetTriangles(array[num4], num4, false);
			}
			val.RecalculateBounds();
			return val;
			int Midpoint(int a, int b)
			{
				//IL_0049: Unknown result type (might be due to invalid IL or missing references)
				//IL_0055: Unknown result type (might be due to invalid IL or missing references)
				//IL_005a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0064: Unknown result type (might be due to invalid IL or missing references)
				//IL_0088: Unknown result type (might be due to invalid IL or missing references)
				//IL_0094: Unknown result type (might be due to invalid IL or missing references)
				//IL_0099: Unknown result type (might be due to invalid IL or missing references)
				//IL_009e: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c6: 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_00d7: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
				//IL_0105: Unknown result type (might be due to invalid IL or missing references)
				//IL_0111: Unknown result type (might be due to invalid IL or missing references)
				//IL_0116: Unknown result type (might be due to invalid IL or missing references)
				//IL_0120: Unknown result type (might be due to invalid IL or missing references)
				//IL_0173: Unknown result type (might be due to invalid IL or missing references)
				//IL_0182: Unknown result type (might be due to invalid IL or missing references)
				//IL_0187: Unknown result type (might be due to invalid IL or missing references)
				//IL_0191: Unknown result type (might be due to invalid IL or missing references)
				ulong key = ((ulong)(uint)Math.Min(a, b) << 32) | (uint)Math.Max(a, b);
				if (midpoints.TryGetValue(key, out var value))
				{
					return value;
				}
				int count = vertices.Count;
				vertices.Add((vertices[a] + vertices[b]) * 0.5f);
				if (hasNormals)
				{
					List<Vector3> list = normals;
					Vector3 val2 = normals[a] + normals[b];
					list.Add(((Vector3)(ref val2)).normalized);
				}
				if (hasTangents)
				{
					tangents.Add((tangents[a] + tangents[b]) * 0.5f);
				}
				if (hasColors)
				{
					colors.Add((colors[a] + colors[b]) * 0.5f);
				}
				for (int j = 0; j < 8; j++)
				{
					if (uv[j].Count >= originalCount && uv[j].Count == count)
					{
						uv[j].Add((uv[j][a] + uv[j][b]) * 0.5f);
					}
				}
				midpoints[key] = count;
				return count;
			}
			void Refine(int a, int b, int c, int depth, List<int> output)
			{
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				//IL_0015: Unknown result type (might be due to invalid IL or missing references)
				//IL_001a: Unknown result type (might be due to invalid IL or missing references)
				//IL_002a: Unknown result type (might be due to invalid IL or missing references)
				//IL_002f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0034: Unknown result type (might be due to invalid IL or missing references)
				//IL_0044: Unknown result type (might be due to invalid IL or missing references)
				//IL_0049: Unknown result type (might be due to invalid IL or missing references)
				//IL_004e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0071: Unknown result type (might be due to invalid IL or missing references)
				//IL_0076: Unknown result type (might be due to invalid IL or missing references)
				//IL_0087: Unknown result type (might be due to invalid IL or missing references)
				//IL_008d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0093: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
				//IL_0179: Unknown result type (might be due to invalid IL or missing references)
				//IL_017a: Unknown result type (might be due to invalid IL or missing references)
				//IL_017b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0180: Unknown result type (might be due to invalid IL or missing references)
				//IL_018b: Unknown result type (might be due to invalid IL or missing references)
				//IL_018c: Unknown result type (might be due to invalid IL or missing references)
				//IL_018d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0192: Unknown result type (might be due to invalid IL or missing references)
				//IL_019d: Unknown result type (might be due to invalid IL or missing references)
				//IL_019e: Unknown result type (might be due to invalid IL or missing references)
				//IL_019f: Unknown result type (might be due to invalid IL or missing references)
				//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
				//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c3: 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_00e4: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
				//IL_0102: Unknown result type (might be due to invalid IL or missing references)
				//IL_0111: Unknown result type (might be due to invalid IL or missing references)
				//IL_0117: Unknown result type (might be due to invalid IL or missing references)
				//IL_011d: 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)
				Vector3 val2 = transform.TransformPoint(vertices[a]);
				Vector3 val3 = transform.TransformPoint(vertices[b]);
				Vector3 val4 = transform.TransformPoint(vertices[c]);
				float num5 = float.PositiveInfinity;
				SpongeDryZone[] array2 = worldZones;
				foreach (SpongeDryZone spongeDryZone in array2)
				{
					Bounds bounds = spongeDryZone.Bounds;
					float num6 = spongeDryZone.Size * 0.5f;
					if (!(Mathf.Max(val2.x, Mathf.Max(val3.x, val4.x)) < ((Bounds)(ref bounds)).min.x - num6) && !(Mathf.Min(val2.x, Mathf.Min(val3.x, val4.x)) > ((Bounds)(ref bounds)).max.x + num6) && !(Mathf.Max(val2.z, Mathf.Max(val3.z, val4.z)) < ((Bounds)(ref bounds)).min.z - num6) && !(Mathf.Min(val2.z, Mathf.Min(val3.z, val4.z)) > ((Bounds)(ref bounds)).max.z + num6))
					{
						num5 = Mathf.Min(num5, Mathf.Max(0.05f, spongeDryZone.Size / 3f));
					}
				}
				Vector3 val5 = val2 - val3;
				float sqrMagnitude = ((Vector3)(ref val5)).sqrMagnitude;
				val5 = val3 - val4;
				float sqrMagnitude2 = ((Vector3)(ref val5)).sqrMagnitude;
				val5 = val4 - val2;
				float sqrMagnitude3 = ((Vector3)(ref val5)).sqrMagnitude;
				if (depth >= 14 || vertices.Count >= 50000 || Mathf.Max(sqrMagnitude, Mathf.Max(sqrMagnitude2, sqrMagnitude3)) <= num5 * num5)
				{
					output.Add(a);
					output.Add(b);
					output.Add(c);
				}
				else if (sqrMagnitude >= sqrMagnitude2 && sqrMagnitude >= sqrMagnitude3)
				{
					int num7 = Midpoint(a, b);
					Refine(a, num7, c, depth + 1, output);
					Refine(num7, b, c, depth + 1, output);
				}
				else if (sqrMagnitude2 >= sqrMagnitude3)
				{
					int num8 = Midpoint(b, c);
					Refine(a, b, num8, depth + 1, output);
					Refine(a, num8, c, depth + 1, output);
				}
				else
				{
					int num9 = Midpoint(c, a);
					Refine(a, b, num9, depth + 1, output);
					Refine(num9, b, c, depth + 1, output);
				}
			}
		}

		private static void ApplyDeformation()
		{
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			List<int> list = null;
			foreach (KeyValuePair<int, SurfaceState> surface in Surfaces)
			{
				SurfaceState value = surface.Value;
				if ((Object)(object)value.Filter == (Object)null || (Object)(object)value.RuntimeMesh == (Object)null)
				{
					if (list == null)
					{
						list = new List<int>();
					}
					list.Add(surface.Key);
					continue;
				}
				Mesh val = RefineNearZones(value.OriginalMesh, ((Component)value.Filter).transform);
				Object.Destroy((Object)(object)value.RuntimeMesh);
				value.RuntimeMesh = val;
				value.Filter.sharedMesh = val;
				value.OriginalVertices = val.vertices;
				Vector3[] array = (Vector3[])value.OriginalVertices.Clone();
				Transform transform = ((Component)value.Filter).transform;
				bool flag = false;
				for (int i = 0; i < array.Length; i++)
				{
					Vector3 val2 = transform.TransformPoint(value.OriginalVertices[i]);
					if (TryGetDryBottom(val2, out var bottomY))
					{
						val2.y = Mathf.Min(val2.y, bottomY + 0.02f);
						array[i] = transform.InverseTransformPoint(val2);
						flag = true;
					}
				}
				if (flag)
				{
					value.RuntimeMesh.vertices = array;
					value.RuntimeMesh.RecalculateBounds();
				}
				else
				{
					value.RuntimeMesh.vertices = array;
					value.RuntimeMesh.RecalculateBounds();
				}
			}
			if (list == null)
			{
				return;
			}
			foreach (int item in list)
			{
				Surfaces.Remove(item);
			}
		}

		private static bool TryGetDryBottom(Vector3 worldPoint, out float bottomY)
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			bool flag = false;
			bottomY = 0f;
			for (int num = SpongeDryZone.Instances.Count - 1; num >= 0; num--)
			{
				SpongeDryZone spongeDryZone = SpongeDryZone.Instances[num];
				if (!((Object)(object)spongeDryZone == (Object)null) && ((Behaviour)spongeDryZone).isActiveAndEnabled)
				{
					Bounds bounds = spongeDryZone.Bounds;
					if (spongeDryZone.ContainsFootprint(worldPoint))
					{
						if (!flag)
						{
							bottomY = ((Bounds)(ref bounds)).min.y;
						}
						else
						{
							bottomY = Mathf.Min(bottomY, ((Bounds)(ref bounds)).min.y);
						}
						flag = true;
					}
				}
			}
			return flag;
		}

		internal static MeshRenderer FindNearestWaterSurface(Vector3 point)
		{
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: 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_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: 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_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			WaterVolume[] array = Object.FindObjectsOfType<WaterVolume>();
			MeshRenderer result = null;
			float num = float.PositiveInfinity;
			WaterVolume[] array2 = array;
			foreach (WaterVolume val in array2)
			{
				if (!((Object)(object)val == (Object)null) && !((Object)(object)val.m_waterSurface == (Object)null))
				{
					MeshRenderer waterSurface = val.m_waterSurface;
					Bounds bounds = ((Renderer)waterSurface).bounds;
					float num2 = ((point.x < ((Bounds)(ref bounds)).min.x) ? (((Bounds)(ref bounds)).min.x - point.x) : ((point.x > ((Bounds)(ref bounds)).max.x) ? (point.x - ((Bounds)(ref bounds)).max.x) : 0f));
					float num3 = ((point.z < ((Bounds)(ref bounds)).min.z) ? (((Bounds)(ref bounds)).min.z - point.z) : ((point.z > ((Bounds)(ref bounds)).max.z) ? (point.z - ((Bounds)(ref bounds)).max.z) : 0f));
					float num4 = num2 * num2 + num3 * num3;
					if (num4 < num)
					{
						num = num4;
						result = waterSurface;
					}
				}
			}
			return result;
		}
	}
	internal static class WaterExclusionManager
	{
		[ThreadStatic]
		internal static bool BypassLiquidPatches;

		internal static bool IsExcluded(Vector3 point)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			for (int num = SpongeDryZone.Instances.Count - 1; num >= 0; num--)
			{
				SpongeDryZone spongeDryZone = SpongeDryZone.Instances[num];
				if ((Object)(object)spongeDryZone != (Object)null && ((Behaviour)spongeDryZone).isActiveAndEnabled && spongeDryZone.Contains(point))
				{
					return true;
				}
			}
			return false;
		}

		internal static bool TryGetLoweredWaterSurface(Vector3 point, out float surfaceY)
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			bool flag = false;
			surfaceY = 0f;
			for (int num = SpongeDryZone.Instances.Count - 1; num >= 0; num--)
			{
				SpongeDryZone spongeDryZone = SpongeDryZone.Instances[num];
				if (!((Object)(object)spongeDryZone == (Object)null) && ((Behaviour)spongeDryZone).isActiveAndEnabled)
				{
					Bounds bounds = spongeDryZone.Bounds;
					if (spongeDryZone.ContainsFootprint(point))
					{
						if (!flag)
						{
							surfaceY = ((Bounds)(ref bounds)).min.y;
						}
						else
						{
							surfaceY = Mathf.Min(surfaceY, ((Bounds)(ref bounds)).min.y);
						}
						flag = true;
					}
				}
			}
			return flag;
		}

		internal static bool IntersectsExistingZone(Vector3 center, float size)
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: 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_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: 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_00dc: Unknown result type (might be due to invalid IL or missing references)
			float num = size * 0.5f;
			for (int num2 = SpongeDryZone.Instances.Count - 1; num2 >= 0; num2--)
			{
				SpongeDryZone spongeDryZone = SpongeDryZone.Instances[num2];
				if (!((Object)(object)spongeDryZone == (Object)null) && ((Behaviour)spongeDryZone).isActiveAndEnabled)
				{
					Bounds bounds = spongeDryZone.Bounds;
					float num3 = Mathf.Min(center.x + num, ((Bounds)(ref bounds)).max.x) - Mathf.Max(center.x - num, ((Bounds)(ref bounds)).min.x);
					float num4 = Mathf.Min(center.y + num, ((Bounds)(ref bounds)).max.y) - Mathf.Max(center.y - num, ((Bounds)(ref bounds)).min.y);
					float num5 = Mathf.Min(center.z + num, ((Bounds)(ref bounds)).max.z) - Mathf.Max(center.z - num, ((Bounds)(ref bounds)).min.z);
					if (num3 > 0.01f && num4 > 0.01f && num5 > 0.01f)
					{
						return true;
					}
				}
			}
			return false;
		}

		internal static SpongeDryZone RaycastZone(Ray ray, float maxDistance)
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			SpongeDryZone result = null;
			float maxDistance2 = maxDistance;
			foreach (SpongeDryZone instance in SpongeDryZone.Instances)
			{
				if (!((Object)(object)instance == (Object)null) && ((Behaviour)instance).isActiveAndEnabled && instance.Raycast(ray, maxDistance2, out var distance))
				{
					result = instance;
					maxDistance2 = distance;
				}
			}
			return result;
		}

		internal static float GetVanillaLiquidLevel(Vector3 point)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				BypassLiquidPatches = true;
				return Floating.GetLiquidLevel(point, 1f, (LiquidType)0);
			}
			finally
			{
				BypassLiquidPatches = false;
			}
		}

		internal static bool CubeContainsAvailableWater(Vector3 center, float size, float yaw = 0f)
		{
			//IL_001f: 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_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: 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_0071: 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)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			float num = size * 0.5f;
			for (int i = 0; i < 7; i++)
			{
				for (int j = 0; j < 7; j++)
				{
					for (int k = 0; k < 7; k++)
					{
						Vector3 val = center + Quaternion.Euler(0f, yaw, 0f) * new Vector3(Mathf.Lerp(0f - num, num, (float)i / 6f), Mathf.Lerp(0f - num, num, (float)j / 6f), Mathf.Lerp(0f - num, num, (float)k / 6f));
						if (!IsExcluded(val))
						{
							float vanillaLiquidLevel = GetVanillaLiquidLevel(val);
							if (!float.IsNaN(vanillaLiquidLevel) && !float.IsInfinity(vanillaLiquidLevel) && val.y <= vanillaLiquidLevel + Mathf.Max(0f, Plugin.AboveWaterPlacementHeight.Value) + 0.001f)
							{
								return true;
							}
						}
					}
				}
			}
			return false;
		}
	}
	internal sealed class SpongePlacementController : MonoBehaviour
	{
		private enum Mode
		{
			None,
			Dry,
			Refill
		}

		private enum SnapMode
		{
			Auto,
			Top,
			Bottom,
			Side,
			Free
		}

		private Mode _mode;

		private ItemData _sourceItem;

		private ItemData _uiEquippedItem;

		private Inventory _sourceInventory;

		private GameObject _preview;

		private Material _previewMaterial;

		private Material _placementFillMaterial;

		private Vector3 _target;

		private SpongeDryZone _targetZone;

		private bool _valid;

		private SnapMode _snapMode = SnapMode.Auto;

		private float _placementRotation;

		private readonly Dictionary<SpongeDryZone, GameObject> _refillMarkers = new Dictionary<SpongeDryZone, GameObject>();

		private Material _refillMaterial;

		private Material _outlineMaterial;

		private static readonly FieldInfo BuildRangeField = AccessTools.Field(typeof(Player), "m_maxPlaceDistance");

		private static Color DryValid => Plugin.ReadHex(Plugin.DryPreviewColor, new Color(0.1f, 1f, 0.2f, 1f));

		private static Color RefillValid => Plugin.ReadHex(Plugin.RefillPreviewColor, new Color(0.15f, 0.55f, 1f, 1f));

		private static Color Invalid => Plugin.ReadHex(Plugin.InvalidPreviewColor, new Color(1f, 0.1f, 0.1f, 1f));

		internal bool Active => _mode != Mode.None;

		internal bool SnappingInputActive => Active && Time.timeScale != 0f;

		private bool ShowHologramBorders => (_mode == Mode.Refill) ? Plugin.WetHologramBorders.Value : Plugin.DryHologramBorders.Value;

		private void Awake()
		{
			CreatePreview();
		}

		internal void BeginDry(Inventory inventory, ItemData item)
		{
			Begin(Mode.Dry, inventory, item);
		}

		internal void BeginRefill(Inventory inventory, ItemData item)
		{
			Begin(Mode.Refill, inventory, item);
		}

		internal void SyncEquippedSponge(Player player)
		{
			if ((Object)(object)player == (Object)null)
			{
				return;
			}
			Inventory inventory = ((Humanoid)player).GetInventory();
			if (inventory == null)
			{
				return;
			}
			ItemData val = null;
			foreach (ItemData allItem in inventory.GetAllItems())
			{
				if (allItem != null && !((Object)(object)allItem.m_dropPrefab == (Object)null) && allItem.m_equipped)
				{
					string name = ((Object)allItem.m_dropPrefab).name;
					if (name == "DriedSponge" || name == "WetSponge")
					{
						val = allItem;
						break;
					}
				}
			}
			if (val == null)
			{
				if (Active)
				{
					Cancel();
				}
				return;
			}
			string name2 = ((Object)val.m_dropPrefab).name;
			Mode mode = ((name2 == "DriedSponge") ? Mode.Dry : Mode.Refill);
			if (!Active || _mode != mode || _sourceItem != val)
			{
				Begin(mode, inventory, val);
			}
		}

		private void Begin(Mode mode, Inventory inventory, ItemData item)
		{
			if (_uiEquippedItem != null && _uiEquippedItem != item)
			{
				_uiEquippedItem.m_equipped = false;
			}
			_mode = mode;
			_sourceInventory = inventory;
			_sourceItem = item;
			_uiEquippedItem = item;
			if ((Object)(object)_preview != (Object)null)
			{
				_preview.SetActive(true);
			}
			ManualLogSource log = Plugin.Log;
			if (log != null)
			{
				object arg = _mode;
				object obj;
				if (item == null)
				{
					obj = null;
				}
				else
				{
					GameObject dropPrefab = item.m_dropPrefab;
					obj = ((dropPrefab != null) ? ((Object)dropPrefab).name : null);
				}
				if (obj == null)
				{
					obj = "<null>";
				}
				log.LogInfo((object)($"Sponge placement begin: mode={arg}, item={obj}, " + "inventory=" + ((inventory != null) ? "valid" : "null") + "."));
			}
		}

		private void ShowSnappingMode()
		{
			if (!((Object)(object)MessageHud.instance == (Object)null))
			{
				string text = _snapMode switch
				{
					SnapMode.Auto => "Auto", 
					SnapMode.Top => "Top Center", 
					SnapMode.Bottom => "Bottom Center", 
					SnapMode.Side => "Side Center", 
					_ => "Free", 
				};
				MessageHud.instance.ShowMessage((MessageType)2, "Snapping: " + text, 0, (Sprite)null, false, true);
			}
		}

		private Color WithOpacity(Color color)
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			color.a *= Mathf.Clamp01((_mode == Mode.Refill) ? Plugin.WetHologramOpacity.Value : Plugin.DryHologramOpacity.Value);
			return color;
		}

		private void UpdateRefillMarkers()
		{
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Expected O, but got Unknown
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: 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_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_021f: Unknown result type (might be due to invalid IL or missing references)
			bool flag = Active && (Object)(object)Player.m_localPlayer != (Object)null;
			SpongeDryZone[] array = _refillMarkers.Keys.ToArray();
			foreach (SpongeDryZone spongeDryZone in array)
			{
				if (!flag || (Object)(object)spongeDryZone == (Object)null || !SpongeDryZone.Instances.Contains(spongeDryZone))
				{
					Object.Destroy((Object)(object)_refillMarkers[spongeDryZone]);
					_refillMarkers.Remove(spongeDryZone);
				}
			}
			if (!flag)
			{
				return;
			}
			if ((Object)(object)_refillMaterial == (Object)null)
			{
				Shader val = Shader.Find("Sprites/Default");
				if ((Object)(object)val == (Object)null)
				{
					return;
				}
				_refillMaterial = new Material(val);
				_refillMaterial.renderQueue = 3001;
			}
			_refillMaterial.color = WithOpacity(Plugin.ReadHex((_mode == Mode.Refill) ? Plugin.WetAreaFillColor : Plugin.DryAreaFillColor, new Color(0.2f, 0.5f, 1f, 0.18f)));
			foreach (SpongeDryZone instance in SpongeDryZone.Instances)
			{
				if (!((Object)(object)instance == (Object)null) && ((Behaviour)instance).isActiveAndEnabled)
				{
					if (!_refillMarkers.TryGetValue(instance, out var value))
					{
						value = GameObject.CreatePrimitive((PrimitiveType)3);
						((Object)value).name = "SpongeRefillArea_Blue";
						Object.Destroy((Object)(object)value.GetComponent<Collider>());
						Renderer component = value.GetComponent<Renderer>();
						component.sharedMaterial = _refillMaterial;
						component.shadowCastingMode = (ShadowCastingMode)0;
						component.receiveShadows = false;
						_refillMarkers.Add(instance, value);
					}
					value.transform.position = ((Component)instance).transform.position;
					value.transform.rotation = ((Component)instance).transform.rotation;
					value.transform.localScale = Vector3.one * instance.Size;
				}
			}
		}

		private void OnRenderObject()
		{
			//IL_00f1: 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_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Expected O, but got Unknown
			//IL_0209: 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_021e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0231: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: Unknown result type (might be due to invalid IL or missing references)
			//IL_025c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0261: Unknown result type (might be due to invalid IL or missing references)
			//IL_024b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0250: Unknown result type (might be due to invalid IL or missing references)
			//IL_0266: Unknown result type (might be due to invalid IL or missing references)
			//IL_0276: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: 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_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			if (!Active || (Object)(object)Camera.current == (Object)null || (Object)(object)Camera.current != (Object)(object)Camera.main)
			{
				return;
			}
			if ((Object)(object)_outlineMaterial == (Object)null)
			{
				Shader val = Shader.Find("Hidden/Internal-Colored");
				if ((Object)(object)val == (Object)null)
				{
					return;
				}
				_outlineMaterial = new Material(val)
				{
					hideFlags = (HideFlags)61
				};
				_outlineMaterial.SetInt("_SrcBlend", 5);
				_outlineMaterial.SetInt("_DstBlend", 10);
				_outlineMaterial.SetInt("_Cull", 0);
				_outlineMaterial.SetInt("_ZWrite", 0);
				_outlineMaterial.SetInt("_ZTest", 8);
			}
			if (!_outlineMaterial.SetPass(0))
			{
				return;
			}
			GL.PushMatrix();
			GL.MultMatrix(Matrix4x4.identity);
			GL.Begin(1);
			if (ShowHologramBorders)
			{
				foreach (SpongeDryZone instance in SpongeDryZone.Instances)
				{
					if ((Object)(object)instance != (Object)null && ((Behaviour)instance).isActiveAndEnabled)
					{
						DrawOutline(new Bounds(((Component)instance).transform.position, Vector3.one * instance.Size), WithOpacity(Plugin.ReadHex((_mode == Mode.Refill) ? Plugin.WetAreaOutlineColor : Plugin.DryAreaOutlineColor, new Color(0.25f, 0.65f, 1f, 0.8f))), ((Component)instance).transform.rotation);
					}
				}
			}
			if (ShowHologramBorders && (Object)(object)_preview != (Object)null && _preview.activeSelf)
			{
				DrawOutline(new Bounds(_preview.transform.position, _preview.transform.localScale), WithOpacity((!_valid) ? Plugin.ReadHex(Plugin.InvalidOverlayColor, Color.red) : ((_mode == Mode.Dry) ? Plugin.ReadHex(Plugin.DryOverlayColor, Color.green) : Plugin.ReadHex(Plugin.RefillOverlayColor, Color.cyan))), _preview.transform.rotation);
			}
			GL.End();
			GL.PopMatrix();
		}

		private static void DrawOutline(Bounds bounds, Color color, Quaternion rotation)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			GL.Color(color);
			for (int i = 0; i < 3; i++)
			{
				for (int j = 0; j < 2; j++)
				{
					for (int k = 0; k < 2; k++)
					{
						Vector3 min = ((Bounds)(ref bounds)).min;
						int num = (i + 1) % 3;
						int num2 = (i + 2) % 3;
						Vector3 val;
						float num3;
						if (j != 0)
						{
							val = ((Bounds)(ref bounds)).max;
							num3 = ((Vector3)(ref val))[num];
						}
						else
						{
							val = ((Bounds)(ref bounds)).min;
							num3 = ((Vector3)(ref val))[num];
						}
						((Vector3)(ref min))[num] = num3;
						float num4;
						if (k != 0)
						{
							val = ((Bounds)(ref bounds)).max;
							num4 = ((Vector3)(ref val))[num2];
						}
						else
						{
							val = ((Bounds)(ref bounds)).min;
							num4 = ((Vector3)(ref val))[num2];
						}
						((Vector3)(ref min))[num2] = num4;
						Vector3 val2 = min;
						int num5 = i;
						val = ((Bounds)(ref bounds)).max;
						((Vector3)(ref val2))[num5] = ((Vector3)(ref val))[i];
						GL.Vertex(((Bounds)(ref bounds)).center + rotation * (min - ((Bounds)(ref bounds)).center));
						GL.Vertex(((Bounds)(ref bounds)).center + rotation * (val2 - ((Bounds)(ref bounds)).center));
					}
				}
			}
		}

		private void CreatePreview()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Expected O, but got Unknown
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Expected O, but got Unknown
			_preview = new GameObject("SpongePlacementPreview");
			Object.DontDestroyOnLoad((Object)(object)_preview);
			Shader val = Shader.Find("Sprites/Default");
			if ((Object)(object)val == (Object)null)
			{
				val = Shader.Find("UI/Default");
			}
			if ((Object)(object)val == (Object)null)
			{
				val = Shader.Find("Unlit/Color");
			}
			if ((Object)(object)val == (Object)null)
			{
				ManualLogSource log = Plugin.Log;
				if (log != null)
				{
					log.LogError((object)"Could not find a shader for Sponge placement hologram.");
				}
				_preview.SetActive(false);
				return;
			}
			_previewMaterial = new Material(val)
			{
				name = "SpongePlacementPreviewMaterial",
				renderQueue = 4000
			};
			CreatePreviewEdges(_preview.transform, _previewMaterial);
			_placementFillMaterial = new Material(val)
			{
				name = "SpongePlacementFill",
				renderQueue = 3002
			};
			GameObject val2 = GameObject.CreatePrimitive((PrimitiveType)3);
			((Object)val2).name = "Fill";
			val2.transform.SetParent(_preview.transform, false);
			Object.Destroy((Object)(object)val2.GetComponent<Collider>());
			Renderer component = val2.GetComponent<Renderer>();
			component.sharedMaterial = _placementFillMaterial;
			component.shadowCastingMode = (ShadowCastingMode)0;
			component.receiveShadows = false;
			_preview.SetActive(false);
			ManualLogSource log2 = Plugin.Log;
			if (log2 != null)
			{
				log2.LogInfo((object)("Created Sponge placement hologram: shader=" + ((Object)val).name + ", " + $"supported={val.isSupported}, renderers=12."));
			}
		}

		private static void CreatePreviewEdges(Transform root, Material material)
		{
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < 3; i++)
			{
				for (int j = -1; j <= 1; j += 2)
				{
					for (int k = -1; k <= 1; k += 2)
					{
						GameObject val = GameObject.CreatePrimitive((PrimitiveType)3);
						((Object)val).name = "Edge";
						val.transform.SetParent(root, false);
						Collider component = val.GetComponent<Collider>();
						if ((Object)(object)component != (Object)null)
						{
							Object.Destroy((Object)(object)component);
						}
						Vector3 zero = Vector3.zero;
						Vector3 localScale = Vector3.one * 0.0125f;
						switch (i)
						{
						case 0:
							((Vector3)(ref zero))..ctor(0f, (float)j * 0.5f, (float)k * 0.5f);
							localScale.x = 1f;
							break;
						case 1:
							((Vector3)(ref zero))..ctor((float)j * 0.5f, 0f, (float)k * 0.5f);
							localScale.y = 1f;
							break;
						default:
							((Vector3)(ref zero))..ctor((float)j * 0.5f, (float)k * 0.5f, 0f);
							localScale.z = 1f;
							break;
						}
						val.transform.localPosition = zero;
						val.transform.localRotation = Quaternion.identity;
						val.transform.localScale = localScale;
						MeshRenderer component2 = val.GetComponent<MeshRenderer>();
						((Renderer)component2).sharedMaterial = material;
						((Renderer)component2).shadowCastingMode = (ShadowCastingMode)0;
						((Renderer)component2).receiveShadows = false;
					}
				}
			}
		}

		private void SetPreviewColor(Color color)
		{
			//IL_0031: 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_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_previewMaterial == (Object)null)
			{
				return;
			}
			if (_previewMaterial.HasProperty("_Color"))
			{
				_previewMaterial.color = WithOpacity(color);
			}
			if ((Object)(object)_placementFillMaterial != (Object)null)
			{
				Color val = Plugin.ReadHex((_mode == Mode.Refill) ? Plugin.WetPlacementFillColor : Plugin.DryPlacementFillColor, (_mode == Mode.Refill) ? new Color(0.15f, 0.55f, 1f, 0.18f) : new Color(0.1f, 1f, 0.2f, 0.18f));
				if (!_valid)
				{
					Color invalid = Invalid;
					((Color)(ref val))..ctor(invalid.r, invalid.g, invalid.b, val.a);
				}
				_placementFillMaterial.color = WithOpacity(val);
			}
			if (!((Object)(object)_preview != (Object)null))
			{
				return;
			}
			Renderer[] componentsInChildren = _preview.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val2 in componentsInChildren)
			{
				if (((Object)((Component)val2).gameObject).name == "Edge")
				{
					val2.enabled = ShowHologramBorders;
				}
			}
		}

		private void Update()
		{
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			SpongeWaterVisuals.Tick();
			UpdateRefillMarkers();
			if (_mode == Mode.None)
			{
				return;
			}
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null)
			{
				Cancel();
				return;
			}
			if (_sourceInventory == null)
			{
				_sourceInventory = ((Humanoid)localPlayer).GetInventory();
			}
			if (_sourceInventory == null)
			{
				Cancel();
				return;
			}
			if (_sourceItem == null || !_sourceInventory.ContainsItem(_sourceItem))
			{
				string text = ((_mode == Mode.Dry) ? "DriedSponge" : "WetSponge");
				_sourceItem = null;
				foreach (ItemData allItem in _sourceInventory.GetAllItems())
				{
					if (allItem == null || (Object)(object)allItem.m_dropPrefab == (Object)null || ((Object)allItem.m_dropPrefab).name != text)
					{
						continue;
					}
					_sourceItem = allItem;
					_uiEquippedItem = allItem;
					break;
				}
				if (_sourceItem == null)
				{
					Cancel();
					return;
				}
			}
			if (Time.timeScale == 0f)
			{
				return;
			}
			Camera main = Camera.main;
			if ((Object)(object)main != (Object)null)
			{
				Vector3 forward = ((Component)main).transform.forward;
				forward.y = 0f;
				if (((Vector3)(ref forward)).sqrMagnitude > 0.0001f)
				{
					((Component)localPlayer).transform.rotation = Quaternion.LookRotation(((Vector3)(ref forward)).normalized, Vector3.up);
				}
			}
			float axis = Input.GetAxis("Mouse ScrollWheel");
			if (Mathf.Abs(axis) > 0.001f)
			{
				_placementRotation = Mathf.Repeat(_placementRotation + ((axis > 0f) ? 22.5f : (-22.5f)), 360f);
			}
			if (Input.GetKeyDown((KeyCode)113))
			{
				_snapMode = (SnapMode)((int)(_snapMode + 4) % 5);
				ShowSnappingMode();
			}
			if (Input.GetKeyDown((KeyCode)101))
			{
				_snapMode = (SnapMode)((int)(_snapMode + 1) % 5);
				ShowSnappingMode();
			}
			if ((Object)(object)_preview != (Object)null)
			{
				if (!_preview.activeSelf)
				{
					_preview.SetActive(true);
				}
				Renderer[] componentsInChildren = _preview.GetComponentsInChildren<Renderer>(true);
				foreach (Renderer val in componentsInChildren)
				{
					val.enabled = true;
				}
			}
			UpdateTarget();
			if (Input.GetKeyDown((KeyCode)27))
			{
				Cancel();
			}
			else if (Input.GetMouseButtonDown(0))
			{
				Confirm();
			}
		}

		private void UpdateTarget()
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: 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_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_020f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0216: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0271: Unknown result type (might be due to invalid IL or missing references)
			//IL_0288: Unknown result type (might be due to invalid IL or missing references)
			//IL_0283: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0294: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_02af: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0301: Unknown result type (might be due to invalid IL or missing references)
			//IL_0303: Unknown result type (might be due to invalid IL or missing references)
			//IL_032f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0345: Unknown result type (might be due to invalid IL or missing references)
			//IL_0356: Unknown result type (might be due to invalid IL or missing references)
			//IL_036d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0366: Unknown result type (might be due to invalid IL or missing references)
			Camera main = Camera.main;
			if ((Object)(object)main == (Object)null)
			{
				_valid = false;
				return;
			}
			Ray val = default(Ray);
			((Ray)(ref val))..ctor(((Component)main).transform.position, ((Component)main).transform.forward);
			Player localPlayer = Player.m_localPlayer;
			float buildRange = GetBuildRange(localPlayer);
			float num = buildRange + (((Object)(object)localPlayer != (Object)null) ? Vector3.Distance(((Component)main).transform.position, ((Component)localPlayer).transform.position) : 0f);
			float num2 = Mathf.Max(0.01f, Plugin.AbsorptionSize.Value);
			if (_mode == Mode.Refill)
			{
				_targetZone = WaterExclusionManager.RaycastZone(val, num);
				_valid = (Object)(object)_targetZone != (Object)null;
				_target = (_valid ? ((Component)_targetZone).transform.position : ((Ray)(ref val)).GetPoint(num));
				_preview.transform.localScale = (_valid ? (Vector3.one * _targetZone.Size) : (Vector3.one * num2));
			}
			else
			{
				_targetZone = null;
				_target = FindDryTarget(Player.m_localPlayer, val, num, num2);
				if (Plugin.FollowWaterSurface.Value && !Input.GetKey((KeyCode)308) && _snapMode != SnapMode.Top && _snapMode != SnapMode.Bottom && _snapMode != SnapMode.Free)
				{
					float vanillaLiquidLevel = WaterExclusionManager.GetVanillaLiquidLevel(_target);
					if (vanillaLiquidLevel > -10000f && !float.IsNaN(vanillaLiquidLevel) && !float.IsInfinity(vanillaLiquidLevel))
					{
						_target.y = vanillaLiquidLevel - num2 * 0.5f;
					}
				}
				_target = ApplySnapMode(_target, num2, val, num);
				_valid = WaterExclusionManager.CubeContainsAvailableWater(_target, num2, _placementRotation);
				_preview.transform.localScale = Vector3.one * num2;
			}
			float num3 = ((_mode == Mode.