Decompiled source of Renovator v0.6.2

BepInEx\plugins\Renovator\InfernoProtocol.Renovator.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text.Json;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using FrankMods;
using Game.Data;
using Game.Effects;
using Game.LevelOperations;
using Game.PlayerOperations;
using Game.UI;
using HarmonyLib;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.Attributes;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using SaveSystem;
using TMPro;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.InputSystem.LowLevel;
using UnityEngine.InputSystem.Utilities;
using UnityEngine.Rendering;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("InfernoProtocol.Renovator")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.6.2.0")]
[assembly: AssemblyInformationalVersion("0.6.2+42c07716b0f1760aa9b937f1baf249ddeb6011f6")]
[assembly: AssemblyProduct("InfernoProtocol.Renovator")]
[assembly: AssemblyTitle("InfernoProtocol.Renovator")]
[assembly: AssemblyVersion("0.6.2.0")]
namespace InfernoProtocol.Renovator;

public sealed class RenovatorChoice
{
	public int Pattern { get; set; }

	public int Scale { get; set; } = 1;
}
public sealed class RenovatorController : MonoBehaviour
{
	private static readonly float[] MoveSteps = new float[5] { 0.05f, 0.1f, 0.25f, 0.5f, 1f };

	private static readonly float[] AngleSteps = new float[5] { 1f, 5f, 15f, 45f, 90f };

	private static readonly float[] FreeSpeeds = new float[5] { 0.35f, 0.7f, 1.35f, 2.5f, 4f };

	private static readonly Dictionary<Items, bool> Eligibility = new Dictionary<Items, bool>();

	private readonly Dictionary<int, APlacable> _pieces = new Dictionary<int, APlacable>();

	private readonly Dictionary<string, APlacable> _piecesByKey = new Dictionary<string, APlacable>(StringComparer.Ordinal);

	private readonly Dictionary<int, RenovatorFinish> _applied = new Dictionary<int, RenovatorFinish>();

	private readonly Dictionary<string, RenovatorChoice> _networkChoices = new Dictionary<string, RenovatorChoice>(StringComparer.Ordinal);

	private readonly Dictionary<string, (Vector3 Position, Quaternion Rotation)> _pendingMoves = new Dictionary<string, (Vector3, Quaternion)>(StringComparer.Ordinal);

	private readonly HashSet<string> _snapshotChoices = new HashSet<string>(StringComparer.Ordinal);

	private readonly HashSet<int> _pendingRestore = new HashSet<int>();

	private readonly HashSet<int> _failed = new HashSet<int>();

	private readonly List<int> _completed = new List<int>();

	private readonly List<string> _staleChoices = new List<string>();

	private Dictionary<string, RenovatorChoice> _saved = new Dictionary<string, RenovatorChoice>();

	private readonly Texture2D[] _textures = (Texture2D[])(object)new Texture2D[RenovatorPatterns.Names.Length];

	private readonly Texture2D[] _thumbnails = (Texture2D[])(object)new Texture2D[RenovatorPatterns.Names.Length];

	private readonly RenovatorTargetCue _cue = new RenovatorTargetCue();

	private readonly RenovatorLookMaterialOverride _lookMaterialOverride = new RenovatorLookMaterialOverride();

	private readonly RenovatorPlacementPreview _placementPreview = new RenovatorPlacementPreview();

	private readonly List<InputActionMap> _maps = new List<InputActionMap>();

	private readonly List<InputAction> _disabled = new List<InputAction>();

	private RenovatorHomePanel _homeUi;

	private RenovatorPanel _ui;

	private RenovatorMovePanel _moveUi;

	private GameObject _inputBlocker;

	private APlacable _target;

	private APlacable _moveTarget;

	private Vector3 _moveStartPosition;

	private Quaternion _moveStartRotation;

	private Vector3 _movePrecisionOffset;

	private Vector3 _nativeBasePosition;

	private Vector3 _lastPreviewPosition;

	private Quaternion _nativeBaseRotation;

	private Quaternion _lastPreviewRotation;

	private string _file;

	private float _nextTarget;

	private float _nextWorld;

	private float _nextRestore;

	private float _nextMoveUiRefresh;

	private float _nextInputMaintenance;

	private float _nextHighlightMaintenance;

	private float _opened;

	private float _moveRepeat;

	private int _moveDirection;

	private int _moveStepIndex;

	private int _moveAngleIndex;

	private int _nativePlacementFrame = -1;

	private bool _scanned;

	private bool _faulted;

	private bool _reported;

	private bool _release;

	private bool _look;

	private bool _move;

	private bool _cursor;

	private bool _inputCaptured;

	private bool _moveBlocked;

	private bool _moveController;

	private bool _moveMouseLook;

	private bool _previewPoseReady;

	private bool _previewPoseApplied;

	private bool _readyThisFrame;

	private bool _hammerThisFrame;

	private bool _highlightSuppression;

	private bool _moveInputStateKnown;

	private bool _moveInputAllowsLook;

	private CursorLockMode _lock;

	private readonly RenovatorNetworkSync _networkSync;

	internal bool Editing => _inputCaptured;

	public RenovatorController(IntPtr pointer)
		: base(pointer)
	{
		_networkSync = new RenovatorNetworkSync(() => _file != null && !_faulted, () => _saved, BeginNetworkSnapshot, ReceiveNetworkFinish, ReceiveNetworkMove, EndNetworkSnapshot, ClearNetworkState);
	}

