Decompiled source of MovingDay v1.0.7

MovingDay.dll

Decompiled 5 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace MovingDay;

[BepInPlugin("com.drakosdj.movingday", "MovingDay", "1.0.7")]
public class MovingDayPlugin : BaseUnityPlugin
{
	public class SelectedPieceInfo
	{
		public Piece piece;

		public ZDO zdo;

		public Vector3 relPos;

		public Quaternion relRot;

		public string prefabName;
	}

	[HarmonyPatch(typeof(Chat), "InputText")]
	public static class Chat_InputText_Patch
	{
		public static bool Prefix(Chat __instance)
		{
			string chatText = GetChatText(__instance);
			if (string.IsNullOrEmpty(chatText))
			{
				return true;
			}
			if (chatText.StartsWith("/movingdayclean") || chatText.StartsWith("/mdclean"))
			{
				string[] array = chatText.Split(new char[1] { ' ' });
				float radius = 150f;
				if (array.Length > 1 && float.TryParse(array[1], out var result))
				{
					radius = result;
				}
				CleanWorldOrigin(radius);
				object inputField = GetInputField(__instance);
				if (inputField != null)
				{
					PropertyInfo property = inputField.GetType().GetProperty("text");
					if (property != null)
					{
						property.SetValue(inputField, "", null);
					}
				}
				return false;
			}
			return true;
		}
	}

	[HarmonyPatch(typeof(Player), "UpdatePlacement")]
	public static class Player_UpdatePlacement_Patch
	{
		public static bool Prefix()
		{
			if (m_inMoveMode)
			{
				return false;
			}
			return true;
		}
	}

	[HarmonyPatch(typeof(WearNTear), "HaveSupport")]
	public static class WearNTear_HaveSupport_Patch
	{
		public static bool Prefix(WearNTear __instance, ref bool __result)
		{
			if (IsRecentlyMoved(__instance))
			{
				__result = true;
				return false;
			}
			return true;
		}
	}

	private delegate bool FindClosestSnapPointsDelegate(Player player, Transform ghost, float maxSnapDistance, out Transform a, out Transform b, List<Piece> pieces);

	[HarmonyPatch(typeof(Player), "UpdatePlacementGhost")]
	public static class Player_UpdatePlacementGhost_Patch
	{
		public static bool Prefix()
		{
			if (m_inMoveMode)
			{
				return false;
			}
			return true;
		}

		public static void Postfix(Player __instance)
		{
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: 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_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			GameObject field = GetField<GameObject>(__instance, "m_placementGhost");
			if ((Object)(object)field == (Object)null)
			{
				return;
			}
			Transform a = null;
			Transform b = null;
			m_myTempPieces.Clear();
			if (!FindClosestSnapPoints(__instance, field.transform, 0.5f, out a, out b, m_myTempPieces) || !((Object)(object)a != (Object)null) || !((Object)(object)b != (Object)null) || !(Vector3.Distance(a.position, b.position) < 0.05f))
			{
				return;
			}
			Piece componentInParent = ((Component)b).GetComponentInParent<Piece>();
			if ((Object)(object)componentInParent != (Object)null)
			{
				Quaternion rotation = ((Component)componentInParent).transform.rotation;
				float y = ((Quaternion)(ref rotation)).eulerAngles.y;
				float num = Mathf.Round(y / 22.5f) * 22.5f;
				float num2 = y - num;
				if (Mathf.Abs(num2) > 0.01f)
				{
					rotation = field.transform.rotation;
					Vector3 eulerAngles = ((Quaternion)(ref rotation)).eulerAngles;
					Quaternion rotation2 = Quaternion.Euler(eulerAngles.x, eulerAngles.y + num2, eulerAngles.z);
					field.transform.rotation = rotation2;
					Vector3 position = b.position - a.position + field.transform.position;
					field.transform.position = position;
				}
			}
		}
	}

	public static ConfigEntry<KeyboardShortcut> configSelectHotkey;

	public static ConfigEntry<KeyboardShortcut> configSelectConnectedHotkey;

	public static ConfigEntry<KeyboardShortcut> configMoveHotkey;

	public static ConfigEntry<KeyboardShortcut> configModifierKey;

	public static ConfigEntry<float> configConnectionRadius;

	public static ConfigEntry<string> configPlayerSafety;

	public static ConfigEntry<string> configChestSafety;

	public static ConfigEntry<bool> configMoveTamed;

	public static ConfigEntry<float> configTerrainRadiusBuffer;

	public static ConfigEntry<string> configContainerMetalAction;

	public static ConfigEntry<string> configPlayerMetalAction;

	public static ConfigEntry<KeyboardShortcut> configHeightUpHotkey;

	public static ConfigEntry<KeyboardShortcut> configHeightDownHotkey;

	public static ConfigEntry<KeyboardShortcut> configHeightResetHotkey;

	public static Piece m_pivotPiece = null;

	public static Vector3 m_oldPivotPos;

	public static float m_oldPivotYaw;

	public static bool m_inMoveMode = false;

	public static float m_targetYaw = 0f;

	public static float m_maxSelectedDistance = 5f;

	public static bool m_lastCopyTerrainState = false;

	public static float m_sourceHeightOffset = 0f;

	public static float m_sourceHeightOffsetActual = 0f;

	public static float m_additionalHeightOffset = 0f;

	public static MovingDayPlugin instance;

	private static float m_debugLogTimer = 0f;

	public static List<SelectedPieceInfo> m_selectedPieceInfos = new List<SelectedPieceInfo>();

	public static Dictionary<WearNTear, float> m_recentlyMovedPieces = new Dictionary<WearNTear, float>();

	private static List<Piece> m_myTempPieces = new List<Piece>();

	private static FindClosestSnapPointsDelegate m_findClosestSnapPoints = null;

	public static bool IsRecentlyMoved(WearNTear wear)
	{
		if ((Object)(object)wear == (Object)null)
		{
			return false;
		}
		float time = Time.time;
		if (m_recentlyMovedPieces.TryGetValue(wear, out var value))
		{
			if (time < value)
			{
				return true;
			}
			m_recentlyMovedPieces.Remove(wear);
		}
		return false;
	}

	private static void PruneRecentlyMoved()
	{
		float time = Time.time;
		List<WearNTear> list = new List<WearNTear>();
		foreach (KeyValuePair<WearNTear, float> recentlyMovedPiece in m_recentlyMovedPieces)
		{
			if ((Object)(object)recentlyMovedPiece.Key == (Object)null || time >= recentlyMovedPiece.Value)
			{
				list.Add(recentlyMovedPiece.Key);
			}
		}
		foreach (WearNTear item in list)
		{
			if ((Object)(object)item != (Object)null)
			{
				m_recentlyMovedPieces.Remove(item);
			}
		}
	}

	private void Awake()
	{
		//IL_001f: 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_0077: 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_01cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_022b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0244: Unknown result type (might be due to invalid IL or missing references)
		//IL_024a: Expected O, but got Unknown
		instance = this;
		configSelectHotkey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Keybinds", "SelectHotkey", new KeyboardShortcut((KeyCode)103, (KeyCode[])(object)new KeyCode[0]), "Hotkey to select/deselect a hovered piece.");
		configSelectConnectedHotkey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Keybinds", "SelectConnectedHotkey", new KeyboardShortcut((KeyCode)104, (KeyCode[])(object)new KeyCode[0]), "Hotkey to select all connected pieces of a structure.");
		configMoveHotkey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Keybinds", "MoveHotkey", new KeyboardShortcut((KeyCode)108, (KeyCode[])(object)new KeyCode[0]), "Hotkey to enter Move Mode once pieces are selected.");
		configModifierKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Keybinds", "TerrainModifierKey", new KeyboardShortcut((KeyCode)306, (KeyCode[])(object)new KeyCode[0]), "Modifier key held during placement to copy and revert terrain modifications.");
		configConnectionRadius = ((BaseUnityPlugin)this).Config.Bind<float>("General", "ConnectionRadius", 2f, "Maximum distance between pieces to consider them connected in BFS selection.");
		configPlayerSafety = ((BaseUnityPlugin)this).Config.Bind<string>("Safety", "PlayerSafetyAction", "Block", "Action when other players are in the footprint. Options: Block, Teleport, Ignore");
		configChestSafety = ((BaseUnityPlugin)this).Config.Bind<string>("Safety", "ChestSafetyAction", "Block", "Action when containers are in use. Options: Block, Ignore");
		configMoveTamed = ((BaseUnityPlugin)this).Config.Bind<bool>("Safety", "MoveTamedAnimals", true, "If true, tamed animals inside the building footprint will be moved to the new location.");
		configTerrainRadiusBuffer = ((BaseUnityPlugin)this).Config.Bind<float>("General", "TerrainRadiusBuffer", 3f, "Extra radius in meters to capture terrain modifications around the structure footprint.");
		configContainerMetalAction = ((BaseUnityPlugin)this).Config.Bind<string>("Safety", "ContainerMetalAction", "Block", "Controls behavior when chests/carts contain non-teleportable materials. Options: Allow, Block, Drop");
		configPlayerMetalAction = ((BaseUnityPlugin)this).Config.Bind<string>("Safety", "PlayerMetalAction", "BlockMove", "Controls behavior if a player is standing inside the structure footprint carrying metals. Options: Allow, BlockMove, LeaveBehind");
		configHeightUpHotkey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Keybinds", "HeightUpHotkey", new KeyboardShortcut((KeyCode)273, (KeyCode[])(object)new KeyCode[0]), "Hotkey to raise the structure height in Move Mode.");
		configHeightDownHotkey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Keybinds", "HeightDownHotkey", new KeyboardShortcut((KeyCode)274, (KeyCode[])(object)new KeyCode[0]), "Hotkey to lower the structure height in Move Mode.");
		configHeightResetHotkey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Keybinds", "HeightResetHotkey", new KeyboardShortcut((KeyCode)278, (KeyCode[])(object)new KeyCode[0]), "Hotkey to reset structure height adjustment (Home snaps to ground, Shift + Home restores original offset).");
		Harmony val = new Harmony("com.drakosdj.movingday");
		val.PatchAll();
		Debug.Log((object)"[MovingDay] Standalone plugin loaded successfully!");
	}

	private void Start()
	{
		TryLinkSharedSelection();
	}

	private void TryLinkSharedSelection()
	{
		try
		{
			Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
			foreach (Assembly assembly in assemblies)
			{
				if (!(assembly.GetName().Name == "PrefabHammer"))
				{
					continue;
				}
				Type type = assembly.GetType("PrefabHammer.PrefabHammerPlugin");
				if (type != null)
				{
					FieldInfo field = type.GetField("m_selectedPieces", BindingFlags.Static | BindingFlags.Public);
					if (field != null && field.GetValue(null) is HashSet<Piece> selectedPieces)
					{
						MovingDaySelection.m_selectedPieces = selectedPieces;
						Debug.Log((object)"[MovingDay] Successfully linked to PrefabHammer selection HashSet!");
					}
				}
				break;
			}
		}
		catch (Exception ex)
		{
			Debug.LogWarning((object)("[MovingDay] Failed to link shared selection with PrefabHammer: " + ex.Message));
		}
	}

