Decompiled source of BuildWater v0.9.2

BepInEx/plugins/BuildWater.dll

Decompiled 6 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
namespace BuildWater;

internal sealed class ConfigurationManagerAttributes
{
	public bool? ReadOnly;

	public bool? ShowRangeAsPercent;

	public int? Order;

	public bool? IsAdvanced;

	public string Category;

	public string Subcategory;

	public Action<ConfigEntryBase> CustomDrawer;

	public bool? Browsable;

	public bool? HideSettingName;
}
[BepInPlugin("buildwater", "Build Water", "0.9.2")]
public sealed class BuildWaterPlugin : BaseUnityPlugin
{
	[CompilerGenerated]
	private sealed class <EnsurePieceRoutine>d__19 : IEnumerator<object>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private object <>2__current;

		private int <i>5__2;

		object IEnumerator<object>.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		object IEnumerator.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		[DebuggerHidden]
		public <EnsurePieceRoutine>d__19(int <>1__state)
		{
			this.<>1__state = <>1__state;
		}

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Expected O, but got Unknown
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Expected O, but got Unknown
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Expected O, but got Unknown
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Expected O, but got Unknown
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				<i>5__2 = 0;
				break;
			case 1:
				<>1__state = -1;
				if (Enabled.Value && !((Object)ZNetScene.instance == (Object)null) && !((Object)ObjectDB.instance == (Object)null) && !((Object)ZNet.instance == (Object)null))
				{
					Player localPlayer = Player.m_localPlayer;
					BuildWaterPrefab.TryRegisterPieceTable();
					if ((Object)localPlayer != (Object)null)
					{
						BuildWaterPrefab.TryUnlockPieceForPlayer(localPlayer);
					}
					BuildWaterPrefab.EnsurePieceInAllPieceTables();
				}
				<i>5__2++;
				break;
			}
			if (<i>5__2 < 12)
			{
				<>2__current = (object)new WaitForSeconds(1f);
				<>1__state = 1;
				return true;
			}
			return false;
		}

		bool IEnumerator.MoveNext()
		{
			//ILSpy generated this explicit interface implementation from .override directive in MoveNext
			return this.MoveNext();
		}

		[DebuggerHidden]
		void IEnumerator.Reset()
		{
			throw new NotSupportedException();
		}
	}

	internal static ManualLogSource Log;

	internal static ConfigEntry<bool> Enabled;

	internal static ConfigEntry<float> WaterLevelOffset;

	internal static ConfigEntry<float> WaterDepth;

	internal static ConfigEntry<float> SurfacePadding;

	internal static ConfigEntry<float> TerrainInfluenceRadius;

	internal static ConfigEntry<float> TerrainInfluenceMaxDepth;

	internal static ConfigEntry<float> PlayerCheckAboveSurface;

	internal static ConfigEntry<float> CurtainMinDepth;

	private Harmony _harmony;

	public const string PluginGuid = "buildwater";

	public const string PluginName = "Build Water";

	public const string PluginVersion = "0.9.2";

	internal static BuildWaterPlugin Instance { get; private set; }

	private void Awake()
	{
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Expected O, but got Unknown
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Expected O, but got Unknown
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Expected O, but got Unknown
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: Expected O, but got Unknown
		//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bb: Expected O, but got Unknown
		//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f8: Expected O, but got Unknown
		//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fd: Expected O, but got Unknown
		//IL_012b: Unknown result type (might be due to invalid IL or missing references)
		//IL_013a: Expected O, but got Unknown
		//IL_0135: Unknown result type (might be due to invalid IL or missing references)
		//IL_013f: Expected O, but got Unknown
		//IL_016d: Unknown result type (might be due to invalid IL or missing references)
		//IL_017c: Expected O, but got Unknown
		//IL_0177: Unknown result type (might be due to invalid IL or missing references)
		//IL_0181: Expected O, but got Unknown
		//IL_01af: Unknown result type (might be due to invalid IL or missing references)
		//IL_01be: Expected O, but got Unknown
		//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c3: Expected O, but got Unknown
		//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0200: Expected O, but got Unknown
		//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0205: Expected O, but got Unknown
		//IL_0227: Unknown result type (might be due to invalid IL or missing references)
		//IL_0231: Expected O, but got Unknown
		Instance = this;
		Log = ((BaseUnityPlugin)this).Logger;
		Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, new ConfigDescription("Enable BuildWater features.", (AcceptableValueBase)null, Array.Empty<object>()));
		WaterLevelOffset = ((BaseUnityPlugin)this).Config.Bind<float>("Water", "LevelOffset", 0f, new ConfigDescription("Vertical offset applied when placing water-related pieces.", (AcceptableValueBase)new AcceptableValueRange<float>(-5f, 5f), Array.Empty<object>()));
		WaterDepth = ((BaseUnityPlugin)this).Config.Bind<float>("Water", "DepthMeters", 3f, new ConfigDescription("Depth of the placed water volume in meters.", (AcceptableValueBase)new AcceptableValueRange<float>(0.5f, 20f), Array.Empty<object>()));
		SurfacePadding = ((BaseUnityPlugin)this).Config.Bind<float>("Water", "SurfacePaddingMeters", -0.0105042f, new ConfigDescription("Extra padding added to water surface/volume size to eliminate visible gaps between adjacent pieces.", (AcceptableValueBase)new AcceptableValueRange<float>(-2f, 0.5f), Array.Empty<object>()));
		TerrainInfluenceRadius = ((BaseUnityPlugin)this).Config.Bind<float>("Water", "TerrainInfluenceRadiusMeters", 1f, new ConfigDescription("Horizontal radius around water blocks that can turn terrain into water vegetation.", (AcceptableValueBase)new AcceptableValueRange<float>(0f, 3f), Array.Empty<object>()));
		TerrainInfluenceMaxDepth = ((BaseUnityPlugin)this).Config.Bind<float>("Water", "TerrainInfluenceMaxDepthMeters", 3f, new ConfigDescription("Maximum vertical distance below the water surface that can affect terrain.", (AcceptableValueBase)new AcceptableValueRange<float>(0.1f, 20f), Array.Empty<object>()));
		PlayerCheckAboveSurface = ((BaseUnityPlugin)this).Config.Bind<float>("Water", "PlayerCheckAboveSurface", 1f, new ConfigDescription("How far above the water surface (meters) the player is still considered inside the water volume.", (AcceptableValueBase)new AcceptableValueRange<float>(0f, 5f), Array.Empty<object>()));
		CurtainMinDepth = ((BaseUnityPlugin)this).Config.Bind<float>("Water", "CurtainMinDepth", 10f, new ConfigDescription("Minimum depth (meters) for water curtains falling from block edges.", (AcceptableValueBase)new AcceptableValueRange<float>(0.5f, 30f), Array.Empty<object>()));
		((BaseUnityPlugin)this).Config.SettingChanged += OnConfigSettingChanged;
		_harmony = new Harmony("buildwater");
		_harmony.PatchAll(Assembly.GetExecutingAssembly());
		((MonoBehaviour)this).StartCoroutine(EnsurePieceRoutine());
	}

	private void OnDestroy()
	{
		try
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
		catch
		{
		}
		if (((BaseUnityPlugin)this).Config != null)
		{
			((BaseUnityPlugin)this).Config.SettingChanged -= OnConfigSettingChanged;
		}
	}

	[IteratorStateMachine(typeof(<EnsurePieceRoutine>d__19))]
	private IEnumerator EnsurePieceRoutine()
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <EnsurePieceRoutine>d__19(0);
	}

	private void OnConfigSettingChanged(object sender, SettingChangedEventArgs args)
	{
		if (!Enabled.Value)
		{
			BuildWaterPieceBehaviour.SetTerrainToolMode(enabled: false);
		}
		else
		{
			BuildWaterPieceBehaviour.NotifyConfigChanged();
		}
	}
}
internal sealed class BuildWaterDebugReporter : MonoBehaviour
{
	private float _lastStayLogTime;

	public void Initialize()
	{
		_lastStayLogTime = -10f;
	}

	private void OnTriggerEnter(Collider other)
	{
		LogTrigger("enter", other, rateLimit: false);
	}

	private void OnTriggerExit(Collider other)
	{
		LogTrigger("exit", other, rateLimit: false);
	}

	private void OnTriggerStay(Collider other)
	{
		LogTrigger("stay", other, rateLimit: true);
	}

	private void LogTrigger(string label, Collider other, bool rateLimit)
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Expected O, but got Unknown
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Expected O, but got Unknown
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Expected O, but got Unknown
		if (BuildWaterPlugin.Log == null || (Object)other == (Object)null)
		{
			return;
		}
		if (rateLimit)
		{
			if (Time.time - _lastStayLogTime < 2f)
			{
				return;
			}
			_lastStayLogTime = Time.time;
		}
		Player componentInParent = ((Component)other).GetComponentInParent<Player>();
		Character componentInParent2 = ((Component)other).GetComponentInParent<Character>();
		if (!((Object)componentInParent != (Object)null))
		{
			if ((Object)componentInParent2 != (Object)null)
			{
				_ = "Character:" + ((Object)componentInParent2).name;
			}
		}
		else
		{
			_ = "Player:" + componentInParent.GetPlayerName();
		}
	}
}
[HarmonyPatch]
internal static class BuildWaterPatches
{
	[CompilerGenerated]
	private sealed class <ClutterSystem_GenerateVegPatch_Transpiler>d__25 : IEnumerable<CodeInstruction>, IEnumerable, IEnumerator<CodeInstruction>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private CodeInstruction <>2__current;