	internal void Register(APlacable piece)
	{
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)piece == (Object)null) && piece.placableId != 0L)
		{
			int instanceID = ((Object)piece).GetInstanceID();
			bool num = !_pieces.ContainsKey(instanceID);
			_pieces[instanceID] = piece;
			string key = Key(piece);
			_piecesByKey[key] = piece;
			if (_pendingMoves.Remove(key, out (Vector3, Quaternion) value))
			{
				((Component)piece).transform.SetPositionAndRotation(value.Item1, value.Item2);
				Physics.SyncTransforms();
			}
			if (num && Eligible(piece.placableItem))
			{
				_pendingRestore.Add(instanceID);
			}
		}
	}

	internal void Forget(APlacable piece)
	{
		if (!((Object)(object)piece == (Object)null))
		{
			if ((Object)(object)piece == (Object)(object)_moveTarget)
			{
				CancelMove();
			}
			if ((Object)(object)piece == (Object)(object)_target)
			{
				SetTarget(null);
			}
			int instanceID = ((Object)piece).GetInstanceID();
			if (_applied.Remove(instanceID, out var value))
			{
				value.Dispose();
			}
			_piecesByKey.Remove(Key(piece));
			_pieces.Remove(instanceID);
			_pendingRestore.Remove(instanceID);
			_failed.Remove(instanceID);
		}
	}

	internal bool SuppressHammerHighlight(Renderer renderer)
	{
		if ((Object)(object)renderer == (Object)null || !RenovatorPlugin.Enabled.Value || !Hammer())
		{
			return false;
		}
		try
		{
			EffectManager.UnhighlightRenderer(renderer);
		}
		catch
		{
		}
		return true;
	}

	private bool Ready()
	{
		if (RenovatorPlugin.Enabled.Value && Player.isLocalPlayerLoaded && (Object)(object)Player.localPlayer != (Object)null && ((NetworkBehaviour)Player.localPlayer).IsServer)
		{
			return !((ANetworkEntity)Player.localPlayer).isDead;
		}
		return false;
	}

	private bool Hammer()
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Invalid comparison between Unknown and I4
		if ((Object)(object)Player.localPlayer != (Object)null)
		{
			return (int)Player.localPlayer.currentItemData.item == 196;
		}
		return false;
	}

	private static bool CanMove(APlacable piece)
	{
		if ((Object)(object)piece != (Object)null && piece.placableId != 0L)
		{
			return (Object)(object)((Component)piece).transform != (Object)null;
		}
		return false;
	}

	private static bool CanRenovate(APlacable piece)
	{
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)piece != (Object)null && piece.placableId != 0L && (Object)(object)piece.objectRenderer != (Object)null)
		{
			return Eligible(piece.placableItem);
		}
		return false;
	}

	private unsafe static bool Eligible(Items item)
	{
		//IL_0005: 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)
		if (Eligibility.TryGetValue(item, out var value))
		{
			return value;
		}
		value = RenovatorPatterns.Eligible(((object)(*(Items*)(&item))/*cast due to .constrained prefix*/).ToString());
		Eligibility[item] = value;
		return value;
	}

	private static string Key(APlacable piece)
	{
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		return piece.interiorIndex + ":" + piece.placableId + ":" + ((object)piece.placableItem/*cast due to .constrained prefix*/).ToString();
	}

	private void SetTarget(APlacable piece)
	{
		if (!((Object)(object)piece == (Object)(object)_target))
		{
			_target = piece;
			if ((Object)(object)piece == (Object)null)
			{
				_cue.Hide();
			}
			else
			{
				_cue.Show(piece);
			}
		}
	}

	private void Update()
	{
		//IL_05c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_05d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0676: Unknown result type (might be due to invalid IL or missing references)
		//IL_0686: Unknown result type (might be due to invalid IL or missing references)
		//IL_0748: Unknown result type (might be due to invalid IL or missing references)
		//IL_0754: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			float unscaledTime = Time.unscaledTime;
			bool flag = RenovatorPlugin.Enabled.Value && Player.isLocalPlayerLoaded && (Object)(object)Player.localPlayer != (Object)null;
			_networkSync.Tick(flag);
			if (_release && Released())
			{
				ReleaseInput();
			}
			_readyThisFrame = Ready();
			_hammerThisFrame = _readyThisFrame && Hammer();
			if (flag && _networkSync.IsRemoteClient)
			{
				if (!_scanned)
				{
					_scanned = true;
					foreach (APlacable item in Object.FindObjectsOfType<APlacable>(false))
					{
						Register(item);
					}
				}
				if (_pendingRestore.Count > 0 && unscaledTime >= _nextRestore)
				{
					_nextRestore = unscaledTime + 0.1f;
					RestorePending();
				}
				RenovatorHomePanel homeUi = _homeUi;
				if (homeUi != null && homeUi.Open)
				{
					CloseHome();
				}
				RenovatorPanel ui = _ui;
				if (ui != null && ui.Open)
				{
					Close(committed: false);
				}
				RenovatorMovePanel moveUi = _moveUi;
				if (moveUi != null && moveUi.Open)
				{
					CancelMove();
				}
				SetTarget(null);
				_ui?.Prompt(show: false);
				return;
			}
			if (!_readyThisFrame)
			{
				RenovatorHomePanel homeUi2 = _homeUi;
				if (homeUi2 != null && homeUi2.Open)
				{
					CloseHome();
				}
				RenovatorPanel ui2 = _ui;
				if (ui2 != null && ui2.Open)
				{
					Close(committed: false);
				}
				RenovatorMovePanel moveUi2 = _moveUi;
				if (moveUi2 != null && moveUi2.Open)
				{
					CancelMove();
				}
				SetTarget(null);
				_ui?.Prompt(show: false);
				if (!Player.isLocalPlayerLoaded && (_file != null || _scanned))
				{
					ResetWorld();
				}
				return;
			}
			if (unscaledTime >= _nextWorld)
			{
				_nextWorld = unscaledTime + 1f;
				string saveFile = SaveManager.GetSaveFile("Renovator.v1.json");
				if (saveFile != _file)
				{
					ResetWorld();
					if (string.IsNullOrWhiteSpace(saveFile))
					{
						return;
					}
					_file = saveFile;
					try
					{
						if (!File.Exists(saveFile))
						{
							string[] array = new string[2] { "Rennovator.v1.json", "Wallpaper.v1.json" };
							for (int i = 0; i < array.Length; i++)
							{
								string saveFile2 = SaveManager.GetSaveFile(array[i]);
								if (!string.IsNullOrWhiteSpace(saveFile2) && File.Exists(saveFile2))
								{
									File.Copy(saveFile2, saveFile);
									RenovatorPlugin.Logger.LogInfo((object)"Existing surface finishes migrated to Renovator.");
									break;
								}
							}
						}
						_saved = (File.Exists(saveFile) ? JsonSerializer.Deserialize<Dictionary<string, RenovatorChoice>>(File.ReadAllText(saveFile)) : new Dictionary<string, RenovatorChoice>());
						if (_saved == null)
						{
							throw new InvalidDataException("Empty wallpaper save");
						}
						_staleChoices.Clear();
						foreach (KeyValuePair<string, RenovatorChoice> item2 in _saved)
						{
							RenovatorChoice value = item2.Value;
							if (value == null || !RenovatorPatterns.StoredChoiceValid(value.Pattern, value.Scale))
							{
								throw new InvalidDataException("Invalid wallpaper choice");
							}
							if (!RenovatorPatterns.Available(value.Pattern))
							{
								_staleChoices.Add(item2.Key);
							}
						}
						foreach (string staleChoice in _staleChoices)
						{
							_saved.Remove(staleChoice);
						}
						if (_staleChoices.Count > 0)
						{
							WriteChoices(_saved);
							RenovatorPlugin.Logger.LogInfo((object)("Removed " + _staleChoices.Count + " retired surface finish preference(s)."));
						}
					}
					catch (Exception ex)
					{
						_faulted = true;
						RenovatorPlugin.Logger.LogError((object)("Renovator preferences could not be read; preserving file and disabling writes: " + ex.Message));
					}
					if (!_faulted)
					{
						_networkSync.BroadcastSnapshot();
					}
				}
			}
			if (_file == null || _faulted)
			{
				return;
			}
			if (!_scanned)
			{
				_scanned = true;
				foreach (APlacable item3 in Object.FindObjectsOfType<APlacable>(false))
				{
					Register(item3);
				}
			}
			if (_pendingRestore.Count > 0 && unscaledTime >= _nextRestore)
			{
				_nextRestore = unscaledTime + 0.1f;
				RestorePending();
			}
			RenovatorMovePanel moveUi3 = _moveUi;
			if (moveUi3 != null && moveUi3.Open)
			{
				if (!Application.isFocused || !_hammerThisFrame || (Object)(object)_moveTarget == (Object)null || (Object)(object)Player.mainCamera == (Object)null || !((Component)_moveTarget).gameObject.activeInHierarchy || PlayerInventoryUI.isOpen || (!_moveBlocked && !_placementPreview.Active))
				{
					CancelMove();
					return;
				}
				UpdateMoveControlMode();
				MaintainMoveInput();
				if (unscaledTime - _opened > 0.25f)
				{
					MoveTick();
				}
				return;
			}
			RenovatorHomePanel homeUi3 = _homeUi;
			if (homeUi3 != null && homeUi3.Open)
			{
				if (!Application.isFocused || !_hammerThisFrame || (!CanMove(_target) && !CanRenovate(_target)) || (Object)(object)Player.mainCamera == (Object)null || !((Component)_target).gameObject.activeInHierarchy || PlayerInventoryUI.isOpen || Vector3.Distance(((Component)Player.mainCamera).transform.position, ((Component)_target).transform.position) > 5f)
				{
					CloseHome();
					return;
				}
				MaintainInputLock();
				if (unscaledTime - _opened > 0.25f)
				{
					_homeUi.Tick();
				}
				return;
			}
			RenovatorPanel ui3 = _ui;
			if (ui3 != null && ui3.Open)
			{
				if (!Application.isFocused || !_hammerThisFrame || !CanRenovate(_target) || (Object)(object)Player.mainCamera == (Object)null || !((Component)_target).gameObject.activeInHierarchy || PlayerInventoryUI.isOpen || Vector3.Distance(((Component)Player.mainCamera).transform.position, ((Component)_target).transform.position) > 5f)
				{
					Close(committed: false);
					return;
				}
				MaintainInputLock();
				if (unscaledTime - _opened > 0.25f)
				{
					_ui.Tick();
				}
				return;
			}
			if (_release || !_hammerThisFrame || !Application.isFocused || Cursor.visible || PlayerInventoryUI.isOpen || SkillWheelManager.isOpen)
			{
				SetTarget(null);
				_ui?.Prompt(show: false);
				return;
			}
			if (unscaledTime >= _nextTarget)
			{
				_nextTarget = unscaledTime + 0.08f;
				APlacable target = null;
				Camera mainCamera = Player.mainCamera;
				RaycastHit val = default(RaycastHit);
				if ((Object)(object)mainCamera != (Object)null && Physics.Raycast(((Component)mainCamera).transform.position, ((Component)mainCamera).transform.forward, ref val, 2.7f, -1, (QueryTriggerInteraction)1))
				{
					APlacable componentInParent = ((Component)((RaycastHit)(ref val)).collider).GetComponentInParent<APlacable>();
					if ((Object)(object)componentInParent != (Object)null && ((Object)(object)componentInParent.objectMeshFilter != (Object)null || (Object)(object)componentInParent.objectRenderer != (Object)null))
					{
						target = componentInParent;
						if (CanMove(componentInParent))
						{
							Register(componentInParent);
						}
					}
				}
				SetTarget(target);
				bool flag2 = CanMove(_target) || CanRenovate(_target);
				if (flag2)
				{
					EnsureUI();
				}
				_ui?.Prompt(flag2);
			}
			if (!CanMove(_target) && !CanRenovate(_target))
			{
				return;
			}
			if (!RenovatorPlugin.EditorKeyPressed(Keyboard.current))
			{
				Mouse current5 = Mouse.current;
				if ((current5 == null || !current5.middleButton.wasPressedThisFrame) && !RenovatorPlugin.EditorControllerPressed(Gamepad.current))
				{
					return;
				}
			}
			if (!OtherEditorOpen())
			{
				OpenHome();
			}
		}
		catch (Exception ex2)
		{
			RenovatorHomePanel homeUi4 = _homeUi;
			if (homeUi4 != null && homeUi4.Open)
			{
				CloseHome();
			}
			RenovatorPanel ui4 = _ui;
			if (ui4 != null && ui4.Open)
			{
				Close(committed: false);
			}
			RenovatorMovePanel moveUi4 = _moveUi;
			if (moveUi4 != null && moveUi4.Open)
			{
				CancelMove();
			}
			_nextTarget = Time.unscaledTime + 2f;
			if (!_reported)
			{
				RenovatorPlugin.Logger.LogWarning((object)("Renovator waiting/recovering: " + ex2));
				_reported = true;
			}
		}
	}

	private void LateUpdate()
	{
		try
		{
			RenovatorMovePanel moveUi = _moveUi;
			if (moveUi != null && moveUi.Open && !_moveBlocked && _nativePlacementFrame != Time.frameCount)
			{
				FollowPlacementPreview();
			}
		}
		catch (Exception ex)
		{
			if (!_reported)
			{
				RenovatorPlugin.Logger.LogDebug((object)("Move follow deferred: " + ex.Message));
				_reported = true;
			}
		}
		try
		{
			bool flag = _readyThisFrame && _hammerThisFrame;
			float unscaledTime = Time.unscaledTime;
			if (flag != _highlightSuppression || unscaledTime >= _nextHighlightMaintenance)
			{
				_highlightSuppression = flag;
				_nextHighlightMaintenance = unscaledTime + (flag ? 0.1f : 0.5f);
				_lookMaterialOverride.Update(flag);
			}
		}
		catch (Exception ex2)
		{
			if (!_reported)
			{
				RenovatorPlugin.Logger.LogDebug((object)("Hammer highlight suppression deferred: " + ex2.Message));
				_reported = true;
			}
		}
	}

	private void EnsureHomeUI()
	{
		if (_homeUi == null)
		{
			_homeUi = new RenovatorHomePanel(OpenFinishFromHome, OpenMoveFromHome, CloseHome);
		}
	}

	private void EnsureUI()
	{
		if (_ui == null)
		{
			_ui = new RenovatorPanel(Thumbnail, Preview, Save, BackFromFinish);
		}
	}

	private void EnsureMoveUI()
	{
		if (_moveUi == null)
		{
			_moveUi = new RenovatorMovePanel(HandleMoveCommand);
		}
	}

	private void CaptureInput()
	{
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0113: Unknown result type (might be due to invalid IL or missing references)
		//IL_011d: Expected O, but got Unknown
		if (_inputCaptured)
		{
			return;
		}
		PlayerActionContainer actions = PlayerInputDispatcher.actions;
		int look;
		if (actions == null)
		{
			look = 0;
		}
		else
		{
			InputAction look2 = actions.look;
			look = ((((look2 != null) ? new bool?(look2.enabled) : ((bool?)null)) == true) ? 1 : 0);
		}
		_look = (byte)look != 0;
		PlayerActionContainer actions2 = PlayerInputDispatcher.actions;
		int move;
		if (actions2 == null)
		{
			move = 0;
		}
		else
		{
			InputAction move2 = actions2.move;
			move = ((((move2 != null) ? new bool?(move2.enabled) : ((bool?)null)) == true) ? 1 : 0);
		}
		_move = (byte)move != 0;
		_cursor = Cursor.visible;
		_lock = Cursor.lockState;
		InputActionAsset inputActionsAsset = PlayerInputDispatcher.inputActionsAsset;
		ReadOnlyArray<InputActionMap> val = ((inputActionsAsset != null) ? inputActionsAsset.actionMaps : null);
		if (val != null)
		{
			Enumerator<InputActionMap> enumerator = val.GetEnumerator();
			while (enumerator.MoveNext())
			{
				InputActionMap current = enumerator.Current;
				if (!current.enabled)
				{
					continue;
				}
				Enumerator<InputAction> enumerator2 = current.actions.GetEnumerator();
				while (enumerator2.MoveNext())
				{
					InputAction current2 = enumerator2.Current;
					if (!current2.enabled)
					{
						_disabled.Add(current2);
					}
				}
				_maps.Add(current);
				current.Disable();
			}
		}
		_inputBlocker = new GameObject("Renovator_InputBlocker");
		((Object)_inputBlocker).hideFlags = (HideFlags)61;
		_inputCaptured = true;
		_nextInputMaintenance = 0f;
		MaintainInputLock(force: true);
	}

	private void MaintainInputLock(bool force = false)
	{
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		float unscaledTime = Time.unscaledTime;
		if (!force && unscaledTime < _nextInputMaintenance)
		{
			return;
		}
		_nextInputMaintenance = unscaledTime + 0.25f;
		if ((int)Cursor.lockState != 0)
		{
			Cursor.lockState = (CursorLockMode)0;
		}
		if (!Cursor.visible)
		{
			Cursor.visible = true;
		}
		PlayerInputDispatcher.SetEnableLookInput(false);
		InputActionAsset inputActionsAsset = PlayerInputDispatcher.inputActionsAsset;
		ReadOnlyArray<InputActionMap> val = ((inputActionsAsset != null) ? inputActionsAsset.actionMaps : null);
		if (val == null)
		{
			return;
		}
		Enumerator<InputActionMap> enumerator = val.GetEnumerator();
		while (enumerator.MoveNext())
		{
			InputActionMap current = enumerator.Current;
			if (current.enabled)
			{
				current.Disable();
			}
		}
	}

	private void UpdateMoveControlMode()
	{
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: 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_0110: Unknown result type (might be due to invalid IL or missing references)
		//IL_0115: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_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)
		Gamepad current = Gamepad.current;
		Mouse current2 = Mouse.current;
		Keyboard current3 = Keyboard.current;
		Vector2 val;
		int num;
		if (current != null)
		{
			val = ((InputControl<Vector2>)(object)current.leftStick).ReadValue();
			if (!(((Vector2)(ref val)).sqrMagnitude > 0.02f))
			{
				val = ((InputControl<Vector2>)(object)current.rightStick).ReadValue();
				if (!(((Vector2)(ref val)).sqrMagnitude > 0.02f))
				{
					val = ((InputControl<Vector2>)(object)current.dpad).ReadValue();
					if (!(((Vector2)(ref val)).sqrMagnitude > 0.01f) && !current.buttonSouth.wasPressedThisFrame && !current.buttonEast.wasPressedThisFrame && !current.buttonWest.wasPressedThisFrame && !current.buttonNorth.wasPressedThisFrame && !current.leftShoulder.isPressed && !current.rightShoulder.isPressed && !current.leftStickButton.wasPressedThisFrame && !current.rightStickButton.wasPressedThisFrame && !(((InputControl<float>)(object)current.leftTrigger).ReadValue() > 0.1f))
					{
						num = ((((InputControl<float>)(object)current.rightTrigger).ReadValue() > 0.1f) ? 1 : 0);
						goto IL_0107;
					}
				}
			}
			num = 1;
		}
		else
		{
			num = 0;
		}
		goto IL_0107;
		IL_0107:
		int num2;
		if (current2 != null)
		{
			val = ((InputControl<Vector2>)(object)((Pointer)current2).delta).ReadValue();
			if (!(((Vector2)(ref val)).sqrMagnitude > 16f) && !current2.leftButton.isPressed && !current2.rightButton.isPressed && !current2.middleButton.isPressed)
			{
				val = ((InputControl<Vector2>)(object)current2.scroll).ReadValue();
				num2 = ((((Vector2)(ref val)).sqrMagnitude > 0.01f) ? 1 : 0);
			}
			else
			{
				num2 = 1;
			}
		}
		else
		{
			num2 = 0;
		}
		bool flag = (byte)num2 != 0;
		bool flag2 = current3 != null && (((ButtonControl)current3.iKey).isPressed || ((ButtonControl)current3.jKey).isPressed || ((ButtonControl)current3.kKey).isPressed || ((ButtonControl)current3.lKey).isPressed || ((ButtonControl)current3.rKey).isPressed || ((ButtonControl)current3.fKey).isPressed || ((ButtonControl)current3.qKey).isPressed || ((ButtonControl)current3.eKey).isPressed || ((ButtonControl)current3.leftAltKey).isPressed);
		if (num != 0)
		{
			_moveController = true;
		}
		else if (flag || flag2)
		{
			_moveController = false;
		}
		_moveMouseLook = !_moveController && (current3 == null || !((ButtonControl)current3.leftAltKey).isPressed);
		_moveUi?.SetInputHint(_moveController, _moveMouseLook);
	}

	private void MaintainMoveInput()
	{
		//IL_0121: Unknown result type (might be due to invalid IL or missing references)
		//IL_0123: Unknown result type (might be due to invalid IL or missing references)
		//IL_0128: Unknown result type (might be due to invalid IL or missing references)
		//IL_012c: Unknown result type (might be due to invalid IL or missing references)
		PlayerActionContainer actions = PlayerInputDispatcher.actions;
		InputAction val = ((actions != null) ? actions.move : null);
		PlayerActionContainer actions2 = PlayerInputDispatcher.actions;
		InputAction val2 = ((actions2 != null) ? actions2.look : null);
		bool flag = _moveController || _moveMouseLook;
		float unscaledTime = Time.unscaledTime;
		if (_moveInputStateKnown && _moveInputAllowsLook == flag && unscaledTime < _nextInputMaintenance)
		{
			return;
		}
		_moveInputStateKnown = true;
		_moveInputAllowsLook = flag;
		_nextInputMaintenance = unscaledTime + 0.25f;
		InputActionAsset inputActionsAsset = PlayerInputDispatcher.inputActionsAsset;
		ReadOnlyArray<InputActionMap> val3 = ((inputActionsAsset != null) ? inputActionsAsset.actionMaps : null);
		if (val3 != null)
		{
			Enumerator<InputActionMap> enumerator = val3.GetEnumerator();
			while (enumerator.MoveNext())
			{
				Enumerator<InputAction> enumerator2 = enumerator.Current.actions.GetEnumerator();
				while (enumerator2.MoveNext())
				{
					InputAction current = enumerator2.Current;
					if (current.enabled && current != val && current != val2)
					{
						current.Disable();
					}
				}
			}
		}
		if (val != null && !val.enabled)
		{
			val.Enable();
		}
		if (val2 != null && val2.enabled != flag)
		{
			if (flag)
			{
				val2.Enable();
			}
			else
			{
				val2.Disable();
			}
		}
		PlayerInputDispatcher.SetEnableLookInput(flag);
		CursorLockMode val4 = (CursorLockMode)(flag ? 1 : 0);
		if (Cursor.lockState != val4)
		{
			Cursor.lockState = val4;
		}
		if (Cursor.visible == flag)
		{
			Cursor.visible = !flag;
		}
	}

	private static bool OtherEditorOpen()
	{
		if ((Object)(object)GameObject.Find("Artistic_InputBlocker") != (Object)null)
		{
			return true;
		}
		GameObject obj = GameObject.Find("BetterLights_Canvas");
		if (obj == null)
		{
			return false;
		}
		Transform obj2 = obj.transform.Find("Picker");
		return ((obj2 != null) ? new bool?(((Component)obj2).gameObject.activeInHierarchy) : ((bool?)null)) == true;
	}

	internal Texture2D Texture(int pattern)
	{
		if ((Object)(object)_textures[pattern] != (Object)null)
		{
			return _textures[pattern];
		}
		_textures[pattern] = GenerateTexture(pattern, 512, mipmaps: true, 4, "Renovator_Surface_");
		return _textures[pattern];
	}

	private Texture2D Thumbnail(int pattern)
	{
		if ((Object)(object)_thumbnails[pattern] != (Object)null)
		{
			return _thumbnails[pattern];
		}
		_thumbnails[pattern] = GenerateTexture(pattern, 128, mipmaps: false, 1, "Renovator_Thumbnail_");
		return _thumbnails[pattern];
	}

	private static Texture2D GenerateTexture(int pattern, int size, bool mipmaps, int anisotropy, string prefix)
	{
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: 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_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: Expected O, but got Unknown
		Color32[] array = (Color32[])(object)new Color32[size * size];
		for (int i = 0; i < size; i++)
		{
			for (int j = 0; j < size; j++)
			{
				(float, float, float) tuple = RenovatorPatterns.Sample(pattern, ((float)j + 0.5f) / (float)size, ((float)i + 0.5f) / (float)size);
				array[i * size + j] = Color32.op_Implicit(new Color(tuple.Item1, tuple.Item2, tuple.Item3, 1f));
			}
		}
		Texture2D val = new Texture2D(size, size, (TextureFormat)4, mipmaps)
		{
			name = prefix + pattern,
			wrapMode = (TextureWrapMode)0,
			filterMode = (FilterMode)((!mipmaps) ? 1 : 2),
			anisoLevel = anisotropy
		};
		val.SetPixels32(Il2CppStructArray<Color32>.op_Implicit(array));
		val.Apply(mipmaps, true);
		return val;
	}

	[HideFromIl2Cpp]
	private RenovatorFinish Finish(APlacable piece)
	{
		int instanceID = ((Object)piece).GetInstanceID();
		if (!_applied.TryGetValue(instanceID, out var value))
		{
			value = new RenovatorFinish(piece);
			_applied.Add(instanceID, value);
		}
		return value;
	}

	private void RestorePending()
	{
		//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
		int num = 0;
		_completed.Clear();
		_staleChoices.Clear();
		foreach (int item in _pendingRestore)
		{
			if (!_pieces.TryGetValue(item, out var value) || (Object)(object)value == (Object)null)
			{
				_completed.Add(item);
				_pieces.Remove(item);
				_failed.Remove(item);
			}
			else
			{
				if (!((Component)value).gameObject.activeInHierarchy || (Object)(object)value.objectRenderer == (Object)null)
				{
					continue;
				}
				if (_applied.ContainsKey(item) || _failed.Contains(item))
				{
					_completed.Add(item);
					continue;
				}
				string text = Key(value);
				if (!(_networkSync.IsRemoteClient ? _networkChoices : _saved).TryGetValue(text, out var value2) || value2.Pattern == 0)
				{
					_completed.Add(item);
				}
				else if (!_networkSync.IsRemoteClient && !value.loadedFromSave)
				{
					_staleChoices.Add(text);
					_completed.Add(item);
				}
				else
				{
					if (num >= 4)
					{
						continue;
					}
					num++;
					try
					{
						Finish(value).Apply(Texture(value2.Pattern), value2.Pattern, value2.Scale);
						_completed.Add(item);
					}
					catch (Exception ex)
					{
						if (_applied.Remove(item, out var value3))
						{
							value3.Dispose();
						}
						_failed.Add(item);
						_completed.Add(item);
						RenovatorPlugin.Logger.LogWarning((object)("Renovator restore skipped " + ((object)value.placableItem/*cast due to .constrained prefix*/).ToString() + ": " + ex.Message));
					}
				}
			}
		}
		foreach (int item2 in _completed)
		{
			_pendingRestore.Remove(item2);
		}
		if (_staleChoices.Count == 0)
		{
			return;
		}
		Dictionary<string, RenovatorChoice> dictionary = new Dictionary<string, RenovatorChoice>(_saved);
		foreach (string staleChoice in _staleChoices)
		{
			dictionary.Remove(staleChoice);
		}
		try
		{
			WriteChoices(dictionary);
			_saved = dictionary;
			RenovatorPlugin.Logger.LogInfo((object)("Renovator removed " + _staleChoices.Count + " stale placed-piece preference(s)."));
		}
		catch (Exception ex2)
		{
			_faulted = true;
			RenovatorPlugin.Logger.LogError((object)("Stale wallpaper preferences could not be cleaned safely; writes disabled: " + ex2.Message));
		}
	}

	private void OpenHome()
	{
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		if (CanMove(_target) || CanRenovate(_target))
		{
			EnsureHomeUI();
			CaptureInput();
			string target = ((object)_target.placableItem/*cast due to .constrained prefix*/).ToString().Replace('_', ' ');
			_homeUi.Show(target, CanRenovate(_target));
			_ui?.Prompt(show: false);
			_opened = Time.unscaledTime;
		}
	}

	private void OpenFinishFromHome()
	{
		if (!CanRenovate(_target))
		{
			CloseHome();
		}
		else
		{
			OpenFinish();
		}
	}

	private void BackFromFinish()
	{
		Close(committed: false, releaseInput: false);
		if (CanReturnHome())
		{
			ShowHomeWithoutCapture();
		}
		else
		{
			_release = true;
		}
	}

	private void OpenMoveFromHome()
	{
		if (!CanMove(_target))
		{
			CloseHome();
		}
		else
		{
			BeginMove(inputCaptured: true);
		}
	}

	private void CloseHome()
	{
		_homeUi?.Hide();
		if (_inputCaptured)
		{
			_release = true;
		}
	}

	private void ShowHomeWithoutCapture()
	{
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		EnsureHomeUI();
		string target = ((object)_target.placableItem/*cast due to .constrained prefix*/).ToString().Replace('_', ' ');
		_homeUi.Show(target, CanRenovate(_target));
		_opened = Time.unscaledTime;
	}

	private bool CanReturnHome()
	{
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		if (CanMove(_target) && Hammer() && Application.isFocused && !PlayerInventoryUI.isOpen && (Object)(object)Player.mainCamera != (Object)null && ((Component)_target).gameObject.activeInHierarchy)
		{
			return Vector3.Distance(((Component)Player.mainCamera).transform.position, ((Component)_target).transform.position) <= 5f;
		}
		return false;
	}

	private void OpenFinish()
	{
		//IL_008d: 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)
		if (!CanRenovate(_target))
		{
			return;
		}
		EnsureUI();
		CaptureInput();
		_saved.TryGetValue(Key(_target), out var value);
		_ui.Show(value?.Pattern ?? 0, value?.Scale ?? 1);
		_opened = Time.unscaledTime;
		try
		{
			Finish(_target);
		}
		catch (Exception ex)
		{
			_ui.Message(ex.Message);
			RenovatorPlugin.Logger.LogWarning((object)(((object)_target.placableItem/*cast due to .constrained prefix*/).ToString() + ": " + ex.Message));
		}
	}

	private void BeginMove(bool inputCaptured)
	{
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_00de: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0157: 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)
		if (CanMove(_target))
		{
			if (!inputCaptured)
			{
				CaptureInput();
			}
			EnsureMoveUI();
			_moveTarget = _target;
			_moveStartPosition = ((Component)_target).transform.position;
			_moveStartRotation = ((Component)_target).transform.rotation;
			_moveStepIndex = Math.Clamp(RenovatorPlugin.MoveStepIndex.Value, 0, MoveSteps.Length - 1);
			_moveAngleIndex = Math.Clamp(RenovatorPlugin.AngleStepIndex.Value, 0, AngleSteps.Length - 1);
			bool flag = HasStoredItems(_moveTarget);
			string error = null;
			bool flag2 = !flag && _placementPreview.Begin(_moveTarget, out error);
			_moveBlocked = flag || !flag2;
			_moveDirection = 0;
			_nextMoveUiRefresh = 0f;
			_movePrecisionOffset = Vector3.zero;
			_previewPoseReady = false;
			_previewPoseApplied = false;
			_nativePlacementFrame = -1;
			_moveInputStateKnown = false;
			_nextInputMaintenance = 0f;
			RenovatorHomePanel homeUi = _homeUi;
			int moveController;
			if (homeUi == null || !homeUi.Controller)
			{
				Gamepad current = Gamepad.current;
				moveController = ((current != null && current.rightStickButton.isPressed) ? 1 : 0);
			}
			else
			{
				moveController = 1;
			}
			_moveController = (byte)moveController != 0;
			_moveMouseLook = !_moveController;
			string item = ((object)_moveTarget.placableItem/*cast due to .constrained prefix*/).ToString().Replace('_', ' ');
			string message = (flag ? "Storage contains items. Empty it before moving." : ((!flag2) ? error : "Aim exactly as you do while building. Compatible edges snap automatically."));
			_moveUi.Show(item, _moveBlocked, message);
			_moveUi.SetInputHint(_moveController, _moveMouseLook);
			RefreshMove();
			_ui?.Prompt(show: false);
			_opened = Time.unscaledTime;
		}
	}

	private static bool HasStoredItems(APlacable piece)
	{
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)piece == (Object)null || ItemStash.allStashes == null)
		{
			return false;
		}
		Enumerator<ItemStash> enumerator = ItemStash.allStashes.GetEnumerator();
		while (enumerator.MoveNext())
		{
			ItemStash current = enumerator.Current;
			if ((Object)(object)current == (Object)null || (Object)(object)((ANetworkPlacable)current).attachedPlacable != (Object)(object)piece || current.inventory == null)
			{
				continue;
			}
			for (int i = 0; i < current.inventory.Count; i++)
			{
				if (current.inventory[i].count > 0)
				{
					return true;
				}
			}
		}
		return false;
	}

	private void MoveTick()
	{
		//IL_0394: Unknown result type (might be due to invalid IL or missing references)
		//IL_0387: Unknown result type (might be due to invalid IL or missing references)
		//IL_0399: Unknown result type (might be due to invalid IL or missing references)
		//IL_039b: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_03fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_04f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_04f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0501: Unknown result type (might be due to invalid IL or missing references)
		//IL_0508: Unknown result type (might be due to invalid IL or missing references)
		//IL_050f: Unknown result type (might be due to invalid IL or missing references)
		//IL_052b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0532: Unknown result type (might be due to invalid IL or missing references)
		//IL_0539: Unknown result type (might be due to invalid IL or missing references)
		//IL_0540: Unknown result type (might be due to invalid IL or missing references)
		if (!_moveController && !_moveMouseLook)
		{
			_moveUi.Tick();
		}
		RenovatorMovePanel moveUi = _moveUi;
		if (moveUi == null || !moveUi.Open)
		{
			return;
		}
		Keyboard current = Keyboard.current;
		Gamepad current2 = Gamepad.current;
		Mouse current3 = Mouse.current;
		if ((current != null && ((ButtonControl)current.escapeKey).wasPressedThisFrame) || (current2 != null && current2.buttonEast.wasPressedThisFrame))
		{
			CancelMove(returnHome: true);
		}
		else if ((current != null && ((ButtonControl)current.enterKey).wasPressedThisFrame) || (current2 != null && current2.buttonSouth.wasPressedThisFrame) || (_moveMouseLook && current3 != null && current3.leftButton.wasPressedThisFrame))
		{
			if (_moveBlocked)
			{
				CancelMove(returnHome: true);
			}
			else
			{
				ApplyMove();
			}
		}
		else
		{
			if (_moveBlocked)
			{
				return;
			}
			if ((current != null && ((ButtonControl)current.gKey).wasPressedThisFrame) || (current2 != null && current2.buttonWest.wasPressedThisFrame))
			{
				HandleMoveCommand(RenovatorMoveCommand.ToggleSnap);
			}
			if ((current != null && ((ButtonControl)current.homeKey).wasPressedThisFrame) || (current2 != null && current2.buttonNorth.wasPressedThisFrame))
			{
				HandleMoveCommand(RenovatorMoveCommand.Reset);
			}
			if ((current != null && ((ButtonControl)current.zKey).wasPressedThisFrame) || (current2 != null && current2.leftStickButton.wasPressedThisFrame))
			{
				HandleMoveCommand(RenovatorMoveCommand.CycleStep);
			}
			if ((current != null && ((ButtonControl)current.cKey).wasPressedThisFrame) || (current2 != null && current2.rightStickButton.wasPressedThisFrame))
			{
				HandleMoveCommand(RenovatorMoveCommand.CycleAngle);
			}
			if (RenovatorPlugin.MoveSnap.Value)
			{
				int num = (((current != null && ((ButtonControl)current.iKey).isPressed) || (current2 != null && current2.dpad.up.isPressed)) ? 1 : 0) | (((current != null && ((ButtonControl)current.kKey).isPressed) || (current2 != null && current2.dpad.down.isPressed)) ? 2 : 0) | (((current != null && ((ButtonControl)current.jKey).isPressed) || (current2 != null && current2.dpad.left.isPressed)) ? 4 : 0) | (((current != null && ((ButtonControl)current.lKey).isPressed) || (current2 != null && current2.dpad.right.isPressed)) ? 8 : 0) | (((current != null && ((ButtonControl)current.rKey).isPressed) || ((current2 != null) ? ((InputControl<float>)(object)current2.rightTrigger).ReadValue() : 0f) > 0.55f) ? 16 : 0) | (((current != null && ((ButtonControl)current.fKey).isPressed) || ((current2 != null) ? ((InputControl<float>)(object)current2.leftTrigger).ReadValue() : 0f) > 0.55f) ? 32 : 0) | (((current != null && ((ButtonControl)current.qKey).isPressed) || (current2 != null && current2.leftShoulder.isPressed)) ? 64 : 0) | (((current != null && ((ButtonControl)current.eKey).isPressed) || (current2 != null && current2.rightShoulder.isPressed)) ? 128 : 0);
				if (num != 0 && (num != _moveDirection || Time.unscaledTime >= _moveRepeat))
				{
					if ((num & 1) != 0)
					{
						HandleMoveCommand(RenovatorMoveCommand.Forward);
					}
					if ((num & 2) != 0)
					{
						HandleMoveCommand(RenovatorMoveCommand.Back);
					}
					if ((num & 4) != 0)
					{
						HandleMoveCommand(RenovatorMoveCommand.Left);
					}
					if ((num & 8) != 0)
					{
						HandleMoveCommand(RenovatorMoveCommand.Right);
					}
					if ((num & 0x10) != 0)
					{
						HandleMoveCommand(RenovatorMoveCommand.Up);
					}
					if ((num & 0x20) != 0)
					{
						HandleMoveCommand(RenovatorMoveCommand.Down);
					}
					if ((num & 0x40) != 0)
					{
						HandleMoveCommand(RenovatorMoveCommand.RotateLeft);
					}
					if ((num & 0x80) != 0)
					{
						HandleMoveCommand(RenovatorMoveCommand.RotateRight);
					}
					_moveRepeat = Time.unscaledTime + ((num != _moveDirection) ? 0.28f : 0.11f);
				}
				_moveDirection = num;
			}
			else
			{
				_moveDirection = 0;
				Vector2 val = ((current2 != null) ? ((InputControl<Vector2>)(object)current2.dpad).ReadValue() : Vector2.zero);
				val += new Vector2((float)(((current != null && ((ButtonControl)current.lKey).isPressed) ? 1 : 0) - ((current != null && ((ButtonControl)current.jKey).isPressed) ? 1 : 0)), (float)(((current != null && ((ButtonControl)current.iKey).isPressed) ? 1 : 0) - ((current != null && ((ButtonControl)current.kKey).isPressed) ? 1 : 0)));
				if (((Vector2)(ref val)).sqrMagnitude > 1f)
				{
					((Vector2)(ref val)).Normalize();
				}
				float num2 = (float)(((current != null && ((ButtonControl)current.rKey).isPressed) ? 1 : 0) - ((current != null && ((ButtonControl)current.fKey).isPressed) ? 1 : 0)) + ((current2 != null) ? ((InputControl<float>)(object)current2.rightTrigger).ReadValue() : 0f) - ((current2 != null) ? ((InputControl<float>)(object)current2.leftTrigger).ReadValue() : 0f);
				float num3 = ((current != null && ((ButtonControl)current.eKey).isPressed) ? 1 : 0) - ((current != null && ((ButtonControl)current.qKey).isPressed) ? 1 : 0) + ((current2 != null && current2.rightShoulder.isPressed) ? 1 : 0) - ((current2 != null && current2.leftShoulder.isPressed) ? 1 : 0);
				float num4 = Mathf.Min(Time.unscaledDeltaTime, 0.05f);
				float num5 = FreeSpeeds[_moveStepIndex];
				bool flag = false;
				if (((Vector2)(ref val)).sqrMagnitude > 0.001f)
				{
					Translate(CameraDirection(val.x, val.y, cardinal: false) * num5 * num4);
					flag = true;
				}
				if (Mathf.Abs(num2) > 0.01f)
				{
					Translate(Vector3.up * num2 * num5 * num4);
					flag = true;
				}
				if (Mathf.Abs(num3) > 0.01f)
				{
					Rotate(num3 * AngleSteps[_moveAngleIndex] * 4f * num4);
					flag = true;
				}
				if (flag)
				{
					RefreshMove();
				}
			}
		}
	}

	[HideFromIl2Cpp]
	private void HandleMoveCommand(RenovatorMoveCommand command)
	{
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_0108: Unknown result type (might be due to invalid IL or missing references)
		//IL_010e: Unknown result type (might be due to invalid IL or missing references)
		//IL_011e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0124: Unknown result type (might be due to invalid IL or missing references)
		//IL_0134: Unknown result type (might be due to invalid IL or missing references)
		//IL_013a: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_020f: Unknown result type (might be due to invalid IL or missing references)
		RenovatorMovePanel moveUi = _moveUi;
		if (moveUi == null || !moveUi.Open)
		{
			return;
		}
		if (_moveBlocked)
		{
			if ((uint)(command - 12) <= 1u)
			{
				CancelMove(returnHome: true);
			}
			return;
		}
		float num = MoveSteps[_moveStepIndex];
		float num2 = AngleSteps[_moveAngleIndex];
		switch (command)
		{
		case RenovatorMoveCommand.Forward:
			Translate(CameraDirection(0f, 1f, cardinal: true) * num);
			break;
		case RenovatorMoveCommand.Back:
			Translate(CameraDirection(0f, -1f, cardinal: true) * num);
			break;
		case RenovatorMoveCommand.Left:
			Translate(CameraDirection(-1f, 0f, cardinal: true) * num);
			break;
		case RenovatorMoveCommand.Right:
			Translate(CameraDirection(1f, 0f, cardinal: true) * num);
			break;
		case RenovatorMoveCommand.Up:
			Translate(Vector3.up * num);
			break;
		case RenovatorMoveCommand.Down:
			Translate(Vector3.down * num);
			break;
		case RenovatorMoveCommand.RotateLeft:
			Rotate(0f - num2);
			break;
		case RenovatorMoveCommand.RotateRight:
			Rotate(num2);
			break;
		case RenovatorMoveCommand.ToggleSnap:
			RenovatorPlugin.MoveSnap.Value = !RenovatorPlugin.MoveSnap.Value;
			break;
		case RenovatorMoveCommand.CycleStep:
			_moveStepIndex = (_moveStepIndex + 1) % MoveSteps.Length;
			RenovatorPlugin.MoveStepIndex.Value = _moveStepIndex;
			break;
		case RenovatorMoveCommand.CycleAngle:
			_moveAngleIndex = (_moveAngleIndex + 1) % AngleSteps.Length;
			RenovatorPlugin.AngleStepIndex.Value = _moveAngleIndex;
			break;
		case RenovatorMoveCommand.Reset:
			_movePrecisionOffset = Vector3.zero;
			if (_placementPreview.Active)
			{
				Player._placablePreviewRotation = _moveStartRotation;
				Player._rawRotationY = ((Quaternion)(ref _moveStartRotation)).eulerAngles.y;
				Player._snappedDisplayY = ((Quaternion)(ref _moveStartRotation)).eulerAngles.y;
				_previewPoseReady = false;
				_previewPoseApplied = false;
			}
			break;
		case RenovatorMoveCommand.Apply:
			ApplyMove();
			return;
		case RenovatorMoveCommand.Cancel:
			CancelMove(returnHome: true);
			return;
		}
		RefreshMove();
	}

	private Vector3 CameraDirection(float x, float z, bool cardinal)
	{
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: 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_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: 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_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0092: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		Camera mainCamera = Player.mainCamera;
		Vector3 val = (((Object)(object)mainCamera != (Object)null) ? ((Component)mainCamera).transform.forward : Vector3.forward);
		val.y = 0f;
		if (((Vector3)(ref val)).sqrMagnitude < 0.001f)
		{
			val = Vector3.forward;
		}
		else
		{
			((Vector3)(ref val)).Normalize();
		}
		Vector3 val2 = new Vector3(val.z, 0f, 0f - val.x) * x + val * z;
		if (!cardinal)
		{
			return val2;
		}
		if (Mathf.Abs(val2.x) > Mathf.Abs(val2.z))
		{
			return new Vector3(Mathf.Sign(val2.x), 0f, 0f);
		}
		return new Vector3(0f, 0f, Mathf.Sign(val2.z));
	}

	private void Translate(Vector3 delta)
	{
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)_moveTarget == (Object)null) && _placementPreview.Active)
		{
			_movePrecisionOffset += delta;
			if (((Vector3)(ref _movePrecisionOffset)).sqrMagnitude > 400f)
			{
				_movePrecisionOffset = ((Vector3)(ref _movePrecisionOffset)).normalized * 20f;
			}
			ApplyPreviewOffset();
		}
	}

	private void FollowPlacementPreview()
	{
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		if (!_placementPreview.Active)
		{
			return;
		}
		Transform transform = _placementPreview.Transform;
		Vector3 position = transform.position;
		Quaternion rotation = transform.rotation;
		int num;
		if (_previewPoseApplied)
		{
			Vector3 val = position - _lastPreviewPosition;
			if (((Vector3)(ref val)).sqrMagnitude < 1E-06f)
			{
				num = ((Quaternion.Angle(rotation, _lastPreviewRotation) < 0.001f) ? 1 : 0);
				goto IL_005f;
			}
		}
		num = 0;
		goto IL_005f;
		IL_005f:
		bool flag = (byte)num != 0;
		if (!_previewPoseReady || !flag)
		{
			_nativeBasePosition = position;
			_nativeBaseRotation = rotation;
			_previewPoseReady = true;
		}
		ApplyPreviewOffset();
		RefreshMove(force: false);
	}

	internal void AfterNativePlacementUpdate()
	{
		RenovatorMovePanel moveUi = _moveUi;
		if (moveUi == null || !moveUi.Open || _moveBlocked || !_placementPreview.Active)
		{
			return;
		}
		try
		{
			_previewPoseReady = false;
			_previewPoseApplied = false;
			_nativePlacementFrame = Time.frameCount;
			FollowPlacementPreview();
		}
		catch (Exception ex)
		{
			if (!_reported)
			{
				RenovatorPlugin.Logger.LogWarning((object)("Native placement offset deferred: " + ex.Message));
				_reported = true;
			}
		}
	}

	private void ApplyPreviewOffset()
	{
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: 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_00a0: 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)
		Transform transform = _placementPreview.Transform;
		if ((Object)(object)transform == (Object)null)
		{
			return;
		}
		if (!_previewPoseReady)
		{
			_nativeBasePosition = transform.position;
			_nativeBaseRotation = transform.rotation;
			_previewPoseReady = true;
		}
		_lastPreviewPosition = _nativeBasePosition + _movePrecisionOffset;
		_lastPreviewRotation = _nativeBaseRotation;
		Vector3 val = transform.position - _lastPreviewPosition;
		int num;
		if (!(((Vector3)(ref val)).sqrMagnitude > 1E-07f))
		{
			num = ((Quaternion.Angle(transform.rotation, _lastPreviewRotation) > 0.0001f) ? 1 : 0);
			if (num == 0)
			{
				goto IL_00b0;
			}
		}
		else
		{
			num = 1;
		}
		transform.SetPositionAndRotation(_lastPreviewPosition, _lastPreviewRotation);
		goto IL_00b0;
		IL_00b0:
		_previewPoseApplied = true;
		if (num != 0)
		{
			Physics.SyncTransforms();
		}
	}

	private void Rotate(float degrees)
	{
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)_moveTarget == (Object)null) && _placementPreview.Active)
		{
			Player._placablePreviewRotation = Quaternion.AngleAxis(degrees, Vector3.up) * Player._placablePreviewRotation;
			Player._rawRotationY += degrees;
			Player._snappedDisplayY += degrees;
			_previewPoseReady = false;
			_previewPoseApplied = false;
		}
	}

	private void RefreshMove(bool force = true)
	{
		//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00af: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)_moveTarget == (Object)null)
		{
			return;
		}
		RenovatorMovePanel moveUi = _moveUi;
		if (moveUi == null || !moveUi.Open)
		{
			return;
		}
		float unscaledTime = Time.unscaledTime;
		if (force || !(unscaledTime < _nextMoveUiRefresh))
		{
			_nextMoveUiRefresh = unscaledTime + 0.05f;
			APlacable val = (_placementPreview.Active ? _placementPreview.Placable : _moveTarget);
			if ((Object)(object)val != (Object)null)
			{
				_cue.Show(val);
			}
			Transform val2 = (_placementPreview.Active ? _placementPreview.Transform : ((Component)_moveTarget).transform);
			_moveUi.Refresh(val2.position, val2.eulerAngles.y, RenovatorPlugin.MoveSnap.Value, MoveSteps[_moveStepIndex], AngleSteps[_moveAngleIndex], _placementPreview.IsSnapped, _placementPreview.CanPlace);
		}
	}

	private void ApplyMove()
	{
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0100: Unknown result type (might be due to invalid IL or missing references)
		//IL_0110: Unknown result type (might be due to invalid IL or missing references)
		//IL_012a: Unknown result type (might be due to invalid IL or missing references)
		//IL_012f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c5: 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_00cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)_moveTarget == (Object)null || _moveBlocked)
		{
			CancelMove();
			return;
		}
		if (_placementPreview.Active && !_placementPreview.CanPlace)
		{
			_moveUi.SetPlacementIssue("That position is blocked. Aim at a valid surface or snap point.");
			return;
		}
		if (HasStoredItems(_moveTarget))
		{
			_placementPreview.End(apply: false, Vector3.zero, Quaternion.identity);
			((Component)_moveTarget).transform.SetPositionAndRotation(_moveStartPosition, _moveStartRotation);
			Physics.SyncTransforms();
			_moveBlocked = true;
			_moveUi.SetBlocked("Items were added to this storage. Move cancelled; empty it first.");
			RefreshMove();
			return;
		}
		if (_placementPreview.Active)
		{
			Transform transform = _placementPreview.Transform;
			Vector3 position = transform.position;
			Quaternion rotation = transform.rotation;
			_placementPreview.End(apply: true, position, rotation);
		}
		Physics.SyncTransforms();
		_networkSync.BroadcastMove(Key(_moveTarget), ((Component)_moveTarget).transform.position, ((Component)_moveTarget).transform.rotation);
		RenovatorPlugin.Logger.LogInfo((object)("Moved " + ((object)_moveTarget.placableItem/*cast due to .constrained prefix*/).ToString() + " / " + Key(_moveTarget)));
		_moveUi.Hide();
		_moveTarget = null;
		_moveBlocked = false;
		_moveMouseLook = false;
		_previewPoseReady = false;
		_previewPoseApplied = false;
		_nativePlacementFrame = -1;
		_moveInputStateKnown = false;
		_release = true;
	}

	private void CancelMove(bool returnHome = false)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		_placementPreview.End(apply: false, Vector3.zero, Quaternion.identity);
		if ((Object)(object)_moveTarget != (Object)null && !_moveBlocked)
		{
			((Component)_moveTarget).transform.SetPositionAndRotation(_moveStartPosition, _moveStartRotation);
			Physics.SyncTransforms();
			_cue.Show(_moveTarget);
		}
		_moveUi?.Hide();
		_moveTarget = null;
		_moveBlocked = false;
		_moveMouseLook = false;
		_previewPoseReady = false;
		_previewPoseApplied = false;
		_nativePlacementFrame = -1;
		_moveInputStateKnown = false;
		if (returnHome && CanReturnHome())
		{
			ShowHomeWithoutCapture();
		}
		else
		{
			_release = true;
		}
	}

	private void Preview(int pattern, int scale)
	{
		if (!CanRenovate(_target) || !RenovatorPatterns.Valid(pattern, scale))
		{
			return;
		}
		try
		{
			Finish(_target).Apply((pattern == 0) ? null : Texture(pattern), pattern, scale);
			_ui.Message(null);
		}
		catch (Exception ex)
		{
			_ui.Message(ex.Message);
		}
	}

	private void Save(int pattern, int scale)
	{
		if (!CanRenovate(_target) || _faulted || !RenovatorPatterns.Valid(pattern, scale))
		{
			return;
		}
		try
		{
			Finish(_target).Apply((pattern == 0) ? null : Texture(pattern), pattern, scale);
			Dictionary<string, RenovatorChoice> dictionary = new Dictionary<string, RenovatorChoice>(_saved);
			if (pattern == 0)
			{
				dictionary.Remove(Key(_target));
			}
			else
			{
				dictionary[Key(_target)] = new RenovatorChoice
				{
					Pattern = pattern,
					Scale = scale
				};
			}
			WriteChoices(dictionary);
			_saved = dictionary;
			if (pattern == 0)
			{
				ReleaseFinish(_target);
			}
			_networkSync.BroadcastFinish(Key(_target), pattern, scale);
			RenovatorPlugin.Logger.LogInfo((object)("Renovator saved for " + Key(_target) + ": " + RenovatorPatterns.Names[pattern]));
			Close(committed: true);
		}
		catch (Exception ex)
		{
			_ui.Message("Not saved: " + ex.Message);
		}
	}

	[HideFromIl2Cpp]
	private void WriteChoices(Dictionary<string, RenovatorChoice> choices)
	{
		string text = _file + ".tmp";
		File.WriteAllText(text, JsonSerializer.Serialize(choices));
		if (File.Exists(_file))
		{
			File.Replace(text, _file, _file + ".bak");
		}
		else
		{
			File.Move(text, _file);
		}
	}

	private void Close(bool committed, bool releaseInput = true)
	{
		RenovatorPanel ui = _ui;
		if (ui == null || !ui.Open)
		{
			return;
		}
		if (!committed && (Object)(object)_target != (Object)null && _applied.TryGetValue(((Object)_target).GetInstanceID(), out var value))
		{
			try
			{
				if (_saved.TryGetValue(Key(_target), out var value2))
				{
					value.Apply(Texture(value2.Pattern), value2.Pattern, value2.Scale);
				}
				else
				{
					value.Restore();
					ReleaseFinish(_target);
				}
			}
			catch (Exception ex)
			{
				RenovatorPlugin.Logger.LogWarning((object)("Renovator preview cleanup: " + ex.Message));
			}
		}
		_ui.Hide();
		if (releaseInput)
		{
			_release = true;
		}
	}

	private void ReleaseFinish(APlacable piece)
	{
		if ((Object)(object)piece != (Object)null && _applied.Remove(((Object)piece).GetInstanceID(), out var value))
		{
			value.Dispose();
		}
	}

	private void BeginNetworkSnapshot()
	{
		_snapshotChoices.Clear();
	}

	private void ReceiveNetworkFinish(string key, int pattern, int scale)
	{
		_snapshotChoices.Add(key);
		if (pattern == 0)
		{
			_networkChoices.Remove(key);
			RestoreNetworkPiece(key);
			return;
		}
		RenovatorChoice renovatorChoice = new RenovatorChoice
		{
			Pattern = pattern,
			Scale = scale
		};
		_networkChoices[key] = renovatorChoice;
		ApplyOrQueueNetworkPiece(key, renovatorChoice);
	}

	private void EndNetworkSnapshot()
	{
		_staleChoices.Clear();
		foreach (string key in _networkChoices.Keys)
		{
			if (!_snapshotChoices.Contains(key))
			{
				_staleChoices.Add(key);
			}
		}
		foreach (string staleChoice in _staleChoices)
		{
			_networkChoices.Remove(staleChoice);
			RestoreNetworkPiece(staleChoice);
		}
		_snapshotChoices.Clear();
	}

	private void ReceiveNetworkMove(string key, Vector3 position, Quaternion rotation)
	{
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		if (_piecesByKey.TryGetValue(key, out var value) && (Object)(object)value != (Object)null)
		{
			((Component)value).transform.SetPositionAndRotation(position, rotation);
			Physics.SyncTransforms();
		}
		else
		{
			_pendingMoves[key] = (position, rotation);
		}
	}

	[HideFromIl2Cpp]
	private void ApplyOrQueueNetworkPiece(string key, RenovatorChoice choice)
	{
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		if (!_piecesByKey.TryGetValue(key, out var value) || (Object)(object)value == (Object)null)
		{
			return;
		}
		int instanceID = ((Object)value).GetInstanceID();
		_failed.Remove(instanceID);
		if (_applied.TryGetValue(instanceID, out var value2))
		{
			try
			{
				value2.Apply(Texture(choice.Pattern), choice.Pattern, choice.Scale);
				return;
			}
			catch (Exception ex)
			{
				value2.Dispose();
				_applied.Remove(instanceID);
				_failed.Add(instanceID);
				RenovatorPlugin.Logger.LogWarning((object)("Renovator network finish skipped " + ((object)value.placableItem/*cast due to .constrained prefix*/).ToString() + ": " + ex.Message));
				return;
			}
		}
		_pendingRestore.Add(instanceID);
	}

	private void RestoreNetworkPiece(string key)
	{
		if (_piecesByKey.TryGetValue(key, out var value) && !((Object)(object)value == (Object)null))
		{
			ReleaseFinish(value);
			_pendingRestore.Remove(((Object)value).GetInstanceID());
		}
	}

	private void ClearNetworkState()
	{
		foreach (string key in _networkChoices.Keys)
		{
			RestoreNetworkPiece(key);
		}
		_networkChoices.Clear();
		_snapshotChoices.Clear();
		_pendingMoves.Clear();
	}

	private static bool Released()
	{
		//IL_0155: Unknown result type (might be due to invalid IL or missing references)
		//IL_015a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0179: Unknown result type (might be due to invalid IL or missing references)
		//IL_017e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0199: Unknown result type (might be due to invalid IL or missing references)
		//IL_019e: Unknown result type (might be due to invalid IL or missing references)
		Gamepad current = Gamepad.current;
		Keyboard current2 = Keyboard.current;
		if (current2 == null || !((ButtonControl)current2.anyKey).isPressed)
		{
			Mouse current3 = Mouse.current;
			if (current3 == null || !current3.leftButton.isPressed)
			{
				Mouse current4 = Mouse.current;
				if (current4 == null || !current4.middleButton.isPressed)
				{
					Mouse current5 = Mouse.current;
					if ((current5 == null || !current5.rightButton.isPressed) && (current == null || !current.buttonSouth.isPressed) && (current == null || !current.buttonEast.isPressed) && (current == null || !current.buttonWest.isPressed) && (current == null || !current.buttonNorth.isPressed) && (current == null || !current.leftStickButton.isPressed) && (current == null || !current.rightStickButton.isPressed) && (current == null || !current.leftShoulder.isPressed) && (current == null || !current.rightShoulder.isPressed) && !(((current != null) ? ((InputControl<float>)(object)current.leftTrigger).ReadValue() : 0f) > 0.1f) && !(((current != null) ? ((InputControl<float>)(object)current.rightTrigger).ReadValue() : 0f) > 0.1f))
					{
						float num;
						Vector2 val;
						if (current == null)
						{
							num = 0f;
						}
						else
						{
							val = ((InputControl<Vector2>)(object)current.leftStick).ReadValue();
							num = ((Vector2)(ref val)).sqrMagnitude;
						}
						if (!(num > 0.01f))
						{
							float num2;
							if (current == null)
							{
								num2 = 0f;
							}
							else
							{
								val = ((InputControl<Vector2>)(object)current.rightStick).ReadValue();
								num2 = ((Vector2)(ref val)).sqrMagnitude;
							}
							if (!(num2 > 0.01f))
							{
								int num3;
								if (current == null)
								{
									num3 = 0;
								}
								else
								{
									val = ((InputControl<Vector2>)(object)current.dpad).ReadValue();
									num3 = ((((Vector2)(ref val)).sqrMagnitude > 0.01f) ? 1 : 0);
								}
								return num3 == 0;
							}
						}
					}
				}
			}
		}
		return false;
	}

	private void ReleaseInput()
	{
		//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
		foreach (InputActionMap map in _maps)
		{
			if (map != null)
			{
				map.Enable();
			}
		}
		_maps.Clear();
		foreach (InputAction item in _disabled)
		{
			if (item != null)
			{
				item.Disable();
			}
		}
		_disabled.Clear();
		if (!_move)
		{
			PlayerActionContainer actions = PlayerInputDispatcher.actions;
			if (actions != null)
			{
				InputAction move = actions.move;
				if (move != null)
				{
					move.Disable();
				}
			}
		}
		if (!_look)
		{
			PlayerActionContainer actions2 = PlayerInputDispatcher.actions;
			if (actions2 != null)
			{
				InputAction look = actions2.look;
				if (look != null)
				{
					look.Disable();
				}
			}
		}
		PlayerInputDispatcher.SetEnableLookInput(_look);
		Cursor.visible = _cursor;
		Cursor.lockState = _lock;
		if ((Object)(object)_inputBlocker != (Object)null)
		{
			Object.Destroy((Object)(object)_inputBlocker);
		}
		_inputBlocker = null;
		_release = false;
		_inputCaptured = false;
		_moveInputStateKnown = false;
		_nextInputMaintenance = 0f;
	}

	private void ResetWorld()
	{
		RenovatorMovePanel moveUi = _moveUi;
		if (moveUi != null && moveUi.Open)
		{
			CancelMove();
		}
		RenovatorHomePanel homeUi = _homeUi;
		if (homeUi != null && homeUi.Open)
		{
			CloseHome();
		}
		Close(committed: false);
		foreach (RenovatorFinish value in _applied.Values)
		{
			value.Dispose();
		}
		_applied.Clear();
		_pieces.Clear();
		_piecesByKey.Clear();
		_pendingRestore.Clear();
		_failed.Clear();
		_saved.Clear();
		_networkChoices.Clear();
		_snapshotChoices.Clear();
		_pendingMoves.Clear();
		SetTarget(null);
		_file = null;
		_faulted = false;
		_scanned = false;
		_reported = false;
	}

	public void Cleanup()
	{
		ResetWorld();
		if (_release)
		{
			ReleaseInput();
		}
		_networkSync.Dispose();
		_placementPreview.Dispose();
		_lookMaterialOverride.Dispose();
		_cue.Dispose();
		_homeUi?.Dispose();
		_homeUi = null;
		_ui?.Dispose();
		_ui = null;
		_moveUi?.Dispose();
		_moveUi = null;
		Texture2D[] textures = _textures;
		foreach (Texture2D val in textures)
		{
			if ((Object)(object)val != (Object)null)
			{
				Object.Destroy((Object)(object)val);
			}
		}
		textures = _thumbnails;
		foreach (Texture2D val2 in textures)
		{
			if ((Object)(object)val2 != (Object)null)
			{
				Object.Destroy((Object)(object)val2);
			}
		}
		Array.Clear(_textures, 0, _textures.Length);
		Array.Clear(_thumbnails, 0, _thumbnails.Length);
	}

	private void OnDestroy()
	{
		Cleanup();
	}
}
internal sealed class RenovatorFinish : IDisposable
{
	private readonly Renderer _renderer;

