Decompiled source of Architect v0.23.34

Architect.dll

Decompiled 12 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Logging;
using HarmonyLib;
using Splatform;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Rendering;
using UnityEngine.UI;

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

[HarmonyPatch(typeof(CraftingStation), "GetStationBuildRange")]
internal static class AlcanceBancadaObra
{
	private static void Postfix(CraftingStation __instance, ref float __result)
	{
		if (BancadaObra.Eh(((Component)__instance).GetComponent<Piece>()))
		{
			__result = 50f;
		}
	}
}
internal static class Anel
{
	private static GameObject go;

	private static CircleProjector cp;

	private static Material vermelho;

	private static float raioFeito = -1f;

	private static readonly MethodInfo mCriar = AccessTools.Method(typeof(CircleProjector), "CreateSegments", (Type[])null, (Type[])null);

	private static bool Criar()
	{
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: Expected O, but got Unknown
		//IL_009e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = (((Object)(object)ZNetScene.instance != (Object)null) ? ZNetScene.instance.GetPrefab("guard_stone") : null);
		PrivateArea val2 = (((Object)(object)val != (Object)null) ? val.GetComponent<PrivateArea>() : null);
		CircleProjector val3 = (((Object)(object)val2 != (Object)null) ? val2.m_areaMarker : null);
		if ((Object)(object)val3 == (Object)null || (Object)(object)val3.m_prefab == (Object)null)
		{
			return false;
		}
		go = new GameObject("Architect_Anel");
		go.SetActive(false);
		cp = go.AddComponent<CircleProjector>();
		cp.m_prefab = val3.m_prefab;
		cp.m_mask = val3.m_mask;
		cp.m_speed = val3.m_speed;
		cp.m_radius = 1f;
		cp.m_nrOfSegments = 8;
		go.SetActive(true);
		raioFeito = -1f;
		return true;
	}

	private static void Pintar()
	{
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Expected O, but got Unknown
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Expected O, but got Unknown
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		Color val3 = default(Color);
		foreach (Transform item in go.transform)
		{
			Transform val = item;
			Renderer[] componentsInChildren = ((Component)val).GetComponentsInChildren<Renderer>();
			foreach (Renderer val2 in componentsInChildren)
			{
				if ((Object)(object)vermelho == (Object)null)
				{
					vermelho = new Material(val2.sharedMaterial);
					((Color)(ref val3))..ctor(1f, 0.12f, 0.08f, 1f);
					if (vermelho.HasProperty("_Color"))
					{
						vermelho.color = val3;
					}
					if (vermelho.HasProperty("_EmissionColor"))
					{
						vermelho.EnableKeyword("_EMISSION");
						vermelho.SetColor("_EmissionColor", val3 * 1.5f);
					}
				}
				val2.sharedMaterial = vermelho;
			}
		}
	}

	internal static void Mostrar(Vector3 centro, float raio)
	{
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)go == (Object)null && !Criar())
		{
			return;
		}
		go.transform.position = centro;
		if (Mathf.Abs(raio - raioFeito) < 0.02f)
		{
			return;
		}
		raioFeito = raio;
		cp.m_radius = raio;
		cp.m_nrOfSegments = Mathf.Clamp(Mathf.RoundToInt((float)Math.PI * 2f * raio / 1.2f), 8, 220);
		if (mCriar != null)
		{
			try
			{
				mCriar.Invoke(cp, null);
			}
			catch
			{
			}
		}
		Pintar();
	}

	internal static void Esconder()
	{
		if ((Object)(object)go != (Object)null)
		{
			Object.Destroy((Object)(object)go);
		}
		go = null;
		cp = null;
		raioFeito = -1f;
	}
}
internal static class ArquivoCopia
{
	internal static string NomeSeguro(string nome)
	{
		string text = (nome ?? "").Trim();
		if (text.EndsWith(".blueprint", StringComparison.OrdinalIgnoreCase))
		{
			text = text.Substring(0, text.Length - 10);
		}
		StringBuilder stringBuilder = new StringBuilder();
		string text2 = text;
		foreach (char c in text2)
		{
			if (char.IsControl(c) || Array.IndexOf(Path.GetInvalidFileNameChars(), c) >= 0)
			{
				stringBuilder.Append('_');
			}
			else
			{
				stringBuilder.Append(c);
			}
		}
		text = stringBuilder.ToString().Trim(' ', '.');
		if (text.Length > 80)
		{
			text = text.Substring(0, 80).TrimEnd(' ', '.');
		}
		if (text.Length == 0)
		{
			throw new ArgumentException("Dê um nome para a blueprint.");
		}
		string text3 = text.Split('.')[0].ToUpperInvariant();
		switch (text3)
		{
		default:
			if (text3.Length != 4 || (!text3.StartsWith("COM") && !text3.StartsWith("LPT")) || text3[3] < '1' || text3[3] > '9')
			{
				break;
			}
			goto case "CON";
		case "CON":
		case "PRN":
		case "AUX":
		case "NUL":
			text = "Blueprint " + text;
			break;
		}
		return text;
	}

	internal static string Gravar(string pasta, string nome, IList<string> linhas)
	{
		string text = NomeSeguro(nome);
		Directory.CreateDirectory(pasta);
		string text2 = null;
		for (int i = 0; i < 1000; i++)
		{
			string text3 = text + ((i == 0) ? "" : (" (" + i.ToString(CultureInfo.InvariantCulture) + ")"));
			text2 = Path.Combine(pasta, text3 + ".blueprint");
			FileStream stream;
			try
			{
				stream = new FileStream(text2, FileMode.CreateNew, FileAccess.Write, FileShare.None);
			}
			catch (IOException)
			{
				if (File.Exists(text2))
				{
					continue;
				}
				throw;
			}
			try
			{
				using StreamWriter streamWriter = new StreamWriter(stream, new UTF8Encoding(encoderShouldEmitUTF8Identifier: false));
				streamWriter.WriteLine("#Name:" + text3);
				streamWriter.WriteLine("#Creator:Architect");
				streamWriter.WriteLine("#Description:Copia da construcao; sem inventarios ou estado de dano.");
				streamWriter.WriteLine("#Category:Architect");
				streamWriter.WriteLine("#Pieces");
				foreach (string linha in linhas)
				{
					streamWriter.WriteLine(linha);
				}
				return text2;
			}
			catch
			{
				try
				{
					File.Delete(text2);
				}
				catch
				{
				}
				throw;
			}
		}
		throw new IOException("Já existem muitas cópias com esse nome.");
	}
}
internal static class BancadaObra
{
	internal const float Alcance = 50f;

	internal const string Nome = "Bancada de obra";

	internal const string Chave = "architect_mesa_obra";

	private static GameObject raiz;

	private static GameObject modelo;

	internal static Piece Ativa;

	internal static bool MenuAberto;

	private static float proxima;

	private static Piece bancadaProxima;

	private static float buscaAte = -1f;

	internal static bool Permitida
	{
		get
		{
			if (Rede.Liberado())
			{
				if (!Rede.Montar)
				{
					return Rede.Desmontar;
				}
				return true;
			}
			return false;
		}
	}

	internal static Piece Base
	{
		get
		{
			GameObject val = (((Object)(object)ZNetScene.instance != (Object)null) ? ZNetScene.instance.GetPrefab("piece_workbench") : null);
			if (!((Object)(object)val != (Object)null))
			{
				return null;
			}
			return val.GetComponent<Piece>();
		}
	}

	internal static Piece PecaModelo
	{
		get
		{
			if (!((Object)(object)modelo != (Object)null))
			{
				return null;
			}
			return modelo.GetComponent<Piece>();
		}
	}