	private void Update()
	{
		PruneRecentlyMoved();
		if ((Object)(object)Player.m_localPlayer == (Object)null)
		{
			if (m_inMoveMode)
			{
				Debug.Log((object)"[MovingDay Diag] Update: player is null, canceling Move Mode");
				CancelMove();
			}
			MovingDaySelection.ClearSelection();
		}
		else if (m_inMoveMode)
		{
			UpdateMoveMode(Player.m_localPlayer);
		}
		else if (!IsHoldingBuildTool(Player.m_localPlayer))
		{
			HideSelectionHighlights();
		}
		else
		{
			RestoreAndHighlightSelection(Player.m_localPlayer);
			HandleSelectionInput(Player.m_localPlayer);
		}
	}

	private static void HideSelectionHighlights()
	{
		foreach (Piece selectedPiece in MovingDaySelection.m_selectedPieces)
		{
			if ((Object)(object)selectedPiece != (Object)null)
			{
				MovingDaySelectionHighlight component = ((Component)selectedPiece).GetComponent<MovingDaySelectionHighlight>();
				if ((Object)(object)component != (Object)null)
				{
					Object.Destroy((Object)(object)component);
				}
				Component component2 = ((Component)selectedPiece).GetComponent("PrefabSelectionHighlight");
				if ((Object)(object)component2 != (Object)null)
				{
					Object.Destroy((Object)(object)component2);
				}
			}
		}
		MovingDaySelection.m_selectedPieces.Clear();
	}

	private static void RestoreAndHighlightSelection(Player player)
	{
		//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00df: Unknown result type (might be due to invalid IL or missing references)
		if (MovingDaySelection.m_selectedZDOIDs.Count == 0)
		{
			if (MovingDaySelection.m_selectedPieces.Count > 0)
			{
				MovingDaySelection.m_selectedPieces.Clear();
			}
			return;
		}
		MovingDaySelection.m_selectedPieces.RemoveWhere((Piece p) => (Object)(object)p == (Object)null);
		List<Piece> allPieces = MovingDaySelection.GetAllPieces();
		foreach (Piece item in allPieces)
		{
			if ((Object)(object)item == (Object)null)
			{
				continue;
			}
			ZNetView component = ((Component)item).GetComponent<ZNetView>();
			if (!((Object)(object)component != (Object)null) || !component.IsValid())
			{
				continue;
			}
			ZDO zDO = component.GetZDO();
			if (zDO == null)
			{
				continue;
			}
			ZDOID uid = zDO.m_uid;
			if (MovingDaySelection.m_selectedZDOIDs.Contains(uid))
			{
				if (!MovingDaySelection.m_selectedPieces.Contains(item))
				{
					MovingDaySelection.m_selectedPieces.Add(item);
				}
				if ((Object)(object)((Component)item).GetComponent<MovingDaySelectionHighlight>() == (Object)null)
				{
					((Component)item).gameObject.AddComponent<MovingDaySelectionHighlight>();
				}
			}
		}
	}

	private static bool IsHoldingBuildTool(Player player)
	{
		ItemData rightItem = GetRightItem(player);
		return rightItem != null && (Object)(object)rightItem.m_shared.m_buildPieces != (Object)null;
	}

	private static GameObject ZNetScene_CreateObject(ZDO zdo)
	{
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Expected O, but got Unknown
		if ((Object)(object)ZNetScene.instance == (Object)null)
		{
			return null;
		}
		MethodInfo method = typeof(ZNetScene).GetMethod("CreateObject", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
		if (method != null)
		{
			return (GameObject)method.Invoke(ZNetScene.instance, new object[1] { zdo });
		}
		return null;
	}

	private static bool PlayerCanTakeInput(Player player)
	{
		if ((Object)(object)player == (Object)null)
		{
			return false;
		}
		MethodInfo method = typeof(Character).GetMethod("TakeInput", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
		if (method != null)
		{
			return (bool)method.Invoke(player, null);
		}
		return true;
	}

	private static bool MyGetKey(KeyCode key)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Invalid comparison between Unknown and I4
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Invalid comparison between Unknown and I4
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Invalid comparison between Unknown and I4
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: Invalid comparison between Unknown and I4
		//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00af: Invalid comparison between Unknown and I4
		//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cc: Invalid comparison between Unknown and I4
		//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ec: Invalid comparison between Unknown and I4
		//IL_0106: Unknown result type (might be due to invalid IL or missing references)
		//IL_010c: Invalid comparison between Unknown and I4
		//IL_0126: Unknown result type (might be due to invalid IL or missing references)
		//IL_012c: Invalid comparison between Unknown and I4
		//IL_0143: Unknown result type (might be due to invalid IL or missing references)
		//IL_0149: Invalid comparison between Unknown and I4
		//IL_0160: Unknown result type (might be due to invalid IL or missing references)
		//IL_0166: Invalid comparison between Unknown and I4
		//IL_017d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0183: Invalid comparison between Unknown and I4
		if (ZInput.GetKey(key, true))
		{
			return true;
		}
		try
		{
			Keyboard current = Keyboard.current;
			if (current != null)
			{
				if ((int)key == 280)
				{
					return ((ButtonControl)current.pageUpKey).isPressed;
				}
				if ((int)key == 281)
				{
					return ((ButtonControl)current.pageDownKey).isPressed;
				}
				if ((int)key == 273)
				{
					return ((ButtonControl)current.upArrowKey).isPressed;
				}
				if ((int)key == 274)
				{
					return ((ButtonControl)current.downArrowKey).isPressed;
				}
				if ((int)key == 278)
				{
					return ((ButtonControl)current.homeKey).isPressed;
				}
				if ((int)key == 27)
				{
					return ((ButtonControl)current.escapeKey).isPressed;
				}
				if ((int)key == 304)
				{
					return ((ButtonControl)current.leftShiftKey).isPressed;
				}
				if ((int)key == 303)
				{
					return ((ButtonControl)current.rightShiftKey).isPressed;
				}
				if ((int)key == 306)
				{
					return ((ButtonControl)current.leftCtrlKey).isPressed;
				}
				if ((int)key == 305)
				{
					return ((ButtonControl)current.rightCtrlKey).isPressed;
				}
				if ((int)key == 308)
				{
					return ((ButtonControl)current.leftAltKey).isPressed;
				}
				if ((int)key == 307)
				{
					return ((ButtonControl)current.rightAltKey).isPressed;
				}
			}
		}
		catch (Exception)
		{
		}
		return false;
	}

	private static bool MyGetKeyDown(KeyCode key)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Invalid comparison between Unknown and I4
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Invalid comparison between Unknown and I4
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Invalid comparison between Unknown and I4
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: Invalid comparison between Unknown and I4
		//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00af: Invalid comparison between Unknown and I4
		//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cc: Invalid comparison between Unknown and I4
		//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ec: Invalid comparison between Unknown and I4
		//IL_0106: Unknown result type (might be due to invalid IL or missing references)
		//IL_010c: Invalid comparison between Unknown and I4
		//IL_0126: Unknown result type (might be due to invalid IL or missing references)
		//IL_012c: Invalid comparison between Unknown and I4
		//IL_0143: Unknown result type (might be due to invalid IL or missing references)
		//IL_0149: Invalid comparison between Unknown and I4
		//IL_0160: Unknown result type (might be due to invalid IL or missing references)
		//IL_0166: Invalid comparison between Unknown and I4
		//IL_017d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0183: Invalid comparison between Unknown and I4
		if (ZInput.GetKeyDown(key, true))
		{
			return true;
		}
		try
		{
			Keyboard current = Keyboard.current;
			if (current != null)
			{
				if ((int)key == 280)
				{
					return ((ButtonControl)current.pageUpKey).wasPressedThisFrame;
				}
				if ((int)key == 281)
				{
					return ((ButtonControl)current.pageDownKey).wasPressedThisFrame;
				}
				if ((int)key == 273)
				{
					return ((ButtonControl)current.upArrowKey).wasPressedThisFrame;
				}
				if ((int)key == 274)
				{
					return ((ButtonControl)current.downArrowKey).wasPressedThisFrame;
				}
				if ((int)key == 278)
				{
					return ((ButtonControl)current.homeKey).wasPressedThisFrame;
				}
				if ((int)key == 27)
				{
					return ((ButtonControl)current.escapeKey).wasPressedThisFrame;
				}
				if ((int)key == 304)
				{
					return ((ButtonControl)current.leftShiftKey).wasPressedThisFrame;
				}
				if ((int)key == 303)
				{
					return ((ButtonControl)current.rightShiftKey).wasPressedThisFrame;
				}
				if ((int)key == 306)
				{
					return ((ButtonControl)current.leftCtrlKey).wasPressedThisFrame;
				}
				if ((int)key == 305)
				{
					return ((ButtonControl)current.rightCtrlKey).wasPressedThisFrame;
				}
				if ((int)key == 308)
				{
					return ((ButtonControl)current.leftAltKey).wasPressedThisFrame;
				}
				if ((int)key == 307)
				{
					return ((ButtonControl)current.rightAltKey).wasPressedThisFrame;
				}
			}
		}
		catch (Exception)
		{
		}
		return false;
	}