	private readonly Material[] _original;

	private readonly Material[] _owned;

	private readonly string[] _maps;

	private RenovatorMesh _mesh;

	private bool _attached;

	internal RenovatorFinish(APlacable piece)
	{
		//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f9: Expected O, but got Unknown
		_renderer = piece.objectRenderer;
		if ((Object)(object)_renderer == (Object)null)
		{
			throw new InvalidOperationException("This piece has no supported renderer.");
		}
		Il2CppReferenceArray<Material> sharedMaterials = _renderer.sharedMaterials;
		Material highlightMaterial = EffectManager.highlightMaterial;
		int num = (((Object)(object)piece.objectMesh != (Object)null) ? piece.objectMesh.subMeshCount : ((Il2CppArrayBase<Material>)(object)sharedMaterials).Length);
		_original = (Material[])(object)new Material[((Il2CppArrayBase<Material>)(object)sharedMaterials).Length];
		_owned = (Material[])(object)new Material[((Il2CppArrayBase<Material>)(object)sharedMaterials).Length];
		_maps = new string[((Il2CppArrayBase<Material>)(object)sharedMaterials).Length];
		int num2 = 0;
		try
		{
			for (int i = 0; i < ((Il2CppArrayBase<Material>)(object)sharedMaterials).Length; i++)
			{
				Material val = ((Il2CppArrayBase<Material>)(object)sharedMaterials)[i];
				_original[i] = val;
				if ((Object)(object)val == (Object)null || (i >= num && (Object)(object)highlightMaterial != (Object)null && (Object)(object)val.shader == (Object)(object)highlightMaterial.shader) || (val.HasProperty("_Surface") && val.GetFloat("_Surface") > 0f) || (val.HasProperty("_SurfaceType") && val.GetFloat("_SurfaceType") > 0f) || (val.HasProperty("_AlphaClip") && val.GetFloat("_AlphaClip") > 0f) || (val.HasProperty("_AlphaCutoffEnable") && val.GetFloat("_AlphaCutoffEnable") > 0f) || val.IsKeywordEnabled("_ALPHATEST_ON") || val.IsKeywordEnabled("_ALPHABLEND_ON"))
				{
					continue;
				}
				string text = (val.HasProperty("_BaseColorMap") ? "_BaseColorMap" : (val.HasProperty("_BaseMap") ? "_BaseMap" : (val.HasProperty("_MainTex") ? "_MainTex" : null)));
				if (text == null)
				{
					continue;
				}
				_maps[i] = text;
				_owned[i] = new Material(val);
				((Object)_owned[i]).name = "Renovator_Owned";
				string[] array = new string[8] { "_BumpMap", "_NormalMap", "_MaskMap", "_MetallicGlossMap", "_OcclusionMap", "_ParallaxMap", "_DetailAlbedoMap", "_DetailNormalMap" };
				foreach (string text2 in array)
				{
					if (_owned[i].HasProperty(text2))
					{
						_owned[i].SetTexture(text2, (Texture)null);
					}
				}
				array = new string[3] { "_NORMALMAP", "_PARALLAXMAP", "_DETAIL_MULX2" };
				foreach (string text3 in array)
				{
					_owned[i].DisableKeyword(text3);
				}
				num2++;
			}
			if (num2 == 0)
			{
				throw new InvalidOperationException("This piece has no supported opaque surface material.");
			}
			_mesh = new RenovatorMesh(piece, _owned);
		}
		catch
		{
			Dispose();
			throw;
		}
	}