	internal static bool TemPorPerto
	{
		get
		{
			//IL_00b7: 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_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_00e6: Unknown result type (might be due to invalid IL or missing references)
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null || !Permitida)
			{
				return false;
			}
			if (Time.unscaledTime >= buscaAte)
			{
				buscaAte = Time.unscaledTime + 0.5f;
				bancadaProxima = null;
				float num = float.PositiveInfinity;
				if (AccessTools.Field(typeof(CraftingStation), "m_allStations").GetValue(null) is List<CraftingStation> list)
				{
					foreach (CraftingStation item in list)
					{
						if ((Object)(object)item == (Object)null)
						{
							continue;
						}
						Piece component = ((Component)item).GetComponent<Piece>();
						if (Eh(component) && component.GetCreator() == localPlayer.GetPlayerID() && PertoDoJogador(component) && PrivateArea.CheckAccess(((Component)component).transform.position, 0f, false, false))
						{
							Vector3 val = ((Component)component).transform.position - ((Component)localPlayer).transform.position;
							float sqrMagnitude = ((Vector3)(ref val)).sqrMagnitude;
							if (sqrMagnitude < num)
							{
								num = sqrMagnitude;
								bancadaProxima = component;
							}
						}
					}
				}
			}
			if ((Object)(object)bancadaProxima != (Object)null && Eh(bancadaProxima))
			{
				return PertoDoJogador(bancadaProxima);
			}
			return false;
		}
	}

	internal static float Raio
	{
		get
		{
			if ((Object)(object)Ativa != (Object)null)
			{
				((Component)Ativa).GetComponent<CraftingStation>();
			}
			return 50f;
		}
	}

	internal static bool Eh(Piece p)
	{
		ZNetView val = (((Object)(object)p != (Object)null) ? ((Component)p).GetComponent<ZNetView>() : null);
		if ((Object)(object)val != (Object)null && val.IsValid())
		{
			return val.GetZDO().GetBool("architect_mesa_obra", false);
		}
		return false;
	}

	internal static bool Modelo(Piece p)
	{
		if ((Object)(object)p != (Object)null)
		{
			return ((Object)((Component)p).gameObject).name == "Architect_BancadaObra_Modelo";
		}
		return false;
	}

	internal static GameObject Garantir(PieceTable tabela, Player pl)
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Expected O, but got Unknown
		//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d3: Expected O, but got Unknown
		if ((Object)(object)Base == (Object)null)
		{
			return null;
		}
		if ((Object)(object)modelo == (Object)null)
		{
			raiz = new GameObject("Architect_ModeloMesa");
			raiz.SetActive(false);
			Object.DontDestroyOnLoad((Object)(object)raiz);
			modelo = Object.Instantiate<GameObject>(((Component)Base).gameObject, raiz.transform, false);
			((Object)modelo).name = "Architect_BancadaObra_Modelo";
			Piece component = modelo.GetComponent<Piece>();
			component.m_name = "Bancada de obra";
			component.m_icon = IconesFerramentas.Bancada();
			component.m_description = "";
			component.m_category = (PieceCategory)100;
			component.m_craftingStation = null;
			ItemDrop component2 = ObjectDB.instance.GetItemPrefab("Wood").GetComponent<ItemDrop>();
			Requirement[] array = (Requirement[])(object)new Requirement[1];
			Requirement val = new Requirement();
			val.m_resItem = component2;
			val.m_amount = 10;
			val.m_recover = true;
			array[0] = val;
			component.m_resources = array;
			ModeloMesaObra.Aplicar(component);
		}
		if (!tabela.m_pieces.Contains(modelo))
		{
			tabela.m_pieces.Insert(1, modelo);
			if (AccessTools.Field(typeof(Player), "m_knownRecipes").GetValue(pl) is HashSet<string> hashSet)
			{
				hashSet.Add("Bancada de obra");
			}
			AccessTools.Method(typeof(Player), "UpdateAvailablePiecesList", (Type[])null, (Type[])null).Invoke(pl, null);
		}
		return modelo;
	}

	internal static void AtualizarProximidade()
	{
		buscaAte = -1f;
		bancadaProxima = null;
	}

	private static bool PertoDoJogador(Piece p)
	{
		//IL_0030: 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_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		Player localPlayer = Player.m_localPlayer;
		if ((Object)(object)localPlayer == (Object)null || (Object)(object)p == (Object)null)
		{
			return false;
		}
		CraftingStation component = ((Component)p).GetComponent<CraftingStation>();
		if ((Object)(object)component != (Object)null)
		{
			return RegraAlcanceMesa.Contem(((Component)p).transform.position.x, ((Component)p).transform.position.z, ((Component)localPlayer).transform.position.x, ((Component)localPlayer).transform.position.z, 50f);
		}
		return false;
	}

	internal static bool Disponivel()
	{
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		Player localPlayer = Player.m_localPlayer;
		if (Permitida && (Object)(object)localPlayer != (Object)null && (Object)(object)Ativa != (Object)null && Eh(Ativa) && Ativa.GetCreator() == localPlayer.GetPlayerID())
		{
			return PrivateArea.CheckAccess(((Component)Ativa).transform.position, 0f, false, false);
		}
		return false;
	}

	internal static bool Contem(Vector3 p)
	{
		//IL_0013: 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)
		if (!Disponivel())
		{
			return false;
		}
		return RegraAlcanceMesa.Contem(((Component)Ativa).transform.position.x, ((Component)Ativa).transform.position.z, p.x, p.z, Raio);
	}

	internal static bool Contem(Bounds b)
	{
		//IL_0013: 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_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: 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)
		if (!Disponivel())
		{
			return false;
		}
		Vector3 position = ((Component)Ativa).transform.position;
		return RegraAlcanceMesa.Retangulo(position.x, position.z, ((Bounds)(ref b)).min.x, ((Bounds)(ref b)).min.z, ((Bounds)(ref b)).max.x, ((Bounds)(ref b)).max.z, Raio);
	}

	internal static bool Contem(Planta p)
	{
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: 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_0074: Unknown result type (might be due to invalid IL or missing references)
		if (!Disponivel() || p == null)
		{
			return false;
		}
		Vector3 position = ((Component)Ativa).transform.position;
		float raio = Raio;
		foreach (Peca peca in p.Pecas)
		{
			Bounds mundo = peca.Mundo;
			if (!RegraAlcanceMesa.Retangulo(position.x, position.z, ((Bounds)(ref mundo)).min.x, ((Bounds)(ref mundo)).min.z, ((Bounds)(ref mundo)).max.x, ((Bounds)(ref mundo)).max.z, raio))
			{
				return false;
			}
		}
		return true;
	}

	internal static bool NoRaio(Vector3 p)
	{
		//IL_0019: 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 ((Object)(object)Ativa == (Object)null)
		{
			return false;
		}
		Vector3 position = ((Component)Ativa).transform.position;
		return RegraAlcanceMesa.Contem(position.x, position.z, p.x, p.z, Raio);
	}

	internal static bool PodeVincular()
	{
		if (Disponivel())
		{
			return ((Component)Ativa).GetComponent<ZNetView>().GetZDO().GetString("architect_pedido_tipo", "") == "";
		}
		return false;
	}

	internal static bool PrepararSelecao()
	{
		//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0103: 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)
		if (PodeVincular() && PertoDoJogador(Ativa))
		{
			return true;
		}
		Player localPlayer = Player.m_localPlayer;
		if ((Object)(object)localPlayer == (Object)null || !Permitida)
		{
			return false;
		}
		List<CraftingStation> list = AccessTools.Field(typeof(CraftingStation), "m_allStations").GetValue(null) as List<CraftingStation>;
		Piece val = null;
		float num = float.PositiveInfinity;
		if (list != null)
		{
			foreach (CraftingStation item in list)
			{
				if ((Object)(object)item == (Object)null)
				{
					continue;
				}
				Piece component = ((Component)item).GetComponent<Piece>();
				if (Eh(component) && component.GetCreator() == localPlayer.GetPlayerID() && PertoDoJogador(component) && !(((Component)component).GetComponent<ZNetView>().GetZDO().GetString("architect_pedido_tipo", "") != "") && PrivateArea.CheckAccess(((Component)component).transform.position, 0f, false, false))
				{
					Vector3 val2 = ((Component)component).transform.position - ((Component)localPlayer).transform.position;
					float sqrMagnitude = ((Vector3)(ref val2)).sqrMagnitude;
					if (sqrMagnitude < num)
					{
						num = sqrMagnitude;
						val = component;
					}
				}
			}
		}
		if ((Object)(object)val != (Object)null)
		{
			Ativa = val;
			return true;
		}
		if (!Disponivel())
		{
			Plugin.Avisar("Coloque uma bancada de obra para vincular a seleção.");
		}
		return false;
	}

	internal static void Interagir(Piece p)
	{
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		Player localPlayer = Player.m_localPlayer;
		if ((Object)(object)localPlayer == (Object)null || (Object)(object)p == (Object)null || p.GetCreator() != localPlayer.GetPlayerID() || !Permitida || !PrivateArea.CheckAccess(((Component)p).transform.position, 0f, false, false))
		{
			return;
		}
		string text = ((Component)p).GetComponent<ZNetView>().GetZDO().GetString("architect_pedido_tipo", "");
		if (!(text == "") && !Obra.Ocupada && !Desmontar.Ocupada)
		{
			Ativa = p;
			if (text == "montar")
			{
				Obra.InteragirMesa();
			}
			else if (text == "desmontar")
			{
				BancadaPedido.Interagir(p);
			}
		}
	}

	internal static string Texto(Piece p)
	{
		//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)
		if ((Object)(object)p == (Object)null)
		{
			return "Bancada de obra";
		}
		ZNetView component = ((Component)p).GetComponent<ZNetView>();
		string text = (((Object)(object)component != (Object)null && component.IsValid()) ? component.GetZDO().GetString("architect_pedido_tipo", "") : "");
		if (text == "montar")
		{
			string text2 = component.GetZDO().GetString("architect_pedido_nome", "");
			if (text2.Length == 0 && Obra.PedidoNoPonto(component.GetZDO().GetVec3("architect_pedido_centro", Vector3.zero)))
			{
				text2 = Obra.NomePlanta();
			}
			string text3 = "Obra selecionada: " + text2.Replace("\n", " ").Replace("\r", " ") + " — " + (PainelObra.Pronta ? "Pronta" : "Em preparação");
			if (!PainelObra.Pronta)
			{
				return text3;
			}
			return text3 + "\n[<color=yellow><b>$KEY_Use</b></color>] Construir";
		}
		string text4 = ((text == "desmontar") ? "Conferir desmontagem" : null);
		if (text4 != null)
		{
			return "Bancada de obra\n[<color=yellow><b>$KEY_Use</b></color>] " + text4;
		}
		return "Bancada de obra";
	}

	internal static void OnGUI()
	{
	}

	internal static void FecharMenu()
	{
		MenuAberto = false;
	}

	internal static void Atualizar()
	{
		if (Time.unscaledTime < proxima || (Object)(object)Player.m_localPlayer == (Object)null)
		{
			return;
		}
		proxima = Time.unscaledTime + 2f;
		if (!(AccessTools.Field(typeof(CraftingStation), "m_allStations").GetValue(null) is List<CraftingStation> list))
		{
			return;
		}
		foreach (CraftingStation item in list)
		{
			if ((Object)(object)item == (Object)null)
			{
				continue;
			}
			Piece component = ((Component)item).GetComponent<Piece>();
			if (Eh(component))
			{
				ModeloMesaObra.Aplicar(component);
				ZNetView component2 = ((Component)component).GetComponent<ZNetView>();
				if (!CopiarBlueprint.Ativo && component.GetCreator() == Player.m_localPlayer.GetPlayerID() && component2.IsOwner() && component2.GetZDO().GetString("architect_pedido_tipo", "") == "copiar")
				{
					component2.GetZDO().Set("architect_pedido_tipo", "");
				}
			}
		}
	}

	internal static void AoRemover(Piece p)
	{
		AtualizarProximidade();
		if (!((Object)(object)p == (Object)null) && Eh(p) && !((Object)(object)p != (Object)(object)Ativa))
		{
			Ativa = null;
			FecharMenu();
			Obra.CancelarPelaMesa();
			Desmontar.CancelarPedido();
			CopiarBlueprint.Fechar();
			Ferramentas.CancelarSelecao();
		}
	}
}
[HarmonyPatch(typeof(Player), "PlacePiece")]
internal static class ColocarMesaManual
{
	[HarmonyPriority(800)]
	private static void Prefix(Player __instance, ref Piece piece, Vector3 pos, ref HashSet<ZDOID> __state)
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)__instance != (Object)(object)Player.m_localPlayer || !BancadaObra.Modelo(piece))
		{
			return;
		}
		__state = new HashSet<ZDOID>();
		List<Piece> list = new List<Piece>();
		Piece.GetAllPiecesInRadius(pos, 0.3f, list);
		foreach (Piece item in list)
		{
			ZNetView component = ((Component)item).GetComponent<ZNetView>();
			if ((Object)(object)component != (Object)null && component.IsValid())
			{
				__state.Add(component.GetZDO().m_uid);
			}
		}
		piece = BancadaObra.Base;
	}

	private static void Postfix(Player __instance, Vector3 pos, HashSet<ZDOID> __state)
	{
		//IL_000a: 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)
		if (__state == null)
		{
			return;
		}
		List<Piece> list = new List<Piece>();
		Piece.GetAllPiecesInRadius(pos, 0.3f, list);
		foreach (Piece item in list)
		{
			ZNetView component = ((Component)item).GetComponent<ZNetView>();
			if (!((Object)(object)component == (Object)null) && component.IsValid() && !__state.Contains(component.GetZDO().m_uid) && item.GetCreator() == __instance.GetPlayerID() && !(Utils.GetPrefabName(((Component)item).gameObject) != "piece_workbench"))
			{
				component.GetZDO().Set("architect_mesa_obra", true);
				component.GetZDO().Set("architect_obra", true);
				ModeloMesaObra.Aplicar(item);
				BancadaObra.Ativa = item;
				BancadaObra.AtualizarProximidade();
				break;
			}
		}
	}
}
internal static class BancadaPedido
{
	private const string Tipo = "architect_pedido_tipo";

	private const string Ponto = "architect_pedido_centro";

	private const string Raio = "architect_pedido_raio";

	private static Piece montagem;

	private static Piece desmonte;

	internal static bool TemDesmonte => (Object)(object)desmonte != (Object)null;

	internal static bool RetomarDesmonte()
	{
		//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)
		Piece ativa = BancadaObra.Ativa;
		if ((Object)(object)ativa == (Object)null || !EhDesmonte(ativa))
		{
			return false;
		}
		desmonte = ativa;
		ZNetView component = ((Component)ativa).GetComponent<ZNetView>();
		Desmontar.TravarPedido(component.GetZDO().GetVec3("architect_pedido_centro", ((Component)ativa).transform.position), component.GetZDO().GetFloat("architect_pedido_raio", 8f));
		return true;
	}

	internal static void VincularDesmonte(Piece p, Vector3 centro, float raio)
	{
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		desmonte = p;
		ZNetView component = ((Component)p).GetComponent<ZNetView>();
		component.ClaimOwnership();
		component.GetZDO().Set("architect_pedido_tipo", "desmontar");
		component.GetZDO().Set("architect_pedido_centro", centro);
		component.GetZDO().Set("architect_pedido_raio", raio);
		PinsDaObra.Registrar(p);
	}

	internal static bool DesmonteEm(Vector3 centro, float raio)
	{
		//IL_0036: 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_0041: 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)
		if ((Object)(object)desmonte == (Object)null)
		{
			return false;
		}
		ZNetView component = ((Component)desmonte).GetComponent<ZNetView>();
		if ((Object)(object)component != (Object)null && component.IsValid())
		{
			Vector3 val = component.GetZDO().GetVec3("architect_pedido_centro", Vector3.zero) - centro;
			if (((Vector3)(ref val)).sqrMagnitude < 0.01f)
			{
				return Mathf.Abs(component.GetZDO().GetFloat("architect_pedido_raio", 0f) - raio) < 0.01f;
			}
		}
		return false;
	}

	internal static bool EhDesmonte(Piece p)
	{
		ZNetView val = (((Object)(object)p != (Object)null) ? ((Component)p).GetComponent<ZNetView>() : null);
		if ((Object)(object)val != (Object)null && val.IsValid())
		{
			return val.GetZDO().GetString("architect_pedido_tipo", "") == "desmontar";
		}
		return false;
	}

