Decompiled source of TripleDrop v1.0.2

TripleDrop.dll

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

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

[BepInPlugin("yuri.TripleDrop", "Triple Drop", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
	private class Marca
	{
		public Vector3 pos;

		public float quando;
	}

	private class Alvo
	{
		public Character bicho;

		public Vector3 pos;

		public float quando;
	}

	[HarmonyPatch(typeof(Character), "Damage")]
	private static class AoGolpe
	{
		private static void Postfix(Character __instance, HitData hit)
		{
			if (!((Object)(object)Inst == (Object)null) && Inst.Ativo() && hit != null && !((Object)(object)__instance == (Object)null))
			{
				Character attacker = hit.GetAttacker();
				if (!((Object)(object)attacker == (Object)null) && !((Object)(object)attacker != (Object)(object)Player.m_localPlayer))
				{
					Inst.MarcarGolpe(__instance);
				}
			}
		}
	}

	[HarmonyPatch(typeof(Character), "OnDeath")]
	private static class AoMorrer
	{
		private static void Postfix(Character __instance)
		{
			if (!((Object)(object)Inst == (Object)null) && Inst.Ativo())
			{
				Inst.MarcarMorte(__instance);
			}
		}
	}

	[HarmonyPatch(typeof(Player), "OnDeath")]
	private static class AoMorrerEu
	{
		private static void Prefix(Player __instance)
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)Inst == (Object)null) && Inst.Ativo() && !((Object)(object)__instance != (Object)(object)Player.m_localPlayer))
			{
				Inst.MarcarMinhaMorte(((Component)__instance).transform.position);
			}
		}
	}

	[HarmonyPatch(typeof(MineRock), "Damage")]
	private static class AoMinerar
	{
		private static void Postfix(MineRock __instance, HitData hit)
		{
			MarcarPedra((Component)(object)__instance, hit);
		}
	}

	[HarmonyPatch(typeof(MineRock5), "Damage")]
	private static class AoMinerar5
	{
		private static void Postfix(MineRock5 __instance, HitData hit)
		{
			MarcarPedra((Component)(object)__instance, hit);
		}
	}

	[HarmonyPatch(typeof(TreeBase), "Damage")]
	private static class AoCortar
	{
		private static void Postfix(TreeBase __instance, HitData hit)
		{
			MarcarCorteSeMeu((Component)(object)__instance, hit);
		}
	}

	[HarmonyPatch(typeof(TreeLog), "Damage")]
	private static class AoCortarTronco
	{
		private static void Postfix(TreeLog __instance, HitData hit)
		{
			MarcarCorteSeMeu((Component)(object)__instance, hit);
		}
	}

	[HarmonyPatch(typeof(Destructible), "Damage")]
	private static class AoQuebrar
	{
		private static void Postfix(Destructible __instance, HitData hit)
		{
			MarcarCorteSeMeu((Component)(object)__instance, hit);
		}
	}

	[HarmonyPatch(typeof(Smelter), "OnEmpty")]
	private static class AoEsvaziarForno
	{
		private static void Postfix(Smelter __instance, Humanoid user)
		{
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)Inst == (Object)null) && Inst.Ativo() && !((Object)(object)__instance == (Object)null) && !((Object)(object)user == (Object)null) && !((Object)(object)user != (Object)(object)Player.m_localPlayer))
			{
				Inst.MarcarForno(((Component)__instance).transform.position);
			}
		}
	}

	[HarmonyPatch(typeof(ItemDrop), "OnPlayerDrop")]
	private static class AoLargar
	{
		private static void Postfix(ItemDrop __instance)
		{
			if (!((Object)(object)Inst == (Object)null))
			{
				Inst.MarcarLargado(__instance);
			}
		}
	}

	[HarmonyPatch(typeof(Humanoid), "Pickup")]
	private static class AoPegar
	{
		private static int stackAntes;

		private static void Prefix(GameObject go)
		{
			stackAntes = 0;
			if (!((Object)(object)go == (Object)null))
			{
				ItemDrop component = go.GetComponent<ItemDrop>();
				if ((Object)(object)component != (Object)null && component.m_itemData != null)
				{
					stackAntes = component.m_itemData.m_stack;
				}
			}
		}

		private static void Postfix(Humanoid __instance, GameObject go, bool __result)
		{
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			if (!__result || (Object)(object)Inst == (Object)null || !Inst.Ativo() || (Object)(object)__instance != (Object)(object)Player.m_localPlayer || (Object)(object)go == (Object)null)
			{
				return;
			}
			ItemDrop component = go.GetComponent<ItemDrop>();
			if (!((Object)(object)component == (Object)null) && component.m_itemData != null && !Inst.FoiLargado(component) && !Inst.VeioDaMinhaMorte(go.transform.position))
			{
				int stack = component.m_itemData.m_stack;
				int num = stackAntes - stack;
				if (num < 1)
				{
					num = stackAntes;
				}
				if (num < 1)
				{
					num = 1;
				}
				Inst.Entregar(component.m_itemData, num);
			}
		}
	}

	[HarmonyPatch(typeof(Humanoid), "GiveDefaultItems")]
	private static class AoKitInicial
	{
		private static void Prefix()
		{
			IgnorarPadrao++;
		}

		private static void Postfix()
		{
			IgnorarPadrao--;
			if (IgnorarPadrao < 0)
			{
				IgnorarPadrao = 0;
			}
		}
	}

	[HarmonyPatch(typeof(Humanoid), "PickupPrefab")]
	private static class AoPrefab
	{
		private static void Postfix(Humanoid __instance, GameObject prefab, int stackSize, ItemData __result)
		{
			if (__result != null && !((Object)(object)Inst == (Object)null) && Inst.Ativo() && IgnorarPadrao <= 0 && !((Object)(object)__instance != (Object)(object)Player.m_localPlayer) && !((Object)(object)prefab == (Object)null))
			{
				int num = stackSize;
				if (num < 1)
				{
					num = 1;
				}
				Inst.EntregarPrefab(prefab, num);
			}
		}
	}

	[HarmonyPatch(typeof(FishingFloat), "Catch")]
	private static class AoPescar
	{
		private static void Prefix()
		{
			Pesca++;
		}

		private static void Postfix()
		{
			Pesca--;
			if (Pesca < 0)
			{
				Pesca = 0;
			}
		}
	}

	[HarmonyPatch(typeof(Inventory), "AddItem", new Type[]
	{
		typeof(GameObject),
		typeof(int)
	})]
	private static class AoExtraDoPeixe
	{
		private static void Postfix(Inventory __instance, GameObject prefab, int amount, bool __result)
		{
			if (__result && !((Object)(object)Inst == (Object)null) && Inst.Ativo() && Pesca > 0 && Inst.entregando <= 0 && Inst.EhBolsaLocal(__instance))
			{
				Inst.EntregarPrefab(prefab, amount);
			}
		}
	}

	[HarmonyPatch(typeof(StoreGui), "BuySelectedItem")]
	private static class AoComprar
	{
		private static int antes;

		private static string nome;

		private static ItemDrop prefab;

		private static int pilha;

		private static void Prefix(TradeItem ___m_selectedItem)
		{
			antes = -1;
			nome = "";
			prefab = null;
			pilha = 0;
			if (___m_selectedItem != null && !((Object)(object)___m_selectedItem.m_prefab == (Object)null) && ___m_selectedItem.m_prefab.m_itemData != null && ___m_selectedItem.m_prefab.m_itemData.m_shared != null)
			{
				nome = ___m_selectedItem.m_prefab.m_itemData.m_shared.m_name;
				prefab = ___m_selectedItem.m_prefab;
				pilha = ___m_selectedItem.m_stack;
				antes = Contar(nome);
			}
		}

		private static void Postfix()
		{
			if (antes >= 0 && !((Object)(object)Inst == (Object)null) && !((Object)(object)prefab == (Object)null))
			{
				int num = Contar(nome) - antes;
				if (num < 1)
				{
					num = pilha;
				}
				if (num >= 1 && Contar(nome) > antes)
				{
					Inst.Entregar(prefab.m_itemData, num);
				}
			}
		}
	}

	[HarmonyPatch(typeof(Inventory), "MoveItemToThis", new Type[]
	{
		typeof(Inventory),
		typeof(ItemData)
	})]
	private static class AoTirarUm
	{
		private static ItemData pendente;

		private static int stackPendente;

		private static Inventory origemPendente;

		private static bool loot;

		private static void Prefix(Inventory __instance, Inventory fromInventory, ItemData item)
		{
			loot = false;
			if (!((Object)(object)Inst == (Object)null) && Inst.Ativo() && item != null && Inst.EhBolsaLocal(__instance) && Inst.BauDeLoot(fromInventory))
			{
				pendente = item;
				stackPendente = item.m_stack;
				origemPendente = fromInventory;
				loot = true;
			}
		}

		private static void Postfix()
		{
			if (!loot || (Object)(object)Inst == (Object)null)
			{
				return;
			}
			loot = false;
			int quantidade = stackPendente;
			if (origemPendente != null && pendente != null)
			{
				List<ItemData> allItems = origemPendente.GetAllItems();
				for (int i = 0; i < allItems.Count; i++)
				{
					if (allItems[i] == pendente)
					{
						quantidade = stackPendente - pendente.m_stack;
					}
				}
			}
			Inst.Entregar(pendente, quantidade);
			pendente = null;
			origemPendente = null;
		}
	}

	[HarmonyPatch(typeof(Inventory), "MoveItemToThis", new Type[]
	{
		typeof(Inventory),
		typeof(ItemData),
		typeof(int),
		typeof(int),
		typeof(int)
	})]
	private static class AoTirarParte
	{
		private static void Prefix(Inventory __instance, Inventory fromInventory, ref bool __state)
		{
			__state = false;
			if (!((Object)(object)Inst == (Object)null) && Inst.Ativo() && Inst.EhBolsaLocal(__instance) && Inst.BauDeLoot(fromInventory))
			{
				__state = true;
			}
		}

		private static void Postfix(ItemData item, int amount, bool __result, bool __state)
		{
			if (__state && __result && !((Object)(object)Inst == (Object)null))
			{
				Inst.Entregar(item, amount);
			}
		}
	}

	[HarmonyPatch(typeof(Inventory), "MoveAll")]
	private static class AoTirarTudo
	{
		private class Pilha
		{
			public ItemData item;

			public int stack;
		}

		private static List<Pilha> antes;

		private static Inventory origem;

		private static void Prefix(Inventory __instance, Inventory fromInventory)
		{
			antes = null;
			if ((Object)(object)Inst == (Object)null || !Inst.Ativo() || !Inst.EhBolsaLocal(__instance) || !Inst.BauDeLoot(fromInventory))
			{
				return;
			}
			origem = fromInventory;
			antes = new List<Pilha>();
			List<ItemData> allItems = fromInventory.GetAllItems();
			for (int i = 0; i < allItems.Count; i++)
			{
				if (allItems[i] != null)
				{
					Pilha pilha = new Pilha();
					pilha.item = allItems[i];
					pilha.stack = allItems[i].m_stack;
					antes.Add(pilha);
				}
			}
		}

		private static void Postfix()
		{
			if (antes == null || (Object)(object)Inst == (Object)null)
			{
				return;
			}
			List<Pilha> list = antes;
			Inventory val = origem;
			antes = null;
			origem = null;
			for (int i = 0; i < list.Count; i++)
			{
				int quantidade = list[i].stack;
				if (val != null)
				{
					List<ItemData> allItems = val.GetAllItems();
					for (int j = 0; j < allItems.Count; j++)
					{
						if (allItems[j] == list[i].item)
						{
							quantidade = list[i].stack - list[i].item.m_stack;
						}
					}
				}
				Inst.Entregar(list[i].item, quantidade);
			}
		}
	}

	[HarmonyPatch(typeof(Pickable), "Interact")]
	private static class AoColher
	{
		private static bool estava;

		private static void Prefix(bool ___m_picked, bool ___m_pickedLocal)
		{
			estava = ___m_picked || ___m_pickedLocal;
		}

		private static void Postfix(Pickable __instance, Humanoid character, bool ___m_picked, bool ___m_pickedLocal)
		{
			if (estava || (Object)(object)Inst == (Object)null || !Inst.Ativo() || (Object)(object)__instance == (Object)null || (Object)(object)character != (Object)(object)Player.m_localPlayer || (!___m_pickedLocal && !___m_picked) || (Object)(object)__instance.m_itemPrefab == (Object)null)
			{
				return;
			}
			ItemDrop component = __instance.m_itemPrefab.GetComponent<ItemDrop>();
			if (!((Object)(object)component == (Object)null) && component.m_itemData != null)
			{
				int num = __instance.m_amount;
				if (num < 1)
				{
					num = 1;
				}
				Inst.Entregar(component.m_itemData, num);
			}
		}
	}

	public static Plugin Inst;

	private ConfigEntry<bool> Ligado;

	private ConfigEntry<int> Vezes;

	private List<Marca> mortes = new List<Marca>();

	private List<Marca> minas = new List<Marca>();

	private List<Marca> cortes = new List<Marca>();

	private List<Marca> fornos = new List<Marca>();

	private List<Marca> minhasMortes = new List<Marca>();

	private List<Alvo> alvos = new List<Alvo>();

	private List<ItemDrop> largados = new List<ItemDrop>();

	private float proximaLimpeza;

	private int entregando;

	private float ultimoAvisoPeso;

	public static int Pesca;

	public static int IgnorarPadrao;

	private void Awake()
	{
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Expected O, but got Unknown
		Inst = this;
		Ligado = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Triples what you pick up. Your grave and the inventory from your own death stay at the normal amount. Extra copies stop at your carry weight. Only your own game needs this mod.");
		Vezes = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Times", 3, "How many times the item comes in. 3 means the normal drop plus two extra copies.");
		Harmony val = new Harmony("yuri.TripleDrop");
		val.PatchAll(typeof(Plugin).Assembly);
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Triple Drop 1.0.7");
	}

	private void Update()
	{
		VigiarAlvos();
		if (Time.time < proximaLimpeza)
		{
			return;
		}
		proximaLimpeza = Time.time + 2f;
		Limpar(mortes, 45f);
		Limpar(minas, 180f);
		Limpar(cortes, 180f);
		Limpar(fornos, 180f);
		Limpar(minhasMortes, 7200f);
		for (int num = largados.Count - 1; num >= 0; num--)
		{
			if ((Object)(object)largados[num] == (Object)null)
			{
				largados.RemoveAt(num);
			}
		}
	}

	private static void Limpar(List<Marca> lista, float vida)
	{
		float time = Time.time;
		for (int num = lista.Count - 1; num >= 0; num--)
		{
			if (time - lista[num].quando > vida)
			{
				lista.RemoveAt(num);
			}
		}
	}

	public int Multiplicador()
	{
		int num = Vezes.Value;
		if (num < 1)
		{
			num = 1;
		}
		if (num > 5)
		{
			num = 5;
		}
		return num;
	}

	public bool Ativo()
	{
		return Ligado.Value && Multiplicador() > 1;
	}

	public void Avisar(string texto)
	{
		((BaseUnityPlugin)this).Logger.LogInfo((object)texto);
	}

	public void MarcarGolpe(Character bicho)
	{
		//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00af: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)bicho == (Object)null || bicho.IsPlayer())
		{
			return;
		}
		for (int i = 0; i < alvos.Count; i++)
		{
			if ((Object)(object)alvos[i].bicho == (Object)(object)bicho)
			{
				alvos[i].quando = Time.time;
				return;
			}
		}
		if (alvos.Count > 24)
		{
			alvos.RemoveAt(0);
		}
		Alvo alvo = new Alvo();
		alvo.bicho = bicho;
		alvo.pos = ((Component)bicho).transform.position;
		alvo.quando = Time.time;
		alvos.Add(alvo);
	}

	private void VigiarAlvos()
	{
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		for (int num = alvos.Count - 1; num >= 0; num--)
		{
			Alvo alvo = alvos[num];
			if ((Object)(object)alvo.bicho == (Object)null)
			{
				Guardar(mortes, alvo.pos, 16);
				alvos.RemoveAt(num);
			}
			else
			{
				alvo.pos = ((Component)alvo.bicho).transform.position;
				if (alvo.bicho.IsDead() || alvo.bicho.GetHealth() <= 0f)
				{
					Guardar(mortes, alvo.pos, 16);
					alvos.RemoveAt(num);
				}
				else if (Time.time - alvo.quando > 180f)
				{
					alvos.RemoveAt(num);
				}
			}
		}
	}

	public void MarcarMorte(Character bicho)
	{
		//IL_0076: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)bicho == (Object)null)
		{
			return;
		}
		bool flag = false;
		for (int num = alvos.Count - 1; num >= 0; num--)
		{
			if ((Object)(object)alvos[num].bicho == (Object)(object)bicho)
			{
				flag = true;
				alvos.RemoveAt(num);
			}
		}
		if (flag)
		{
			Guardar(mortes, ((Component)bicho).transform.position, 16);
		}
	}

	public void MarcarMina(Vector3 pos)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		Guardar(minas, pos, 24);
	}

	public void MarcarCorte(Vector3 pos)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		Guardar(cortes, pos, 24);
	}

	public void MarcarForno(Vector3 pos)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		Guardar(fornos, pos, 16);
	}

	public void MarcarLargado(ItemDrop drop)
	{
		if (!((Object)(object)drop == (Object)null) && !largados.Contains(drop))
		{
			largados.Add(drop);
		}
	}

	private static void Guardar(List<Marca> lista, Vector3 pos, int max)
	{
		//IL_001d: 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)
		if (lista.Count >= max)
		{
			lista.RemoveAt(0);
		}
		Marca marca = new Marca();
		marca.pos = pos;
		marca.quando = Time.time;
		lista.Add(marca);
	}

	public bool VeioDeMonstro(Vector3 pos)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		return Perto(mortes, pos, 18f, 45f);
	}

	public bool VeioDeMina(Vector3 pos, string prefab)
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		if (!EhMinerio(prefab))
		{
			return false;
		}
		return Perto(minas, pos, 14f, 180f);
	}

	public bool VeioDeCorte(Vector3 pos, string prefab)
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		if (!EhMadeira(prefab))
		{
			return false;
		}
		return Perto(cortes, pos, 20f, 180f);
	}

	public bool VeioDeForno(Vector3 pos, string prefab)
	{
		//IL_0018: 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_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		if (!EhMetal(prefab))
		{
			return false;
		}
		if (Perto(fornos, pos, 8f, 180f))
		{
			return true;
		}
		Smelter[] array = Object.FindObjectsOfType<Smelter>();
		if (array == null)
		{
			return false;
		}
		for (int i = 0; i < array.Length; i++)
		{
			if (!((Object)(object)array[i] == (Object)null))
			{
				Vector3 val = ((Component)array[i]).transform.position - pos;
				if (((Vector3)(ref val)).sqrMagnitude <= 64f)
				{
					return true;
				}
			}
		}
		return false;
	}

	public bool FoiLargado(ItemDrop drop)
	{
		return (Object)(object)drop != (Object)null && largados.Contains(drop);
	}

	public bool EhBolsaLocal(Inventory bolsa)
	{
		Player localPlayer = Player.m_localPlayer;
		return (Object)(object)localPlayer != (Object)null && bolsa != null && ((Humanoid)localPlayer).GetInventory() == bolsa;
	}

	public bool BauDeLoot(Inventory bolsa)
	{
		if (bolsa == null)
		{
			return false;
		}
		Container[] array = Object.FindObjectsOfType<Container>();
		if (array == null)
		{
			return false;
		}
		foreach (Container val in array)
		{
			if (!((Object)(object)val == (Object)null) && val.GetInventory() == bolsa)
			{
				if ((Object)(object)val.m_wagon != (Object)null)
				{
					return false;
				}
				if (EhLapide((Component)(object)val))
				{
					return false;
				}
				Piece val2 = ((Component)val).GetComponent<Piece>();
				if ((Object)(object)val2 == (Object)null)
				{
					val2 = ((Component)val).GetComponentInParent<Piece>();
				}
				if ((Object)(object)val2 != (Object)null && val2.IsPlacedByPlayer())
				{
					return false;
				}
				return true;
			}
		}
		return false;
	}

	public void MarcarMinhaMorte(Vector3 pos)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		Guardar(minhasMortes, pos, 12);
	}

	public bool VeioDaMinhaMorte(Vector3 pos)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		return Perto(minhasMortes, pos, 18f, 7200f);
	}

	private static bool EhLapide(Component coisa)
	{
		if ((Object)(object)coisa == (Object)null)
		{
			return false;
		}
		if ((Object)(object)coisa.GetComponent<TombStone>() != (Object)null)
		{
			return true;
		}
		if ((Object)(object)coisa.GetComponentInParent<TombStone>() != (Object)null)
		{
			return true;
		}
		Transform val = coisa.transform;
		while ((Object)(object)val != (Object)null)
		{
			string name = ((Object)val).name;
			if (name != null && name.ToLower().IndexOf("tomb") >= 0)
			{
				return true;
			}
			val = val.parent;
		}
		return false;
	}

	public void Entregar(ItemData modelo, int quantidade)
	{
		if (modelo != null)
		{
			GameObject val = modelo.m_dropPrefab;
			if ((Object)(object)val == (Object)null && modelo.m_shared != null && (Object)(object)ObjectDB.instance != (Object)null)
			{
				val = ObjectDB.instance.GetItemPrefab(modelo.m_shared.m_name);
			}
			EntregarPrefab(val, quantidade);
		}
	}

	public void EntregarPrefab(GameObject origem, int quantidade)
	{
		if (!Ativo() || (Object)(object)origem == (Object)null || quantidade < 1 || entregando > 0)
		{
			return;
		}
		int num = quantidade * (Multiplicador() - 1);
		if (num < 1)
		{
			return;
		}
		Player localPlayer = Player.m_localPlayer;
		if ((Object)(object)localPlayer == (Object)null)
		{
			return;
		}
		Inventory inventory = ((Humanoid)localPlayer).GetInventory();
		if (inventory == null)
		{
			return;
		}
		entregando++;
		int num2 = 0;
		bool flag = false;
		float num3 = PesoDeUm(origem);
		float maxCarryWeight = localPlayer.GetMaxCarryWeight();
		for (int i = 0; i < num; i++)
		{
			if (num3 > 0.001f && inventory.GetTotalWeight() + num3 > maxCarryWeight + 0.05f)
			{
				flag = true;
				break;
			}
			if (!inventory.AddItem(origem, 1))
			{
				break;
			}
			num2++;
		}
		entregando--;
		if (flag && Time.time - ultimoAvisoPeso > 3f)
		{
			ultimoAvisoPeso = Time.time;
			string text = "Carry weight is full.";
			if (num2 == 0)
			{
				text = "Carry weight is full. The extra did not go in.";
			}
			((Character)localPlayer).Message((MessageType)2, text, 0, (Sprite)null, true);
		}
		else if (num2 == 0)
		{
			((Character)localPlayer).Message((MessageType)2, "Bag is full. The extra did not fit.", 0, (Sprite)null, true);
		}
		else
		{
			Avisar("Extra " + ((Object)origem).name + " x" + num2);
		}
	}

	private static float PesoDeUm(GameObject origem)
	{
		if ((Object)(object)origem == (Object)null)
		{
			return 0f;
		}
		ItemDrop component = origem.GetComponent<ItemDrop>();
		if ((Object)(object)component == (Object)null || component.m_itemData == null || component.m_itemData.m_shared == null)
		{
			return 0f;
		}
		return component.m_itemData.GetWeight(1);
	}

	public static int Contar(string nome)
	{
		Player localPlayer = Player.m_localPlayer;
		if ((Object)(object)localPlayer == (Object)null || ((Humanoid)localPlayer).GetInventory() == null || nome == null || nome == "")
		{
			return 0;
		}
		int num = 0;
		List<ItemData> allItems = ((Humanoid)localPlayer).GetInventory().GetAllItems();
		for (int i = 0; i < allItems.Count; i++)
		{
			if (allItems[i] != null && allItems[i].m_shared != null && allItems[i].m_shared.m_name == nome)
			{
				num += allItems[i].m_stack;
			}
		}
		return num;
	}

	private static bool Perto(List<Marca> lista, Vector3 pos, float raio, float vida)
	{
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: 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)
		float time = Time.time;
		float num = raio * raio;
		for (int i = 0; i < lista.Count; i++)
		{
			if (!(time - lista[i].quando > vida))
			{
				Vector3 val = lista[i].pos - pos;
				if (((Vector3)(ref val)).sqrMagnitude <= num)
				{
					return true;
				}
			}
		}
		return false;
	}

	private static double Idade(ItemDrop drop)
	{
		try
		{
			if ((Object)(object)drop == (Object)null)
			{
				return 0.0;
			}
			FieldInfo field = typeof(ItemDrop).GetField("m_nview", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			object obj = ((field == null) ? null : field.GetValue(drop));
			if (obj == null)
			{
				return 0.0;
			}
			MethodInfo method = obj.GetType().GetMethod("IsValid");
			if (method != null && !(bool)method.Invoke(obj, null))
			{
				return 0.0;
			}
			MethodInfo method2 = obj.GetType().GetMethod("GetZDO");
			if (method2 != null && method2.Invoke(obj, null) == null)
			{
				return 0.0;
			}
			MethodInfo method3 = typeof(ItemDrop).GetMethod("GetTimeSinceSpawned", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (method3 == null)
			{
				return 0.0;
			}
			object obj2 = method3.Invoke(drop, null);
			if (obj2 is double result)
			{
				return result;
			}
			if (obj2 is float)
			{
				return (float)obj2;
			}
		}
		catch
		{
		}
		return 0.0;
	}

	private static bool EhMinerio(string nome)
	{
		if (string.IsNullOrEmpty(nome))
		{
			return false;
		}
		string[] array = new string[17]
		{
			"Stone", "Flint", "Coal", "CopperOre", "TinOre", "IronScrap", "SilverOre", "Obsidian", "Chitin", "BlackMarble",
			"CopperScrap", "FlametalOre", "Sulfur", "ProustitePowder", "Grausten", "BlackwoodAsh", "Ashstone"
		};
		for (int i = 0; i < array.Length; i++)
		{
			if (nome == array[i])
			{
				return true;
			}
		}
		return false;
	}

	private static bool EhMadeira(string nome)
	{
		if (string.IsNullOrEmpty(nome))
		{
			return false;
		}
		string[] array = new string[11]
		{
			"Wood", "FineWood", "RoundLog", "ElderBark", "YggdrasilWood", "Blackwood", "Resin", "BeechSeeds", "BirchSeeds", "Acorn",
			"FirCone"
		};
		for (int i = 0; i < array.Length; i++)
		{
			if (nome == array[i])
			{
				return true;
			}
		}
		return false;
	}

	private static bool EhMetal(string nome)
	{
		if (string.IsNullOrEmpty(nome))
		{
			return false;
		}
		string[] array = new string[11]
		{
			"Coal", "Tar", "Copper", "Tin", "Bronze", "Iron", "Silver", "BlackMetal", "Flametal", "Eitr",
			"LinenThread"
		};
		for (int i = 0; i < array.Length; i++)
		{
			if (nome == array[i])
			{
				return true;
			}
		}
		return false;
	}

	private static void MarcarPedra(Component pedra, HitData hit)
	{
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)Inst == (Object)null) && Inst.Ativo() && !((Object)(object)pedra == (Object)null) && hit != null)
		{
			Character attacker = hit.GetAttacker();
			if (!((Object)(object)attacker == (Object)null) && !((Object)(object)attacker != (Object)(object)Player.m_localPlayer))
			{
				Inst.MarcarMina(pedra.transform.position);
			}
		}
	}

	private static void MarcarCorteSeMeu(Component alvo, HitData hit)
	{
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)Inst == (Object)null) && Inst.Ativo() && !((Object)(object)alvo == (Object)null) && hit != null)
		{
			Character attacker = hit.GetAttacker();
			if (!((Object)(object)attacker == (Object)null) && !((Object)(object)attacker != (Object)(object)Player.m_localPlayer))
			{
				Inst.MarcarCorte(alvo.transform.position);
			}
		}
	}
}