	internal void Apply(Texture2D texture, int pattern, int scale)
	{
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_0127: Unknown result type (might be due to invalid IL or missing references)
		//IL_012c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0140: Unknown result type (might be due to invalid IL or missing references)
		//IL_0147: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)_renderer == (Object)null)
		{
			throw new InvalidOperationException("The building piece was removed.");
		}
		if (pattern == 0)
		{
			Restore();
			return;
		}
		Il2CppReferenceArray<Material> sharedMaterials = _renderer.sharedMaterials;
		if (((Il2CppArrayBase<Material>)(object)sharedMaterials).Length != _original.Length)
		{
			throw new InvalidOperationException("The game's material layout changed; close and reopen Renovator.");
		}
		for (int i = 0; i < ((Il2CppArrayBase<Material>)(object)sharedMaterials).Length; i++)
		{
			if ((Object)(object)((Il2CppArrayBase<Material>)(object)sharedMaterials)[i] != (Object)(object)_original[i] && (Object)(object)((Il2CppArrayBase<Material>)(object)sharedMaterials)[i] != (Object)(object)_owned[i])
			{
				throw new InvalidOperationException("Another effect is changing this piece. Try again when it finishes.");
			}
		}
		for (int j = 0; j < ((Il2CppArrayBase<Material>)(object)sharedMaterials).Length; j++)
		{
			if ((Object)(object)_owned[j] == (Object)null)
			{
				continue;
			}
			Material val = _owned[j];
			val.SetTexture(_maps[j], (Texture)(object)texture);
			val.SetTextureScale(_maps[j], Vector2.one * RenovatorPatterns.Repeats[scale]);
			val.SetTextureOffset(_maps[j], Vector2.zero);
			string[] array = new string[2] { "_BaseColor", "_Color" };
			foreach (string text in array)
			{
				if (val.HasProperty(text))
				{
					Color color = val.GetColor(text);
					val.SetColor(text, new Color(1f, 1f, 1f, color.a));
				}
			}
			((Il2CppArrayBase<Material>)(object)sharedMaterials)[j] = val;
		}
		_mesh.Apply();
		_renderer.sharedMaterials = sharedMaterials;
		_attached = true;
	}