	internal static void VincularMontagem(Piece p, Vector3 centro)
	{
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		montagem = p;
		if (BancadaObra.Eh(p))
		{
			BancadaObra.Ativa = p;
		}
		ZNetView component = ((Component)p).GetComponent<ZNetView>();
		if ((Object)(object)component != (Object)null && component.IsValid())
		{
			component.ClaimOwnership();
			component.GetZDO().Set("architect_pedido_tipo", "montar");
			component.GetZDO().Set("architect_pedido_nome", Obra.NomePlanta());
			component.GetZDO().Set("architect_pedido_centro", centro);
			PinsDaObra.Registrar(p);
		}
	}

	internal static bool RetomarMontagem(Vector3 centro)
	{
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_0086: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: 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_00a0: 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)
		Player localPlayer = Player.m_localPlayer;
		if ((Object)(object)localPlayer == (Object)null)
		{
			return false;
		}
		List<Piece> list = new List<Piece>();
		Piece.GetAllPiecesInRadius(centro, 80f, list);
		Piece val = null;
		foreach (Piece item in list)
		{
			if ((Object)(object)item == (Object)null || item.GetCreator() != localPlayer.GetPlayerID() || !BancadaObra.Eh(item) || !PostoDaObra.MesaTemporaria(item) || EhDesmonte(item) || !MontagemAtual(item))
			{
				continue;
			}
			if (!((Object)(object)val == (Object)null))
			{
				Vector3 val2 = ((Component)item).transform.position - centro;
				float sqrMagnitude = ((Vector3)(ref val2)).sqrMagnitude;
				Vector3 val3 = ((Component)val).transform.position - centro;
				if (!(sqrMagnitude < ((Vector3)(ref val3)).sqrMagnitude))
				{
					continue;
				}
			}
			val = item;
		}
		if ((Object)(object)val != (Object)null)
		{
			VincularMontagem(val, centro);
			return true;
		}
		return false;
	}

	internal static void ConcluirDesmonte()
	{
		Piece val = desmonte;
		desmonte = null;
		if ((Object)(object)val == (Object)null)
		{
			return;
		}
		PinsDaObra.Remover(val);
		ZNetView component = ((Component)val).GetComponent<ZNetView>();
		if ((Object)(object)component == (Object)null || !component.IsValid())
		{
			return;
		}
		component.ClaimOwnership();
		component.GetZDO().Set("architect_pedido_tipo", "");
		if (BancadaObra.Eh(val))
		{
			PinsDaObra.Registrar(val);
			return;
		}
		WearNTear component2 = ((Component)val).GetComponent<WearNTear>();
		if ((Object)(object)component2 != (Object)null)
		{
			component2.Remove(false);
		}
	}

	internal static void CancelarVinculoDesmonte()
	{
		Piece val = (((Object)(object)desmonte != (Object)null) ? desmonte : BancadaObra.Ativa);
		desmonte = null;
		if ((Object)(object)val == (Object)null)
		{
			return;
		}
		ZNetView component = ((Component)val).GetComponent<ZNetView>();
		if (!((Object)(object)component == (Object)null) && component.IsValid() && !(component.GetZDO().GetString("architect_pedido_tipo", "") != "desmontar"))
		{
			component.ClaimOwnership();
			component.GetZDO().Set("architect_pedido_tipo", "");
			PinsDaObra.Remover(val);
			if (BancadaObra.Eh(val))
			{
				PinsDaObra.Registrar(val);
			}
		}
	}

	internal static void CancelarVinculoMontagem()
	{
		Piece val = (((Object)(object)montagem != (Object)null) ? montagem : BancadaObra.Ativa);
		montagem = null;
		if ((Object)(object)val == (Object)null)
		{
			return;
		}
		ZNetView component = ((Component)val).GetComponent<ZNetView>();
		if (!((Object)(object)component == (Object)null) && component.IsValid() && !(component.GetZDO().GetString("architect_pedido_tipo", "") != "montar"))
		{
			component.ClaimOwnership();
			component.GetZDO().Set("architect_pedido_tipo", "");
			component.GetZDO().Set("architect_pedido_nome", "");
			PinsDaObra.Remover(val);
			if (BancadaObra.Eh(val))
			{
				PinsDaObra.Registrar(val);
			}
		}
	}

	internal static void Interagir(Piece p)
	{
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		Player localPlayer = Player.m_localPlayer;
		ZNetView val = (((Object)(object)p != (Object)null) ? ((Component)p).GetComponent<ZNetView>() : null);
		if (!((Object)(object)localPlayer == (Object)null) && p.GetCreator() == localPlayer.GetPlayerID() && !((Object)(object)val == (Object)null) && val.IsValid() && PrivateArea.CheckAccess(((Component)p).transform.position, 0f, false, false))
		{
			desmonte = p;
			Desmontar.AbrirPedido(val.GetZDO().GetVec3("architect_pedido_centro", ((Component)p).transform.position), val.GetZDO().GetFloat("architect_pedido_raio", 8f));
		}
	}

	private static bool MontagemAtual(Piece p)
	{
		//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)
		ZNetView component = ((Component)p).GetComponent<ZNetView>();
		if ((Object)(object)component != (Object)null && component.IsValid() && component.GetZDO().GetString("architect_pedido_tipo", "") == "montar")
		{
			return Obra.PedidoNoPonto(component.GetZDO().GetVec3("architect_pedido_centro", Vector3.zero));
		}
		return false;
	}

	internal static void Retirada(Piece p)
	{
		BancadaObra.AoRemover(p);
		PinsDaObra.Remover(p);
		if ((Object)(object)p == (Object)null || PostoDaObra.Retirando(p))
		{
			return;
		}
		Player localPlayer = Player.m_localPlayer;
		if (!((Object)(object)localPlayer == (Object)null) && p.GetCreator() == localPlayer.GetPlayerID())
		{
			if (EhDesmonte(p) && (Object)(object)p == (Object)(object)desmonte)
			{
				desmonte = null;
				Desmontar.CancelarPedido();
				Ferramentas.CancelarSelecao();
			}
			else if (MontagemAtual(p) || ((Object)(object)p == (Object)(object)montagem && Obra.Fase == Fase.Fixado))
			{
				montagem = null;
				Obra.CancelarPelaMesa();
			}
		}
	}
}
[HarmonyPatch(typeof(WearNTear), "Destroy")]
internal static class CancelarPedidoNaDemolicao
{
	private static void Prefix(WearNTear __instance)
	{
		ZNetView component = ((Component)__instance).GetComponent<ZNetView>();
		if ((Object)(object)component != (Object)null && component.IsValid() && component.IsOwner())
		{
			BancadaPedido.Retirada(((Component)__instance).GetComponent<Piece>());
		}
	}
}
internal static class BancadasDesmonte
{
	internal static List<string> Ausentes(IEnumerable<Piece> pecas, Func<string, Vector3, bool> alcance)
	{
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		Dictionary<string, bool> dictionary = new Dictionary<string, bool>();
		foreach (Piece peca in pecas)
		{
			if (!((Object)(object)peca == (Object)null) && !((Object)(object)peca.m_craftingStation == (Object)null))
			{
				string name = peca.m_craftingStation.m_name;
				dictionary.TryGetValue(name, out var value);
				if (!value)
				{
					dictionary[name] = alcance(name, ((Component)peca).transform.position);
				}
			}
		}
		List<string> list = new List<string>();
		foreach (KeyValuePair<string, bool> item in dictionary)
		{
			if (!item.Value)
			{
				list.Add(item.Key);
			}
		}
		list.Sort(StringComparer.Ordinal);
		return list;
	}

	internal static string Mensagem(IEnumerable<Piece> pecas, Func<string, string> nome)
	{
		List<string> chaves = Ausentes(pecas, (string chave, Vector3 pos) => (Object)(object)CraftingStation.HaveBuildStationInRange(chave, pos) != (Object)null);
		return RegraMensagemEstacoes.Criar("desconstruir", chaves, nome);
	}
}
internal static class BauDaObra
{
	internal const string Chave = "architect_obra";

	internal const int Largura = 8;

	internal const int Altura = 7;

	internal const string Nome = "Caixote da obra";

	private const string Base = "piece_chest_wood";

	internal const string Prefab = "architect_bau";

	internal const string Comum = "architect_bau_comum";

	private const string Vanilla = "piece_chest_wood";

	private static GameObject modelo;

	private static GameObject suporte;

	private static readonly FieldInfo fNomeados = AccessTools.Field(typeof(ZNetScene), "m_namedPrefabs");

	private static readonly FieldInfo fW = AccessTools.Field(typeof(Inventory), "m_width");

	private static readonly FieldInfo fH = AccessTools.Field(typeof(Inventory), "m_height");

	private static readonly FieldInfo fNome = AccessTools.Field(typeof(Inventory), "m_name");

	private static float proximoAjuste;

	internal static Piece PecaComum()
	{
		GameObject val = (((Object)(object)ZNetScene.instance != (Object)null) ? ZNetScene.instance.GetPrefab("piece_chest_wood") : null);
		if (!((Object)(object)val != (Object)null))
		{
			return null;
		}
		return val.GetComponent<Piece>();
	}

	internal static bool Caixote(Container c)
	{
		ZNetView val = (((Object)(object)c != (Object)null) ? Rede(c) : null);
		if ((Object)(object)val == (Object)null || val.GetZDO() == null)
		{
			return false;
		}
		if (Utils.GetPrefabName(((Component)val).gameObject) == "architect_bau")
		{
			return true;
		}
		if (val.GetZDO().GetBool("architect_obra", false))
		{
			return !val.GetZDO().GetBool("architect_bau_comum", false);
		}
		return false;
	}

	internal static GameObject Modelo()
	{
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Expected O, but got Unknown
		if ((Object)(object)modelo == (Object)null)
		{
			GameObject val = (((Object)(object)ZNetScene.instance != (Object)null) ? ZNetScene.instance.GetPrefab("piece_chest_wood") : null);
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			suporte = new GameObject("Architect_Modelos");
			suporte.SetActive(false);
			Object.DontDestroyOnLoad((Object)(object)suporte);
			modelo = Object.Instantiate<GameObject>(val, suporte.transform, false);
			((Object)modelo).name = "architect_bau";
			Container componentInChildren = modelo.GetComponentInChildren<Container>();
			if ((Object)(object)componentInChildren != (Object)null)
			{
				componentInChildren.m_width = 8;
				componentInChildren.m_height = 7;
				componentInChildren.m_name = "Caixote da obra";
			}
			Piece component = modelo.GetComponent<Piece>();
			if ((Object)(object)component != (Object)null)
			{
				component.m_name = "Caixote da obra";
				component.m_description = "Caixote do Architect: 56 espaços, respeitando as pilhas normais do jogo.";
			}
		}
		Registrar();
		return modelo;
	}

	internal static void Registrar()
	{
		ZNetScene instance = ZNetScene.instance;
		if ((Object)(object)instance == (Object)null || (Object)(object)modelo == (Object)null)
		{
			return;
		}
		IDictionary dictionary = ((fNomeados != null) ? (fNomeados.GetValue(instance) as IDictionary) : null);
		int stableHashCode = StringExtensionMethods.GetStableHashCode("architect_bau");
		if (dictionary == null || !dictionary.Contains(stableHashCode) || !((Object)/*isinst with value type is only supported in some contexts*/ == (Object)(object)modelo))
		{
			if (!instance.m_prefabs.Contains(modelo))
			{
				instance.m_prefabs.Add(modelo);
			}
			if (dictionary != null)
			{
				dictionary[stableHashCode] = modelo;
			}
		}
	}

	internal static void Esquecer()
	{
		modelo = null;
		suporte = null;
	}

	internal static ZNetView Rede(Container c)
	{
		if (!((Object)(object)c.m_rootObjectOverride != (Object)null))
		{
			return ((Component)c).GetComponent<ZNetView>();
		}
		return ((Component)c.m_rootObjectOverride).GetComponent<ZNetView>();
	}

