Decompiled source of CofreFijo v1.1.3

BepInEx/plugins/CofreFijo/CofreFijo.dll

Decompiled 8 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("CofreFijo")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.1.3.0")]
[assembly: AssemblyInformationalVersion("1.1.3")]
[assembly: AssemblyProduct("CofreFijo")]
[assembly: AssemblyTitle("CofreFijo")]
[assembly: AssemblyVersion("1.1.3.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 CofreFijo
{
	internal struct Categoria : IEquatable<Categoria>
	{
		private readonly string _clave;

		internal static readonly Categoria Ninguna = new Categoria(null);

		internal static readonly Categoria Comida = new Categoria("Comida");

		internal static readonly Categoria Municion = new Categoria("Municion");

		internal static readonly Categoria Armas = new Categoria("Armas");

		internal static readonly Categoria Armaduras = new Categoria("Armaduras");

		internal static readonly Categoria Herramientas = new Categoria("Herramientas");

		internal static readonly Categoria Trofeos = new Categoria("Trofeos");

		internal static readonly Categoria Pieles = new Categoria("Pieles");

		internal static readonly Categoria Minerales = new Categoria("Minerales");

		internal static readonly Categoria Madera = new Categoria("Madera");

		internal static readonly Categoria Semillas = new Categoria("Semillas");

		internal static readonly Categoria Monstruos = new Categoria("Monstruos");

		internal static readonly Categoria Materiales = new Categoria("Materiales");

		internal static readonly Categoria Varios = new Categoria("Varios");

		internal bool EsNinguna => string.IsNullOrEmpty(_clave);

		internal string Clave => _clave ?? string.Empty;

		internal string Nombre
		{
			get
			{
				if (EsNinguna)
				{
					return "Sin clasificar";
				}
				if (!(_clave == "Municion"))
				{
					return _clave;
				}
				return "Munición";
			}
		}

		private Categoria(string clave)
		{
			_clave = clave;
		}

		internal static Categoria Desde(string nombre)
		{
			if (string.IsNullOrEmpty(nombre))
			{
				return Ninguna;
			}
			string text = nombre.Trim();
			if (text.Length != 0)
			{
				return new Categoria(text);
			}
			return Ninguna;
		}

		public bool Equals(Categoria otra)
		{
			return string.Equals(Clave, otra.Clave, StringComparison.OrdinalIgnoreCase);
		}

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

		public override int GetHashCode()
		{
			return Clave.ToLowerInvariant().GetHashCode();
		}

		public override string ToString()
		{
			return Clave;
		}

		public static bool operator ==(Categoria a, Categoria b)
		{
			return a.Equals(b);
		}

		public static bool operator !=(Categoria a, Categoria b)
		{
			return !a.Equals(b);
		}
	}
	internal static class Categorias
	{
		internal sealed class Propia
		{
			internal Categoria Categoria;

			internal string[] Palabras = new string[0];
		}

		internal static readonly Categoria[] Integradas = new Categoria[13]
		{
			Categoria.Comida,
			Categoria.Municion,
			Categoria.Armas,
			Categoria.Armaduras,
			Categoria.Herramientas,
			Categoria.Trofeos,
			Categoria.Pieles,
			Categoria.Minerales,
			Categoria.Madera,
			Categoria.Semillas,
			Categoria.Monstruos,
			Categoria.Materiales,
			Categoria.Varios
		};

		internal static string[] Pieles = new string[0];

		internal static string[] Minerales = new string[0];

		internal static string[] Madera = new string[0];

		internal static string[] Semillas = new string[0];

		internal static string[] Monstruos = new string[0];

		internal static Propia[] Propias = new Propia[0];

		internal static Categoria[] Todas
		{
			get
			{
				List<Categoria> list = new List<Categoria>(Integradas);
				Propia[] propias = Propias;
				foreach (Propia propia in propias)
				{
					if (!list.Contains(propia.Categoria))
					{
						list.Add(propia.Categoria);
					}
				}
				return list.ToArray();
			}
		}

		internal static string Nombre(Categoria categoria)
		{
			return categoria.Nombre;
		}

		internal static void CargarPropias(string valor)
		{
			List<Propia> list = new List<Propia>();
			if (!string.IsNullOrEmpty(valor))
			{
				string[] array = valor.Split(new char[1] { ';' }, StringSplitOptions.RemoveEmptyEntries);
				for (int i = 0; i < array.Length; i++)
				{
					string[] array2 = array[i].Split(new char[1] { '=' }, 2);
					Categoria categoria = Categoria.Desde(array2[0]);
					if (!categoria.EsNinguna && !YaEsta(list, categoria))
					{
						list.Add(new Propia
						{
							Categoria = categoria,
							Palabras = ((array2.Length > 1) ? ParseLista(array2[1]) : new string[0])
						});
					}
				}
			}
			Propias = list.ToArray();
		}

		private static bool YaEsta(List<Propia> lista, Categoria categoria)
		{
			foreach (Propia listum in lista)
			{
				if (listum.Categoria == categoria)
				{
					return true;
				}
			}
			return false;
		}

		internal static string[] ParseLista(string valor)
		{
			if (string.IsNullOrEmpty(valor))
			{
				return new string[0];
			}
			string[] array = valor.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries);
			List<string> list = new List<string>(array.Length);
			string[] array2 = array;
			for (int i = 0; i < array2.Length; i++)
			{
				string text = array2[i].Trim();
				if (text.Length > 0)
				{
					list.Add(text.ToLowerInvariant());
				}
			}
			return list.ToArray();
		}

		internal static Categoria DeItem(ItemData item)
		{
			return DeItem(item, NombreInterno(item));
		}

		internal static Categoria DeItem(ItemData item, string nombreInterno)
		{
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Expected I4, but got Unknown
			SharedData val = item?.m_shared;
			if (val == null)
			{
				return Categoria.Ninguna;
			}
			if (ReglasItems.TryObtener(nombreInterno, out var categoria))
			{
				return categoria;
			}
			Propia[] propias = Propias;
			foreach (Propia propia in propias)
			{
				if (Coincide(nombreInterno, propia.Palabras))
				{
					return propia.Categoria;
				}
			}
			ItemType itemType = val.m_itemType;
			switch (itemType - 1)
			{
			case 8:
			case 22:
				return Categoria.Municion;
			case 1:
			case 20:
				return Categoria.Comida;
			case 2:
			case 3:
			case 4:
			case 13:
			case 14:
			case 19:
			case 21:
				return Categoria.Armas;
			case 5:
			case 6:
			case 9:
			case 10:
			case 11:
			case 16:
			case 17:
			case 23:
				return Categoria.Armaduras;
			case 18:
				return Categoria.Herramientas;
			case 12:
				return Categoria.Trofeos;
			case 0:
				return DeMaterial(nombreInterno);
			default:
				if (string.IsNullOrEmpty(val.m_ammoType))
				{
					return Categoria.Varios;
				}
				return Categoria.Municion;
			}
		}

		private static Categoria DeMaterial(string nombre)
		{
			if (Coincide(nombre, Monstruos))
			{
				return Categoria.Monstruos;
			}
			if (Coincide(nombre, Pieles))
			{
				return Categoria.Pieles;
			}
			if (Coincide(nombre, Minerales))
			{
				return Categoria.Minerales;
			}
			if (Coincide(nombre, Madera))
			{
				return Categoria.Madera;
			}
			if (Coincide(nombre, Semillas))
			{
				return Categoria.Semillas;
			}
			return Categoria.Materiales;
		}

		internal static string NombreInterno(ItemData item)
		{
			if ((Object)(object)item.m_dropPrefab != (Object)null && !string.IsNullOrEmpty(((Object)item.m_dropPrefab).name))
			{
				return ((Object)item.m_dropPrefab).name.ToLowerInvariant();
			}
			if (item.m_shared == null || item.m_shared.m_name == null)
			{
				return string.Empty;
			}
			return item.m_shared.m_name.ToLowerInvariant();
		}

		private static bool Coincide(string nombre, string[] lista)
		{
			if (string.IsNullOrEmpty(nombre))
			{
				return false;
			}
			foreach (string value in lista)
			{
				if (nombre.IndexOf(value, StringComparison.Ordinal) >= 0)
				{
					return true;
				}
			}
			return false;
		}

		internal static Categoria DeCofre(Inventory inventario)
		{
			if (inventario == null)
			{
				return Categoria.Ninguna;
			}
			Dictionary<Categoria, int> dictionary = new Dictionary<Categoria, int>();
			foreach (ItemData allItem in inventario.GetAllItems())
			{
				Categoria categoria = DeItem(allItem);
				if (!(categoria == Categoria.Ninguna))
				{
					dictionary[categoria] = ((!dictionary.TryGetValue(categoria, out var value)) ? 1 : (value + 1));
				}
			}
			Categoria result = Categoria.Ninguna;
			int num = 0;
			foreach (KeyValuePair<Categoria, int> item in dictionary)
			{
				if (item.Value > num)
				{
					num = item.Value;
					result = item.Key;
				}
			}
			return result;
		}
	}
	[HarmonyPatch(typeof(Piece), "SetCreator")]
	internal static class ParcheAutoVincular
	{
		private static void Postfix(Piece __instance)
		{
			try
			{
				CofreFijoPlugin instancia = CofreFijoPlugin.Instancia;
				if (!((Object)(object)instancia == (Object)null) && instancia.AutoVincularNuevos && !((Object)(object)__instance == (Object)null))
				{
					Container component = ((Component)__instance).GetComponent<Container>();
					if (!((Object)(object)component == (Object)null))
					{
						Vinculo.Marcar(component, vinculado: true);
					}
				}
			}
			catch
			{
			}
		}
	}
	[HarmonyPatch(typeof(Player), "TakeInput")]
	internal static class ParcheBloquearInput
	{
		private static bool Prefix(ref bool __result)
		{
			if (!VentanaCategorias.Abierta)
			{
				return true;
			}
			__result = false;
			return false;
		}
	}
	[HarmonyPatch(typeof(GameCamera), "UpdateMouseCapture")]
	internal static class ParcheCursor
	{
		private static bool Prefix()
		{
			if (!VentanaCategorias.Abierta)
			{
				return true;
			}
			Cursor.lockState = (CursorLockMode)0;
			Cursor.visible = true;
			return false;
		}
	}
	[HarmonyPatch(typeof(Container), "GetHoverText")]
	internal static class ParcheTextoCofre
	{
		private class Entrada
		{
			internal float Momento;

			internal Categoria Categoria;
		}

		private const float DuracionCache = 1f;

		private const int MaximoEnCache = 64;

		private static readonly Dictionary<Container, Entrada> Cache = new Dictionary<Container, Entrada>();

		private static void Postfix(Container __instance, ref string __result)
		{
			try
			{
				if (!((Object)(object)__instance == (Object)null) && !string.IsNullOrEmpty(__result) && Vinculo.EstaVinculado(__instance))
				{
					Categoria categoria = CategoriaCacheada(__instance);
					string text = ((categoria == Categoria.Ninguna) ? "vinculado - libre" : ("vinculado - " + Categorias.Nombre(categoria)));
					__result = __result + "\n<color=#D6A24A>[CofreFijo] " + text + "</color>";
				}
			}
			catch
			{
			}
		}

		private static Categoria CategoriaCacheada(Container cofre)
		{
			float time = Time.time;
			if (Cache.TryGetValue(cofre, out var value) && time - value.Momento < 1f)
			{
				return value.Categoria;
			}
			if (Cache.Count > 64)
			{
				Cache.Clear();
			}
			Categoria categoria = Categorias.DeCofre(cofre.GetInventory());
			Cache[cofre] = new Entrada
			{
				Momento = time,
				Categoria = categoria
			};
			return categoria;
		}
	}
	[BepInPlugin("altairfernando.cofrefijo", "CofreFijo", "1.1.3")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class CofreFijoPlugin : BaseUnityPlugin
	{
		private class Destino
		{
			internal Container Cofre;

			internal Inventory Inventario;

			internal Categoria Categoria;

			internal float Distancia;
		}

		private class GrupoItems
		{
			internal string Clave;

			internal readonly List<ItemData> Items = new List<ItemData>();
		}

		private class Faltante
		{
			internal string Nombre;

			internal int Calidad;

			internal int Falta;
		}

		public const string PluginGuid = "altairfernando.cofrefijo";

		public const string PluginName = "CofreFijo";

		public const string PluginVersion = "1.1.3";

		private static readonly MethodInfo MetodoGuardarCofre = AccessTools.Method(typeof(Container), "Save", (Type[])null, (Type[])null);

		internal static CofreFijoPlugin Instancia;

		private ConfigEntry<KeyboardShortcut> _teclaVincular;

		private ConfigEntry<KeyboardShortcut> _teclaEnviar;

		private ConfigEntry<KeyboardShortcut> _teclaRellenar;

		private ConfigEntry<float> _rango;

		private ConfigEntry<bool> _incluirEquipado;

		private ConfigEntry<int> _dejarMinimoPorItem;

		private ConfigEntry<int> _dejarMinimoMunicion;

		private ConfigEntry<string> _listaPieles;

		private ConfigEntry<string> _listaMinerales;

		private ConfigEntry<string> _listaMadera;

		private ConfigEntry<string> _listaSemillas;

		private ConfigEntry<string> _listaMonstruos;

		private ConfigEntry<string> _categoriasPropias;

		private ConfigEntry<bool> _autoVincular;

		private ConfigEntry<KeyboardShortcut> _teclaCategorias;

		private ConfigEntry<string> _reglasPorItem;

		internal bool AutoVincularNuevos
		{
			get
			{
				if (_autoVincular != null)
				{
					return _autoVincular.Value;
				}
				return false;
			}
		}

		private void Awake()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Expected O, but got Unknown
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Expected O, but got Unknown
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Expected O, but got Unknown
			//IL_026c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0345: Unknown result type (might be due to invalid IL or missing references)
			Instancia = this;
			_teclaVincular = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("1 - Teclas", "TeclaVincular", new KeyboardShortcut((KeyCode)107, Array.Empty<KeyCode>()), "Mirando un cofre, lo vincula. Si ya estaba vinculado, lo desvincula.");
			_teclaEnviar = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("1 - Teclas", "TeclaEnviar", new KeyboardShortcut((KeyCode)106, Array.Empty<KeyCode>()), "Reparte tu inventario entre los cofres vinculados que esten dentro del rango.");
			_teclaRellenar = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("1 - Teclas", "TeclaRellenar", new KeyboardShortcut((KeyCode)117, Array.Empty<KeyCode>()), "Rellena desde los cofres las pilas que ya traes, hasta su maximo. No trae items nuevos.");
			_rango = ((BaseUnityPlugin)this).Config.Bind<float>("2 - General", "Rango", 20f, new ConfigDescription("Distancia maxima en metros entre tu personaje y un cofre para poder enviarle cosas.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 200f), Array.Empty<object>()));
			_incluirEquipado = ((BaseUnityPlugin)this).Config.Bind<bool>("2 - General", "IncluirEquipado", false, "Si esta activo, tambien envia lo que traes equipado. Recomendado dejarlo apagado.");
			_dejarMinimoPorItem = ((BaseUnityPlugin)this).Config.Bind<int>("3 - Reservas", "DejarMinimoPorItem", 0, new ConfigDescription("Unidades de cada item que siempre se quedan contigo. 0 = mandar todo.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
			_dejarMinimoMunicion = ((BaseUnityPlugin)this).Config.Bind<int>("3 - Reservas", "DejarMinimoMunicion", 0, new ConfigDescription("Unidades de cada tipo de municion que siempre se quedan contigo (flechas, etc). 0 = mandar todo.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 500), Array.Empty<object>()));
			_listaPieles = ((BaseUnityPlugin)this).Config.Bind<string>("4 - Categorias", "Pieles", "hide,pelt,leather,scale", "Textos que, si aparecen en el nombre interno del item, lo marcan como piel. Separados por coma.");
			_listaMinerales = ((BaseUnityPlugin)this).Config.Bind<string>("4 - Categorias", "Minerales", "ore,ingot,scrap,metal,coal,copper,tin,bronze,iron,silver,flametal,obsidian,flint,stone", "Textos que marcan un material como mineral. Separados por coma.");
			_listaMadera = ((BaseUnityPlugin)this).Config.Bind<string>("4 - Categorias", "Madera", "wood,log,beech,fir,oak,birch,yggdrasil,resin", "Textos que marcan un material como madera. Separados por coma.");
			_listaSemillas = ((BaseUnityPlugin)this).Config.Bind<string>("4 - Categorias", "Semillas", "seed,sapling", "Textos que marcan un material como semilla. Separados por coma.");
			_listaMonstruos = ((BaseUnityPlugin)this).Config.Bind<string>("4 - Categorias", "Monstruos", "greydwarfeye,bonefragments,witheredbone,entrails,necktail,wolffang,freezegland,ticksack,chitin,carapace,guck,bloodbag,softtissue", "Textos que marcan un material como despojo de monstruo. Separados por coma.");
			_categoriasPropias = ((BaseUnityPlugin)this).Config.Bind<string>("5 - Categorias propias", "Propias", "", "Tus propias categorias, ademas de las que trae el mod. Formato: Nombre=palabra1,palabra2;Otro\nLas palabras son opcionales: con ellas se clasifican solos los items cuyo nombre interno las contenga, y sin ellas la categoria solo se usa al asignarla a mano desde la ventana. Ejemplo: Pociones=mead,potion;Gemas");
			_autoVincular = ((BaseUnityPlugin)this).Config.Bind<bool>("2 - General", "AutoVincularNuevos", true, "Vincula automaticamente cada cofre nuevo que construyas.");
			_teclaCategorias = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("1 - Teclas", "TeclaCategorias", new KeyboardShortcut((KeyCode)287, Array.Empty<KeyCode>()), "Abre la ventana para elegir a mano la categoria de cada item.");
			_reglasPorItem = ((BaseUnityPlugin)this).Config.Bind<string>("6 - Reglas por item", "CategoriasElegidas", "", "Categorias elegidas a mano desde la ventana. Formato: item=Categoria;item=Categoria");
			ReglasItems.Iniciar(_reglasPorItem);
			RecargarListas();
			_listaPieles.SettingChanged += delegate
			{
				RecargarListas();
			};
			_listaMinerales.SettingChanged += delegate
			{
				RecargarListas();
			};
			_listaMadera.SettingChanged += delegate
			{
				RecargarListas();
			};
			_listaSemillas.SettingChanged += delegate
			{
				RecargarListas();
			};
			_listaMonstruos.SettingChanged += delegate
			{
				RecargarListas();
			};
			_categoriasPropias.SettingChanged += delegate
			{
				RecargarListas();
			};
			new Harmony("altairfernando.cofrefijo").PatchAll(Assembly.GetExecutingAssembly());
			((BaseUnityPlugin)this).Logger.LogInfo((object)"CofreFijo 1.1.3 cargado.");
		}

		private void RecargarListas()
		{
			Categorias.Pieles = Categorias.ParseLista(_listaPieles.Value);
			Categorias.Minerales = Categorias.ParseLista(_listaMinerales.Value);
			Categorias.Madera = Categorias.ParseLista(_listaMadera.Value);
			Categorias.Semillas = Categorias.ParseLista(_listaSemillas.Value);
			Categorias.Monstruos = Categorias.ParseLista(_listaMonstruos.Value);
			Categorias.CargarPropias(_categoriasPropias.Value);
		}

		private void OnGUI()
		{
			VentanaCategorias.Dibujar();
		}

		private void Update()
		{
			//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)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			if (EscribiendoTexto())
			{
				return;
			}
			KeyboardShortcut value = _teclaCategorias.Value;
			if (((KeyboardShortcut)(ref value)).IsDown())
			{
				VentanaCategorias.Alternar();
				return;
			}
			if (VentanaCategorias.Abierta)
			{
				if (Input.GetKeyDown((KeyCode)27))
				{
					VentanaCategorias.Cerrar();
				}
				return;
			}
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null || InterfazBloquea())
			{
				return;
			}
			value = _teclaVincular.Value;
			if (((KeyboardShortcut)(ref value)).IsDown())
			{
				AlternarCofreApuntado(localPlayer);
				return;
			}
			value = _teclaEnviar.Value;
			if (((KeyboardShortcut)(ref value)).IsDown())
			{
				Enviar(localPlayer);
				return;
			}
			value = _teclaRellenar.Value;
			if (((KeyboardShortcut)(ref value)).IsDown())
			{
				Rellenar(localPlayer);
			}
		}

		private static bool InterfazBloquea()
		{
			if (!Menu.IsVisible() && !InventoryGui.IsVisible())
			{
				return EscribiendoTexto();
			}
			return true;
		}

		private static bool EscribiendoTexto()
		{
			if (TextInput.IsVisible() || Console.IsVisible())
			{
				return true;
			}
			Chat instance = Chat.instance;
			if ((Object)(object)instance != (Object)null)
			{
				return instance.HasFocus();
			}
			return false;
		}

		private void AlternarCofreApuntado(Player jugador)
		{
			GameObject hoverObject = ((Humanoid)jugador).GetHoverObject();
			Container val = (((Object)(object)hoverObject != (Object)null) ? hoverObject.GetComponentInParent<Container>() : null);
			if ((Object)(object)val == (Object)null)
			{
				Mensaje("Apunta a un cofre para vincularlo");
				return;
			}
			bool flag = !Vinculo.EstaVinculado(val);
			if (!Vinculo.Marcar(val, flag))
			{
				Mensaje("No pude cambiar ese cofre, inténtalo de nuevo");
				return;
			}
			if (!flag)
			{
				Mensaje("Cofre desvinculado");
				return;
			}
			Categoria categoria = Categorias.DeCofre(val.GetInventory());
			Mensaje((categoria == Categoria.Ninguna) ? "Cofre vinculado y libre: se le asignará categoría sola" : ("Cofre vinculado: " + Categorias.Nombre(categoria)));
		}

		private void Enviar(Player jugador)
		{
			List<Destino> list = ReunirDestinos(jugador);
			if (list.Count == 0)
			{
				Mensaje("No hay cofres vinculados dentro de " + _rango.Value.ToString("0") + " m");
				return;
			}
			Inventory inventory = ((Humanoid)jugador).GetInventory();
			if (inventory == null)
			{
				return;
			}
			int num = 0;
			int num2 = 0;
			HashSet<Container> hashSet = new HashSet<Container>();
			HashSet<Categoria> hashSet2 = new HashSet<Categoria>();
			HashSet<ItemData> enSlotsEspeciales = SlotsExternos.ItemsEnSlots();
			foreach (GrupoItems item in AgruparMovibles(inventory, enSlotsEspeciales))
			{
				int num3 = ReservaPendiente(inventory, item, enSlotsEspeciales);
				foreach (ItemData item2 in item.Items)
				{
					int num4 = item2.m_stack - num3;
					if (num4 <= 0)
					{
						num3 -= item2.m_stack;
						continue;
					}
					num3 = 0;
					Destino destino = ElegirDestino(list, item2, num4);
					if (destino == null)
					{
						num2++;
						hashSet2.Add(Categorias.DeItem(item2));
					}
					else if (Mover(inventory, destino.Inventario, item2, num4))
					{
						num++;
						hashSet.Add(destino.Cofre);
					}
					else
					{
						num2++;
						hashSet2.Add(Categorias.DeItem(item2));
					}
				}
			}
			foreach (Container item3 in hashSet)
			{
				if (MetodoGuardarCofre != null)
				{
					MetodoGuardarCofre.Invoke(item3, null);
				}
			}
			string text = DescribirPendientes(num2, hashSet2);
			if (num == 0)
			{
				Mensaje((num2 > 0) ? text : "No hay nada que enviar");
				return;
			}
			string text2 = "Enviados " + num + ((num == 1) ? " objeto a " : " objetos a ") + hashSet.Count + ((hashSet.Count == 1) ? " cofre" : " cofres");
			Mensaje((num2 > 0) ? (text2 + ". " + text) : text2);
		}

		private static string DescribirPendientes(int sinDestino, HashSet<Categoria> categorias)
		{
			string text = sinDestino + ((sinDestino == 1) ? " objeto se quedó" : " objetos se quedaron");
			List<string> list = new List<string>();
			foreach (Categoria categoria in categorias)
			{
				if (categoria != Categoria.Ninguna)
				{
					list.Add(Categorias.Nombre(categoria));
				}
			}
			if (list.Count == 0)
			{
				return text + ": no hay cofre con espacio";
			}
			list.Sort(StringComparer.Ordinal);
			return text + ": falta cofre de " + string.Join(", ", list.ToArray());
		}

		private void Rellenar(Player jugador)
		{
			List<Destino> list = ReunirDestinos(jugador);
			if (list.Count == 0)
			{
				Mensaje("No hay cofres vinculados dentro de " + _rango.Value.ToString("0") + " m");
				return;
			}
			Inventory inventory = ((Humanoid)jugador).GetInventory();
			if (inventory == null)
			{
				return;
			}
			int num = 0;
			HashSet<Container> hashSet = new HashSet<Container>();
			foreach (Faltante item in CalcularFaltantes(inventory))
			{
				int num2 = item.Falta;
				foreach (Destino item2 in list)
				{
					if (num2 <= 0)
					{
						break;
					}
					foreach (ItemData item3 in new List<ItemData>(item2.Inventario.GetAllItems()))
					{
						if (num2 <= 0)
						{
							break;
						}
						if (item3.m_shared != null && string.Equals(item3.m_shared.m_name, item.Nombre, StringComparison.Ordinal) && item3.m_quality == item.Calidad)
						{
							int num3 = Math.Min(num2, item3.m_stack);
							ItemData val = item3.Clone();
							val.m_stack = num3;
							if (inventory.CanAddItem(val, num3) && inventory.AddItem(val))
							{
								item2.Inventario.RemoveItem(item3, num3);
								hashSet.Add(item2.Cofre);
								num2 -= num3;
								num += num3;
							}
						}
					}
				}
			}
			foreach (Container item4 in hashSet)
			{
				if (MetodoGuardarCofre != null)
				{
					MetodoGuardarCofre.Invoke(item4, null);
				}
			}
			if (num == 0)
			{
				Mensaje("No hay nada con qué rellenar");
				return;
			}
			Mensaje("Rellenadas " + num + ((num == 1) ? " unidad desde " : " unidades desde ") + hashSet.Count + ((hashSet.Count == 1) ? " cofre" : " cofres"));
		}

		private static List<Faltante> CalcularFaltantes(Inventory inventario)
		{
			Dictionary<string, Faltante> dictionary = new Dictionary<string, Faltante>();
			foreach (ItemData allItem in inventario.GetAllItems())
			{
				SharedData shared = allItem.m_shared;
				if (shared == null || shared.m_maxStackSize <= 1 || string.IsNullOrEmpty(shared.m_name))
				{
					continue;
				}
				int num = shared.m_maxStackSize - allItem.m_stack;
				if (num > 0)
				{
					string key = shared.m_name + "#" + allItem.m_quality;
					if (!dictionary.TryGetValue(key, out var value))
					{
						value = (dictionary[key] = new Faltante
						{
							Nombre = shared.m_name,
							Calidad = allItem.m_quality
						});
					}
					value.Falta += num;
				}
			}
			return new List<Faltante>(dictionary.Values);
		}

		private List<Destino> ReunirDestinos(Player jugador)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			List<Destino> list = new List<Destino>();
			Vector3 position = ((Component)jugador).transform.position;
			Container[] array = Object.FindObjectsByType<Container>((FindObjectsSortMode)0);
			foreach (Container val in array)
			{
				if ((Object)(object)val == (Object)null || !Vinculo.EstaVinculado(val))
				{
					continue;
				}
				float num = Vector3.Distance(position, ((Component)val).transform.position);
				if (num > _rango.Value || val.IsInUse() || !PrivateArea.CheckAccess(((Component)val).transform.position, 0f, false, false))
				{
					continue;
				}
				ZNetView component = ((Component)val).GetComponent<ZNetView>();
				if (!((Object)(object)component == (Object)null) && component.IsValid())
				{
					Inventory inventory = val.GetInventory();
					if (inventory != null)
					{
						component.ClaimOwnership();
						list.Add(new Destino
						{
							Cofre = val,
							Inventario = inventory,
							Categoria = Categorias.DeCofre(inventory),
							Distancia = num
						});
					}
				}
			}
			list.Sort((Destino a, Destino b) => a.Distancia.CompareTo(b.Distancia));
			return list;
		}

		private static Destino ElegirDestino(List<Destino> destinos, ItemData item, int cantidad)
		{
			Categoria categoria = Categorias.DeItem(item);
			string text = ((item.m_shared != null) ? item.m_shared.m_name : null);
			Destino destino = null;
			int num = 0;
			foreach (Destino destino2 in destinos)
			{
				int num2 = 0;
				if (!string.IsNullOrEmpty(text) && destino2.Inventario.ContainsItemByName(text))
				{
					num2 = 2;
				}
				else if (categoria != Categoria.Ninguna && destino2.Categoria == categoria)
				{
					num2 = 1;
				}
				if (num2 != 0 && destino2.Inventario.CanAddItem(item, cantidad) && num2 > num)
				{
					destino = destino2;
					num = num2;
				}
			}
			if (destino != null || categoria == Categoria.Ninguna)
			{
				return destino;
			}
			foreach (Destino destino3 in destinos)
			{
				if (destino3.Categoria == Categoria.Ninguna && destino3.Inventario.CanAddItem(item, cantidad))
				{
					destino3.Categoria = categoria;
					return destino3;
				}
			}
			return null;
		}

		private static bool Mover(Inventory origen, Inventory destino, ItemData item, int cantidad)
		{
			if (cantidad <= 0)
			{
				return false;
			}
			if (cantidad >= item.m_stack)
			{
				if (!destino.CanAddItem(item, item.m_stack) || !destino.AddItem(item))
				{
					return false;
				}
				origen.RemoveItem(item);
				return true;
			}
			ItemData val = item.Clone();
			val.m_stack = cantidad;
			if (!destino.CanAddItem(val, cantidad) || !destino.AddItem(val))
			{
				return false;
			}
			origen.RemoveItem(item, cantidad);
			return true;
		}

		private List<GrupoItems> AgruparMovibles(Inventory inventario, HashSet<ItemData> enSlotsEspeciales)
		{
			List<GrupoItems> list = new List<GrupoItems>();
			Dictionary<string, GrupoItems> dictionary = new Dictionary<string, GrupoItems>();
			foreach (ItemData allItem in inventario.GetAllItems())
			{
				if (!EsMovible(allItem, enSlotsEspeciales))
				{
					continue;
				}
				string text = ((allItem.m_shared != null) ? allItem.m_shared.m_name : Categorias.NombreInterno(allItem));
				if (!string.IsNullOrEmpty(text))
				{
					if (!dictionary.TryGetValue(text, out var value))
					{
						value = (dictionary[text] = new GrupoItems
						{
							Clave = text
						});
						list.Add(value);
					}
					value.Items.Add(allItem);
				}
			}
			return list;
		}

		private bool EsMovible(ItemData item, HashSet<ItemData> enSlotsEspeciales)
		{
			if (item == null || item.m_shared == null)
			{
				return false;
			}
			if (item.m_gridPos.y == 0)
			{
				return false;
			}
			if (enSlotsEspeciales != null && enSlotsEspeciales.Contains(item))
			{
				return false;
			}
			if (!_incluirEquipado.Value)
			{
				return !item.m_equipped;
			}
			return true;
		}

		private int ReservaPendiente(Inventory inventario, GrupoItems grupo, HashSet<ItemData> enSlotsEspeciales)
		{
			int num = ((Categorias.DeItem(grupo.Items[0]) == Categoria.Municion) ? _dejarMinimoMunicion.Value : _dejarMinimoPorItem.Value);
			if (num <= 0)
			{
				return 0;
			}
			int num2 = 0;
			foreach (ItemData allItem in inventario.GetAllItems())
			{
				if (!EsMovible(allItem, enSlotsEspeciales) && allItem.m_shared != null && string.Equals(allItem.m_shared.m_name, grupo.Clave, StringComparison.Ordinal))
				{
					num2 += allItem.m_stack;
				}
			}
			int num3 = num - num2;
			if (num3 <= 0)
			{
				return 0;
			}
			return num3;
		}

		private static void Mensaje(string texto)
		{
			MessageHud instance = MessageHud.instance;
			if ((Object)(object)instance != (Object)null)
			{
				instance.ShowMessage((MessageType)2, texto, 0, (Sprite)null, false, false);
			}
		}
	}
	internal static class ReglasItems
	{
		private const char SeparadorRegistro = ';';

		private const char SeparadorCampo = '=';

		private static ConfigEntry<string> _almacen;

		private static Dictionary<string, Categoria> _reglas = new Dictionary<string, Categoria>();

		internal static int Cantidad => _reglas.Count;

		internal static void Iniciar(ConfigEntry<string> almacen)
		{
			_almacen = almacen;
			Releer();
			_almacen.SettingChanged += delegate
			{
				Releer();
			};
		}

		internal static bool TryObtener(string nombreInterno, out Categoria categoria)
		{
			return _reglas.TryGetValue(nombreInterno, out categoria);
		}

		internal static void Asignar(string nombreInterno, Categoria categoria)
		{
			if (!string.IsNullOrEmpty(nombreInterno))
			{
				_reglas[nombreInterno.ToLowerInvariant()] = categoria;
				Guardar();
			}
		}

		internal static void Quitar(string nombreInterno)
		{
			if (!string.IsNullOrEmpty(nombreInterno) && _reglas.Remove(nombreInterno.ToLowerInvariant()))
			{
				Guardar();
			}
		}

		private static void Releer()
		{
			Dictionary<string, Categoria> dictionary = new Dictionary<string, Categoria>();
			if (_almacen == null || string.IsNullOrEmpty(_almacen.Value))
			{
				_reglas = dictionary;
				return;
			}
			string[] array = _almacen.Value.Split(new char[1] { ';' }, StringSplitOptions.RemoveEmptyEntries);
			for (int i = 0; i < array.Length; i++)
			{
				string[] array2 = array[i].Split(new char[1] { '=' });
				if (array2.Length != 2)
				{
					continue;
				}
				string text = array2[0].Trim().ToLowerInvariant();
				if (text.Length != 0)
				{
					Categoria value = Categoria.Desde(array2[1]);
					if (!value.EsNinguna)
					{
						dictionary[text] = value;
					}
				}
			}
			_reglas = dictionary;
		}

		private static void Guardar()
		{
			if (_almacen == null)
			{
				return;
			}
			List<string> list = new List<string>(_reglas.Count);
			foreach (KeyValuePair<string, Categoria> regla in _reglas)
			{
				list.Add(regla.Key + "=" + regla.Value.ToString());
			}
			list.Sort(StringComparer.Ordinal);
			_almacen.Value = string.Join(';'.ToString(), list.ToArray());
		}
	}
	internal static class SlotsExternos
	{
		private const string NombreEnsamblado = "ExtraSlots";

		private const string NombreTipo = "ExtraSlots.API";

		private const string NombreMetodo = "GetAllExtraSlotsItems";

		private static bool _buscado;

		private static MethodInfo _metodo;

		internal static bool Disponible => Metodo != null;

		private static MethodInfo Metodo
		{
			get
			{
				if (!_buscado)
				{
					_buscado = true;
					_metodo = Localizar();
				}
				return _metodo;
			}
		}

		private static MethodInfo Localizar()
		{
			try
			{
				Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
				foreach (Assembly assembly in assemblies)
				{
					if (!(assembly.GetName().Name != "ExtraSlots"))
					{
						Type type = assembly.GetType("ExtraSlots.API");
						if (!(type == null))
						{
							return type.GetMethod("GetAllExtraSlotsItems", BindingFlags.Static | BindingFlags.Public);
						}
					}
				}
			}
			catch
			{
			}
			return null;
		}

		internal static HashSet<ItemData> ItemsEnSlots()
		{
			HashSet<ItemData> hashSet = new HashSet<ItemData>();
			MethodInfo metodo = Metodo;
			if (metodo == null)
			{
				return hashSet;
			}
			try
			{
				if (!(metodo.Invoke(null, null) is IEnumerable enumerable))
				{
					return hashSet;
				}
				foreach (object item in enumerable)
				{
					ItemData val = (ItemData)((item is ItemData) ? item : null);
					if (val != null)
					{
						hashSet.Add(val);
					}
				}
			}
			catch
			{
			}
			return hashSet;
		}
	}
	internal static class VentanaCategorias
	{
		private class Entrada
		{
			internal string Interno;

			internal string Visible;

			internal ItemData Datos;
		}

		[CompilerGenerated]
		private static class <>O
		{
			public static WindowFunction <0>__Contenido;
		}

		private const int MaximoFilas = 150;

		private static readonly int IdVentana = "CofreFijo.Categorias".GetHashCode();

		private const int CategoriasPorFila = 6;

		private static readonly List<Entrada> Items = new List<Entrada>();

		private static Rect _rect = new Rect(120f, 90f, 620f, 520f);

		private static Vector2 _scroll;

		private static string _busqueda = "";

		private static string _editando;

		internal static bool Abierta { get; private set; }

		internal static void Alternar()
		{
			Abierta = !Abierta;
			if (Abierta && Items.Count == 0)
			{
				Construir();
			}
			if (!Abierta)
			{
				_editando = null;
			}
		}

		internal static void Cerrar()
		{
			Abierta = false;
			_editando = null;
		}

		private static void Construir()
		{
			Items.Clear();
			ObjectDB instance = ObjectDB.instance;
			if ((Object)(object)instance == (Object)null || instance.m_items == null)
			{
				return;
			}
			foreach (GameObject item in instance.m_items)
			{
				if (!((Object)(object)item == (Object)null))
				{
					ItemDrop component = item.GetComponent<ItemDrop>();
					if (!((Object)(object)component == (Object)null) && component.m_itemData != null && component.m_itemData.m_shared != null)
					{
						Items.Add(new Entrada
						{
							Interno = ((Object)item).name.ToLowerInvariant(),
							Visible = Localizar(component.m_itemData.m_shared.m_name),
							Datos = component.m_itemData
						});
					}
				}
			}
			Items.Sort((Entrada a, Entrada b) => string.Compare(a.Visible, b.Visible, StringComparison.OrdinalIgnoreCase));
		}

		private static string Localizar(string token)
		{
			try
			{
				Localization instance = Localization.instance;
				if (instance != null)
				{
					string text = instance.Localize(token);
					if (!string.IsNullOrEmpty(text))
					{
						return text;
					}
				}
			}
			catch
			{
			}
			return token;
		}

		internal static void Dibujar()
		{
			//IL_000d: 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_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			if (Abierta)
			{
				int idVentana = IdVentana;
				Rect rect = _rect;
				object obj = <>O.<0>__Contenido;
				if (obj == null)
				{
					WindowFunction val = Contenido;
					<>O.<0>__Contenido = val;
					obj = (object)val;
				}
				_rect = GUILayout.Window(idVentana, rect, (WindowFunction)obj, "CofreFijo - Categorías de items", Array.Empty<GUILayoutOption>());
			}
		}

		private static void Contenido(int id)
		{
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label("Buscar:", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(55f) });
			_busqueda = GUILayout.TextField(_busqueda ?? "", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(220f) });
			if (GUILayout.Button("Limpiar", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(70f) }))
			{
				_busqueda = "";
			}
			GUILayout.FlexibleSpace();
			GUILayout.Label(ReglasItems.Cantidad + " manuales", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(95f) });
			if (GUILayout.Button("Cerrar", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(65f) }))
			{
				Cerrar();
			}
			GUILayout.EndHorizontal();
			if (Items.Count == 0)
			{
				GUILayout.Label("No pude leer la lista de items. Entra a un mundo y vuelve a abrir.", Array.Empty<GUILayoutOption>());
				GUI.DragWindow();
				return;
			}
			GUILayout.Label("La categoría en gris es la automática. Si eliges una, queda fija para ese item.", Array.Empty<GUILayoutOption>());
			GUILayout.Space(4f);
			_scroll = GUILayout.BeginScrollView(_scroll, Array.Empty<GUILayoutOption>());
			string text = (_busqueda ?? "").Trim().ToLowerInvariant();
			int num = 0;
			foreach (Entrada item in Items)
			{
				if (text.Length <= 0 || item.Interno.IndexOf(text, StringComparison.Ordinal) >= 0 || item.Visible.ToLowerInvariant().IndexOf(text, StringComparison.Ordinal) >= 0)
				{
					if (num >= 150)
					{
						GUILayout.Label("... hay más. Escribe en el buscador para acotar.", Array.Empty<GUILayoutOption>());
						break;
					}
					num++;
					DibujarFila(item);
				}
			}
			if (num == 0)
			{
				GUILayout.Label("Ningún item coincide con \"" + _busqueda + "\"", Array.Empty<GUILayoutOption>());
			}
			GUILayout.EndScrollView();
			GUI.DragWindow();
		}

		private static void DibujarFila(Entrada entrada)
		{
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: 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_009e: Unknown result type (might be due to invalid IL or missing references)
			Categoria categoria;
			bool flag = ReglasItems.TryObtener(entrada.Interno, out categoria);
			Categoria categoria2 = Categorias.DeItem(entrada.Datos, entrada.Interno);
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label(entrada.Visible, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(200f) });
			GUILayout.Label(entrada.Interno, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(150f) });
			Color color = GUI.color;
			GUI.color = (flag ? Color.white : Color.gray);
			GUILayout.Label(Categorias.Nombre(categoria2), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(95f) });
			GUI.color = color;
			bool flag2 = _editando == entrada.Interno;
			if (GUILayout.Button(flag2 ? "Cancelar" : "Cambiar", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(75f) }))
			{
				_editando = (flag2 ? null : entrada.Interno);
			}
			if (flag && GUILayout.Button("Auto", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(50f) }))
			{
				ReglasItems.Quitar(entrada.Interno);
				_editando = null;
			}
			GUILayout.EndHorizontal();
			if (!flag2)
			{
				return;
			}
			Categoria[] todas = Categorias.Todas;
			for (int i = 0; i < todas.Length; i += 6)
			{
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				GUILayout.Space(20f);
				for (int j = i; j < i + 6 && j < todas.Length; j++)
				{
					if (GUILayout.Button(Categorias.Nombre(todas[j]), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(88f) }))
					{
						ReglasItems.Asignar(entrada.Interno, todas[j]);
						_editando = null;
					}
				}
				GUILayout.FlexibleSpace();
				GUILayout.EndHorizontal();
			}
		}
	}
	internal static class Vinculo
	{
		private const string Clave = "CofreFijo_vinculado";

		internal static bool EstaVinculado(Container cofre)
		{
			ZNetView val = VistaDe(cofre);
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			ZDO zDO = val.GetZDO();
			if (zDO != null && zDO.IsValid())
			{
				return zDO.GetBool("CofreFijo_vinculado", false);
			}
			return false;
		}

		internal static bool Marcar(Container cofre, bool vinculado)
		{
			ZNetView val = VistaDe(cofre);
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			val.ClaimOwnership();
			ZDO zDO = val.GetZDO();
			if (zDO == null || !zDO.IsValid())
			{
				return false;
			}
			zDO.Set("CofreFijo_vinculado", vinculado);
			return true;
		}

		private static ZNetView VistaDe(Container cofre)
		{
			if ((Object)(object)cofre == (Object)null)
			{
				return null;
			}
			ZNetView component = ((Component)cofre).GetComponent<ZNetView>();
			if (!((Object)(object)component != (Object)null) || !component.IsValid())
			{
				return null;
			}
			return component;
		}
	}
}