	internal void Restore()
	{
		_mesh?.Restore();
		if (!_attached || (Object)(object)_renderer == (Object)null)
		{
			return;
		}
		Il2CppReferenceArray<Material> sharedMaterials = _renderer.sharedMaterials;
		for (int i = 0; i < ((Il2CppArrayBase<Material>)(object)sharedMaterials).Length && i < _owned.Length; i++)
		{
			if ((Object)(object)_owned[i] != (Object)null && (Object)(object)((Il2CppArrayBase<Material>)(object)sharedMaterials)[i] == (Object)(object)_owned[i])
			{
				((Il2CppArrayBase<Material>)(object)sharedMaterials)[i] = _original[i];
			}
		}
		_renderer.sharedMaterials = sharedMaterials;
		_attached = false;
	}

	public void Dispose()
	{
		Restore();
		_mesh?.Dispose();
		_mesh = null;
		Material[] owned = _owned;
		foreach (Material val in owned)
		{
			if ((Object)(object)val != (Object)null)
			{
				Object.Destroy((Object)(object)val);
			}
		}
	}
}
internal sealed class RenovatorHomePanel : IDisposable
{
	private readonly GameObject _canvas;

	private readonly GameObject _panel;

	private readonly RectTransform[] _cards = (RectTransform[])(object)new RectTransform[2];