	internal static bool Eh(Container c)
	{
		if ((Object)(object)c == (Object)null)
		{
			return false;
		}
		ZNetView val = Rede(c);
		if ((Object)(object)val == (Object)null || !val.IsValid())
		{
			return false;
		}
		if (!(Utils.GetPrefabName(((Component)val).gameObject) == "architect_bau"))
		{
			return val.GetZDO().GetBool("architect_obra", false);
		}
		return true;
	}

	internal static void Compactar(Container c)
	{
		ZNetView val = (((Object)(object)c != (Object)null) ? Rede(c) : null);
		Inventory val2 = (((Object)(object)c != (Object)null) ? c.GetInventory() : null);
		if ((Object)(object)val == (Object)null || !val.IsValid() || !val.IsOwner() || val2 == null || c.IsInUse())
		{
			return;
		}
		bool flag = false;
		foreach (ItemData item in new List<ItemData>(val2.GetAllItems()))
		{
			int num = Mathf.Max(1, item.m_shared.m_maxStackSize);
			while (item.m_stack > num && val2.GetEmptySlots() > 0)
			{
				ItemData val3 = item.Clone();
				int num2 = (val3.m_stack = Mathf.Min(num, item.m_stack - num));
				if (!val2.AddItem(val3))
				{
					break;
				}
				item.m_stack -= num2;
				flag = true;
			}
		}
		if (flag)
		{
			PilhaPegarTudo.Mudou(val2);
		}
		if (TemPilhaLegada(c) && (Object)(object)Player.m_localPlayer != (Object)null)
		{
			MigrarExcesso(c);
		}
	}

	private static void MigrarExcesso(Container origem)
	{
		//IL_0037: 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_0179: Unknown result type (might be due to invalid IL or missing references)
		//IL_022c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0234: Unknown result type (might be due to invalid IL or missing references)
		//IL_0246: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a6: 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_01c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
		Player localPlayer = Player.m_localPlayer;
		Piece componentInParent = ((Component)origem).GetComponentInParent<Piece>();
		if ((Object)(object)componentInParent == (Object)null || componentInParent.GetCreator() != localPlayer.GetPlayerID())
		{
			return;
		}
		List<Container> list = new List<Container>();
		List<Piece> list2 = new List<Piece>();
		Piece.GetAllPiecesInRadius(((Component)origem).transform.position, 12f, list2);
		foreach (Piece item in list2)
		{
			Container val = (((Object)(object)item != (Object)null) ? ((Component)item).GetComponentInChildren<Container>() : null);
			if ((Object)(object)val != (Object)null && (Object)(object)val != (Object)(object)origem && Eh(val) && item.GetCreator() == localPlayer.GetPlayerID() && !val.IsInUse() && Rede(val).IsOwner())
			{
				list.Add(val);
			}
		}
		Inventory inventory = origem.GetInventory();
		int num = 0;
		foreach (ItemData item2 in new List<ItemData>(inventory.GetAllItems()))
		{
			int num2 = Mathf.Max(1, item2.m_shared.m_maxStackSize);
			while (item2.m_stack > num2)
			{
				Container val2 = null;
				foreach (Container item3 in list)
				{
					if (item3.GetInventory().GetEmptySlots() > 0)
					{
						val2 = item3;
						break;
					}
				}
				if ((Object)(object)val2 == (Object)null)
				{
					if (num >= 6)
					{
						return;
					}
					Vector3 val3 = Vector3.zero;
					bool flag = false;
					for (float num3 = 2f; num3 <= 12f; num3 += 1.5f)
					{
						if (flag)
						{
							break;
						}
						for (int i = 0; i < 24; i++)
						{
							if (flag)
							{
								break;
							}
							float num4 = (float)i * (float)Math.PI / 12f;
							Vector3 ponto = ((Component)origem).transform.position + new Vector3(Mathf.Cos(num4) * num3, 0f, Mathf.Sin(num4) * num3);
							if (PostoDaObra.Bom(PecaComum(), ponto, ((Component)origem).transform.rotation, null, out var nivel))
							{
								val3 = nivel;
								flag = true;
							}
						}
					}
					if (!flag)
					{
						return;
					}
					localPlayer.PlacePiece(PecaComum(), val3, ((Component)origem).transform.rotation, false, false);
					list2.Clear();
					Piece.GetAllPiecesInRadius(val3, 0.2f, list2);
					foreach (Piece item4 in list2)
					{
						if ((Object)(object)item4 != (Object)null && Utils.GetPrefabName(((Component)item4).gameObject) == "piece_chest_wood" && item4.GetCreator() == localPlayer.GetPlayerID() && ((Component)item4).GetComponentInChildren<Container>().GetInventory().NrOfItems() == 0)
						{
							val2 = ((Component)item4).GetComponentInChildren<Container>();
							break;
						}
					}
					if ((Object)(object)val2 == (Object)null)
					{
						return;
					}
					Marcar(val2);
					list.Add(val2);
					num++;
					Plugin.Log.LogInfo((object)"recipiente de migracao legado criado; sem alterar quantidade de recursos");
				}
				ItemData val4 = item2.Clone();
				int num5 = (val4.m_stack = Mathf.Min(num2, item2.m_stack - num2));
				if (!val2.GetInventory().AddItem(val4))
				{
					return;
				}
				item2.m_stack -= num5;
				PilhaPegarTudo.Mudou(inventory);
				PilhaPegarTudo.Mudou(val2.GetInventory());
			}
		}
	}

	internal static bool TemPilhaLegada(Container c)
	{
		if ((Object)(object)c == (Object)null || c.GetInventory() == null)
		{
			return false;
		}
		foreach (ItemData allItem in c.GetInventory().GetAllItems())
		{
			if (allItem.m_stack > Mathf.Max(1, allItem.m_shared.m_maxStackSize))
			{
				return true;
			}
		}
		return false;
	}

	internal static void Marcar(Container c)
	{
		ZNetView val = (((Object)(object)c != (Object)null) ? Rede(c) : null);
		if (!((Object)(object)val == (Object)null) && val.IsValid())
		{
			val.ClaimOwnership();
			bool flag = Utils.GetPrefabName(((Component)val).gameObject) != "architect_bau" && !val.GetZDO().GetBool("architect_obra", false);
			val.GetZDO().Set("architect_obra", true);
			if (flag)
			{
				val.GetZDO().Set("architect_bau_comum", true);
			}
			if (Caixote(c))
			{
				Ampliar(c);
			}
			PostoDaObra.Sincronizar(c);
		}
	}

	internal static void AjustarPerto(Vector3 p)
	{
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_012b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0137: Unknown result type (might be due to invalid IL or missing references)
		if (Time.time < proximoAjuste)
		{
			return;
		}
		proximoAjuste = Time.time + 2f;
		List<Piece> list = new List<Piece>();
		Piece.GetAllPiecesInRadius(p, 40f, list);
		List<Piece> list2 = new List<Piece>();
		foreach (Piece item in list)
		{
			if (PostoDaObra.MesaTemporaria(item))
			{
				list2.Add(item);
				if (!BancadaObra.Eh(item))
				{
					PostoDaObra.Assentar(item);
				}
			}
		}
		long num = (((Object)(object)Player.m_localPlayer != (Object)null) ? Player.m_localPlayer.GetPlayerID() : 0);
		if (list2.Count > 0 && num != 0)
		{
			foreach (Piece item2 in list)
			{
				if ((Object)(object)item2 == (Object)null || item2.GetCreator() != num || (Object)(object)((Component)item2).GetComponentInParent<Rigidbody>() != (Object)null)
				{
					continue;
				}
				Container componentInChildren = ((Component)item2).GetComponentInChildren<Container>();
				if ((Object)(object)componentInChildren == (Object)null || Eh(componentInChildren) || componentInChildren.IsInUse())
				{
					continue;
				}
				foreach (Piece item3 in list2)
				{
					if (Vector3.Distance(((Component)item3).transform.position, ((Component)item2).transform.position) <= 8f)
					{
						Marcar(componentInChildren);
						break;
					}
				}
			}
		}
		foreach (Piece item4 in list)
		{
			if ((Object)(object)item4 != (Object)null && Marcado(item4))
			{
				MobiliaDaObra.MesaEm(item4);
			}
			Container val = (((Object)(object)item4 != (Object)null) ? ((Component)item4).GetComponentInChildren<Container>() : null);
			if (!((Object)(object)val == (Object)null) && Eh(val) && !val.IsInUse())
			{
				PostoDaObra.Sincronizar(val);
				MobiliaDaObra.BauEm(val);
				MobiliaDaObra.BauNormal(val);
				Inventory inventory = val.GetInventory();
				if (Caixote(val) && inventory != null && (inventory.GetWidth() != 8 || inventory.GetHeight() != 7 || val.m_name != "Caixote da obra"))
				{
					Ampliar(val);
				}
				Compactar(val);
			}
		}
	}

	private static void Ampliar(Container c)
	{
		c.m_width = 8;
		c.m_height = 7;
		c.m_name = "Caixote da obra";
		Inventory inventory = c.GetInventory();
		if (inventory != null)
		{
			if (fW != null)
			{
				fW.SetValue(inventory, 8);
			}
			if (fH != null)
			{
				fH.SetValue(inventory, 7);
			}
			if (fNome != null)
			{
				fNome.SetValue(inventory, "Caixote da obra");
			}
			Arrumar(c);
		}
	}

	internal static void Arrumar(Container c)
	{
		//IL_0076: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		Inventory val = (((Object)(object)c != (Object)null) ? c.GetInventory() : null);
		if (val == null)
		{
			return;
		}
		bool flag = false;
		foreach (ItemData allItem in val.GetAllItems())
		{
			if (allItem.m_gridPos.x < val.GetWidth() && allItem.m_gridPos.y < val.GetHeight())
			{
				continue;
			}
			bool flag2 = false;
			for (int i = 0; i < val.GetHeight(); i++)
			{
				if (flag2)
				{
					break;
				}
				for (int j = 0; j < val.GetWidth(); j++)
				{
					if (flag2)
					{
						break;
					}
					if (val.GetItemAt(j, i) == null)
					{
						allItem.m_gridPos = new Vector2i(j, i);
						flag2 = true;
					}
				}
			}
			if (flag2)
			{
				flag = true;
			}
		}
		ZNetView val2 = Rede(c);
		if (flag && (Object)(object)val2 != (Object)null && val2.IsValid() && val2.IsOwner())
		{
			PilhaPegarTudo.Mudou(val);
		}
	}

	internal static Container Perto(Vector3 p, float raio)
	{
		//IL_0015: 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_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)Player.m_localPlayer == (Object)null)
		{
			return null;
		}
		List<Piece> list = new List<Piece>();
		Piece.GetAllPiecesInRadius(p, raio, list);
		Container result = null;
		float num = float.MaxValue;
		foreach (Piece item in list)
		{
			Container val = (((Object)(object)item != (Object)null) ? ((Component)item).GetComponentInChildren<Container>() : null);
			if (Eh(val) && item.GetCreator() == Player.m_localPlayer.GetPlayerID() && PrivateArea.CheckAccess(((Component)item).transform.position, 0f, false, false))
			{
				Vector3 val2 = ((Component)item).transform.position - p;
				float sqrMagnitude = ((Vector3)(ref val2)).sqrMagnitude;
				if (sqrMagnitude < num)
				{
					num = sqrMagnitude;
					result = val;
				}
			}
		}
		return result;
	}

	private static bool Marcado(Piece p)
	{
		ZNetView val = (((Object)(object)p != (Object)null) ? ((Component)p).GetComponent<ZNetView>() : null);
		if ((Object)(object)val != (Object)null && val.IsValid())
		{
			return val.GetZDO().GetBool("architect_obra", false);
		}
		return false;
	}