	private void HandleSelectionInput(Player player)
	{
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_035b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0360: Unknown result type (might be due to invalid IL or missing references)
		//IL_0364: Unknown result type (might be due to invalid IL or missing references)
		//IL_04ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_04b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0aa7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0aac: Unknown result type (might be due to invalid IL or missing references)
		//IL_0abd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0ac2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0ac6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0ad5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0ada: Unknown result type (might be due to invalid IL or missing references)
		//IL_0adc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0ade: Unknown result type (might be due to invalid IL or missing references)
		//IL_0ae3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0aef: Unknown result type (might be due to invalid IL or missing references)
		//IL_0af4: Unknown result type (might be due to invalid IL or missing references)
		//IL_0af8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0b04: Unknown result type (might be due to invalid IL or missing references)
		//IL_0b06: Unknown result type (might be due to invalid IL or missing references)
		//IL_0bb2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0bba: Unknown result type (might be due to invalid IL or missing references)
		//IL_0bbf: Unknown result type (might be due to invalid IL or missing references)
		//IL_0bc1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0bc6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0bcb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0bd6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0bdb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0bdf: Unknown result type (might be due to invalid IL or missing references)
		//IL_0bf3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0bf8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0bfc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0c11: Unknown result type (might be due to invalid IL or missing references)
		//IL_0c16: Unknown result type (might be due to invalid IL or missing references)
		//IL_0c1a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0c24: Unknown result type (might be due to invalid IL or missing references)
		//IL_0c29: Unknown result type (might be due to invalid IL or missing references)
		//IL_0cc7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0cd2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0804: Unknown result type (might be due to invalid IL or missing references)
		//IL_0809: Unknown result type (might be due to invalid IL or missing references)
		//IL_0810: Unknown result type (might be due to invalid IL or missing references)
		//IL_0d77: Unknown result type (might be due to invalid IL or missing references)
		//IL_0d8d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0dde: Unknown result type (might be due to invalid IL or missing references)
		//IL_0e1a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0dc7: Unknown result type (might be due to invalid IL or missing references)
		//IL_08bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_08bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_0a57: Unknown result type (might be due to invalid IL or missing references)
		if (!PlayerCanTakeInput(player))
		{
			return;
		}
		KeyboardShortcut value;
		Piece hoveringPiece;
		if (configSelectHotkey != null)
		{
			value = configSelectHotkey.Value;
			KeyCode mainKey = ((KeyboardShortcut)(ref value)).MainKey;
			if (MyGetKeyDown(mainKey))
			{
				if (MyGetKey((KeyCode)304) || MyGetKey((KeyCode)303) || MyGetKey((KeyCode)306) || MyGetKey((KeyCode)305))
				{
					if (MovingDaySelection.m_selectedZDOIDs.Count > 0 || MovingDaySelection.m_selectedPieces.Count > 0)
					{
						MovingDaySelection.ClearSelection();
						((Character)player).Message((MessageType)2, "Cleared selection.", 0, (Sprite)null);
					}
				}
				else
				{
					hoveringPiece = GetHoveringPiece(player);
					if ((Object)(object)hoveringPiece != (Object)null)
					{
						if (!hoveringPiece.IsPlacedByPlayer())
						{
							((Character)player).Message((MessageType)2, "Cannot select world-generated structures.", 0, (Sprite)null);
							return;
						}
						if (MovingDaySelection.m_selectedPieces.Contains(hoveringPiece))
						{
							MovingDaySelection.RemoveFromSelection(hoveringPiece);
							((Character)player).Message((MessageType)2, "Deselected piece (Total: " + MovingDaySelection.m_selectedPieces.Count + ")", 0, (Sprite)null);
						}
						else
						{
							MovingDaySelection.AddToSelection(hoveringPiece);
							((Character)player).Message((MessageType)2, "Selected piece (Total: " + MovingDaySelection.m_selectedPieces.Count + ")", 0, (Sprite)null);
						}
					}
					else if (MovingDaySelection.m_selectedZDOIDs.Count > 0)
					{
						MovingDaySelection.ClearSelection();
						((Character)player).Message((MessageType)2, "Cleared selection.", 0, (Sprite)null);
					}
					else
					{
						((Character)player).Message((MessageType)2, "No piece hovered to select.", 0, (Sprite)null);
					}
				}
			}
		}
		if (configSelectConnectedHotkey != null)
		{
			value = configSelectConnectedHotkey.Value;
			KeyCode mainKey = ((KeyboardShortcut)(ref value)).MainKey;
			if (MyGetKeyDown(mainKey))
			{
				if (MyGetKey((KeyCode)304) || MyGetKey((KeyCode)303) || MyGetKey((KeyCode)306) || MyGetKey((KeyCode)305))
				{
					if (MovingDaySelection.m_selectedZDOIDs.Count > 0 || MovingDaySelection.m_selectedPieces.Count > 0)
					{
						MovingDaySelection.ClearSelection();
						((Character)player).Message((MessageType)2, "Cleared selection.", 0, (Sprite)null);
					}
				}
				else
				{
					hoveringPiece = GetHoveringPiece(player);
					if ((Object)(object)hoveringPiece != (Object)null)
					{
						if (!hoveringPiece.IsPlacedByPlayer())
						{
							((Character)player).Message((MessageType)2, "Cannot select world-generated structures.", 0, (Sprite)null);
							return;
						}
						((Character)player).Message((MessageType)2, "Selecting structure...", 0, (Sprite)null);
						MovingDaySelection.SelectConnected(hoveringPiece, configConnectionRadius.Value);
						((Character)player).Message((MessageType)2, "Selected structure of " + MovingDaySelection.m_selectedPieces.Count + " pieces.", 0, (Sprite)null);
					}
					else if (MovingDaySelection.m_selectedZDOIDs.Count > 0)
					{
						MovingDaySelection.ClearSelection();
						((Character)player).Message((MessageType)2, "Cleared selection.", 0, (Sprite)null);
					}
					else
					{
						((Character)player).Message((MessageType)2, "No piece hovered to select structure.", 0, (Sprite)null);
					}
				}
			}
		}
		if (configMoveHotkey == null)
		{
			return;
		}
		value = configMoveHotkey.Value;
		if (!MyGetKeyDown(((KeyboardShortcut)(ref value)).MainKey))
		{
			return;
		}
		if (MovingDaySelection.m_selectedPieces.Count == 0)
		{
			((Character)player).Message((MessageType)2, "No pieces selected to move.", 0, (Sprite)null);
			return;
		}
		hoveringPiece = GetHoveringPiece(player);
		if ((Object)(object)hoveringPiece != (Object)null && MovingDaySelection.m_selectedPieces.Contains(hoveringPiece))
		{
			m_pivotPiece = hoveringPiece;
		}
		else
		{
			foreach (Piece selectedPiece in MovingDaySelection.m_selectedPieces)
			{
				if ((Object)(object)selectedPiece != (Object)null)
				{
					m_pivotPiece = selectedPiece;
					break;
				}
			}
		}
		if ((Object)(object)m_pivotPiece == (Object)null)
		{
			return;
		}
		List<Player> allPlayers = Player.GetAllPlayers();
		foreach (Player item in allPlayers)
		{
			if ((Object)(object)item == (Object)null)
			{
				continue;
			}
			bool flag = false;
			foreach (Piece selectedPiece2 in MovingDaySelection.m_selectedPieces)
			{
				if ((Object)(object)selectedPiece2 != (Object)null && Vector3.Distance(((Component)item).transform.position, ((Component)selectedPiece2).transform.position) < 3f)
				{
					flag = true;
					break;
				}
			}
			if (!flag)
			{
				continue;
			}
			bool flag2 = PlayerHasNonTeleportable(item);
			string value2 = configPlayerMetalAction.Value;
			string value3 = configPlayerSafety.Value;
			if (flag2 && value2.Equals("BlockMove", StringComparison.OrdinalIgnoreCase))
			{
				if ((Object)(object)item == (Object)(object)Player.m_localPlayer)
				{
					((Character)player).Message((MessageType)2, "Cannot move: You are carrying non-teleportable items.", 0, (Sprite)null);
				}
				else
				{
					((Character)player).Message((MessageType)2, "Cannot move: Player '" + item.GetPlayerName() + "' is carrying non-teleportable items.", 0, (Sprite)null);
				}
				return;
			}
			if ((Object)(object)item == (Object)(object)Player.m_localPlayer && value3.Equals("Block", StringComparison.OrdinalIgnoreCase))
			{
				((Character)player).Message((MessageType)2, "Cannot move: You are inside the building.", 0, (Sprite)null);
				return;
			}
			if (!((Object)(object)item != (Object)(object)Player.m_localPlayer) || (!value3.Equals("Block", StringComparison.OrdinalIgnoreCase) && !value3.Equals("Teleport", StringComparison.OrdinalIgnoreCase)))
			{
				continue;
			}
			((Character)player).Message((MessageType)2, "Cannot move: Player '" + item.GetPlayerName() + "' is inside.", 0, (Sprite)null);
			return;
		}
		foreach (Piece selectedPiece3 in MovingDaySelection.m_selectedPieces)
		{
			if ((Object)(object)selectedPiece3 == (Object)null)
			{
				continue;
			}
			Container component = ((Component)selectedPiece3).GetComponent<Container>();
			if (!((Object)(object)component != (Object)null))
			{
				continue;
			}
			if (configChestSafety.Value.Equals("Block", StringComparison.OrdinalIgnoreCase) && component.IsInUse())
			{
				((Character)player).Message((MessageType)2, "Cannot move: A container is currently open/in use.", 0, (Sprite)null);
				return;
			}
			if (ContainerHasNonTeleportable(component))
			{
				string value4 = configContainerMetalAction.Value;
				if (value4.Equals("Block", StringComparison.OrdinalIgnoreCase))
				{
					((Character)player).Message((MessageType)2, "Cannot move: Chest contains non-teleportable items.", 0, (Sprite)null);
					return;
				}
			}
		}
		if (configContainerMetalAction.Value.Equals("Drop", StringComparison.OrdinalIgnoreCase))
		{
			Vector3 val = default(Vector3);
			foreach (Piece selectedPiece4 in MovingDaySelection.m_selectedPieces)
			{
				if ((Object)(object)selectedPiece4 == (Object)null)
				{
					continue;
				}
				Container component = ((Component)selectedPiece4).GetComponent<Container>();
				if (!((Object)(object)component != (Object)null) || !ContainerHasNonTeleportable(component))
				{
					continue;
				}
				GameObject prefab = ZNetScene.instance.GetPrefab("CargoCrate");
				if (!((Object)(object)prefab != (Object)null))
				{
					continue;
				}
				Vector3 position = ((Component)selectedPiece4).transform.position;
				float groundHeight = ZoneSystem.instance.GetGroundHeight(position);
				Inventory inventory = component.GetInventory();
				List<ItemData> list = new List<ItemData>();
				foreach (ItemData allItem in inventory.GetAllItems())
				{
					if (allItem != null && !allItem.m_shared.m_teleportable)
					{
						list.Add(allItem);
					}
				}
				int num = 0;
				while (list.Count > 0 && num < 10)
				{
					((Vector3)(ref val))..ctor(position.x, groundHeight + 0.5f + (float)num * 0.4f, position.z);
					GameObject val2 = Object.Instantiate<GameObject>(prefab, val, Quaternion.identity);
					Container component2 = val2.GetComponent<Container>();
					if ((Object)(object)component2 == (Object)null)
					{
						Object.Destroy((Object)(object)val2);
						break;
					}
					Inventory inventory2 = component2.GetInventory();
					List<ItemData> list2 = new List<ItemData>();
					foreach (ItemData item2 in list)
					{
						int stack = item2.m_stack;
						inventory2.MoveItemToThis(inventory, item2);
						if (!inventory.ContainsItem(item2) || item2.m_stack < stack)
						{
							list2.Add(item2);
						}
					}
					SaveContainer(component2);
					num++;
					list.Clear();
					foreach (ItemData allItem2 in inventory.GetAllItems())
					{
						if (allItem2 != null && !allItem2.m_shared.m_teleportable)
						{
							list.Add(allItem2);
						}
					}
					if (list2.Count == 0)
					{
						break;
					}
				}
				SaveContainer(component);
				Debug.Log((object)("[MovingDay Debug] Spawned " + num + " CargoCrate(s) and dropped all non-teleportable items from chest at " + position));
			}
		}
		m_selectedPieceInfos.Clear();
		Vector3 position2 = ((Component)m_pivotPiece).transform.position;
		Quaternion rotation = ((Component)m_pivotPiece).transform.rotation;
		Quaternion val3 = Quaternion.Euler(0f, ((Quaternion)(ref rotation)).eulerAngles.y, 0f);
		Quaternion val4 = Quaternion.Inverse(val3);
		rotation = ((Component)m_pivotPiece).transform.rotation;
		float y = ((Quaternion)(ref rotation)).eulerAngles.y;
		m_oldPivotPos = position2;
		m_oldPivotYaw = y;
		foreach (Piece selectedPiece5 in MovingDaySelection.m_selectedPieces)
		{
			if (!((Object)(object)selectedPiece5 != (Object)null))
			{
				continue;
			}
			ZNetView component3 = ((Component)selectedPiece5).GetComponent<ZNetView>();
			if ((Object)(object)component3 != (Object)null && component3.IsValid())
			{
				ZDO zDO = component3.GetZDO();
				if (zDO != null)
				{
					component3.ClaimOwnership();
					zDO.SetOwner(ZDOMan.GetSessionID());
					SelectedPieceInfo selectedPieceInfo = new SelectedPieceInfo();
					selectedPieceInfo.piece = selectedPiece5;
					selectedPieceInfo.zdo = zDO;
					selectedPieceInfo.relPos = val4 * (((Component)selectedPiece5).transform.position - position2);
					rotation = ((Component)selectedPiece5).transform.rotation;
					float y2 = ((Quaternion)(ref rotation)).eulerAngles.y;
					rotation = ((Component)selectedPiece5).transform.rotation;
					float x = ((Quaternion)(ref rotation)).eulerAngles.x;
					float num2 = y2 - y;
					rotation = ((Component)selectedPiece5).transform.rotation;
					selectedPieceInfo.relRot = Quaternion.Euler(x, num2, ((Quaternion)(ref rotation)).eulerAngles.z);
					selectedPieceInfo.prefabName = ((Object)selectedPiece5).name;
					m_selectedPieceInfos.Add(selectedPieceInfo);
				}
			}
		}
		Debug.Log((object)("[MovingDay] Populated m_selectedPieceInfos: count=" + m_selectedPieceInfos.Count));
		float num3 = 5f;
		foreach (Piece selectedPiece6 in MovingDaySelection.m_selectedPieces)
		{
			if ((Object)(object)selectedPiece6 != (Object)null)
			{
				float num4 = Vector3.Distance(((Component)m_pivotPiece).transform.position, ((Component)selectedPiece6).transform.position);
				if (num4 > num3)
				{
					num3 = num4;
				}
			}
		}
		m_maxSelectedDistance = num3 + configTerrainRadiusBuffer.Value;
		m_inMoveMode = true;
		m_targetYaw = 0f;
		m_additionalHeightOffset = 0f;
		m_lastCopyTerrainState = false;
		GameObject field = GetField<GameObject>(player, "m_placementGhost");
		if ((Object)(object)field != (Object)null)
		{
			field.SetActive(false);
		}
		float baseHeight = MovingDayTerrain.GetBaseHeight(((Component)m_pivotPiece).transform.position);
		m_sourceHeightOffset = ((Component)m_pivotPiece).transform.position.y - baseHeight;
		float num5 = baseHeight;
		if ((Object)(object)ZoneSystem.instance != (Object)null)
		{
			num5 = ZoneSystem.instance.GetGroundHeight(((Component)m_pivotPiece).transform.position);
		}
		m_sourceHeightOffsetActual = ((Component)m_pivotPiece).transform.position.y - num5;
		m_additionalHeightOffset = 0f - m_sourceHeightOffsetActual;
		Debug.Log((object)("[MovingDay] Calculated sourceHeightOffsets: pivotY=" + ((Component)m_pivotPiece).transform.position.y + " baseHeight=" + baseHeight + " actualHeight=" + num5 + " baseOffset=" + m_sourceHeightOffset + " actualOffset=" + m_sourceHeightOffsetActual + " | Initial height adjustment set to: " + m_additionalHeightOffset));
		MovingDayGhost.SpawnGhosts(MovingDaySelection.m_selectedPieces, m_pivotPiece);
		((Character)player).Message((MessageType)2, "Entered Move Mode. Left Click to place, Right Click/Esc to cancel.", 0, (Sprite)null);
	}