	private readonly Image[] _backgrounds = (Image[])(object)new Image[2];

	private readonly Image[] _bars = (Image[])(object)new Image[2];

	private readonly TextMeshProUGUI[] _titles = (TextMeshProUGUI[])(object)new TextMeshProUGUI[2];

	private readonly TextMeshProUGUI[] _descriptions = (TextMeshProUGUI[])(object)new TextMeshProUGUI[2];

	private readonly TextMeshProUGUI _target;

	private readonly TextMeshProUGUI _hint;

	private readonly RectTransform _close;

	private readonly Image _closeBackground;

	private readonly Action _finish;

	private readonly Action _move;

	private readonly Action _cancel;

	private readonly Color _accent = new Color(0.57f, 0.84f, 0.74f);

	private readonly Color _card = new Color(0.065f, 0.095f, 0.1f, 0.98f);

	private readonly Color _hover = new Color(0.105f, 0.155f, 0.15f, 0.98f);

	private readonly Color _muted = new Color(0.62f, 0.73f, 0.72f);

	private int _selection;

	private int _hoverIndex = -1;

	private bool _canFinish;

	private bool _controller;

	internal bool Open { get; private set; }

	internal bool Controller => _controller;

	internal RenovatorHomePanel(Action finish, Action move, Action cancel)
	{
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_00fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0106: Expected O, but got Unknown
		//IL_013f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0192: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0209: Unknown result type (might be due to invalid IL or missing references)
		//IL_0258: Unknown result type (might be due to invalid IL or missing references)
		//IL_0285: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02df: Unknown result type (might be due to invalid IL or missing references)
		//IL_0333: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_0426: Unknown result type (might be due to invalid IL or missing references)
		_finish = finish;
		_move = move;
		_cancel = cancel;
		_canvas = new GameObject("RenovatorToolsUI", (Type[])(object)new Type[4]
		{
			Il2CppType.Of<RectTransform>(),
			Il2CppType.Of<Canvas>(),
			Il2CppType.Of<CanvasScaler>(),
			Il2CppType.Of<GraphicRaycaster>()
		});
		Canvas component = _canvas.GetComponent<Canvas>();
		component.renderMode = (RenderMode)0;
		component.sortingOrder = 32205;
		CanvasScaler component2 = _canvas.GetComponent<CanvasScaler>();
		component2.uiScaleMode = (ScaleMode)1;
		component2.referenceResolution = new Vector2(1920f, 1080f);
		component2.screenMatchMode = (ScreenMatchMode)0;
		component2.matchWidthOrHeight = 0.5f;
		Image val = Box("ToolList", _canvas.transform, 0.69f, 0.285f, 0.965f, 0.715f, new Color(0.025f, 0.043f, 0.045f, 0.945f));
		_panel = ((Component)val).gameObject;
		((Graphic)val).raycastTarget = true;
		RectTransform rectTransform = ((Graphic)val).rectTransform;
		Vector2 val2 = default(Vector2);
		((Vector2)(ref val2))..ctor(1f, 0.5f);
		rectTransform.anchorMax = val2;
		rectTransform.anchorMin = val2;
		rectTransform.pivot = new Vector2(1f, 0.5f);
		rectTransform.sizeDelta = new Vector2(470f, 464f);
		rectTransform.anchoredPosition = new Vector2(-32f, 0f);
		Box("EdgeAccent", ((Component)val).transform, 0f, 0f, 0.008f, 1f, new Color(_accent.r, _accent.g, _accent.b, 0.72f));
		Text(((Component)val).transform, 0.065f, 0.91f, 0.93f, 0.95f, "RENOVATOR", 12, _muted);
		Text(((Component)val).transform, 0.065f, 0.84f, 0.93f, 0.91f, "Choose a tool", 27, Color.white);
		_target = Text(((Component)val).transform, 0.065f, 0.785f, 0.93f, 0.835f, "", 14, _accent);
		Box("Rule", ((Component)val).transform, 0.065f, 0.765f, 0.93f, 0.768f, new Color(_accent.r, _accent.g, _accent.b, 0.22f));
		AddCard(0, 0.065f, 0.555f, 0.93f, 0.735f, "Surface finishes", "Wallpaper, tile, wood and patterned materials");
		AddCard(1, 0.065f, 0.345f, 0.93f, 0.525f, "Move & rotate", "Reposition, align, raise and rotate this object");
		_closeBackground = Box("Close", ((Component)val).transform, 0.065f, 0.205f, 0.93f, 0.285f, _card);
		_close = ((Graphic)_closeBackground).rectTransform;
		((TMP_Text)Text(((Component)_closeBackground).transform, 0f, 0f, 1f, 1f, "Close", 16, Color.white)).alignment = (TextAlignmentOptions)514;
		_hint = Text(((Component)val).transform, 0.065f, 0.055f, 0.93f, 0.17f, "", 11, _muted);
		((TMP_Text)_hint).alignment = (TextAlignmentOptions)514;
		Hide();
	}