	internal static bool DaObra(CraftingStation st)
	{
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)st == (Object)null)
		{
			return false;
		}
		Piece componentInParent = ((Component)st).GetComponentInParent<Piece>();
		if (Marcado(componentInParent))
		{
			return true;
		}
		if ((Object)(object)componentInParent != (Object)null && st.m_name == "$piece_workbench" && (Object)(object)Player.m_localPlayer != (Object)null && componentInParent.GetCreator() == Player.m_localPlayer.GetPlayerID())
		{
			return (Object)(object)Perto(((Component)st).transform.position, 6f) != (Object)null;
		}
		return false;
	}

	private static bool PodePagar(Player pl, Piece pc, out string falta)
	{
		falta = null;
		Requirement[] resources = pc.m_resources;
		foreach (Requirement val in resources)
		{
			if ((Object)(object)val.m_resItem != (Object)null && val.m_amount > 0 && ((Humanoid)pl).GetInventory().CountItems(val.m_resItem.m_itemData.m_shared.m_name, -1, true) < val.m_amount)
			{
				falta = Obra.Nome(val.m_resItem.m_itemData.m_shared.m_name) + " " + val.m_amount;
				return false;
			}
		}
		return true;
	}

	private static void Pagar(Player pl, Piece pc)
	{
		Requirement[] resources = pc.m_resources;
		foreach (Requirement val in resources)
		{
			if ((Object)(object)val.m_resItem != (Object)null && val.m_amount > 0)
			{
				((Humanoid)pl).GetInventory().RemoveItem(val.m_resItem.m_itemData.m_shared.m_name, val.m_amount, -1, true);
			}
		}
	}

	internal static void Explodir(Vector3 ancora, float raio)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		List<Piece> list = new List<Piece>();
		Piece.GetAllPiecesInRadius(ancora, raio, list);
		foreach (Piece item in list)
		{
			if (!((Object)(object)item == (Object)null) && Marcado(item) && !BancadaObra.Eh(item))
			{
				WearNTear component = ((Component)item).GetComponent<WearNTear>();
				if ((Object)(object)component != (Object)null)
				{
					component.Remove(false);
				}
			}
		}
	}
}
[HarmonyPatch(typeof(Container), "Awake")]
internal static class BauDaObraAwake
{
	private static void Prefix(Container __instance)
	{
		if (BauDaObra.Caixote(__instance))
		{
			__instance.m_width = 8;
			__instance.m_height = 7;
			__instance.m_name = "Caixote da obra";
		}
	}

	private static void Postfix(Container __instance)
	{
		if (BauDaObra.Eh(__instance))
		{
			BauDaObra.Arrumar(__instance);
			PostoDaObra.Sincronizar(__instance);
		}
	}
}
[HarmonyPatch(typeof(Container), "Interact")]
internal static class BloquearPilhaLegada
{
	private static bool Prefix(Container __instance, ref bool __result)
	{
		if (!BauDaObra.Eh(__instance))
		{
			return true;
		}
		BauDaObra.Compactar(__instance);
		if (!BauDaObra.TemPilhaLegada(__instance))
		{
			return true;
		}
		Plugin.Avisar("bau legado: quantidade preservada; falta espaco para converter pilhas vanilla");
		__result = false;
		return false;
	}
}
[HarmonyPatch(typeof(Player), "PlacePiece")]
internal static class VincularBauNovo
{
	private static void Postfix(Player __instance, Piece piece, Vector3 pos)
	{
		//IL_0036: 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_00af: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)__instance != (Object)(object)Player.m_localPlayer || (Object)(object)piece == (Object)null || ((Object)((Component)piece).gameObject).name != "piece_chest_wood")
		{
			return;
		}
		bool flag = false;
		List<Piece> list = new List<Piece>();
		Piece.GetAllPiecesInRadius(pos, 6f, list);
		foreach (Piece item in list)
		{
			if ((Object)(object)item != (Object)null && BauDaObra.DaObra(((Component)item).GetComponentInChildren<CraftingStation>()))
			{
				flag = true;
			}
		}
		if (!flag)
		{
			return;
		}
		foreach (Piece item2 in list)
		{
			if (!((Object)(object)item2 == (Object)null) && !(Vector3.Distance(((Component)item2).transform.position, pos) > 0.1f) && item2.GetCreator() == __instance.GetPlayerID())
			{
				Container componentInChildren = ((Component)item2).GetComponentInChildren<Container>();
				if ((Object)(object)componentInChildren != (Object)null && Utils.GetPrefabName(((Component)item2).gameObject) == "piece_chest_wood")
				{
					BauDaObra.Marcar(componentInChildren);
				}
			}
		}
	}
}
internal static class BuscaLocaisBaus
{
	internal delegate bool Avaliar(Piece modelo, Vector3 ponto, Quaternion rot, Transform ignorar, out Vector3 nivel);

	internal sealed class Resultado
	{
		internal int Candidatos;

		internal int Avaliados;

		internal float Distancia;
	}

	private const float Passo = 2.2f;

	private const float Folga = 16f;

	internal static bool Fora(Vector3 p, List<Bounds> volumes, float folga = 16f)
	{
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: 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_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: Unknown result type (might be due to invalid IL or missing references)
		foreach (Bounds volume in volumes)
		{
			Bounds current = volume;
			float num = Mathf.Max(new float[3]
			{
				((Bounds)(ref current)).min.x - p.x,
				0f,
				p.x - ((Bounds)(ref current)).max.x
			});
			float num2 = Mathf.Max(new float[3]
			{
				((Bounds)(ref current)).min.z - p.z,
				0f,
				p.z - ((Bounds)(ref current)).max.z
			});
			if (num * num + num2 * num2 < folga * folga)
			{
				return false;
			}
		}
		return true;
	}

	private static bool Separado(Vector3 p, List<Vector3> reservados)
	{
		//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)
		foreach (Vector3 reservado in reservados)
		{
			float num = p.x - reservado.x;
			float num2 = p.z - reservado.z;
			if (num * num + num2 * num2 < 4.6225004f)
			{
				return false;
			}
		}
		return true;
	}

	internal static int AneisCarregados(Vector3 origem, Vector3 direcao, Vector3 lateral)
	{
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_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)
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		//IL_0086: Unknown result type (might be due to invalid IL or missing references)
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		float num = 0f;
		foreach (Heightmap allHeightmap in Heightmap.GetAllHeightmaps())
		{
			if ((Object)(object)allHeightmap == (Object)null)
			{
				continue;
			}
			float num2 = (float)allHeightmap.m_width * allHeightmap.m_scale * 0.5f;
			for (int i = -1; i <= 1; i += 2)
			{
				for (int j = -1; j <= 1; j += 2)
				{
					Vector3 val = ((Component)allHeightmap).transform.position + new Vector3((float)i * num2, 0f, (float)j * num2) - origem;
					num = Mathf.Max(new float[3]
					{
						num,
						Mathf.Abs(Vector3.Dot(val, direcao)),
						Mathf.Abs(Vector3.Dot(val, lateral))
					});
				}
			}
		}
		return Mathf.CeilToInt(num / 2.2f) + 1;
	}

	internal static IEnumerator PertoDaMesa(Piece modelo, Vector3 mesa, Vector3 centro, List<Bounds> volumes, float mar, int n, List<Vector3> lugares, Func<bool> cancelar, Avaliar avaliar, Resultado resultado)
	{
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: 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_0017: Unknown result type (might be due to invalid IL or missing references)
		if (n <= lugares.Count || (Object)(object)modelo == (Object)null || (Object)(object)ZoneSystem.instance == (Object)null)
		{
			yield break;
		}
		int aneis = AneisCarregados(mesa, Vector3.forward, Vector3.right);
		int quadro = 0;
		Stopwatch relogio = Stopwatch.StartNew();
		float h = default(float);
		foreach (CelulaBuscaBaus c in RegraBuscaBaus.Candidatos(aneis))
		{
			if (cancelar())
			{
				break;
			}
			int num;
			quadro = (num = quadro + 1);
			if (num >= 8 || relogio.Elapsed.TotalMilliseconds >= 1.5)
			{
				yield return null;
				quadro = 0;
				relogio.Restart();
			}
			Vector3 ponto = mesa + new Vector3((float)c.Lado * 2.2f, 0f, (float)c.Frente * 2.2f);
			resultado.Candidatos++;
			Vector2 val = new Vector2(ponto.x - mesa.x, ponto.z - mesa.z);
			if (((Vector2)(ref val)).magnitude < 3f || !Fora(ponto, volumes, 1.5f) || !Separado(ponto, lugares) || !ZoneSystem.instance.IsZoneLoaded(ponto) || !ZoneSystem.instance.GetGroundHeight(ponto, ref h) || h < mar + 1f)
			{
				continue;
			}
			Vector3 delta = ponto - centro;
			delta.y = 0f;
			float num2;
			if (!(((Vector3)(ref delta)).sqrMagnitude > 0.01f))
			{
				num2 = 0f;
			}
			else
			{
				Quaternion val2 = Quaternion.LookRotation(delta);
				num2 = ((Quaternion)(ref val2)).eulerAngles.y;
			}
			Quaternion rot = Quaternion.Euler(0f, Mathf.Round(num2 / 22.5f) * 22.5f, 0f);
			resultado.Avaliados++;
			if (avaliar(modelo, ponto, rot, null, out var seguro) && Fora(seguro, volumes, 1.5f) && Separado(seguro, lugares))
			{
				lugares.Add(seguro);
				float distancia = resultado.Distancia;
				Vector2 val3 = new Vector2(seguro.x - mesa.x, seguro.z - mesa.z);
				resultado.Distancia = Mathf.Max(distancia, ((Vector2)(ref val3)).magnitude);
				if (lugares.Count >= n)
				{
					break;
				}
			}
		}
	}

	internal static IEnumerator Procurar(Piece modelo, Vector3 centro, Vector3 direcao, float limite, List<Bounds> volumes, float mar, int n, List<Vector3> lugares, Func<bool> cancelar, Avaliar avaliar, Resultado resultado)
	{
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: 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_0017: Unknown result type (might be due to invalid IL or missing references)
		if (n <= lugares.Count || (Object)(object)modelo == (Object)null || (Object)(object)ZoneSystem.instance == (Object)null)
		{
			yield break;
		}
		direcao.y = 0f;
		if (((Vector3)(ref direcao)).sqrMagnitude < 0.01f)
		{
			direcao = Vector3.forward;
		}
		((Vector3)(ref direcao)).Normalize();
		Vector3 lateral = new Vector3(direcao.z, 0f, 0f - direcao.x);
		Vector3 origem = centro + direcao * (limite + 16f);
		int aneis = AneisCarregados(origem, direcao, lateral);
		Stopwatch relogio = Stopwatch.StartNew();
		int nesteQuadro = 0;
		float h = default(float);
		foreach (CelulaBuscaBaus c in RegraBuscaBaus.Candidatos(aneis))
		{
			if (cancelar())
			{
				break;
			}
			int num;
			nesteQuadro = (num = nesteQuadro + 1);
			if (num >= 8 || relogio.Elapsed.TotalMilliseconds >= 1.5)
			{
				yield return null;
				nesteQuadro = 0;
				relogio.Restart();
				if (cancelar())
				{
					break;
				}
			}
			resultado.Candidatos++;
			Vector3 ponto = origem + direcao * ((float)c.Frente * 2.2f) + lateral * ((float)c.Lado * 2.2f);
			if (!Fora(ponto, volumes) || !Separado(ponto, lugares) || !ZoneSystem.instance.IsZoneLoaded(ponto) || !ZoneSystem.instance.GetGroundHeight(ponto, ref h) || h < mar + 1f)
			{
				continue;
			}
			Vector3 d = ponto - centro;
			d.y = 0f;
			float num2;
			if (!(((Vector3)(ref d)).sqrMagnitude > 0.01f))
			{
				num2 = 0f;
			}
			else
			{
				Quaternion val = Quaternion.LookRotation(d);
				num2 = ((Quaternion)(ref val)).eulerAngles.y;
			}
			Quaternion rot = Quaternion.Euler(0f, Mathf.Round(num2 / 22.5f) * 22.5f, 0f);
			resultado.Avaliados++;
			if (avaliar(modelo, ponto, rot, null, out var seguro) && Fora(seguro, volumes) && Separado(seguro, lugares))
			{
				lugares.Add(seguro);
				float distancia = resultado.Distancia;
				Vector2 val2 = new Vector2(seguro.x - centro.x, seguro.z - centro.z);
				resultado.Distancia = Mathf.Max(distancia, ((Vector2)(ref val2)).magnitude);
				if (lugares.Count >= n)
				{
					break;
				}
			}
		}
	}
}
[HarmonyPatch(typeof(GameCamera), "UpdateCamera")]
internal static class CameraRaioObra
{
	private static float RodaCamera()
	{
		if (!Desmontar.AjustandoRaio && !CopiarBlueprint.AjustandoRaio && !Seletor.Aberto)
		{
			return ZInput.GetMouseScrollWheel();
		}
		return 0f;
	}

