Decompiled source of EffortlessStorage v1.0.0

plugins/EffortlessStorage.dll

Decompiled 3 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: AssemblyCompany("EffortlessStorage")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+eaa141ec07961ac4f246c43a4211870b981ae374")]
[assembly: AssemblyProduct("EffortlessStorage")]
[assembly: AssemblyTitle("EffortlessStorage")]
[assembly: AssemblyVersion("1.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 PlayToDate.EffortlessStorage
{
	internal static class Compat
	{
		private static readonly Dictionary<string, MethodInfo> Cache = new Dictionary<string, MethodInfo>();

		private static readonly HashSet<string> Warned = new HashSet<string>();

		private const BindingFlags All = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;

		internal static object Call(object target, string name, params object[] lead)
		{
			if (target == null)
			{
				return null;
			}
			Type type = target.GetType();
			string text = type.FullName + "." + name + "/" + string.Join(",", lead.Select((object a) => (a != null) ? a.GetType().Name : "null"));
			if (!Cache.TryGetValue(text, out var value))
			{
				value = Find(type, name, lead);
				Cache[text] = value;
				if (value != null)
				{
					Plugin.Log("Effortless Storage: using " + type.Name + "." + name + "(" + string.Join(", ", from p in value.GetParameters()
						select p.ParameterType.Name) + ")");
				}
			}
			if (value == null)
			{
				if (Warned.Add(text))
				{
					Plugin.Warn("Effortless Storage: " + type.Name + "." + name + " not found");
				}
				return null;
			}
			ParameterInfo[] parameters = value.GetParameters();
			object[] array = new object[parameters.Length];
			for (int num = 0; num < parameters.Length; num++)
			{
				if (num < lead.Length)
				{
					array[num] = lead[num];
				}
				else if (parameters[num].HasDefaultValue)
				{
					array[num] = parameters[num].DefaultValue;
				}
				else
				{
					array[num] = (parameters[num].ParameterType.IsValueType ? Activator.CreateInstance(parameters[num].ParameterType) : null);
				}
			}
			return value.Invoke(target, array);
		}

		private static MethodInfo Find(Type t, string name, object[] lead)
		{
			MethodInfo methodInfo = null;
			Type type = t;
			while (type != null)
			{
				MethodInfo[] methods = type.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				foreach (MethodInfo methodInfo2 in methods)
				{
					if (methodInfo2.Name != name)
					{
						continue;
					}
					ParameterInfo[] parameters = methodInfo2.GetParameters();
					if (parameters.Length >= lead.Length)
					{
						bool flag = true;
						for (int j = 0; j < lead.Length && flag; j++)
						{
							Type parameterType = parameters[j].ParameterType;
							flag = ((lead[j] != null) ? parameterType.IsAssignableFrom(lead[j].GetType()) : (!parameterType.IsValueType));
						}
						for (int k = lead.Length; k < parameters.Length && flag; k++)
						{
							flag = parameters[k].HasDefaultValue || parameters[k].ParameterType.IsValueType || !parameters[k].ParameterType.IsByRef;
						}
						if (flag && (methodInfo == null || parameters.Length < methodInfo.GetParameters().Length))
						{
							methodInfo = methodInfo2;
						}
					}
				}
				if (methodInfo != null)
				{
					return methodInfo;
				}
				type = type.BaseType;
			}
			return null;
		}

		internal static void Message(Player p, MessageType type, string text)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			Call(p, "Message", type, text);
		}

		internal static bool AddItemAt(Inventory inv, ItemData item, int amount, int x, int y)
		{
			object obj = Call(inv, "AddItem", item, amount, x, y);
			bool flag = default(bool);
			int num;
			if (obj is bool)
			{
				flag = (bool)obj;
				num = 1;
			}
			else
			{
				num = 0;
			}
			return (byte)((uint)num & (flag ? 1u : 0u)) != 0;
		}

		internal static void Changed(Inventory inv)
		{
			Call(inv, "Changed");
		}
	}
	[BepInPlugin("it.playtodate.effortlessstorage", "Effortless Storage", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public const string Guid = "it.playtodate.effortlessstorage";

		public const string Name = "Effortless Storage";

		public const string Version = "1.0.0";

		public const string PrefabName = "PTD_DepositRune";

		internal static ConfigEntry<float> Radius;

		internal static ConfigEntry<bool> Labels;

		internal static Plugin Self;

		private void Awake()
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Expected O, but got Unknown
			Self = this;
			Radius = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Radius", 20f, new ConfigDescription("Chests within this distance (meters) of the rune. / Scrigni entro questa distanza (metri) dalla runa.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(5f, 40f), Array.Empty<object>()));
			Labels = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Show labels", true, "Show over each chest what it received. / Mostra sopra ogni scrigno cosa ha ricevuto.");
			AddTranslations();
			PrefabManager.OnVanillaPrefabsAvailable += AddPiece;
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Effortless Storage 1.0.0 ready");
		}

		internal static void Log(string s)
		{
			Plugin self = Self;
			if (self != null)
			{
				((BaseUnityPlugin)self).Logger.LogInfo((object)s);
			}
		}

		internal static void Warn(string s)
		{
			Plugin self = Self;
			if (self != null)
			{
				((BaseUnityPlugin)self).Logger.LogWarning((object)s);
			}
		}

		private void AddTranslations()
		{
			CustomLocalization localization = LocalizationManager.Instance.GetLocalization();
			string text = "English";
			localization.AddTranslation(ref text, new Dictionary<string, string>
			{
				{ "ptd_depositrune", "Deposit Rune" },
				{ "ptd_depositrune_desc", "Sends what you carry to the nearby chests that already hold it." },
				{ "ptd_deposit_use", "Deposit into chests" },
				{ "ptd_deposit_hint", "Chests within {0} m · only where the item already is" },
				{ "ptd_deposit_done", "Deposited {0} items in {1} chests" },
				{ "ptd_deposit_done1", "Deposited {0} items in 1 chest" },
				{ "ptd_deposit_none", "Nothing to deposit: no nearby chest holds what you carry" },
				{ "ptd_deposit_left", "Chests full, kept: {0}" },
				{ "ptd_deposit_busy", "{0} chests skipped: someone is using them" },
				{ "ptd_deposit_noaccess", "You have no access here" }
			});
			text = "Italian";
			localization.AddTranslation(ref text, new Dictionary<string, string>
			{
				{ "ptd_depositrune", "Runa del Deposito" },
				{ "ptd_depositrune_desc", "Manda quello che hai addosso negli scrigni vicini che già lo contengono." },
				{ "ptd_deposit_use", "Deposita negli scrigni" },
				{ "ptd_deposit_hint", "Scrigni entro {0} m · solo dove l'oggetto c'è già" },
				{ "ptd_deposit_done", "Depositati {0} oggetti in {1} scrigni" },
				{ "ptd_deposit_done1", "Depositati {0} oggetti in 1 scrigno" },
				{ "ptd_deposit_none", "Niente da depositare: nessuno scrigno vicino contiene quello che hai" },
				{ "ptd_deposit_left", "Scrigni pieni, tenuti: {0}" },
				{ "ptd_deposit_busy", "{0} scrigni saltati: qualcuno li sta usando" },
				{ "ptd_deposit_noaccess", "Qui non hai accesso" }
			});
		}

		private void AddPiece()
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: 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_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Expected O, but got Unknown
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Expected O, but got Unknown
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Expected O, but got Unknown
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Expected O, but got Unknown
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Expected O, but got Unknown
			PrefabManager.OnVanillaPrefabsAvailable -= AddPiece;
			try
			{
				GameObject val = RuneBuilder.Build("PTD_DepositRune");
				PieceConfig val2 = new PieceConfig
				{
					Name = "$ptd_depositrune",
					Description = "$ptd_depositrune_desc",
					PieceTable = PieceTables.Hammer,
					Category = PieceCategories.Furniture,
					CraftingStation = CraftingStations.Workbench,
					Icon = RuneBuilder.Icon()
				};
				val2.AddRequirement(new RequirementConfig("Stone", 10, 0, true));
				val2.AddRequirement(new RequirementConfig("Wood", 5, 0, true));
				val2.AddRequirement(new RequirementConfig("Resin", 2, 0, true));
				PieceManager.Instance.AddPiece(new CustomPiece(val, false, val2));
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Effortless Storage: Deposit Rune added to the hammer (Furniture)");
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("Effortless Storage: could not create the Deposit Rune: " + ex));
			}
		}
	}
	public class DepositRune : MonoBehaviour, Hoverable, Interactable
	{
		private ZNetView _nview;

		private float _busyUntil;

		private static bool _hoverErrLogged;

		private Coroutine _glow;

		private void Awake()
		{
			_nview = ((Component)this).GetComponent<ZNetView>();
			Plugin.Log($"Effortless Storage: rune ready (layer {LayerMask.LayerToName(((Component)this).gameObject.layer)}, colliders {((Component)this).GetComponentsInChildren<Collider>().Length})");
		}

		public string GetHoverName()
		{
			return Localization.instance.Localize("$ptd_depositrune");
		}

		public string GetHoverText()
		{
			try
			{
				return HoverText();
			}
			catch (Exception ex)
			{
				if (!_hoverErrLogged)
				{
					_hoverErrLogged = true;
					Plugin.Warn("Effortless Storage: hover text failed: " + ex);
				}
				return Localization.instance.Localize("$ptd_depositrune\n[<color=yellow><b>$KEY_Use</b></color>] $ptd_deposit_use");
			}
		}

		private string HoverText()
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			string text = Localization.instance.Localize("$ptd_depositrune");
			if (!PrivateArea.CheckAccess(((Component)this).transform.position, 0f, false, false))
			{
				return text + "\n" + Localization.instance.Localize("$piece_noaccess");
			}
			string text2 = string.Format(Localization.instance.Localize("$ptd_deposit_hint"), Mathf.RoundToInt(Plugin.Radius.Value));
			return Localization.instance.Localize(text + "\n[<color=yellow><b>$KEY_Use</b></color>] $ptd_deposit_use") + "\n<size=80%><color=#bba98a>" + text2 + "</color></size>";
		}

		public bool Interact(Humanoid user, bool hold, bool alt)
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			Plugin.Log("Effortless Storage: rune used");
			if (hold || Time.time < _busyUntil)
			{
				return false;
			}
			Player val = (Player)(object)((user is Player) ? user : null);
			if ((Object)(object)val == (Object)null || (Object)(object)val != (Object)(object)Player.m_localPlayer)
			{
				return false;
			}
			if (!PrivateArea.CheckAccess(((Component)this).transform.position, 0f, true, false))
			{
				return true;
			}
			_busyUntil = Time.time + 1f;
			Depositor.Run(val, this);
			return true;
		}

		public bool UseItem(Humanoid user, ItemData item)
		{
			return false;
		}

		public virtual float GetHoverOffset()
		{
			return 0f;
		}

		internal void Glow()
		{
			if (_glow != null)
			{
				((MonoBehaviour)this).StopCoroutine(_glow);
			}
			_glow = ((MonoBehaviour)this).StartCoroutine(GlowRoutine());
		}

		internal void Beams(List<KeyValuePair<Container, Dictionary<string, int>>> targets)
		{
			for (int i = 0; i < targets.Count; i++)
			{
				((MonoBehaviour)this).StartCoroutine(BeamRoutine(targets[i].Key, targets[i].Value, (float)i * 0.12f));
			}
		}

		private IEnumerator BeamRoutine(Container chest, Dictionary<string, int> got, float delay)
		{
			if (delay > 0f)
			{
				yield return (object)new WaitForSeconds(delay);
			}
			if (!Object.op_Implicit((Object)(object)chest))
			{
				yield break;
			}
			Shader val = RuneBuilder.FxShader();
			Color val2 = default(Color);
			((Color)(ref val2))..ctor(1f, 0.37f, 0.64f);
			Color val3 = default(Color);
			((Color)(ref val3))..ctor(0.3f, 0.85f, 1f);
			Vector3 a = ((Component)this).transform.TransformPoint(new Vector3(0f, 1.12f, 0.2f));
			Vector3 b = ((Component)chest).transform.position + Vector3.up * 0.6f;
			float num = Vector3.Distance(a, b);
			Vector3 ctrl = (a + b) * 0.5f + Vector3.up * (0.8f + num * 0.18f);
			GameObject lineGo = new GameObject("PTD_DepositBeam");
			LineRenderer line = lineGo.AddComponent<LineRenderer>();
			((Renderer)line).material = new Material(val);
			line.useWorldSpace = true;
			line.numCapVertices = 4;
			((Renderer)line).shadowCastingMode = (ShadowCastingMode)0;
			line.widthCurve = new AnimationCurve((Keyframe[])(object)new Keyframe[2]
			{
				new Keyframe(0f, 0.025f),
				new Keyframe(1f, 0.07f)
			});
			Gradient val4 = new Gradient();
			val4.SetKeys((GradientColorKey[])(object)new GradientColorKey[2]
			{
				new GradientColorKey(val2, 0f),
				new GradientColorKey(val3, 1f)
			}, (GradientAlphaKey[])(object)new GradientAlphaKey[3]
			{
				new GradientAlphaKey(0f, 0f),
				new GradientAlphaKey(0.85f, 0.7f),
				new GradientAlphaKey(1f, 1f)
			});
			line.colorGradient = val4;
			GameObject orb = GameObject.CreatePrimitive((PrimitiveType)0);
			Collider component = orb.GetComponent<Collider>();
			if (Object.op_Implicit((Object)(object)component))
			{
				Object.Destroy((Object)(object)component);
			}
			((Object)orb).name = "PTD_DepositOrb";
			orb.transform.localScale = Vector3.one * 0.11f;
			((Renderer)orb.GetComponent<MeshRenderer>()).material = new Material(val)
			{
				color = Color.Lerp(val3, Color.white, 0.35f)
			};
			Light ol = orb.AddComponent<Light>();
			ol.type = (LightType)2;
			ol.color = val3;
			ol.range = 2.2f;
			ol.intensity = 1.4f;
			ol.shadows = (LightShadows)0;
			float travel = 0.45f + num * 0.035f;
			float t = 0f;
			while (t < travel)
			{
				t += Time.deltaTime;
				float num2 = Mathf.SmoothStep(0f, 1f, Mathf.Clamp01(t / travel));
				float num3 = Mathf.Max(0f, num2 - 0.45f);
				line.positionCount = 24;
				for (int i = 0; i < 24; i++)
				{
					line.SetPosition(i, P(Mathf.Lerp(num3, num2, (float)i / 23f)));
				}
				if (Object.op_Implicit((Object)(object)orb))
				{
					orb.transform.position = P(num2);
				}
				yield return null;
			}
			if (Object.op_Implicit((Object)(object)chest))
			{
				try
				{
					Compat.Call(chest.m_openEffects, "Create", ((Component)chest).transform.position, ((Component)chest).transform.rotation, null, 1f, -1);
				}
				catch (Exception ex)
				{
					Plugin.Warn("Effortless Storage: chest sound failed (" + ex.Message + ")");
				}
				Depositor.Highlight(chest);
				if (Plugin.Labels.Value)
				{
					Depositor.Label(chest, got);
				}
			}
			float f = 0f;
			float fade = 0.35f;
			while (f < fade)
			{
				f += Time.deltaTime;
				float num4 = Mathf.Clamp01(f / fade);
				for (int j = 0; j < 24; j++)
				{
					line.SetPosition(j, P(Mathf.Lerp(0.55f + 0.45f * num4, 1f, (float)j / 23f)));
				}
				line.widthMultiplier = 1f - num4;
				if (Object.op_Implicit((Object)(object)orb))
				{
					orb.transform.localScale = Vector3.one * 0.11f * (1f + num4 * 1.5f);
					ol.intensity = 1.4f * (1f - num4);
				}
				yield return null;
			}
			Object.Destroy((Object)(object)lineGo);
			if (Object.op_Implicit((Object)(object)orb))
			{
				Object.Destroy((Object)(object)orb);
			}
			Vector3 P(float u)
			{
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				//IL_0015: Unknown result type (might be due to invalid IL or missing references)
				//IL_002a: Unknown result type (might be due to invalid IL or missing references)
				//IL_002f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0034: Unknown result type (might be due to invalid IL or missing references)
				//IL_003d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0042: Unknown result type (might be due to invalid IL or missing references)
				//IL_0047: Unknown result type (might be due to invalid IL or missing references)
				return (1f - u) * (1f - u) * a + 2f * (1f - u) * u * ctrl + u * u * b;
			}
		}

		private IEnumerator GlowRoutine()
		{
			Light light = ((Component)this).GetComponentInChildren<Light>();
			Transform obj = ((Component)this).transform.Find("Rune");
			MeshRenderer val = ((obj != null) ? ((Component)obj).GetComponent<MeshRenderer>() : null);
			Material mat = (((Object)(object)val != (Object)null) ? ((Renderer)val).material : null);
			List<Transform> sparks = new List<Transform>();
			for (int i = 0; i < 18; i++)
			{
				GameObject val2 = GameObject.CreatePrimitive((PrimitiveType)0);
				Collider component = val2.GetComponent<Collider>();
				if (Object.op_Implicit((Object)(object)component))
				{
					Object.Destroy((Object)(object)component);
				}
				val2.transform.SetParent(((Component)this).transform, false);
				float num = (float)i * 0.9f;
				val2.transform.localPosition = new Vector3(Mathf.Cos(num) * 0.55f, 0.35f + (float)(i % 6) * 0.08f, Mathf.Sin(num) * 0.55f);
				val2.transform.localScale = Vector3.one * 0.035f;
				MeshRenderer component2 = val2.GetComponent<MeshRenderer>();
				if ((Object)(object)mat != (Object)null)
				{
					((Renderer)component2).material = new Material(mat)
					{
						mainTexture = (Texture)(object)Texture2D.whiteTexture,
						color = ((i % 2 == 0) ? new Color(1f, 0.5f, 0.75f) : new Color(0.5f, 0.9f, 1f))
					};
				}
				sparks.Add(val2.transform);
			}
			float t = 0f;
			float dur = 2.4f;
			while (t < dur)
			{
				t += Time.deltaTime;
				float num2 = Mathf.Sin(Mathf.Clamp01(t / dur) * (float)Math.PI);
				if (Object.op_Implicit((Object)(object)light))
				{
					light.intensity = 0.6f + 1.8f * num2;
				}
				if (Object.op_Implicit((Object)(object)mat))
				{
					mat.color = Color.white * (0.85f + 0.6f * num2);
				}
				for (int j = 0; j < sparks.Count; j++)
				{
					Transform val3 = sparks[j];
					if (Object.op_Implicit((Object)(object)val3))
					{
						val3.localPosition += new Vector3(0f, Time.deltaTime * (0.6f + (float)(j % 5) * 0.12f), 0f);
						val3.localScale = Vector3.one * 0.035f * (1f - Mathf.Clamp01(t / dur));
					}
				}
				yield return null;
			}
			foreach (Transform item in sparks)
			{
				if (Object.op_Implicit((Object)(object)item))
				{
					Object.Destroy((Object)(object)((Component)item).gameObject);
				}
			}
			if (Object.op_Implicit((Object)(object)light))
			{
				light.intensity = 0.6f;
			}
			if (Object.op_Implicit((Object)(object)mat))
			{
				mat.color = Color.white * 0.85f;
			}
		}
	}
	internal static class Depositor
	{
		private static readonly HashSet<SkillType> ToolSkills = new HashSet<SkillType>
		{
			(SkillType)12,
			(SkillType)13,
			(SkillType)104
		};

		private static bool Keep(ItemData it)
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Invalid comparison between Unknown and I4
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Invalid comparison between Unknown and I4
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Invalid comparison between Unknown and I4
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			if (it == null || it.m_shared == null)
			{
				return true;
			}
			if (it.m_equipped)
			{
				return true;
			}
			if (it.m_gridPos.y == 0)
			{
				return true;
			}
			ItemType itemType = it.m_shared.m_itemType;
			if ((int)itemType == 19)
			{
				return true;
			}
			if ((int)itemType == 15)
			{
				return true;
			}
			if ((int)itemType == 2)
			{
				return true;
			}
			if (ToolSkills.Contains(it.m_shared.m_skillType))
			{
				return true;
			}
			return false;
		}

		internal static void Run(Player player, DepositRune rune)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			float value = Plugin.Radius.Value;
			Vector3 origin = ((Component)rune).transform.position;
			Inventory inventory = ((Humanoid)player).GetInventory();
			long playerID = player.GetPlayerID();
			List<Container> list = new List<Container>();
			int num = 0;
			Container[] array = Object.FindObjectsOfType<Container>();
			foreach (Container val in array)
			{
				if (!Object.op_Implicit((Object)(object)val) || Vector3.Distance(((Component)val).transform.position, origin) > value)
				{
					continue;
				}
				ZNetView component = ((Component)val).GetComponent<ZNetView>();
				if ((Object)(object)component == (Object)null || !component.IsValid() || (Object)(object)((Component)val).GetComponentInParent<Ship>() != (Object)null || (Object)(object)((Component)val).GetComponentInParent<Vagon>() != (Object)null)
				{
					continue;
				}
				object obj = Compat.Call(val, "CheckAccess", playerID);
				if ((!(obj is bool) || (bool)obj) && PrivateArea.CheckAccess(((Component)val).transform.position, 0f, false, false))
				{
					if (val.IsInUse() || SomeoneElseAt(((Component)val).transform.position, player))
					{
						num++;
					}
					else
					{
						list.Add(val);
					}
				}
			}
			list.Sort((Container a, Container b) => Vector3.Distance(((Component)a).transform.position, origin).CompareTo(Vector3.Distance(((Component)b).transform.position, origin)));
			int num2 = 0;
			Dictionary<Container, Dictionary<string, int>> dictionary = new Dictionary<Container, Dictionary<string, int>>();
			Dictionary<string, int> dictionary2 = new Dictionary<string, int>();
			foreach (ItemData item in inventory.GetAllItems().ToList())
			{
				if (Keep(item))
				{
					continue;
				}
				string name = item.m_shared.m_name;
				bool flag = false;
				foreach (Container item2 in list)
				{
					Inventory inventory2 = item2.GetInventory();
					if (inventory2 == null || !inventory2.GetAllItems().Any((ItemData x) => x != null && x.m_shared != null && x.m_shared.m_name == name))
					{
						continue;
					}
					flag = true;
					ZNetView component2 = ((Component)item2).GetComponent<ZNetView>();
					if (!component2.IsOwner())
					{
						component2.ClaimOwnership();
					}
					if (!inventory.ContainsItem(item))
					{
						break;
					}
					int num3 = Move(inventory, inventory2, item);
					int num4 = (inventory.ContainsItem(item) ? item.m_stack : 0);
					if (num3 > 0)
					{
						num2 += num3;
						if (!dictionary.TryGetValue(item2, out var value2))
						{
							value2 = (dictionary[item2] = new Dictionary<string, int>());
						}
						value2[name] = (value2.TryGetValue(name, out var value3) ? value3 : 0) + num3;
					}
					if (num4 == 0)
					{
						break;
					}
				}
				if (flag && inventory.ContainsItem(item))
				{
					dictionary2[name] = (dictionary2.TryGetValue(name, out var value4) ? value4 : 0) + item.m_stack;
				}
			}
			if (num2 > 0)
			{
				rune.Glow();
				string text = ((dictionary.Count == 1) ? "$ptd_deposit_done1" : "$ptd_deposit_done");
				Compat.Message(player, (MessageType)2, string.Format(Localization.instance.Localize(text), num2, dictionary.Count));
				rune.Beams(dictionary.ToList());
			}
			else
			{
				Compat.Message(player, (MessageType)2, Localization.instance.Localize("$ptd_deposit_none"));
			}
			if (num2 > 0 && dictionary2.Count > 0)
			{
				string text2 = string.Join(", ", from kv in dictionary2.Take(2)
					select Localization.instance.Localize(kv.Key) + " ×" + kv.Value);
				if (dictionary2.Count > 2)
				{
					text2 = text2 + " +" + (dictionary2.Count - 2);
				}
				Compat.Message(player, (MessageType)1, string.Format(Localization.instance.Localize("$ptd_deposit_left"), text2));
			}
			if (num > 0)
			{
				Compat.Message(player, (MessageType)1, string.Format(Localization.instance.Localize("$ptd_deposit_busy"), num));
			}
			Plugin.Log($"Effortless Storage: {num2} items into {dictionary.Count} chests, {dictionary2.Count} kinds left, {num} chests busy");
		}

		private static int Move(Inventory from, Inventory to, ItemData item)
		{
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: 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_015b: Unknown result type (might be due to invalid IL or missing references)
			int stack = item.m_stack;
			int num = Math.Max(1, item.m_shared.m_maxStackSize);
			if (num > 1)
			{
				foreach (ItemData allItem in to.GetAllItems())
				{
					if (item.m_stack <= 0)
					{
						break;
					}
					if (allItem != null && allItem.m_shared != null && !(allItem.m_shared.m_name != item.m_shared.m_name) && allItem.m_quality == item.m_quality && allItem.m_variant == item.m_variant)
					{
						int num2 = num - allItem.m_stack;
						if (num2 > 0)
						{
							int num3 = Math.Min(num2, item.m_stack);
							allItem.m_stack += num3;
							item.m_stack -= num3;
						}
					}
				}
			}
			while (item.m_stack > 0 && Compat.Call(to, "FindEmptySlot", false) is Vector2i val && val.x >= 0 && val.y >= 0)
			{
				int num4 = Math.Min(num, item.m_stack);
				ItemData val2 = item.Clone();
				val2.m_stack = num4;
				val2.m_equipped = false;
				if (!Compat.AddItemAt(to, val2, num4, val.x, val.y))
				{
					break;
				}
				item.m_stack -= num4;
			}
			int num5 = stack - item.m_stack;
			if (num5 > 0)
			{
				if (item.m_stack <= 0)
				{
					from.RemoveItem(item);
				}
				else
				{
					Compat.Changed(from);
				}
				Compat.Changed(to);
			}
			return num5;
		}

		private static bool SomeoneElseAt(Vector3 pos, Player me)
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			foreach (Player allPlayer in Player.GetAllPlayers())
			{
				if (Object.op_Implicit((Object)(object)allPlayer) && (Object)(object)allPlayer != (Object)(object)me && Vector3.Distance(((Component)allPlayer).transform.position, pos) < 4f)
				{
					return true;
				}
			}
			return false;
		}

		internal static void Label(Container c, Dictionary<string, int> got)
		{
			//IL_005c: 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)
			try
			{
				string text = string.Join(" · ", from kv in got.Take(3)
					select Localization.instance.Localize(kv.Key) + " ×" + kv.Value);
				if (got.Count > 3)
				{
					text += " …";
				}
				Chat instance = Chat.instance;
				if (instance != null)
				{
					instance.SetNpcText(((Component)c).gameObject, Vector3.up * 1.4f, 30f, 5f, "", text, false);
				}
			}
			catch (Exception ex)
			{
				Plugin.Warn("Effortless Storage: label failed (" + ex.Message + ")");
			}
		}

		internal static void Highlight(Container c)
		{
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				WearNTear component = ((Component)c).GetComponent<WearNTear>();
				if ((Object)(object)component == (Object)null)
				{
					return;
				}
				MethodInfo[] methods = typeof(WearNTear).GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				foreach (MethodInfo methodInfo in methods)
				{
					if (methodInfo.Name != "Highlight")
					{
						continue;
					}
					ParameterInfo[] parameters = methodInfo.GetParameters();
					object[] array = new object[parameters.Length];
					for (int j = 0; j < parameters.Length; j++)
					{
						if (parameters[j].ParameterType == typeof(Color))
						{
							array[j] = (object)new Color(0.9f, 0.77f, 0.45f);
						}
						else if (parameters[j].ParameterType == typeof(float))
						{
							array[j] = 2.5f;
						}
						else
						{
							array[j] = (parameters[j].HasDefaultValue ? parameters[j].DefaultValue : (parameters[j].ParameterType.IsValueType ? Activator.CreateInstance(parameters[j].ParameterType) : null));
						}
					}
					methodInfo.Invoke(component, array);
					break;
				}
			}
			catch
			{
			}
		}
	}
	internal static class RuneBuilder
	{
		private static Texture2D _runeTex;

		private static Sprite _icon;

		internal static GameObject Build(string name)
		{
			//IL_0096: 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_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: 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_0203: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: Unknown result type (might be due to invalid IL or missing references)
			//IL_022f: 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_0291: Unknown result type (might be due to invalid IL or missing references)
			//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0319: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = PrefabManager.Instance.CreateEmptyPrefab(name, false);
			MeshRenderer component = val.GetComponent<MeshRenderer>();
			if (Object.op_Implicit((Object)(object)component))
			{
				Object.DestroyImmediate((Object)(object)component);
			}
			MeshFilter component2 = val.GetComponent<MeshFilter>();
			if (Object.op_Implicit((Object)(object)component2))
			{
				Object.DestroyImmediate((Object)(object)component2);
			}
			Collider[] components = val.GetComponents<Collider>();
			for (int i = 0; i < components.Length; i++)
			{
				Object.DestroyImmediate((Object)(object)components[i]);
			}
			int num = LayerMask.NameToLayer("piece");
			if (num >= 0)
			{
				val.layer = num;
			}
			Material mat = StoneMaterial();
			AddMesh(val, "Base", Prism(7, 0.72f, 0.62f, 0.24f), mat, Vector3.zero);
			AddMesh(val, "Stele", Stele(0.9f, 1.75f, 0.32f), mat, new Vector3(0f, 0.2f, 0f));
			MeshRenderer[] componentsInChildren = val.GetComponentsInChildren<MeshRenderer>(true);
			foreach (MeshRenderer val2 in componentsInChildren)
			{
				object[] obj = new object[4]
				{
					((Object)val2).name,
					null,
					null,
					null
				};
				Material sharedMaterial = ((Renderer)val2).sharedMaterial;
				obj[1] = ((sharedMaterial != null) ? ((Object)sharedMaterial).name : null);
				Material sharedMaterial2 = ((Renderer)val2).sharedMaterial;
				object obj2;
				if (sharedMaterial2 == null)
				{
					obj2 = null;
				}
				else
				{
					Shader shader = sharedMaterial2.shader;
					obj2 = ((shader != null) ? ((Object)shader).name : null);
				}
				obj[2] = obj2;
				Material sharedMaterial3 = ((Renderer)val2).sharedMaterial;
				bool? obj3;
				if (sharedMaterial3 == null)
				{
					obj3 = null;
				}
				else
				{
					Shader shader2 = sharedMaterial3.shader;
					obj3 = ((shader2 != null) ? new bool?(shader2.isSupported) : ((bool?)null));
				}
				obj[3] = obj3;
				Plugin.Log(string.Format("Effortless Storage: {0} uses {1} ({2}, supported {3})", obj));
			}
			GameObject val3 = new GameObject("Rune");
			val3.transform.SetParent(val.transform, false);
			val3.transform.localPosition = new Vector3(0f, 1.12f, 0.19f);
			val3.AddComponent<MeshFilter>().sharedMesh = Quad(0.34f, 0.68f);
			MeshRenderer obj4 = val3.AddComponent<MeshRenderer>();
			((Renderer)obj4).sharedMaterial = RuneMaterial();
			((Renderer)obj4).shadowCastingMode = (ShadowCastingMode)0;
			GameObject val4 = new GameObject("Light");
			val4.transform.SetParent(val.transform, false);
			val4.transform.localPosition = new Vector3(0f, 1.15f, 0.7f);
			Light obj5 = val4.AddComponent<Light>();
			obj5.type = (LightType)2;
			obj5.color = new Color(0.5f, 0.72f, 1f);
			obj5.range = 3f;
			obj5.intensity = 0.6f;
			obj5.shadows = (LightShadows)0;
			BoxCollider obj6 = val.AddComponent<BoxCollider>();
			obj6.center = new Vector3(0f, 1f, 0f);
			obj6.size = new Vector3(0.95f, 2f, 0.4f);
			(val.GetComponent<ZNetView>() ?? val.AddComponent<ZNetView>()).m_persistent = true;
			Piece obj7 = val.GetComponent<Piece>() ?? val.AddComponent<Piece>();
			obj7.m_name = "$ptd_depositrune";
			obj7.m_description = "$ptd_depositrune_desc";
			obj7.m_icon = Icon();
			obj7.m_groundPiece = false;
			WearNTear val5 = val.AddComponent<WearNTear>();
			val5.m_health = 600f;
			val5.m_materialType = (MaterialType)1;
			val5.m_noRoofWear = false;
			val5.m_noSupportWear = false;
			val5.m_new = null;
			val5.m_worn = null;
			val5.m_broken = null;
			CopyStoneEffects(obj7, val5);
			val.AddComponent<DepositRune>();
			SetLayer(val, num);
			return val;
		}

		private static void CopyStoneEffects(Piece piece, WearNTear wnt)
		{
			string[] array = new string[4] { "stone_wall_1x1", "stone_wall_2x1", "stone_pillar", "stone_floor_2x2" };
			foreach (string text in array)
			{
				GameObject prefab = Cache.GetPrefab<GameObject>(text);
				if (!((Object)(object)prefab == (Object)null))
				{
					Piece component = prefab.GetComponent<Piece>();
					WearNTear component2 = prefab.GetComponent<WearNTear>();
					if (!((Object)(object)component == (Object)null) && !((Object)(object)component2 == (Object)null))
					{
						piece.m_placeEffect = component.m_placeEffect;
						wnt.m_hitEffect = component2.m_hitEffect;
						wnt.m_destroyedEffect = component2.m_destroyedEffect;
						wnt.m_switchEffect = component2.m_switchEffect;
						Plugin.Log("Effortless Storage: build/hit/destroy sounds from " + text);
						return;
					}
				}
			}
			Plugin.Warn("Effortless Storage: no stone piece found for sounds");
		}

		private static void SetLayer(GameObject go, int layer)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			if (layer < 0)
			{
				return;
			}
			go.layer = layer;
			foreach (Transform item in go.transform)
			{
				SetLayer(((Component)item).gameObject, layer);
			}
		}

		private static void AddMesh(GameObject parent, string name, Mesh mesh, Material mat, Vector3 pos)
		{
			//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_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name);
			val.transform.SetParent(parent.transform, false);
			val.transform.localPosition = pos;
			val.AddComponent<MeshFilter>().sharedMesh = mesh;
			((Renderer)val.AddComponent<MeshRenderer>()).sharedMaterial = mat;
		}

		private static Material StoneMaterial()
		{
			//IL_01bd: 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_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Expected O, but got Unknown
			string[] array = new string[12]
			{
				"Rock_3", "Rock_4", "Rock_7", "rock4_forest", "rock4_coast", "rock2_heath", "rock3_mountain", "rock1_mountain", "stone_wall_1x1", "stone_wall_2x1",
				"stone_pillar", "stone_floor_2x2"
			};
			foreach (string text in array)
			{
				GameObject prefab = Cache.GetPrefab<GameObject>(text);
				if ((Object)(object)prefab == (Object)null)
				{
					Plugin.Log("Effortless Storage: no prefab " + text);
					continue;
				}
				MeshRenderer[] componentsInChildren = prefab.GetComponentsInChildren<MeshRenderer>(true);
				foreach (MeshRenderer val in componentsInChildren)
				{
					Material sharedMaterial = ((Renderer)val).sharedMaterial;
					if (!((Object)(object)sharedMaterial == (Object)null) && !((Object)(object)sharedMaterial.shader == (Object)null) && sharedMaterial.shader.isSupported && ((Object)sharedMaterial).name.IndexOf("shadow", StringComparison.OrdinalIgnoreCase) < 0)
					{
						Plugin.Log("Effortless Storage: stone material " + ((Object)sharedMaterial).name + " (" + ((Object)sharedMaterial.shader).name + ") from " + text + "/" + ((Object)val).name);
						return sharedMaterial;
					}
				}
				Plugin.Log("Effortless Storage: " + text + " has no usable material");
			}
			Plugin.Warn("Effortless Storage: stone material not found, using a plain one");
			Shader val2 = Shader.Find("Custom/Piece");
			if ((Object)(object)val2 == (Object)null || !val2.isSupported)
			{
				val2 = Shader.Find("Standard");
			}
			return new Material(val2)
			{
				color = new Color(0.55f, 0.53f, 0.5f)
			};
		}

		internal static Shader FxShader()
		{
			return FindShader();
		}

		private static Shader FindShader()
		{
			string[] array = new string[5] { "Sprites/Default", "Unlit/Transparent", "Legacy Shaders/Particles/Alpha Blended", "Particles/Standard Unlit", "Standard" };
			for (int i = 0; i < array.Length; i++)
			{
				Shader val = Shader.Find(array[i]);
				if ((Object)(object)val != (Object)null)
				{
					return val;
				}
			}
			return Shader.Find("Standard");
		}

		private static Material RuneMaterial()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			return new Material(FindShader())
			{
				mainTexture = (Texture)(object)RuneTexture(),
				color = Color.white * 0.85f,
				renderQueue = 3000
			};
		}

		internal static Texture2D RuneTexture()
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Expected O, but got Unknown
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_022d: Unknown result type (might be due to invalid IL or missing references)
			//IL_022e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: 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_0242: Unknown result type (might be due to invalid IL or missing references)
			//IL_021d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0276: 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_025c: 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_026f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0278: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_runeTex != (Object)null)
			{
				return _runeTex;
			}
			Vector2[] poly = (Vector2[])(object)new Vector2[8]
			{
				V(64f, 10f),
				V(118f, 80f),
				V(74f, 128f),
				V(118f, 176f),
				V(64f, 246f),
				V(10f, 176f),
				V(54f, 128f),
				V(10f, 80f)
			};
			Vector2[] poly2 = (Vector2[])(object)new Vector2[4]
			{
				V(64f, 44f),
				V(96f, 84f),
				V(64f, 118f),
				V(32f, 84f)
			};
			Vector2[] poly3 = (Vector2[])(object)new Vector2[4]
			{
				V(64f, 138f),
				V(96f, 172f),
				V(64f, 212f),
				V(32f, 172f)
			};
			Color val = default(Color);
			((Color)(ref val))..ctor(1f, 0.37f, 0.64f);
			Color val2 = default(Color);
			((Color)(ref val2))..ctor(0.3f, 0.85f, 1f);
			Texture2D val3 = new Texture2D(128, 256, (TextureFormat)4, false)
			{
				wrapMode = (TextureWrapMode)1
			};
			Color[] array = (Color[])(object)new Color[32768];
			Vector2 val4 = default(Vector2);
			for (int i = 0; i < 256; i++)
			{
				for (int j = 0; j < 128; j++)
				{
					((Vector2)(ref val4))..ctor((float)j + 0.5f, (float)(256 - i) - 0.5f);
					bool flag = Inside(val4, poly) && !Inside(val4, poly2) && !Inside(val4, poly3);
					Color val5 = Color.Lerp(val, val2, val4.y / 256f);
					array[i * 128 + j] = (Color)(flag ? val5 : new Color(val5.r, val5.g, val5.b, 0f));
				}
			}
			val3.SetPixels(array);
			val3.Apply();
			return _runeTex = val3;
		}

		internal static Sprite Icon()
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Expected O, but got Unknown
			//IL_02e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: 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_01cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_026c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0298: Unknown result type (might be due to invalid IL or missing references)
			//IL_029a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0251: Unknown result type (might be due to invalid IL or missing references)
			//IL_0256: Unknown result type (might be due to invalid IL or missing references)
			//IL_0258: Unknown result type (might be due to invalid IL or missing references)
			//IL_0266: Unknown result type (might be due to invalid IL or missing references)
			//IL_0268: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_icon != (Object)null)
			{
				return _icon;
			}
			Vector2[] poly = (Vector2[])(object)new Vector2[8]
			{
				V(24f, 110f),
				V(24f, 38f),
				V(30f, 24f),
				V(40f, 14f),
				V(88f, 14f),
				V(98f, 24f),
				V(104f, 38f),
				V(104f, 110f)
			};
			Vector2[] poly2 = (Vector2[])(object)new Vector2[4]
			{
				V(14f, 110f),
				V(114f, 110f),
				V(108f, 124f),
				V(20f, 124f)
			};
			Texture2D val = RuneTexture();
			Texture2D val2 = new Texture2D(128, 128, (TextureFormat)4, false);
			Color[] array = (Color[])(object)new Color[16384];
			Color val4 = default(Color);
			for (int i = 0; i < 128; i++)
			{
				for (int j = 0; j < 128; j++)
				{
					Vector2 val3 = new Vector2((float)j + 0.5f, (float)(128 - i) - 0.5f);
					((Color)(ref val4))..ctor(0f, 0f, 0f, 0f);
					if (Inside(val3, poly2))
					{
						((Color)(ref val4))..ctor(0.42f, 0.4f, 0.37f);
					}
					if (Inside(val3, poly))
					{
						val4 = new Color(0.58f, 0.56f, 0.52f) * (0.9f + 0.1f * Mathf.PerlinNoise((float)j * 0.15f, (float)i * 0.15f));
					}
					float num = (val3.x - 42f) / 44f;
					float num2 = (val3.y - 20f) / 88f;
					if (num >= 0f && num < 1f && num2 >= 0f && num2 < 1f)
					{
						Color pixelBilinear = val.GetPixelBilinear(num, 1f - num2);
						if (pixelBilinear.a > 0.5f)
						{
							val4 = pixelBilinear;
						}
					}
					val4.a = ((val4.a > 0f) ? 1f : 0f);
					array[i * 128 + j] = val4;
				}
			}
			val2.SetPixels(array);
			val2.Apply();
			return _icon = Sprite.Create(val2, new Rect(0f, 0f, 128f, 128f), new Vector2(0.5f, 0.5f));
		}

		private static Vector2 V(float x, float y)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			return new Vector2(x, y);
		}

		private static bool Inside(Vector2 p, Vector2[] poly)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: 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)
			bool flag = false;
			int num = 0;
			int num2 = poly.Length - 1;
			while (num < poly.Length)
			{
				if (poly[num].y > p.y != poly[num2].y > p.y && p.x < (poly[num2].x - poly[num].x) * (p.y - poly[num].y) / (poly[num2].y - poly[num].y) + poly[num].x)
				{
					flag = !flag;
				}
				num2 = num++;
			}
			return flag;
		}

		private static Mesh Quad(float w, float h)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			Mesh val = new Mesh();
			val.vertices = (Vector3[])(object)new Vector3[4]
			{
				new Vector3((0f - w) / 2f, (0f - h) / 2f, 0f),
				new Vector3(w / 2f, (0f - h) / 2f, 0f),
				new Vector3(w / 2f, h / 2f, 0f),
				new Vector3((0f - w) / 2f, h / 2f, 0f)
			};
			val.uv = (Vector2[])(object)new Vector2[4]
			{
				new Vector2(0f, 0f),
				new Vector2(1f, 0f),
				new Vector2(1f, 1f),
				new Vector2(0f, 1f)
			};
			val.triangles = new int[6] { 0, 1, 2, 0, 2, 3 };
			val.RecalculateNormals();
			val.RecalculateBounds();
			return val;
		}

		private static Mesh Prism(int n, float rb, float rt, float h)
		{
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: 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_00d7: 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_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: Unknown result type (might be due to invalid IL or missing references)
			List<Vector3> list = new List<Vector3>();
			List<Vector2> list2 = new List<Vector2>();
			List<int> list3 = new List<int>();
			Vector3 val = default(Vector3);
			Vector3 val2 = default(Vector3);
			Vector3 val3 = default(Vector3);
			Vector3 val4 = default(Vector3);
			for (int i = 0; i < n; i++)
			{
				float num = (float)i * (float)Math.PI * 2f / (float)n;
				float num2 = (float)(i + 1) * (float)Math.PI * 2f / (float)n;
				((Vector3)(ref val))..ctor(Mathf.Cos(num) * rb, 0f, Mathf.Sin(num) * rb);
				((Vector3)(ref val2))..ctor(Mathf.Cos(num2) * rb, 0f, Mathf.Sin(num2) * rb);
				((Vector3)(ref val3))..ctor(Mathf.Cos(num) * rt, h, Mathf.Sin(num) * rt);
				((Vector3)(ref val4))..ctor(Mathf.Cos(num2) * rt, h, Mathf.Sin(num2) * rt);
				int count = list.Count;
				list.AddRange((IEnumerable<Vector3>)(object)new Vector3[4] { val, val2, val4, val3 });
				float num3 = Vector3.Distance(val, val2);
				list2.AddRange((IEnumerable<Vector2>)(object)new Vector2[4]
				{
					new Vector2((float)i * num3, 0f),
					new Vector2((float)(i + 1) * num3, 0f),
					new Vector2((float)(i + 1) * num3, h),
					new Vector2((float)i * num3, h)
				});
				list3.AddRange(new int[6]
				{
					count,
					count + 2,
					count + 1,
					count,
					count + 3,
					count + 2
				});
			}
			int count2 = list.Count;
			list.Add(new Vector3(0f, h, 0f));
			list2.Add(new Vector2(0.5f, 0.5f));
			for (int j = 0; j < n; j++)
			{
				float num4 = (float)j * (float)Math.PI * 2f / (float)n;
				list.Add(new Vector3(Mathf.Cos(num4) * rt, h, Mathf.Sin(num4) * rt));
				list2.Add(new Vector2(0.5f + Mathf.Cos(num4) * 0.5f, 0.5f + Mathf.Sin(num4) * 0.5f));
			}
			for (int k = 0; k < n; k++)
			{
				list3.AddRange(new int[3]
				{
					count2,
					count2 + 1 + (k + 1) % n,
					count2 + 1 + k
				});
			}
			return Finish(list, list2, list3);
		}

		private static Mesh Stele(float w, float h, float d)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: 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_014d: 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_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: 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_0252: Unknown result type (might be due to invalid IL or missing references)
			//IL_0259: Unknown result type (might be due to invalid IL or missing references)
			//IL_0261: Unknown result type (might be due to invalid IL or missing references)
			//IL_0266: Unknown result type (might be due to invalid IL or missing references)
			//IL_026d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0274: Unknown result type (might be due to invalid IL or missing references)
			//IL_027c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0281: Unknown result type (might be due to invalid IL or missing references)
			//IL_0288: Unknown result type (might be due to invalid IL or missing references)
			//IL_028f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0298: Unknown result type (might be due to invalid IL or missing references)
			//IL_029d: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02df: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0307: Unknown result type (might be due to invalid IL or missing references)
			//IL_030c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0316: Unknown result type (might be due to invalid IL or missing references)
			//IL_031b: Unknown result type (might be due to invalid IL or missing references)
			float num = w / 2f;
			float num2 = d / 2f;
			List<Vector2> list = new List<Vector2>
			{
				new Vector2(num, 0f)
			};
			for (int i = 0; i <= 8; i++)
			{
				float num3 = (float)i / 8f;
				list.Add(new Vector2(num * (1f - 0.38f * num3 * num3), h * (0.73f + 0.27f * num3)));
			}
			List<Vector2> list2 = new List<Vector2>(list);
			for (int num4 = list.Count - 1; num4 >= 0; num4--)
			{
				list2.Add(new Vector2(0f - list[num4].x, list[num4].y));
			}
			Vector2[] array = list2.ToArray();
			List<Vector3> list3 = new List<Vector3>();
			List<Vector2> list4 = new List<Vector2>();
			List<int> list5 = new List<int>();
			float[] array2 = new float[2] { 1f, -1f };
			foreach (float num5 in array2)
			{
				int count = list3.Count;
				list3.Add(new Vector3(0f, h * 0.5f, num5 * num2));
				list4.Add(new Vector2(0.5f * w, 0.5f * h));
				Vector2[] array3 = array;
				foreach (Vector2 val in array3)
				{
					list3.Add(new Vector3(val.x, val.y, num5 * num2));
					list4.Add(new Vector2(val.x + num, val.y));
				}
				for (int l = 0; l < array.Length; l++)
				{
					int num6 = count + 1 + l;
					int num7 = count + 1 + (l + 1) % array.Length;
					if (num5 > 0f)
					{
						list5.AddRange(new int[3] { count, num6, num7 });
					}
					else
					{
						list5.AddRange(new int[3] { count, num7, num6 });
					}
				}
			}
			float num8 = 0f;
			for (int m = 0; m < array.Length; m++)
			{
				Vector2 val2 = array[m];
				Vector2 val3 = array[(m + 1) % array.Length];
				int count2 = list3.Count;
				list3.AddRange((IEnumerable<Vector3>)(object)new Vector3[4]
				{
					new Vector3(val2.x, val2.y, num2),
					new Vector3(val3.x, val3.y, num2),
					new Vector3(val3.x, val3.y, 0f - num2),
					new Vector3(val2.x, val2.y, 0f - num2)
				});
				float num9 = Vector2.Distance(val2, val3);
				list4.AddRange((IEnumerable<Vector2>)(object)new Vector2[4]
				{
					new Vector2(num8, 0f),
					new Vector2(num8 + num9, 0f),
					new Vector2(num8 + num9, d),
					new Vector2(num8, d)
				});
				num8 += num9;
				list5.AddRange(new int[6]
				{
					count2,
					count2 + 2,
					count2 + 1,
					count2,
					count2 + 3,
					count2 + 2
				});
			}
			return Finish(list3, list4, list5);
		}

		private static Mesh Finish(List<Vector3> v, List<Vector2> uv, List<int> t)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			Mesh val = new Mesh();
			val.SetVertices(v);
			val.SetUVs(0, uv);
			val.SetTriangles(t, 0);
			Color[] array = (Color[])(object)new Color[v.Count];
			for (int i = 0; i < array.Length; i++)
			{
				array[i] = Color.white;
			}
			val.colors = array;
			val.RecalculateNormals();
			val.RecalculateTangents();
			val.RecalculateBounds();
			return val;
		}
	}
}