	private void AddCard(int index, float x0, float y0, float x1, float y1, string title, string description)
	{
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_009c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		Image val = Box("Tool" + index, _panel.transform, x0, y0, x1, y1, _card);
		_cards[index] = ((Graphic)val).rectTransform;
		_backgrounds[index] = val;
		_bars[index] = Box("Selection", ((Component)val).transform, 0f, 0f, 0.012f, 1f, _accent);
		_titles[index] = Text(((Component)val).transform, 0.055f, 0.53f, 0.94f, 0.86f, title, 19, Color.white);
		_descriptions[index] = Text(((Component)val).transform, 0.055f, 0.17f, 0.94f, 0.52f, description, 12, _muted);
	}

	internal void Show(string target, bool canFinish)
	{
		((TMP_Text)_target).text = "TARGET  /  " + target;
		_canFinish = canFinish;
		_selection = ((!canFinish) ? 1 : 0);
		Gamepad current = Gamepad.current;
		_controller = current != null && current.rightStickButton.isPressed;
		_hoverIndex = -1;
		Open = true;
		_panel.SetActive(true);
		Refresh();
	}

	internal void Hide()
	{
		Open = false;
		_panel.SetActive(false);
	}

	private void Refresh(int hover = -1)
	{
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		for (int i = 0; i < 2; i++)
		{
			bool flag = i != 0 || _canFinish;
			bool flag2 = i == _selection;
			((Graphic)_backgrounds[i]).color = ((i == hover && flag) ? _hover : _card);
			((Component)_bars[i]).gameObject.SetActive(flag2 && flag);
			((Graphic)_titles[i]).color = (Color)((!flag) ? new Color(0.38f, 0.46f, 0.45f) : (flag2 ? _accent : Color.white));
			((Graphic)_descriptions[i]).color = (Color)(flag ? _muted : new Color(0.31f, 0.38f, 0.37f));
			if (i == 0)
			{
				((TMP_Text)_descriptions[i]).text = (flag ? "Wallpaper, tile, wood and patterned materials" : "Not available for this type of object");
			}
		}
		((TMP_Text)_hint).text = (_controller ? "D-PAD CHOOSE  /  A OPEN  /  B CLOSE" : "CLICK A TOOL  /  ARROWS + ENTER  /  ESC CLOSE");
	}

	private void Select(int delta)
	{
		int num = _selection;
		do
		{
			num = (num + delta + 2) % 2;
		}
		while (num == 0 && !_canFinish);
		_selection = num;
		_hoverIndex = -1;
		Refresh();
	}

	private void Activate()
	{
		Hide();
		if (_selection == 0 && _canFinish)
		{
			_finish();
		}
		else
		{
			_move();
		}
	}