	private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> codigo)
	{
		MethodInfo origem = AccessTools.Method(typeof(ZInput), "GetMouseScrollWheel", (Type[])null, (Type[])null);
		MethodInfo destino = AccessTools.Method(typeof(CameraRaioObra), "RodaCamera", (Type[])null, (Type[])null);
		foreach (CodeInstruction i in codigo)
		{
			if (CodeInstructionExtensions.Calls(i, origem))
			{
				i.opcode = OpCodes.Call;
				i.operand = destino;
			}
			yield return i;
		}
	}
}
internal static class CatalogoBlueprints
{
	internal static string Pasta(string config, string jogo)
	{
		string path = Path.Combine(config, "marcopogo.PlanBuild.cfg");
		if (File.Exists(path))
		{
			bool flag = false;
			string[] array = File.ReadAllLines(path);
			foreach (string text in array)
			{
				string text2 = text.Trim();
				if (text2.StartsWith("#") || text2.StartsWith(";") || text2.Length == 0)
				{
					continue;
				}
				if (text2.StartsWith("["))
				{
					flag = text2.Equals("[Directories]", StringComparison.OrdinalIgnoreCase);
					continue;
				}
				int num = text2.IndexOf('=');
				if (flag && num >= 0 && text2.Substring(0, num).Trim().Equals("Save directory", StringComparison.OrdinalIgnoreCase))
				{
					string text3 = Environment.ExpandEnvironmentVariables(text2.Substring(num + 1).Trim().Trim('"'));
					if (text3.Length > 0)
					{
						return Path.GetFullPath(Path.IsPathRooted(text3) ? text3 : Path.Combine(jogo, text3));
					}
				}
			}
		}
		return Path.Combine(config, "PlanBuild", "blueprints");
	}

	internal static string Chave(string arquivo)
	{
		string text = Path.GetFileNameWithoutExtension(arquivo).Normalize(NormalizationForm.FormD);
		StringBuilder stringBuilder = new StringBuilder();
		string text2 = text;
		foreach (char c in text2)
		{
			if (CharUnicodeInfo.GetUnicodeCategory(c) != UnicodeCategory.NonSpacingMark)
			{
				stringBuilder.Append(char.ToLowerInvariant(c));
			}
		}
		text = stringBuilder.ToString().Replace('_', ' ').Trim();
		return text switch
		{
			"11 prado" => "prado", 
			"12 floresta negra" => "floresta negra", 
			"13 pantano" => "pantano", 
			"14 planicies" => "planicies", 
			"15 montanha" => "montanha", 
			_ => text, 
		};
	}

	internal static List<string> Listar(IEnumerable<string> pastas, Action<string> aviso)
	{
		List<string> list = new List<string>();
		HashSet<string> hashSet = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
		HashSet<string> locais = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
		foreach (string pasta in pastas)
		{
			if (!Directory.Exists(pasta))
			{
				continue;
			}
			List<string> list2 = new List<string>();
			Varrer(pasta, list2, locais, aviso);
			list2.Sort(StringComparer.OrdinalIgnoreCase);
			foreach (string item in list2)
			{
				if (hashSet.Add(Chave(item)))
				{
					list.Add(item);
				}
			}
		}
		list.Sort(StringComparer.OrdinalIgnoreCase);
		return list;
	}

	private static void Varrer(string pasta, List<string> arquivos, HashSet<string> locais, Action<string> aviso)
	{
		try
		{
			string fullPath = Path.GetFullPath(pasta);
			if (!locais.Add(fullPath))
			{
				return;
			}
			string[] files = Directory.GetFiles(fullPath);
			foreach (string text in files)
			{
				if (Path.GetExtension(text).Equals(".blueprint", StringComparison.OrdinalIgnoreCase))
				{
					arquivos.Add(text);
				}
			}
			string[] directories = Directory.GetDirectories(fullPath);
			foreach (string text2 in directories)
			{
				if ((File.GetAttributes(text2) & FileAttributes.ReparsePoint) == 0)
				{
					Varrer(text2, arquivos, locais, aviso);
				}
			}
		}
		catch (Exception ex)
		{
			aviso?.Invoke("pasta " + pasta + ": " + ex.Message);
		}
	}

	internal static int Localizar(List<string> arquivos, string anterior)
	{
		int num = arquivos.FindIndex((string f) => f.Equals(anterior, StringComparison.OrdinalIgnoreCase));
		if (num < 0)
		{
			return arquivos.FindIndex((string f) => Chave(f) == Chave(anterior));
		}
		return num;
	}
}
internal static class Compat
{
	internal const string RecipeGate = "raaotium.recipegate";
}
[HarmonyPatch]
internal static class BancadaNoRecipeGate
{
	private static IEnumerable<MethodBase> TargetMethods()
	{
		Type tipo = AccessTools.TypeByName("RecipeGate.Trava");
		MethodInfo metodo = ((tipo == null) ? null : AccessTools.Method(tipo, "TrancadaPeca", new Type[1] { typeof(Piece) }, (Type[])null));
		if (metodo != null)
		{
			yield return metodo;
		}
	}

	private static void Prefix(ref Piece peca)
	{
		if (BancadaObra.Modelo(peca) && (Object)(object)BancadaObra.Base != (Object)null)
		{
			peca = BancadaObra.Base;
		}
	}
}
[HarmonyPatch(typeof(Player), "HaveRequirements", new Type[]
{
	typeof(Piece),
	typeof(RequirementMode)
})]
internal static class FerramentaConhecida
{
	[HarmonyPriority(0)]
	[HarmonyAfter(new string[] { "raaotium.recipegate" })]
	private static void Postfix(Player __instance, Piece piece, RequirementMode mode, ref bool __result)
	{
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		if (BancadaObra.Modelo(piece))
		{
			__result = BancadaObra.Permitida && __instance.HaveRequirements(BancadaObra.Base, mode);
		}
		else if ((Object)(object)piece != (Object)null && Ferramentas.EhFerramenta(piece.m_name))
		{
			__result = Ferramentas.Visivel(piece.m_name);
		}
	}
}
[HarmonyPatch(typeof(PieceTable), "IsPieceAvailable")]
internal static class FerramentaDisponivel
{
	[HarmonyAfter(new string[] { "raaotium.recipegate" })]
	[HarmonyPriority(0)]
	private static void Postfix(Piece piece, ref bool __result)
	{
		if (BancadaObra.Modelo(piece))
		{
			__result = BancadaObra.Permitida;
		}
		else if ((Object)(object)piece != (Object)null && Ferramentas.EhFerramenta(piece.m_name))
		{
			__result = Ferramentas.Visivel(piece.m_name);
		}
	}
}
[HarmonyPatch(typeof(PieceTable), "UpdateAvailable")]
internal static class FerramentaNoMenu
{
	private static readonly FieldInfo fDisp = AccessTools.Field(typeof(PieceTable), "m_availablePieces");

	private static readonly FieldInfo fPorAba = AccessTools.Field(typeof(PieceTable), "m_availablePiecesByCategory");

	[HarmonyPriority(0)]
	[HarmonyAfter(new string[] { "raaotium.recipegate" })]
	private static void Postfix(PieceTable __instance)
	{
		List<Piece> list = Ferramentas.PecasNaTabela(__instance, visiveis: true);
		List<Piece> list2 = Ferramentas.PecasNaTabela(__instance, visiveis: false);
		HashSet<Piece> hashSet = ((fDisp != null) ? (fDisp.GetValue(__instance) as HashSet<Piece>) : null);
		List<List<Piece>> list3 = ((fPorAba != null) ? (fPorAba.GetValue(__instance) as List<List<Piece>>) : null);
		if (hashSet != null)
		{
			foreach (Piece item in list2)
			{
				hashSet.Remove(item);
			}
		}
		if (list3 != null)
		{
			foreach (List<Piece> item2 in list3)
			{
				if (item2 == null)
				{
					continue;
				}
				foreach (Piece item3 in list2)
				{
					item2.Remove(item3);
				}
			}
		}
		if (list.Count == 0)
		{
			return;
		}
		if (hashSet != null)
		{
			foreach (Piece item4 in list)
			{
				hashSet.Add(item4);
			}
		}
		if (list3 == null)
		{
			return;
		}
		foreach (List<Piece> item5 in list3)
		{
			if (item5 == null)
			{
				continue;
			}
			int num = -1;
			for (int i = 0; i < item5.Count; i++)
			{
				if ((Object)(object)item5[i] != (Object)null && item5[i].m_repairPiece)
				{
					num = i + 1;
					break;
				}
			}
			if (num < 0)
			{
				continue;
			}
			foreach (Piece item6 in list)
			{
				int num2 = item5.IndexOf(item6);
				if (num2 >= 0)
				{
					num = num2 + 1;
					continue;
				}
				item5.Insert(Mathf.Min(num, item5.Count), item6);
				num++;
			}
		}
	}
}
internal static class ConfirmacaoVanilla
{
	internal static int FechouNoQuadro = -1;

	private static bool contando;

	private static Vector2 textoPos;

	private static Vector2 textoSize;

	private static Vector2 textoMin;

	private static Vector2 textoMax;

	private static GameObject janela;

	private static TMP_Text pergunta;

	private static Button sim;

	private static Button nao;

	private static Action confirmar;

	private static Action cancelar;

	internal static bool Aberta
	{
		get
		{
			if ((Object)(object)janela != (Object)null)
			{
				return janela.activeSelf;
			}
			return false;
		}
	}

	internal static bool Modal
	{
		get
		{
			if (Aberta)
			{
				return !contando;
			}
			return false;
		}
	}

	internal static bool Contando => contando;

	private static void Preparar()
	{
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Expected O, but got Unknown
		//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_00af: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: 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_00c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00df: Unknown result type (might be due to invalid IL or missing references)
		//IL_012a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0134: Expected O, but got Unknown
		//IL_0139: Unknown result type (might be due to invalid IL or missing references)
		//IL_0143: Expected O, but got Unknown
		//IL_015b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0165: Expected O, but got Unknown
		//IL_0187: Unknown result type (might be due to invalid IL or missing references)
		//IL_0191: Expected O, but got Unknown
		//IL_0209: Unknown result type (might be due to invalid IL or missing references)
		//IL_020e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0215: 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_0221: 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_022d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0232: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)janela != (Object)null)
		{
			return;
		}
		Menu val = Object.FindFirstObjectByType<Menu>();
		if ((Object)(object)val == (Object)null)
		{
			throw new InvalidOperationException("Menu nativo indisponível.");
		}
		Transform val2 = (Transform)AccessTools.Field(typeof(Menu), "m_logoutDialog").GetValue(val);
		Canvas componentInParent = ((Component)val2).GetComponentInParent<Canvas>(true);
		Transform val3 = val2.Find("dialog");
		janela = Object.Instantiate<GameObject>(((Component)val3).gameObject, ((Component)componentInParent).transform, false);
		((Object)janela).name = "Architect_ConfirmacaoMadeira";
		janela.SetActive(false);
		RectTransform component = janela.GetComponent<RectTransform>();
		Vector2 val4 = (component.pivot = new Vector2(0.5f, 0.5f));
		Vector2 anchorMin = (component.anchorMax = val4);
		component.anchorMin = anchorMin;
		component.anchoredPosition = Vector2.zero;
		component.sizeDelta = new Vector2(348f, 200f);
		sim = ((Component)janela.transform.Find("Button_yes")).GetComponent<Button>();
		nao = ((Component)janela.transform.Find("Button_no")).GetComponent<Button>();
		sim.onClick = new ButtonClickedEvent();
		nao.onClick = new ButtonClickedEvent();
		((UnityEvent)sim.onClick).AddListener((UnityAction)delegate
		{
			Encerrar(aceito: true);
		});
		((UnityEvent)nao.onClick).AddListener((UnityAction)delegate
		{
			Encerrar(aceito: false);
		});
		TMP_Text[] componentsInChildren = janela.GetComponentsInChildren<TMP_Text>(true);
		foreach (TMP_Text val7 in componentsInChildren)
		{
			if (!val7.transform.IsChildOf(((Component)sim).transform) && !val7.transform.IsChildOf(((Component)nao).transform))
			{
				pergunta = val7;
				break;
			}
		}
		RectTransform rectTransform = pergunta.rectTransform;
		textoPos = rectTransform.anchoredPosition;
		textoSize = rectTransform.sizeDelta;
		textoMin = rectTransform.anchorMin;
		textoMax = rectTransform.anchorMax;
	}