	public static void UpdateMoveMode(Player player)
	{
		//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_022a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0235: Unknown result type (might be due to invalid IL or missing references)
		//IL_023f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0244: Unknown result type (might be due to invalid IL or missing references)
		//IL_0249: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00da: Unknown result type (might be due to invalid IL or missing references)
		//IL_00df: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_041f: 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_0145: Unknown result type (might be due to invalid IL or missing references)
		//IL_015e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0562: Unknown result type (might be due to invalid IL or missing references)
		//IL_0595: Unknown result type (might be due to invalid IL or missing references)
		//IL_059a: Unknown result type (might be due to invalid IL or missing references)
		//IL_029d: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_05df: Unknown result type (might be due to invalid IL or missing references)
		//IL_05e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_05c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_06df: Unknown result type (might be due to invalid IL or missing references)
		//IL_06e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0337: Unknown result type (might be due to invalid IL or missing references)
		//IL_037a: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)player == (Object)null || (Object)(object)Camera.main == (Object)null)
		{
			Debug.Log((object)("[MovingDay Diag] UpdateMoveMode: early return - player=" + (((Object)(object)player == (Object)null) ? "null" : "ok") + " camera=" + (((Object)(object)Camera.main == (Object)null) ? "null" : "ok")));
			return;
		}
		m_debugLogTimer += Time.deltaTime;
		KeyboardShortcut value;
		if (m_debugLogTimer >= 2f)
		{
			m_debugLogTimer = 0f;
			bool flag = PlayerCanTakeInput(player);
			int num;
			if (configHeightUpHotkey == null)
			{
				num = 273;
			}
			else
			{
				value = configHeightUpHotkey.Value;
				num = (int)((KeyboardShortcut)(ref value)).MainKey;
			}
			KeyCode key = (KeyCode)num;
			int num2;
			if (configHeightDownHotkey == null)
			{
				num2 = 274;
			}
			else
			{
				value = configHeightDownHotkey.Value;
				num2 = (int)((KeyboardShortcut)(ref value)).MainKey;
			}
			KeyCode key2 = (KeyCode)num2;
			Debug.Log((object)("[MovingDay Diag] UpdateMoveMode RUNNING: m_inMoveMode=" + m_inMoveMode + " takeInput=" + flag + " heightOffset=" + m_additionalHeightOffset.ToString("F2") + " up=" + MyGetKey(key) + " dn=" + MyGetKey(key2)));
		}
		int mask = LayerMask.GetMask(new string[4] { "Default", "static_solid", "piece", "terrain" });
		Ray val = default(Ray);
		((Ray)(ref val))..ctor(((Component)Camera.main).transform.position, ((Component)Camera.main).transform.forward);
		string text = "None";
		RaycastHit val2 = default(RaycastHit);
		Vector3 targetPos;
		if (Physics.Raycast(val, ref val2, 50f, mask))
		{
			targetPos = ((RaycastHit)(ref val2)).point;
			text = (((Object)(object)((RaycastHit)(ref val2)).collider != (Object)null) ? ((Object)((RaycastHit)(ref val2)).collider).name : "NullCollider");
		}
		else
		{
			targetPos = ((Component)player).transform.position + ((Component)player).transform.forward * 5f;
		}
		bool flag2 = PlayerCanTakeInput(player);
		if (flag2)
		{
			float num3 = ((MyGetKey((KeyCode)304) || MyGetKey((KeyCode)303)) ? 1f : 5f);
			int num4;
			if (configHeightUpHotkey == null)
			{
				num4 = 273;
			}
			else
			{
				value = configHeightUpHotkey.Value;
				num4 = (int)((KeyboardShortcut)(ref value)).MainKey;
			}
			KeyCode key = (KeyCode)num4;
			int num5;
			if (configHeightDownHotkey == null)
			{
				num5 = 274;
			}
			else
			{
				value = configHeightDownHotkey.Value;
				num5 = (int)((KeyboardShortcut)(ref value)).MainKey;
			}
			KeyCode key2 = (KeyCode)num5;
			int num6;
			if (configHeightResetHotkey == null)
			{
				num6 = 278;
			}
			else
			{
				value = configHeightResetHotkey.Value;
				num6 = (int)((KeyboardShortcut)(ref value)).MainKey;
			}
			KeyCode key3 = (KeyCode)num6;
			if (MyGetKey(key))
			{
				m_additionalHeightOffset += num3 * Time.deltaTime;
				Debug.Log((object)("[MovingDay Debug] Height adjustment raise held. New offset: " + m_additionalHeightOffset));
			}
			else if (MyGetKey(key2))
			{
				m_additionalHeightOffset -= num3 * Time.deltaTime;
				Debug.Log((object)("[MovingDay Debug] Height adjustment lower held. New offset: " + m_additionalHeightOffset));
			}
			else if (MyGetKeyDown(key3))
			{
				if (MyGetKey((KeyCode)304) || MyGetKey((KeyCode)303))
				{
					m_additionalHeightOffset = 0f;
					((Character)player).Message((MessageType)2, "Height reset to original structure offset.", 0, (Sprite)null);
					Debug.Log((object)"[MovingDay Debug] Height adjustment reset to original structure offset (0).");
				}
				else
				{
					m_additionalHeightOffset = 0f - m_sourceHeightOffsetActual;
					((Character)player).Message((MessageType)2, "Height reset to ground level.", 0, (Sprite)null);
					Debug.Log((object)"[MovingDay Debug] Height adjustment reset to ground level (-m_sourceHeightOffsetActual).");
				}
			}
		}
		float y = targetPos.y;
		if (IsModifierPressed())
		{
			float baseHeight = MovingDayTerrain.GetBaseHeight(targetPos);
			targetPos.y = baseHeight + m_sourceHeightOffset;
		}
		else
		{
			targetPos.y = y + m_sourceHeightOffsetActual;
		}
		if (flag2)
		{
			float mouseScrollWheel = ZInput.GetMouseScrollWheel();
			if (mouseScrollWheel != 0f)
			{
				if (MyGetKey((KeyCode)308) || MyGetKey((KeyCode)307))
				{
					float num7 = (MyGetKey((KeyCode)304) ? 0.1f : 0.5f);
					m_additionalHeightOffset += ((mouseScrollWheel > 0f) ? num7 : (0f - num7));
					Debug.Log((object)("[MovingDay Debug] Alt+Scroll detected. Scroll=" + mouseScrollWheel + ", New offset: " + m_additionalHeightOffset));
				}
				else if (mouseScrollWheel > 0f)
				{
					m_targetYaw += 22.5f;
				}
				else if (mouseScrollWheel < 0f)
				{
					m_targetYaw -= 22.5f;
				}
			}
		}
		float y2 = ((Component)player).transform.eulerAngles.y;
		float num8 = Mathf.Round(y2 / 22.5f) * 22.5f;
		Quaternion val3 = Quaternion.Euler(0f, num8 + m_targetYaw, 0f);
		if (!MyGetKey((KeyCode)304) && !MyGetKey((KeyCode)303))
		{
			FindAndApplySnapping(ref targetPos, val3);
		}
		targetPos.y += m_additionalHeightOffset;
		MovingDayGhost.UpdateGhosts(targetPos, val3);
		((Character)player).Message((MessageType)2, "BaseOffset: " + m_sourceHeightOffset.ToString("F1") + " | ActOffset: " + m_sourceHeightOffsetActual.ToString("F1") + " | HeightAdj: " + m_additionalHeightOffset.ToString("F1") + " | FinalY: " + targetPos.y.ToString("F1"), 0, (Sprite)null);
		bool flag3 = IsModifierPressed();
		if (flag3 != m_lastCopyTerrainState)
		{
			m_lastCopyTerrainState = flag3;
			if (flag3)
			{
				((Character)player).Message((MessageType)2, "Terrain Modification: COPY/REVERT ENABLED", 0, (Sprite)null);
			}
			else
			{
				((Character)player).Message((MessageType)2, "Terrain Modification: COPY/REVERT DISABLED", 0, (Sprite)null);
			}
		}
		if (flag2)
		{
			if (ZInput.GetMouseButtonDown(0))
			{
				ConfirmMove(player, targetPos, val3);
			}
			else if (ZInput.GetMouseButtonDown(1) || MyGetKeyDown((KeyCode)27))
			{
				CancelMove();
				((Character)player).Message((MessageType)2, "Move canceled.", 0, (Sprite)null);
			}
		}
	}

	private static void ConfirmMove(Player player, Vector3 targetPos, Quaternion targetRot)
	{
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: 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_0515: Unknown result type (might be due to invalid IL or missing references)
		//IL_0296: 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_029a: Unknown result type (might be due to invalid IL or missing references)
		//IL_029f: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0158: Unknown result type (might be due to invalid IL or missing references)
		//IL_0159: Unknown result type (might be due to invalid IL or missing references)
		//IL_015c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0161: Unknown result type (might be due to invalid IL or missing references)
		//IL_0166: Unknown result type (might be due to invalid IL or missing references)
		//IL_016b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0174: Unknown result type (might be due to invalid IL or missing references)
		//IL_0179: Unknown result type (might be due to invalid IL or missing references)
		//IL_05ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_05bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_05be: Unknown result type (might be due to invalid IL or missing references)
		//IL_05c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_05c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_05f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0604: Unknown result type (might be due to invalid IL or missing references)
		//IL_0618: Unknown result type (might be due to invalid IL or missing references)
		//IL_0619: Unknown result type (might be due to invalid IL or missing references)
		//IL_0626: Unknown result type (might be due to invalid IL or missing references)
		//IL_0653: Unknown result type (might be due to invalid IL or missing references)
		//IL_0664: Unknown result type (might be due to invalid IL or missing references)
		//IL_06d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_06d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_06da: Unknown result type (might be due to invalid IL or missing references)
		//IL_06df: Unknown result type (might be due to invalid IL or missing references)
		//IL_06e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_06e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_06eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_06ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_06f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_06f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_06fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_071b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0729: Unknown result type (might be due to invalid IL or missing references)
		//IL_0733: Unknown result type (might be due to invalid IL or missing references)
		//IL_0738: Unknown result type (might be due to invalid IL or missing references)
		//IL_073a: Unknown result type (might be due to invalid IL or missing references)
		//IL_073c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0741: Unknown result type (might be due to invalid IL or missing references)
		//IL_076b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0781: Unknown result type (might be due to invalid IL or missing references)
		//IL_08b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_08c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_08eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0800: Unknown result type (might be due to invalid IL or missing references)
		//IL_0814: Unknown result type (might be due to invalid IL or missing references)
		//IL_0859: Unknown result type (might be due to invalid IL or missing references)
		//IL_0868: Unknown result type (might be due to invalid IL or missing references)
		//IL_088e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0ca2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0ca3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0cb2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0cb7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0cb8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0cbd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0cc2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0cc4: Unknown result type (might be due to invalid IL or missing references)
		//IL_0cc5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0cc6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0cc8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0ccd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0cd2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0cde: Unknown result type (might be due to invalid IL or missing references)
		//IL_0ce3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0ce7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0cec: Unknown result type (might be due to invalid IL or missing references)
		//IL_0cf0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0d16: Unknown result type (might be due to invalid IL or missing references)
		//IL_0d1b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0d1d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0d1f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0d24: Unknown result type (might be due to invalid IL or missing references)
		//IL_0d2b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0d2d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0abc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0abd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0ac9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0ace: Unknown result type (might be due to invalid IL or missing references)
		//IL_0acf: Unknown result type (might be due to invalid IL or missing references)
		//IL_0ad4: Unknown result type (might be due to invalid IL or missing references)
		//IL_0ad9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0adb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0adc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0add: Unknown result type (might be due to invalid IL or missing references)
		//IL_0adf: Unknown result type (might be due to invalid IL or missing references)
		//IL_0ae4: Unknown result type (might be due to invalid IL or missing references)
		//IL_0ae9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0af2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0af7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0afb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0b00: Unknown result type (might be due to invalid IL or missing references)
		//IL_0b04: Unknown result type (might be due to invalid IL or missing references)
		//IL_0b2a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0b2f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0b31: Unknown result type (might be due to invalid IL or missing references)
		//IL_0b33: Unknown result type (might be due to invalid IL or missing references)
		//IL_0b38: Unknown result type (might be due to invalid IL or missing references)
		//IL_0b69: Unknown result type (might be due to invalid IL or missing references)
		//IL_0b80: Unknown result type (might be due to invalid IL or missing references)
		//IL_0d6d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0d72: Unknown result type (might be due to invalid IL or missing references)
		//IL_0d79: Unknown result type (might be due to invalid IL or missing references)
		//IL_0df6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0dff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0c04: Unknown result type (might be due to invalid IL or missing references)
		//IL_0c13: Unknown result type (might be due to invalid IL or missing references)
		//IL_0c38: Unknown result type (might be due to invalid IL or missing references)
		//IL_0c42: Unknown result type (might be due to invalid IL or missing references)
		//IL_0c4c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0c59: Unknown result type (might be due to invalid IL or missing references)
		//IL_0bdc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0be6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0ec4: Unknown result type (might be due to invalid IL or missing references)
		//IL_0ec5: Unknown result type (might be due to invalid IL or missing references)
		if (m_selectedPieceInfos.Count == 0)
		{
			((Character)player).Message((MessageType)2, "Move aborted: No cached pieces to move.", 0, (Sprite)null);
			CancelMove();
			return;
		}
		Vector3 oldPivotPos = m_oldPivotPos;
		float oldPivotYaw = m_oldPivotYaw;
		Quaternion val = Quaternion.Euler(0f, oldPivotYaw, 0f);
		Debug.Log((object)string.Concat("[MovingDay Debug] ConfirmMove triggered! piecesCount=", m_selectedPieceInfos.Count, " oldPivotPos=", oldPivotPos, " targetPos=", targetPos));
		List<Player> allPlayers = Player.GetAllPlayers();
		List<Player> list = new List<Player>();
		List<Player> list2 = new List<Player>();
		List<Character> list3 = new List<Character>();
		if (configMoveTamed.Value)
		{
			List<Character> allCharacters = Character.GetAllCharacters();
			Debug.Log((object)("[MovingDay Debug] Scanning " + allCharacters.Count + " total active characters for tamed animals..."));
			foreach (Character item in allCharacters)
			{
				if ((Object)(object)item == (Object)null)
				{
					continue;
				}
				bool flag = item.IsTamed();
				float num = float.MaxValue;
				foreach (SelectedPieceInfo selectedPieceInfo in m_selectedPieceInfos)
				{
					Vector3 val2 = oldPivotPos + val * selectedPieceInfo.relPos;
					float num2 = Vector3.Distance(((Component)item).transform.position, val2);
					if (num2 < num)
					{
						num = num2;
					}
				}
				if (flag && num < 6f)
				{
					list3.Add(item);
					Debug.Log((object)("[MovingDay Debug] -> Added " + ((Object)item).name + " to teleport list (distance: " + num.ToString("F1") + "m)."));
				}
			}
		}
		foreach (Player item2 in allPlayers)
		{
			if ((Object)(object)item2 == (Object)null)
			{
				continue;
			}
			bool flag2 = false;
			foreach (SelectedPieceInfo selectedPieceInfo2 in m_selectedPieceInfos)
			{
				Vector3 val2 = oldPivotPos + val * selectedPieceInfo2.relPos;
				if (Vector3.Distance(((Component)item2).transform.position, val2) < 3f)
				{
					flag2 = true;
					break;
				}
			}
			if (!flag2)
			{
				continue;
			}
			bool flag3 = PlayerHasNonTeleportable(item2);
			string value = configPlayerMetalAction.Value;
			string value2 = configPlayerSafety.Value;
			if (flag3 && value.Equals("BlockMove", StringComparison.OrdinalIgnoreCase))
			{
				if ((Object)(object)item2 == (Object)(object)Player.m_localPlayer)
				{
					((Character)player).Message((MessageType)2, "Cannot move: You are carrying non-teleportable items.", 0, (Sprite)null);
				}
				else
				{
					((Character)player).Message((MessageType)2, "Cannot move: Player '" + item2.GetPlayerName() + "' is carrying non-teleportable items.", 0, (Sprite)null);
				}
				Debug.LogWarning((object)"[MovingDay Debug] Move aborted: Player carrying metal when PlayerMetalAction=BlockMove.");
				return;
			}
			if ((Object)(object)item2 == (Object)(object)Player.m_localPlayer)
			{
				if (value2.Equals("Block", StringComparison.OrdinalIgnoreCase))
				{
					((Character)player).Message((MessageType)2, "Cannot move: You are inside the building.", 0, (Sprite)null);
					Debug.LogWarning((object)"[MovingDay Debug] Move aborted: Local player is inside and PlayerSafetyAction=Block.");
					return;
				}
				if (value2.Equals("Teleport", StringComparison.OrdinalIgnoreCase))
				{
					if (flag3 && value.Equals("LeaveBehind", StringComparison.OrdinalIgnoreCase))
					{
						list2.Add(item2);
					}
					else
					{
						list.Add(item2);
					}
				}
				else
				{
					list2.Add(item2);
				}
			}
			else
			{
				if (value2.Equals("Block", StringComparison.OrdinalIgnoreCase) || value2.Equals("Teleport", StringComparison.OrdinalIgnoreCase))
				{
					((Character)player).Message((MessageType)2, "Cannot move: Player '" + item2.GetPlayerName() + "' is inside.", 0, (Sprite)null);
					Debug.LogWarning((object)("[MovingDay Debug] Move aborted: Other player is inside and PlayerSafetyAction=" + value2));
					return;
				}
				list2.Add(item2);
			}
		}
		bool flag4 = IsModifierPressed();
		Debug.Log((object)string.Concat("[MovingDay Debug] Modifier Key Check: copyTerrain=", flag4, " (Config=", configModifierKey.Value, " LeftCtrl=", ZInput.GetKey((KeyCode)306, true), " RightCtrl=", ZInput.GetKey((KeyCode)305, true), ")"));
		List<TerrainPoint> list4 = null;
		HashSet<TerrainComp> affectedComps = new HashSet<TerrainComp>();
		if (flag4)
		{
			((Character)player).Message((MessageType)2, "Processing terrain updates...", 0, (Sprite)null);
			List<Vector3> list5 = new List<Vector3>();
			foreach (SelectedPieceInfo selectedPieceInfo3 in m_selectedPieceInfos)
			{
				list5.Add(oldPivotPos + val * selectedPieceInfo3.relPos);
			}
			list4 = MovingDayTerrain.CaptureTerrain(oldPivotPos, m_maxSelectedDistance, list5);
			float yawRad = (((Quaternion)(ref targetRot)).eulerAngles.y - oldPivotYaw) * ((float)Math.PI / 180f);
			MovingDayTerrain.ApplyTerrain(oldPivotPos, targetPos, yawRad, list4, ref affectedComps);
			MovingDayTerrain.ClearTerrain(oldPivotPos, list4, ref affectedComps);
			MovingDayTerrain.RebuildTerrain(affectedComps);
			if ((Object)(object)ClutterSystem.instance != (Object)null)
			{
				ClutterSystem.instance.ResetGrass(oldPivotPos, m_maxSelectedDistance);
				ClutterSystem.instance.ResetGrass(targetPos, m_maxSelectedDistance);
			}
		}
		((Character)player).Message((MessageType)2, "Moving structure...", 0, (Sprite)null);
		Debug.Log((object)"[MovingDay Debug] Relocating GameObjects...");
		List<WearNTear> list6 = new List<WearNTear>();
		int num3 = 0;
		foreach (SelectedPieceInfo selectedPieceInfo4 in m_selectedPieceInfos)
		{
			if (selectedPieceInfo4.zdo == null || !selectedPieceInfo4.zdo.IsValid())
			{
				continue;
			}
			Vector3 val3 = targetPos + targetRot * selectedPieceInfo4.relPos;
			Quaternion val4 = targetRot * selectedPieceInfo4.relRot;
			float num4 = Mathf.Round(((Quaternion)(ref val4)).eulerAngles.y / 22.5f) * 22.5f;
			val4 = Quaternion.Euler(((Quaternion)(ref val4)).eulerAngles.x, num4, ((Quaternion)(ref val4)).eulerAngles.z);
			val4 = NormalizeQuaternion(val4);
			Debug.Log((object)string.Concat("[MovingDay Debug] Relocating piece '", selectedPieceInfo4.prefabName, "' to pos=", val3, " rot=", ((Quaternion)(ref val4)).eulerAngles));
			if ((Object)(object)selectedPieceInfo4.piece != (Object)null)
			{
				WearNTear component = ((Component)selectedPieceInfo4.piece).GetComponent<WearNTear>();
				if ((Object)(object)component != (Object)null && ((Behaviour)component).enabled)
				{
					((Behaviour)component).enabled = false;
					list6.Add(component);
				}
				((Component)selectedPieceInfo4.piece).transform.position = val3;
				((Component)selectedPieceInfo4.piece).transform.rotation = val4;
				ZNetView component2 = ((Component)selectedPieceInfo4.piece).GetComponent<ZNetView>();
				if ((Object)(object)component2 != (Object)null && component2.IsValid())
				{
					component2.ClaimOwnership();
				}
				selectedPieceInfo4.zdo.SetPosition(val3);
				selectedPieceInfo4.zdo.SetRotation(val4);
				ZDOMan.instance.ZDOSectorInvalidated(selectedPieceInfo4.zdo);
				ZDOMan.instance.ClientChanged(selectedPieceInfo4.zdo.m_uid);
			}
			else
			{
				selectedPieceInfo4.zdo.SetOwner(ZDOMan.GetSessionID());
				selectedPieceInfo4.zdo.SetPosition(val3);
				selectedPieceInfo4.zdo.SetRotation(val4);
				ZDOMan.instance.ZDOSectorInvalidated(selectedPieceInfo4.zdo);
				ZDOMan.instance.ClientChanged(selectedPieceInfo4.zdo.m_uid);
			}
			num3++;
		}
		Debug.Log((object)("[MovingDay Debug] Relocated " + num3 + " GameObjects. Syncing transforms..."));
		Physics.SyncTransforms();
		foreach (WearNTear item3 in list6)
		{
			ResetPieceStabilityCache(item3);
		}
		float value3 = Time.time + 5f;
		foreach (WearNTear item4 in list6)
		{
			if ((Object)(object)item4 != (Object)null)
			{
				m_recentlyMovedPieces[item4] = value3;
			}
		}
		if ((Object)(object)instance != (Object)null)
		{
			((MonoBehaviour)instance).StartCoroutine(ReenableStabilityDelay(list6));
		}
		else
		{
			Debug.LogWarning((object)"[MovingDay Debug] instance is null! Fallback to instant stability re-enable.");
			foreach (WearNTear item5 in list6)
			{
				if ((Object)(object)item5 != (Object)null)
				{
					item5.OnPlaced();
					((Behaviour)item5).enabled = true;
				}
			}
		}
		Quaternion rotation;
		if (configMoveTamed.Value)
		{
			foreach (Character item6 in list3)
			{
				if ((Object)(object)item6 == (Object)null)
				{
					continue;
				}
				Vector3 val5 = Quaternion.Inverse(val) * (((Component)item6).transform.position - oldPivotPos);
				Vector3 val6 = targetPos + targetRot * val5;
				rotation = ((Component)item6).transform.rotation;
				Vector3 eulerAngles = ((Quaternion)(ref rotation)).eulerAngles;
				float num5 = ((Quaternion)(ref targetRot)).eulerAngles.y - oldPivotYaw;
				Quaternion q = Quaternion.Euler(eulerAngles.x, eulerAngles.y + num5, eulerAngles.z);
				q = NormalizeQuaternion(q);
				Debug.Log((object)string.Concat("[MovingDay Debug] Teleporting tamed animal '", ((Object)item6).name, "' from ", ((Component)item6).transform.position, " to ", val6));
				ZNetView component2 = ((Component)item6).GetComponent<ZNetView>();
				if ((Object)(object)component2 != (Object)null && component2.IsValid())
				{
					component2.ClaimOwnership();
					ZDO zDO = component2.GetZDO();
					if (zDO != null)
					{
						zDO.SetPosition(val6);
						zDO.SetRotation(q);
						ZDOMan.instance.ZDOSectorInvalidated(zDO);
					}
				}
				((Component)item6).transform.position = val6;
				((Component)item6).transform.rotation = q;
				Rigidbody component3 = ((Component)item6).GetComponent<Rigidbody>();
				if ((Object)(object)component3 != (Object)null)
				{
					component3.position = val6;
					component3.rotation = q;
					component3.velocity = Vector3.zero;
					component3.angularVelocity = Vector3.zero;
				}
			}
		}
		if (list.Contains(Player.m_localPlayer))
		{
			Vector3 val7 = Quaternion.Inverse(val) * (((Component)Player.m_localPlayer).transform.position - oldPivotPos);
			Vector3 val8 = targetPos + targetRot * val7;
			rotation = ((Component)Player.m_localPlayer).transform.rotation;
			Vector3 eulerAngles2 = ((Quaternion)(ref rotation)).eulerAngles;
			float num5 = ((Quaternion)(ref targetRot)).eulerAngles.y - oldPivotYaw;
			Quaternion q2 = Quaternion.Euler(eulerAngles2.x, eulerAngles2.y + num5, eulerAngles2.z);
			q2 = NormalizeQuaternion(q2);
			((Character)Player.m_localPlayer).TeleportTo(val8, q2, true);
		}
		Vector3 val9 = default(Vector3);
		foreach (Player item7 in list2)
		{
			if (!((Object)(object)item7 == (Object)null))
			{
				Vector3 position = ((Component)item7).transform.position;
				float groundHeight = ZoneSystem.instance.GetGroundHeight(position);
				if (position.y > groundHeight + 0.1f)
				{
					((Character)item7).GetSEMan().AddStatusEffect(StringExtensionMethods.GetStableHashCode("Featherfall"), true, 1, 0f);
					Debug.Log((object)("[MovingDay Debug] Applied Featherfall status effect to player " + item7.GetPlayerName()));
					continue;
				}
				((Vector3)(ref val9))..ctor(position.x, groundHeight + 0.5f, position.z);
				((Character)item7).TeleportTo(val9, ((Component)item7).transform.rotation, true);
				Debug.Log((object)("[MovingDay Debug] Snapped player " + item7.GetPlayerName() + " to restored ground Y: " + (groundHeight + 0.5f)));
			}
		}
		GameObject prefab = ZNetScene.instance.GetPrefab("portal_wood");
		if ((Object)(object)prefab != (Object)null)
		{
			TeleportWorld component4 = prefab.GetComponent<TeleportWorld>();
			if ((Object)(object)component4 != (Object)null && component4.m_connected != null)
			{
				component4.m_connected.Create(targetPos, Quaternion.identity, (Transform)null, 1f, -1);
			}
		}
		GameObject field = GetField<GameObject>(player, "m_placementGhost");
		if ((Object)(object)field != (Object)null)
		{
			field.SetActive(true);
		}
		MovingDayGhost.ClearGhosts();
		MovingDaySelection.ClearSelection();
		m_selectedPieceInfos.Clear();
		m_inMoveMode = false;
		m_sourceHeightOffset = 0f;
		m_sourceHeightOffsetActual = 0f;
		m_additionalHeightOffset = 0f;
		((Character)player).Message((MessageType)2, "Structure moved successfully!", 0, (Sprite)null);
	}

	private static void ResetPieceStabilityCache(WearNTear wear)
	{
		if ((Object)(object)wear == (Object)null)
		{
			return;
		}
		try
		{
			Heightmap field = GetField<Heightmap>(wear, "m_connectedHeightMap");
			if ((Object)(object)field != (Object)null)
			{
				MethodInfo method = typeof(Heightmap).GetMethod("remove_m_clearConnectedWearNTearCache", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (method != null)
				{
					MethodInfo method2 = typeof(WearNTear).GetMethod("ClearCachedSupport", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					if (method2 != null)
					{
						Action action = (Action)Delegate.CreateDelegate(typeof(Action), wear, method2);
						method.Invoke(field, new object[1] { action });
					}
				}
			}
			SetField(wear, "m_connectedHeightMap", null);
			SetField(wear, "m_heightmap", null);
			SetField(wear, "m_biome", 0);
			SetField(wear, "m_groundDist", 0f);
			SetField(wear, "m_haveRoof", false);
			SetField(wear, "m_haveAshRoof", false);
			SetField(wear, "m_updateCoverTimer", 0f);
			GetField<List<Collider>>(wear, "m_supportColliders")?.Clear();
			GetField<List<Vector3>>(wear, "m_supportPositions")?.Clear();
			GetField<List<float>>(wear, "m_supportValue")?.Clear();
			MethodInfo method3 = typeof(WearNTear).GetMethod("SetupColliders", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (method3 != null)
			{
				method3.Invoke(wear, null);
			}
			MethodInfo method4 = typeof(WearNTear).GetMethod("GetMaxSupport", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (method4 != null)
			{
				float num = (float)method4.Invoke(wear, null);
				SetField(wear, "m_support", num);
			}
			MethodInfo method5 = typeof(WearNTear).GetMethod("Start", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (method5 != null)
			{
				method5.Invoke(wear, null);
			}
		}
		catch (Exception ex)
		{
			Debug.LogWarning((object)("[MovingDay Debug] Error resetting stability cache: " + ex.Message));
		}
	}

	private static IEnumerator ReenableStabilityDelay(List<WearNTear> wnts)
	{
		yield return null;
		yield return null;
		List<WearNTear> sortedWnts = new List<WearNTear>();
		foreach (WearNTear wnt in wnts)
		{
			if ((Object)(object)wnt != (Object)null)
			{
				sortedWnts.Add(wnt);
			}
		}
		sortedWnts.Sort(delegate(WearNTear a, WearNTear b)
		{
			//IL_0006: 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)
			float y = ((Component)a).transform.position.y;
			return y.CompareTo(((Component)b).transform.position.y);
		});
		Debug.Log((object)("[MovingDay Debug] Re-enabling stability for " + sortedWnts.Count + " pieces in ground-up order."));
		foreach (WearNTear item in sortedWnts)
		{
			item.OnPlaced();
			((Behaviour)item).enabled = true;
		}
		MethodInfo updateSupportMethod = typeof(WearNTear).GetMethod("UpdateSupport", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
		if (updateSupportMethod != null)
		{
			int num = 0;
			foreach (WearNTear item2 in sortedWnts)
			{
				if (!((Object)(object)item2 == (Object)null))
				{
					try
					{
						updateSupportMethod.Invoke(item2, null);
						num++;
					}
					catch (Exception ex)
					{
						Debug.LogWarning((object)("[MovingDay Debug] UpdateSupport failed on " + ((Object)item2).name + ": " + ex.Message));
					}
				}
			}
			Debug.Log((object)("[MovingDay Debug] Synchronously propagated support for " + num + " pieces."));
		}
		else
		{
			Debug.LogWarning((object)"[MovingDay Debug] UpdateSupport method not found via reflection!");
		}
	}

	private static void SetField(object obj, string name, object val)
	{
		if (obj != null)
		{
			FieldInfo field = obj.GetType().GetField(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (field != null)
			{
				field.SetValue(obj, val);
			}
		}
	}

	private static T GetField<T>(object obj, string name)
	{
		if (obj == null)
		{
			return default(T);
		}
		FieldInfo field = obj.GetType().GetField(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
		return (field != null) ? ((T)field.GetValue(obj)) : default(T);
	}

	private static Quaternion NormalizeQuaternion(Quaternion q)
	{
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: Unknown result type (might be due to invalid IL or missing references)
		//IL_007a: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		float num = Mathf.Sqrt(q.x * q.x + q.y * q.y + q.z * q.z + q.w * q.w);
		if (num > 1E-05f)
		{
			return new Quaternion(q.x / num, q.y / num, q.z / num, q.w / num);
		}
		return Quaternion.identity;
	}

	private static void FindAndApplySnapping(ref Vector3 targetPos, Quaternion targetRot)
	{
		//IL_0232: Unknown result type (might be due to invalid IL or missing references)
		//IL_0237: Unknown result type (might be due to invalid IL or missing references)
		//IL_0239: 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_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0090: 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_009a: 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_00a4: 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_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_0173: Unknown result type (might be due to invalid IL or missing references)
		//IL_0179: Unknown result type (might be due to invalid IL or missing references)
		//IL_0250: Unknown result type (might be due to invalid IL or missing references)
		//IL_0255: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0266: Unknown result type (might be due to invalid IL or missing references)
		//IL_026b: Unknown result type (might be due to invalid IL or missing references)
		//IL_026e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0270: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_028d: Unknown result type (might be due to invalid IL or missing references)
		//IL_028f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0291: Unknown result type (might be due to invalid IL or missing references)
		//IL_0293: Unknown result type (might be due to invalid IL or missing references)
		List<Vector3> list = new List<Vector3>();
		foreach (GhostPiece activeGhost in MovingDayGhost.m_activeGhosts)
		{
			if (activeGhost == null || (Object)(object)activeGhost.gameObject == (Object)null)
			{
				continue;
			}
			for (int i = 0; i < activeGhost.gameObject.transform.childCount; i++)
			{
				Transform child = activeGhost.gameObject.transform.GetChild(i);
				if ((Object)(object)child != (Object)null && ((Component)child).CompareTag("snappoint"))
				{
					Vector3 item = targetPos + targetRot * (activeGhost.relPos + activeGhost.relRot * child.localPosition);
					list.Add(item);
				}
			}
		}
		if (list.Count == 0)
		{
			return;
		}
		List<Vector3> list2 = new List<Vector3>();
		List<Piece> allPieces = MovingDaySelection.GetAllPieces();
		float num = m_maxSelectedDistance + 10f;
		foreach (Piece item2 in allPieces)
		{
			if ((Object)(object)item2 == (Object)null || MovingDaySelection.m_selectedPieces.Contains(item2) || Vector3.Distance(((Component)item2).transform.position, targetPos) > num)
			{
				continue;
			}
			for (int i = 0; i < ((Component)item2).transform.childCount; i++)
			{
				Transform child = ((Component)item2).transform.GetChild(i);
				if ((Object)(object)child != (Object)null && ((Component)child).CompareTag("snappoint"))
				{
					list2.Add(child.position);
				}
			}
		}
		if (list2.Count == 0)
		{
			return;
		}
		float num2 = 1f;
		Vector3 val = Vector3.zero;
		Vector3 val2 = Vector3.zero;
		bool flag = false;
		foreach (Vector3 item3 in list)
		{
			foreach (Vector3 item4 in list2)
			{
				float num3 = Vector3.Distance(item3, item4);
				if (num3 < num2)
				{
					num2 = num3;
					val = item3;
					val2 = item4;
					flag = true;
				}
			}
		}
		if (flag)
		{
			Vector3 val3 = val2 - val;
			targetPos += val3;
		}
	}

	private static void CancelMove()
	{
		if ((Object)(object)Player.m_localPlayer != (Object)null)
		{
			GameObject field = GetField<GameObject>(Player.m_localPlayer, "m_placementGhost");
			if ((Object)(object)field != (Object)null)
			{
				field.SetActive(true);
			}
		}
		MovingDayGhost.ClearGhosts();
		m_inMoveMode = false;
		m_sourceHeightOffset = 0f;
		m_sourceHeightOffsetActual = 0f;
		m_additionalHeightOffset = 0f;
		m_selectedPieceInfos.Clear();
	}

	private static bool IsModifierPressed()
	{
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Invalid comparison between Unknown and I4
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		if (configModifierKey == null)
		{
			return false;
		}
		KeyboardShortcut value = configModifierKey.Value;
		KeyCode mainKey = ((KeyboardShortcut)(ref value)).MainKey;
		if ((int)mainKey == 0)
		{
			return false;
		}
		return MyGetKey(mainKey);
	}

	private static ItemData GetRightItem(Player player)
	{
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Expected O, but got Unknown
		if ((Object)(object)player == (Object)null)
		{
			return null;
		}
		Type type = ((object)player).GetType();
		while (type != null)
		{
			FieldInfo field = type.GetField("m_rightItem", BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (field != null)
			{
				return (ItemData)field.GetValue(player);
			}
			type = type.BaseType;
		}
		return null;
	}

	private static Piece GetHoveringPiece(Player player)
	{
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Expected O, but got Unknown
		if ((Object)(object)player == (Object)null)
		{
			return null;
		}
		FieldInfo field = typeof(Player).GetField("m_hoveringPiece", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
		if (field != null)
		{
			return (Piece)field.GetValue(player);
		}
		return null;
	}

	private static bool PlayerHasNonTeleportable(Player player)
	{
		if ((Object)(object)player == (Object)null)
		{
			return false;
		}
		foreach (ItemData allItem in ((Humanoid)player).GetInventory().GetAllItems())
		{
			if (allItem != null && !allItem.m_shared.m_teleportable)
			{
				return true;
			}
		}
		return false;
	}

	private static bool ContainerHasNonTeleportable(Container c)
	{
		if ((Object)(object)c == (Object)null)
		{
			return false;
		}
		foreach (ItemData allItem in c.GetInventory().GetAllItems())
		{
			if (allItem != null && !allItem.m_shared.m_teleportable)
			{
				return true;
			}
		}
		return false;
	}

	private static void SaveContainer(Container c)
	{
		if ((Object)(object)c == (Object)null)
		{
			return;
		}
		try
		{
			MethodInfo method = typeof(Container).GetMethod("Save", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (method != null)
			{
				method.Invoke(c, null);
			}
		}
		catch (Exception ex)
		{
			Debug.LogWarning((object)("[MovingDay Debug] Error saving container: " + ex.Message));
		}
	}

	public static object GetInputField(Chat chat)
	{
		if ((Object)(object)chat == (Object)null)
		{
			return null;
		}
		FieldInfo field = typeof(Chat).GetField("m_input", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
		if (field != null)
		{
			return field.GetValue(chat);
		}
		return null;
	}

	public static string GetChatText(Chat chat)
	{
		object inputField = GetInputField(chat);
		if (inputField == null)
		{
			return null;
		}
		PropertyInfo property = inputField.GetType().GetProperty("text");
		if (property != null)
		{
			return (string)property.GetValue(inputField, null);
		}
		return null;
	}

	public static void CleanWorldOrigin(float radius = 150f)
	{
		//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
		if (ZDOMan.instance == null)
		{
			return;
		}
		int num = 0;
		try
		{
			FieldInfo field = typeof(ZDOMan).GetField("m_objectsByID", BindingFlags.Instance | BindingFlags.NonPublic);
			if (field == null)
			{
				Debug.LogWarning((object)"[MovingDay] Failed to find m_objectsByID field in ZDOMan");
				return;
			}
			Dictionary<ZDOID, ZDO> dictionary = (Dictionary<ZDOID, ZDO>)field.GetValue(ZDOMan.instance);
			if (dictionary == null)
			{
				return;
			}
			List<ZDO> list = new List<ZDO>();
			foreach (KeyValuePair<ZDOID, ZDO> item in dictionary)
			{
				ZDO value = item.Value;
				if (value != null && value.IsValid())
				{
					Vector3 position = value.GetPosition();
					float num2 = Vector2.Distance(new Vector2(position.x, position.z), Vector2.zero);
					if (num2 <= radius && Mathf.Abs(position.y) < 2f && value.GetPrefab() != 0)
					{
						list.Add(value);
					}
				}
			}
			foreach (ZDO item2 in list)
			{
				item2.SetOwner(ZDOMan.GetSessionID());
				ZDOMan.instance.DestroyZDO(item2);
				num++;
			}
			string text = "MovingDay: Cleaned " + num + " ZDO(s) near world origin (0,0,0).";
			Debug.Log((object)("[MovingDay] " + text));
			if ((Object)(object)Player.m_localPlayer != (Object)null)
			{
				((Character)Player.m_localPlayer).Message((MessageType)2, text, 0, (Sprite)null);
			}
		}
		catch (Exception ex)
		{
			Debug.LogWarning((object)("[MovingDay] Error cleaning world origin: " + ex));
		}
	}

	private static bool FindClosestSnapPoints(Player player, Transform ghost, float maxSnapDistance, out Transform a, out Transform b, List<Piece> pieces)
	{
		//IL_0102: Unknown result type (might be due to invalid IL or missing references)
		//IL_0108: Expected O, but got Unknown
		//IL_010d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0113: Expected O, but got Unknown
		a = null;
		b = null;
		try
		{
			if (m_findClosestSnapPoints == null)
			{
				MethodInfo method = typeof(Player).GetMethod("FindClosestSnapPoints", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (method != null)
				{
					m_findClosestSnapPoints = (FindClosestSnapPointsDelegate)Delegate.CreateDelegate(typeof(FindClosestSnapPointsDelegate), null, method);
				}
			}
			if (m_findClosestSnapPoints != null)
			{
				return m_findClosestSnapPoints(player, ghost, maxSnapDistance, out a, out b, pieces);
			}
		}
		catch (Exception ex)
		{
			Debug.LogWarning((object)("[MovingDay Debug] Error calling FindClosestSnapPoints via delegate: " + ex.Message));
		}
		try
		{
			MethodInfo method = typeof(Player).GetMethod("FindClosestSnapPoints", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (method != null)
			{
				object[] array = new object[5] { ghost, maxSnapDistance, null, null, pieces };
				bool result = (bool)method.Invoke(player, array);
				a = (Transform)array[2];
				b = (Transform)array[3];
				return result;
			}
		}
		catch (Exception ex)
		{
			Debug.LogWarning((object)("[MovingDay Debug] Error calling FindClosestSnapPoints: " + ex.Message));
		}
		return false;
	}
}
public class MovingDaySelection
{
	public static HashSet<Piece> m_selectedPieces = new HashSet<Piece>();

	public static HashSet<ZDOID> m_selectedZDOIDs = new HashSet<ZDOID>();

	public static List<Piece> GetAllPieces()
	{
		FieldInfo field = typeof(Piece).GetField("s_allPieces", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
		if (field != null)
		{
			return (List<Piece>)field.GetValue(null);
		}
		return new List<Piece>();
	}

	public static void ClearSelection()
	{
		foreach (Piece selectedPiece in m_selectedPieces)
		{
			if ((Object)(object)selectedPiece != (Object)null)
			{
				MovingDaySelectionHighlight component = ((Component)selectedPiece).GetComponent<MovingDaySelectionHighlight>();
				if ((Object)(object)component != (Object)null)
				{
					Object.Destroy((Object)(object)component);
				}
				Component component2 = ((Component)selectedPiece).GetComponent("PrefabSelectionHighlight");
				if ((Object)(object)component2 != (Object)null)
				{
					Object.Destroy((Object)(object)component2);
				}
			}
		}
		m_selectedPieces.Clear();
		m_selectedZDOIDs.Clear();
	}

	public static void AddToSelection(Piece piece)
	{
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)piece == (Object)null) && piece.IsPlacedByPlayer())
		{
			if (m_selectedPieces.Add(piece) && (Object)(object)((Component)piece).GetComponent<MovingDaySelectionHighlight>() == (Object)null)
			{
				((Component)piece).gameObject.AddComponent<MovingDaySelectionHighlight>();
			}
			ZNetView component = ((Component)piece).GetComponent<ZNetView>();
			if ((Object)(object)component != (Object)null && component.IsValid() && component.GetZDO() != null)
			{
				m_selectedZDOIDs.Add(component.GetZDO().m_uid);
			}
		}
	}

	public static void RemoveFromSelection(Piece piece)
	{
		//IL_009e: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)piece == (Object)null)
		{
			return;
		}
		if (m_selectedPieces.Remove(piece))
		{
			MovingDaySelectionHighlight component = ((Component)piece).GetComponent<MovingDaySelectionHighlight>();
			if ((Object)(object)component != (Object)null)
			{
				Object.Destroy((Object)(object)component);
			}
			Component component2 = ((Component)piece).GetComponent("PrefabSelectionHighlight");
			if ((Object)(object)component2 != (Object)null)
			{
				Object.Destroy((Object)(object)component2);
			}
		}
		ZNetView component3 = ((Component)piece).GetComponent<ZNetView>();
		if ((Object)(object)component3 != (Object)null && component3.IsValid() && component3.GetZDO() != null)
		{
			m_selectedZDOIDs.Remove(component3.GetZDO().m_uid);
		}
	}

	private static Bounds GetPieceBounds(Piece piece, out bool success)
	{
		//IL_000b: 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_007b: 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_0058: 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)
		Collider[] componentsInChildren = ((Component)piece).GetComponentsInChildren<Collider>(true);
		Bounds result = default(Bounds);
		success = false;
		Collider[] array = componentsInChildren;
		foreach (Collider val in array)
		{
			if ((Object)(object)val != (Object)null && !val.isTrigger)
			{
				if (!success)
				{
					result = val.bounds;
					success = true;
				}
				else
				{
					((Bounds)(ref result)).Encapsulate(val.bounds);
				}
			}
		}
		return result;
	}

	private static float GetBoundsDistance(Bounds b1, Bounds b2)
	{
		//IL_0008: 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_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: 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_0069: 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_008e: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		float num = Mathf.Max(0f, Mathf.Abs(((Bounds)(ref b1)).center.x - ((Bounds)(ref b2)).center.x) - (((Bounds)(ref b1)).extents.x + ((Bounds)(ref b2)).extents.x));
		float num2 = Mathf.Max(0f, Mathf.Abs(((Bounds)(ref b1)).center.y - ((Bounds)(ref b2)).center.y) - (((Bounds)(ref b1)).extents.y + ((Bounds)(ref b2)).extents.y));
		float num3 = Mathf.Max(0f, Mathf.Abs(((Bounds)(ref b1)).center.z - ((Bounds)(ref b2)).center.z) - (((Bounds)(ref b1)).extents.z + ((Bounds)(ref b2)).extents.z));
		return Mathf.Sqrt(num * num + num2 * num2 + num3 * num3);
	}

	private static float GetPieceDistance(Piece p1, Piece p2)
	{
		//IL_0004: 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_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)
		//IL_0036: 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_0025: 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)
		bool success;
		Bounds pieceBounds = GetPieceBounds(p1, out success);
		bool success2;
		Bounds pieceBounds2 = GetPieceBounds(p2, out success2);
		if (success && success2)
		{
			return GetBoundsDistance(pieceBounds, pieceBounds2);
		}
		return Vector3.Distance(((Component)p1).transform.position, ((Component)p2).transform.position);
	}

	public static void SelectConnected(Piece startPiece, float maxDistance)
	{
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)startPiece == (Object)null || !startPiece.IsPlacedByPlayer())
		{
			return;
		}
		ClearSelection();
		List<Piece> allPieces = GetAllPieces();
		Queue<Piece> queue = new Queue<Piece>();
		HashSet<Piece> hashSet = new HashSet<Piece>();
		queue.Enqueue(startPiece);
		hashSet.Add(startPiece);
		List<Piece> list = new List<Piece>();
		Vector3 position = ((Component)startPiece).transform.position;
		foreach (Piece item in allPieces)
		{
			if ((Object)(object)item != (Object)null && Vector3.Distance(((Component)item).transform.position, position) < 250f)
			{
				list.Add(item);
			}
		}
		while (queue.Count > 0)
		{
			Piece val = queue.Dequeue();
			AddToSelection(val);
			foreach (Piece item2 in list)
			{
				if (!((Object)(object)item2 == (Object)null) && !hashSet.Contains(item2) && item2.IsPlacedByPlayer())
				{
					float pieceDistance = GetPieceDistance(val, item2);
					if (pieceDistance <= maxDistance)
					{
						hashSet.Add(item2);
						queue.Enqueue(item2);
					}
				}
			}
		}
	}
}
public class MovingDaySelectionHighlight : MonoBehaviour
{
	private GameObject m_highlightRoot;

	private Material m_material;

	private float m_time;

	private List<MeshRenderer> m_renderers = new List<MeshRenderer>();

	private void Awake()
	{
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_0093: Expected O, but got Unknown
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_007a: Expected O, but got Unknown
		//IL_00da: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e4: Expected O, but got Unknown
		//IL_0107: Unknown result type (might be due to invalid IL or missing references)
		//IL_011d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0133: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_024c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0253: Expected O, but got Unknown
		//IL_0279: Unknown result type (might be due to invalid IL or missing references)
		//IL_0291: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
		Shader val = Shader.Find("Legacy Shaders/Transparent/Diffuse");
		if ((Object)(object)val == (Object)null)
		{
			val = Shader.Find("Transparent/Diffuse");
		}
		if ((Object)(object)val == (Object)null)
		{
			val = Shader.Find("UI/Default");
		}
		if ((Object)(object)val == (Object)null)
		{
			val = Shader.Find("Standard");
		}
		if ((Object)(object)val != (Object)null)
		{
			m_material = new Material(val);
		}
		else
		{
			m_material = new Material(Shader.Find("Sprites/Default"));
		}
		if (m_material.HasProperty("_Color"))
		{
			m_material.color = new Color(0.1f, 0.9f, 0.5f, 0.35f);
		}
		m_highlightRoot = new GameObject("MovingDaySelectionHighlightRoot");
		m_highlightRoot.transform.SetParent(((Component)this).transform, false);
		m_highlightRoot.transform.localPosition = Vector3.zero;
		m_highlightRoot.transform.localRotation = Quaternion.identity;
		m_highlightRoot.transform.localScale = Vector3.one;
		MeshFilter[] componentsInChildren = ((Component)this).GetComponentsInChildren<MeshFilter>(true);
		MeshFilter[] array = componentsInChildren;
		foreach (MeshFilter val2 in array)
		{
			if ((Object)(object)val2 == (Object)null || (Object)(object)val2.sharedMesh == (Object)null)
			{
				continue;
			}
			Renderer component = ((Component)val2).GetComponent<Renderer>();
			if (!((Object)(object)component == (Object)null) && component.enabled && ((Component)component).gameObject.activeInHierarchy)
			{
				string text = ((Object)((Component)val2).gameObject).name.ToLower();
				if (!text.Contains("collision") && !text.Contains("collider") && !text.Contains("trigger") && !text.Contains("preview") && !text.Contains("ghost") && !text.Contains("helper") && !text.Contains("dummy"))
				{
					G