Decompiled source of PressUToRelocate v1.0.2

PressUToRelocate.dll

Decompiled 3 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: IgnoresAccessChecksTo("assembly_guiutils")]
[assembly: IgnoresAccessChecksTo("assembly_valheim")]
[assembly: AssemblyCompany("PressUToRelocate")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: AssemblyInformationalVersion("1.0.2")]
[assembly: AssemblyProduct("PressUToRelocate")]
[assembly: AssemblyTitle("PressUToRelocate")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.2.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace PressUToRelocate
{
	internal static class CombatInputSuppression
	{
		internal static void ClearCombatInput(Humanoid humanoid)
		{
			if (!((Object)(object)humanoid == (Object)null))
			{
				((Character)humanoid).m_attack = false;
				((Character)humanoid).m_attackHold = false;
				((Character)humanoid).m_secondaryAttack = false;
				((Character)humanoid).m_secondaryAttackHold = false;
				((Character)humanoid).m_blocking = false;
				Player val = (Player)(object)((humanoid is Player) ? humanoid : null);
				if (val != null)
				{
					val.m_queuedAttackTimer = 0f;
					val.m_queuedSecondAttackTimer = 0f;
				}
				humanoid.m_internalBlockingState = false;
				humanoid.m_blockTimer = -1f;
			}
		}
	}
	[HarmonyPatch(typeof(Player), "SetControls")]
	internal static class Player_SetControls_Patch
	{
		private static void Postfix(Player __instance)
		{
			if (!((Object)(object)__instance == (Object)null) && !((Object)(object)__instance != (Object)(object)Player.m_localPlayer) && RelocateController.ShouldSuppressCombatInput)
			{
				CombatInputSuppression.ClearCombatInput((Humanoid)(object)__instance);
			}
		}
	}
	[HarmonyPatch(typeof(Humanoid), "StartAttack")]
	internal static class Humanoid_StartAttack_Patch
	{
		private static bool Prefix(Humanoid __instance, ref bool __result)
		{
			if ((Object)(object)__instance == (Object)null || (Object)(object)__instance != (Object)(object)Player.m_localPlayer)
			{
				return true;
			}
			if (RelocateController.ShouldSuppressCombatInput)
			{
				CombatInputSuppression.ClearCombatInput(__instance);
				__result = false;
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(Player), "PlayerAttackInput")]
	internal static class Player_PlayerAttackInput_Patch
	{
		private static void Prefix(Player __instance)
		{
			if (!((Object)(object)__instance == (Object)null) && !((Object)(object)__instance != (Object)(object)Player.m_localPlayer) && RelocateController.ShouldSuppressCombatInput)
			{
				CombatInputSuppression.ClearCombatInput((Humanoid)(object)__instance);
			}
		}
	}
	[HarmonyPatch(typeof(Humanoid), "UpdateBlock")]
	internal static class Humanoid_UpdateBlock_Patch
	{
		private static bool Prefix(Humanoid __instance)
		{
			if ((Object)(object)__instance == (Object)null || (Object)(object)__instance != (Object)(object)Player.m_localPlayer)
			{
				return true;
			}
			if (RelocateController.ShouldSuppressCombatInput)
			{
				CombatInputSuppression.ClearCombatInput(__instance);
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(ZInput), "GetMouseScrollWheel")]
	internal static class ZInput_GetMouseScrollWheel_Patch
	{
		private static void Postfix(ref float __result)
		{
			if (RelocateController.IsActive)
			{
				__result = 0f;
			}
		}
	}
	internal static class ColliderPlacement
	{
		private const float ProbeDistance = 50f;

		internal static bool TryResolve(GameObject ghost, Vector3 hitPoint, Vector3 surfaceNormal, Quaternion rotation, out Vector3 position)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: 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_00d9: 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_00db: 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_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: 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_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			position = hitPoint;
			if ((Object)(object)ghost == (Object)null)
			{
				return false;
			}
			surfaceNormal = ((!(((Vector3)(ref surfaceNormal)).sqrMagnitude < 0.001f)) ? ((Vector3)(ref surfaceNormal)).normalized : Vector3.up);
			Vector3 val = hitPoint + surfaceNormal * 50f;
			ghost.transform.SetPositionAndRotation(val, rotation);
			Collider[] componentsInChildren = ghost.GetComponentsInChildren<Collider>(true);
			Vector3 val2 = hitPoint;
			float num = float.MaxValue;
			bool flag = false;
			Collider[] array = componentsInChildren;
			foreach (Collider val3 in array)
			{
				if ((Object)(object)val3 == (Object)null || !val3.enabled || val3.isTrigger)
				{
					continue;
				}
				MeshCollider val4 = (MeshCollider)(object)((val3 is MeshCollider) ? val3 : null);
				if (val4 == null || val4.convex)
				{
					Vector3 val5 = val3.ClosestPoint(hitPoint);
					float num2 = Vector3.Distance(val5, hitPoint);
					if (num2 < num)
					{
						num = num2;
						val2 = val5;
						flag = true;
					}
				}
			}
			if (!flag)
			{
				return false;
			}
			position = hitPoint + (val - val2);
			return true;
		}
	}
	internal static class GhostBuilder
	{
		private static readonly Dictionary<Material, float> RippleDistances = new Dictionary<Material, float>();

		internal static GameObject Create(Piece sourcePiece, GameObject prefab)
		{
			if ((Object)(object)prefab == (Object)null && (Object)(object)sourcePiece != (Object)null)
			{
				prefab = ((Component)sourcePiece).gameObject;
			}
			if ((Object)(object)prefab == (Object)null)
			{
				return null;
			}
			bool forceDisableInit = ZNetView.m_forceDisableInit;
			bool forceDisableTerrainOps = TerrainOp.m_forceDisableTerrainOps;
			try
			{
				ZNetView.m_forceDisableInit = true;
				TerrainOp.m_forceDisableTerrainOps = true;
				GameObject obj = Object.Instantiate<GameObject>(prefab);
				((Object)obj).name = ((Object)prefab).name;
				PrepareGhost(obj);
				SetValid(obj, valid: true);
				return obj;
			}
			finally
			{
				ZNetView.m_forceDisableInit = forceDisableInit;
				TerrainOp.m_forceDisableTerrainOps = forceDisableTerrainOps;
			}
		}

		internal static void SetValid(GameObject ghost, bool valid)
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)ghost == (Object)null))
			{
				Piece component = ghost.GetComponent<Piece>();
				if ((Object)(object)component != (Object)null)
				{
					component.SetInvalidPlacementHeightlight(!valid);
					return;
				}
				Color tint = (valid ? RelocatePlugin.GhostColor.Value : RelocatePlugin.BlockedColor.Value);
				TintRenderers(ghost, tint);
			}
		}

		internal static void DestroyGhost(ref GameObject ghost)
		{
			if ((Object)(object)ghost != (Object)null)
			{
				Object.Destroy((Object)(object)ghost);
				ghost = null;
			}
			RippleDistances.Clear();
		}

		private static void PrepareGhost(GameObject ghost)
		{
			Joint[] componentsInChildren = ghost.GetComponentsInChildren<Joint>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				Object.Destroy((Object)(object)componentsInChildren[i]);
			}
			Rigidbody[] componentsInChildren2 = ghost.GetComponentsInChildren<Rigidbody>(true);
			for (int i = 0; i < componentsInChildren2.Length; i++)
			{
				Object.Destroy((Object)(object)componentsInChildren2[i]);
			}
			FilterGhostColliders(ghost);
			int num = LayerMask.NameToLayer("ghost");
			if (num >= 0)
			{
				Transform[] componentsInChildren3 = ghost.GetComponentsInChildren<Transform>(true);
				for (int i = 0; i < componentsInChildren3.Length; i++)
				{
					((Component)componentsInChildren3[i]).gameObject.layer = num;
				}
			}
			ZNetView[] componentsInChildren4 = ghost.GetComponentsInChildren<ZNetView>(true);
			for (int i = 0; i < componentsInChildren4.Length; i++)
			{
				Object.Destroy((Object)(object)componentsInChildren4[i]);
			}
			MonoBehaviour[] componentsInChildren5 = ghost.GetComponentsInChildren<MonoBehaviour>(true);
			foreach (MonoBehaviour val in componentsInChildren5)
			{
				if (!((Object)(object)val == (Object)null))
				{
					string name = ((object)val).GetType().Name;
					if (name.Contains("Container") || name.Contains("CraftingStation") || name.Contains("Switch") || name.Contains("Door") || name.Contains("Smelter") || name.Contains("Incinerator") || name.Contains("CookingStation") || name.Contains("Beehive") || name.Contains("Trap") || name.Contains("MineRock") || name.Contains("Hoverable") || name.Contains("WearNTear"))
					{
						Object.Destroy((Object)(object)val);
					}
				}
			}
			Transform val2 = ghost.transform.Find("_GhostOnly");
			if ((Object)(object)val2 != (Object)null)
			{
				((Component)val2).gameObject.SetActive(true);
			}
			CleanupGhostMaterials<MeshRenderer>(ghost);
			CleanupGhostMaterials<SkinnedMeshRenderer>(ghost);
		}

		private static void FilterGhostColliders(GameObject ghost)
		{
			Player localPlayer = Player.m_localPlayer;
			int num = (((Object)(object)localPlayer != (Object)null) ? localPlayer.m_placeRayMask : (-1));
			Collider val = null;
			Collider[] componentsInChildren = ghost.GetComponentsInChildren<Collider>(true);
			foreach (Collider val2 in componentsInChildren)
			{
				if (!((Object)(object)val2 == (Object)null))
				{
					if (val2.enabled = ((1 << ((Component)val2).gameObject.layer) & num) != 0)
					{
						val = val2;
					}
					else if ((Object)(object)val == (Object)null && !val2.isTrigger)
					{
						val = val2;
					}
				}
			}
			if (!((Object)(object)val != (Object)null))
			{
				return;
			}
			bool flag2 = false;
			componentsInChildren = ghost.GetComponentsInChildren<Collider>(true);
			foreach (Collider val3 in componentsInChildren)
			{
				if ((Object)(object)val3 != (Object)null && val3.enabled)
				{
					flag2 = true;
					break;
				}
			}
			if (!flag2)
			{
				val.enabled = true;
			}
		}

		private static void CleanupGhostMaterials<T>(GameObject ghost) where T : Renderer
		{
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Expected O, but got Unknown
			T[] componentsInChildren = ghost.GetComponentsInChildren<T>(true);
			foreach (T val in componentsInChildren)
			{
				if ((Object)(object)((Renderer)val).sharedMaterial == (Object)null)
				{
					continue;
				}
				Material[] sharedMaterials = ((Renderer)val).sharedMaterials;
				for (int j = 0; j < sharedMaterials.Length; j++)
				{
					Material val2 = sharedMaterials[j];
					if (!((Object)(object)val2 == (Object)null))
					{
						Material val3 = new Material(val2);
						if (val3.HasProperty("_RippleDistance"))
						{
							RippleDistances[val3] = val3.GetFloat("_RippleDistance");
						}
						if (val3.HasProperty("_ValueNoise"))
						{
							val3.SetFloat("_ValueNoise", 0f);
						}
						if (val3.HasProperty("_TriplanarLocalPos"))
						{
							val3.SetFloat("_TriplanarLocalPos", 1f);
						}
						sharedMaterials[j] = val3;
					}
				}
				((Renderer)val).sharedMaterials = sharedMaterials;
				((Renderer)val).shadowCastingMode = (ShadowCastingMode)0;
			}
		}

		private static void TintRenderers(GameObject ghost, Color tint)
		{
			//IL_0041: 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)
			Renderer[] componentsInChildren = ghost.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val in componentsInChildren)
			{
				Material[] materials = val.materials;
				foreach (Material val2 in materials)
				{
					if (!((Object)(object)val2 == (Object)null))
					{
						if (val2.HasProperty("_Color"))
						{
							val2.SetColor("_Color", tint);
						}
						if (val2.HasProperty("_BaseColor"))
						{
							val2.SetColor("_BaseColor", tint);
						}
					}
				}
				val.materials = materials;
			}
		}
	}
	internal static class PlacementRay
	{
		internal struct HitInfo
		{
			internal Vector3 Point;

			internal Vector3 Normal;

			internal Piece HitPiece;

			internal Heightmap Heightmap;

			internal Collider HitCollider;

			internal Collider WaterSurface;

			internal bool HasHit;
		}

		private const float PhysicsRayLength = 50f;

		private const float VerticalSurfaceThreshold = 0.5f;

		internal static bool TryCast(Player player, Piece sourcePiece, bool water, out HitInfo hit)
		{
			//IL_004d: 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_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			hit = default(HitInfo);
			if ((Object)(object)player == (Object)null || (Object)(object)GameCamera.instance == (Object)null)
			{
				return false;
			}
			Transform eye = ((Character)player).m_eye;
			if ((Object)(object)eye == (Object)null)
			{
				return false;
			}
			int num = (water ? player.m_placeWaterRayMask : player.m_placeRayMask);
			Vector3 position = ((Component)GameCamera.instance).transform.position;
			Vector3 forward = ((Component)GameCamera.instance).transform.forward;
			float maxEyeDistance = GetMaxEyeDistance(sourcePiece);
			Vector3 position2 = eye.position;
			RaycastHit[] array = Physics.RaycastAll(position, forward, 50f, num, (QueryTriggerInteraction)1);
			if (array == null || array.Length == 0)
			{
				return false;
			}
			Array.Sort(array, (RaycastHit a, RaycastHit b) => ((RaycastHit)(ref a)).distance.CompareTo(((RaycastHit)(ref b)).distance));
			RaycastHit[] array2 = array;
			foreach (RaycastHit rayHit in array2)
			{
				if (IsValidHit(rayHit, position2, maxEyeDistance))
				{
					return TryBuildHitInfo(rayHit, out hit);
				}
			}
			return false;
		}

		internal static bool IsLookingTowardWall(Vector3 lookDirection, Vector3 wallNormal)
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			if (((Vector3)(ref lookDirection)).sqrMagnitude < 0.001f || ((Vector3)(ref wallNormal)).sqrMagnitude < 0.001f)
			{
				return false;
			}
			((Vector3)(ref lookDirection)).Normalize();
			((Vector3)(ref wallNormal)).Normalize();
			return Vector3.Dot(lookDirection, -wallNormal) > 0.55f;
		}

		internal static bool TryProjectOnWallPlane(Player player, Piece sourcePiece, Vector3 planePoint, Vector3 planeNormal, Piece wallPiece, Collider wallCollider, out HitInfo hit)
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: 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_0090: 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_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: 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_00ab: 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_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: 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_0129: 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_0133: 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_00ee: 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_00f7: 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_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: 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_0111: 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_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)
			hit = default(HitInfo);
			if ((Object)(object)player == (Object)null || (Object)(object)GameCamera.instance == (Object)null)
			{
				return false;
			}
			planeNormal = ((((Vector3)(ref planeNormal)).sqrMagnitude > 0.001f) ? ((Vector3)(ref planeNormal)).normalized : Vector3.zero);
			if (((Vector3)(ref planeNormal)).sqrMagnitude < 0.001f)
			{
				return false;
			}
			Vector3 position = ((Component)GameCamera.instance).transform.position;
			Vector3 forward = ((Component)GameCamera.instance).transform.forward;
			if (!IsLookingTowardWall(forward, planeNormal))
			{
				return false;
			}
			float num = Vector3.Dot(planeNormal, forward);
			if (Mathf.Abs(num) < 0.001f)
			{
				return false;
			}
			float num2 = Vector3.Dot(planePoint - position, planeNormal) / num;
			if (num2 < 0f)
			{
				return false;
			}
			Vector3 val = position + forward * num2;
			if ((Object)(object)((Character)player).m_eye != (Object)null && Vector3.Distance(((Character)player).m_eye.position, val) > GetMaxEyeDistance(sourcePiece))
			{
				return false;
			}
			if ((Object)(object)wallCollider != (Object)null)
			{
				Vector3 val2 = -planeNormal;
				Vector3 val3 = wallCollider.ClosestPoint(val + val2 * 0.5f);
				if (Vector3.Distance(val, val3) > 0.4f)
				{
					return false;
				}
				val = val3;
			}
			hit.Point = val;
			hit.Normal = planeNormal;
			hit.HitPiece = wallPiece;
			hit.HitCollider = wallCollider;
			hit.Heightmap = null;
			hit.WaterSurface = null;
			hit.HasHit = true;
			return true;
		}

		internal static Vector3 ClampToEyeDistance(Player player, Vector3 targetPoint, Piece sourcePiece)
		{
			//IL_001c: 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_0022: 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_0029: 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_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: 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_0051: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)((Character)(player?)).m_eye == (Object)null)
			{
				return targetPoint;
			}
			Vector3 position = ((Character)player).m_eye.position;
			Vector3 val = targetPoint - position;
			float magnitude = ((Vector3)(ref val)).magnitude;
			float maxEyeDistance = GetMaxEyeDistance(sourcePiece);
			if (magnitude <= maxEyeDistance || magnitude < 0.001f)
			{
				return targetPoint;
			}
			return position + val * (maxEyeDistance / magnitude);
		}

		internal static float EyeDistance(Player player, Vector3 point)
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: 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_002b: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)((Character)(player?)).m_eye == (Object)null)
			{
				return Vector3.Distance(((Object)(object)player != (Object)null) ? ((Component)player).transform.position : point, point);
			}
			return Vector3.Distance(((Character)player).m_eye.position, point);
		}

		private static float GetMaxEyeDistance(Piece sourcePiece)
		{
			float num = RelocatePlugin.MaxPlaceDistance.Value;
			if ((Object)(object)sourcePiece != (Object)null)
			{
				num += (float)sourcePiece.m_extraPlacementDistance;
			}
			return num;
		}

		private static bool IsValidHit(RaycastHit rayHit, Vector3 eyePosition, float maxEyeDistance)
		{
			//IL_0021: 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)
			Collider collider = ((RaycastHit)(ref rayHit)).collider;
			if ((Object)(object)collider == (Object)null || (Object)(object)collider.attachedRigidbody != (Object)null)
			{
				return false;
			}
			return Vector3.Distance(eyePosition, ((RaycastHit)(ref rayHit)).point) <= maxEyeDistance;
		}

		internal static bool IsWallSurfaceHit(RaycastHit rayHit)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			if (((RaycastHit)(ref rayHit)).normal.y >= 0.5f)
			{
				return false;
			}
			Piece componentInParent = ((Component)((RaycastHit)(ref rayHit)).collider).GetComponentInParent<Piece>();
			if ((Object)(object)componentInParent != (Object)null)
			{
				return ((Component)componentInParent).GetComponentInParent<Hoverable>() == null;
			}
			return (Object)(object)((Component)((RaycastHit)(ref rayHit)).collider).GetComponent<Heightmap>() == (Object)null;
		}

		private static bool TryBuildHitInfo(RaycastHit rayHit, out HitInfo hit)
		{
			//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_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_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: 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_0054: Unknown result type (might be due to invalid IL or missing references)
			hit = default(HitInfo);
			Collider collider = ((RaycastHit)(ref rayHit)).collider;
			if ((Object)(object)collider == (Object)null)
			{
				return false;
			}
			hit.Point = ((RaycastHit)(ref rayHit)).point;
			Vector3 normal = ((RaycastHit)(ref rayHit)).normal;
			Vector3 normal2;
			if (!(((Vector3)(ref normal)).sqrMagnitude > 0.001f))
			{
				normal2 = Vector3.up;
			}
			else
			{
				normal = ((RaycastHit)(ref rayHit)).normal;
				normal2 = ((Vector3)(ref normal)).normalized;
			}
			hit.Normal = normal2;
			hit.HitCollider = collider;
			hit.HitPiece = ((Component)collider).GetComponentInParent<Piece>();
			hit.Heightmap = ((Component)collider).GetComponent<Heightmap>();
			hit.WaterSurface = ((((Component)collider).gameObject.layer == LayerMask.NameToLayer("Water")) ? collider : null);
			hit.HasHit = true;
			return true;
		}
	}
	internal static class PlacementTransform
	{
		private const float VerticalSurfaceThreshold = 0.5f;

		private const float GroundSurfaceOffset = 0.02f;

		internal static bool TryResolve(Piece piece, GameObject ghost, Player player, bool rayHit, Vector3 hitPoint, Vector3 hitNormal, Heightmap heightmap, Collider hitCollider, Quaternion targetRotation, WallPlacement.MountContext mountContext, out Vector3 position, out Quaternion rotation, out Vector3 surfaceNormal)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: 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_000d: 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_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: 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_0092: 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_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: 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_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_015b: 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_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: 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_0172: 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_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: 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_014e: 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_01ab: 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_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: 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_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: 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_01a2: Unknown result type (might be due to invalid IL or missing references)
			position = hitPoint;
			rotation = targetRotation;
			surfaceNormal = ((((Vector3)(ref hitNormal)).sqrMagnitude > 0.001f) ? ((Vector3)(ref hitNormal)).normalized : Vector3.up);
			if (!rayHit || (Object)(object)piece == (Object)null || (Object)(object)player == (Object)null)
			{
				return false;
			}
			if (surfaceNormal.y < 0.5f)
			{
				rotation = targetRotation;
				if ((Object)(object)ghost == (Object)null)
				{
					position = hitPoint + surfaceNormal * 0.02f;
					return true;
				}
				position = WallPlacement.ResolveWallPosition(ghost, hitPoint, surfaceNormal, rotation, hitCollider, mountContext);
				return true;
			}
			if (piece.m_notOnFloor || piece.m_inCeilingOnly)
			{
				return false;
			}
			int num;
			if (!piece.m_groundPiece)
			{
				num = (piece.m_groundOnly ? 1 : 0);
				if (num == 0)
				{
					goto IL_00ee;
				}
			}
			else
			{
				num = 1;
			}
			if ((Object)(object)heightmap != (Object)null)
			{
				surfaceNormal = Vector3.up;
			}
			goto IL_00ee;
			IL_00ee:
			if (num != 0)
			{
				Vector3 worldPos = hitPoint;
				worldPos.y = ((Component)player).transform.position.y + 2f;
				if (RelocateUtils.TryFindFloorY(worldPos, 8f, out var floorY))
				{
					position = new Vector3(hitPoint.x, floorY + 0.02f, hitPoint.z);
					surfaceNormal = Vector3.up;
					rotation = targetRotation;
					return true;
				}
				return false;
			}
			rotation = targetRotation;
			if (surfaceNormal.y >= 0.5f)
			{
				surfaceNormal = Vector3.up;
			}
			if ((Object)(object)ghost != (Object)null && ColliderPlacement.TryResolve(ghost, hitPoint, surfaceNormal, rotation, out var position2))
			{
				position = position2;
				return true;
			}
			position = hitPoint + surfaceNormal * 0.02f;
			if ((Object)(object)heightmap == (Object)null && RelocateUtils.TryFindFloorY(position, 4f, out var floorY2))
			{
				position.y = floorY2 + 0.02f;
			}
			return true;
		}
	}
	internal static class PlacementValidator
	{
		internal static bool IsValid(Piece piece, Player player, Vector3 pos, Quaternion rot, Vector3 normal, Heightmap heightmap, Collider waterSurface, Piece hitPiece, Collider hitCollider, Piece sourcePiece, GameObject ghost)
		{
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: 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_00d5: 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_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Invalid comparison between Unknown and I4
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0216: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: 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_01de: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Invalid comparison between Unknown and I4
			//IL_0241: Unknown result type (might be due to invalid IL or missing references)
			//IL_0284: Unknown result type (might be due to invalid IL or missing references)
			//IL_028b: Unknown result type (might be due to invalid IL or missing references)
			//IL_028c: 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_0297: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d9: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)piece == (Object)null || (Object)(object)player == (Object)null)
			{
				return false;
			}
			bool flag = piece.m_notOnFloor || piece.m_inCeilingOnly;
			float num = RelocatePlugin.MaxPlaceDistance.Value;
			if ((Object)(object)sourcePiece != (Object)null)
			{
				num += (float)sourcePiece.m_extraPlacementDistance;
			}
			if (PlacementRay.EyeDistance(player, pos) > num)
			{
				return false;
			}
			if (RelocatePlugin.RequireBuildAccess.Value && Location.IsInsideNoBuildLocation(pos))
			{
				return false;
			}
			if (RelocatePlugin.RespectWards.Value)
			{
				PrivateArea component = ((Component)piece).GetComponent<PrivateArea>();
				float num2 = (((Object)(object)component != (Object)null) ? component.m_radius : 0f);
				bool flag2 = (Object)(object)component != (Object)null;
				if (!PrivateArea.CheckAccess(pos, num2, false, flag2))
				{
					return false;
				}
			}
			WearNTear val = (((Object)(object)hitPiece != (Object)null) ? ((Component)hitPiece).GetComponent<WearNTear>() : null);
			StationExtension component2 = ((Component)piece).GetComponent<StationExtension>();
			if ((Object)(object)component2 != (Object)null && (Object)(object)component2.FindClosestStationInRange(pos) == (Object)null)
			{
				return false;
			}
			if ((Object)(object)component2 != (Object)null && component2.OtherExtensionInRange(piece.m_spaceRequirement))
			{
				return false;
			}
			if (piece.m_waterPiece && (Object)(object)waterSurface == (Object)null)
			{
				return false;
			}
			if (piece.m_noInWater && (Object)(object)waterSurface != (Object)null)
			{
				return false;
			}
			if (piece.m_groundPiece && (Object)(object)heightmap == (Object)null)
			{
				return false;
			}
			if (piece.m_groundOnly && (Object)(object)heightmap == (Object)null)
			{
				return false;
			}
			if (piece.m_cultivatedGroundOnly && ((Object)(object)heightmap == (Object)null || !heightmap.IsCultivated(pos)))
			{
				return false;
			}
			if (piece.m_vegetationGroundOnly)
			{
				bool flag3 = (Object)(object)heightmap == (Object)null;
				if (!flag3)
				{
					Biome biome = heightmap.GetBiome(pos, 0.02f, false);
					float vegetationMask = heightmap.GetVegetationMask(pos);
					flag3 = (((int)biome == 32) ? (vegetationMask > 0.1f) : (vegetationMask < 0.25f));
				}
				if (flag3)
				{
					return false;
				}
			}
			if (piece.m_notOnWood && (Object)(object)hitPiece != (Object)null && (Object)(object)val != (Object)null && ((int)val.m_materialType == 0 || (int)val.m_materialType == 3))
			{
				return false;
			}
			if (piece.m_notOnTiltingSurface && normal.y > 0.5f && normal.y < 0.8f)
			{
				return false;
			}
			if (piece.m_inCeilingOnly && normal.y > -0.5f)
			{
				return false;
			}
			if (flag && normal.y > 0.1f)
			{
				return false;
			}
			if (piece.m_onlyInTeleportArea && !Object.op_Implicit((Object)(object)EffectArea.IsPointInsideArea(pos, (Type)16, 0f)))
			{
				return false;
			}
			if (!piece.m_allowedInDungeons && ((Character)player).InInterior() && !EnvMan.instance.CheckInteriorBuildingOverride() && !ZoneSystem.instance.GetGlobalKey((GlobalKeys)29))
			{
				return false;
			}
			if ((int)piece.m_onlyInBiome != 0 && (Heightmap.FindBiome(pos) & piece.m_onlyInBiome) == 0)
			{
				return false;
			}
			if ((Object)(object)val != (Object)null && !val.m_supports && (Object)(object)hitPiece != (Object)null && (Object)(object)hitPiece != (Object)(object)sourcePiece && (!flag || !IsStructuralPiece(hitPiece)))
			{
				return false;
			}
			if (IsBlockedByOtherPiece(piece, player, sourcePiece, hitPiece, ghost, pos, rot))
			{
				return false;
			}
			if (piece.m_noClipping && (Object)(object)ghost != (Object)null && TestGhostClippingExcluding(player, ghost, 0.2f, hitCollider, hitPiece, sourcePiece))
			{
				return false;
			}
			return true;
		}

		private static bool TestGhostClippingExcluding(Player player, GameObject ghost, float maxDepth, Collider mountCollider, Piece mountPiece, Piece sourcePiece)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			HashSet<Collider> hashSet = new HashSet<Collider>();
			AddExcludedCollider(hashSet, mountCollider);
			AddExcludedCollidersFromPiece(hashSet, mountPiece);
			AddExcludedCollidersFromPiece(hashSet, sourcePiece);
			Collider[] componentsInChildren = ghost.GetComponentsInChildren<Collider>(true);
			if (componentsInChildren == null || componentsInChildren.Length == 0)
			{
				return false;
			}
			Vector3 position = ghost.transform.position;
			Collider[] array = Physics.OverlapSphere(position, 10f, player.m_placeRayMask, (QueryTriggerInteraction)1);
			Collider[] array2 = componentsInChildren;
			Vector3 val3 = default(Vector3);
			float num = default(float);
			foreach (Collider val in array2)
			{
				if ((Object)(object)val == (Object)null || !val.enabled)
				{
					continue;
				}
				Collider[] array3 = array;
				foreach (Collider val2 in array3)
				{
					if (!((Object)(object)val2 == (Object)null) && !val2.isTrigger && !hashSet.Contains(val2) && (!((Object)(object)mountPiece != (Object)null) || !((Component)val2).transform.IsChildOf(((Component)mountPiece).transform)) && (!((Object)(object)sourcePiece != (Object)null) || !((Component)val2).transform.IsChildOf(((Component)sourcePiece).transform)) && Physics.ComputePenetration(val, position, ghost.transform.rotation, val2, ((Component)val2).transform.position, ((Component)val2).transform.rotation, ref val3, ref num) && num > maxDepth)
					{
						return true;
					}
				}
			}
			return false;
		}

		private static void AddExcludedCollider(HashSet<Collider> excluded, Collider collider)
		{
			if (excluded != null && (Object)(object)collider != (Object)null)
			{
				excluded.Add(collider);
			}
		}

		private static void AddExcludedCollidersFromPiece(HashSet<Collider> excluded, Piece piece)
		{
			if (excluded == null || (Object)(object)piece == (Object)null)
			{
				return;
			}
			Collider[] componentsInChildren = ((Component)piece).GetComponentsInChildren<Collider>(true);
			foreach (Collider val in componentsInChildren)
			{
				if ((Object)(object)val != (Object)null)
				{
					excluded.Add(val);
				}
			}
		}

		private static bool IsBlockedByOtherPiece(Piece piece, Player player, Piece sourcePiece, Piece hitPiece, GameObject ghost, Vector3 pos, Quaternion rot)
		{
			//IL_0021: 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_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: 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_0102: 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)
			if ((Object)(object)ghost == (Object)null || (Object)(object)player == (Object)null)
			{
				return false;
			}
			player.m_tempPieces.Clear();
			if (player.IsOverlappingOtherPiece(pos, rot, ((Object)ghost).name, player.m_tempPieces, piece.m_allowRotatedOverlap))
			{
				return true;
			}
			int mask = LayerMask.GetMask(new string[1] { "piece" });
			Collider[] array = Physics.OverlapSphere(pos, 0.25f, mask, (QueryTriggerInteraction)1);
			string name = ((Object)ghost).name;
			bool flag = piece.m_notOnFloor || piece.m_inCeilingOnly;
			Collider[] array2 = array;
			for (int i = 0; i < array2.Length; i++)
			{
				Piece componentInParent = ((Component)array2[i]).GetComponentInParent<Piece>();
				if (!((Object)(object)componentInParent == (Object)null) && !((Object)(object)componentInParent == (Object)(object)sourcePiece) && !((Object)(object)componentInParent == (Object)(object)hitPiece) && !Utils.CustomStartsWith(((Object)((Component)componentInParent).gameObject).name, name) && !RelocateUtils.IsSamePieceType(piece, componentInParent) && (!flag || !IsStructuralPiece(componentInParent)) && Vector3.Distance(pos, ((Component)componentInParent).transform.position) < 0.05f && (!piece.m_allowRotatedOverlap || Quaternion.Angle(((Component)componentInParent).transform.rotation, rot) > 10f))
				{
					return true;
				}
			}
			return false;
		}

		private static bool IsStructuralPiece(Piece piece)
		{
			if ((Object)(object)piece == (Object)null)
			{
				return false;
			}
			return ((Component)piece).GetComponentInParent<Hoverable>() == null;
		}
	}
	internal static class RelocateApplier
	{
		internal static void ApplyOwnerRelocate(ZNetView nview, Piece piece, Vector3 position, Quaternion rotation)
		{
			//IL_0020: 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_0032: 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_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)nview == (Object)null) && nview.IsValid())
			{
				RelocateNetwork.EnsureRegistered(nview);
				nview.ClaimOwnership();
				ApplyVisual(nview, piece, position, rotation);
				ZDO zDO = nview.GetZDO();
				if (zDO != null)
				{
					zDO.SetPosition(position);
					zDO.SetRotation(rotation);
				}
				ZSyncTransform component = ((Component)nview).GetComponent<ZSyncTransform>();
				if ((Object)(object)component != (Object)null)
				{
					((Component)nview).transform.hasChanged = true;
					component.SyncNow();
				}
				Physics.SyncTransforms();
				if ((Object)(object)ZNet.instance != (Object)null)
				{
					nview.InvokeRPC(ZNetView.Everybody, "PressURelocate", new object[2] { position, rotation });
				}
			}
		}

		internal static void ApplyRemoteRelocate(ZNetView nview, Piece piece, Vector3 position, Quaternion rotation)
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: 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)
			if (!((Object)(object)nview == (Object)null) && nview.IsValid())
			{
				ZDO zDO = nview.GetZDO();
				if (zDO != null)
				{
					zDO.SetPosition(position);
					zDO.SetRotation(rotation);
				}
				ApplyVisual(nview, piece, position, rotation);
				ZSyncTransform component = ((Component)nview).GetComponent<ZSyncTransform>();
				if ((Object)(object)component != (Object)null)
				{
					((Component)nview).transform.hasChanged = true;
					component.SyncNow();
				}
				Physics.SyncTransforms();
			}
		}

		internal static void ApplyVisual(ZNetView nview, Piece piece, Vector3 position, Quaternion rotation)
		{
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)nview == (Object)null) && nview.IsValid())
			{
				Rigidbody component = ((Component)nview).GetComponent<Rigidbody>();
				if ((Object)(object)component != (Object)null)
				{
					component.linearVelocity = Vector3.zero;
					component.angularVelocity = Vector3.zero;
					component.position = position;
					component.rotation = rotation;
				}
				((Component)nview).transform.SetPositionAndRotation(position, rotation);
				if ((Object)(object)piece != (Object)null)
				{
					((Component)piece).transform.SetPositionAndRotation(position, rotation);
				}
				Physics.SyncTransforms();
			}
		}
	}
	internal enum RelocateState
	{
		Idle,
		Moving
	}
	internal class RelocateController : MonoBehaviour
	{
		private RelocateState _state;

		private RelocateVisuals _visuals;

		private readonly VanillaPlacementSession _vanillaPlacement = new VanillaPlacementSession();

		private Piece _sourcePiece;

		private ZNetView _sourceView;

		private Vector3 _originPosition;

		private Quaternion _originRotation;

		private Vector3 _ghostPosition;

		private Quaternion _ghostRotation;

		private bool _placementValid;

		internal static float SuppressAttackUntil;

		internal static bool IsMoving { get; private set; }

		internal static bool IsActive { get; private set; }

		internal static bool ShouldSuppressCombatInput
		{
			get
			{
				if (!IsActive)
				{
					return Time.time < SuppressAttackUntil;
				}
				return true;
			}
		}

		internal static bool ShouldSuppressAttack => ShouldSuppressCombatInput;

		private void Awake()
		{
			_visuals = ((Component)this).gameObject.AddComponent<RelocateVisuals>();
			((Component)this).gameObject.AddComponent<RelocateHoverHint>();
		}

		private void Update()
		{
			if (!RelocatePlugin.Enabled.Value || RelocateUtils.IsTextFieldFocused())
			{
				return;
			}
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null)
			{
				if (_state == RelocateState.Moving)
				{
					CancelRelocate();
				}
			}
			else if (_state == RelocateState.Idle)
			{
				TryBeginRelocate(localPlayer);
			}
			else
			{
				UpdateMoving(localPlayer);
			}
		}

		private void TryBeginRelocate(Player player)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			KeyboardShortcut value = RelocatePlugin.GrabKey.Value;
			if (((KeyboardShortcut)(ref value)).IsDown() && RelocateUtils.TryGetHoveredPiece(player, out var piece, out var nview) && RelocateUtils.CanRelocate(player, piece, out var _))
			{
				BeginRelocate(player, piece, nview);
				RelocateNetwork.EnsureRegistered(nview);
			}
		}

		private void BeginRelocate(Player player, Piece piece, ZNetView nview)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: 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_0069: 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_00d1: 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_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: 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)
			_sourcePiece = piece;
			_sourceView = nview;
			_originPosition = ((Component)piece).transform.position;
			_originRotation = ((Component)piece).transform.rotation;
			GameObject val = ResolvePrefab(nview);
			if ((Object)(object)val == (Object)null)
			{
				MessageHud instance = MessageHud.instance;
				if (instance != null)
				{
					instance.ShowMessage((MessageType)2, "Relocate failed", 0, (Sprite)null, false);
				}
				return;
			}
			try
			{
				SourcePieceSuppression.Suppress(piece);
				if (!_vanillaPlacement.Begin(player, val, _originRotation))
				{
					SourcePieceSuppression.Restore();
					MessageHud instance2 = MessageHud.instance;
					if (instance2 != null)
					{
						instance2.ShowMessage((MessageType)2, "Relocate failed", 0, (Sprite)null, false);
					}
					return;
				}
			}
			catch (Exception)
			{
				SourcePieceSuppression.Restore();
				MessageHud instance3 = MessageHud.instance;
				if (instance3 != null)
				{
					instance3.ShowMessage((MessageType)2, "Relocate failed", 0, (Sprite)null, false);
				}
				return;
			}
			_ghostPosition = _originPosition;
			_ghostRotation = _originRotation;
			_placementValid = true;
			_state = RelocateState.Moving;
			IsMoving = true;
			IsActive = true;
			Hud.HidePieceSelection();
			_visuals.Show(_originPosition, _ghostPosition);
			KeyboardShortcut value = RelocatePlugin.GrabKey.Value;
			string text = ((object)((KeyboardShortcut)(ref value)).MainKey/*cast due to .constrained prefix*/).ToString().ToUpperInvariant();
			MessageHud instance4 = MessageHud.instance;
			if (instance4 != null)
			{
				instance4.ShowMessage((MessageType)2, "Relocate: aim and left-click to place, right-click or " + text + " to cancel", 0, (Sprite)null, false);
			}
		}

		private void UpdateMoving(Player player)
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			SuppressAttackUntil = Time.time + 0.75f;
			HandleRotationInput(player);
			UpdateGhostFromVanilla(player);
			UpdateVisuals();
			if (Input.GetMouseButtonDown(0) && _placementValid)
			{
				SuppressAttackUntil = Time.time + 0.75f;
				ApplyRelocate(player);
				return;
			}
			if (!Input.GetMouseButtonDown(1))
			{
				KeyboardShortcut value = RelocatePlugin.GrabKey.Value;
				if (!((KeyboardShortcut)(ref value)).IsDown())
				{
					return;
				}
			}
			SuppressAttackUntil = Time.time + 0.75f;
			CancelRelocate();
		}

		private void HandleRotationInput(Player player)
		{
			float axis = Input.GetAxis("Mouse ScrollWheel");
			if (!(Mathf.Abs(axis) < 0.001f))
			{
				if (axis > 0f)
				{
					player.m_placeRotation++;
				}
				else
				{
					player.m_placeRotation--;
				}
			}
		}

		private void UpdateGhostFromVanilla(Player player)
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: 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_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Invalid comparison between Unknown and I4
			if ((Object)(object)_sourcePiece == (Object)null)
			{
				CancelRelocate();
				return;
			}
			GameObject placementGhost = player.m_placementGhost;
			if ((Object)(object)placementGhost == (Object)null)
			{
				CancelRelocate();
				return;
			}
			player.UpdatePlacementGhost(false);
			_ghostPosition = placementGhost.transform.position;
			_ghostRotation = placementGhost.transform.rotation;
			_placementValid = (int)player.GetPlacementStatus() == 0;
		}

		private static GameObject ResolvePrefab(ZNetView nview)
		{
			if (((nview != null) ? nview.GetZDO() : null) == null || (Object)(object)ZNetScene.instance == (Object)null)
			{
				return null;
			}
			return ZNetScene.instance.GetPrefab(nview.GetZDO().GetPrefab());
		}

		private void UpdateVisuals()
		{
			//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)
			if ((Object)(object)_visuals != (Object)null && _state == RelocateState.Moving)
			{
				_visuals.Show(_originPosition, _ghostPosition);
			}
		}

		private void ApplyRelocate(Player player)
		{
			//IL_002f: 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)
			if ((Object)(object)_sourceView == (Object)null || !_sourceView.IsValid())
			{
				CancelRelocate();
				return;
			}
			RelocateApplier.ApplyOwnerRelocate(_sourceView, _sourcePiece, _ghostPosition, _ghostRotation);
			MessageHud instance = MessageHud.instance;
			if (instance != null)
			{
				instance.ShowMessage((MessageType)2, "Relocated", 0, (Sprite)null, false);
			}
			EndRelocate(player);
		}

		private void CancelRelocate()
		{
			MessageHud instance = MessageHud.instance;
			if (instance != null)
			{
				instance.ShowMessage((MessageType)2, "Relocate cancelled", 0, (Sprite)null, false);
			}
			EndRelocate(Player.m_localPlayer);
		}

		private void EndRelocate(Player player)
		{
			SourcePieceSuppression.Restore();
			if ((Object)(object)player != (Object)null)
			{
				_vanillaPlacement.End(player);
				Hud.HidePieceSelection();
			}
			_visuals?.Hide();
			ResetState();
		}

		private void ResetState()
		{
			_state = RelocateState.Idle;
			IsMoving = false;
			IsActive = false;
			_sourcePiece = null;
			_sourceView = null;
			_placementValid = false;
		}

		private void OnDestroy()
		{
			SourcePieceSuppression.Restore();
			_vanillaPlacement.End(Player.m_localPlayer);
		}
	}
	internal class RelocateHoverHint : MonoBehaviour
	{
		private const string RelocateMarker = "Relocate";

		private void LateUpdate()
		{
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			if (!RelocatePlugin.Enabled.Value || RelocateUtils.IsTextFieldFocused() || (Object)(object)Hud.instance == (Object)null || (Object)(object)Hud.instance.m_hoverName == (Object)null)
			{
				return;
			}
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null || RelocateController.IsMoving || !RelocateUtils.TryGetHoveredPiece(localPlayer, out var piece, out var _) || !RelocateUtils.CanRelocate(localPlayer, piece, out var _))
			{
				return;
			}
			string text = Localization.instance.Localize(RelocateUtils.GetRelocateHoverLine());
			string text2 = ((TMP_Text)Hud.instance.m_hoverName).text ?? string.Empty;
			if (!text2.Contains("Relocate"))
			{
				if (string.IsNullOrEmpty(text2))
				{
					string text3 = ((!string.IsNullOrEmpty(piece.m_name)) ? Localization.instance.Localize(piece.m_name) : ((Object)piece).name);
					((TMP_Text)Hud.instance.m_hoverName).text = text3 + "\n" + text;
				}
				else
				{
					((TMP_Text)Hud.instance.m_hoverName).text = text2 + "\n" + text;
				}
				((Graphic)Hud.instance.m_crosshair).color = Color.yellow;
			}
		}
	}
	internal static class RelocateNetwork
	{
		internal const string RpcName = "PressURelocate";

		private static readonly HashSet<int> RegisteredViews = new HashSet<int>();

		internal static void EnsureRegistered(ZNetView nview)
		{
			if ((Object)(object)nview == (Object)null || !nview.IsValid())
			{
				return;
			}
			int instanceID = ((Object)nview).GetInstanceID();
			if (!RegisteredViews.Add(instanceID))
			{
				return;
			}
			nview.Register<Vector3, Quaternion>("PressURelocate", (Action<long, Vector3, Quaternion>)delegate(long sender, Vector3 position, Quaternion rotation)
			{
				//IL_0021: 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)
				if (nview.IsValid())
				{
					Piece component = ((Component)nview).GetComponent<Piece>();
					RelocateApplier.ApplyRemoteRelocate(nview, component, position, rotation);
				}
			});
		}
	}
	[HarmonyPatch(typeof(ZNetView), "Awake")]
	internal static class ZNetView_Awake_RelocateRpcPatch
	{
		private static void Postfix(ZNetView __instance)
		{
			if ((Object)(object)((Component)__instance).GetComponent<Piece>() != (Object)null)
			{
				RelocateNetwork.EnsureRegistered(__instance);
			}
		}
	}
	[BepInPlugin("dev.modded.pressutorelocate", "Press U To Relocate", "1.0.2")]
	public class RelocatePlugin : BaseUnityPlugin
	{
		public const string GUID = "dev.modded.pressutorelocate";

		public const string NAME = "Press U To Relocate";

		public const string VERSION = "1.0.2";

		internal static RelocatePlugin Instance;

		internal static ConfigEntry<bool> Enabled;

		internal static ConfigEntry<KeyboardShortcut> GrabKey;

		internal static ConfigEntry<float> MaxGrabDistance;

		internal static ConfigEntry<float> MaxPlaceDistance;

		internal static ConfigEntry<float> RotationSnapDegrees;

		internal static ConfigEntry<bool> RespectWards;

		internal static ConfigEntry<bool> RequireBuildAccess;

		internal static ConfigEntry<Color> GhostColor;

		internal static ConfigEntry<Color> BlockedColor;

		internal static ConfigEntry<Color> TrailColor;

		internal static ConfigEntry<Color> RingColor;

		internal static ConfigEntry<float> RingRadius;

		internal static ConfigEntry<float> DashLength;

		internal static ConfigEntry<float> LineWidth;

		private GameObject _manager;

		private Harmony _harmony;

		private void Awake()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Expected O, but got Unknown
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Expected O, but got Unknown
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Expected O, but got Unknown
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_023e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0280: Unknown result type (might be due to invalid IL or missing references)
			//IL_028a: Expected O, but got Unknown
			//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c7: Expected O, but got Unknown
			//IL_02fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0304: Expected O, but got Unknown
			//IL_030f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0319: Expected O, but got Unknown
			Instance = this;
			_harmony = new Harmony("dev.modded.pressutorelocate");
			_harmony.PatchAll(typeof(RelocatePlugin).Assembly);
			Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Master toggle for the relocate feature.");
			GrabKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("General", "GrabKey", new KeyboardShortcut((KeyCode)117, Array.Empty<KeyCode>()), "Key to grab a hovered piece and to cancel an in-progress relocate. Default U avoids conflicting with Forsaken Power (F).");
			MaxGrabDistance = ((BaseUnityPlugin)this).Config.Bind<float>("General", "MaxGrabDistance", 8f, new ConfigDescription("Maximum distance from the player to grab a hovered piece (meters).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 30f), Array.Empty<object>()));
			MaxPlaceDistance = ((BaseUnityPlugin)this).Config.Bind<float>("General", "MaxPlaceDistance", 12f, new ConfigDescription("Maximum distance from the player to place the ghost (meters).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 40f), Array.Empty<object>()));
			RotationSnapDegrees = ((BaseUnityPlugin)this).Config.Bind<float>("General", "RotationSnapDegrees", 22.5f, new ConfigDescription("Degrees to rotate the ghost per scroll-wheel tick.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 90f), Array.Empty<object>()));
			RespectWards = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "RespectWards", true, "If true, block placement inside wards you cannot build in.");
			RequireBuildAccess = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "RequireBuildAccess", true, "If true, require build permission at the target location.");
			GhostColor = ((BaseUnityPlugin)this).Config.Bind<Color>("Appearance", "GhostColor", new Color(0.35f, 0.95f, 0.45f, 0.5f), "Tint applied to the ghost when placement is valid.");
			BlockedColor = ((BaseUnityPlugin)this).Config.Bind<Color>("Appearance", "BlockedColor", new Color(0.95f, 0.25f, 0.2f, 0.5f), "Tint applied to the ghost when placement is blocked.");
			TrailColor = ((BaseUnityPlugin)this).Config.Bind<Color>("Appearance", "TrailColor", new Color(1f, 1f, 1f, 0.85f), "Color of the dashed connector line.");
			RingColor = ((BaseUnityPlugin)this).Config.Bind<Color>("Appearance", "RingColor", new Color(1f, 1f, 1f, 0.9f), "Color of the ground rings at the origin and ghost.");
			RingRadius = ((BaseUnityPlugin)this).Config.Bind<float>("Appearance", "RingRadius", 0.6f, new ConfigDescription("Radius of the ground rings in meters.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 3f), Array.Empty<object>()));
			DashLength = ((BaseUnityPlugin)this).Config.Bind<float>("Appearance", "DashLength", 0.35f, new ConfigDescription("Length of each dash segment along the connector (meters).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.05f, 2f), Array.Empty<object>()));
			LineWidth = ((BaseUnityPlugin)this).Config.Bind<float>("Appearance", "LineWidth", 0.06f, new ConfigDescription("Width of trail and ring lines in meters.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.01f, 0.5f), Array.Empty<object>()));
			_manager = new GameObject("PressUToRelocate_Manager");
			_manager.AddComponent<RelocateController>();
			Object.DontDestroyOnLoad((Object)(object)_manager);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Press U To Relocate v1.0.2 loaded.");
		}

		private void OnDestroy()
		{
			if ((Object)(object)_manager != (Object)null)
			{
				Object.Destroy((Object)(object)_manager);
				_manager = null;
			}
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			_harmony = null;
		}
	}
	internal static class RelocateUtils
	{
		internal static bool IsTextFieldFocused()
		{
			try
			{
				if (Console.IsVisible())
				{
					return true;
				}
				if ((Object)(object)Chat.instance != (Object)null && Chat.instance.HasFocus())
				{
					return true;
				}
			}
			catch
			{
			}
			return false;
		}

		internal static bool CanRelocate(Player player, Piece piece, out string blockedReason)
		{
			//IL_0051: 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_008d: Unknown result type (might be due to invalid IL or missing references)
			blockedReason = null;
			if ((Object)(object)player == (Object)null || (Object)(object)piece == (Object)null)
			{
				return false;
			}
			if (!IsRelocatablePiece(piece, ((Humanoid)player).GetHoverObject()))
			{
				return false;
			}
			ZNetView val = piece.m_nview ?? ((Component)piece).GetComponent<ZNetView>();
			if ((Object)(object)val == (Object)null || !val.IsValid())
			{
				return false;
			}
			if (HorizontalDistance(((Component)player).transform.position, ((Component)piece).transform.position) > RelocatePlugin.MaxGrabDistance.Value)
			{
				blockedReason = "$msg_too_farsaway";
				return false;
			}
			if (RelocatePlugin.RespectWards.Value && !PrivateArea.CheckAccess(((Component)piece).transform.position, 0f, true, false))
			{
				blockedReason = "$piece_noaccess";
				return false;
			}
			return true;
		}

		internal static string GetRelocateHoverLine()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			KeyboardShortcut value = RelocatePlugin.GrabKey.Value;
			string text = ((object)((KeyboardShortcut)(ref value)).MainKey/*cast due to .constrained prefix*/).ToString().ToUpperInvariant();
			return "[<color=yellow><b>" + text + "</b></color>] Relocate";
		}

		internal static bool TryGetHoveredPiece(Player player, out Piece piece, out ZNetView nview)
		{
			piece = null;
			nview = null;
			if ((Object)(object)player == (Object)null)
			{
				return false;
			}
			GameObject hoverObject = ((Humanoid)player).GetHoverObject();
			if ((Object)(object)hoverObject == (Object)null)
			{
				return false;
			}
			piece = hoverObject.GetComponentInParent<Piece>();
			if ((Object)(object)piece == (Object)null || !IsRelocatablePiece(piece, hoverObject))
			{
				return false;
			}
			nview = piece.m_nview ?? ((Component)piece).GetComponent<ZNetView>();
			if ((Object)(object)nview != (Object)null)
			{
				return nview.IsValid();
			}
			return false;
		}

		internal static bool IsRelocatablePiece(Piece piece, GameObject hover)
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Invalid comparison between Unknown and I4
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Invalid comparison between Unknown and I4
			if ((Object)(object)piece == (Object)null || (Object)(object)hover == (Object)null)
			{
				return false;
			}
			if (piece.m_repairPiece || piece.m_removePiece)
			{
				return false;
			}
			if (!piece.IsPlacedByPlayer())
			{
				return false;
			}
			if (hover.GetComponentInParent<Hoverable>() == null)
			{
				return false;
			}
			PieceCategory category = piece.m_category;
			if ((int)category <= 1 || category - 4 <= 3)
			{
				return true;
			}
			return false;
		}

		internal static Vector3 GetGroundPoint(Vector3 worldPos, float searchHeight = 4f)
		{
			//IL_0000: 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_0030: 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_000b: 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)
			if (TryFindFloorY(worldPos, searchHeight, out var floorY))
			{
				return new Vector3(worldPos.x, floorY + 0.03f, worldPos.z);
			}
			return new Vector3(worldPos.x, worldPos.y, worldPos.z);
		}

		internal static bool TryFindFloorY(Vector3 worldPos, float searchHeight, out float floorY)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: 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_0093: 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_00ad: 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)
			floorY = worldPos.y;
			int mask = LayerMask.GetMask(new string[6] { "Default", "static_solid", "Default_small", "piece", "terrain", "water" });
			RaycastHit[] array = Physics.RaycastAll(worldPos + Vector3.up * 0.25f, Vector3.down, searchHeight, mask, (QueryTriggerInteraction)1);
			bool flag = false;
			float num = float.NegativeInfinity;
			RaycastHit[] array2 = array;
			for (int i = 0; i < array2.Length; i++)
			{
				RaycastHit val = array2[i];
				if (!(((RaycastHit)(ref val)).normal.y < 0.7f) && !(((RaycastHit)(ref val)).point.y > worldPos.y + 0.2f) && ((RaycastHit)(ref val)).point.y > num)
				{
					num = ((RaycastHit)(ref val)).point.y;
					flag = true;
				}
			}
			if (flag)
			{
				floorY = num;
			}
			return flag;
		}

		internal static bool IsSamePieceType(Piece a, Piece b)
		{
			if ((Object)(object)a == (Object)null || (Object)(object)b == (Object)null)
			{
				return false;
			}
			return a.m_name == b.m_name;
		}

		internal static float HorizontalDistance(Vector3 a, Vector3 b)
		{
			//IL_0018: 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)
			a.y = 0f;
			b.y = 0f;
			return Vector3.Distance(a, b);
		}
	}
	internal class RelocateVisuals : MonoBehaviour
	{
		private LineRenderer _dashLine;

		private LineRenderer _originRing;

		private LineRenderer _ghostRing;

		private Texture2D _dashTexture;

		private Color _lastTrail;

		private Color _lastRing;

		private float _lastWidth = -1f;

		private float _lastDashLength = -1f;

		private const int RingSegments = 28;

		private void Awake()
		{
			_dashLine = CreateLineRenderer("Relocate_Dash", loop: false, tiled: true);
			_originRing = CreateLineRenderer("Relocate_OriginRing", loop: true, tiled: false);
			_ghostRing = CreateLineRenderer("Relocate_GhostRing", loop: true, tiled: false);
			SetVisible(visible: false);
		}

		private void OnDestroy()
		{
			if ((Object)(object)_dashTexture != (Object)null)
			{
				Object.Destroy((Object)(object)_dashTexture);
				_dashTexture = null;
			}
		}

		private LineRenderer CreateLineRenderer(string name, bool loop, bool tiled)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Expected O, but got Unknown
			GameObject val = new GameObject(name);
			val.transform.SetParent(((Component)this).transform, false);
			LineRenderer val2 = val.AddComponent<LineRenderer>();
			val2.useWorldSpace = true;
			val2.loop = loop;
			val2.numCapVertices = 4;
			val2.numCornerVertices = 2;
			val2.textureMode = (LineTextureMode)(tiled ? 1 : 0);
			((Renderer)val2).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)val2).receiveShadows = false;
			val2.alignment = (LineAlignment)0;
			val2.positionCount = 0;
			Shader val3 = Shader.Find("Sprites/Default") ?? Shader.Find("Unlit/Color") ?? Shader.Find("Particles/Standard Unlit");
			if ((Object)(object)val3 != (Object)null)
			{
				((Renderer)val2).material = new Material(val3);
				((Renderer)val2).material.renderQueue = 3100;
			}
			return val2;
		}

		internal void Show(Vector3 originWorld, Vector3 ghostWorld)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: 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_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: 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_0032: Unknown result type (might be due to invalid IL or missing references)
			ApplyStyleIfChanged();
			Vector3 val = ProjectToGround(originWorld);
			Vector3 val2 = ProjectToGround(ghostWorld);
			DrawRing(_originRing, val);
			DrawRing(_ghostRing, val2);
			DrawDash(val, val2);
			((Renderer)_dashLine).enabled = true;
			((Renderer)_originRing).enabled = true;
			((Renderer)_ghostRing).enabled = true;
		}

		internal void Hide()
		{
			SetVisible(visible: false);
		}

		private Vector3 ProjectToGround(Vector3 worldPos)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			return RelocateUtils.GetGroundPoint(worldPos);
		}

		private void DrawRing(LineRenderer ring, Vector3 center)
		{
			//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_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_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			float value = RelocatePlugin.RingRadius.Value;
			if (ring.positionCount != 28)
			{
				ring.positionCount = 28;
			}
			Vector3 right = Vector3.right;
			Vector3 forward = Vector3.forward;
			for (int i = 0; i < 28; i++)
			{
				float num = (float)i / 28f * (float)Math.PI * 2f;
				Vector3 val = center + (right * Mathf.Cos(num) + forward * Mathf.Sin(num)) * value;
				ring.SetPosition(i, val);
			}
		}

		private void DrawDash(Vector3 from, Vector3 to)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: 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_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			float num = Vector3.Distance(from, to);
			_dashLine.positionCount = 2;
			_dashLine.SetPosition(0, from);
			_dashLine.SetPosition(1, to);
			if ((Object)(object)((Renderer)_dashLine).material != (Object)null)
			{
				EnsureDashTexture();
				((Renderer)_dashLine).material.mainTexture = (Texture)(object)_dashTexture;
				float num2 = Mathf.Max(0.05f, RelocatePlugin.DashLength.Value);
				((Renderer)_dashLine).material.mainTextureScale = new Vector2(Mathf.Max(0.01f, num / num2), 1f);
			}
		}

		private void EnsureDashTexture()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: 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_002f: Expected O, but got Unknown
			//IL_005b: 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_0060: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_dashTexture != (Object)null))
			{
				int num = 10;
				_dashTexture = new Texture2D(num, 1, (TextureFormat)4, false)
				{
					wrapMode = (TextureWrapMode)0,
					filterMode = (FilterMode)1
				};
				Color[] array = (Color[])(object)new Color[num];
				for (int i = 0; i < num; i++)
				{
					array[i] = (Color)((i < 6) ? Color.white : new Color(1f, 1f, 1f, 0f));
				}
				_dashTexture.SetPixels(array);
				_dashTexture.Apply();
			}
		}

		private void ApplyStyleIfChanged()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: 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_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: 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_00db: 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_003a: 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_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)
			float value = RelocatePlugin.LineWidth.Value;
			Color value2 = RelocatePlugin.TrailColor.Value;
			Color value3 = RelocatePlugin.RingColor.Value;
			float value4 = RelocatePlugin.DashLength.Value;
			if (!Mathf.Approximately(value, _lastWidth) || !(value2 == _lastTrail) || !(value3 == _lastRing) || !Mathf.Approximately(value4, _lastDashLength))
			{
				_lastWidth = value;
				_lastTrail = value2;
				_lastRing = value3;
				_lastDashLength = value4;
				_dashLine.widthMultiplier = value;
				_dashLine.startColor = value2;
				_dashLine.endColor = value2;
				_originRing.widthMultiplier = value;
				_originRing.startColor = value3;
				_originRing.endColor = value3;
				_ghostRing.widthMultiplier = value;
				_ghostRing.startColor = value3;
				_ghostRing.endColor = value3;
			}
		}

		private void SetVisible(bool visible)
		{
			if ((Object)(object)_dashLine != (Object)null)
			{
				((Renderer)_dashLine).enabled = visible;
			}
			if ((Object)(object)_originRing != (Object)null)
			{
				((Renderer)_originRing).enabled = visible;
			}
			if ((Object)(object)_ghostRing != (Object)null)
			{
				((Renderer)_ghostRing).enabled = visible;
			}
		}
	}
	internal static class SourcePieceSuppression
	{
		private static readonly List<Collider> DisabledColliders = new List<Collider>();

		internal static void Suppress(Piece piece)
		{
			Restore();
			if ((Object)(object)piece == (Object)null)
			{
				return;
			}
			Collider[] componentsInChildren = ((Component)piece).GetComponentsInChildren<Collider>(true);
			foreach (Collider val in componentsInChildren)
			{
				if (!((Object)(object)val == (Object)null) && val.enabled)
				{
					val.enabled = false;
					DisabledColliders.Add(val);
				}
			}
		}

		internal static void Restore()
		{
			foreach (Collider disabledCollider in DisabledColliders)
			{
				if ((Object)(object)disabledCollider != (Object)null)
				{
					disabledCollider.enabled = true;
				}
			}
			DisabledColliders.Clear();
		}
	}
	[HarmonyPatch(typeof(Player), "UpdatePlacement")]
	internal static class Player_UpdatePlacement_RelocatePatch
	{
		private static bool Prefix()
		{
			return !RelocateController.IsMoving;
		}
	}
	[HarmonyPatch(typeof(Player), "InPlaceMode")]
	internal static class Player_InPlaceMode_RelocatePatch
	{
		private static bool Prefix(ref bool __result)
		{
			if (RelocateController.IsMoving)
			{
				__result = false;
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(Player), "UpdateBuildGuiInput")]
	internal static class Player_UpdateBuildGuiInput_RelocatePatch
	{
		private static bool Prefix()
		{
			return !RelocateController.IsMoving;
		}
	}
	[HarmonyPatch(typeof(Hud), "TogglePieceSelection")]
	internal static class Hud_TogglePieceSelection_RelocatePatch
	{
		private static bool Prefix()
		{
			return !RelocateController.IsMoving;
		}
	}
	[HarmonyPatch(typeof(Hud), "OnRightClickPiece")]
	internal static class Hud_OnRightClickPiece_RelocatePatch
	{
		private static bool Prefix()
		{
			return !RelocateController.IsMoving;
		}
	}
	internal sealed class VanillaPlacementSession
	{
		private PieceTable _savedBuildPieces;

		private int _savedPlaceRotation;

		private bool _savedNoPlacementCost;

		private GameObject _tableObject;

		private PieceTable _relocateTable;

		internal bool Begin(Player player, GameObject prefab, Quaternion originRotation)
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Expected O, but got Unknown
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)player == (Object)null || (Object)(object)prefab == (Object)null)
			{
				return false;
			}
			Piece component = prefab.GetComponent<Piece>();
			if ((Object)(object)component == (Object)null)
			{
				return false;
			}
			_savedBuildPieces = player.m_buildPieces;
			_savedPlaceRotation = player.m_placeRotation;
			_savedNoPlacementCost = player.m_noPlacementCost;
			_tableObject = new GameObject("PressUToRelocate_VanillaPieceTable");
			Object.DontDestroyOnLoad((Object)(object)_tableObject);
			_relocateTable = _tableObject.AddComponent<PieceTable>();
			_relocateTable.m_pieces = new List<GameObject> { prefab };
			_relocateTable.m_categories = new List<PieceCategory> { component.m_category };
			_relocateTable.m_categoryLabels = new List<string> { "Relocate" };
			_relocateTable.m_availablePieces = new List<List<Piece>>
			{
				new List<Piece> { component }
			};
			_relocateTable.m_selectedCategory = component.m_category;
			_relocateTable.m_selectedPiece = (Vector2Int[])(object)new Vector2Int[1]
			{
				new Vector2Int(0, 0)
			};
			player.m_noPlacementCost = true;
			player.m_buildPieces = _relocateTable;
			player.m_placeRotation = ComputePlaceRotationSteps(component, originRotation, player.m_placeRotationDegrees);
			player.SetupPlacementGhost();
			return (Object)(object)player.m_placementGhost != (Object)null;
		}

		internal void End(Player player)
		{
			if ((Object)(object)player == (Object)null)
			{
				CleanupTable();
				return;
			}
			if ((Object)(object)player.m_placementGhost != (Object)null)
			{
				Object.Destroy((Object)(object)player.m_placementGhost);
				player.m_placementGhost = null;
			}
			player.m_buildPieces = _savedBuildPieces;
			player.m_placeRotation = _savedPlaceRotation;
			player.m_noPlacementCost = _savedNoPlacementCost;
			if ((Object)(object)player.m_buildPieces != (Object)null)
			{
				player.SetupPlacementGhost();
			}
			CleanupTable();
			_relocateTable = null;
		}

		private void CleanupTable()
		{
			if ((Object)(object)_tableObject != (Object)null)
			{
				Object.Destroy((Object)(object)_tableObject);
				_tableObject = null;
			}
		}

		private static int ComputePlaceRotationSteps(Piece piece, Quaternion originRotation, float degreesPerStep)
		{
			//IL_000c: 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_0025: Unknown result type (might be due to invalid IL or missing references)
			if (degreesPerStep < 0.001f)
			{
				return 0;
			}
			float y = ((Quaternion)(ref originRotation)).eulerAngles.y;
			Quaternion rotation = ((Component)piece).transform.rotation;
			return Mathf.RoundToInt(Mathf.DeltaAngle(((Quaternion)(ref rotation)).eulerAngles.y, y) / degreesPerStep);
		}
	}
	internal static class WallPlacement
	{
		internal struct MountContext
		{
			internal float PivotStandoff;

			internal Vector3 BackingNormal;

			internal bool HasMountOffset;
		}

		private const float WallProbeDistance = 0.5f;

		internal const float SurfaceClearance = 0.011f;

		internal static MountContext MeasureMountContext(Piece piece)
		{
			//IL_0025: 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_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//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)
			MountContext result = default(MountContext);
			if ((Object)(object)piece == (Object)null || !TryFindBackingSurface(piece, out var surfacePoint, out var surfaceNormal, out var surfaceCollider, out var _))
			{
				return result;
			}
			surfaceNormal = (result.BackingNormal = ((Vector3)(ref surfaceNormal)).normalized);
			result.PivotStandoff = Vector3.Dot(((Component)piece).transform.position - SurfacePointOnCollider(surfacePoint, surfaceNormal, surfaceCollider), surfaceNormal);
			result.HasMountOffset = result.PivotStandoff > 0.001f;
			return result;
		}

		internal static bool TryFindBackingSurface(Piece piece, out Vector3 surfacePoint, out Vector3 surfaceNormal, out Collider surfaceCollider, out Piece backingPiece)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: 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_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: 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_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: 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_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: 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_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			surfacePoint = Vector3.zero;
			surfaceNormal = Vector3.up;
			surfaceCollider = null;
			backingPiece = null;
			if ((Object)(object)piece == (Object)null)
			{
				return false;
			}
			int mask = LayerMask.GetMask(new string[1] { "piece" });
			Vector3 position = ((Component)piece).transform.position;
			float num = float.MaxValue;
			bool result = false;
			Vector3[] array = (Vector3[])(object)new Vector3[6]
			{
				-((Component)piece).transform.forward,
				((Component)piece).transform.forward,
				-((Component)piece).transform.right,
				((Component)piece).transform.right,
				Vector3.down,
				Vector3.up
			};
			RaycastHit val2 = default(RaycastHit);
			for (int i = 0; i < array.Length; i++)
			{
				Vector3 val = array[i];
				if (((Vector3)(ref val)).sqrMagnitude < 0.001f || !Physics.Raycast(position, ((Vector3)(ref val)).normalized, ref val2, 4f, mask, (QueryTriggerInteraction)1))
				{
					continue;
				}
				Piece componentInParent = ((Component)((RaycastHit)(ref val2)).collider).GetComponentInParent<Piece>();
				if (!((Object)(object)componentInParent == (Object)null) && !((Object)(object)componentInParent == (Object)(object)piece) && ((Component)componentInParent).GetComponentInParent<Hoverable>() == null && !(((RaycastHit)(ref val2)).distance >= num))
				{
					num = ((RaycastHit)(ref val2)).distance;
					Vector3 normal = ((RaycastHit)(ref val2)).normal;
					Vector3 normalized;
					if (!(((Vector3)(ref normal)).sqrMagnitude > 0.001f))
					{
						normalized = ((Vector3)(ref val)).normalized;
					}
					else
					{
						normal = ((RaycastHit)(ref val2)).normal;
						normalized = ((Vector3)(ref normal)).normalized;
					}
					surfaceNormal = normalized;
					surfacePoint = ((RaycastHit)(ref val2)).point;
					surfaceCollider = ((RaycastHit)(ref val2)).collider;
					backingPiece = componentInParent;
					result = true;
				}
			}
			return result;
		}

		internal static Vector3 ResolveWallPosition(GameObject ghost, Vector3 hitPoint, Vector3 surfaceNormal, Quaternion rotation, Collider hitCollider, MountContext mountContext)
		{
			//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_0009: 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_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_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: 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_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: 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_005b: 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)
			if ((Object)(object)ghost == (Object)null)
			{
				return hitPoint + ((Vector3)(ref surfaceNormal)).normalized * 0.011f;
			}
			surfaceNormal = ((Vector3)(ref surfaceNormal)).normalized;
			Vector3 val = (((Object)(object)hitCollider != (Object)null) ? SurfacePointOnCollider(hitPoint, surfaceNormal, hitCollider) : hitPoint);
			Vector3 position;
			Vector3 val2 = ((!ColliderPlacement.TryResolve(ghost, val, surfaceNormal, rotation, out position)) ? val : position);
			return val2 + surfaceNormal * 0.011f;
		}

		internal static Vector3 SurfacePointOnCollider(Vector3 hitPoint, Vector3 surfaceNormal, Collider hitCollider)
		{
			//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_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)hitCollider == (Object)null)
			{
				return hitPoint;
			}
			return hitCollider.ClosestPoint(hitPoint - surfaceNormal * 0.5f);
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}