	internal static void Abrir(string texto, Action aoSim, Action aoNao)
	{
		//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)
		Preparar();
		contando = false;
		((Component)sim).gameObject.SetActive(true);
		((Component)nao).gameObject.SetActive(true);
		RectTransform rectTransform = pergunta.rectTransform;
		rectTransform.anchorMin = textoMin;
		rectTransform.anchorMax = textoMax;
		rectTransform.anchoredPosition = textoPos;
		rectTransform.sizeDelta = textoSize;
		confirmar = aoSim;
		cancelar = aoNao;
		janela.transform.SetAsLastSibling();
		janela.SetActive(true);
		pergunta.text = texto;
		pergunta.enableAutoSizing = true;
		pergunta.fontSizeMin = 16f;
		pergunta.fontSizeMax = 24f;
		((Component)sim).GetComponentInChildren<TMP_Text>().text = "Sim";
		((Component)nao).GetComponentInChildren<TMP_Text>().text = "Não";
	}

	private static void Encerrar(bool aceito)
	{
		Action action = (aceito ? confirmar : cancelar);
		Fechar();
		action?.Invoke();
	}

	internal static void Fechar()
	{
		if (Aberta)
		{
			FechouNoQuadro = Time.frameCount;
		}
		if ((Object)(object)janela != (Object)null)
		{
			janela.SetActive(false);
		}
		confirmar = (cancelar = null);
		contando = false;
		ZCursor.Hide();
	}

	internal static void MostrarContagem(int n)
	{
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		Preparar();
		if (!contando)
		{
			confirmar = (cancelar = null);
			contando = true;
			((Component)sim).gameObject.SetActive(false);
			((Component)nao).gameObject.SetActive(false);
			janela.transform.SetAsLastSibling();
			janela.SetActive(true);
			RectTransform rectTransform = pergunta.rectTransform;
			Vector2 anchorMin = (rectTransform.anchorMax = new Vector2(0.5f, 0.5f));
			rectTransform.anchorMin = anchorMin;
			rectTransform.anchoredPosition = Vector2.zero;
			rectTransform.sizeDelta = new Vector2(300f, 110f);
			ZCursor.Hide();
		}
		pergunta.text = ((n > 0) ? n.ToString() : "Saia da área");
		pergunta.enableAutoSizing = false;
		pergunta.fontSize = ((n > 0) ? 56 : 24);
	}

	internal static void Atualizar()
	{
		if (Modal)
		{
			if ((Object)(object)Player.m_localPlayer == (Object)null)
			{
				Fechar();
			}
			else if (Input.GetKeyDown((KeyCode)27) || Input.GetKeyDown((KeyCode)9))
			{
				Encerrar(aceito: false);
			}
		}
	}
}
[HarmonyPatch(typeof(Menu), "Update")]
internal static class EntradaConfirmacaoMadeira
{
	private static bool Prefix()
	{
		if (ConfirmacaoVanilla.FechouNoQuadro == Time.frameCount)
		{
			return false;
		}
		if (!ConfirmacaoVanilla.Modal)
		{
			return true;
		}
		ConfirmacaoVanilla.Atualizar();
		return false;
	}
}
internal static class ConfirmarConstrucaoUI
{
	private static GUIStyle titulo;

	private static GUIStyle nome;

	private static GUIStyle numero;

	private static GUIStyle corpo;

	private static GUIStyle nota;

	private static GUIStyle acao;

	private static GUIStyle vazio;

	private static Texture2D pixel;

	private static Font Fonte(string n)
	{
		Font[] array = Resources.FindObjectsOfTypeAll<Font>();
		foreach (Font val in array)
		{
			if ((Object)(object)val != (Object)null && ((Object)val).name == n)
			{
				return val;
			}
		}
		return GUI.skin.font;
	}

	private static GUIStyle E(string f, int size, Color c)
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Expected O, but got Unknown
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		GUIStyle val = new GUIStyle(GUI.skin.label);
		val.font = Fonte(f);
		val.fontSize = size;
		val.alignment = (TextAnchor)4;
		val.normal.textColor = c;
		val.richText = false;
		val.wordWrap = true;
		return val;
	}

	private static void Preparar()
	{
		//IL_003b: 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_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_0083: 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_00a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00aa: Expected O, but got Unknown
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: Expected O, but got Unknown
		//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
		if (titulo == null)
		{
			Color c = default(Color);
			((Color)(ref c))..ctor(0.34f, 0.31f, 0.25f);
			Color c2 = default(Color);
			((Color)(ref c2))..ctor(0.24f, 0.34f, 0.37f);
			titulo = E("Norsebold", 32, c);
			nome = E("AveriaSerifLibre-Regular", 25, c2);
			numero = E("AveriaSerifLibre-Regular", 29, c2);
			corpo = E("AveriaSerifLibre-Regular", 16, c);
			nota = E("AveriaSerifLibre-Regular", 13, c);
			acao = E("Norsebold", 26, c2);
			vazio = new GUIStyle();
			pixel = new Texture2D(1, 1);
			pixel.SetPixel(0, 0, new Color(c.r, c.g, c.b, 0.35f));
			pixel.Apply();
		}
	}

	private static bool Botao(Rect r, string t)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		GUI.Label(r, t, acao);
		return GUI.Button(r, GUIContent.none, vazio);
	}

	internal static int Desenhar(string planta, int pecas, int demolir)
	{
		//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_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b5: 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_00fe: 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_0150: 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_01aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_021f: 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_02a2: Unknown result type (might be due to invalid IL or missing references)
		Preparar();
		Matrix4x4 matrix = GUI.matrix;
		float num = Mathf.Max(1f, (float)Screen.height / 800f);
		GUI.matrix = Matrix4x4.Scale(new Vector3(num, num, 1f));
		try
		{
			float num2 = (float)Screen.width / num;
			float num3 = (float)Screen.height / num;
			float num4 = Mathf.Min(new float[3]
			{
				700f,
				num2 - 32f,
				(num3 - 32f) * 1.5f
			});
			float num5 = num4 / 700f;
			Rect r = default(Rect);
			((Rect)(ref r))..ctor((num2 - num4) / 2f, (num3 - num4 / 1.5f) / 2f, num4, num4 / 1.5f);
			MesaArquiteturaUI.DesenharMesa(r);
			float num6 = ((Rect)(ref r)).center.x - 185f * num5;
			float num7 = ((Rect)(ref r)).y + 82f * num5;
			float num8 = 370f * num5;
			GUI.Label(new Rect(num6, num7, num8, 42f * num5), "Confirmar construção", titulo);
			GUI.Label(new Rect(num6, num7 + 48f * num5, num8, 35f * num5), planta, nome);
			GUI.Label(new Rect(num6, num7 + 89f * num5, num8, 38f * num5), pecas.ToString("N0"), numero);
			GUI.Label(new Rect(num6, num7 + 127f * num5, num8, 22f * num5), "peças", nota);
			GUI.DrawTexture(new Rect(num6, num7 + 163f * num5, num8, 1f), (Texture)(object)pixel);
			GUI.Label(new Rect(num6 + 8f * num5, num7 + 167f * num5, num8 - 16f * num5, 48f * num5), "Os materiais serão retirados dos baús e pilhas próximos à bancada de construção.", corpo);
			GUI.Label(new Rect(num6 + 8f * num5, num7 + 220f * num5, num8 - 16f * num5, 40f * num5), (demolir > 0) ? (demolir + " peças existentes serão desmontadas antes.") : "Após confirmar, você terá 5 segundos para sair da área.", nota);
			if (Botao(new Rect(num6, num7 + 257f * num5, num8 * 0.47f, 38f * num5), "Construir"))
			{
				return 1;
			}
			if (Botao(new Rect(num6 + num8 * 0.53f, num7 + 257f * num5, num8 * 0.47f, 38f * num5), "Voltar"))
			{
				return -1;
			}
			return 0;
		}
		finally
		{
			GUI.matrix = matrix;
		}
	}
}
internal static class ConfirmarDesmonteUI
{
	private static GUIStyle titulo;

	private static GUIStyle corpo;

	private static GUIStyle numero;

	private static GUIStyle legenda;

	private static GUIStyle acao;

	private static GUIStyle alerta;

	private static GUIStyle vazio;

	private static Texture2D pixel;

	private static Vector2 scroll;

	private static Font Fonte(string n)
	{
		Font[] array = Resources.FindObjectsOfTypeAll<Font>();
		foreach (Font val in array)
		{
			if ((Object)(object)val != (Object)null && ((Object)val).name == n)
			{
				return val;
			}
		}
		return GUI.skin.font;
	}

	private static GUIStyle Estilo(string fonte, int size, Color c)
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Expected O, but got Unknown
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		GUIStyle val = new GUIStyle(GUI.skin.label);
		val.font = Fonte(fonte);
		val.fontSize = size;
		val.alignment = (TextAnchor)4;
		val.normal.textColor = c;
		val.richText = false;
		return val;
	}

	private static void Preparar()
	{
		//IL_003b: 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_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_0083: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c8: Expected O, but got Unknown
		//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d4: Expected O, but got Unknown
		//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
		if (titulo == null)
		{
			Color c = default(Color);
			((Color)(ref c))..ctor(0.34f, 0.31f, 0.25f);
			Color c2 = default(Color);
			((Color)(ref c2))..ctor(0.24f, 0.34f, 0.37f);
			titulo = Estilo("Norsebold", 34, c);
			corpo = Estilo("AveriaSerifLibre-Regular", 17, c);
			numero = Estilo("AveriaSerifLibre-Regular", 29, c2);
			legenda = Estilo("AveriaSerifLibre-Regular", 14, c);
			acao = Estilo("Norsebold", 26, c2);
			alerta = Estilo("AveriaSerifLibre-Regular", 15, new Color(0.53f, 0.24f, 0.14f));
			alerta.wordWrap = true;
			vazio = new GUIStyle();
			pixel = new Texture2D(1, 1);
			pixel.SetPixel(0, 0, new Color(0.34f, 0.31f, 0.25f, 0.35f));
			pixel.Apply();
		}
	}

	private static void Linha(float x, float y, float w)
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		GUI.DrawTexture(new Rect(x, y, w, 1f), (Texture)(object)pixel);
	}

	private static bool Botao(Rect r, string t)
	{
		//IL_0000: 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_004b: Unknown result type (might be due to invalid IL or missing references)
		GUI.Label(r, t, acao);
		if (((Rect)(ref r)).Contains(Event.current.mousePosition))
		{
			Linha(((Rect)(ref r)).x + 15f, ((Rect)(ref r)).yMax - 3f, ((Rect)(ref r)).width - 30f);
		}
		return GUI.Button(r, GUIContent.none, vazio);
	}

	internal static int Desenhar(int pecas, float raio, string recuperado, string destino, string aviso)
	{
		//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_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0390: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b5: 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_00fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_012f: Unknown result type (might be due to invalid IL or missing references)
		//IL_016b: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e7: 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_023f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0246: Expected O, but got Unknown
		//IL_0259: Unknown result type (might be due to invalid IL or missing references)
		//IL_026b: Expected O, but got Unknown
		//IL_0290: Unknown result type (might be due to invalid IL or missing references)
		//IL_0292: 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_02b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_030b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0339: Unknown result type (might be due to invalid IL or missing references)
		//IL_0375: Unknown result type (might be due to invalid IL or missing references)
		Preparar();
		Matrix4x4 matrix = GUI.matrix;
		float num = Mathf.Max(0.72f, (float)Screen.height / 1111.1111f);
		GUI.matrix = Matrix4x4.Scale(new Vector3(num, num, 1f));
		try
		{
			float num2 = (float)Screen.width / num;
			float num3 = (float)Screen.height / num;
			float num4 = Mathf.Min(new float[3]
			{
				780f,
				num2 - 32f,
				(num3 - 32f) * 1.5f
			});
			float num5 = num4 / 780f;
			Rect r = default(Rect);
			((Rect)(ref r))..ctor((num2 - num4) / 2f, (num3 - num4 / 1.5f) / 2f, num4, num4 / 1.5f);
			MesaArquiteturaUI.DesenharMesa(r);
			float num6 = ((Rect)(ref r)).center.x - 215f * num5;
			float num7 = ((Rect)(ref r)).y + 79f * num5;
			float num8 = 430f * num5;
			GUI.Label(new Rect(num6, num7, num8, 43f * num5), "Confirmar desmonte", titulo);
			GUI.Label(new Rect(num6, num7 + 53f * num5, num8 / 2f, 34f * num5), pecas.ToString(), numero);
			GUI.Label(new Rect(num6 + num8 / 2f, num7 + 53f * num5, num8 / 2f, 34f * num5), raio.ToString("0.0") + " m", numero);
			GUI.Label(new Rect(num6, num7 + 86f * num5, num8 / 2f, 24f * num5), "peças selecionadas", legenda);
			GUI.Label(new Rect(num6 + num8 / 2f, num7 + 86f * num5, num8 / 2f, 24f * num5), "raio da área", legenda);
			Linha(num6, num7 + 119f * num5, num8);
			GUI.Label(new Rect(num6, num7 + 130f * num5, num8, 27f * num5), "Você vai receber", corpo);
			GUIStyle val = new GUIStyle(corpo);
			val.wordWrap = true;
			float num9 = Mathf.Max(48f * num5, val.CalcHeight(new GUIContent(recuperado), num8 - 20f));
			Rect val2 = default(Rect);
			((Rect)(ref val2))..ctor(num6, num7 + 161f * num5, num8, 51f * num5);
			scroll = GUI.BeginScrollView(val2, scroll, new Rect(0f, 0f, num8 - 20f, num9));
			GUI.Label(new Rect(0f, 0f, num8 - 20f, num9), recuperado, val);
			GUI.EndScrollView();
			Linha(num6, num7 + 222f * num5, num8);
			GUI.Label(new Rect(num6, num7 + 264f * num5, num8, 37f * num5), aviso, alerta);
			if (Botao(new Rect(num6, num7 + 311f * num5, num8 * 0.47f, 38f * num5), "Desmontar"))
			{
				return 1;
			}
			if (Botao(new Rect(num6 + num8 * 0.53f, num7 + 311f * num5, num8 * 0.47f, 38f * num5), "Voltar"))
			{
				return -1;
			}
			return 0;
		}
		finally
		{
			GUI.matrix = matrix;
		}
	}
}
internal static class Contador
{
	internal static void OnGUI()
	{
		int num = Obra.Contagem_();
		if (num < 0)
		{
			num = Desmontar.Contagem_();
		}
		if (num >= 0)
		{
			ConfirmacaoVanilla.MostrarContagem(num);
		}
		else if (ConfirmacaoVanilla.Contando)
		{
			ConfirmacaoVanilla.Fechar();
		}
	}
}
internal static class ContagemUI
{
	private static GUIStyle titulo;

	private static GUIStyle numero;

	private static GUIStyle nota;

	private static Font Fonte(string n)
	{
		Font[] array = Resources.FindObjectsOfTypeAll<Font>();
		foreach (Font val in array)
		{
			if ((Object)(object)val != (Object)null && ((Object)val).name == n)
			{
				return val;
			}
		}
		return GUI.skin.font;
	}

	private static GUIStyle Estilo(string f, int size, Color c)
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Expected O, but got Unknown
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		GUIStyle val = new GUIStyle(GUI.skin.label);
		val.font = Fonte(f);
		val.fontSize = size;
		val.alignment = (TextAnchor)4;
		val.normal.textColor = c;
		val.richText = false;
		return val;
	}

	internal static void Desenhar(int segundos, bool construir)
	{
		//IL_024d: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: 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_00a4: 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_0047: 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_0108: 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_014d: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0237: Unknown result type (might be due to invalid IL or missing references)
		//IL_0197: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
		if (segundos < 0)
		{
			return;
		}
		if (titulo == null)
		{
			titulo = Estilo("Norsebold", 15, new Color(0.34f, 0.31f, 0.25f));
			numero = Estilo("AveriaSerifLibre-Regular", 36, new Color(0.24f, 0.34f, 0.37f));
			nota = Estilo("AveriaSerifLibre-Regular", 10, new Color(0.4f, 0.3f, 0.22f));
		}
		Matrix4x4 matrix = GUI.matrix;
		float num = Mathf.Max(1f, (float)Screen.height / 1080f);
		GUI.matrix = Matrix4x4.Scale(new Vector3(num, num, 1f));
		try
		{
			float num2 = (float)Screen.width / num;
			float num3 = (float)Screen.height / num;
			float num4 = Mathf.Min(280f, num2 - 24f);
			float num5 = num4 / 540f;
			Rect r = default(Rect);
			((Rect)(ref r))..ctor((num2 - num4) / 2f, num3 - num4 / 1.5f - 16f, num4, num4 / 1.5f);
			MesaArquiteturaUI.DesenharMesa(r);
			float num6 = ((Rect)(ref r)).center.x - 150f * num5;
			float num7 = ((Rect)(ref r)).y + 76f * num5;
			GUI.Label(new Rect(num6, num7, 300f * num5, 40f * num5), (segundos <= 0) ? "Aguardando" : (construir ? "Construção em" : "Desmonte em"), titulo);
			if (segundos > 0)
			{
				GUI.Label(new Rect(num6, num7 + 43f * num5, 300f * num5, 90f * num5), segundos.ToString(), numero);
				GUI.Label(new Rect(num6, num7 + 141f * num5, 300f * num5, 30f * num5), "Afaste-se da área marcada", nota);
			}
			else
			{
				GUI.Label(new Rect(num6, num7 + 62f * num5, 300f * num5, 50f * num5), "Saia da área marcada", nota);
				GUI.Label(new Rect(num6 - 15f * num5, num7 + 127f * num5, 330f * num5, 40f * num5), "A operação começa quando você sair", nota);
			}
		}
		finally
		{
			GUI.matrix = matrix;
		}
	}
}
internal static class CopiarBlueprint
{
	private sealed class NomeDaBlueprint : TextReceiver
	{
		public string GetText()
		{
			return nome;
		}

		public void SetText(string valor)
		{
			nome = valor;
			Salvar();
			if (Ativo)
			{
				Plugin.Avisar(erro);
				Fechar();
			}
		}
	}

	internal static bool Ativo;

	internal static bool Nomeando;

	private static Vector3 centro;

	private static float raio = 3f;

	private static float proxima;

	private static float abriu;

	private static string nome = "";

	private static string erro = "";

	private static List<Piece> pecas = new List<Piece>();

	internal static bool AjustandoRaio
	{
		get
		{
			if (Ativo)
			{
				return !Nomeando;
			}
			return false;
		}
	}

	internal static void Abrir()
	{
		//IL_0081: Unknown result type (might be due to invalid IL or missing references)
		//IL_0086: Unknown result type (might be due to invalid IL or missing references)
		if (BancadaObra.PrepararSelecao())
		{
			if (Obra.Ocupada || Desmontar.Ativo)
			{
				Plugin.Avisar("termine a obra ou o desmonte antes de copiar");
				return;
			}
			if ((Object)(object)Player.m_localPlayer == (Object)null)
			{
				Plugin.Avisar("entre em um mundo para copiar uma construcao");
				return;
			}
			Seletor.Fechar();
			PainelObra.Fechar();
			raio = 3f;
			Ativo = true;
			Nomeando = false;
			erro = "";
			pecas.Clear();
			abriu = Time.unscaledTime;
			centro = ((Component)Player.m_localPlayer).transform.position;
			Obra.OcultarParaCopiar();
			Plugin.Dizer("COPIAR: mire o centro, ajuste o raio com a roda e clique para conferir e salvar");
		}
	}

	internal static void Fechar()
	{
		if (Nomeando)
		{
			Piece ativa = BancadaObra.Ativa;
			ZNetView val = (((Object)(object)ativa != (Object)null) ? ((Component)ativa).GetComponent<ZNetView>() : null);
			if ((Object)(object)val != (Object)null && val.IsValid() && val.IsOwner() && val.GetZDO().GetString("architect_pedido_tipo", "") == "copiar")
			{
				val.GetZDO().Set("architect_pedido_tipo", "");
			}
		}
		if (Nomeando && (Object)(object)TextInput.instance != (Object)null && TextInput.IsVisible())
		{
			TextInput.instance.Hide();
		}
		Ativo = (Nomeando = false);
		pecas.Clear();
		Anel.Esconder();
		ZCursor.Hide();
	}

	private static bool Pode(Piece p)
	{
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_008e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0093: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)p == (Object)null || !p.IsPlacedByPlayer() || p.GetCreator() != Player.m_localPlayer.GetPlayerID() || (Object)(object)((Component)p).GetComponentInParent<Rigidbody>() != (Object)null)
		{
			return false;
		}
		if ((Object)(object)((Component)p).GetComponent<Ship>() != (Object)null || (Object)(object)((Component)p).GetComponent<Vagon>() != (Object)null)
		{
			return false;
		}
		ZNetView component = ((Component)p).GetComponent<ZNetView>();
		if ((Object)(object)component == (Object)null || !component.IsValid() || component.GetZDO().GetBool("architect_obra", false))
		{
			return false;
		}
		Vector3 val = ((Component)p).transform.position - centro;
		val.y = 0f;
		return ((Vector3)(ref val)).magnitude <= raio;
	}

	private static void Levantar()
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		pecas.Clear();
		List<Piece> list = new List<Piece>();
		Piece.GetAllPiecesInRadius(centro, float.MaxValue, list);
		foreach (Piece item in list)
		{
			if (Pode(item))
			{
				pecas.Add(item);
			}
		}
	}

	internal static void Update()
	{
		//IL_0065: 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_00cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_011a: Unknown result type (might be due to invalid IL or missing references)
		//IL_011f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0176: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
		if (Ativo && !Nomeando && !Plugin.ComMartelo())
		{
			Anel.Esconder();
		}
		else
		{
			if (!Ativo)
			{
				return;
			}
			if ((Object)(object)Player.m_localPlayer == (Object)null || (!Nomeando && !Ferramentas.CopiarNaMao()))
			{
				Fechar();
			}
			else if (Nomeando)
			{
				if (!TextInput.IsVisible())
				{
					Fechar();
				}
			}
			else
			{
				if (!Plugin.UiLivre())
				{
					return;
				}
				if (Input.GetKeyDown(Plugin.TeclaVoltar.Value) || Input.GetKeyDown((KeyCode)27))
				{
					Fechar();
					return;
				}
				raio = Mathf.Max(1f, raio + Plugin.Roda() * (Input.GetKey((KeyCode)304) ? 2f : 0.5f));
				if ((Object)(object)GameCamera.instance != (Object)null)
				{
					Transform transform = ((Component)GameCamera.instance).transform;