		private int <>l__initialThreadId;

		private IEnumerable<CodeInstruction> instructions;

		public IEnumerable<CodeInstruction> <>3__instructions;

		private FieldInfo <waterLevelField>5__2;

		private MethodInfo <getWaterLevel>5__3;

		private IEnumerator<CodeInstruction> <>7__wrap3;

		CodeInstruction IEnumerator<CodeInstruction>.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		object IEnumerator.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		[DebuggerHidden]
		public <ClutterSystem_GenerateVegPatch_Transpiler>d__25(int <>1__state)
		{
			this.<>1__state = <>1__state;
			<>l__initialThreadId = Environment.CurrentManagedThreadId;
		}

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			int num = <>1__state;
			if (num == -3 || (uint)(num - 1) <= 1u)
			{
				try
				{
				}
				finally
				{
					<>m__Finally1();
				}
			}
			<waterLevelField>5__2 = null;
			<getWaterLevel>5__3 = null;
			<>7__wrap3 = null;
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Expected O, but got Unknown
			try
			{
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<waterLevelField>5__2 = AccessTools.Field(typeof(ClutterSystem), "m_waterLevel");
					<getWaterLevel>5__3 = AccessTools.Method(typeof(BuildWaterPatches), "GetClutterWaterLevel", (Type[])null, (Type[])null);
					<>7__wrap3 = instructions.GetEnumerator();
					<>1__state = -3;
					break;
				case 1:
					<>1__state = -3;
					break;
				case 2:
					<>1__state = -3;
					break;
				}
				if (<>7__wrap3.MoveNext())
				{
					CodeInstruction current = <>7__wrap3.Current;
					if (current.opcode == OpCodes.Ldfld && object.Equals(current.operand, <waterLevelField>5__2))
					{
						<>2__current = new CodeInstruction(OpCodes.Call, (object)<getWaterLevel>5__3);
						<>1__state = 1;
						return true;
					}
					<>2__current = current;
					<>1__state = 2;
					return true;
				}
				<>m__Finally1();
				<>7__wrap3 = null;
				return false;
			}
			catch
			{
				//try-fault
				((IDisposable)this).Dispose();
				throw;
			}
		}

		bool IEnumerator.MoveNext()
		{
			//ILSpy generated this explicit interface implementation from .override directive in MoveNext
			return this.MoveNext();
		}

		private void <>m__Finally1()
		{
			<>1__state = -1;
			if (<>7__wrap3 != null)
			{
				<>7__wrap3.Dispose();
			}
		}

		[DebuggerHidden]
		void IEnumerator.Reset()
		{
			throw new NotSupportedException();
		}

		[DebuggerHidden]
		IEnumerator<CodeInstruction> IEnumerable<CodeInstruction>.GetEnumerator()
		{
			<ClutterSystem_GenerateVegPatch_Transpiler>d__25 <ClutterSystem_GenerateVegPatch_Transpiler>d__;
			if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId)
			{
				<>1__state = 0;
				<ClutterSystem_GenerateVegPatch_Transpiler>d__ = this;
			}
			else
			{
				<ClutterSystem_GenerateVegPatch_Transpiler>d__ = new <ClutterSystem_GenerateVegPatch_Transpiler>d__25(0);
			}
			<ClutterSystem_GenerateVegPatch_Transpiler>d__.instructions = <>3__instructions;
			return <ClutterSystem_GenerateVegPatch_Transpiler>d__;
		}

		[DebuggerHidden]
		IEnumerator IEnumerable.GetEnumerator()
		{
			return ((IEnumerable<CodeInstruction>)this).GetEnumerator();
		}
	}

	internal const float BuildWaterWaveScale = 1f;

	private const int BuildWaterSupportLimit = 100;

	private static readonly int WaterLayer = ResolveWaterLayer();

	private static readonly FieldRef<Player, int> PlaceGroundRayMaskRef = AccessTools.FieldRefAccess<Player, int>("m_placeGroundRayMask");

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

	private static readonly FieldRef<Heightmap, float[]> OceanDepthRef = AccessTools.FieldRefAccess<Heightmap, float[]>("m_oceanDepth");

	private static readonly FieldRef<Heightmap, Material> HeightmapMaterialRef = AccessTools.FieldRefAccess<Heightmap, Material>("m_materialInstance");

	private static int _savedGroundMask;

	private static bool _groundMaskAdjusted;

	[ThreadStatic]
	private static bool _hasClutterWaterLevel;

	[ThreadStatic]
	private static float _cachedClutterWaterLevel;

	[HarmonyPatch(typeof(ZNetScene), "Awake")]
	[HarmonyPostfix]
	private static void ZNetScene_Awake_Postfix()
	{
		BuildWaterPrefab.TryRegisterPrefab();
	}

	[HarmonyPatch(typeof(WaterVolume), "StaticUpdate")]
	[HarmonyPrefix]
	private static bool WaterVolume_StaticUpdate_Prefix()
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Expected O, but got Unknown
		return !((Object)ZNet.instance == (Object)null);
	}

	[HarmonyPatch(typeof(ObjectDB), "Awake")]
	[HarmonyPostfix]
	private static void ObjectDB_Awake_Postfix()
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Expected O, but got Unknown
		if (!((Object)ZNet.instance == (Object)null))
		{
			BuildWaterPrefab.TryRegisterPieceTable();
		}
	}

	[HarmonyPatch(typeof(ObjectDB), "CopyOtherDB")]
	[HarmonyPostfix]
	private static void ObjectDB_CopyOtherDB_Postfix()
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Expected O, but got Unknown
		if (!((Object)ZNet.instance == (Object)null))
		{
			BuildWaterPrefab.TryRegisterPieceTable();
		}
	}

	[HarmonyPatch(typeof(Player), "Awake")]
	[HarmonyPostfix]
	private static void Player_Awake_Postfix(Player __instance)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Expected O, but got Unknown
		if (!((Object)ZNet.instance == (Object)null))
		{
			BuildWaterPrefab.TryRegisterPieceTable();
			BuildWaterPrefab.TryUnlockPieceForPlayer(__instance);
		}
	}

	[HarmonyPatch(typeof(WaterVolume), "GetWaterSurface", new Type[]
	{
		typeof(Vector3),
		typeof(float)
	})]
	[HarmonyPostfix]
	private static void WaterVolume_GetWaterSurface_Postfix(WaterVolume __instance, Vector3 point, float waveFactor, ref float __result)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Expected O, but got Unknown
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Expected O, but got Unknown
		//IL_004d: 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)
		if (!((Object)__instance == (Object)null) && IsBuildWaterVolume(__instance))
		{
			float num = (((Object)__instance.m_waterSurface != (Object)null) ? ((Component)__instance.m_waterSurface).transform.position.y : (((Component)__instance).transform.position.y + __instance.m_surfaceOffset));
			float num2 = __result - num;
			__result = num + num2 * 1f;
		}
	}

	[HarmonyPatch(typeof(WearNTear), "HaveSupport")]
	[HarmonyPrefix]
	private static bool WearNTear_HaveSupport_Prefix(WearNTear __instance, ref bool __result)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Expected O, but got Unknown
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Expected O, but got Unknown
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Expected O, but got Unknown
		if ((Object)__instance == (Object)null || !BuildWaterPlugin.Enabled.Value)
		{
			return true;
		}
		BuildWaterPieceBehaviour buildWaterPieceBehaviour = ((Component)__instance).GetComponent<BuildWaterPieceBehaviour>();
		if ((Object)buildWaterPieceBehaviour == (Object)null)
		{
			buildWaterPieceBehaviour = ((Component)__instance).GetComponentInParent<BuildWaterPieceBehaviour>();
		}
		if ((Object)buildWaterPieceBehaviour == (Object)null)
		{
			return true;
		}
		if (buildWaterPieceBehaviour.GetSupportClusterCount(101) <= 100)
		{
			__result = true;
			return false;
		}
		return true;
	}

	private static bool IsBuildWaterVolume(WaterVolume volume)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Expected O, but got Unknown
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Expected O, but got Unknown
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Expected O, but got Unknown
		if ((Object)volume == (Object)null)
		{
			return false;
		}
		if ((Object)((Component)volume).gameObject != (Object)null && ((Object)((Component)volume).gameObject).name == "BuildWater_WaterVolume")
		{
			return true;
		}
		return (Object)((Component)volume).GetComponentInParent<BuildWaterPieceBehaviour>() != (Object)null;
	}

	[HarmonyPatch(typeof(Player), "UpdatePlacement")]
	[HarmonyPrefix]
	private static void Player_UpdatePlacement_Prefix(Player __instance)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Expected O, but got Unknown
		if ((Object)__instance == (Object)null || !BuildWaterPlugin.Enabled.Value)
		{
			BuildWaterPieceBehaviour.SetTerrainToolMode(enabled: false);
			return;
		}
		if (WaterLayer < 0)
		{
			BuildWaterPieceBehaviour.SetTerrainToolMode(enabled: false);
			return;
		}
		bool num = IsTerrainTool(__instance);
		BuildWaterPieceBehaviour.SetTerrainToolMode(num);
		if (num)
		{
			int num2 = PlaceGroundRayMaskRef.Invoke(__instance);
			int num3 = 1 << WaterLayer;
			if ((num2 & num3) != 0)
			{
				_savedGroundMask = num2;
				PlaceGroundRayMaskRef.Invoke(__instance) = num2 & ~num3;
				_groundMaskAdjusted = true;
			}
		}
	}

	[HarmonyPatch(typeof(Player), "UpdatePlacement")]
	[HarmonyPostfix]
	private static void Player_UpdatePlacement_Postfix(Player __instance)
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Expected O, but got Unknown
		if (_groundMaskAdjusted)
		{
			_groundMaskAdjusted = false;
			if (!((Object)__instance == (Object)null))
			{
				PlaceGroundRayMaskRef.Invoke(__instance) = _savedGroundMask;
			}
		}
	}

	[HarmonyPatch(typeof(Heightmap), "GetOceanDepth", new Type[] { typeof(Vector3) })]
	[HarmonyPostfix]
	private static void Heightmap_GetOceanDepth_Postfix(Heightmap __instance, Vector3 worldPos, ref float __result)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Expected O, but got Unknown
		//IL_0020: 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_0031: 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)
		float num = 0f;
		if (!((Object)__instance == (Object)null) && BuildWaterPlugin.Enabled.Value && Heightmap.GetHeight(worldPos, ref num) && BuildWaterPieceBehaviour.TryGetWaterSurfaceAtPoint(new Vector3(worldPos.x, num, worldPos.z), out var surfaceY))
		{
			float num2 = surfaceY - num;
			if (num2 > __result)
			{
				__result = num2;
			}
		}
	}

	[HarmonyPatch(typeof(Heightmap), "UpdateCornerDepths")]
	[HarmonyPostfix]
	private static void Heightmap_UpdateCornerDepths_Postfix(Heightmap __instance)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Expected O, but got Unknown
		//IL_004d: 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_005b: 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_0069: 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_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0093: Unknown result type (might be due to invalid IL or missing references)
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: 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_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c1: 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_00cf: 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_00dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0100: Unknown result type (might be due to invalid IL or missing references)
		//IL_010b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0114: Unknown result type (might be due to invalid IL or missing references)
		//IL_011b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0162: Unknown result type (might be due to invalid IL or missing references)
		//IL_016d: Expected O, but got Unknown
		if ((Object)__instance == (Object)null || !BuildWaterPlugin.Enabled.Value)
		{
			return;
		}
		float[] array = OceanDepthRef.Invoke(__instance);
		if (array == null || array.Length < 4)
		{
			return;
		}
		float num = (float)__instance.m_width * __instance.m_scale * 0.5f;
		Vector3 position = ((Component)__instance).transform.position;
		Vector3[] array2 = (Vector3[])(object)new Vector3[4]
		{
			new Vector3(position.x - num, position.y, position.z + num),
			new Vector3(position.x + num, position.y, position.z + num),
			new Vector3(position.x + num, position.y, position.z - num),
			new Vector3(position.x - num, position.y, position.z - num)
		};
		bool flag = false;
		float num2 = 0f;
		for (int i = 0; i < array2.Length; i++)
		{
			Vector3 val = array2[i];
			if (Heightmap.GetHeight(val, ref num2) && BuildWaterPieceBehaviour.TryGetWaterSurfaceAtPoint(new Vector3(val.x, num2, val.z), out var surfaceY))
			{
				float num3 = surfaceY - num2;
				if (!(num3 <= array[i]))
				{
					array[i] = num3;
					flag = true;
				}
			}
		}
		if (flag)
		{
			Material val2 = HeightmapMaterialRef.Invoke(__instance);
			if ((Object)val2 != (Object)null)
			{
				val2.SetFloatArray("_depth", array);
			}
		}
	}

	[HarmonyPatch(typeof(ClutterSystem), "GetGroundInfo")]
	[HarmonyPostfix]
	private static void ClutterSystem_GetGroundInfo_Postfix(ClutterSystem __instance, ref bool __result, ref Vector3 point)
	{
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Expected O, but got Unknown
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		if (!__result)
		{
			_hasClutterWaterLevel = false;
			return;
		}
		float cachedClutterWaterLevel = (((Object)__instance != (Object)null) ? __instance.m_waterLevel : 0f);
		if (BuildWaterPlugin.Enabled.Value && BuildWaterPieceBehaviour.TryGetWaterSurfaceAtPoint(point, out var surfaceY))
		{
			cachedClutterWaterLevel = surfaceY;
		}
		_cachedClutterWaterLevel = cachedClutterWaterLevel;
		_hasClutterWaterLevel = true;
	}

	private static float GetClutterWaterLevel(ClutterSystem instance)
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Expected O, but got Unknown
		if (_hasClutterWaterLevel)
		{
			return _cachedClutterWaterLevel;
		}
		if (!((Object)instance != (Object)null))
		{
			return 0f;
		}
		return instance.m_waterLevel;
	}

	[IteratorStateMachine(typeof(<ClutterSystem_GenerateVegPatch_Transpiler>d__25))]
	[HarmonyPatch(typeof(ClutterSystem), "GenerateVegPatch")]
	[HarmonyTranspiler]
	private static IEnumerable<CodeInstruction> ClutterSystem_GenerateVegPatch_Transpiler(IEnumerable<CodeInstruction> instructions)
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <ClutterSystem_GenerateVegPatch_Transpiler>d__25(-2)
		{
			<>3__instructions = instructions
		};
	}

	private static bool IsTerrainTool(Player player)
	{
		ItemData val = RightItemRef.Invoke(player);
		if (val == null || val.m_shared == null)
		{
			return false;
		}
		string text = val.m_shared.m_name ?? string.Empty;
		if (text == "$item_hoe" || text == "$item_cultivator")
		{
			return true;
		}
		if (!text.Equals("Hoe", StringComparison.OrdinalIgnoreCase))
		{
			return text.Equals("Cultivator", StringComparison.OrdinalIgnoreCase);
		}
		return true;
	}

	private static int ResolveWaterLayer()
	{
		int num = LayerMask.NameToLayer("water");
		if (num >= 0)
		{
			return num;
		}
		return LayerMask.NameToLayer("Water");
	}
}
internal sealed class BuildWaterPieceBehaviour : MonoBehaviour
{
	private struct ConnectionInfo
	{
		public BoxCollider Collider;

		public float SurfaceY;
	}

	private const string WaterRootName = "BuildWater_WaterVolume";

	private const string ConnectionsRootName = "BuildWater_Connections";

	private const string HighlightRootName = "BuildWater_Highlight";

	private const float ConnectionGapMax = 1f;

	private const float ConnectionGapVisualMin = 0.06f;

	private const float ConnectionSurfaceYOffset = 0.01f;

	private const float ConnectionEdgeOverlap = 0.03f;

	private const float ConnectionSquareTolerance = 0.15f;

	private const float ConnectionBridgeMinOverlap = 0.05f;

	private const float ConnectionSearchRadius = 1.2f;

	private const float ConnectionLevelTolerance = 0.25f;

	private const float ConnectionVerticalMax = 1.25f;

	private const float ConnectionMinOverlap = 0.2f;

	private const float ConnectionWallThickness = 0.25f;

	private const float ConnectionRebuildInterval = 0.4f;

	private const float GridCellSize = 4f;

	private const float ConnectionAngleTolerance = 12f;

	private const int ConnectionCascadeSegments = 8;

	private const float ConnectionCascadeDepthMin = 0.08f;

	private const float ConnectionCascadeDepthMax = 0.6f;

	private const bool DebugCascadeMaterial = false;

	private const bool DebugCascadeSolid = false;

	private const bool UseDynamicBridgeSurface = false;

	private const bool DebugBridgeMaterial = false;

	private const bool UseClusterSurface = true;

	private const float ClusterRebuildInterval = 0.5f;

	private const float ClusterAdjacencyTolerance = 0.35f;

	private const float ClusterEdgeOverlap = 0.01f;

	private const float ClusterUvScale = 4f;

	private const float HighlightThickness = 0.06f;

	private const float HighlightThicknessMin = 0.01f;

	private const float HighlightInset = 0.005f;

	private const float HighlightFallbackDistance = 6f;

	private const bool UseSurfaceWaveDeform = false;

	private const bool UseClusterCurtains = true;

	private const int ClusterCurtainSegments = 6;

	private const float ClusterCurtainDepthScale = 0.35f;

	private const float ClusterCurtainDepthMin = 0.05f;

	private const float ClusterCurtainDepthMax = 0.45f;

	private const float ClusterCurtainMinHeight = 0.08f;

	private const float ClusterCurtainMinDepth = 10f;

	private const float ClusterCurtainNeighborOverlap = 0.35f;

	private const float WaterWaveAmplitudeScale = 0.25f;

	private const float WaterWaveSpeedScale = 0.6f;

	private static readonly Dictionary<Vector3Int, HashSet<BuildWaterPieceBehaviour>> _grid = new Dictionary<Vector3Int, HashSet<BuildWaterPieceBehaviour>>();

	private static Material _cachedWaterMaterial;

	private static string _cachedWaterMaterialSource;

	private static readonly Dictionary<int, Material> _cachedScaledWaterMaterials = new Dictionary<int, Material>();

	private static bool _loggedWaterShaderProps;

	private static Material _cachedCascadeDebugMaterial;

	private static Material _cachedBridgeDebugMaterial;

	private static Material _cachedHighlightMaterial;

	private static MethodInfo _playerGetHoverObjectMethod;

	private static bool _playerGetHoverObjectSearched;

	private static MethodInfo _playerInPlaceModeMethod;

	private static bool _playerInPlaceModeSearched;

	private static MethodInfo _playerGetRightItemMethod;

	private static bool _playerGetRightItemSearched;

	private static FieldInfo _playerHoverObjectField;

	private static FieldInfo _playerHoverComponentField;

	private static bool _playerHoverFieldSearched;

	private static bool _loggedLiquidVolumeFields;

	private static bool _loggedWaterVolumeFields;

	private static bool _terrainToolMode;

	private static readonly HashSet<BuildWaterPieceBehaviour> _queryBuffer = new HashSet<BuildWaterPieceBehaviour>();

	private MeshRenderer _surfaceRenderer;

	private WaterVolume _waterVolume;

	private Collider _volumeCollider;

	private float _volumeDepth;

	private float _surfaceWorldY;

	private float _surfaceOffset;

	private float _manualDown;

	private float _manualUp;

	private float _boundsRefreshTimer;

	private bool _boundsDirty;

	private Transform _waterRoot;

	private Bounds _worldBounds;

	private float _playerCheckTimer;

	private bool _manualApplied;

	private bool _playerInsideVolume;

	private float _debugTimer;

	private int _instanceKey;

	private Vector3Int _gridCell;

	private bool _registered;

	private Transform _connectionsRoot;

	private readonly Dictionary<string, GameObject> _connections = new Dictionary<string, GameObject>();

	private readonly List<ConnectionInfo> _connectionInfos = new List<ConnectionInfo>();

	private bool _connectionsDirty;

	private float _connectionsRebuildTimer;

	private bool _clusterDirty;

	private float _clusterRebuildTimer;

	private Mesh _clusterMesh;

	private int _supportClusterCount;

	private float _supportClusterTime;

	private Vector3 _lastPosition;

	private Quaternion _lastRotation;

	private Vector3 _lastScale;

	private float _lastSurfaceY;

	private Bounds _lastBounds;

	private Renderer[] _highlightRenderers;

	private Transform _highlightRoot;

	private bool _highlightVisible;

	private float _highlightTimer;

	private bool _initialized;

	private bool _ghostInitialized;