	internal void Tick()
	{
		//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0151: Unknown result type (might be due to invalid IL or missing references)
		//IL_0156: Unknown result type (might be due to invalid IL or missing references)
		//IL_0175: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
		Keyboard current = Keyboard.current;
		Gamepad current2 = Gamepad.current;
		Mouse current3 = Mouse.current;
		if ((current != null && ((ButtonControl)current.escapeKey).wasPressedThisFrame) || (current2 != null && current2.buttonEast.wasPressedThisFrame))
		{
			Hide();
			_cancel();
			return;
		}
		if ((current != null && ((ButtonControl)current.upArrowKey).wasPressedThisFrame) || (current2 != null && current2.dpad.up.wasPressedThisFrame))
		{
			Select(-1);
		}
		if ((current != null && ((ButtonControl)current.downArrowKey).wasPressedThisFrame) || (current2 != null && current2.dpad.down.wasPressedThisFrame))
		{
			Select(1);
		}
		if ((current != null && ((ButtonControl)current.enterKey).wasPressedThisFrame) || (current2 != null && current2.buttonSouth.wasPressedThisFrame))
		{
			Activate();
			return;
		}
		int num;
		Vector2 val;
		if (current2 == null)
		{
			num = 0;
		}
		else
		{
			val = ((InputControl<Vector2>)(object)current2.dpad).ReadValue();
			num = ((((Vector2)(ref val)).sqrMagnitude > 0.1f) ? 1 : 0);
		}
		int num2;
		if (current3 != null)
		{
			val = ((InputControl<Vector2>)(object)((Pointer)current3).delta).ReadValue();
			if (((Vector2)(ref val)).sqrMagnitude > 1f)
			{
				num2 = 1;
				goto IL_0113;
			}
		}
		num2 = ((current != null && ((ButtonControl)current.anyKey).wasPressedThisFrame) ? 1 : 0);
		goto IL_0113;
		IL_0113:
		bool flag = (byte)num2 != 0;
		if (num != 0 && !_controller)
		{
			_controller = true;
			Refresh();
		}
		else if (flag && _controller)
		{
			_controller = false;
			Refresh();
		}
		if (current3 == null)
		{
			return;
		}
		Vector2 point = ((InputControl<Vector2>)(object)((Pointer)current3).position).ReadValue();
		int num3 = -1;
		for (int i = 0; i < 2; i++)
		{
			if ((i != 0 || _canFinish) && Hit(_cards[i], point))
			{
				num3 = i;
			}
		}
		if (num3 != _hoverIndex)
		{
			_hoverIndex = num3;
			Refresh(num3);
		}
		((Graphic)_closeBackground).color = (Hit(_close, point) ? _hover : _card);
		if (current3.leftButton.wasPressedThisFrame)
		{
			if (Hit(_close, point))
			{
				Hide();
				_cancel();
			}
			else if (num3 >= 0)
			{
				_selection = num3;
				Activate();
			}
		}
	}

	private static bool Hit(RectTransform rect, Vector2 point)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		return RectTransformUtility.RectangleContainsScreenPoint(rect, point, (Camera)null);
	}

	private static void Place(RectTransform rect, float x0, float y0, float x1, float y1)
	{
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		rect.anchorMin = new Vector2(x0, y0);
		rect.anchorMax = new Vector2(x1, y1);
		Vector2 offsetMin = (rect.offsetMax = Vector2.zero);
		rect.offsetMin = offsetMin;
	}

	private static Image Box(string name, Transform parent, float x0, float y0, float x1, float y1, Color color)
	{
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject(name, (Type[])(object)new Type[3]
		{
			Il2CppType.Of<RectTransform>(),
			Il2CppType.Of<CanvasRenderer>(),
			Il2CppType.Of<Image>()
		});
		val.transform.SetParent(parent, false);
		Image component = val.GetComponent<Image>();
		((Graphic)component).color = color;
		((Graphic)component).raycastTarget = false;
		Place(((Graphic)component).rectTransform, x0, y0, x1, y1);
		return component;
	}

	private static TextMeshProUGUI Text(Transform parent, float x0, float y0, float x1, float y1, string text, int size, Color color)
	{
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject("Text", (Type[])(object)new Type[3]
		{
			Il2CppType.Of<RectTransform>(),
			Il2CppType.Of<CanvasRenderer>(),
			Il2CppType.Of<TextMeshProUGUI>()
		});
		val.transform.SetParent(parent, false);
		TextMeshProUGUI component = val.GetComponent<TextMeshProUGUI>();
		Place(((TMP_Text)component).rectTransform, x0, y0, x1, y1);
		((TMP_Text)component).text = text;
		((TMP_Text)component).fontSize = size;
		((TMP_Text)component).fontSizeMax = size;
		((TMP_Text)component).fontSizeMin = (float)size * 0.8f;
		((TMP_Text)component).enableAutoSizing = true;
		((TMP_Text)component).enableWordWrapping = true;
		((Graphic)component).color = color;
		((Graphic)component).raycastTarget = false;
		((TMP_Text)component).alignment = (TextAlignmentOptions)4097;
		((TMP_Text)component).overflowMode = (TextOverflowModes)1;
		return component;
	}

	public void Dispose()
	{
		if ((Object)(object)_canvas != (Object)null)
		{
			Object.Destroy((Object)(object)_canvas);
		}
	}
}
internal sealed class RenovatorLookMaterialOverride : IDisposable
{
	private Material _material;

	private Material _backup;

	private int[] _colors = Array.Empty<int>();

	private int[] _floats = Array.Empty<int>();

	private static readonly int[] ColorProperties = new int[5]
	{
		Shader.PropertyToID("_BaseColor"),
		Shader.PropertyToID("_Color"),
		Shader.PropertyToID("_EmissionColor"),
		Shader.PropertyToID("_OutlineColor"),
		Shader.PropertyToID("_TintColor")
	};

	private static readonly int[] FloatProperties = new int[4]
	{
		Shader.PropertyToID("_Alpha"),
		Shader.PropertyToID("_Opacity"),
		Shader.PropertyToID("_Intensity"),
		Shader.PropertyToID("_EmissionIntensity")
	};

	internal void Update(bool enabled)
	{
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Expected O, but got Unknown
		if (!enabled)
		{
			Restore();
			return;
		}
		Material val = null;
		try
		{
			val = Player._lookPlaceMaterial;
		}
		catch
		{
			return;
		}
		if (!((Object)(object)val == (Object)null))
		{
			if ((Object)(object)_material != (Object)(object)val)
			{
				Restore();
				_material = val;
				_backup = new Material(val)
				{
					name = "Renovator_LookPlaceMaterial_Backup"
				};
				_colors = Supported(val, ColorProperties);
				_floats = Supported(val, FloatProperties);
			}
			MakeInvisible();
		}
	}

	private static int[] Supported(Material material, int[] candidates)
	{
		int num = 0;
		int[] array = candidates;
		foreach (int num2 in array)
		{
			if (material.HasProperty(num2))
			{
				num++;
			}
		}
		if (num == 0)
		{
			return Array.Empty<int>();
		}
		int[] array2 = new int[num];
		int num3 = 0;
		array = candidates;
		foreach (int num4 in array)
		{
			if (material.HasProperty(num4))
			{
				array2[num3++] = num4;
			}
		}
		return array2;
	}

	private void MakeInvisible()
	{
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		int[] colors = _colors;
		foreach (int num in colors)
		{
			if (_material.GetColor(num) != Color.clear)
			{
				_material.SetColor(num, Color.clear);
			}
		}
		colors = _floats;
		foreach (int num2 in colors)
		{
			if (_material.GetFloat(num2) != 0f)
			{
				_material.SetFloat(num2, 0f);
			}
		}
		if (_material.IsKeywordEnabled("_EMISSION"))
		{
			_material.DisableKeyword("_EMISSION");
		}
	}

	private void Restore()
	{
		if ((Object)(object)_material != (Object)null && (Object)(object)_backup != (Object)null)
		{
			_material.CopyPropertiesFromMaterial(_backup);
		}
		if ((Object)(object)_backup != (Object)null)
		{
			Object.Destroy((Object)(object)_backup);
		}
		_material = null;
		_backup = null;
		_colors = Array.Empty<int>();
		_floats = Array.Empty<int>();
	}

	public void Dispose()
	{
		Restore();
	}
}
internal static class RenovatorMapping
{
	internal static (float U, float V) Project(float x, float y, float z, int axis)
	{
		return axis switch
		{
			1 => (U: x, V: z), 
			0 => (U: z, V: y), 
			_ => (U: x, V: y), 
		};
	}

	internal static (float U, float V) Surface(float x, float y, float z, float nx, float ny, float nz)
	{
		int num = Axis(nx, ny, nz);
		float num2 = MathF.Sqrt(nx * nx + ny * ny + nz * nz);
		if (num2 < 1E-05f)
		{
			return Project(x, y, z, 2);
		}
		float num3 = ((!(num switch
		{
			1 => ny, 
			0 => nx, 
			_ => 0f - nz, 
		} > 0f)) ? 1 : (-1));
		nx = nx / num2 * num3;
		ny = ny / num2 * num3;
		nz = nz / num2 * num3;
		float num4 = ((num == 0) ? nz : nx);
		float num5 = (float)((num != 0) ? 1 : 0) - nx * num4;
		float num6 = (0f - ny) * num4;
		float num7 = (float)((num == 0) ? 1 : 0) - nz * num4;
		num2 = MathF.Sqrt(num5 * num5 + num6 * num6 + num7 * num7);
		num5 /= num2;
		num6 /= num2;
		num7 /= num2;
		float num8 = ny * num7 - nz * num6;
		float num9 = nz * num5 - nx * num7;
		float num10 = nx * num6 - ny * num5;
		return (U: x * num5 + y * num6 + z * num7, V: x * num8 + y * num9 + z * num10);
	}

	internal static int Axis(float x, float y, float z)
	{
		x = MathF.Abs(x);
		y = MathF.Abs(y);
		z = MathF.Abs(z);
		if (!(x >= y) || !(x >= z))
		{
			if (!(y >= z))
			{
				return 2;
			}
			return 1;
		}
		return 0;
	}
}
internal sealed class RenovatorMesh : IDisposable
{
	private readonly struct CacheKey : IEquatable<CacheKey>
	{
		private readonly int _mesh;

		private readonly int _x;

		private readonly int _y;

		private readonly int _z;

		private readonly ulong _surfaces;

		internal CacheKey(Mesh mesh, Vector3 scale, ulong surfaces)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			_mesh = ((Object)mesh).GetInstanceID();
			_x = Mathf.RoundToInt(scale.x * 10000f);
			_y = Mathf.RoundToInt(scale.y * 10000f);
			_z = Mathf.RoundToInt(scale.z * 10000f);
			_surfaces = surfaces;
		}

		public bool Equals(CacheKey other)
		{
			if (_mesh == other._mesh && _x == other._x && _y == other._y && _z == other._z)
			{
				return _surfaces == other._surfaces;
			}
			return false;
		}

		public override bool Equals(object obj)
		{
			if (obj is CacheKey other)
			{
				return Equals(other);
			}
			return false;
		}

		public override int GetHashCode()
		{
			return HashCode.Combine(_mesh, _x, _y, _z, _surfaces);
		}
	}

	private sealed class CacheEntry
	{
		internal readonly Mesh Mesh;

		internal int Users;

		internal CacheEntry(Mesh mesh)
		{
			Mesh = mesh;
			Users = 1;
		}
	}

	private static readonly Dictionary<CacheKey, CacheEntry> Cache = new Dictionary<CacheKey, CacheEntry>();

	private readonly MeshFilter _filter;

	private readonly Mesh _original;

	private readonly CacheKey _cacheKey;

	private CacheEntry _cacheEntry;

	private Mesh _owned;

	internal RenovatorMesh(APlacable piece, Material[] materials)
	{
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0086: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fa: