Decompiled source of Enigmas Shelf Life v0.1.3

EnigmasShelfLife.dll

Decompiled a day 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 BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using TMPro;
using UnityEngine;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("0.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace EnigmasShelfLife
{
	[BepInPlugin("EnigmaPrime.EnigmasShelfLife", "Enigma's Shelf Life", "0.1.3")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public const string PluginGuid = "EnigmaPrime.EnigmasShelfLife";

		public const string PluginName = "Enigma's Shelf Life";

		public const string PluginVersion = "0.1.3";

		internal static ManualLogSource Log;

		internal static Plugin Instance;

		internal static ConfigEntry<string> ExtraItems;

		private Harmony _harmony;

		private void Awake()
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Expected O, but got Unknown
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Expected O, but got Unknown
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			ExtraItems = ((BaseUnityPlugin)this).Config.Bind<string>("Bulk bin", "Extra items", "", new ConfigDescription("Extra prefab names the bulk bin accepts on top of the built-in list, separated by commas. Exact prefab names only, no wildcards, case does not matter. Example: Wood,Coins. Synced from the server.", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
			ExtraItems.SettingChanged += delegate
			{
				BulkBinLock.RebuildAllowed();
			};
			BulkBinLock.RebuildAllowed();
			FillConfig.Bind((BaseUnityPlugin)(object)this);
			WoodFillConfig.Bind((BaseUnityPlugin)(object)this);
			NoBuildConfig.Bind((BaseUnityPlugin)(object)this);
			CabinetConfig.Bind((BaseUnityPlugin)(object)this);
			ShelfPieces.Hook();
			_harmony = new Harmony("EnigmaPrime.EnigmasShelfLife");
			_harmony.PatchAll();
			Log.LogInfo((object)"Enigma's Shelf Life 0.1.3 loaded.");
		}

		private void Start()
		{
			((MonoBehaviour)this).InvokeRepeating("FillTick", 2f, 2f);
		}

		private void FillTick()
		{
			EP_BulkBinFill.TickAll();
			EP_WoodRackFill.TickAll();
		}

		private void OnDestroy()
		{
			if (_harmony != null)
			{
				_harmony.UnpatchSelf();
			}
		}
	}
	[Serializable]
	public class BakedV3
	{
		public float x;

		public float y;

		public float z;

		public Vector3 ToVector()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			return new Vector3(x, y, z);
		}
	}
	[Serializable]
	public class BakedQ4
	{
		public float x;

		public float y;

		public float z;

		public float w;

		public Quaternion ToQuaternion()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			return new Quaternion(x, y, z, w);
		}
	}
	[Serializable]
	public class BakedXform
	{
		public BakedV3 position;

		public BakedQ4 rotation;

		public BakedV3 scale;
	}
	[Serializable]
	public class BakedItem
	{
		public string item;

		public int amount;
	}
	[Serializable]
	public class BakedPart
	{
		public string sourcePrefab;

		public string sourcePath;

		public string state;

		public string group;

		public string mesh;

		public List<string> materials;

		public string shadowCasting;

		public bool receiveShadows;

		public string layer;

		public BakedXform xform;
	}
	[Serializable]
	public class BakedCollider
	{
		public string sourcePrefab;

		public string sourcePath;

		public string group;

		public string type;

		public bool isTrigger;

		public string layer;

		public BakedV3 center;

		public BakedV3 size;

		public float radius;

		public float height;

		public int direction;

		public string mesh;

		public bool convex;

		public BakedXform xform;
	}
	[Serializable]
	public class BakedSign
	{
		public string sourcePrefab;

		public string group;

		public bool active;

		public bool nameable;

		public string text;

		public int characterLimit;

		public BakedV3 widgetSize;

		public float fontSize;

		public List<float> fontColor;

		public string alignment;

		public string font;

		public BakedXform xform;

		public BakedXform widgetXform;
	}
	[Serializable]
	public class BakedDoor
	{
		public string group;

		public string sourcePrefab;

		public BakedXform xform;
	}
	[Serializable]
	public class BakedMarker
	{
		public BakedV3 offset;

		public float scale;
	}
	[Serializable]
	public class BakedIcon
	{
		public float pitch;

		public float yaw;

		public int size;
	}
	[Serializable]
	public class BakedWear
	{
		public string materialType;

		public bool supports;

		public bool noRoofWear;

		public bool noSupportWear;

		public bool burnable;

		public bool snowDamageImmune;

		public bool ashDamageImmune;

		public bool ashDamageResist;

		public int minToolTier;

		public float hitNoise;

		public float destroyNoise;

		public bool triggerPrivateArea;

		public Dictionary<string, string> damages;
	}
	[Serializable]
	public class BakedPrefab
	{
		public int format;

		public string kind;

		public string name;

		public string front;

		public string origin;

		public float health;

		public bool noClipping;

		public bool blockedByFurniture;

		public BakedWear wearNTear;

		public string effectsFrom;

		public BakedMarker frontMarker;

		public BakedIcon icon;

		public float costFactor;

		public string costRule;

		public List<BakedItem> cost;

		public List<BakedItem> capturedCost;

		public string sourceCapture;

		public string sourceTool;

		public string sourceDate;

		public string sourceGame;

		public List<BakedV3> snapPoints;

		public List<BakedPart> parts;

		public List<BakedCollider> colliders;

		public List<BakedSign> signMarkers;

		public List<BakedDoor> doors;

		public List<BakedStand> stands;

		public List<BakedArmorStand> armorStands;

		public List<BakedSource> sources;
	}
	[Serializable]
	public class BakedSource
	{
		public string guid;

		public string name;

		public string version;

		public string author;

		public string thunderstore;

		public string page;

		public string permission;

		public string found;

		public List<string> prefabs;
	}
	[Serializable]
	public class BakedArmorStand
	{
		public string sourcePrefab;

		public int pose;

		public BakedXform xform;
	}
	[Serializable]
	public class BakedStand
	{
		public string sourcePrefab;

		public string slot;

		public string group;

		public BakedXform xform;

		public BakedXform attachXform;

		public List<string> rejectTypes;
	}
	public class EPDoor : MonoBehaviour
	{
		public string Id = "EP_Door_0";

		public string DoorName = "door";

		public bool CanNotBeClosed;

		public bool InvertedOpenClosedText;

		public bool CheckGuardStone = true;

		public float HoverOffset;

		public bool SwingToModelFront = true;

		public GameObject OpenEnable;

		public EffectList OpenEffects = new EffectList();

		public EffectList CloseEffects = new EffectList();

		private ZNetView _nview;

		private Animator _animator;

		private uint _lastRevision = uint.MaxValue;

		private int _stateKey;

		private string _rpcName;

		private void Awake()
		{
			_animator = ((Component)this).GetComponent<Animator>();
			_stateKey = StringExtensionMethods.GetStableHashCode("EP_door_state_" + Id);
			_rpcName = "EP_SetDoor_" + Id;
		}

		private void Start()
		{
			_nview = ((Component)this).GetComponentInParent<ZNetView>();
			if (!((Object)(object)_nview == (Object)null) && _nview.GetZDO() != null)
			{
				_nview.Register<int>(_rpcName, (Action<long, int>)RPC_SetDoor);
				((MonoBehaviour)this).InvokeRepeating("UpdateState", 0f, 0.2f);
			}
		}

		internal bool Valid()
		{
			if ((Object)(object)_nview != (Object)null && _nview.IsValid())
			{
				return (Object)(object)_animator != (Object)null;
			}
			return false;
		}

		internal int GetState()
		{
			return _nview.GetZDO().GetInt(_stateKey, 0);
		}

		internal bool IsIdle()
		{
			//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)
			AnimatorStateInfo currentAnimatorStateInfo = _animator.GetCurrentAnimatorStateInfo(0);
			if (!((AnimatorStateInfo)(ref currentAnimatorStateInfo)).IsTag("open"))
			{
				return ((AnimatorStateInfo)(ref currentAnimatorStateInfo)).IsTag("closed");
			}
			return true;
		}

		internal bool OpensForward(Vector3 fromDoor)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			if (!SwingToModelFront)
			{
				return Vector3.Dot(((Component)this).transform.forward, fromDoor) < 0f;
			}
			return Vector3.Dot(((Component)this).transform.forward, ((Component)_nview).transform.forward) >= 0f;
		}

		internal void RequestState(int state)
		{
			_nview.InvokeRPC(_rpcName, new object[1] { state });
		}

		private void RPC_SetDoor(long uid, int state)
		{
			if (Valid())
			{
				_nview.GetZDO().Set(_stateKey, Mathf.Clamp(state, -1, 1), false);
				UpdateState();
			}
		}

		private void UpdateState()
		{
			if (Valid())
			{
				uint dataRevision = _nview.GetZDO().DataRevision;
				if (_lastRevision != dataRevision)
				{
					_lastRevision = dataRevision;
					SetState(GetState());
				}
			}
		}

		private void SetState(int state)
		{
			//IL_0056: 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_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: 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)
			if (_animator.GetInteger("state") != state)
			{
				if (state != 0)
				{
					OpenEffects.Create(((Component)this).transform.position, ((Component)this).transform.rotation, (Transform)null, 1f, -1, default(ZDOID));
				}
				else
				{
					CloseEffects.Create(((Component)this).transform.position, ((Component)this).transform.rotation, (Transform)null, 1f, -1, default(ZDOID));
				}
				_animator.SetInteger("state", state);
			}
			if ((Object)(object)OpenEnable != (Object)null)
			{
				OpenEnable.SetActive(state != 0);
			}
		}
	}
	public class EPModelDoors : MonoBehaviour, Hoverable, Interactable
	{
		private ZNetView _nview;

		private EPDoor[] _doors;

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

		private EPDoor[] Doors()
		{
			if (_doors == null)
			{
				_doors = ((Component)this).GetComponentsInChildren<EPDoor>(true);
			}
			return _doors;
		}

		private bool AnyOpen()
		{
			EPDoor[] array = Doors();
			foreach (EPDoor ePDoor in array)
			{
				if (ePDoor.Valid() && ePDoor.GetState() != 0)
				{
					return true;
				}
			}
			return false;
		}

		public string GetHoverText()
		{
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_nview == (Object)null || !_nview.IsValid())
			{
				return "";
			}
			Hoverable[] components = ((Component)this).GetComponents<Hoverable>();
			foreach (Hoverable val in components)
			{
				if ((object)val != this)
				{
					string hoverText = val.GetHoverText();
					if (!string.IsNullOrEmpty(hoverText))
					{
						return hoverText;
					}
				}
			}
			EPDoor[] array = Doors();
			if (array.Length == 0 || !array[0].Valid())
			{
				return "";
			}
			EPDoor ePDoor = array[0];
			if (ePDoor.CheckGuardStone && !PrivateArea.CheckAccess(((Component)this).transform.position, 0f, false, false))
			{
				return Localization.instance.Localize(ePDoor.DoorName + "\n$piece_noaccess");
			}
			string text = ((AnyOpen() == ePDoor.InvertedOpenClosedText) ? "$piece_door_open" : "$piece_door_close");
			return Localization.instance.Localize(ePDoor.DoorName + "\n[<color=yellow><b>$KEY_Use</b></color>] " + text);
		}

		public string GetHoverName()
		{
			Hoverable[] components = ((Component)this).GetComponents<Hoverable>();
			foreach (Hoverable val in components)
			{
				if ((object)val != this)
				{
					string hoverName = val.GetHoverName();
					if (!string.IsNullOrEmpty(hoverName))
					{
						return hoverName;
					}
				}
			}
			EPDoor[] array = Doors();
			if (array.Length == 0)
			{
				return "";
			}
			return array[0].DoorName;
		}

		public float GetHoverOffset()
		{
			return 0f;
		}

		public bool Interact(Humanoid user, bool hold, bool alt)
		{
			bool flag = false;
			Interactable[] components = ((Component)this).GetComponents<Interactable>();
			foreach (Interactable val in components)
			{
				if ((object)val != this)
				{
					flag |= val.Interact(user, hold, alt);
				}
			}
			if (hold)
			{
				return flag;
			}
			return ToggleDoors(user) || flag;
		}

		public bool UseItem(Humanoid user, ItemData item)
		{
			bool flag = false;
			Interactable[] components = ((Component)this).GetComponents<Interactable>();
			foreach (Interactable val in components)
			{
				if ((object)val != this)
				{
					flag |= val.UseItem(user, item);
				}
			}
			return flag;
		}

		public void CloseAll()
		{
			if ((Object)(object)_nview == (Object)null || !_nview.IsValid())
			{
				return;
			}
			EPDoor[] array = Doors();
			foreach (EPDoor ePDoor in array)
			{
				if (ePDoor.Valid() && ePDoor.GetState() != 0 && !ePDoor.CanNotBeClosed)
				{
					ePDoor.RequestState(0);
				}
			}
		}

		private bool ToggleDoors(Humanoid user)
		{
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_nview == (Object)null || !_nview.IsValid())
			{
				return false;
			}
			EPDoor[] array = Doors();
			if (array.Length == 0)
			{
				return false;
			}
			EPDoor[] array2 = array;
			foreach (EPDoor ePDoor in array2)
			{
				if (!ePDoor.Valid() || !ePDoor.IsIdle())
				{
					return false;
				}
			}
			if (array[0].CheckGuardStone && !PrivateArea.CheckAccess(((Component)this).transform.position, 0f, true, false))
			{
				return true;
			}
			bool flag = AnyOpen();
			array2 = array;
			foreach (EPDoor ePDoor2 in array2)
			{
				if (flag)
				{
					if (ePDoor2.GetState() != 0 && !ePDoor2.CanNotBeClosed)
					{
						ePDoor2.RequestState(0);
					}
				}
				else
				{
					Vector3 val = ((Component)user).transform.position - ((Component)ePDoor2).transform.position;
					Vector3 normalized = ((Vector3)(ref val)).normalized;
					ePDoor2.RequestState(ePDoor2.OpensForward(normalized) ? 1 : (-1));
				}
			}
			Game.instance.IncrementPlayerStat((PlayerStatType)(flag ? 75 : 74), 1f, false);
			return true;
		}
	}
	public interface IEPNameplateText
	{
		string GetNameplateText();
	}
	public class EPNameplate : MonoBehaviour, Hoverable, Interactable, TextReceiver
	{
		public TextMeshProUGUI Widget;

		public int CharacterLimit = 50;

		private static readonly int TextKey = StringExtensionMethods.GetStableHashCode("EP_nameplate_text");

		private ZNetView _nview;

		private string _shown;

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

		private void Start()
		{
			UpdateText();
			((MonoBehaviour)this).InvokeRepeating("UpdateText", 0.5f, 1f);
		}

		private bool Valid()
		{
			if ((Object)(object)_nview != (Object)null)
			{
				return _nview.IsValid();
			}
			return false;
		}

		private string AutoText()
		{
			IEPNameplateText componentInParent = ((Component)this).GetComponentInParent<IEPNameplateText>();
			if (componentInParent == null)
			{
				return null;
			}
			string nameplateText = componentInParent.GetNameplateText();
			if (!string.IsNullOrEmpty(nameplateText))
			{
				return nameplateText;
			}
			return null;
		}

		private string DefaultText()
		{
			Piece componentInParent = ((Component)this).GetComponentInParent<Piece>();
			if (!((Object)(object)componentInParent != (Object)null))
			{
				return "";
			}
			return Localization.instance.Localize(componentInParent.m_name);
		}

		private void UpdateText()
		{
			if (!((Object)(object)Widget == (Object)null))
			{
				string text = GetText();
				if (!(text == _shown))
				{
					((TMP_Text)Widget).text = text;
					_shown = text;
				}
			}
		}

		private Interactable ParentInteractable()
		{
			if (!((Object)(object)((Component)this).transform.parent != (Object)null))
			{
				return null;
			}
			return ((Component)((Component)this).transform.parent).GetComponentInParent<Interactable>();
		}

		private Hoverable ParentHoverable()
		{
			if (!((Object)(object)((Component)this).transform.parent != (Object)null))
			{
				return null;
			}
			return ((Component)((Component)this).transform.parent).GetComponentInParent<Hoverable>();
		}

		public string GetText()
		{
			string text = AutoText();
			if (text != null)
			{
				return text;
			}
			if (Valid())
			{
				string text2 = _nview.GetZDO().GetString(TextKey, "");
				if (text2.Length > 0)
				{
					return text2;
				}
			}
			return DefaultText();
		}

		public void SetText(string text)
		{
			if (Valid())
			{
				_nview.ClaimOwnership();
				_nview.GetZDO().Set(TextKey, text ?? "");
				UpdateText();
			}
		}

		public string GetHoverText()
		{
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			if (AutoText() != null)
			{
				Hoverable val = ParentHoverable();
				if (val != null)
				{
					return val.GetHoverText();
				}
				return "\"" + GetText() + "\"";
			}
			string text = "\"" + GetText() + "\"";
			if (!PrivateArea.CheckAccess(((Component)this).transform.position, 0f, false, false))
			{
				return text;
			}
			return Localization.instance.Localize(text + "\n[<color=yellow><b>$KEY_Use</b></color>] Rename");
		}

		public string GetHoverName()
		{
			if (AutoText() != null)
			{
				Hoverable val = ParentHoverable();
				if (val != null)
				{
					return val.GetHoverName();
				}
			}
			return GetText();
		}

		public float GetHoverOffset()
		{
			return 0f;
		}

		public bool Interact(Humanoid user, bool hold, bool alt)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			if (AutoText() != null)
			{
				Interactable val = ParentInteractable();
				if (val != null)
				{
					return val.Interact(user, hold, alt);
				}
				return false;
			}
			if (hold)
			{
				return false;
			}
			if (!PrivateArea.CheckAccess(((Component)this).transform.position, 0f, true, false))
			{
				return true;
			}
			if (!Valid() || (Object)(object)TextInput.instance == (Object)null)
			{
				return false;
			}
			TextInput.instance.RequestText((TextReceiver)(object)this, "$piece_sign_input", CharacterLimit);
			return true;
		}

		public bool UseItem(Humanoid user, ItemData item)
		{
			if (AutoText() != null)
			{
				Interactable val = ParentInteractable();
				if (val != null)
				{
					return val.UseItem(user, item);
				}
				return false;
			}
			return false;
		}
	}
	public class EPArmorStandLink : MonoBehaviour
	{
		private static readonly MethodInfo OnDestroyedMethod = typeof(ArmorStand).GetMethod("OnDestroyed", BindingFlags.Instance | BindingFlags.NonPublic);

		private ArmorStand _stand;

		private void Start()
		{
			_stand = ((Component)this).GetComponent<ArmorStand>();
			WearNTear componentInParent = ((Component)this).GetComponentInParent<WearNTear>();
			if ((Object)(object)componentInParent != (Object)null && (Object)(object)_stand != (Object)null)
			{
				componentInParent.m_onDestroyed = (Action)Delegate.Combine(componentInParent.m_onDestroyed, new Action(OnModelDestroyed));
			}
		}

		private void OnModelDestroyed()
		{
			if ((Object)(object)_stand == (Object)null || OnDestroyedMethod == null)
			{
				return;
			}
			ZNetView netViewOverride = _stand.m_netViewOverride;
			if ((Object)(object)netViewOverride == (Object)null || !netViewOverride.IsValid() || !netViewOverride.IsOwner())
			{
				return;
			}
			try
			{
				OnDestroyedMethod.Invoke(_stand, null);
			}
			catch (Exception ex)
			{
				Debug.LogWarning((object)("EP Ghost Box: armor stand drop failed, the model is removed anyway: " + (ex.InnerException ?? ex).Message));
			}
		}
	}
	public class EPItemStand : MonoBehaviour, Hoverable, Interactable
	{
		public static bool TapToTake;

		public static readonly string[] LongTypes = new string[3] { "TwoHandedWeapon", "TwoHandedWeaponLeft", "Bow" };

		public int Index;

		public string Slot = "";

		public List<string> RejectTypes;

		public ItemStand Source;

		public Transform Attach;

		public Transform DropPoint;

		public bool Driven;

		private ZNetView _nview;

		private GameObject _visual;

		private int _visualHash;

		private int _visualVariant;

		private int _visualOrientation;

		private int _updateCount;

		private string _currentItemName = "";

		private readonly List<OrientationSettings> _orientationSettings = new List<OrientationSettings>();

		private int _keysFor = -1;

		private int _kItem;

		private int _kVariant;

		private int _kQuality;

		private int _kType;

		private void Start()
		{
			((MonoBehaviour)this).InvokeRepeating("RefreshVisual", 0.2f, 0.5f);
			WearNTear componentInParent = ((Component)this).GetComponentInParent<WearNTear>();
			if ((Object)(object)componentInParent != (Object)null)
			{
				componentInParent.m_onDestroyed = (Action)Delegate.Combine(componentInParent.m_onDestroyed, new Action(OnModelDestroyed));
			}
		}

		private void OnModelDestroyed()
		{
			ZNetView val = View();
			if ((Object)(object)val != (Object)null && val.IsValid() && val.IsOwner())
			{
				DropItem();
			}
		}

		private ZNetView View()
		{
			if ((Object)(object)_nview == (Object)null)
			{
				_nview = ((Component)this).GetComponentInParent<ZNetView>();
			}
			return _nview;
		}

		private bool Valid()
		{
			ZNetView val = View();
			if ((Object)(object)val != (Object)null)
			{
				return val.IsValid();
			}
			return false;
		}

		private void Keys()
		{
			if (_keysFor != Index)
			{
				_keysFor = Index;
				_kItem = StringExtensionMethods.GetStableHashCode("EP_stand_item_" + Index);
				_kVariant = StringExtensionMethods.GetStableHashCode("EP_stand_variant_" + Index);
				_kQuality = StringExtensionMethods.GetStableHashCode("EP_stand_quality_" + Index);
				_kType = StringExtensionMethods.GetStableHashCode("EP_stand_type_" + Index);
			}
		}

		public bool HaveAttachment()
		{
			if (!Valid())
			{
				return false;
			}
			Keys();
			return View().GetZDO().GetInt(_kItem, 0) != 0;
		}

		public bool TryGetCell(out int column, out int row)
		{
			column = 0;
			row = 0;
			if (string.IsNullOrEmpty(Slot))
			{
				return false;
			}
			string[] array = Slot.Split(new char[1] { '-' });
			if (array.Length == 2 && int.TryParse(array[0], out column) && int.TryParse(array[1], out row) && column > 0)
			{
				return row > 0;
			}
			return false;
		}

		public static Dictionary<string, EPItemStand> FindSlots(GameObject model)
		{
			Dictionary<string, EPItemStand> dictionary = new Dictionary<string, EPItemStand>();
			EPItemStand[] componentsInChildren = model.GetComponentsInChildren<EPItemStand>(true);
			foreach (EPItemStand ePItemStand in componentsInChildren)
			{
				if (!string.IsNullOrEmpty(ePItemStand.Slot) && !dictionary.ContainsKey(ePItemStand.Slot))
				{
					dictionary.Add(ePItemStand.Slot, ePItemStand);
				}
			}
			return dictionary;
		}

		private void RefreshVisual()
		{
			if (Driven)
			{
				((MonoBehaviour)this).CancelInvoke("RefreshVisual");
			}
			else if (Valid())
			{
				Keys();
				ZDO zDO = View().GetZDO();
				SetVisualItem(zDO.GetInt(_kItem, 0), zDO.GetInt(_kVariant, 0), zDO.GetInt(_kQuality, 1), zDO.GetInt(_kType, 0));
				_updateCount++;
			}
		}

		public void ShowDriven(ItemData item)
		{
			Driven = true;
			if (item == null || (Object)(object)item.m_dropPrefab == (Object)null)
			{
				SetVisualItem(0, 0, 1, 0);
			}
			else
			{
				SetVisualItem(StringExtensionMethods.GetStableHashCode(((Object)item.m_dropPrefab).name), item.m_variant, item.m_quality, 0);
			}
		}

		public bool CanShow(ItemData item)
		{
			return CanAttach(item);
		}

		private Interactable RootInteractable()
		{
			ZNetView val = View();
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			Interactable[] components = ((Component)val).GetComponents<Interactable>();
			int num = 0;
			if (num < components.Length)
			{
				return components[num];
			}
			return null;
		}

		private Hoverable RootHoverable()
		{
			ZNetView val = View();
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			Hoverable[] components = ((Component)val).GetComponents<Hoverable>();
			int num = 0;
			if (num < components.Length)
			{
				return components[num];
			}
			return null;
		}

		private void SetVisualItem(int hash, int variant, int quality, int orientation)
		{
			//IL_0121: 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_0149: 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_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: 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_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: 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_0250: Unknown result type (might be due to invalid IL or missing references)
			//IL_0255: Unknown result type (might be due to invalid IL or missing references)
			//IL_0263: Unknown result type (might be due to invalid IL or missing references)
			//IL_0269: Unknown result type (might be due to invalid IL or missing references)
			if (_visualHash == hash && _visualVariant == variant && _visualOrientation == orientation)
			{
				return;
			}
			if ((Object)(object)_visual != (Object)null)
			{
				Object.Destroy((Object)(object)_visual);
			}
			_visual = null;
			_visualHash = hash;
			_visualVariant = variant;
			_visualOrientation = orientation;
			_currentItemName = "";
			if (hash == 0)
			{
				return;
			}
			GameObject val = (((Object)(object)ObjectDB.instance != (Object)null) ? ObjectDB.instance.GetItemPrefab(hash) : null);
			if ((Object)(object)val == (Object)null)
			{
				ZLog.LogWarning((object)("EP item stand: missing item prefab " + hash));
				return;
			}
			GameObject attachPrefab = ItemStand.GetAttachPrefab(val);
			if ((Object)(object)attachPrefab == (Object)null)
			{
				ZLog.LogWarning((object)("EP item stand: failed to get attach prefab for item " + hash));
				return;
			}
			ItemDrop component = val.GetComponent<ItemDrop>();
			if (!((Object)(object)component == (Object)null))
			{
				_currentItemName = component.m_itemData.m_shared.m_name;
				LoadOrientationSettings(component.m_itemData);
				Transform val2 = (((Object)(object)Attach != (Object)null) ? Attach : ((Component)this).transform);
				GameObject attachGameObject = ItemStand.GetAttachGameObject(attachPrefab);
				_visual = Object.Instantiate<GameObject>(attachGameObject, val2.position, val2.rotation, val2);
				Transform transform = _visual.transform;
				transform.localPosition = attachPrefab.transform.localPosition;
				transform.localRotation = attachPrefab.transform.localRotation;
				transform.localScale = Vector3.Scale(attachPrefab.transform.localScale, component.m_itemData.GetScale((float)quality));
				OrientationSettings val3 = _orientationSettings[Mathf.Min(_orientationSettings.Count - 1, orientation)];
				transform.localPosition += val3.m_position;
				transform.localRotation *= Quaternion.Euler(val3.m_rotation);
				transform.localScale = Vector3.Scale(transform.localScale, val3.m_scale);
				ParticleIntensityScaler[] componentsInChildren = _visual.GetComponentsInChildren<ParticleIntensityScaler>(true);
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					componentsInChildren[i].SetQuality(quality);
				}
				if (_updateCount > 0 && (Object)(object)Source != (Object)null && Source.m_effects != null)
				{
					Source.m_effects.Create(val2.position, Quaternion.identity, (Transform)null, 1f, -1, default(ZDOID));
				}
				SetupVariant(variant);
			}
		}

		private void LoadOrientationSettings(ItemData item)
		{
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Expected O, but got Unknown
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			_orientationSettings.Clear();
			if (item != null && item.m_shared != null && item.m_shared.m_itemStandOffsets != null && (Object)(object)Source != (Object)null)
			{
				foreach (OrientationSettings itemStandOffset in item.m_shared.m_itemStandOffsets)
				{
					if ((Source.m_orientationType & itemStandOffset.m_orientations) != 0)
					{
						_orientationSettings.Add(itemStandOffset);
					}
				}
			}
			if (_orientationSettings.Count == 0)
			{
				_orientationSettings.Insert(0, new OrientationSettings());
			}
		}

		private void SetupVariant(int variant)
		{
			Component[] components = _visual.GetComponents<Component>();
			foreach (Component val in components)
			{
				if (!((Object)(object)val == (Object)null) && !(((object)val).GetType().GetInterface("IEquipmentVisual") == null))
				{
					MethodInfo method = ((object)val).GetType().GetMethod("Setup", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[1] { typeof(int) }, null);
					if (method != null)
					{
						method.Invoke(val, new object[1] { variant });
					}
					break;
				}
			}
		}

		private bool CanAttach(ItemData item)
		{
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)Source == (Object)null || item == null)
			{
				return false;
			}
			if ((Object)(object)ItemStand.GetAttachPrefab(item.m_dropPrefab) == (Object)null)
			{
				return false;
			}
			if (RejectTypes != null && RejectTypes.Contains(((object)Unsafe.As<ItemType, ItemType>(ref item.m_shared.m_itemType)/*cast due to .constrained prefix*/).ToString()))
			{
				return false;
			}
			if (IsUnsupported(item))
			{
				return false;
			}
			if (IsSupported(item))
			{
				return true;
			}
			return Source.m_supportedTypes.Contains(item.m_shared.m_itemType);
		}

		private bool IsUnsupported(ItemData item)
		{
			foreach (ItemDrop unsupportedItem in Source.m_unsupportedItems)
			{
				if (unsupportedItem.m_itemData.m_shared.m_name == item.m_shared.m_name)
				{
					return true;
				}
			}
			return false;
		}

		private bool IsSupported(ItemData item)
		{
			if (Source.m_supportedItems.Count == 0)
			{
				return true;
			}
			foreach (ItemDrop supportedItem in Source.m_supportedItems)
			{
				if (supportedItem.m_itemData.m_shared.m_name == item.m_shared.m_name)
				{
					return true;
				}
			}
			return false;
		}

		public string GetHoverText()
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			if (Driven)
			{
				Hoverable val = RootHoverable();
				if (val == null)
				{
					return "";
				}
				return val.GetHoverText();
			}
			if ((Object)(object)Player.m_localPlayer == (Object)null || (Object)(object)Source == (Object)null)
			{
				return "";
			}
			if (!PrivateArea.CheckAccess(((Component)this).transform.position, 0f, false, false))
			{
				return Localization.instance.Localize(Source.m_name + "\n$piece_noaccess");
			}
			if (HaveAttachment())
			{
				if (!Source.m_canBeRemoved)
				{
					return "";
				}
				string text = (TapToTake ? "" : "$ui_hold ");
				string text2 = ((!ZInput.IsGamepadActive()) ? (Source.m_name + " ( " + _currentItemName + " )\n[<color=yellow><b>" + text + "$KEY_Use</b></color>] $piece_itemstand_take") : (Source.m_name + " ( " + _currentItemName + " )\n<b>" + text + "$KEY_Use</b> $piece_itemstand_take"));
				if ((Object)(object)_visual != (Object)null && _orientationSettings.Count > 1)
				{
					text2 = ((!ZInput.IsNonClassicFunctionality() || !ZInput.IsGamepadActive()) ? (text2 + "\n[<color=yellow><b>$KEY_AltPlace + $KEY_Use</b></color>] $hud_changeorientation") : (text2 + "\n[<color=yellow><b>$KEY_AltKeys + $KEY_Use</b></color>] $hud_changeorientation"));
				}
				return Localization.instance.Localize(text2);
			}
			if (Source.m_autoAttach && Source.m_supportedItems.Count == 1)
			{
				return Localization.instance.Localize(Source.m_name + "\n[<color=yellow><b>$KEY_Use</b></color>] $piece_itemstand_attach");
			}
			return Localization.instance.Localize(Source.m_name + "\n[<color=yellow><b>$KEY_HotbarUse</b></color>] $piece_itemstand_attach");
		}

		public string GetHoverName()
		{
			if (Driven)
			{
				Hoverable val = RootHoverable();
				if (val == null)
				{
					return "";
				}
				return val.GetHoverName();
			}
			if (!((Object)(object)Source != (Object)null))
			{
				return "";
			}
			return Localization.instance.Localize(Source.m_name);
		}

		public float GetHoverOffset()
		{
			if (!((Object)(object)Source != (Object)null))
			{
				return 0f;
			}
			return Source.m_hoverOffset;
		}

		public bool Interact(Humanoid user, bool hold, bool alt)
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			if (Driven)
			{
				Interactable val = RootInteractable();
				if (val != null)
				{
					return val.Interact(user, hold, alt);
				}
				return false;
			}
			if ((Object)(object)Source == (Object)null || !Valid())
			{
				return false;
			}
			if (!PrivateArea.CheckAccess(((Component)this).transform.position, 0f, true, false))
			{
				return true;
			}
			if (!HaveAttachment())
			{
				if (Source.m_autoAttach && Source.m_supportedItems.Count == 1)
				{
					ItemData item = user.GetInventory().GetItem(Source.m_supportedItems[0].m_itemData.m_shared.m_name, -1, false);
					if (item != null)
					{
						UseItem(user, item);
						return true;
					}
					((Character)user).Message((MessageType)2, "$piece_itemstand_missingitem", 0, (Sprite)null, false);
				}
				return false;
			}
			if (alt)
			{
				if ((Object)(object)_visual != (Object)null && _orientationSettings.Count > 1)
				{
					int num = ((_visualOrientation + 1 != _orientationSettings.Count) ? (_visualOrientation + 1) : 0);
					Keys();
					View().ClaimOwnership();
					View().GetZDO().Set(_kType, num, false);
					RefreshVisual();
				}
				return true;
			}
			if (Source.m_canBeRemoved && (hold || TapToTake))
			{
				DropItem();
				return true;
			}
			return false;
		}

		public bool UseItem(Humanoid user, ItemData item)
		{
			if (Driven)
			{
				Interactable val = RootInteractable();
				if (val != null)
				{
					return val.UseItem(user, item);
				}
				return false;
			}
			if ((Object)(object)Source == (Object)null || !Valid())
			{
				return false;
			}
			if (HaveAttachment())
			{
				return false;
			}
			if (!CanAttach(item))
			{
				((Character)user).Message((MessageType)2, "$piece_itemstand_cantattach", 0, (Sprite)null, false);
				return true;
			}
			Player val2 = (Player)(object)((user is Player) ? user : null);
			if ((Object)(object)val2 == (Object)null || !((Humanoid)val2).GetInventory().ContainsItem(item))
			{
				return false;
			}
			Keys();
			View().ClaimOwnership();
			ZDO zDO = View().GetZDO();
			ItemData val3 = item.Clone();
			val3.m_stack = 1;
			zDO.Set(_kItem, StringExtensionMethods.GetStableHashCode(((Object)item.m_dropPrefab).name), false);
			zDO.Set(_kVariant, val3.m_variant, false);
			zDO.Set(_kQuality, val3.m_quality, false);
			zDO.Set(_kType, 0, false);
			ItemDrop.SaveToZDO(val3, zDO, Index);
			((Humanoid)val2).UnequipItem(item, true);
			((Humanoid)val2).GetInventory().RemoveOneItem(item);
			RefreshVisual();
			return true;
		}

		private void DropItem()
		{
			//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_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: 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_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_00d1: 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_00dd: 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_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			if (!HaveAttachment())
			{
				return;
			}
			Keys();
			View().ClaimOwnership();
			ZDO zDO = View().GetZDO();
			GameObject val = (((Object)(object)ObjectDB.instance != (Object)null) ? ObjectDB.instance.GetItemPrefab(zDO.GetInt(_kItem, 0)) : null);
			if ((Object)(object)val != (Object)null)
			{
				Vector3 val2 = Vector3.zero;
				Quaternion val3 = Quaternion.identity;
				Transform val4 = val.transform.Find("attach");
				if ((Object)(object)val.transform.Find("attachobj") != (Object)null && (Object)(object)val4 != (Object)null)
				{
					val3 = val4.localRotation;
					val2 = val4.localPosition;
				}
				Transform val5 = (((Object)(object)DropPoint != (Object)null) ? DropPoint : ((Component)this).transform);
				GameObject val6 = Object.Instantiate<GameObject>(val, val5.position + val2, val5.rotation * val3);
				ItemDrop component = val6.GetComponent<ItemDrop>();
				if ((Object)(object)component != (Object)null)
				{
					ItemDrop.LoadFromZDO(component.m_itemData, zDO, Index);
					ZNetView component2 = val6.GetComponent<ZNetView>();
					if ((Object)(object)component2 != (Object)null && component2.IsValid())
					{
						ItemDrop.SaveToZDO(component.m_itemData, component2.GetZDO(), -1);
					}
					component.SetQuality(component.m_itemData.m_quality);
				}
				Rigidbody component3 = val6.GetComponent<Rigidbody>();
				if ((Object)(object)component3 != (Object)null)
				{
					component3.linearVelocity = Vector3.up * 4f;
				}
				if ((Object)(object)Source != (Object)null && Source.m_effects != null)
				{
					Source.m_effects.Create(val5.position, Quaternion.identity, (Transform)null, 1f, -1, default(ZDOID));
				}
			}
			zDO.Set(_kItem, 0, false);
			zDO.Set(_kType, 0, false);
			RefreshVisual();
		}
	}
	public class EPFrontMarker : MonoBehaviour
	{
		public Vector3 Offset = new Vector3(0f, 0.05f, 1.6f);

		public float Scale = 1f;

		private GameObject _marker;

		private void Start()
		{
			//IL_0093: 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_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			ZNetView component = ((Component)this).GetComponent<ZNetView>();
			if (!((Object)(object)component != (Object)null) || !component.IsValid())
			{
				GameObject val = (((Object)(object)ZNetScene.instance != (Object)null) ? ZNetScene.instance.GetPrefab("Player") : null);
				Player val2 = (((Object)(object)val != (Object)null) ? val.GetComponent<Player>() : null);
				GameObject val3 = (((Object)(object)val2 != (Object)null) ? val2.m_placeMarker : null);
				if (!((Object)(object)val3 == (Object)null))
				{
					_marker = Object.Instantiate<GameObject>(val3, ((Component)this).transform);
					_marker.SetActive(true);
					_marker.transform.localPosition = Offset;
					_marker.transform.localRotation = Quaternion.LookRotation(Vector3.up, Vector3.forward);
					_marker.transform.localScale = Vector3.one * Scale;
				}
			}
		}
	}
	public class EPBlockedByFurniture : MonoBehaviour
	{
	}
	[HarmonyPatch(typeof(Player), "UpdatePlacementGhost")]
	internal static class EPBlockedByFurniturePatch
	{
		private const float MaxPenetration = 0.05f;

		private const float CabinetPenetration = 0.25f;

		private const float SideLimit = 0.3f;

		private static int _mask;

		private static readonly Collider[] Hits = (Collider[])(object)new Collider[64];

		private static readonly List<Collider> Own = new List<Collider>(64);

		private static void Postfix(GameObject ___m_placementGhost, ref PlacementStatus ___m_placementStatus)
		{
			if (!((Object)(object)___m_placementGhost == (Object)null) && ___m_placementGhost.activeInHierarchy && (int)___m_placementStatus == 0 && !((Object)(object)___m_placementGhost.GetComponent<EPBlockedByFurniture>() == (Object)null) && OverlapsFurniture(___m_placementGhost))
			{
				___m_placementStatus = (PlacementStatus)1;
				Piece component = ___m_placementGhost.GetComponent<Piece>();
				if ((Object)(object)component != (Object)null)
				{
					component.SetInvalidPlacementHeightlight(true);
				}
			}
		}

		private static bool OverlapsFurniture(GameObject ghost)
		{
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			if (_mask == 0)
			{
				_mask = LayerMask.GetMask(new string[2] { "piece", "piece_nonsolid" });
			}
			bool flag = (Object)(object)ghost.GetComponent<EP_BulkBin>() != (Object)null;
			bool flag2 = (Object)(object)ghost.GetComponent<EP_Cabinet>() != (Object)null;
			ghost.GetComponentsInChildren<Collider>(Own);
			int num = Physics.OverlapSphereNonAlloc(ghost.transform.position, 6f, Hits, _mask);
			Vector3 val2 = default(Vector3);
			float num3 = default(float);
			for (int i = 0; i < num; i++)
			{
				Collider val = Hits[i];
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				Piece componentInParent = ((Component)val).GetComponentInParent<Piece>();
				if ((Object)(object)componentInParent == (Object)null || (Object)(object)((Component)componentInParent).gameObject == (Object)(object)ghost || !IsFurniture(componentInParent) || (flag && (Object)(object)((Component)componentInParent).GetComponent<EP_BulkBin>() != (Object)null))
				{
					continue;
				}
				float num2 = 0.05f;
				if (flag2 && (Object)(object)((Component)componentInParent).GetComponent<EP_Cabinet>() != (Object)null && ghost.transform.InverseTransformPoint(((Component)componentInParent).transform.position).z < 0.3f)
				{
					num2 = 0.25f;
				}
				foreach (Collider item in Own)
				{
					if (!((Object)(object)item == (Object)null) && item.enabled && Physics.ComputePenetration(item, ((Component)item).transform.position, ((Component)item).transform.rotation, val, ((Component)val).transform.position, ((Component)val).transform.rotation, ref val2, ref num3) && num3 > num2)
					{
						return true;
					}
				}
			}
			return false;
		}

		private static bool IsFurniture(Piece p)
		{
			if (!((Object)(object)((Component)p).GetComponent<Container>() != (Object)null) && !((Object)(object)((Component)p).GetComponent<CraftingStation>() != (Object)null) && !((Object)(object)((Component)p).GetComponent<Smelter>() != (Object)null) && !((Object)(object)((Component)p).GetComponent<CookingStation>() != (Object)null) && !((Object)(object)((Component)p).GetComponent<Fermenter>() != (Object)null) && !((Object)(object)((Component)p).GetComponent<Beehive>() != (Object)null) && !((Object)(object)((Component)p).GetComponent<Bed>() != (Object)null) && !((Object)(object)((Component)p).GetComponent<Fireplace>() != (Object)null) && !((Object)(object)((Component)p).GetComponent<ArmorStand>() != (Object)null))
			{
				return (Object)(object)((Component)p).GetComponent<ItemStand>() != (Object)null;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(Player), "UpdatePlacementGhost")]
	internal static class EPFrontMarkerPatch
	{
		private static void Postfix(GameObject ___m_placementGhost, GameObject ___m_placementMarkerInstance)
		{
			if (!((Object)(object)___m_placementGhost == (Object)null) && !((Object)(object)___m_placementMarkerInstance == (Object)null) && (Object)(object)___m_placementGhost.GetComponent<EPFrontMarker>() != (Object)null)
			{
				___m_placementMarkerInstance.SetActive(false);
			}
		}
	}
	public static class PrefabBuilder
	{
		public const int ArmorStandIndexBase = 100;

		public static WearNTear AddWearNTear(GameObject root, BakedPrefab data)
		{
			//IL_0258: Unknown result type (might be due to invalid IL or missing references)
			//IL_025d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			WearNTear val = root.GetComponent<WearNTear>();
			if ((Object)(object)val == (Object)null)
			{
				val = root.AddComponent<WearNTear>();
			}
			if (data.health > 0f)
			{
				val.m_health = data.health;
			}
			val.m_autoCreateFragments = false;
			Transform val2 = root.transform.Find("EP_New");
			Transform val3 = root.transform.Find("EP_Worn");
			Transform val4 = root.transform.Find("EP_Broken");
			if ((Object)(object)val2 != (Object)null || (Object)(object)val3 != (Object)null || (Object)(object)val4 != (Object)null)
			{
				if ((Object)(object)val2 == (Object)null)
				{
					val2 = EmptyLook(root, "EP_New", on: true);
				}
				if ((Object)(object)val3 == (Object)null)
				{
					val3 = EmptyLook(root, "EP_Worn", on: false);
				}
				if ((Object)(object)val4 == (Object)null)
				{
					val4 = EmptyLook(root, "EP_Broken", on: false);
				}
			}
			if ((Object)(object)val2 != (Object)null)
			{
				val.m_new = ((Component)val2).gameObject;
			}
			if ((Object)(object)val3 != (Object)null)
			{
				val.m_worn = ((Component)val3).gameObject;
			}
			if ((Object)(object)val4 != (Object)null)
			{
				val.m_broken = ((Component)val4).gameObject;
			}
			BakedWear wearNTear = data.wearNTear;
			if (wearNTear == null)
			{
				return val;
			}
			if (Enum.TryParse<MaterialType>(wearNTear.materialType, out MaterialType result))
			{
				val.m_materialType = result;
			}
			val.m_supports = wearNTear.supports;
			val.m_noRoofWear = wearNTear.noRoofWear;
			val.m_noSupportWear = wearNTear.noSupportWear;
			val.m_burnable = wearNTear.burnable;
			val.m_snowDamageImmune = wearNTear.snowDamageImmune;
			val.m_ashDamageImmune = wearNTear.ashDamageImmune;
			val.m_ashDamageResist = wearNTear.ashDamageResist;
			val.m_minToolTier = wearNTear.minToolTier;
			val.m_hitNoise = wearNTear.hitNoise;
			val.m_destroyNoise = wearNTear.destroyNoise;
			val.m_triggerPrivateArea = wearNTear.triggerPrivateArea;
			if (wearNTear.damages != null)
			{
				object obj = val.m_damages;
				foreach (KeyValuePair<string, string> damage in wearNTear.damages)
				{
					FieldInfo field = obj.GetType().GetField(damage.Key);
					if (!(field == null) && field.FieldType.IsEnum)
					{
						try
						{
							field.SetValue(obj, Enum.Parse(field.FieldType, damage.Value));
						}
						catch (Exception)
						{
						}
					}
				}
				val.m_damages = (DamageModifiers)obj;
			}
			return val;
		}

		private static Transform EmptyLook(GameObject root, string name, bool on)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: 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)
			GameObject val = new GameObject(name);
			val.transform.SetParent(root.transform, false);
			val.layer = LayerMask.NameToLayer("piece");
			val.SetActive(on);
			return val.transform;
		}

		public static bool RequiredModsLoaded(BakedPrefab data, List<string> problems)
		{
			bool result = true;
			if (data == null || data.sources == null)
			{
				return true;
			}
			foreach (BakedSource source in data.sources)
			{
				if (source != null && !string.IsNullOrEmpty(source.guid) && !Chainloader.PluginInfos.ContainsKey(source.guid))
				{
					result = false;
					problems?.Add("required mod is not loaded: " + (string.IsNullOrEmpty(source.name) ? source.guid : source.name) + " (" + source.guid + ")" + (string.IsNullOrEmpty(source.thunderstore) ? "" : (", Thunderstore " + source.thunderstore)));
				}
			}
			return result;
		}

		public static string BuildPiece(GameObject root, BakedPrefab data, Func<string, GameObject> lookup, List<string> problems)
		{
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			if (!RequiredModsLoaded(data, problems))
			{
				return "skipped, a required mod is not loaded";
			}
			string result = Fill(root, data, lookup, problems);
			Piece val = root.GetComponent<Piece>();
			if ((Object)(object)val == (Object)null)
			{
				val = root.AddComponent<Piece>();
			}
			val.m_noClipping = data.noClipping;
			val.m_allowRotatedOverlap = true;
			AddDoors(root, data, lookup, problems);
			AddNameplates(root, data, lookup, problems);
			AddStands(root, data, lookup, problems);
			AddArmorStands(root, data, lookup, problems);
			AddWearNTear(root, data);
			CopyEffects(root, data, lookup, problems);
			if (data.blockedByFurniture)
			{
				root.AddComponent<EPBlockedByFurniture>();
			}
			EPFrontMarker ePFrontMarker = root.AddComponent<EPFrontMarker>();
			if (data.frontMarker != null && data.frontMarker.offset != null)
			{
				ePFrontMarker.Offset = data.frontMarker.offset.ToVector();
				if (data.frontMarker.scale > 0f)
				{
					ePFrontMarker.Scale = data.frontMarker.scale;
				}
			}
			root.layer = LayerMask.NameToLayer("piece");
			return result;
		}

		public static void AddDoors(GameObject root, BakedPrefab data, Func<string, GameObject> lookup, List<string> problems)
		{
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Expected O, but got Unknown
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: 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_0161: Expected O, but got Unknown
			//IL_03bf: Unknown result type (might be due to invalid IL or missing references)
			if (data.doors == null)
			{
				return;
			}
			int layer = LayerMask.NameToLayer("piece");
			foreach (BakedDoor door in data.doors)
			{
				GameObject val = lookup(door.sourcePrefab);
				Door val2 = (((Object)(object)val != (Object)null) ? val.GetComponent<Door>() : null);
				Animator val3 = (((Object)(object)val != (Object)null) ? val.GetComponent<Animator>() : null);
				if ((Object)(object)val2 == (Object)null || (Object)(object)val3 == (Object)null)
				{
					problems.Add("door " + door.group + ": no Door and Animator on the vanilla '" + door.sourcePrefab + "'");
					continue;
				}
				GameObject val4 = new GameObject(door.group);
				val4.transform.SetParent(root.transform, false);
				val4.transform.localPosition = door.xform.position.ToVector();
				val4.transform.localRotation = door.xform.rotation.ToQuaternion();
				val4.transform.localScale = door.xform.scale.ToVector();
				val4.layer = layer;
				WearNTear component = val.GetComponent<WearNTear>();
				Dictionary<Transform, Transform> dictionary = new Dictionary<Transform, Transform>();
				foreach (Transform item2 in val.transform)
				{
					Transform val5 = item2;
					GameObject gameObject = ((Component)val5).gameObject;
					if (gameObject.activeSelf && (!((Object)(object)component != (Object)null) || (!((Object)(object)gameObject == (Object)(object)component.m_new) && !((Object)(object)gameObject == (Object)(object)component.m_worn) && !((Object)(object)gameObject == (Object)(object)component.m_broken))) && !gameObject.CompareTag("snappoint"))
					{
						GameObject val6 = Object.Instantiate<GameObject>(gameObject, val4.transform, false);
						((Object)val6).name = ((Object)gameObject).name;
						dictionary[val5] = val6.transform;
					}
				}
				LODGroup component2 = val.GetComponent<LODGroup>();
				Renderer[] renderers;
				if ((Object)(object)component2 != (Object)null)
				{
					LOD[] lODs = component2.GetLODs();
					HashSet<Renderer> hashSet = new HashSet<Renderer>();
					if (lODs.Length != 0 && lODs[0].renderers != null)
					{
						renderers = lODs[0].renderers;
						foreach (Renderer item in renderers)
						{
							hashSet.Add(item);
						}
					}
					for (int j = 1; j < lODs.Length; j++)
					{
						if (lODs[j].renderers == null)
						{
							continue;
						}
						renderers = lODs[j].renderers;
						foreach (Renderer val7 in renderers)
						{
							if (!((Object)(object)val7 == (Object)null) && !hashSet.Contains(val7))
							{
								Transform val8 = MapInClone(((Component)val7).transform, val.transform, dictionary);
								Renderer val9 = (((Object)(object)val8 != (Object)null) ? ((Component)val8).GetComponent<Renderer>() : null);
								if ((Object)(object)val9 != (Object)null)
								{
									val9.enabled = false;
								}
							}
						}
					}
				}
				renderers = val4.GetComponentsInChildren<Renderer>(true);
				foreach (Renderer val10 in renderers)
				{
					Material[] sharedMaterials = val10.sharedMaterials;
					foreach (Material val11 in sharedMaterials)
					{
						if ((Object)(object)val11 != (Object)null && ((Object)val11).name.IndexOf("snow", StringComparison.OrdinalIgnoreCase) >= 0)
						{
							val10.enabled = false;
							break;
						}
					}
				}
				Animator obj = val4.AddComponent<Animator>();
				obj.runtimeAnimatorController = val3.runtimeAnimatorController;
				obj.avatar = val3.avatar;
				obj.applyRootMotion = val3.applyRootMotion;
				obj.cullingMode = val3.cullingMode;
				if ((Object)(object)root.GetComponent<EPModelDoors>() == (Object)null)
				{
					root.AddComponent<EPModelDoors>();
				}
				EPDoor ePDoor = val4.AddComponent<EPDoor>();
				ePDoor.Id = door.group;
				ePDoor.DoorName = val2.m_name;
				ePDoor.CanNotBeClosed = val2.m_canNotBeClosed;
				ePDoor.InvertedOpenClosedText = val2.m_invertedOpenClosedText;
				ePDoor.CheckGuardStone = val2.m_checkGuardStone;
				ePDoor.HoverOffset = val2.m_hoverOffset;
				ePDoor.OpenEffects = val2.m_openEffects;
				ePDoor.CloseEffects = val2.m_closeEffects;
				if ((Object)(object)val2.m_openEnable != (Object)null)
				{
					List<string> list = new List<string>();
					Transform val12 = val2.m_openEnable.transform;
					while ((Object)(object)val12 != (Object)null && (Object)(object)val12 != (Object)(object)val.transform)
					{
						list.Insert(0, ((Object)val12).name);
						val12 = val12.parent;
					}
					Transform val13 = ((list.Count == 0) ? val4.transform : val4.transform.Find(string.Join("/", list.ToArray())));
					ePDoor.OpenEnable = (((Object)(object)val13 != (Object)null) ? ((Component)val13).gameObject : null);
				}
			}
		}

		private static Transform MapInClone(Transform src, Transform vanillaRoot, Dictionary<Transform, Transform> cloneOfTop)
		{
			List<int> list = new List<int>();
			Transform val = src;
			while ((Object)(object)val != (Object)null && (Object)(object)val.parent != (Object)(object)vanillaRoot)
			{
				list.Insert(0, val.GetSiblingIndex());
				val = val.parent;
			}
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			if (!cloneOfTop.TryGetValue(val, out var value))
			{
				return null;
			}
			foreach (int item in list)
			{
				if (item >= value.childCount)
				{
					return null;
				}
				value = value.GetChild(item);
			}
			return value;
		}

		public static void AddNameplates(GameObject root, BakedPrefab data, Func<string, GameObject> lookup, List<string> problems)
		{
			if (data.signMarkers == null)
			{
				return;
			}
			foreach (BakedSign signMarker in data.signMarkers)
			{
				if (signMarker.active && !string.IsNullOrEmpty(signMarker.group))
				{
					GameObject val = GroupChild(root, signMarker.group, LayerMask.NameToLayer("piece"));
					EPNameplate ePNameplate = val.GetComponent<EPNameplate>();
					if ((Object)(object)ePNameplate == (Object)null)
					{
						ePNameplate = val.AddComponent<EPNameplate>();
					}
					ePNameplate.CharacterLimit = ((signMarker.characterLimit > 0) ? signMarker.characterLimit : 50);
					ePNameplate.Widget = CloneWidget(val.transform, signMarker, lookup, problems);
				}
			}
		}

		public static bool HasArmorStand(BakedPrefab data)
		{
			if (data != null && data.armorStands != null)
			{
				return data.armorStands.Count > 0;
			}
			return false;
		}

		public static void AddArmorStands(GameObject root, BakedPrefab data, Func<string, GameObject> lookup, List<string> problems)
		{
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Expected O, but got Unknown
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Expected O, but got Unknown
			//IL_02d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0310: Unknown result type (might be due to invalid IL or missing references)
			if (!HasArmorStand(data))
			{
				return;
			}
			if (data.armorStands.Count > 1)
			{
				problems.Add("armor stand: " + data.armorStands.Count + " in the file, only the first is used");
			}
			BakedArmorStand bakedArmorStand = data.armorStands[0];
			if (bakedArmorStand == null || bakedArmorStand.xform == null)
			{
				problems.Add("armor stand: no place in the file");
				return;
			}
			ZNetView component = root.GetComponent<ZNetView>();
			if ((Object)(object)component == (Object)null)
			{
				problems.Add("armor stand: the model root has no ZNetView");
				return;
			}
			GameObject val = lookup(bakedArmorStand.sourcePrefab);
			if ((Object)(object)val == (Object)null || (Object)(object)val.GetComponent<ArmorStand>() == (Object)null)
			{
				problems.Add("armor stand: '" + bakedArmorStand.sourcePrefab + "' is not a vanilla armor stand");
				return;
			}
			GameObject val2 = new GameObject("EP_ArmorStandHolder");
			val2.SetActive(false);
			GameObject val3 = Object.Instantiate<GameObject>(val, val2.transform);
			((Object)val3).name = "EP_ArmorStand";
			ZNetView component2 = val3.GetComponent<ZNetView>();
			List<KeyValuePair<Component, FieldInfo>> list = new List<KeyValuePair<Component, FieldInfo>>();
			Component[] componentsInChildren;
			if ((Object)(object)component2 != (Object)null)
			{
				componentsInChildren = val3.GetComponentsInChildren<Component>(true);
				foreach (Component val4 in componentsInChildren)
				{
					if ((Object)(object)val4 == (Object)null || val4 is ZNetView)
					{
						continue;
					}
					FieldInfo[] fields = ((object)val4).GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					foreach (FieldInfo fieldInfo in fields)
					{
						if (!(fieldInfo.FieldType != typeof(ZNetView)) && (Object)(ZNetView)fieldInfo.GetValue(val4) == (Object)(object)component2)
						{
							list.Add(new KeyValuePair<Component, FieldInfo>(val4, fieldInfo));
						}
					}
				}
			}
			componentsInChildren = (Component[])(object)new Component[3]
			{
				(Component)val3.GetComponent<ZNetView>(),
				(Component)val3.GetComponent<Piece>(),
				(Component)val3.GetComponent<WearNTear>()
			};
			foreach (Component val5 in componentsInChildren)
			{
				if ((Object)(object)val5 != (Object)null)
				{
					Object.DestroyImmediate((Object)(object)val5);
				}
			}
			foreach (KeyValuePair<Component, FieldInfo> item in list)
			{
				item.Value.SetValue(item.Key, component);
			}
			ArmorStand component3 = val3.GetComponent<ArmorStand>();
			component3.m_netViewOverride = component;
			VisEquipment[] componentsInChildren2 = val3.GetComponentsInChildren<VisEquipment>(true);
			for (int i = 0; i < componentsInChildren2.Length; i++)
			{
				componentsInChildren2[i].m_nViewOverride = component;
			}
			Debug.Log((object)("EP Ghost Box: armor stand copy, " + list.Count + " ZNetView reference(s) pointed to the model root"));
			component3.m_startPose = bakedArmorStand.pose;
			val3.AddComponent<EPArmorStandLink>();
			val3.transform.SetParent(root.transform, false);
			val3.transform.localPosition = bakedArmorStand.xform.position.ToVector();
			val3.transform.localRotation = bakedArmorStand.xform.rotation.ToQuaternion();
			val3.transform.localScale = bakedArmorStand.xform.scale.ToVector();
			Object.Destroy((Object)(object)val2);
		}

		public static void AddStands(GameObject root, BakedPrefab data, Func<string, GameObject> lookup, List<string> problems)
		{
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Invalid comparison between Unknown and I4
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: 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_01c8: 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_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Expected O, but got Unknown
			//IL_020a: Unknown result type (might be due to invalid IL or missing references)
			//IL_020f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			if (data.stands == null)
			{
				return;
			}
			int layer = LayerMask.NameToLayer("piece");
			for (int i = 0; i < data.stands.Count; i++)
			{
				BakedStand bakedStand = data.stands[i];
				if (string.IsNullOrEmpty(bakedStand.group) || bakedStand.xform == null || bakedStand.attachXform == null)
				{
					continue;
				}
				GameObject val = lookup(bakedStand.sourcePrefab);
				ItemStand val2 = (((Object)(object)val != (Object)null) ? val.GetComponentInChildren<ItemStand>(true) : null);
				if ((Object)(object)val2 == (Object)null)
				{
					problems.Add("stand " + i + ": no ItemStand on the vanilla '" + bakedStand.sourcePrefab + "'");
					continue;
				}
				GameObject val3 = GroupChild(root, bakedStand.group, layer);
				EPItemStand ePItemStand = val3.GetComponent<EPItemStand>();
				if ((Object)(object)ePItemStand == (Object)null)
				{
					ePItemStand = val3.AddComponent<EPItemStand>();
				}
				ePItemStand.Index = (HasArmorStand(data) ? 100 : 0) + i;
				ePItemStand.Slot = bakedStand.slot ?? "";
				ePItemStand.Source = val2;
				if (bakedStand.rejectTypes != null)
				{
					ePItemStand.RejectTypes = bakedStand.rejectTypes;
				}
				else if ((int)val2.m_orientationType == 2)
				{
					ePItemStand.RejectTypes = new List<string>(EPItemStand.LongTypes);
				}
				ePItemStand.Attach = NewChild(val3, "EP_Attach", bakedStand.attachXform, layer).transform;
				Transform val4 = (((Object)(object)val2.m_dropSpawnPoint != (Object)null) ? val2.m_dropSpawnPoint : ((Component)val2).transform);
				Matrix4x4 val5 = Matrix4x4.TRS(bakedStand.xform.position.ToVector(), bakedStand.xform.rotation.ToQuaternion(), bakedStand.xform.scale.ToVector()) * (val.transform.worldToLocalMatrix * val4.localToWorldMatrix);
				GameObject val6 = new GameObject("EP_Drop");
				val6.transform.SetParent(val3.transform, false);
				val6.transform.localPosition = Vector4.op_Implicit(((Matrix4x4)(ref val5)).GetColumn(3));
				val6.transform.localRotation = ((Matrix4x4)(ref val5)).rotation;
				val6.layer = layer;
				ePItemStand.DropPoint = val6.transform;
			}
		}

		private static TextMeshProUGUI CloneWidget(Transform parent, BakedSign m, Func<string, GameObject> lookup, List<string> problems)
		{
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: 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_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Expected O, but got Unknown
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_0205: Unknown result type (might be due to invalid IL or missing references)
			//IL_020a: Unknown result type (might be due to invalid IL or missing references)
			//IL_020f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0214: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: Unknown result type (might be due to invalid IL or missing references)
			//IL_0225: Unknown result type (might be due to invalid IL or missing references)
			//IL_022a: Unknown result type (might be due to invalid IL or missing references)
			//IL_023b: Unknown result type (might be due to invalid IL or missing references)
			//IL_023d: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0265: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = lookup(m.sourcePrefab);
			Sign val2 = (((Object)(object)val != (Object)null) ? val.GetComponent<Sign>() : null);
			TextMeshProUGUI val3 = (((Object)(object)val2 != (Object)null) ? val2.m_textWidget : null);
			if ((Object)(object)val3 == (Object)null)
			{
				problems.Add("nameplate: no text widget on the vanilla '" + m.sourcePrefab + "'");
				return null;
			}
			Canvas val4 = null;
			Transform val5 = ((TMP_Text)val3).transform;
			while ((Object)(object)val5 != (Object)null && (Object)(object)val4 == (Object)null)
			{
				val4 = ((Component)val5).GetComponent<Canvas>();
				val5 = val5.parent;
			}
			if ((Object)(object)val4 == (Object)null)
			{
				problems.Add("nameplate: the vanilla sign's text has no canvas");
				return null;
			}
			Transform transform = val.transform;
			Matrix4x4 val6 = Matrix4x4.identity;
			Transform val7 = ((Component)val4).transform;
			while ((Object)(object)val7 != (Object)null && (Object)(object)val7 != (Object)(object)transform)
			{
				val6 = Matrix4x4.TRS(val7.localPosition, val7.localRotation, val7.localScale) * val6;
				val7 = val7.parent;
			}
			List<string> list = new List<string>();
			Transform val8 = ((TMP_Text)val3).transform;
			while ((Object)(object)val8 != (Object)null && (Object)(object)val8 != (Object)(object)((Component)val4).transform)
			{
				list.Insert(0, ((Object)val8).name);
				val8 = val8.parent;
			}
			string text = string.Join("/", list.ToArray());
			GameObject val9 = new GameObject("EP_NameplateFrame");
			val9.transform.SetParent(parent, false);
			val9.transform.localPosition = m.xform.position.ToVector();
			val9.transform.localRotation = m.xform.rotation.ToQuaternion();
			val9.transform.localScale = m.xform.scale.ToVector();
			val9.layer = LayerMask.NameToLayer("piece");
			GameObject val10 = Object.Instantiate<GameObject>(((Component)val4).gameObject, val9.transform, false);
			((Object)val10).name = "EP_NameplateCanvas";
			Vector3 val11 = Vector4.op_Implicit(((Matrix4x4)(ref val6)).GetColumn(0));
			Vector3 val12 = Vector4.op_Implicit(((Matrix4x4)(ref val6)).GetColumn(1));
			Vector3 val13 = Vector4.op_Implicit(((Matrix4x4)(ref val6)).GetColumn(2));
			val10.transform.localPosition = Vector4.op_Implicit(((Matrix4x4)(ref val6)).GetColumn(3));
			val10.transform.localRotation = Quaternion.LookRotation(val13, val12);
			val10.transform.localScale = new Vector3(((Vector3)(ref val11)).magnitude, ((Vector3)(ref val12)).magnitude, ((Vector3)(ref val13)).magnitude);
			Transform val14 = ((text.Length == 0) ? val10.transform : val10.transform.Find(text));
			TextMeshProUGUI obj = (((Object)(object)val14 != (Object)null) ? ((Component)val14).GetComponent<TextMeshProUGUI>() : null);
			if ((Object)(object)obj == (Object)null)
			{
				problems.Add("nameplate: the copied text widget was not found at '" + text + "'");
			}
			return obj;
		}

		public static void CopyEffects(GameObject root, BakedPrefab data, Func<string, GameObject> lookup, List<string> problems)
		{
			if (!string.IsNullOrEmpty(data.effectsFrom))
			{
				GameObject val = lookup(data.effectsFrom);
				if ((Object)(object)val == (Object)null)
				{
					problems.Add("effects: vanilla piece '" + data.effectsFrom + "' not found");
					return;
				}
				CopyField(val.GetComponent<Piece>(), root.GetComponent<Piece>(), "m_placeEffect", problems);
				WearNTear component = val.GetComponent<WearNTear>();
				WearNTear component2 = root.GetComponent<WearNTear>();
				CopyField(component, component2, "m_hitEffect", problems);
				CopyField(component, component2, "m_switchEffect", problems);
				CopyField(component, component2, "m_destroyedEffect", problems);
			}
		}

		private static void CopyField(object source, object target, string field, List<string> problems)
		{
			if (source == null || target == null)
			{
				problems.Add("effects: no component to copy " + field);
				return;
			}
			FieldInfo field2 = source.GetType().GetField(field, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (field2 == null)
			{
				problems.Add("effects: field " + field + " not found");
				return;
			}
			try
			{
				field2.SetValue(target, field2.GetValue(source));
			}
			catch (Exception ex)
			{
				problems.Add("effects: could not copy " + field + ": " + ex.Message);
			}
		}

		public static Quaternion IconRotation(BakedPrefab data)
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			float num = ((data.icon != null) ? data.icon.pitch : 18f);
			float num2 = ((data.icon != null) ? data.icon.yaw : (-18f));
			return Quaternion.Euler(num, 0f, 0f) * Quaternion.Euler(0f, 180f + num2, 0f);
		}

		public static BakedPrefab Load(string json)
		{
			return JsonConvert.DeserializeObject<BakedPrefab>(json);
		}

		public static string Fill(GameObject root, BakedPrefab data, Func<string, GameObject> lookup, List<string> problems)
		{
			//IL_0329: Unknown result type (might be due to invalid IL or missing references)
			//IL_033b: Unknown result type (might be due to invalid IL or missing references)
			//IL_04da: Unknown result type (might be due to invalid IL or missing references)
			//IL_04df: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f1: 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_0503: Unknown result type (might be due to invalid IL or missing references)
			//IL_023b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0365: Unknown result type (might be due to invalid IL or missing references)
			//IL_039c: Unknown result type (might be due to invalid IL or missing references)
			int num = LayerMask.NameToLayer("piece");
			int num2 = 0;
			int num3 = 0;
			if (data.parts == null)
			{
				data.parts = new List<BakedPart>();
			}
			if (data.colliders == null)
			{
				data.colliders = new List<BakedCollider>();
			}
			if (data.snapPoints == null)
			{
				data.snapPoints = new List<BakedV3>();
			}
			for (int i = 0; i < data.parts.Count; i++)
			{
				BakedPart bakedPart = data.parts[i];
				Mesh val = null;
				Material[] sharedMaterials = null;
				Transform val2 = FindSource(lookup, bakedPart.sourcePrefab, bakedPart.sourcePath);
				if ((Object)(object)val2 != (Object)null)
				{
					MeshFilter component = ((Component)val2).GetComponent<MeshFilter>();
					MeshRenderer component2 = ((Component)val2).GetComponent<MeshRenderer>();
					SkinnedMeshRenderer component3 = ((Component)val2).GetComponent<SkinnedMeshRenderer>();
					if ((Object)(object)component != (Object)null && (Object)(object)component2 != (Object)null)
					{
						val = component.sharedMesh;
						sharedMaterials = ((Renderer)component2).sharedMaterials;
					}
					else if ((Object)(object)component3 != (Object)null)
					{
						val = component3.sharedMesh;
						sharedMaterials = ((Renderer)component3).sharedMaterials;
					}
				}
				if ((Object)(object)val == (Object)null)
				{
					problems.Add("part " + i + ": no mesh at " + bakedPart.sourcePrefab + "/" + bakedPart.sourcePath);
					continue;
				}
				if (!string.IsNullOrEmpty(bakedPart.mesh) && ((Object)val).name != bakedPart.mesh)
				{
					problems.Add("part " + i + ": mesh is '" + ((Object)val).name + "', capture had '" + bakedPart.mesh + "'");
				}
				GameObject obj = NewChild((!string.IsNullOrEmpty(bakedPart.group)) ? GroupChild(root, bakedPart.group, num) : LookGroup(root, bakedPart.state, num), "EP_Part_" + i + "_" + bakedPart.sourcePrefab, bakedPart.xform, LayerOf(bakedPart.layer, num));
				obj.AddComponent<MeshFilter>().sharedMesh = val;
				MeshRenderer val3 = obj.AddComponent<MeshRenderer>();
				((Renderer)val3).sharedMaterials = sharedMaterials;
				if (Enum.TryParse<ShadowCastingMode>(bakedPart.shadowCasting, out ShadowCastingMode result))
				{
					((Renderer)val3).shadowCastingMode = result;
				}
				((Renderer)val3).receiveShadows = bakedPart.receiveShadows;
				num2++;
			}
			for (int j = 0; j < data.colliders.Count; j++)
			{
				BakedCollider bakedCollider = data.colliders[j];
				GameObject val4 = NewChild((!string.IsNullOrEmpty(bakedCollider.group)) ? GroupChild(root, bakedCollider.group, num) : root, "EP_Collider_" + j, bakedCollider.xform, LayerOf(bakedCollider.layer, num));
				bool flag = true;
				switch (bakedCollider.type)
				{
				case "BoxCollider":
				{
					BoxCollider obj3 = val4.AddComponent<BoxCollider>();
					obj3.center = bakedCollider.center.ToVector();
					obj3.size = bakedCollider.size.ToVector();
					((Collider)obj3).isTrigger = bakedCollider.isTrigger;
					break;
				}
				case "SphereCollider":
				{
					SphereCollider obj5 = val4.AddComponent<SphereCollider>();
					obj5.center = bakedCollider.center.ToVector();
					obj5.radius = bakedCollider.radius;
					((Collider)obj5).isTrigger = bakedCollider.isTrigger;
					break;
				}
				case "CapsuleCollider":
				{
					CapsuleCollider obj4 = val4.AddComponent<CapsuleCollider>();
					obj4.center = bakedCollider.center.ToVector();
					obj4.radius = bakedCollider.radius;
					obj4.height = bakedCollider.height;
					obj4.direction = bakedCollider.direction;
					((Collider)obj4).isTrigger = bakedCollider.isTrigger;
					break;
				}
				case "MeshCollider":
				{
					Transform val5 = FindSource(lookup, bakedCollider.sourcePrefab, bakedCollider.sourcePath);
					MeshCollider val6 = (((Object)(object)val5 != (Object)null) ? ((Component)val5).GetComponent<MeshCollider>() : null);
					if ((Object)(object)val6 != (Object)null && (Object)(object)val6.sharedMesh != (Object)null)
					{
						MeshCollider obj2 = val4.AddComponent<MeshCollider>();
						obj2.sharedMesh = val6.sharedMesh;
						obj2.convex = bakedCollider.convex;
						((Collider)obj2).isTrigger = bakedCollider.isTrigger;
					}
					else
					{
						flag = false;
					}
					break;
				}
				default:
					flag = false;
					break;
				}
				if (!flag)
				{
					problems.Add("collider " + j + " (" + bakedCollider.type + "): not built");
					Object.DestroyImmediate((Object)(object)val4);
				}
				else
				{
					num3++;
				}
			}
			foreach (BakedV3 snapPoint in data.snapPoints)
			{
				GameObject val7 = new GameObject("EP_snappoint");
				val7.transform.SetParent(root.transform, false);
				val7.transform.localPosition = snapPoint.ToVector();
				val7.tag = "snappoint";
				val7.SetActive(false);
			}
			return data.name + ": " + num2 + "/" + data.parts.Count + " meshes, " + num3 + "/" + data.colliders.Count + " colliders, " + data.snapPoints.Count + " snap points";
		}

		private static Transform FindSource(Func<string, GameObject> lookup, string prefab, string path)
		{
			GameObject val = lookup(prefab);
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			if (string.IsNullOrEmpty(path))
			{
				return val.transform;
			}
			return val.transform.Find(path);
		}

		private static GameObject GroupChild(GameObject root, string name, int layer)
		{
			//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_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Expected O, but got Unknown
			Transform val = root.transform.Find(name);
			if ((Object)(object)val != (Object)null)
			{
				return ((Component)val).gameObject;
			}
			GameObject val2 = new GameObject(name);
			val2.transform.SetParent(root.transform, false);
			val2.layer = layer;
			return val2;
		}

		private static GameObject LookGroup(GameObject root, string state, int layer)
		{
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Expected O, but got Unknown
			string text = state switch
			{
				"broken" => "EP_Broken", 
				"worn" => "EP_Worn", 
				"new" => "EP_New", 
				_ => null, 
			};
			if (text == null)
			{
				return root;
			}
			Transform val = root.transform.Find(text);
			if ((Object)(object)val != (Object)null)
			{
				return ((Component)val).gameObject;
			}
			GameObject val2 = new GameObject(text);
			val2.transform.SetParent(root.transform, false);
			val2.layer = layer;
			val2.SetActive(state == "new");
			return val2;
		}

		private static GameObject NewChild(GameObject root, string name, BakedXform x, int layer)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: 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_002e: 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_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Expected O, but got Unknown
			GameObject val = new GameObject(name);
			val.transform.SetParent(root.transform, false);
			val.transform.localPosition = x.position.ToVector();
			val.transform.localRotation = x.rotation.ToQuaternion();
			val.transform.localScale = x.scale.ToVector();
			val.layer = layer;
			return val;
		}

		private static int LayerOf(string name, int fallback)
		{
			int num = (string.IsNullOrEmpty(name) ? (-1) : LayerMask.NameToLayer(name));
			if (num < 0)
			{
				return fallback;
			}
			return num;
		}
	}
	public class EP_BulkBin : MonoBehaviour, IEPNameplateText
	{
		public const string PrefabName = "EP_Bulk_Storage_Bin";

		public const string MaterialKey = "EP_binMaterial";

		public const string DefaultSign = "Bulk Bin";

		public bool WoodRack;

		private ZNetView _nview;

		internal ZNetView View
		{
			get
			{
				if ((Object)(object)_nview == (Object)null)
				{
					_nview = ((Component)this).GetComponentInParent<ZNetView>();
				}
				return _nview;
			}
		}

		internal string RememberedMaterial()
		{
			if ((Object)(object)_nview == (Object)null || !_nview.IsValid())
			{
				return "";
			}
			return _nview.GetZDO().GetString("EP_binMaterial", "");
		}

		public string GetNameplateText()
		{
			string text = RememberedMaterial();
			if (!string.IsNullOrEmpty(text))
			{
				return Localization.instance.Localize(text);
			}
			return "Bulk Bin";
		}
	}
	internal static class BulkBinLock
	{
		[HarmonyPatch(typeof(Container), "Awake")]
		private static class ContainerAwake
		{
			private static void Postfix(Container __instance)
			{
				EP_BulkBin componentInParent = ((Component)__instance).GetComponentInParent<EP_BulkBin>();
				if ((Object)(object)componentInParent != (Object)null)
				{
					Register(__instance.GetInventory(), componentInParent);
				}
				EP_Cabinet componentInParent2 = ((Component)__instance).GetComponentInParent<EP_Cabinet>();
				if ((Object)(object)componentInParent2 != (Object)null)
				{
					RegisterCabinet(__instance.GetInventory(), componentInParent2);
				}
			}
		}

		[HarmonyPatch(typeof(Container), "GetHoverText")]
		private static class ContainerHover
		{
			private static void Postfix(Container __instance, ref string __result)
			{
				if (!_anyBin || string.IsNullOrEmpty(__result))
				{
					return;
				}
				Inventory inventory = __instance.GetInventory();
				if (inventory == null || !Bins.TryGetValue(inventory, out var value) || !value.WoodRack)
				{
					return;
				}
				List<ItemData> allItems = inventory.GetAllItems();
				string text = ((allItems.Count > 0) ? allItems[0].m_shared.m_name : value.RememberedMaterial());
				if (!string.IsNullOrEmpty(text))
				{
					string text2 = Localization.instance.Localize(__instance.m_name);
					int num = __result.IndexOf(text2, StringComparison.Ordinal);
					if (num >= 0)
					{
						__result = __result.Insert(num + text2.Length, " (" + Localization.instance.Localize(text) + ")");
					}
				}
			}
		}

		[HarmonyPatch(typeof(Container), "Save")]
		private static class ContainerSave
		{
			private static void Postfix(Container __instance)
			{
				Inventory inventory = __instance.GetInventory();
				if (!_anyBin || inventory == null || !Bins.TryGetValue(inventory, out var value))
				{
					return;
				}
				ZNetView view = value.View;
				if ((Object)(object)view == (Object)null || !view.IsValid() || !view.IsOwner())
				{
					return;
				}
				List<ItemData> allItems = inventory.GetAllItems();
				if (allItems.Count != 0)
				{
					string name = allItems[0].m_shared.m_name;
					if (view.GetZDO().GetString("EP_binMaterial", "") != name)
					{
						view.GetZDO().Set("EP_binMaterial", name);
					}
				}
			}
		}

		[HarmonyPatch(typeof(Inventory), "CanAddItem", new Type[]
		{
			typeof(ItemData),
			typeof(int)
		})]
		private static class CanAddItemData
		{
			[HarmonyPriority(800)]
			private static bool Prefix(Inventory __instance, ItemData item, ref bool __result)
			{
				if (!Refuse(__instance, item, speak: false))
				{
					return true;
				}
				__result = false;
				return false;
			}
		}

		[HarmonyPatch(typeof(Inventory), "AddItem", new Type[] { typeof(ItemData) })]
		private static class AddItemData
		{
			[HarmonyPriority(800)]
			private static bool Prefix(Inventory __instance, ItemData item, ref bool __result)
			{
				if (!Refuse(__instance, item, speak: true))
				{
					return true;
				}
				__result = false;
				return false;
			}
		}

		[HarmonyPatch(typeof(Inventory), "AddItem", new Type[]
		{
			typeof(ItemData),
			typeof(Vector2i)
		})]
		private static class AddItemDataPos
		{
			[HarmonyPriority(800)]
			private static bool Prefix(Inventory __instance, ItemData item, ref bool __result)
			{
				if (!Refuse(__instance, item, speak: true))
				{
					return true;
				}
				__result = false;
				return false;
			}
		}

		[HarmonyPatch(typeof(Inventory), "AddItem", new Type[]
		{
			typeof(GameObject),
			typeof(int)
		})]
		private static class AddItemPrefab
		{
			[HarmonyPriority(800)]
			private static bool Prefix(Inventory __instance, GameObject prefab, ref bool __result)
			{
				if (!Refuse(__instance, FromPrefab(prefab), speak: true))
				{
					return true;
				}
				__result = false;
				return false;
			}
		}

		[HarmonyPatch(typeof(Inventory), "AddItem", new Type[]
		{
			typeof(ItemData),
			typeof(int),
			typeof(int),
			typeof(int),
			typeof(bool)
		})]
		private static class AddItemSlot
		{
			[HarmonyPriority(800)]
			private static bool Prefix(Inventory __instance, ItemData item, ref bool __result)
			{
				if (!Refuse(__instance, item, speak: true))
				{
					return true;
				}
				__result = false;
				return false;
			}
		}

		private static readonly ConditionalWeakTable<Inventory, EP_BulkBin> Bins = new ConditionalWeakTable<Inventory, EP_BulkBin>();

		private static readonly ConditionalWeakTable<Inventory, EP_Cabinet> Cabinets = new ConditionalWeakTable<Inventory, EP_Cabinet>();

		private static float _lastMessage = -10f;

		private static bool _anyBin;

		private static readonly string[] BuiltIn = new string[34]
		{
			"Stone", "Flint", "Coal", "Grausten", "BlackMarble", "Obsidian", "SulfurStone", "Tar", "Ice", "FaderEmber",
			"SurtlingCore", "BlackCore", "Resin", "Sap", "Ooze", "Guck", "CopperOre", "TinOre", "IronOre", "SilverOre",
			"FlametalOreNew", "IronScrap", "BlackMetalScrap", "EP_FlametalScrap", "CopperScrap", "BronzeScrap", "EP_TinScrap", "EP_SilverScrap", "BoneFragments", "CharredBone",
			"WitheredBone", "Chitin", "Carapace", "Mandible"
		};

		private static HashSet<string> _allowed;

		private static readonly HashSet<string> WoodAllowed = new HashSet<string>(new string[7] { "Wood", "FineWood", "RoundLog", "YggdrasilWood", "Blackwood", "ElderBark", "Frostwood" }, StringComparer.OrdinalIgnoreCase);

		internal static void RebuildAllowed()
		{
			HashSet<string> hashSet = new HashSet<string>(BuiltIn, StringComparer.OrdinalIgnoreCase);
			string[] array = ((Plugin.ExtraItems != null) ? Plugin.ExtraItems.Value : "").Split(new char[3] { ',', ';', '\n' }, StringSplitOptions.RemoveEmptyEntries);
			for (int i = 0; i < array.Length; i++)
			{
				string text = array[i].Trim();
				if (text.Length > 0)
				{
					hashSet.Add(text);
				}
			}
			_allowed = hashSet;
		}

		internal static void Register(Inventory inv, EP_BulkBin bin)
		{
			if (inv != null && !((Object)(object)bin == (Object)null))
			{
				_anyBin = true;
				Bins.Remove(inv);
				Bins.Add(inv, bin);
			}
		}

		internal static void RegisterCabinet(Inventory inv, EP_Cabinet cab)
		{
			if (inv != null && !((Object)(object)cab == (Object)null))
			{
				_anyBin = true;
				Cabinets.Remove(inv);
				Cabinets.Add(inv, cab);
			}
		}

		private static bool RefuseCabinet(EP_Cabinet cab, ItemData item, bool speak)
		{
			string prefabName = PrefabNameOf(item);
			bool flag = !CabinetConfig.IsBlocked(prefabName) && (CabinetConfig.IsExtra(prefabName) || cab.CanHold(item));
			if (!flag && speak)
			{
				Say("Cabinet: not accepted");
			}
			return !flag;
		}

		private static string PrefabNameOf(ItemData item)
		{
			if (item == null || (Object)(object)item.m_dropPrefab == (Object)null)
			{
				return "";
			}
			string name = ((Object)item.m_dropPrefab).name;
			if (!name.EndsWith("(Clone)", StringComparison.Ordinal))
			{
				return name;
			}
			return name.Substring(0, name.Length - 7);
		}

		private static void Say(string text)
		{
			if (!((Object)(object)Player.m_localPlayer == (Object)null) && !(Time.unscaledTime - _lastMessage < 1f))
			{
				_lastMessage = Time.unscaledTime;
				((Character)Player.m_localPlayer).Message((MessageType)2, text, 0, (Sprite)null, false);
			}
		}

		internal static bool Refuse(Inventory inv, ItemData item, bool speak)
		{
			if (!_anyBin || item == null || inv == null)
			{
				return false;
			}
			if (Cabinets.TryGetValue(inv, out var value))
			{
				return RefuseCabinet(value, item, speak);
			}
			if (!Bins.TryGetValue(inv, out var value2))
			{
				return false;
			}
			if (_allowed == null)
			{
				RebuildAllowed();
			}
			string text = (value2.WoodRack ? "Woodpile rack" : "Bulk bin");
			if (!(value2.WoodRack ? WoodAllowed : _allowed).Contains(PrefabNameOf(item)))
			{
				if (speak)
				{
					Say(text + ": not accepted");
				}
				return true;
			}
			List<ItemData> allItems = inv.GetAllItems();
			if (allItems.Count > 0 && allItems[0].m_shared.m_name != item.m_shared.m_name)
			{
				if (speak)
				{
					Say(text + ": only " + Localization.instance.Localize(allItems[0].m_shared.m_name));
				}
				return true;
			}
			return false;
		}

		private static ItemData FromPrefab(GameObject prefab)
		{
			ItemDrop val = (((Object)(object)prefab != (Object)null) ? prefab.GetComponent<ItemDrop>() : null);
			if (!((Object)(object)val != (Object)null))
			{
				return null;
			}
			return val.m_itemData;
		}
	}
	internal static class FillConfig
	{
		internal static ConfigEntry<float> HalfX;

		internal static ConfigEntry<float> HalfZ;

		internal static ConfigEntry<float> CenterX;

		internal static ConfigEntry<float> CenterZ;

		internal static ConfigEntry<float> FloorY;

		internal static ConfigEntry<float> RimY;

		internal static ConfigEntry<float> PieceScale;

		internal static ConfigEntry<float> MoundInset;

		internal static ConfigEntry<float> MoundMax;

		internal static ConfigEntry<float> PeakSize;

		internal static ConfigEntry<float> MoundBulge;

		internal static ConfigEntry<float> MoundCurve;

		internal static ConfigEntry<float> Scatter;

		internal static ConfigEntry<float> Packing;

		internal static ConfigEntry<int> Layers;

		internal static ConfigEntry<bool> FillSides;

		internal static int Version;

		internal static event Action Changed;

		internal static void Bind(BaseUnityPlugin p)
		{
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Expected O, but got Unknown
			HalfX = F(p, "Bulk bin fill display", "Inside half width", 0.75f, "Half of the inside width (left to right) the contents may fill. Lower it if pieces poke through the walls.");
			HalfZ = F(p, "Bulk bin fill display", "Inside half depth", 0.75f, "Half of the inside depth (front to back).");
			CenterX = F(p, "Bulk bin fill display", "Inside center X", 0f, "Shifts the filled area sideways.");
			CenterZ = F(p, "Bulk bin fill display", "Inside center Z", 0f, "Shifts the filled area front to back.");
			FloorY = F(p, "Bulk bin fill display", "Floor height", 0.1f, "Height of the top of the floor above the bottom of the bin.");
			RimY = F(p, "Bulk bin fill display", "Rim height", 1f, "Height of the top of the walls. The pile is level with this before the mound starts.");
			PieceScale = F(p, "Bulk bin fill display", "Piece size", 1f, "Multiplies the size of each shown piece (1 = about a quarter of a metre).");
			Scatter = F(p, "Bulk bin fill display", "Scatter", 1f, "How far pieces wander from their grid spot (1 = up to half the spacing between pieces in any direction, 0 = neat grid). Rotation is always fully random.");
			Packing = F(p, "Bulk bin fill display", "Packing", 0.6f, "Distance between neighbouring pieces as a fraction of a piece's size. Lower packs the pile tighter (more pieces, less see-through), 1 = touching side by side.");
			Layers = p.Config.Bind<int>("Bulk bin fill display", "Visible layers", 2, new ConfigDescription("How many layers under the surface are drawn, so you cannot see gaps into the pile. 1 = surface only.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 4), Array.Empty<object>()));
			MoundInset = F(p, "Bulk bin fill display", "Mound edge gap", 0f, "Distance from the walls where the mound starts to rise above the rim. Nothing rises right at the lip.");
			MoundMax = F(p, "Bulk bin fill display", "Mound height", 0.7f, "Height of the mound's flat top above the rim (the no-build space above the bin is 1 m).");
			PeakSize = F(p, "Bulk bin fill display", "Mound top size", 0.1f, "Width of the flat top of the mound. A wider top looks less like a spike but makes the sides steeper.");
			MoundBulge = F(p, "Bulk bin fill display", "Mound bulge", 0.9f, "Shape of the mound seen from above. 0 = straight-sided pyramid with square contours, 1 = round. In between the corner ridges bulge out like a heap.");
			MoundCurve = F(p, "Bulk bin fill display", "Mound curve", 0.8f, "Profile of the mound's sides. 1 = straight slope; above 1 the foot flares out gently toward the walls and the top is steeper; below 1 the sides bulge out like a dome.");
			FillSides = p.Config.Bind<bool>("Bulk bin fill display", "Fill behind the gaps", true, "Show pieces behind the gaps between the wall beams so the bin does not look empty from the side.");
			ConfigEntry<float>[] array = new ConfigEntry<float>[14]
			{
				HalfX, HalfZ, CenterX, CenterZ, FloorY, RimY, PieceScale, Scatter, Packing, MoundInset,
				MoundMax, PeakSize, MoundBulge, MoundCurve
			};
			for (int i = 0; i < array.Length; i++)
			{
				array[i].SettingChanged += delegate
				{
					Raise();
				};
			}
			Layers.SettingChanged += delegate
			{
				Raise();
			};
			FillSides.SettingChanged += delegate
			{
				Raise();
			};
		}

		private static void Raise()
		{
			Version++;
			if (FillConfig.Changed != null)
			{
				FillConfig.Changed();
			}
		}

		private static ConfigEntry<float> F(BaseUnityPlugin p, string s, string k, float v, string d)
		{
			return p.Config.Bind<float>(s, k, v, d);
		}
	}
	public class EP_BulkBinFill : MonoBehaviour
	{
		private struct Col
		{
			public float X;

			public float Z;

			public float Mound;

			public bool Edge;

			public int Levels;
		}

		private struct Spot
		{
			public int Col;

			public int Level;
		}

		private static readonly List<EP_BulkBinFill> Live;

		private static readonly Dictionary<string, GameObject> Templates;

		private static Transform _holder;

		internal static readonly Dictionary<string, Vector3> Dims;

		private const float Cell = 0.25f;

		private const float NearRange = 70f;

		private static int _planVersion;

		private static List<Col> _cols;

		private static List<Spot> _plan;

		private static float _size;

		private static float _spacing;

		private static float _restY;

		private static float _dy;

		private static float _hx;

		private static float _hz;

		private static int _nx;

		private static int _nz;

		private static float _cellX;

		private static float _cellZ;

		private static List<int> _levelCount;

		private static int[] _nEff;

		private static bool[] _taken;

		private Inventory _inv;

		private GameObject _template;

		private Transform _root;

		private readonly List<GameObject> _pool = new List<GameObject>();

		private int _lastCount = -1;

		private int _lastFilled = -1;

		private string _lastPrefab = "";

		private bool _far;

		private bool _dirty;

		private PileColliders _pile;

		private static int[] _levels;

		private static readonly List<Vector3> SpotBuf;

		static EP_BulkBinFill()
		{
			Live = new List<EP_BulkBinFill>();
			Templates = new Dictionary<string, GameObject>();
			Dims = new Dictionary<string, Vector3>();
			_planVersion = -1;
			_nEff = new int[0];
			_taken = new bool[0];
			_levels = new int[0];
			SpotBuf = new List<Vector3>(256);
			FillConfig.Changed += delegate
			{
				foreach (EP_BulkBinFill item in Live)
				{
					item.Redraw(force: true);
				}
			};
		}

		private void Start()
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			Container componentInParent = ((Component)this).GetComponentInParent<Container>();
			_inv = (