Decompiled source of MineCompany v0.2.0

MineCompany.dll

Decompiled 4 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using DunGen;
using GameNetcodeStuff;
using HarmonyLib;
using LethalLib.Modules;
using Microsoft.CodeAnalysis;
using MineCompany.Dev;
using MineCompany.Items;
using MineCompany.Mobs;
using MineCompany.Voxel;
using TMPro;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Audio;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.Networking;
using UnityEngine.Rendering;
using UnityEngine.Rendering.HighDefinition;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("MineCompany")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+9d213c740e8115a51ce16d8bd00154f82cc37979")]
[assembly: AssemblyProduct("MineCompany")]
[assembly: AssemblyTitle("MineCompany")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace MineCompany
{
	public class Recipe
	{
		public string Name;

		public string Result;

		public Block ResultBlock;

		public int Count = 1;

		public (Block block, int n)[] Blocks = new(Block, int)[0];

		public (string id, int n)[] Items = new(string, int)[0];

		public string Cost => string.Join(", ", Blocks.Select(((Block block, int n) b) => $"{b.n} {Mining.Name(b.block)}").Concat(Items.Select(((string id, int n) i) => $"{i.n} {Content.Get(i.id).Name}")));
	}
	[HarmonyPatch]
	public static class Crafting
	{
		public abstract class StationMarker : MonoBehaviour
		{
			private void Awake()
			{
				((Object)((Component)this).gameObject).hideFlags = (HideFlags)0;
			}

			private void Start()
			{
				((Renderer)((Component)this).GetComponentInChildren<MeshRenderer>()).sharedMaterial = BlockMaterial();
			}
		}

		public class FurnaceMarker : StationMarker
		{
		}

		public class TableMarker : StationMarker
		{
		}

		public enum Station
		{
			None,
			Table,
			Furnace
		}

		public const float Reach = 3f;

		public const float IngredientRadius = 3f;

		public static readonly List<Recipe> Recipes = new List<Recipe>();

		public static UnlockableItem FurnaceUnlockable;

		public static UnlockableItem TableUnlockable;

		private static GameObject furnacePrefab;

		private static GameObject tablePrefab;

		private static TableMarker table;

		public static Transform Table
		{
			get
			{
				if ((Object)(object)table == (Object)null)
				{
					table = Object.FindObjectOfType<TableMarker>();
				}
				if (!((Object)(object)table != (Object)null))
				{
					return null;
				}
				return ((Component)table).transform;
			}
		}

		internal static void Init()
		{
			Recipes.Add(new Recipe
			{
				Name = "4 Planks",
				ResultBlock = Block.Planks,
				Count = 4,
				Blocks = new(Block, int)[1] { (Block.Log, 1) }
			});
			Recipes.Add(new Recipe
			{
				Name = "2 Sticks",
				Result = "stick",
				Count = 2,
				Blocks = new(Block, int)[1] { (Block.Planks, 2) }
			});
			Recipes.Add(new Recipe
			{
				Name = "4 Torches",
				ResultBlock = Block.Torch,
				Count = 4,
				Items = new(string, int)[2]
				{
					("stick", 1),
					("coal", 1)
				}
			});
			Tool("wooden_pickaxe", null, Block.Planks, 3);
			Tool("wooden_sword", null, Block.Planks, 2);
			Tool("stone_pickaxe", null, Block.Cobblestone, 3);
			Tool("stone_sword", null, Block.Cobblestone, 2);
			Tool("iron_pickaxe", "iron_ingot", Block.Air, 3);
			Tool("iron_sword", "iron_ingot", Block.Air, 2);
			Tool("diamond_pickaxe", "diamond", Block.Air, 3);
			Tool("diamond_sword", "diamond", Block.Air, 2);
			Net.Actions["craft"] = OnCraft;
			Net.Actions["smelt"] = OnSmelt;
			furnacePrefab = BuildFurniture<FurnaceMarker>("MineCompany_Furnace", BlockModel.Cube(1f, "furnace_top", "furnace_top", "furnace_front", "furnace_side", "furnace_side", "furnace_side"));
			FurnaceUnlockable = Unlockable("Furnace", furnacePrefab);
			Unlockables.RegisterUnlockable(FurnaceUnlockable, (StoreType)1, (TerminalNode)null, (TerminalNode)null, (TerminalNode)null, Plugin.FurnacePrice);
			tablePrefab = BuildFurniture<TableMarker>("MineCompany_CraftingTable", BlockModel.Cube(1f, "crafting_table_top", "oak_planks", "crafting_table_front", "crafting_table_side", "crafting_table_side", "crafting_table_front"));
			TableUnlockable = Unlockable("Crafting table", tablePrefab);
			Unlockables.RegisterUnlockable(TableUnlockable, (StoreType)0, (TerminalNode)null, (TerminalNode)null, (TerminalNode)null, 0);
			static void Tool(string id, string mat, Block block, int n)
			{
				Recipe recipe = new Recipe
				{
					Name = Content.Get(id).Name,
					Result = id
				};
				if (mat != null)
				{
					recipe.Items = new(string, int)[2]
					{
						(mat, n),
						("stick", id.EndsWith("sword") ? 1 : 2)
					};
				}
				else
				{
					recipe.Blocks = new(Block, int)[1] { (block, n) };
					recipe.Items = new(string, int)[1] { ("stick", id.EndsWith("sword") ? 1 : 2) };
				}
				Recipes.Add(recipe);
			}
		}

		private static GameObject BuildFurniture<T>(string name, Mesh mesh) where T : StationMarker
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: 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_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = NetworkPrefabs.CreateNetworkPrefab(name);
			val.AddComponent<T>();
			AutoParentToShip parentObject = val.AddComponent<AutoParentToShip>();
			GameObject val2 = new GameObject("Model");
			val2.transform.SetParent(val.transform, false);
			MeshFilter val3 = val2.AddComponent<MeshFilter>();
			val3.sharedMesh = mesh;
			val2.AddComponent<MeshRenderer>();
			BoxCollider obj = val2.AddComponent<BoxCollider>();
			obj.center = new Vector3(0f, 0.5f, 0f);
			obj.size = Vector3.one;
			GameObject val4 = new GameObject("PlacementCollider")
			{
				layer = 26,
				tag = "PlaceableObject"
			};
			val4.transform.SetParent(val.transform, false);
			BoxCollider val5 = val4.AddComponent<BoxCollider>();
			val5.center = new Vector3(0f, 0.5f, 0f);
			val5.size = Vector3.one * 1.02f;
			val4.AddComponent<AudioSource>().playOnAwake = false;
			PlaceableShipObject obj2 = val4.AddComponent<PlaceableShipObject>();
			obj2.parentObject = parentObject;
			obj2.mainMesh = val3;
			obj2.mainTransform = val.transform;
			obj2.placeObjectCollider = (Collider)(object)val5;
			obj2.AllowPlacementOnCounters = false;
			return val;
		}

		private static UnlockableItem Unlockable(string name, GameObject prefab)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: 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)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Expected O, but got Unknown
			return new UnlockableItem
			{
				unlockableName = name,
				prefabObject = prefab,
				unlockableType = 1,
				IsPlaceable = true,
				spawnPrefab = true,
				alwaysInStock = true,
				canBeStored = true,
				maxNumber = 1
			};
		}

		internal static Material BlockMaterial()
		{
			Item? obj = ((IEnumerable<Item>)StartOfRound.Instance.allItemsList.itemsList).FirstOrDefault((Func<Item, bool>)((Item i) => i?.itemName == "Shovel"));
			object like;
			if (obj == null)
			{
				like = null;
			}
			else
			{
				MeshRenderer componentInChildren = obj.spawnPrefab.GetComponentInChildren<MeshRenderer>();
				like = ((componentInChildren != null) ? ((Renderer)componentInChildren).sharedMaterial : null);
			}
			return Atlas.Material((Material)like);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(StartOfRound), "Start")]
		private static void ShipStart(StartOfRound __instance)
		{
			//IL_0006: 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_012d: Unknown result type (might be due to invalid IL or missing references)
			Defaults(__instance, furnacePrefab, Plugin.FurnacePosition, Plugin.FurnaceYaw);
			Defaults(__instance, tablePrefab, Plugin.TablePosition, Plugin.TableYaw);
			PlaceableShipObject val = ((IEnumerable<PlaceableShipObject>)Object.FindObjectsOfType<PlaceableShipObject>()).FirstOrDefault((Func<PlaceableShipObject, bool>)((PlaceableShipObject o) => (Object)(object)o.placeObjectSFX != (Object)null && (Object)(object)((Component)o).GetComponentInParent<StationMarker>() == (Object)null));
			if ((Object)(object)val != (Object)null)
			{
				foreach (PlaceableShipObject item in ((IEnumerable<GameObject>)(object)new GameObject[2] { furnacePrefab, tablePrefab }).Select((GameObject g) => g.GetComponentInChildren<PlaceableShipObject>(true)).Concat(from m in Object.FindObjectsOfType<StationMarker>()
					select ((Component)m).GetComponentInChildren<PlaceableShipObject>()))
				{
					item.placeObjectSFX = val.placeObjectSFX;
					AudioSource component = ((Component)item).GetComponent<AudioSource>();
					AudioSource component2 = ((Component)val).GetComponent<AudioSource>();
					if ((Object)(object)component != (Object)null && (Object)(object)component2 != (Object)null)
					{
						component.outputAudioMixerGroup = component2.outputAudioMixerGroup;
						component.spatialBlend = component2.spatialBlend;
						component.maxDistance = component2.maxDistance;
						component.rolloffMode = component2.rolloffMode;
					}
				}
			}
			if (!((NetworkBehaviour)__instance).IsServer)
			{
				return;
			}
			int num = __instance.unlockablesList.unlockables.IndexOf(TableUnlockable);
			if (num < 0)
			{
				num = __instance.unlockablesList.unlockables.FindIndex((UnlockableItem u) => u.unlockableName == TableUnlockable.unlockableName);
			}
			if (num >= 0 && !__instance.unlockablesList.unlockables[num].hasBeenUnlockedByPlayer)
			{
				__instance.UnlockShipObject(num);
				Plugin.Log.LogInfo((object)$"Crafting table unlocked (unlockable #{num})");
			}
		}

		private static void Defaults(StartOfRound s, GameObject prefab, Vector3 pos, float yaw)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: 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)
			AutoParentToShip component = prefab.GetComponent<AutoParentToShip>();
			component.unlockableID = prefab.GetComponentInChildren<PlaceableShipObject>().unlockableID;
			component.overrideOffset = true;
			component.positionOffset = Floor(s.elevatorTransform, pos);
			component.rotationOffset = new Vector3(0f, yaw, 0f);
		}

		internal static Vector3 Front(Vector3 tablePos)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: 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)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: 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)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			Bounds bounds = StartOfRound.Instance.shipInnerRoomBounds.bounds;
			Vector3 val = ((Bounds)(ref bounds)).center - tablePos;
			val.y = 0f;
			return tablePos + ((Vector3)(ref val)).normalized * 1.1f + Vector3.up * 0.6f;
		}

		internal static Vector3 Floor(Transform ship, Vector3 local)
		{
			//IL_0001: 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)
			//IL_0012: 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)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: 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_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			RaycastHit val = default(RaycastHit);
			if (Physics.Raycast(ship.TransformPoint(new Vector3(local.x, 2.5f, local.z)), Vector3.down, ref val, 6f, StartOfRound.Instance.collidersAndRoomMaskAndDefault, (QueryTriggerInteraction)1))
			{
				return new Vector3(local.x, ship.InverseTransformPoint(((RaycastHit)(ref val)).point).y, local.z);
			}
			return local;
		}

		public static Station LookingAt(PlayerControllerB p, out Transform station)
		{
			//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)
			station = null;
			Transform transform = ((Component)p.gameplayCamera).transform;
			RaycastHit val = default(RaycastHit);
			if (!Physics.Raycast(transform.position, transform.forward, ref val, 3f, StartOfRound.Instance.collidersAndRoomMaskAndDefault | 0x4000000, (QueryTriggerInteraction)1))
			{
				return Station.None;
			}
			StationMarker componentInParent = ((Component)((RaycastHit)(ref val)).collider).GetComponentInParent<StationMarker>();
			if (componentInParent is TableMarker)
			{
				station = ((Component)componentInParent).transform;
				return Station.Table;
			}
			if (componentInParent is FurnaceMarker)
			{
				station = ((Component)componentInParent).transform;
				return Station.Furnace;
			}
			return Station.None;
		}

		public static List<GrabbableObject> Nearby(Vector3 pos, string id)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			return (from g in Object.FindObjectsOfType<GrabbableObject>()
				where !g.isHeld && !g.isPocketed && !g.deactivated && Content.Of(g.itemProperties)?.Id == id && Vector3.Distance(((Component)g).transform.position, pos) < 3f
				select g).ToList();
		}

		public static bool CanCraft(Recipe r, Vector3 at, out string missing)
		{
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			List<string> list = new List<string>();
			(Block, int)[] blocks = r.Blocks;
			for (int i = 0; i < blocks.Length; i++)
			{
				var (b, num) = blocks[i];
				if (Mining.Count(b) < num)
				{
					list.Add($"{num - Mining.Count(b)} {Mining.Name(b)}");
				}
			}
			(string, int)[] items = r.Items;
			for (int i = 0; i < items.Length; i++)
			{
				(string, int) tuple2 = items[i];
				string item = tuple2.Item1;
				int item2 = tuple2.Item2;
				int count = Nearby(at, item).Count;
				if (count < item2)
				{
					list.Add($"{item2 - count} {Content.Get(item).Name}");
				}
			}
			missing = string.Join(", ", list);
			return list.Count == 0;
		}

		public static void Craft(int index)
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			Recipe recipe = Recipes[index];
			if ((Object)(object)Table == (Object)null)
			{
				return;
			}
			if (!CanCraft(recipe, Table.position, out var missing))
			{
				Mining.Tip("Missing " + missing, 3f);
				return;
			}
			(Block, int)[] blocks;
			if (recipe.Result == null && recipe.Items.Length == 0)
			{
				blocks = recipe.Blocks;
				for (int i = 0; i < blocks.Length; i++)
				{
					var (key, num) = blocks[i];
					Mining.Stock[key] -= num;
				}
				Mining.AddStock(recipe.ResultBlock, recipe.Count);
				Mining.Tip($"+{recipe.Count} {Mining.Name(recipe.ResultBlock)}");
				return;
			}
			blocks = recipe.Blocks;
			for (int i = 0; i < blocks.Length; i++)
			{
				var (key2, num2) = blocks[i];
				Mining.Stock[key2] -= num2;
			}
			Vector3 pos = Table.position;
			Net.Action("craft", delegate(FastBufferWriter w)
			{
				//IL_000a: 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)
				((FastBufferWriter)(ref w)).WriteValueSafe<int>(ref index, default(ForPrimitives));
				((FastBufferWriter)(ref w)).WriteValueSafe(ref pos);
			});
		}

		private static void OnCraft(ulong sender, FastBufferReader r)
		{
			//IL_0006: 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)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			int num = default(int);
			((FastBufferReader)(ref r)).ReadValueSafe<int>(ref num, default(ForPrimitives));
			Vector3 val = default(Vector3);
			((FastBufferReader)(ref r)).ReadValueSafe(ref val);
			if (num < 0 || num >= Recipes.Count)
			{
				return;
			}
			Recipe recipe = Recipes[num];
			List<GrabbableObject> list = new List<GrabbableObject>();
			(string, int)[] items = recipe.Items;
			for (int i = 0; i < items.Length; i++)
			{
				(string, int) tuple = items[i];
				string item = tuple.Item1;
				int item2 = tuple.Item2;
				List<GrabbableObject> list2 = Nearby(val, item);
				if (list2.Count < item2)
				{
					Net.Reply(sender, "craft-fail", $"Missing {item2 - list2.Count} {Content.Get(item).Name}", num);
					return;
				}
				list.AddRange(list2.Take(item2));
			}
			foreach (GrabbableObject item3 in list)
			{
				Consume(item3);
			}
			if (recipe.Result == null)
			{
				Net.Reply(sender, "craft-block", $"+{recipe.Count} {Mining.Name(recipe.ResultBlock)}", num);
				return;
			}
			Def def = Content.Get(recipe.Result);
			for (int j = 0; j < recipe.Count; j++)
			{
				Content.Spawn(def, Front(val) + Random.insideUnitSphere * 0.15f, (!def.Tool) ? 2 : 0);
			}
			Net.Reply(sender, "craft-ok", "Crafted " + recipe.Name, num);
			Plugin.Log.LogInfo((object)$"Crafted {recipe.Name} for client {sender}");
		}

		internal static void OnReply(string kind, string text, int index)
		{
			Mining.Tip(text, 3f);
			if (kind == "craft-block" && index >= 0 && index < Recipes.Count)
			{
				Mining.AddStock(Recipes[index].ResultBlock, Recipes[index].Count);
			}
			if (kind == "craft-fail" && index >= 0 && index < Recipes.Count)
			{
				(Block, int)[] blocks = Recipes[index].Blocks;
				for (int i = 0; i < blocks.Length; i++)
				{
					var (b, n) = blocks[i];
					Mining.AddStock(b, n);
				}
			}
		}

		private static void Consume(GrabbableObject g)
		{
			NetworkObject networkObject = ((NetworkBehaviour)g).NetworkObject;
			if ((Object)(object)networkObject != (Object)null && networkObject.IsSpawned)
			{
				networkObject.Despawn(true);
			}
			else
			{
				Object.Destroy((Object)(object)((Component)g).gameObject);
			}
		}

		public static void Smelt(Transform furnace)
		{
			NetworkObject component = ((Component)furnace).GetComponent<NetworkObject>();
			if (!((Object)(object)component == (Object)null))
			{
				ulong id = component.NetworkObjectId;
				Net.Action("smelt", delegate(FastBufferWriter w)
				{
					//IL_000a: 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)
					((FastBufferWriter)(ref w)).WriteValueSafe<ulong>(ref id, default(ForPrimitives));
				});
			}
		}

		private static void OnSmelt(ulong sender, FastBufferReader r)
		{
			//IL_0006: 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)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: 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_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			ulong key = default(ulong);
			((FastBufferReader)(ref r)).ReadValueSafe<ulong>(ref key, default(ForPrimitives));
			if (!NetworkManager.Singleton.SpawnManager.SpawnedObjects.TryGetValue(key, out var value))
			{
				return;
			}
			Vector3 position = ((Component)value).transform.position;
			List<GrabbableObject> list = Nearby(position, "coal");
			List<GrabbableObject> list2 = Nearby(position, "raw_iron").Concat(Nearby(position, "raw_gold")).ToList();
			if (list2.Count == 0)
			{
				Net.Reply(sender, "smelt", "Drop raw iron or raw gold next to the furnace", -1);
				return;
			}
			if (list.Count == 0)
			{
				Net.Reply(sender, "smelt", "The furnace needs coal", -1);
				return;
			}
			int num = list.Count * Plugin.SmeltsPerCoal;
			int num2 = 0;
			int num3 = 0;
			int num4 = 0;
			foreach (GrabbableObject item in list2)
			{
				if (num2 >= num)
				{
					break;
				}
				if (num2 % Plugin.SmeltsPerCoal == 0)
				{
					num4 = list[num3].scrapValue / Plugin.SmeltsPerCoal;
					Consume(list[num3++]);
				}
				bool flag = Content.Of(item.itemProperties).Id == "raw_iron";
				int num5 = Mathf.RoundToInt((float)item.scrapValue * 1.5f) + num4;
				Consume(item);
				Content.Spawn(Content.Get(flag ? "iron_ingot" : "gold_ingot"), Front(position), Mathf.Max(1, num5));
				num2++;
			}
			Net.Reply(sender, "smelt", string.Format("Smelted {0} ingot{1}", num2, (num2 == 1) ? "" : "s"), -1);
			Plugin.Log.LogInfo((object)$"Smelted {num2} for client {sender} using {num3} coal");
		}
	}
	internal static class CraftMenu
	{
		private static PlayerControllerB player;

		private static Vector2 scroll;

		private static GUIStyle label;

		private static GUIStyle button;

		private static GUIStyle title;

		private static float openedAt;

		public static bool Open { get; private set; }

		public static void Show(PlayerControllerB p)
		{
			Open = true;
			player = p;
			openedAt = Time.time;
			p.disableLookInput = true;
			p.disableMoveInput = true;
			Cursor.lockState = (CursorLockMode)0;
			Cursor.visible = true;
		}

		public static void Close()
		{
			if (Open)
			{
				Open = false;
				if ((Object)(object)player != (Object)null)
				{
					player.disableLookInput = false;
					player.disableMoveInput = false;
				}
				Cursor.lockState = (CursorLockMode)1;
				Cursor.visible = false;
			}
		}

		public static void Update(PlayerControllerB p)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			Keyboard current = Keyboard.current;
			if ((Object)(object)Crafting.Table == (Object)null || Vector3.Distance(((Component)p).transform.position, Crafting.Table.position) > 4f || p.isPlayerDead || (current != null && ((ButtonControl)current.escapeKey).wasPressedThisFrame) || (Time.time - openedAt > 0.2f && Mining.Interact()))
			{
				Close();
			}
		}

		public static void Draw()
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Expected O, but got Unknown
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Expected O, but got Unknown
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Expected O, but got Unknown
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)Crafting.Table == (Object)null)
			{
				Close();
				return;
			}
			float num = (float)Screen.height / 720f;
			if (label == null)
			{
				label = new GUIStyle(GUI.skin.label)
				{
					wordWrap = true
				};
			}
			if (button == null)
			{
				button = new GUIStyle(GUI.skin.button);
			}
			if (title == null)
			{
				title = new GUIStyle(GUI.skin.label)
				{
					fontStyle = (FontStyle)1,
					alignment = (TextAnchor)4
				};
			}
			GUIStyle obj = label;
			int fontSize = (button.fontSize = Mathf.RoundToInt(15f * num));
			obj.fontSize = fontSize;
			title.fontSize = Mathf.RoundToInt(20f * num);
			float num3 = 560f * num;
			float num4 = 470f * num;
			Rect val = default(Rect);
			((Rect)(ref val))..ctor(((float)Screen.width - num3) / 2f, ((float)Screen.height - num4) / 2f, num3, num4);
			GUI.color = new Color(1f, 1f, 1f, 0.97f);
			GUI.Box(val, "");
			GUI.Box(val, "");
			GUILayout.BeginArea(new Rect(((Rect)(ref val)).x + 12f * num, ((Rect)(ref val)).y + 10f * num, ((Rect)(ref val)).width - 24f * num, ((Rect)(ref val)).height - 20f * num));
			GUILayout.Label("Crafting table", title, Array.Empty<GUILayoutOption>());
			GUILayout.Label("Blocks come from your block stock. Drop items (sticks, ingots, diamonds) on the floor next to the table.", label, Array.Empty<GUILayoutOption>());
			scroll = GUILayout.BeginScrollView(scroll, Array.Empty<GUILayoutOption>());
			Vector3 position = Crafting.Table.position;
			for (int i = 0; i < Crafting.Recipes.Count; i++)
			{
				Recipe recipe = Crafting.Recipes[i];
				string missing;
				bool flag = Crafting.CanCraft(recipe, position, out missing);
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				GUI.enabled = flag;
				if (GUILayout.Button(recipe.Name, button, (GUILayoutOption[])(object)new GUILayoutOption[2]
				{
					GUILayout.Width(170f * num),
					GUILayout.Height(30f * num)
				}))
				{
					Crafting.Craft(i);
				}
				GUI.enabled = true;
				GUILayout.Label(flag ? recipe.Cost : (recipe.Cost + "  <color=#ff7755>missing " + missing + "</color>"), label, Array.Empty<GUILayoutOption>());
				GUILayout.EndHorizontal();
			}
			GUILayout.EndScrollView();
			GUILayout.Label("[E] or [Esc] to close", label, Array.Empty<GUILayoutOption>());
			GUILayout.EndArea();
		}
	}
	internal static class Fallback
	{
		private static readonly Dictionary<string, Color32> Base = new Dictionary<string, Color32>
		{
			["grass_block_top"] = new Color32((byte)150, (byte)150, (byte)150, byte.MaxValue),
			["dirt"] = new Color32((byte)134, (byte)96, (byte)67, byte.MaxValue),
			["coarse_dirt"] = new Color32((byte)119, (byte)85, (byte)59, byte.MaxValue),
			["stone"] = new Color32((byte)125, (byte)125, (byte)125, byte.MaxValue),
			["cobblestone"] = new Color32((byte)118, (byte)118, (byte)118, byte.MaxValue),
			["bedrock"] = new Color32((byte)70, (byte)70, (byte)70, byte.MaxValue),
			["sand"] = new Color32((byte)219, (byte)207, (byte)163, byte.MaxValue),
			["sandstone"] = new Color32((byte)216, (byte)203, (byte)155, byte.MaxValue),
			["sandstone_top"] = new Color32((byte)222, (byte)210, (byte)165, byte.MaxValue),
			["sandstone_bottom"] = new Color32((byte)210, (byte)196, (byte)148, byte.MaxValue),
			["red_sand"] = new Color32((byte)190, (byte)102, (byte)33, byte.MaxValue),
			["terracotta"] = new Color32((byte)152, (byte)94, (byte)67, byte.MaxValue),
			["snow"] = new Color32((byte)240, (byte)250, (byte)250, byte.MaxValue),
			["gravel"] = new Color32((byte)131, (byte)127, (byte)126, byte.MaxValue),
			["oak_planks"] = new Color32((byte)162, (byte)130, (byte)78, byte.MaxValue),
			["oak_log"] = new Color32((byte)109, (byte)85, (byte)50, byte.MaxValue),
			["oak_log_top"] = new Color32((byte)151, (byte)122, (byte)72, byte.MaxValue),
			["oak_leaves"] = new Color32((byte)150, (byte)150, (byte)150, byte.MaxValue),
			["deepslate"] = new Color32((byte)80, (byte)80, (byte)82, byte.MaxValue),
			["deepslate_top"] = new Color32((byte)84, (byte)84, (byte)86, byte.MaxValue),
			["crafting_table_top"] = new Color32((byte)160, (byte)120, (byte)70, byte.MaxValue),
			["crafting_table_front"] = new Color32((byte)140, (byte)105, (byte)60, byte.MaxValue),
			["crafting_table_side"] = new Color32((byte)140, (byte)105, (byte)60, byte.MaxValue),
			["furnace_front"] = new Color32((byte)110, (byte)110, (byte)110, byte.MaxValue),
			["furnace_side"] = new Color32((byte)110, (byte)110, (byte)110, byte.MaxValue),
			["furnace_top"] = new Color32((byte)120, (byte)120, (byte)120, byte.MaxValue)
		};

		private static readonly Dictionary<string, Color32> Specks = new Dictionary<string, Color32>
		{
			["coal_ore"] = new Color32((byte)40, (byte)40, (byte)40, byte.MaxValue),
			["iron_ore"] = new Color32((byte)216, (byte)175, (byte)147, byte.MaxValue),
			["gold_ore"] = new Color32((byte)252, (byte)238, (byte)75, byte.MaxValue),
			["diamond_ore"] = new Color32((byte)93, (byte)236, (byte)245, byte.MaxValue)
		};

		public static Texture2D Paint(string name)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0311: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_034f: Unknown result type (might be due to invalid IL or missing references)
			//IL_033e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0223: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: Unknown result type (might be due to invalid IL or missing references)
			//IL_022d: Unknown result type (might be due to invalid IL or missing references)
			//IL_022e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			//IL_0235: 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_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_023a: 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_0241: Unknown result type (might be due to invalid IL or missing references)
			//IL_0354: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_026d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0274: Unknown result type (might be due to invalid IL or missing references)
			//IL_0279: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0380: Unknown result type (might be due to invalid IL or missing references)
			//IL_0396: Unknown result type (might be due to invalid IL or missing references)
			//IL_039b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_0436: Unknown result type (might be due to invalid IL or missing references)
			//IL_043d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0442: Unknown result type (might be due to invalid IL or missing references)
			//IL_0443: Unknown result type (might be due to invalid IL or missing references)
			//IL_0445: Unknown result type (might be due to invalid IL or missing references)
			//IL_044a: Unknown result type (might be due to invalid IL or missing references)
			//IL_044c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0483: Unknown result type (might be due to invalid IL or missing references)
			//IL_048a: Unknown result type (might be due to invalid IL or missing references)
			//IL_048f: Unknown result type (might be due to invalid IL or missing references)
			//IL_053d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0544: Unknown result type (might be due to invalid IL or missing references)
			//IL_0549: Unknown result type (might be due to invalid IL or missing references)
			//IL_054a: Unknown result type (might be due to invalid IL or missing references)
			//IL_054c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0551: Unknown result type (might be due to invalid IL or missing references)
			//IL_0553: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_04fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0500: Unknown result type (might be due to invalid IL or missing references)
			//IL_058f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0594: Unknown result type (might be due to invalid IL or missing references)
			if (name == "entity/creeper/creeper")
			{
				return Creeper();
			}
			Texture2D val = new Texture2D(16, 16, (TextureFormat)4, false);
			Color32[] array = (Color32[])(object)new Color32[256];
			string text = (name.StartsWith("item/") ? name.Substring(5) : (name.StartsWith("block/") ? name.Substring(6) : name));
			Color32 value;
			if (name.StartsWith("item/"))
			{
				PaintItem(text, array);
			}
			else if (Specks.TryGetValue(text, out value))
			{
				Noise(array, Base["stone"], text.GetHashCode(), 18);
				Random random = new Random(text.GetHashCode());
				for (int i = 0; i < 6; i++)
				{
					int num = random.Next(1, 14);
					int num2 = random.Next(1, 14);
					array[num2 * 16 + num] = value;
					array[num2 * 16 + num + 1] = value;
					array[(num2 + 1) * 16 + num] = Shade(value, 0.8f);
				}
			}
			else if (text == "torch")
			{
				for (int j = 0; j < 256; j++)
				{
					array[j] = new Color32((byte)0, (byte)0, (byte)0, (byte)0);
				}
				for (int k = 0; k < 10; k++)
				{
					for (int l = 7; l < 9; l++)
					{
						array[k * 16 + l] = (Color32)((k >= 8) ? new Color32(byte.MaxValue, (byte)216, (byte)60, byte.MaxValue) : Shade(new Color32((byte)110, (byte)80, (byte)40, byte.MaxValue), (l == 7) ? 1f : 0.8f));
					}
				}
			}
			else if (text.StartsWith("chest_"))
			{
				Color32 c = default(Color32);
				((Color32)(ref c))..ctor((byte)160, (byte)112, (byte)46, byte.MaxValue);
				Noise(array, c, text.GetHashCode(), 14);
				for (int m = 0; m < 16; m++)
				{
					array[m] = (array[240 + m] = (array[m * 16] = (array[m * 16 + 15] = Shade(c, 0.45f))));
				}
				if (text != "chest_top")
				{
					for (int n = 0; n < 16; n++)
					{
						array[144 + n] = Shade(c, 0.45f);
					}
				}
				if (text == "chest_front")
				{
					for (int num3 = 9; num3 < 13; num3++)
					{
						for (int num4 = 7; num4 < 9; num4++)
						{
							array[num3 * 16 + num4] = new Color32((byte)190, (byte)190, (byte)190, byte.MaxValue);
						}
					}
				}
			}
			else if (text == "grass_block_side" || text == "grass_block_snow")
			{
				Noise(array, Base["dirt"], text.GetHashCode(), 22);
				Color32 c2 = (Color32)((text == "grass_block_snow") ? Base["snow"] : new Color32((byte)121, (byte)192, (byte)90, byte.MaxValue));
				Random random2 = new Random(7);
				for (int num5 = 0; num5 < 16; num5++)
				{
					int num6 = 0;
					for (int num7 = 3 + random2.Next(3); num6 < num7; num6++)
					{
						array[(15 - num6) * 16 + num5] = Shade(c2, 0.9f + (float)random2.NextDouble() * 0.15f);
					}
				}
			}
			else
			{
				Color32 value2;
				Color32 c3 = (Color32)(Base.TryGetValue(text, out value2) ? value2 : new Color32((byte)200, (byte)0, (byte)200, byte.MaxValue));
				Noise(array, c3, text.GetHashCode(), (text == "snow" || text == "sand") ? 10 : 24);
				if (text == "oak_planks")
				{
					for (int num8 = 0; num8 < 16; num8++)
					{
						array[48 + num8] = (array[176 + num8] = Shade(c3, 0.7f));
					}
				}
				if (text == "cobblestone")
				{
					for (int num9 = 0; num9 < 256; num9++)
					{
						if ((num9 * 7 + num9 / 16 * 5) % 11 == 0)
						{
							array[num9] = Shade(c3, 0.65f);
						}
					}
				}
				if (text == "oak_log_top")
				{
					for (int num10 = 0; num10 < 16; num10++)
					{
						for (int num11 = 0; num11 < 16; num11++)
						{
							if ((int)Mathf.Sqrt(((float)num11 - 7.5f) * ((float)num11 - 7.5f) + ((float)num10 - 7.5f) * ((float)num10 - 7.5f)) % 3 == 0)
							{
								array[num10 * 16 + num11] = Shade(c3, 0.8f);
							}
						}
					}
				}
				if (text == "crafting_table_top")
				{
					for (int num12 = 0; num12 < 16; num12++)
					{
						array[num12 * 16 + 7] = (array[112 + num12] = Shade(c3, 0.6f));
					}
				}
				if (text == "furnace_front")
				{
					for (int num13 = 2; num13 < 7; num13++)
					{
						for (int num14 = 4; num14 < 12; num14++)
						{
							array[num13 * 16 + num14] = new Color32((byte)30, (byte)30, (byte)30, byte.MaxValue);
						}
					}
				}
			}
			val.SetPixels32(array);
			val.Apply();
			return val;
		}

		private static Texture2D Creeper()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//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)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(64, 32, (TextureFormat)4, false);
			Color32[] px = (Color32[])(object)new Color32[2048];
			Random random = new Random(3);
			for (int i = 0; i < px.Length; i++)
			{
				int num = random.Next(10);
				px[i] = ((num < 5) ? new Color32((byte)94, (byte)168, (byte)76, byte.MaxValue) : ((num < 8) ? new Color32((byte)70, (byte)140, (byte)58, byte.MaxValue) : new Color32((byte)150, (byte)200, (byte)130, byte.MaxValue)));
			}
			for (int j = 10; j < 12; j++)
			{
				Dark(9, j);
				Dark(10, j);
				Dark(13, j);
				Dark(14, j);
			}
			for (int k = 12; k < 16; k++)
			{
				Dark(11, k);
				Dark(12, k);
			}
			for (int l = 13; l < 16; l++)
			{
				Dark(10, l);
				Dark(13, l);
			}
			val.SetPixels32(px);
			val.Apply();
			return val;
			void Dark(int x, int y)
			{
				//IL_001a: Unknown result type (might be due to invalid IL or missing references)
				//IL_001f: Unknown result type (might be due to invalid IL or missing references)
				px[(31 - y) * 64 + x] = new Color32((byte)12, (byte)12, (byte)12, byte.MaxValue);
			}
		}

		private static void Noise(Color32[] px, Color32 c, int seed, int amount)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			Random random = new Random(seed);
			for (int i = 0; i < 256; i++)
			{
				px[i] = Shade(c, 1f + (float)random.Next(-amount, amount + 1) / 255f * 2f);
			}
		}

		private static Color32 Shade(Color32 c, float k)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			return new Color32((byte)Mathf.Clamp((float)(int)c.r * k, 0f, 255f), (byte)Mathf.Clamp((float)(int)c.g * k, 0f, 255f), (byte)Mathf.Clamp((float)(int)c.b * k, 0f, 255f), c.a);
		}

		private static void PaintItem(string n, Color32[] px)
		{
			//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)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_021c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: Unknown result type (might be due to invalid IL or missing references)
			//IL_023c: Unknown result type (might be due to invalid IL or missing references)
			//IL_026a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0278: Unknown result type (might be due to invalid IL or missing references)
			//IL_027e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0290: Unknown result type (might be due to invalid IL or missing references)
			//IL_0296: Unknown result type (might be due to invalid IL or missing references)
			//IL_0363: Unknown result type (might be due to invalid IL or missing references)
			//IL_0378: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c1: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < 256; i++)
			{
				px[i] = new Color32((byte)0, (byte)0, (byte)0, (byte)0);
			}
			Color32 c = (Color32)(n.StartsWith("wooden") ? Base["oak_planks"] : (n.StartsWith("stone") ? Base["cobblestone"] : (n.StartsWith("iron") ? new Color32((byte)216, (byte)216, (byte)216, byte.MaxValue) : ((n.StartsWith("golden") || n.StartsWith("gold")) ? new Color32((byte)250, (byte)220, (byte)60, byte.MaxValue) : (n.StartsWith("diamond") ? new Color32((byte)80, (byte)230, (byte)220, byte.MaxValue) : (n.StartsWith("coal") ? new Color32((byte)45, (byte)45, (byte)45, byte.MaxValue) : (n.StartsWith("raw_iron") ? new Color32((byte)200, (byte)160, (byte)130, byte.MaxValue) : new Color32((byte)140, (byte)100, (byte)60, byte.MaxValue))))))));
			Color32 c2 = default(Color32);
			((Color32)(ref c2))..ctor((byte)110, (byte)80, (byte)40, byte.MaxValue);
			if (n.EndsWith("pickaxe") || n.EndsWith("sword") || n == "stick")
			{
				int num = ((n == "stick") ? 14 : (n.EndsWith("sword") ? 5 : 11));
				for (int j = 0; j < num; j++)
				{
					P(1 + j, 1 + j, c2);
					P(2 + j, 1 + j, Shade(c2, 0.7f));
				}
				if (n.EndsWith("pickaxe"))
				{
					for (int k = 0; k < 11; k++)
					{
						P(4 + k, 14 - Mathf.Abs(k - 5) / 2 - 1, c);
						P(4 + k, 14 - Mathf.Abs(k - 5) / 2, Shade(c, 0.75f));
					}
				}
				if (n.EndsWith("sword"))
				{
					for (int l = 5; l < 15; l++)
					{
						P(l, l, c);
						P(l + 1, l, Shade(c, 0.8f));
						P(l, l - 1, Shade(c, 1.1f));
					}
					for (int m = 0; m < 5; m++)
					{
						P(2 + m, 8 - m, Shade(c, 0.6f));
					}
				}
				return;
			}
			bool flag = n.EndsWith("ingot");
			for (int num2 = 0; num2 < 16; num2++)
			{
				for (int num3 = 0; num3 < 16; num3++)
				{
					bool num4;
					if (!flag)
					{
						num4 = ((float)num3 - 7.5f) * ((float)num3 - 7.5f) + ((float)num2 - 7.5f) * ((float)num2 - 7.5f) < (float)(30 + (num3 * 13 + num2 * 7) % 9);
					}
					else
					{
						if (num3 < 2 || num3 > 13 || num2 < 5 || num2 > 10)
						{
							continue;
						}
						num4 = num3 - 2 >= (10 - num2) / 2;
					}
					if (num4)
					{
						P(num3, num2, Shade(c, 0.85f + (float)((num3 + num2) % 4) * 0.07f));
					}
				}
			}
			P(6, 10, Color32.op_Implicit(Color.white));
			P(7, 10, Shade(c, 1.3f));
			void P(int x, int y, Color32 val)
			{
				//IL_001e: Unknown result type (might be due to invalid IL or missing references)
				//IL_001f: Unknown result type (might be due to invalid IL or missing references)
				if (x >= 0 && x < 16 && y >= 0 && y < 16)
				{
					px[y * 16 + x] = val;
				}
			}
		}
	}
	public static class McAssets
	{
		private static readonly Dictionary<string, Texture2D> cache = new Dictionary<string, Texture2D>();

		private static ZipArchive jar;

		private static bool searched;

		private static string jarPath;

		public static string Source { get; private set; } = "fallback art";

		public static string JarPath
		{
			get
			{
				Jar();
				return jarPath;
			}
		}

		public static string MinecraftDir
		{
			get
			{
				string minecraftDirConfig = Plugin.MinecraftDirConfig;
				if (!string.IsNullOrWhiteSpace(minecraftDirConfig))
				{
					return minecraftDirConfig;
				}
				return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), ".minecraft");
			}
		}

		private static ZipArchive Jar()
		{
			if (searched)
			{
				return jar;
			}
			searched = true;
			try
			{
				string path = Path.Combine(MinecraftDir, "versions");
				if (!Directory.Exists(path))
				{
					return null;
				}
				var anon = (from d in Directory.GetDirectories(path)
					select new
					{
						dir = d,
						name = Path.GetFileName(d),
						jar = Path.Combine(d, Path.GetFileName(d) + ".jar")
					} into v
					where File.Exists(v.jar) && Regex.IsMatch(v.name, "^\\d+(\\.\\d+){1,2}$")
					orderby Version(v.name) descending
					select v).FirstOrDefault();
				if (anon == null)
				{
					return null;
				}
				jar = ZipFile.OpenRead(anon.jar);
				jarPath = anon.jar;
				Source = "Minecraft " + anon.name + " (your install)";
				Plugin.Log.LogInfo((object)("Using Minecraft textures from " + anon.jar));
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Could not open a Minecraft jar, using fallback art: " + ex.Message));
				jar = null;
			}
			return jar;
		}

		private static long Version(string v)
		{
			long num = 0L;
			foreach (string item in (v + ".0.0").Split('.').Take(3))
			{
				num = num * 10000 + (long.TryParse(item, out var result) ? result : 0);
			}
			return num;
		}

		public static Texture2D Texture(string name)
		{
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Expected O, but got Unknown
			if (cache.TryGetValue(name, out var value))
			{
				return value;
			}
			string entryName = (name.Contains("/") ? ("assets/minecraft/textures/" + name + ".png") : ("assets/minecraft/textures/block/" + name + ".png"));
			byte[] array = null;
			ZipArchive zipArchive = Jar();
			if (zipArchive != null && !Plugin.ForceFallbackArt)
			{
				ZipArchiveEntry entry = zipArchive.GetEntry(entryName);
				if (entry != null)
				{
					using Stream stream = entry.Open();
					using MemoryStream memoryStream = new MemoryStream();
					stream.CopyTo(memoryStream);
					array = memoryStream.ToArray();
				}
			}
			if (array != null)
			{
				value = new Texture2D(2, 2, (TextureFormat)4, false);
				ImageConversion.LoadImage(value, array);
				if (((Texture)value).height > ((Texture)value).width)
				{
					Crop(ref value);
				}
			}
			else
			{
				value = Fallback.Paint(name);
			}
			((Texture)value).filterMode = (FilterMode)0;
			((Texture)value).wrapMode = (TextureWrapMode)1;
			((Object)value).name = name;
			cache[name] = value;
			return value;
		}

		private static void Crop(ref Texture2D t)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			Texture2D val = new Texture2D(((Texture)t).width, ((Texture)t).width, (TextureFormat)4, false);
			val.SetPixels(t.GetPixels(0, ((Texture)t).height - ((Texture)t).width, ((Texture)t).width, ((Texture)t).width));
			val.Apply();
			t = val;
		}

		public static byte[] JarFile(string path)
		{
			ZipArchiveEntry zipArchiveEntry = Jar()?.GetEntry(path);
			if (zipArchiveEntry == null)
			{
				return null;
			}
			using Stream stream = zipArchiveEntry.Open();
			using MemoryStream memoryStream = new MemoryStream();
			stream.CopyTo(memoryStream);
			return memoryStream.ToArray();
		}
	}
	[HarmonyPatch]
	public static class Mining
	{
		private class Hud : MonoBehaviour
		{
			private static Hud instance;

			private GUIStyle style;

			public static void Ensure()
			{
				//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_0020: Unknown result type (might be due to invalid IL or missing references)
				//IL_0026: Expected O, but got Unknown
				if (!((Object)(object)instance != (Object)null))
				{
					GameObject val = new GameObject("MineCompanyHud")
					{
						hideFlags = (HideFlags)61
					};
					Object.DontDestroyOnLoad((Object)val);
					instance = val.AddComponent<Hud>();
				}
			}

			private void OnGUI()
			{
				//IL_0051: Unknown result type (might be due to invalid IL or missing references)
				//IL_0056: Unknown result type (might be due to invalid IL or missing references)
				//IL_005d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0069: Expected O, but got Unknown
				//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f1: 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_0136: Unknown result type (might be due to invalid IL or missing references)
				if (CraftMenu.Open)
				{
					CraftMenu.Draw();
					return;
				}
				PlayerControllerB val = GameNetworkManager.Instance?.localPlayerController;
				if (!((Object)(object)val == (Object)null) && !val.isPlayerDead && !((Object)(object)StartOfRound.Instance == (Object)null))
				{
					if (style == null)
					{
						style = new GUIStyle(GUI.skin.label)
						{
							alignment = (TextAnchor)4,
							fontStyle = (FontStyle)1
						};
					}
					style.fontSize = Mathf.RoundToInt((float)Screen.height / 42f);
					float num = (float)Screen.height * 0.72f;
					float num2 = (float)style.fontSize * 1.6f;
					if (Count(Selected) > 0)
					{
						Label(new Rect(0f, num, (float)Screen.width, num2), $"{Name(Selected)} x{Count(Selected)}    [{Plugin.PlaceKey}] place   [{Plugin.CycleKey}] switch");
					}
					if (tip != null && Time.time < tipUntil)
					{
						Label(new Rect(0f, num - num2, (float)Screen.width, num2), tip);
					}
				}
			}

			private void Label(Rect r, string text)
			{
				//IL_001f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0051: Unknown result type (might be due to invalid IL or missing references)
				//IL_0081: 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)
				style.normal.textColor = new Color(0f, 0f, 0f, 0.8f);
				GUI.Label(new Rect(((Rect)(ref r)).x + 2f, ((Rect)(ref r)).y + 2f, ((Rect)(ref r)).width, ((Rect)(ref r)).height), text, style);
				style.normal.textColor = new Color(1f, 0.55f, 0.2f, 1f);
				GUI.Label(r, text, style);
			}
		}

		public static readonly Dictionary<Block, int> Stock = new Dictionary<Block, int>();

		public static Block Selected = Block.Air;

		private static Vector3Int target;

		private static BlockGroup targetGroup;

		private static int hits;

		private static float nextPunch;

		private static string tip;

		private static float tipUntil;

		private static readonly float[] Speed = new float[5] { 1f, 1f, 1.5f, 2f, 3f };

		private static readonly string[] TierNames = new string[5] { "", "wooden", "stone", "iron", "diamond" };

		private const float Reach = 3.6f;

		private const float PlaceReach = 4.5f;

		public static void Tip(string text, float seconds = 2f)
		{
			tip = text;
			tipUntil = Time.time + seconds;
		}

		public static void AddStock(Block b, int n)
		{
			Stock.TryGetValue(b, out var value);
			Stock[b] = value + n;
			if (Selected == Block.Air || !Stock.TryGetValue(Selected, out var value2) || value2 <= 0)
			{
				Selected = b;
			}
		}

		public static int Count(Block b)
		{
			if (!Stock.TryGetValue(b, out var value))
			{
				return 0;
			}
			return value;
		}

		public static bool Look(PlayerControllerB p, float range, out BlockGroup group, out Vector3Int hit, out Vector3Int before, out RaycastHit h)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0011: 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)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: 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_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: 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_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: 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_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: 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_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_0220: Unknown result type (might be due to invalid IL or missing references)
			//IL_0225: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: 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)
			group = null;
			hit = (before = default(Vector3Int));
			h = default(RaycastHit);
			Transform transform = ((Component)p.gameplayCamera).transform;
			RaycastHit[] source = Physics.RaycastAll(transform.position, transform.forward, range, StartOfRound.Instance.collidersAndRoomMaskAndDefault | 4, (QueryTriggerInteraction)2);
			bool flag = false;
			foreach (RaycastHit item in source.OrderBy((RaycastHit x) => ((RaycastHit)(ref x)).distance))
			{
				RaycastHit current = item;
				if ((!((RaycastHit)(ref current)).collider.isTrigger || !((Object)(object)((Component)((RaycastHit)(ref current)).collider).GetComponent<BlockGroup.TorchHit>() == (Object)null)) && !((Component)((RaycastHit)(ref current)).collider).transform.IsChildOf(((Component)p).transform))
				{
					h = current;
					flag = true;
					break;
				}
			}
			if (!flag)
			{
				return false;
			}
			BlockGroup.TorchHit component = ((Component)((RaycastHit)(ref h)).collider).GetComponent<BlockGroup.TorchHit>();
			if ((Object)(object)component != (Object)null)
			{
				group = component.Group;
				hit = (before = component.Cell);
				return true;
			}
			group = ((Component)((RaycastHit)(ref h)).collider).GetComponentInParent<BlockGroup>();
			if ((Object)(object)group == (Object)null)
			{
				return true;
			}
			hit = group.CellAt(((RaycastHit)(ref h)).point - ((RaycastHit)(ref h)).normal * 0.01f);
			before = group.CellAt(((RaycastHit)(ref h)).point + ((RaycastHit)(ref h)).normal * 0.01f);
			if (group.Get(hit) == Block.Air)
			{
				Vector3Int[] array = (Vector3Int[])(object)new Vector3Int[6]
				{
					Vector3Int.right,
					Vector3Int.left,
					Vector3Int.up,
					Vector3Int.down,
					new Vector3Int(0, 0, 1),
					new Vector3Int(0, 0, -1)
				};
				foreach (Vector3Int val in array)
				{
					if (group.Get(hit + val) != Block.Air)
					{
						hit += val;
						break;
					}
				}
			}
			return true;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Shovel), "HitShovel")]
		private static void Swing(Shovel __instance, bool cancel)
		{
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			if (cancel)
			{
				return;
			}
			PlayerControllerB previousPlayerHeldBy = __instance.previousPlayerHeldBy;
			if ((Object)(object)previousPlayerHeldBy == (Object)null || (Object)(object)previousPlayerHeldBy != (Object)(object)GameNetworkManager.Instance.localPlayerController)
			{
				return;
			}
			int num = 0;
			bool flag = false;
			float speed;
			if (__instance is McTool mcTool)
			{
				if (mcTool.Def == null)
				{
					return;
				}
				flag = mcTool.Def.Kind == Kind.Pickaxe;
				num = (flag ? mcTool.Def.Tier : 0);
				speed = (flag ? Speed[Mathf.Clamp(num, 0, 4)] : 1f);
			}
			else
			{
				speed = 2f;
			}
			if (Look(previousPlayerHeldBy, 3.6f, out var group, out var hit, out var _, out var _) && !((Object)(object)group == (Object)null))
			{
				MineAt(group, hit, num, speed, flag);
			}
		}

		public static bool MineAt(BlockGroup g, Vector3Int cell, int tier, float speed, bool pickaxe)
		{
			//IL_0001: 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)
			//IL_0098: 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_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			Block block = g.Get(cell);
			if (block == Block.Air)
			{
				return false;
			}
			int num = Blocks.Hardness[(uint)block];
			int num2 = Blocks.Tier[(uint)block];
			if (num == 0)
			{
				Tip("Unbreakable");
				return false;
			}
			if (num2 > 0 && !pickaxe)
			{
				Tip("Needs a pickaxe");
				return false;
			}
			if (num2 > tier)
			{
				Tip("Needs a " + TierNames[Mathf.Clamp(num2, 1, 4)] + " pickaxe");
				return false;
			}
			if ((Object)(object)g != (Object)(object)targetGroup || cell != target)
			{
				targetGroup = g;
				target = cell;
				hits = 0;
			}
			int num3 = Mathf.Max(1, Mathf.CeilToInt((float)num / speed));
			if (++hits < num3)
			{
				Tip(Name(block) + "  " + new string('#', hits) + new string('-', num3 - hits), 1.5f);
				return false;
			}
			hits = 0;
			Net.Edit(g, cell, Block.Air, mined: true);
			if (!Blocks.IsOre(block) && Blocks.Drop(block) != Block.Air)
			{
				Block b = Blocks.Drop(block);
				AddStock(b, 1);
				Tip("+1 " + Name(b), 1f);
			}
			return true;
		}

		public static string Name(Block b)
		{
			switch (b)
			{
			case Block.CoalOre:
				return "Coal ore";
			case Block.IronOre:
				return "Iron ore";
			case Block.GoldOre:
				return "Gold ore";
			case Block.DiamondOre:
				return "Diamond ore";
			case Block.RedSand:
				return "Red sand";
			case Block.SnowyGrass:
				return "Snowy grass";
			case Block.CoarseDirt:
				return "Coarse dirt";
			case Block.Torch:
			case Block.TorchPX:
			case Block.TorchNX:
			case Block.TorchPZ:
			case Block.TorchNZ:
				return "Torch";
			default:
				return b.ToString();
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(PlayerControllerB), "Update")]
		private static void Tick(PlayerControllerB __instance)
		{
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)__instance != (Object)(object)GameNetworkManager.Instance?.localPlayerController)
			{
				return;
			}
			Hud.Ensure();
			Keyboard current = Keyboard.current;
			if (CraftMenu.Open)
			{
				CraftMenu.Update(__instance);
			}
			else
			{
				if (current == null || __instance.isPlayerDead || __instance.isTypingChat || __instance.inTerminalMenu || ((Object)(object)__instance.quickMenuManager != (Object)null && __instance.quickMenuManager.isMenuOpen))
				{
					return;
				}
				Transform station2;
				Crafting.Station station = Crafting.LookingAt(__instance, out station2);
				if (station != Crafting.Station.None)
				{
					((TMP_Text)__instance.cursorTip).text = ((station == Crafting.Station.Table) ? "Craft : [E]" : "Smelt ores : [E]");
					if (Interact())
					{
						if (station == Crafting.Station.Table)
						{
							CraftMenu.Show(__instance);
						}
						else
						{
							Crafting.Smelt(station2);
						}
					}
				}
				if (((ButtonControl)current[Plugin.CycleKey]).wasPressedThisFrame)
				{
					Cycle();
				}
				if (((ButtonControl)current[Plugin.PlaceKey]).wasPressedThisFrame)
				{
					Place(__instance);
				}
				if ((Object)(object)__instance.currentlyHeldObjectServer == (Object)null && !__instance.inSpecialInteractAnimation && !__instance.isClimbingLadder)
				{
					Punch(__instance);
				}
			}
		}

		internal static bool Interact()
		{
			IngamePlayerSettings instance = IngamePlayerSettings.Instance;
			object obj;
			if (instance == null)
			{
				obj = null;
			}
			else
			{
				PlayerInput playerInput = instance.playerInput;
				if (playerInput == null)
				{
					obj = null;
				}
				else
				{
					InputActionAsset actions = playerInput.actions;
					obj = ((actions != null) ? actions.FindAction("Interact", false) : null);
				}
			}
			InputAction val = (InputAction)obj;
			if (val != null)
			{
				return val.WasPressedThisFrame();
			}
			return false;
		}

		private static void Punch(PlayerControllerB p)
		{
			//IL_0020: 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)
			if (!Look(p, 3.6f, out var group, out var hit, out var _, out var _) || (Object)(object)group == (Object)null)
			{
				return;
			}
			Block block = group.Get(hit);
			if (block == Block.Air || Blocks.Tier[(uint)block] > 0 || Blocks.Hardness[(uint)block] == 0)
			{
				return;
			}
			if (string.IsNullOrEmpty(((TMP_Text)p.cursorTip).text))
			{
				((TMP_Text)p.cursorTip).text = "Punch : [LMB]";
			}
			IngamePlayerSettings instance = IngamePlayerSettings.Instance;
			object obj;
			if (instance == null)
			{
				obj = null;
			}
			else
			{
				PlayerInput playerInput = instance.playerInput;
				if (playerInput == null)
				{
					obj = null;
				}
				else
				{
					InputActionAsset actions = playerInput.actions;
					obj = ((actions != null) ? actions.FindAction("ActivateItem", false) : null);
				}
			}
			InputAction val = (InputAction)obj;
			if (val != null && val.WasPressedThisFrame() && !(Time.time < nextPunch))
			{
				nextPunch = Time.time + 0.35f;
				MineAt(group, hit, 0, 0.5f, pickaxe: false);
			}
		}

		private static void Cycle()
		{
			List<Block> list = (from kv in Stock
				where kv.Value > 0
				select kv.Key into b
				orderby (int)b
				select b).ToList();
			if (list.Count == 0)
			{
				Tip("No blocks. Mine some first");
				return;
			}
			int num = list.IndexOf(Selected);
			Selected = list[(num + 1) % list.Count];
		}

		public static bool Place(PlayerControllerB p)
		{
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: 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_0083: 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_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			if (Count(Selected) <= 0)
			{
				Cycle();
				if (Count(Selected) <= 0)
				{
					return false;
				}
			}
			if (!Look(p, 4.5f, out var group, out var _, out var before, out var h))
			{
				return false;
			}
			if ((Object)(object)((Component)((RaycastHit)(ref h)).collider).GetComponent<BlockGroup.TorchHit>() != (Object)null)
			{
				return false;
			}
			Block b = Selected;
			bool flag = Blocks.IsTorch(b);
			if ((Object)(object)group == (Object)null)
			{
				StartOfRound instance = StartOfRound.Instance;
				int num;
				if (!p.isInHangarShipRoom)
				{
					Bounds bounds = instance.shipInnerRoomBounds.bounds;
					num = (((Bounds)(ref bounds)).Contains(((RaycastHit)(ref h)).point) ? 1 : 0);
				}
				else
				{
					num = 1;
				}
				bool flag2 = (byte)num != 0;
				group = BlockGroup.Resolve((!flag) ? (flag2 ? 1 : 2) : (flag2 ? 4 : 3));
				if ((Object)(object)group == (Object)null)
				{
					Tip("Can't build here");
					return false;
				}
				before = group.CellAt(((RaycastHit)(ref h)).point + ((RaycastHit)(ref h)).normal * 0.01f);
			}
			if (flag)
			{
				Vector3 val = ((Component)group).transform.InverseTransformDirection(((RaycastHit)(ref h)).normal);
				if (val.y < -0.5f)
				{
					Tip("Torches go on floors and walls");
					return false;
				}
				b = ((!(val.y < 0.6f)) ? Block.Torch : ((!(Mathf.Abs(val.x) > Mathf.Abs(val.z))) ? ((val.z > 0f) ? Block.TorchPZ : Block.TorchNZ) : ((val.x > 0f) ? Block.TorchPX : Block.TorchNX)));
			}
			if (group.Get(before) != Block.Air)
			{
				return false;
			}
			if (!flag && Physics.CheckBox(group.Center(before), group.HalfExtents * 0.96f, ((Component)group).transform.rotation, 524296, (QueryTriggerInteraction)1))
			{
				Tip("Something is in the way");
				return false;
			}
			Stock[Selected]--;
			Net.Edit(group, before, b, mined: false);
			return true;
		}
	}
	[HarmonyPatch]
	public static class Net
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static HandleNamedMessageDelegate <0>__OnEdit;

			public static HandleNamedMessageDelegate <1>__OnEdits;

			public static HandleNamedMessageDelegate <2>__OnAsk;

			public static HandleNamedMessageDelegate <3>__OnAction;

			public static HandleNamedMessageDelegate <4>__OnReply;
		}

		private const string EditMsg = "MineCompany.Edit";

		private const string EditsMsg = "MineCompany.Edits";

		private const string AskMsg = "MineCompany.AskEdits";

		private const string ActionMsg = "MineCompany.Action";

		private const string ReplyMsg = "MineCompany.Reply";

		public static readonly Dictionary<string, Action<ulong, FastBufferReader>> Actions = new Dictionary<string, Action<ulong, FastBufferReader>>();

		private static CustomMessagingManager Messaging
		{
			get
			{
				NetworkManager singleton = NetworkManager.Singleton;
				if (singleton == null)
				{
					return null;
				}
				return singleton.CustomMessagingManager;
			}
		}

		private static bool IsServer
		{
			get
			{
				if ((Object)(object)NetworkManager.Singleton != (Object)null)
				{
					return NetworkManager.Singleton.IsServer;
				}
				return false;
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(StartOfRound), "Start")]
		private static void Register()
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			//IL_0046: 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)
			//IL_0051: Expected O, but got Unknown
			//IL_006c: 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_0077: Expected O, but got Unknown
			//IL_0092: 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)
			//IL_009d: Expected O, but got Unknown
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Expected O, but got Unknown
			CustomMessagingManager messaging = Messaging;
			if (messaging != null)
			{
				object obj = <>O.<0>__OnEdit;
				if (obj == null)
				{
					HandleNamedMessageDelegate val = OnEdit;
					<>O.<0>__OnEdit = val;
					obj = (object)val;
				}
				messaging.RegisterNamedMessageHandler("MineCompany.Edit", (HandleNamedMessageDelegate)obj);
				object obj2 = <>O.<1>__OnEdits;
				if (obj2 == null)
				{
					HandleNamedMessageDelegate val2 = OnEdits;
					<>O.<1>__OnEdits = val2;
					obj2 = (object)val2;
				}
				messaging.RegisterNamedMessageHandler("MineCompany.Edits", (HandleNamedMessageDelegate)obj2);
				object obj3 = <>O.<2>__OnAsk;
				if (obj3 == null)
				{
					HandleNamedMessageDelegate val3 = OnAsk;
					<>O.<2>__OnAsk = val3;
					obj3 = (object)val3;
				}
				messaging.RegisterNamedMessageHandler("MineCompany.AskEdits", (HandleNamedMessageDelegate)obj3);
				object obj4 = <>O.<3>__OnAction;
				if (obj4 == null)
				{
					HandleNamedMessageDelegate val4 = OnAction;
					<>O.<3>__OnAction = val4;
					obj4 = (object)val4;
				}
				messaging.RegisterNamedMessageHandler("MineCompany.Action", (HandleNamedMessageDelegate)obj4);
				object obj5 = <>O.<4>__OnReply;
				if (obj5 == null)
				{
					HandleNamedMessageDelegate val5 = OnReply;
					<>O.<4>__OnReply = val5;
					obj5 = (object)val5;
				}
				messaging.RegisterNamedMessageHandler("MineCompany.Reply", (HandleNamedMessageDelegate)obj5);
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(StartOfRound), "OnDestroy")]
		private static void Unregister()
		{
			CustomMessagingManager messaging = Messaging;
			if (messaging != null)
			{
				string[] array = new string[5] { "MineCompany.Edit", "MineCompany.Edits", "MineCompany.AskEdits", "MineCompany.Action", "MineCompany.Reply" };
				foreach (string text in array)
				{
					messaging.UnregisterNamedMessageHandler(text);
				}
			}
		}

		public unsafe static void Edit(BlockGroup g, Vector3Int p, Block b, bool mined)
		{
			//IL_000b: 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_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)g == (Object)null)
			{
				return;
			}
			Block old = g.Get(p);
			g.Set(p, b);
			if (IsServer)
			{
				ServerApply(g, p, b, old, mined, 0uL);
				return;
			}
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(32, (Allocator)2, -1);
			try
			{
				Write(val, g.Id, p, b, old, mined);
				Messaging.SendNamedMessage("MineCompany.Edit", 0uL, val, (NetworkDelivery)3);
			}
			finally
			{
				((IDisposable)(*(FastBufferWriter*)(&val))/*cast due to .constrained prefix*/).Dispose();
			}
		}

		private static void Write(FastBufferWriter buf, int id, Vector3Int p, Block b, Block old, bool mined)
		{
			//IL_0006: 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)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: 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_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: 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)
			((FastBufferWriter)(ref buf)).WriteValueSafe<int>(ref id, default(ForPrimitives));
			int x = ((Vector3Int)(ref p)).x;
			((FastBufferWriter)(ref buf)).WriteValueSafe<int>(ref x, default(ForPrimitives));
			x = ((Vector3Int)(ref p)).y;
			((FastBufferWriter)(ref buf)).WriteValueSafe<int>(ref x, default(ForPrimitives));
			x = ((Vector3Int)(ref p)).z;
			((FastBufferWriter)(ref buf)).WriteValueSafe<int>(ref x, default(ForPrimitives));
			byte b2 = (byte)b;
			((FastBufferWriter)(ref buf)).WriteValueSafe<byte>(ref b2, default(ForPrimitives));
			b2 = (byte)old;
			((FastBufferWriter)(ref buf)).WriteValueSafe<byte>(ref b2, default(ForPrimitives));
			((FastBufferWriter)(ref buf)).WriteValueSafe<bool>(ref mined, default(ForPrimitives));
		}

		private static void OnEdit(ulong sender, FastBufferReader r)
		{
			//IL_0006: 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)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: 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_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: 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_00ca: Unknown result type (might be due to invalid IL or missing references)
			int id = default(int);
			((FastBufferReader)(ref r)).ReadValueSafe<int>(ref id, default(ForPrimitives));
			int num = default(int);
			((FastBufferReader)(ref r)).ReadValueSafe<int>(ref num, default(ForPrimitives));
			int num2 = default(int);
			((FastBufferReader)(ref r)).ReadValueSafe<int>(ref num2, default(ForPrimitives));
			int num3 = default(int);
			((FastBufferReader)(ref r)).ReadValueSafe<int>(ref num3, default(ForPrimitives));
			byte b = default(byte);
			((FastBufferReader)(ref r)).ReadValueSafe<byte>(ref b, default(ForPrimitives));
			byte b2 = default(byte);
			((FastBufferReader)(ref r)).ReadValueSafe<byte>(ref b2, default(ForPrimitives));
			bool flag = default(bool);
			((FastBufferReader)(ref r)).ReadValueSafe<bool>(ref flag, default(ForPrimitives));
			Vector3Int val = default(Vector3Int);
			((Vector3Int)(ref val))..ctor(num, num2, num3);
			if (IsServer)
			{
				BlockGroup blockGroup = BlockGroup.Resolve(id);
				if (!((Object)(object)blockGroup == (Object)null))
				{
					Block block = blockGroup.Get(val);
					if (!flag || block != Block.Air)
					{
						blockGroup.Set(val, (Block)b);
						ServerApply(blockGroup, val, (Block)b, block, flag, sender);
					}
				}
			}
			else
			{
				BlockGroup.Apply(id, val, (Block)b);
			}
		}

		private unsafe static void ServerApply(BlockGroup g, Vector3Int p, Block b, Block old, bool mined, ulong sender)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: 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_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(32, (Allocator)2, -1);
			try
			{
				Write(val, g.Id, p, b, old, mined);
				foreach (ulong connectedClientsId in NetworkManager.Singleton.ConnectedClientsIds)
				{
					if (connectedClientsId != 0L && connectedClientsId != sender)
					{
						Messaging.SendNamedMessage("MineCompany.Edit", connectedClientsId, val, (NetworkDelivery)3);
					}
				}
			}
			finally
			{
				((IDisposable)(*(FastBufferWriter*)(&val))/*cast due to .constrained prefix*/).Dispose();
			}
			if (mined)
			{
				if (Blocks.IsOre(old))
				{
					Content.SpawnOreDrop(old, g.Center(p), g.Inside);
				}
				else if (old == Block.Chest)
				{
					Content.SpawnChestLoot(g.Center(p), g.Inside);
				}
			}
		}

		public unsafe static void RequestEdits()
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			if (IsServer || Messaging == null)
			{
				return;
			}
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(4, (Allocator)2, -1);
			try
			{
				Messaging.SendNamedMessage("MineCompany.AskEdits", 0uL, val, (NetworkDelivery)3);
			}
			finally
			{
				((IDisposable)(*(FastBufferWriter*)(&val))/*cast due to .constrained prefix*/).Dispose();
			}
		}

		private unsafe static void OnAsk(ulong sender, FastBufferReader r)
		{
			//IL_0085: 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_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			if (!IsServer)
			{
				return;
			}
			List<(int, Vector3Int, Block)> list = BlockGroup.All.Values.Where((BlockGroup g) => (Object)(object)g != (Object)null).SelectMany((BlockGroup g) => from e in g.Edits()
				select (Id: g.Id, Key: e.Key, Value: e.Value)).ToList();
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(8 + list.Count * 17, (Allocator)2, 16777216);
			try
			{
				int count = list.Count;
				((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref count, default(ForPrimitives));
				foreach (var item in list)
				{
					var (num, val2, block) = item;
					((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref num, default(ForPrimitives));
					count = ((Vector3Int)(ref val2)).x;
					((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref count, default(ForPrimitives));
					count = ((Vector3Int)(ref val2)).y;
					((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref count, default(ForPrimitives));
					count = ((Vector3Int)(ref val2)).z;
					((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref count, default(ForPrimitives));
					byte b = (byte)block;
					((FastBufferWriter)(ref val)).WriteValueSafe<byte>(ref b, default(ForPrimitives));
				}
				Messaging.SendNamedMessage("MineCompany.Edits", sender, val, (NetworkDelivery)4);
			}
			finally
			{
				((IDisposable)(*(FastBufferWriter*)(&val))/*cast due to .constrained prefix*/).Dispose();
			}
		}

		private static void OnEdits(ulong sender, FastBufferReader r)
		{
			//IL_0006: 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)
			//IL_001c: 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_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: 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)
			int num = default(int);
			((FastBufferReader)(ref r)).ReadValueSafe<int>(ref num, default(ForPrimitives));
			int id = default(int);
			int num2 = default(int);
			int num3 = default(int);
			int num4 = default(int);
			byte b = default(byte);
			for (int i = 0; i < num; i++)
			{
				((FastBufferReader)(ref r)).ReadValueSafe<int>(ref id, default(ForPrimitives));
				((FastBufferReader)(ref r)).ReadValueSafe<int>(ref num2, default(ForPrimitives));
				((FastBufferReader)(ref r)).ReadValueSafe<int>(ref num3, default(ForPrimitives));
				((FastBufferReader)(ref r)).ReadValueSafe<int>(ref num4, default(ForPrimitives));
				((FastBufferReader)(ref r)).ReadValueSafe<byte>(ref b, default(ForPrimitives));
				BlockGroup.Apply(id, new Vector3Int(num2, num3, num4), (Block)b);
			}
		}

		public unsafe static void Action(string name, Action<FastBufferWriter> write)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(256, (Allocator)2, 4096);
			try
			{
				((FastBufferWriter)(ref val)).WriteValueSafe(name, false);
				write?.Invoke(val);
				if (IsServer)
				{
					FastBufferReader arg = default(FastBufferReader);
					((FastBufferReader)(ref arg))..ctor(val, (Allocator)2, -1, 0, (Allocator)2);
					try
					{
						string text = default(string);
						((FastBufferReader)(ref arg)).ReadValueSafe(ref text, false);
						if (Actions.TryGetValue(name, out var value))
						{
							value(0uL, arg);
						}
						return;
					}
					finally
					{
						((IDisposable)(*(FastBufferReader*)(&arg))/*cast due to .constrained prefix*/).Dispose();
					}
				}
				Messaging.SendNamedMessage("MineCompany.Action", 0uL, val, (NetworkDelivery)3);
			}
			finally
			{
				((IDisposable)(*(FastBufferWriter*)(&val))/*cast due to .constrained prefix*/).Dispose();
			}
		}

		public unsafe static void Reply(ulong client, string kind, string text, int index)
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			if (client == NetworkManager.Singleton.LocalClientId)
			{
				Crafting.OnReply(kind, text, index);
				return;
			}
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(256, (Allocator)2, 4096);
			try
			{
				((FastBufferWriter)(ref val)).WriteValueSafe(kind, false);
				((FastBufferWriter)(ref val)).WriteValueSafe(text, false);
				((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref index, default(ForPrimitives));
				Messaging.SendNamedMessage("MineCompany.Reply", client, val, (NetworkDelivery)3);
			}
			finally
			{
				((IDisposable)(*(FastBufferWriter*)(&val))/*cast due to .constrained prefix*/).Dispose();
			}
		}

		private static void OnReply(ulong sender, FastBufferReader r)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			string kind = default(string);
			((FastBufferReader)(ref r)).ReadValueSafe(ref kind, false);
			string text = default(string);
			((FastBufferReader)(ref r)).ReadValueSafe(ref text, false);
			int index = default(int);
			((FastBufferReader)(ref r)).ReadValueSafe<int>(ref index, default(ForPrimitives));
			Crafting.OnReply(kind, text, index);
		}

		private static void OnAction(ulong sender, FastBufferReader r)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			if (IsServer)
			{
				string key = default(string);
				((FastBufferReader)(ref r)).ReadValueSafe(ref key, false);
				if (Actions.TryGetValue(key, out var value))
				{
					value(sender, r);
				}
			}
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB))]
	internal static class PlayerPatches
	{
		private static float normalStep = -1f;

		[HarmonyPostfix]
		[HarmonyPatch("Update")]
		private static void Step(PlayerControllerB __instance)
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//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)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			CharacterController thisController = __instance.thisController;
			if (!((Object)(object)thisController == (Object)null) && ((NetworkBehaviour)__instance).IsOwner && __instance.isPlayerControlled)
			{
				if (normalStep < 0f)
				{
					normalStep = thisController.stepOffset;
				}
				Vector2 moveInputVector = __instance.moveInputVector;
				Transform transform = ((Component)__instance).transform;
				Vector3 val = transform.right * moveInputVector.x + transform.forward * moveInputVector.y;
				val.y = 0f;
				bool flag = false;
				RaycastHit val2 = default(RaycastHit);
				if (((Vector3)(ref val)).sqrMagnitude > 0.04f && Physics.Raycast(((Component)__instance).transform.position + Vector3.up * 0.3f, ((Vector3)(ref val)).normalized, ref val2, thisController.radius + 0.6f, 256, (QueryTriggerInteraction)1))
				{
					flag = (Object)(object)((Component)((RaycastHit)(ref val2)).collider).GetComponentInParent<BlockGroup>() != (Object)null;
				}
				float num = (flag ? (Plugin.BlockSize * 1.05f) : normalStep);
				if (num >= thisController.height)
				{
					num = thisController.height - 0.05f;
				}
				if (thisController.stepOffset != num)
				{
					thisController.stepOffset = num;
				}
			}
		}
	}
	[BepInPlugin("woode.MineCompany", "MineCompany", "0.2.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public const string Guid = "woode.MineCompany";

		public const string Name = "MineCompany";

		public const string Version = "0.2.0";

		internal static ManualLogSource Log;

		internal static Plugin Instance;

		private static ConfigEntry<string> mcDir;

		private static ConfigEntry<bool> forceFallback;

		private static ConfigEntry<float> blockSize;

		private static ConfigEntry<float> treeDensity;

		private static ConfigEntry<float> treeRadius;

		private static ConfigEntry<float> oreRoom;

		private static ConfigEntry<float> chestRoom;

		private static ConfigEntry<float> doorBlock;

		private static ConfigEntry<float> torchLumens;

		private static ConfigEntry<int> pickaxeRarity;

		private static ConfigEntry<int> maxTorchLights;

		private static ConfigEntry<int> creeperRarity;

		private static ConfigEntry<int> creeperHP;

		private static ConfigEntry<float> creeperRush;

		private static ConfigEntry<float> creeperKill;

		private static ConfigEntry<Key> placeKey;

		private static ConfigEntry<Key> cycleKey;

		private static ConfigEntry<int> furnacePrice;

		private static ConfigEntry<int> smeltsPerCoal;

		internal static Vector3 TablePosition = new Vector3(3.4f, 0