	private void Awake()
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Expected O, but got Unknown
		_instanceKey = ((Object)this).GetInstanceID();
		ZNetView component = ((Component)this).GetComponent<ZNetView>();
		if (!((Object)component != (Object)null) || component.IsValid())
		{
			TryInitialize();
		}
	}

	private void Start()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Expected O, but got Unknown
		if ((Object)_surfaceRenderer != (Object)null)
		{
			ApplyWaterMaterial(_surfaceRenderer);
		}
	}

	private void Update()
	{
		if (!_initialized)
		{
			TryInitialize();
			if (!_initialized && !_ghostInitialized)
			{
				return;
			}
		}
		if (!BuildWaterPlugin.Enabled.Value)
		{
			return;
		}
		if (_highlightRenderers == null || _highlightRenderers.Length == 0)
		{
			EnsureHighlightOutline();
			if (_highlightRenderers == null || _highlightRenderers.Length == 0)
			{
				return;
			}
		}
		_highlightTimer += Time.deltaTime;
		if (!(_highlightTimer < 0.1f))
		{
			_highlightTimer = 0f;
			UpdateHighlight();
		}
	}

	private void TryInitialize()
	{
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: 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_003a: Expected O, but got Unknown
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Expected O, but got Unknown
		if (_initialized)
		{
			return;
		}
		Scene scene = ((Component)this).gameObject.scene;
		if (!((Scene)(ref scene)).IsValid() || !BuildWaterPlugin.Enabled.Value || (Object)ZNetScene.instance == (Object)null || (Object)ZNet.instance == (Object)null)
		{
			return;
		}
		int num = LayerMask.NameToLayer("ghost");
		if (((Component)this).gameObject.layer == num)
		{
			if (!_ghostInitialized)
			{
				_ghostInitialized = true;
				CacheHighlightRenderers();
				if (_highlightRenderers == null || _highlightRenderers.Length == 0)
				{
					EnsureHighlightOutline();
				}
			}
			return;
		}
		_initialized = true;
		_boundsDirty = true;
		_boundsRefreshTimer = 0f;
		HideRenderers();
		CacheHighlightRenderers();
		EnsureColliderLayer();
		EnsureWaterVolume();
		EnsureConnectionsRoot();
		if (_highlightRenderers == null || _highlightRenderers.Length == 0)
		{
			EnsureHighlightOutline();
		}
		RegisterInGrid();
		MarkConnectionsDirty();
		NotifyGrassChanged();
	}

	private void FixedUpdate()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Expected O, but got Unknown
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Expected O, but got Unknown
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Expected O, but got Unknown
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: 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_0092: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ba: Expected O, but got Unknown
		//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0102: Expected O, but got Unknown
		//IL_00d6: 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_0163: Unknown result type (might be due to invalid IL or missing references)
		//IL_0168: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)_waterVolume == (Object)null || (Object)_volumeCollider == (Object)null || (Object)Player.m_localPlayer == (Object)null)
		{
			return;
		}
		_playerCheckTimer += Time.fixedDeltaTime;
		if (_playerCheckTimer < 0.25f)
		{
			return;
		}
		_playerCheckTimer = 0f;
		Vector3 position = ((Component)Player.m_localPlayer).transform.position;
		bool flag = IsPlayerInsideManual(position);
		float num = (flag ? GetSurfaceHeight(position) : float.MinValue);
		if (!flag && TryGetConnectionSurface(position, out var surfaceY))
		{
			flag = true;
			num = surfaceY;
		}
		if (flag)
		{
			((Character)Player.m_localPlayer).SetLiquidLevel(num, (LiquidType)0, (Component)_waterVolume);
			_manualApplied = true;
			if (!_playerInsideVolume)
			{
				_playerInsideVolume = true;
				LogPlayerState("enter-volume", position, num);
			}
		}
		else
		{
			if (_manualApplied)
			{
				((Character)Player.m_localPlayer).SetLiquidLevel(-10000f, (LiquidType)0, (Component)_waterVolume);
				_manualApplied = false;
			}
			if (_playerInsideVolume)
			{
				_playerInsideVolume = false;
				LogPlayerState("exit-volume", position, -10000f);
			}
		}
		_debugTimer += Time.fixedDeltaTime;
		if (_debugTimer >= 2f)
		{
			_debugTimer = 0f;
			LogPlayerState(flag ? "inside-volume" : "outside-volume", position, flag ? num : GetSurfaceHeight(position));
		}
	}

	private void LateUpdate()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Expected O, but got Unknown
		if (!((Object)_waterRoot == (Object)null))
		{
			if (HasTransformChanged())
			{
				_boundsDirty = true;
			}
			_boundsRefreshTimer += Time.deltaTime;
			if (_boundsDirty && _boundsRefreshTimer >= 0.5f)
			{
				_boundsRefreshTimer = 0f;
				RefreshBounds();
				_boundsDirty = false;
				TrackTransformChanges();
			}
			UpdateConnectionsIfNeeded();
			UpdateClusterSurfaceIfNeeded();
		}
	}

	private void HideRenderers()
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Expected O, but got Unknown
		Renderer[] componentsInChildren = ((Component)this).GetComponentsInChildren<Renderer>(true);
		foreach (Renderer val in componentsInChildren)
		{
			if (!((Object)val == (Object)null) && !IsConnectionsElement(((Component)val).transform) && !IsHighlightElement(((Component)val).transform) && !IsWaterSurface(((Component)val).transform) && !IsGhostOnly(((Component)val).transform))
			{
				val.enabled = false;
			}
		}
	}

	private void CacheHighlightRenderers()
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Expected O, but got Unknown
		Renderer[] componentsInChildren = ((Component)this).GetComponentsInChildren<Renderer>(true);
		foreach (Renderer val in componentsInChildren)
		{
			if (!((Object)val == (Object)null) && !IsConnectionsElement(((Component)val).transform) && !IsWaterSurface(((Component)val).transform) && !IsGhostOnly(((Component)val).transform) && !IsHighlightElement(((Component)val).transform))
			{
				val.enabled = false;
				val.shadowCastingMode = (ShadowCastingMode)0;
				val.receiveShadows = false;
			}
		}
		EnsureHighlightOutline();
	}

	private void UpdateHighlight()
	{
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: Expected O, but got Unknown
		//IL_002a: 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)
		Player localPlayer = Player.m_localPlayer;
		bool flag = false;
		if ((Object)localPlayer != (Object)null && IsPlayerInBuildMode(localPlayer))
		{
			flag = IsPlayerHovering(localPlayer);
			if (!flag && Vector3.Distance(GetHighlightCenter(), ((Component)localPlayer).transform.position) <= 6f)
			{
				flag = true;
			}
		}
		SetHighlightVisible(flag);
	}

	private void SetHighlightVisible(bool visible)
	{
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Expected O, but got Unknown
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Expected O, but got Unknown
		if (_highlightRenderers == null || _highlightVisible == visible)
		{
			return;
		}
		_highlightVisible = visible;
		Material val = (visible ? GetHighlightMaterial() : null);
		for (int i = 0; i < _highlightRenderers.Length; i++)
		{
			Renderer val2 = _highlightRenderers[i];
			if (!((Object)val2 == (Object)null))
			{
				if (visible && (Object)val != (Object)null)
				{
					val2.sharedMaterial = val;
				}
				val2.enabled = visible;
			}
		}
	}

	private void EnsureHighlightOutline()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Expected O, but got Unknown
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: Expected O, but got Unknown
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Expected O, but got Unknown
		//IL_0092: Unknown result type (might be due to invalid IL or missing references)
		//IL_009d: Expected O, but got Unknown
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Expected O, but got Unknown
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c8: Expected O, but got Unknown
		//IL_0167: 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_0185: Unknown result type (might be due to invalid IL or missing references)
		//IL_0188: Unknown result type (might be due to invalid IL or missing references)
		//IL_019c: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b7: 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_015d: 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_0115: Unknown result type (might be due to invalid IL or missing references)
		//IL_0120: Expected O, but got Unknown
		//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0137: 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_0128: Unknown result type (might be due to invalid IL or missing references)
		//IL_012d: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0155: Unknown result type (might be due to invalid IL or missing references)
		//IL_015a: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)_highlightRoot == (Object)null)
		{
			Transform val = ((Component)this).transform.Find("BuildWater_Highlight");
			if ((Object)val != (Object)null)
			{
				_highlightRoot = val;
			}
			else
			{
				GameObject val2 = new GameObject("BuildWater_Highlight");
				val2.transform.SetParent(((Component)this).transform, false);
				_highlightRoot = val2.transform;
			}
		}
		if ((Object)_highlightRoot == (Object)null)
		{
			_highlightRenderers = null;
			return;
		}
		MeshFilter val3 = ((Component)_highlightRoot).GetComponent<MeshFilter>();
		if ((Object)val3 == (Object)null)
		{
			val3 = ((Component)_highlightRoot).gameObject.AddComponent<MeshFilter>();
		}
		MeshRenderer val4 = ((Component)_highlightRoot).GetComponent<MeshRenderer>();
		if ((Object)val4 == (Object)null)
		{
			val4 = ((Component)_highlightRoot).gameObject.AddComponent<MeshRenderer>();
		}
		((Renderer)val4).sharedMaterial = GetHighlightMaterial();
		((Renderer)val4).shadowCastingMode = (ShadowCastingMode)0;
		((Renderer)val4).receiveShadows = false;
		((Renderer)val4).enabled = false;
		if (!TryGetLocalBounds(out var bounds))
		{
			if (!TryGetBounds(out var bounds2))
			{
				if ((Object)_volumeCollider != (Object)null)
				{
					bounds2 = _volumeCollider.bounds;
				}
				else
				{
					Vector3 size = ((Bounds)(ref _worldBounds)).size;
					if (!(((Vector3)(ref size)).sqrMagnitude > 0.0001f))
					{
						_highlightRenderers = null;
						return;
					}
					bounds2 = _worldBounds;
				}
			}
			bounds = ToLocalBounds(bounds2);
		}
		Vector3 val5 = ((Bounds)(ref bounds)).min + new Vector3(0.005f, 0.005f, 0.005f);
		Vector3 val6 = ((Bounds)(ref bounds)).max - new Vector3(0.005f, 0.005f, 0.005f);
		if (val5.x < val6.x && val5.y < val6.y && val5.z < val6.z)
		{
			((Bounds)(ref bounds)).SetMinMax(val5, val6);
		}
		DestroyGeneratedMesh(val3.sharedMesh);
		val3.sharedMesh = CreateHighlightMesh(bounds);
		_highlightRenderers = (Renderer[])(object)new Renderer[1] { (Renderer)val4 };
		_highlightVisible = false;
	}

	private bool TryGetLocalBounds(out Bounds bounds)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: 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_0036: Expected O, but got Unknown
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Expected O, but got Unknown
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_0083: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: 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_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: 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_00aa: Unknown result type (might be due to invalid IL or missing references)
		bounds = default(Bounds);
		bool flag = false;
		MeshFilter[] componentsInChildren = ((Component)this).GetComponentsInChildren<MeshFilter>(true);
		Matrix4x4 worldToLocalMatrix = ((Component)this).transform.worldToLocalMatrix;
		MeshFilter[] array = componentsInChildren;
		foreach (MeshFilter val in array)
		{
			if ((Object)val == (Object)null || (Object)val.sharedMesh == (Object)null)
			{
				continue;
			}
			Transform transform = ((Component)val).transform;
			if (!IsWaterSurface(transform) && !IsGhostOnly(transform) && !IsConnectionsElement(transform) && !IsHighlightElement(transform))
			{
				Matrix4x4 matrix = worldToLocalMatrix * transform.localToWorldMatrix;
				Bounds val2 = TransformBounds(val.sharedMesh.bounds, matrix);
				if (!flag)
				{
					bounds = val2;
					flag = true;
				}
				else
				{
					((Bounds)(ref bounds)).Encapsulate(val2);
				}
			}
		}
		return flag;
	}

	private Bounds ToLocalBounds(Bounds worldBounds)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: 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_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: 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_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//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)
		//IL_005a: 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_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: 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_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_009c: 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_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cc: 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_00d8: 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_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_00f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fc: 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_010e: Unknown result type (might be due to invalid IL or missing references)
		//IL_012c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0156: Unknown result type (might be due to invalid IL or missing references)
		//IL_015b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0160: Unknown result type (might be due to invalid IL or missing references)
		//IL_0162: Unknown result type (might be due to invalid IL or missing references)
		//IL_0163: Unknown result type (might be due to invalid IL or missing references)
		//IL_0165: Unknown result type (might be due to invalid IL or missing references)
		//IL_016a: Unknown result type (might be due to invalid IL or missing references)
		//IL_016b: Unknown result type (might be due to invalid IL or missing references)
		//IL_016d: Unknown result type (might be due to invalid IL or missing references)
		//IL_016f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0174: Unknown result type (might be due to invalid IL or missing references)
		//IL_0185: Unknown result type (might be due to invalid IL or missing references)
		//IL_018d: Unknown result type (might be due to invalid IL or missing references)
		//IL_018e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0195: Unknown result type (might be due to invalid IL or missing references)
		Vector3 min = ((Bounds)(ref worldBounds)).min;
		Vector3 max = ((Bounds)(ref worldBounds)).max;
		Vector3[] array = (Vector3[])(object)new Vector3[8]
		{
			new Vector3(min.x, min.y, min.z),
			new Vector3(max.x, min.y, min.z),
			new Vector3(max.x, min.y, max.z),
			new Vector3(min.x, min.y, max.z),
			new Vector3(min.x, max.y, min.z),
			new Vector3(max.x, max.y, min.z),
			new Vector3(max.x, max.y, max.z),
			new Vector3(min.x, max.y, max.z)
		};
		Vector3 val = default(Vector3);
		((Vector3)(ref val))..ctor(float.PositiveInfinity, float.PositiveInfinity, float.PositiveInfinity);
		Vector3 val2 = default(Vector3);
		((Vector3)(ref val2))..ctor(float.NegativeInfinity, float.NegativeInfinity, float.NegativeInfinity);
		for (int i = 0; i < array.Length; i++)
		{
			Vector3 val3 = ((Component)this).transform.InverseTransformPoint(array[i]);
			val = Vector3.Min(val, val3);
			val2 = Vector3.Max(val2, val3);
		}
		Bounds result = default(Bounds);
		((Bounds)(ref result)).SetMinMax(val, val2);
		return result;
	}

	private static Mesh CreateHighlightMesh(Bounds bounds)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Expected O, but got Unknown
		//IL_001b: 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_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_0029: 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_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00af: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c4: 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_00e1: 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_00ed: 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_0109: Unknown result type (might be due to invalid IL or missing references)
		//IL_010f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0115: Unknown result type (might be due to invalid IL or missing references)
		//IL_011f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0131: Unknown result type (might be due to invalid IL or missing references)
		//IL_0137: Unknown result type (might be due to invalid IL or missing references)
		//IL_013d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0147: Unknown result type (might be due to invalid IL or missing references)
		//IL_0159: 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_0165: Unknown result type (might be due to invalid IL or missing references)
		//IL_016f: Unknown result type (might be due to invalid IL or missing references)
		//IL_017f: 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_018d: 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_01a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01df: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_0202: Unknown result type (might be due to invalid IL or missing references)
		//IL_0208: 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_0223: Unknown result type (might be due to invalid IL or missing references)
		//IL_0229: Unknown result type (might be due to invalid IL or missing references)
		//IL_0231: Unknown result type (might be due to invalid IL or missing references)
		//IL_023c: Unknown result type (might be due to invalid IL or missing references)
		//IL_024c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0252: Unknown result type (might be due to invalid IL or missing references)
		//IL_025a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0265: Unknown result type (might be due to invalid IL or missing references)
		//IL_0275: Unknown result type (might be due to invalid IL or missing references)
		//IL_027b: 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_028e: Unknown result type (might be due to invalid IL or missing references)
		//IL_029e: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ac: 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)
		Mesh val = new Mesh();
		((Object)val).name = "BuildWater_HighlightMesh";
		((Object)val).hideFlags = (HideFlags)61;
		Vector3 min = ((Bounds)(ref bounds)).min;
		Vector3 max = ((Bounds)(ref bounds)).max;
		float num = max.x - min.x;
		float num2 = max.y - min.y;
		float num3 = max.z - min.z;
		float num4 = Mathf.Clamp(0.06f, 0.01f, Mathf.Min(new float[3] { num, num2, num3 }) * 0.4f);
		List<Vector3> vertices = new List<Vector3>();
		List<int> list = new List<int>();
		List<Vector3> normals = new List<Vector3>();
		float num5 = (min.x + max.x) * 0.5f;
		float num6 = (min.y + max.y) * 0.5f;
		float num7 = (min.z + max.z) * 0.5f;
		AppendBox(vertices, list, normals, new Vector3(num5, min.y, min.z), new Vector3(num, num4, num4));
		AppendBox(vertices, list, normals, new Vector3(num5, min.y, max.z), new Vector3(num, num4, num4));
		AppendBox(vertices, list, normals, new Vector3(num5, max.y, min.z), new Vector3(num, num4, num4));
		AppendBox(vertices, list, normals, new Vector3(num5, max.y, max.z), new Vector3(num, num4, num4));
		AppendBox(vertices, list, normals, new Vector3(min.x, num6, min.z), new Vector3(num4, num2, num4));
		AppendBox(vertices, list, normals, new Vector3(min.x, num6, max.z), new Vector3(num4, num2, num4));
		AppendBox(vertices, list, normals, new Vector3(max.x, num6, min.z), new Vector3(num4, num2, num4));
		AppendBox(vertices, list, normals, new Vector3(max.x, num6, max.z), new Vector3(num4, num2, num4));
		AppendBox(vertices, list, normals, new Vector3(min.x, min.y, num7), new Vector3(num4, num4, num3));
		AppendBox(vertices, list, normals, new Vector3(min.x, max.y, num7), new Vector3(num4, num4, num3));
		AppendBox(vertices, list, normals, new Vector3(max.x, min.y, num7), new Vector3(num4, num4, num3));
		AppendBox(vertices, list, normals, new Vector3(max.x, max.y, num7), new Vector3(num4, num4, num3));
		val.SetVertices(vertices);
		val.SetNormals(normals);
		val.SetTriangles(list, 0);
		val.RecalculateBounds();
		return val;
	}

	private static void AppendBox(List<Vector3> vertices, List<int> triangles, List<Vector3> normals, Vector3 center, Vector3 size)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: 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_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_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_003c: 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_003e: 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_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: 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_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_007a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00af: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c3: 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_00d5: 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_00df: 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_00e2: 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_00f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fa: 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_0104: 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_0107: 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_0113: 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_011e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0123: Unknown result type (might be due to invalid IL or missing references)
		//IL_0125: Unknown result type (might be due to invalid IL or missing references)
		//IL_012b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0132: Unknown result type (might be due to invalid IL or missing references)
		//IL_0138: Unknown result type (might be due to invalid IL or missing references)
		//IL_013e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0143: Unknown result type (might be due to invalid IL or missing references)
		//IL_0148: Unknown result type (might be due to invalid IL or missing references)
		//IL_014d: Unknown result type (might be due to invalid IL or missing references)
		//IL_014e: Unknown result type (might be due to invalid IL or missing references)
		//IL_014f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0150: Unknown result type (might be due to invalid IL or missing references)
		//IL_0152: Unknown result type (might be due to invalid IL or missing references)
		//IL_015f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0161: Unknown result type (might be due to invalid IL or missing references)
		//IL_0163: Unknown result type (might be due to invalid IL or missing references)
		//IL_0165: Unknown result type (might be due to invalid IL or missing references)
		//IL_0167: Unknown result type (might be due to invalid IL or missing references)
		//IL_0174: Unknown result type (might be due to invalid IL or missing references)
		//IL_0176: Unknown result type (might be due to invalid IL or missing references)
		//IL_0177: 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_017b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0188: Unknown result type (might be due to invalid IL or missing references)
		//IL_0189: Unknown result type (might be due to invalid IL or missing references)
		//IL_018a: 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_018e: Unknown result type (might be due to invalid IL or missing references)
		//IL_019b: Unknown result type (might be due to invalid IL or missing references)
		//IL_019c: 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_01a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01af: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = size * 0.5f;
		Vector3 val2 = center + new Vector3(0f - val.x, 0f - val.y, 0f - val.z);
		Vector3 val3 = center + new Vector3(val.x, 0f - val.y, 0f - val.z);
		Vector3 val4 = center + new Vector3(val.x, 0f - val.y, val.z);
		Vector3 val5 = center + new Vector3(0f - val.x, 0f - val.y, val.z);
		Vector3 val6 = center + new Vector3(0f - val.x, val.y, 0f - val.z);
		Vector3 val7 = center + new Vector3(val.x, val.y, 0f - val.z);
		Vector3 val8 = center + new Vector3(val.x, val.y, val.z);
		Vector3 val9 = center + new Vector3(0f - val.x, val.y, val.z);
		AddQuad(vertices, triangles, normals, val2, val3, val4, val5, Vector3.down);
		AddQuad(vertices, triangles, normals, val6, val7, val8, val9, Vector3.up);
		AddQuad(vertices, triangles, normals, val5, val4, val8, val9, Vector3.forward);
		AddQuad(vertices, triangles, normals, val3, val2, val6, val7, Vector3.back);
		AddQuad(vertices, triangles, normals, val2, val5, val9, val6, Vector3.left);
		AddQuad(vertices, triangles, normals, val4, val3, val7, val8, Vector3.right);
	}

	private static void AddQuad(List<Vector3> vertices, List<int> triangles, List<Vector3> normals, Vector3 a, Vector3 b, Vector3 c, Vector3 d, Vector3 normal)
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: 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_002f: 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_003f: Unknown result type (might be due to invalid IL or missing references)
		int count = vertices.Count;
		vertices.Add(a);
		vertices.Add(b);
		vertices.Add(c);
		vertices.Add(d);
		normals.Add(normal);
		normals.Add(normal);
		normals.Add(normal);
		normals.Add(normal);
		triangles.Add(count);
		triangles.Add(count + 1);
		triangles.Add(count + 2);
		triangles.Add(count);
		triangles.Add(count + 2);
		triangles.Add(count + 3);
	}

	private static bool IsPlayerInBuildMode(Player player)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Expected O, but got Unknown
		//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Expected O, but got Unknown
		//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d9: Expected O, but got Unknown
		if ((Object)player == (Object)null)
		{
			return false;
		}
		if (!_playerInPlaceModeSearched)
		{
			_playerInPlaceModeMethod = AccessTools.Method(typeof(Player), "InPlaceMode", (Type[])null, (Type[])null);
			_playerInPlaceModeSearched = true;
		}
		if (_playerInPlaceModeMethod != null)
		{
			try
			{
				if ((bool)_playerInPlaceModeMethod.Invoke(player, null))
				{
					return true;
				}
			}
			catch
			{
			}
		}
		if (!_playerGetRightItemSearched)
		{
			_playerGetRightItemMethod = AccessTools.Method(typeof(Player), "GetRightItem", (Type[])null, (Type[])null);
			_playerGetRightItemSearched = true;
		}
		if (_playerGetRightItemMethod != null)
		{
			try
			{
				object obj2 = _playerGetRightItemMethod.Invoke(player, null);
				ItemData val = (ItemData)((obj2 is ItemData) ? obj2 : null);
				if (val != null && val.m_shared != null && (Object)val.m_shared.m_buildPieces != (Object)null)
				{
					return true;
				}
			}
			catch
			{
			}
		}
		return false;
	}

	private bool IsPlayerHovering(Player player)
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Expected O, but got Unknown
		//IL_0018: 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_002d: Expected O, but got Unknown
		//IL_002d: Expected O, but got Unknown
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Expected O, but got Unknown
		//IL_005a: Expected O, but got Unknown
		GameObject playerHoverObject = GetPlayerHoverObject(player);
		if ((Object)playerHoverObject == (Object)null)
		{
			return false;
		}
		if ((Object)playerHoverObject == (Object)((Component)this).gameObject || playerHoverObject.transform.IsChildOf(((Component)this).transform))
		{
			return true;
		}
		return (Object)playerHoverObject.GetComponentInParent<BuildWaterPieceBehaviour>() == (Object)this;
	}

	private static GameObject GetPlayerHoverObject(Player player)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Expected O, but got Unknown
		//IL_015d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0168: Expected O, but got Unknown
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Expected O, but got Unknown
		//IL_0125: Unknown result type (might be due to invalid IL or missing references)
		//IL_0130: Expected O, but got Unknown
		if ((Object)player == (Object)null)
		{
			return null;
		}
		if (!_playerGetHoverObjectSearched)
		{
			_playerGetHoverObjectMethod = AccessTools.Method(typeof(Player), "GetHoverObject", (Type[])null, (Type[])null);
			_playerGetHoverObjectSearched = true;
		}
		if (_playerGetHoverObjectMethod != null)
		{
			try
			{
				GameObject val = ResolveHoverObject(_playerGetHoverObjectMethod.Invoke(player, null));
				if ((Object)val != (Object)null)
				{
					return val;
				}
			}
			catch
			{
			}
		}
		if (!_playerHoverFieldSearched)
		{
			FieldInfo[] fields = typeof(Player).GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			foreach (FieldInfo fieldInfo in fields)
			{
				if ((fieldInfo.Name ?? string.Empty).IndexOf("hover", StringComparison.OrdinalIgnoreCase) >= 0)
				{
					if (fieldInfo.FieldType == typeof(GameObject))
					{
						_playerHoverObjectField = fieldInfo;
						break;
					}
					if (typeof(Component).IsAssignableFrom(fieldInfo.FieldType))
					{
						_playerHoverComponentField = fieldInfo;
					}
				}
			}
			_playerHoverFieldSearched = true;
		}
		if (_playerHoverObjectField != null)
		{
			try
			{
				GameObject val2 = ResolveHoverObject(_playerHoverObjectField.GetValue(player));
				if ((Object)val2 != (Object)null)
				{
					return val2;
				}
			}
			catch
			{
			}
		}
		if (_playerHoverComponentField != null)
		{
			try
			{
				GameObject val3 = ResolveHoverObject(_playerHoverComponentField.GetValue(player));
				if ((Object)val3 != (Object)null)
				{
					return val3;
				}
			}
			catch
			{
			}
		}
		return null;
	}

	private static GameObject ResolveHoverObject(object value)
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Expected O, but got Unknown
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Expected O, but got Unknown
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0093: Expected O, but got Unknown
		if (value == null)
		{
			return null;
		}
		GameObject val = (GameObject)((value is GameObject) ? value : null);
		if ((Object)(object)val != (Object)null)
		{
			return val;
		}
		Component val2 = (Component)((value is Component) ? value : null);
		if ((Object)(object)val2 != (Object)null)
		{
			return val2.gameObject;
		}
		PropertyInfo property = value.GetType().GetProperty("gameObject", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
		if (property != null && typeof(GameObject).IsAssignableFrom(property.PropertyType))
		{
			try
			{
				object value2 = property.GetValue(value, null);
				return (GameObject)((value2 is GameObject) ? value2 : null);
			}
			catch
			{
			}
		}
		return null;
	}

	private Vector3 GetHighlightCenter()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Expected O, but got Unknown
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: 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_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)_volumeCollider != (Object)null)
		{
			Bounds bounds = _volumeCollider.bounds;
			return ((Bounds)(ref bounds)).center;
		}
		Vector3 size = ((Bounds)(ref _worldBounds)).size;
		if (((Vector3)(ref size)).sqrMagnitude > 0.0001f)
		{
			return ((Bounds)(ref _worldBounds)).center;
		}
		return ((Component)this).transform.position;
	}

	private static Material GetHighlightMaterial()
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Expected O, but got Unknown
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Expected O, but got Unknown
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Expected O, but got Unknown
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Expected O, but got Unknown
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_007a: Expected O, but got Unknown
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Expected O, but got Unknown
		//IL_0092: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_016a: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)_cachedHighlightMaterial != (Object)null)
		{
			return _cachedHighlightMaterial;
		}
		Shader val = Shader.Find("Hidden/Internal-Colored");
		if ((Object)val == (Object)null)
		{
			val = Shader.Find("Unlit/Color");
		}
		if ((Object)val == (Object)null)
		{
			val = Shader.Find("UI/Default");
		}
		if ((Object)val == (Object)null)
		{
			val = Shader.Find("Standard");
		}
		if ((Object)val == (Object)null)
		{
			return null;
		}
		Material val2 = new Material(val);
		((Object)val2).name = "BuildWater_Highlight";
		Color color = default(Color);
		((Color)(ref color))..ctor(0.2f, 0.9f, 1f, 0.8f);
		val2.color = color;
		val2.renderQueue = 4000;
		val2.SetInt("_Cull", 0);
		val2.SetInt("_ZWrite", 0);
		val2.SetInt("_ZTest", 8);
		val2.SetInt("_SrcBlend", 5);
		val2.SetInt("_DstBlend", 10);
		if (((Object)val).name == "Standard")
		{
			val2.DisableKeyword("_ALPHATEST_ON");
			val2.EnableKeyword("_ALPHABLEND_ON");
			val2.DisableKeyword("_ALPHAPREMULTIPLY_ON");
			val2.SetFloat("_Mode", 3f);
			val2.EnableKeyword("_EMISSION");
			val2.SetColor("_EmissionColor", new Color(0.4f, 0.9f, 1f, 1.2f));
			val2.renderQueue = 4000;
		}
		else
		{
			try
			{
				val2.EnableKeyword("_EMISSION");
				val2.SetColor("_EmissionColor", new Color(0.2f, 0.8f, 1f, 0.9f));
			}
			catch
			{
			}
		}
		_cachedHighlightMaterial = val2;
		return _cachedHighlightMaterial;
	}

	private bool IsWaterSurface(Transform t)
	{
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Expected O, but got Unknown
		Transform val = t;
		while ((Object)val != (Object)null)
		{
			if (((Object)val).name == "BuildWater_WaterVolume" || ((Object)val).name == "WaterSurface")
			{
				return true;
			}
			val = val.parent;
		}
		return false;
	}

	private bool IsGhostOnly(Transform t)
	{
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Expected O, but got Unknown
		Transform val = t;
		while ((Object)val != (Object)null)
		{
			if (((Object)val).name == "_GhostOnly")
			{
				return true;
			}
			val = val.parent;
		}
		return false;
	}

	private bool IsConnectionsElement(Transform t)
	{
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Expected O, but got Unknown
		Transform val = t;
		while ((Object)val != (Object)null)
		{
			if (((Object)val).name == "BuildWater_Connections")
			{
				return true;
			}
			val = val.parent;
		}
		return false;
	}

	private bool IsHighlightElement(Transform t)
	{
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Expected O, but got Unknown
		Transform val = t;
		while ((Object)val != (Object)null)
		{
			if (((Object)val).name == "BuildWater_Highlight")
			{
				return true;
			}
			val = val.parent;
		}
		return false;
	}

	private static bool IsGeneratedMesh(Mesh mesh)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Expected O, but got Unknown
		if ((Object)mesh == (Object)null)
		{
			return false;
		}
		return (((Object)mesh).name ?? string.Empty).StartsWith("BuildWater_", StringComparison.OrdinalIgnoreCase);
	}

	private static void DestroyGeneratedMesh(Mesh mesh)
	{
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Expected O, but got Unknown
		if (!IsGeneratedMesh(mesh))
		{
			return;
		}
		try
		{
			Object.Destroy((Object)mesh);
		}
		catch
		{
		}
	}

	private static void DestroyGeneratedMeshes(Transform root)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Expected O, but got Unknown
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Expected O, but got Unknown
		if ((Object)root == (Object)null)
		{
			return;
		}
		MeshFilter[] componentsInChildren = ((Component)root).GetComponentsInChildren<MeshFilter>(true);
		foreach (MeshFilter val in componentsInChildren)
		{
			if (!((Object)val == (Object)null))
			{
				DestroyGeneratedMesh(val.sharedMesh);
				val.sharedMesh = null;
			}
		}
	}

	private void EnsureColliderLayer()
	{
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Expected O, but got Unknown
		int layer = LayerMask.NameToLayer("piece_nonsolid");
		if (_terrainToolMode)
		{
			int num = ResolveWaterLayer();
			if (num >= 0)
			{
				layer = num;
			}
		}
		Collider[] componentsInChildren = ((Component)this).GetComponentsInChildren<Collider>(true);
		foreach (Collider val in componentsInChildren)
		{
			if (!((Object)val == (Object)null) && !IsWaterSurface(((Component)val).transform))
			{
				((Component)val).gameObject.layer = layer;
			}
		}
	}

	private void EnsureWaterVolume()
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Expected O, but got Unknown
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Expected O, but got Unknown
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Expected O, but got Unknown
		//IL_018e: Unknown result type (might be due to invalid IL or missing references)
		//IL_018f: 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_0195: Unknown result type (might be due to invalid IL or missing references)
		//IL_019c: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a1: 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_01b5: Expected O, but got Unknown
		//IL_016f: 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_00d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e3: Expected O, but got Unknown
		//IL_01e5: 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_0210: Unknown result type (might be due to invalid IL or missing references)
		//IL_0217: Unknown result type (might be due to invalid IL or missing references)
		//IL_0229: Unknown result type (might be due to invalid IL or missing references)
		//IL_0230: Expected O, but got Unknown
		//IL_024a: Unknown result type (might be due to invalid IL or missing references)
		//IL_025b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0273: Unknown result type (might be due to invalid IL or missing references)
		//IL_0274: Unknown result type (might be due to invalid IL or missing references)
		//IL_0279: Unknown result type (might be due to invalid IL or missing references)
		//IL_027d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0285: Unknown result type (might be due to invalid IL or missing references)
		//IL_0292: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b5: 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_02cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d6: Expected O, but got Unknown
		//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0108: Expected O, but got Unknown
		//IL_0336: Unknown result type (might be due to invalid IL or missing references)
		//IL_0344: Unknown result type (might be due to invalid IL or missing references)
		//IL_034e: Unknown result type (might be due to invalid IL or missing references)
		//IL_035a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0377: Unknown result type (might be due to invalid IL or missing references)
		//IL_037e: Unknown result type (might be due to invalid IL or missing references)
		//IL_039a: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_03fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_0404: Expected O, but got Unknown
		//IL_0437: Unknown result type (might be due to invalid IL or missing references)
		//IL_0441: Expected O, but got Unknown
		//IL_047c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0488: Expected O, but got Unknown
		//IL_048e: Unknown result type (might be due to invalid IL or missing references)
		//IL_049a: Expected O, but got Unknown
		//IL_04b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_04bb: Expected O, but got Unknown
		//IL_04bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_04c8: Expected O, but got Unknown
		//IL_04ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_04cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_04d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_04d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_04ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0500: Unknown result type (might be due to invalid IL or missing references)
		//IL_0506: Unknown result type (might be due to invalid IL or missing references)
		//IL_0519: Expected O, but got Unknown
		Transform val = ((Component)this).transform.Find("BuildWater_WaterVolume");
		if ((Object)val != (Object)null)
		{
			_waterRoot = val;
			_volumeCollider = (Collider)((Component)val).GetComponent<BoxCollider>();
			_waterVolume = ((Component)val).GetComponent<WaterVolume>();
			Transform val2 = val.Find("WaterSurface");
			if ((Object)val2 != (Object)null)
			{
				_surfaceRenderer = ((Component)val2).GetComponent<MeshRenderer>();
			}
			_surfaceOffset = BuildWaterPlugin.WaterLevelOffset.Value;
			_volumeDepth = BuildWaterPlugin.WaterDepth.Value;
			_manualDown = Mathf.Max(_volumeDepth, 3f);
			_manualUp = GetPlayerCheckAboveSurface();
			WaterVolume referenceVolume = FindReferenceWaterVolume(_waterVolume);
			ApplyWaterLayerAndTag(val, referenceVolume);
			ApplyWaveDamping(_waterVolume);
			if ((Object)_surfaceRenderer != (Object)null)
			{
				ApplyWaterMaterial(_surfaceRenderer, _waterVolume);
			}
			if ((Object)_volumeCollider != (Object)null)
			{
				_volumeCollider.isTrigger = true;
			}
			TryAddWaterTrigger(((Component)val).gameObject, _waterVolume, _volumeCollider, _surfaceRenderer);
			TryAddLiquidComponents(((Component)val).gameObject, _surfaceRenderer, _volumeCollider, _waterVolume);
			RefreshBounds();
			EnsureSurfaceSizingFromBounds();
			return;
		}
		if (!TryGetBounds(out var bounds))
		{
			((Bounds)(ref bounds))..ctor(((Component)this).transform.position, new Vector3(2f, 0.2f, 2f));
		}
		bounds = NormalizeBounds(bounds);
		Bounds val3 = ExpandBoundsXZ(bounds, GetSurfacePadding());
		WaterVolume val4 = FindReferenceWaterVolume(null);
		if ((Object)val4 == (Object)null)
		{
			return;
		}
		float value = BuildWaterPlugin.WaterDepth.Value;
		float surfaceOffset = (_surfaceOffset = BuildWaterPlugin.WaterLevelOffset.Value);
		_manualDown = Mathf.Max(value, 3f + ((Bounds)(ref bounds)).size.y);
		_manualUp = GetPlayerCheckAboveSurface();
		_volumeDepth = value;
		_worldBounds = val3;
		_surfaceWorldY = ComputeSurfaceWorldY(bounds, surfaceOffset);
		GameObject val5 = new GameObject("BuildWater_WaterVolume");
		val5.transform.SetParent(((Component)this).transform, false);
		val5.transform.localPosition = Vector3.zero;
		val5.transform.localRotation = Quaternion.identity;
		_waterRoot = val5.transform;
		Vector3 val6 = ResolveCenterXZ(val3);
		Vector3 val7 = default(Vector3);
		((Vector3)(ref val7))..ctor(val6.x, _surfaceWorldY, val6.z);
		Vector3 val8 = val5.transform.InverseTransformPoint(val6);
		float y = val5.transform.InverseTransformPoint(val7).y;
		int num = ResolveWaterLayer();
		if ((Object)val4 != (Object)null)
		{
			num = ((Component)val4).gameObject.layer;
			if (!string.IsNullOrEmpty(((Component)val4).gameObject.tag))
			{
				val5.tag = ((Component)val4).gameObject.tag;
			}
		}
		val5.layer = num;
		BoxCollider val9 = val5.AddComponent<BoxCollider>();
		((Collider)val9).isTrigger = true;
		float num2 = _manualDown + _manualUp;
		val9.size = new Vector3(((Bounds)(ref val3)).size.x, num2, ((Bounds)(ref val3)).size.z);
		val9.center = new Vector3(val8.x, y + (_manualUp - _manualDown) * 0.5f, val8.z);
		((Component)val9).gameObject.layer = num;
		MeshRenderer val10 = (_surfaceRenderer = CreateSurfaceFromReference(((Bounds)(ref val3)).size.x, ((Bounds)(ref val3)).size.z, val8, y, val5.transform, num, val5.tag));
		WaterVolume val11 = val5.AddComponent<WaterVolume>();
		CopyWaterVolumeDefaults(val11, val4);
		ApplyWaveDamping(val11);
		val11.m_waterSurface = val10;
		TrySetWaterVolumeCollider(val11, (Collider)val9);
		val11.m_heightmap = null;
		val11.m_forceDepth = Mathf.Clamp01(value / 10f);
		val11.m_surfaceOffset = y;
		val11.m_useGlobalWind = true;
		ApplyWaterVolumeSurfaceRefs(val11, val10, (Collider)val9);
		SetBoolFieldIfExists(val11, "m_isWater", value: true);
		SetBoolFieldIfExists(val11, "m_isLiquid", value: true);
		SetEnumFieldIfExists(val11, "m_liquidType", "Water");
		ApplyWaterMaterial(val10, val11);
		TryAddWaterTrigger(val5, val11, (Collider)val9, val10);
		TryAddLiquidComponents(val5, val10, (Collider)val9, val11);
		val5.AddComponent<BuildWaterDebugReporter>().Initialize();
		_waterVolume = val11;
		_volumeCollider = (Collider)val9;
		float y2;
		if (!((Object)val10 != (Object)null))
		{
			Bounds bounds2 = ((Collider)val9).bounds;
			y2 = ((Bounds)(ref bounds2)).max.y;
		}
		else
		{
			y2 = ((Component)val10).transform.position.y;
		}
		_surfaceWorldY = y2;
		LogVolumeSetup(bounds, val8, y, (Collider)val9, val10, val5.transform);
	}

	private void EnsureConnectionsRoot()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Expected O, but got Unknown
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Expected O, but got Unknown
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Expected O, but got Unknown
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Expected O, but got Unknown
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)_connectionsRoot != (Object)null))
		{
			Transform val = ((Component)this).transform.Find("BuildWater_Connections");
			if ((Object)val != (Object)null)
			{
				_connectionsRoot = val;
				return;
			}
			GameObject val2 = new GameObject("BuildWater_Connections");
			val2.transform.SetParent(((Object)_waterRoot != (Object)null) ? _waterRoot : ((Component)this).transform, false);
			val2.transform.localPosition = Vector3.zero;
			val2.transform.localRotation = Quaternion.identity;
			_connectionsRoot = val2.transform;
		}
	}

	private void TrackTransformChanges()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: 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_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e1: 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_00e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ef: 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_0103: Unknown result type (might be due to invalid IL or missing references)
		//IL_0108: 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_0082: 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_008b: 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_00b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
		Vector3 position = ((Component)this).transform.position;
		Quaternion rotation = ((Component)this).transform.rotation;
		Vector3 lossyScale = ((Component)this).transform.lossyScale;
		bool flag = Vector3.Distance(position, _lastPosition) > 0.05f || Quaternion.Angle(rotation, _lastRotation) > 1f || Vector3.Distance(lossyScale, _lastScale) > 0.02f;
		if (!flag)
		{
			if (Mathf.Abs(_surfaceWorldY - _lastSurfaceY) > 0.05f)
			{
				flag = true;
			}
			else
			{
				Bounds worldBounds = _worldBounds;
				if (Mathf.Abs(((Bounds)(ref worldBounds)).size.x - ((Bounds)(ref _lastBounds)).size.x) > 0.05f || Mathf.Abs(((Bounds)(ref worldBounds)).size.z - ((Bounds)(ref _lastBounds)).size.z) > 0.05f)
				{
					flag = true;
				}
			}
		}
		if (flag)
		{
			_lastPosition = position;
			_lastRotation = rotation;
			_lastScale = lossyScale;
			_lastSurfaceY = _surfaceWorldY;
			_lastBounds = _worldBounds;
			UpdateGridCell();
			MarkConnectionsDirty();
			NotifyNeighbors(_worldBounds);
		}
	}

	private bool HasTransformChanged()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//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_0024: 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_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		Vector3 position = ((Component)this).transform.position;
		Quaternion rotation = ((Component)this).transform.rotation;
		Vector3 lossyScale = ((Component)this).transform.lossyScale;
		if (!(Vector3.Distance(position, _lastPosition)