Decompiled source of DigiModpackV2 v1.0.2

plugins/AnimalFeedingTrough/AnimalFeedingTrough.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using BepInEx;
using HarmonyLib;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using UnityEngine;

[assembly: Guid("55912d84-4458-440a-b4d5-ee0eb383d22e")]
[assembly: AssemblyFileVersion("1.0.5.0")]
[assembly: CompilationRelaxations(8)]
[assembly: ComVisible(false)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyTitle("Animal Feeding Trough")]
[assembly: AssemblyDescription("Adds a functional animal feeding trough to Valheim.")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("xNeliox")]
[assembly: AssemblyProduct("Animal Feeding Trough")]
[assembly: AssemblyCopyright("Copyright © 2026 xNeliox")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyVersion("1.0.5.0")]
namespace AnimalFeedingTrough;

internal enum TroughVariant
{
	Standard,
	Compact,
	Small,
	Curved,
	CurvedCompact,
	CurvedTiny,
	Corner,
	CornerCompact,
	CornerTiny,
	ChickenBowl
}
[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
[BepInPlugin("xneliox.animalfeedingtrough", "Animal Feeding Trough", "1.0.5")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public sealed class AnimalFeedingTroughPlugin : BaseUnityPlugin
{
	public const string PluginGuid = "xneliox.animalfeedingtrough";

	public const string PluginName = "Animal Feeding Trough";

	public const string PluginVersion = "1.0.5";

	internal const string PrefabName = "xneliox_FeedingTrough";

	internal const string CompactPrefabName = "xneliox_FeedingTroughCompact";

	internal const string SmallPrefabName = "xneliox_FeedingTroughSmall";

	internal const string CurvedPrefabName = "xneliox_FeedingTroughCurved";

	internal const string CurvedCompactPrefabName = "xneliox_FeedingTroughCurvedCompact";

	internal const string CurvedTinyPrefabName = "xneliox_FeedingTroughCurvedTiny";

	internal const string CornerPrefabName = "xneliox_FeedingTroughCorner";

	internal const string ChickenBowlPrefabName = "xneliox_ChickenFeedingBowl";

	internal const string CornerCompactPrefabName = "xneliox_FeedingTroughCornerCompact";

	internal const string CornerTinyPrefabName = "xneliox_FeedingTroughCornerTiny";

	private void Awake()
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		TroughTranslations.Register();
		new Harmony("xneliox.animalfeedingtrough").PatchAll(typeof(AnimalFeedingTroughPlugin).Assembly);
		PrefabManager.OnVanillaPrefabsAvailable += RegisterTrough;
	}

	private void OnDestroy()
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		new Harmony("xneliox.animalfeedingtrough").UnpatchSelf();
		PrefabManager.OnVanillaPrefabsAvailable -= RegisterTrough;
	}

	private void RegisterTrough()
	{
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Expected O, but got Unknown
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Expected O, but got Unknown
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Expected O, but got Unknown
		//IL_0083: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: Expected O, but got Unknown
		//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: Expected O, but got Unknown
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c7: Expected O, but got Unknown
		//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f8: Expected O, but got Unknown
		//IL_0103: Unknown result type (might be due to invalid IL or missing references)
		//IL_0109: Expected O, but got Unknown
		//IL_0135: Unknown result type (might be due to invalid IL or missing references)
		//IL_013b: Expected O, but got Unknown
		//IL_0146: Unknown result type (might be due to invalid IL or missing references)
		//IL_014c: Expected O, but got Unknown
		//IL_0177: Unknown result type (might be due to invalid IL or missing references)
		//IL_017d: Expected O, but got Unknown
		//IL_0188: Unknown result type (might be due to invalid IL or missing references)
		//IL_018e: Expected O, but got Unknown
		//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c0: Expected O, but got Unknown
		//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d1: Expected O, but got Unknown
		//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0203: Expected O, but got Unknown
		//IL_020e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0214: Expected O, but got Unknown
		//IL_023f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0245: Expected O, but got Unknown
		//IL_0250: Unknown result type (might be due to invalid IL or missing references)
		//IL_0256: Expected O, but got Unknown
		//IL_0282: Unknown result type (might be due to invalid IL or missing references)
		//IL_0288: Expected O, but got Unknown
		//IL_0293: Unknown result type (might be due to invalid IL or missing references)
		//IL_0299: Expected O, but got Unknown
		PrefabManager.OnVanillaPrefabsAvailable -= RegisterTrough;
		try
		{
			RegisterTroughPiece("xneliox_FeedingTrough", "$xneliox_trough_name", "$xneliox_trough_description", TroughVariant.Standard, 6, new RequirementConfig("Wood", 20, 0, true), new RequirementConfig("BronzeNails", 4, 0, true));
			RegisterTroughPiece("xneliox_FeedingTroughCompact", "$xneliox_trough_compact_name", "$xneliox_trough_compact_description", TroughVariant.Compact, 6, new RequirementConfig("Wood", 14, 0, true), new RequirementConfig("BronzeNails", 3, 0, true));
			RegisterTroughPiece("xneliox_FeedingTroughSmall", "$xneliox_trough_small_name", "$xneliox_trough_small_description", TroughVariant.Small, 6, new RequirementConfig("Wood", 8, 0, true), new RequirementConfig("BronzeNails", 2, 0, true));
			RegisterTroughPiece("xneliox_FeedingTroughCurved", "$xneliox_trough_curved_name", "$xneliox_trough_curved_description", TroughVariant.Curved, 6, new RequirementConfig("Wood", 18, 0, true), new RequirementConfig("BronzeNails", 4, 0, true));
			RegisterTroughPiece("xneliox_FeedingTroughCurvedCompact", "$xneliox_trough_curved_compact_name", "$xneliox_trough_curved_compact_description", TroughVariant.CurvedCompact, 6, new RequirementConfig("Wood", 12, 0, true), new RequirementConfig("BronzeNails", 3, 0, true));
			RegisterTroughPiece("xneliox_FeedingTroughCurvedTiny", "$xneliox_trough_curved_tiny_name", "$xneliox_trough_curved_tiny_description", TroughVariant.CurvedTiny, 6, new RequirementConfig("Wood", 8, 0, true), new RequirementConfig("BronzeNails", 2, 0, true));
			RegisterTroughPiece("xneliox_FeedingTroughCorner", "$xneliox_trough_corner_name", "$xneliox_trough_corner_description", TroughVariant.Corner, 6, new RequirementConfig("Wood", 18, 0, true), new RequirementConfig("BronzeNails", 4, 0, true));
			RegisterTroughPiece("xneliox_FeedingTroughCornerCompact", "$xneliox_trough_corner_compact_name", "$xneliox_trough_corner_compact_description", TroughVariant.CornerCompact, 6, new RequirementConfig("Wood", 12, 0, true), new RequirementConfig("BronzeNails", 3, 0, true));
			RegisterTroughPiece("xneliox_FeedingTroughCornerTiny", "$xneliox_trough_corner_tiny_name", "$xneliox_trough_corner_tiny_description", TroughVariant.CornerTiny, 6, new RequirementConfig("Wood", 8, 0, true), new RequirementConfig("BronzeNails", 2, 0, true));
			RegisterTroughPiece("xneliox_ChickenFeedingBowl", "$xneliox_chicken_bowl_name", "$xneliox_chicken_bowl_description", TroughVariant.ChickenBowl, 6, new RequirementConfig("Wood", 6, 0, true), new RequirementConfig("BronzeNails", 2, 0, true));
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Registered ten networked animal feeding trough variants with six storage slots each.");
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)("Could not register feeding troughs: " + ex));
		}
	}

	private static void RegisterTroughPiece(string prefabName, string nameToken, string descriptionToken, TroughVariant variant, int storageSlots, params RequirementConfig[] requirements)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Expected O, but got Unknown
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Expected O, but got Unknown
		//IL_0207: Unknown result type (might be due to invalid IL or missing references)
		//IL_0214: Unknown result type (might be due to invalid IL or missing references)
		//IL_024a: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_01be: 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_01f0: Unknown result type (might be due to invalid IL or missing references)
		PieceConfig val = new PieceConfig();
		val.Name = nameToken;
		val.Description = descriptionToken;
		val.PieceTable = "_HammerPieceTable";
		val.Category = "Furniture";
		val.CraftingStation = "piece_workbench";
		val.Icon = TroughVariantIcons.Create(variant);
		val.Requirements = requirements;
		PieceConfig val2 = val;
		CustomPiece val3 = new CustomPiece(prefabName, "piece_chest_wood", val2);
		GameObject piecePrefab = val3.PiecePrefab;
		((Object)piecePrefab).name = prefabName;
		Renderer componentInChildren = piecePrefab.GetComponentInChildren<Renderer>(true);
		Material val4 = (Object.op_Implicit((Object)(object)componentInChildren) ? componentInChildren.sharedMaterial : null);
		if (!Object.op_Implicit((Object)(object)val4))
		{
			throw new InvalidOperationException("No Valheim piece material was available.");
		}
		Renderer[] componentsInChildren = piecePrefab.GetComponentsInChildren<Renderer>(true);
		foreach (Renderer val5 in componentsInChildren)
		{
			val5.enabled = false;
		}
		Collider[] componentsInChildren2 = piecePrefab.GetComponentsInChildren<Collider>(true);
		foreach (Collider val6 in componentsInChildren2)
		{
			val6.enabled = false;
		}
		AssetBundleTroughModel.Instantiate(piecePrefab.transform, variant);
		BoxCollider val7 = piecePrefab.GetComponent<BoxCollider>();
		if (!Object.op_Implicit((Object)(object)val7))
		{
			val7 = piecePrefab.AddComponent<BoxCollider>();
		}
		if (variant == TroughVariant.Corner || variant == TroughVariant.CornerCompact || variant == TroughVariant.CornerTiny)
		{
			float num = variant switch
			{
				TroughVariant.CornerCompact => 2.55f, 
				TroughVariant.Corner => 3.5f, 
				_ => 1.85f, 
			};
			float num2 = variant switch
			{
				TroughVariant.CornerCompact => 0.82f, 
				TroughVariant.Corner => 1.15f, 
				_ => 0.58f, 
			};
			float num3 = variant switch
			{
				TroughVariant.CornerCompact => 0.85f, 
				TroughVariant.Corner => 1f, 
				_ => 0.68f, 
			};
			float num4 = variant switch
			{
				TroughVariant.CornerCompact => 1.05f, 
				TroughVariant.Corner => 1.34f, 
				_ => 0.8f, 
			};
			val7.center = new Vector3(0f - num2, 0.5f, 0f);
			val7.size = new Vector3(num, num3, num4);
			BoxCollider val8 = piecePrefab.AddComponent<BoxCollider>();
			val8.center = new Vector3(0f, 0.5f, num2);
			val8.size = new Vector3(num4, num3, num);
			((Collider)val8).enabled = true;
		}
		else
		{
			val7.center = TroughVariantGeometry.ColliderCenter(variant);
			val7.size = TroughVariantGeometry.ColliderSize(variant);
		}
		((Collider)val7).enabled = true;
		Container component = piecePrefab.GetComponent<Container>();
		component.m_name = nameToken;
		component.m_width = storageSlots;
		component.m_height = 1;
		component.m_privacy = (PrivacySetting)2;
		Piece component2 = piecePrefab.GetComponent<Piece>();
		component2.m_name = nameToken;
		component2.m_description = descriptionToken;
		TroughFeeder troughFeeder = piecePrefab.GetComponent<TroughFeeder>();
		if (!Object.op_Implicit((Object)(object)troughFeeder))
		{
			troughFeeder = piecePrefab.AddComponent<TroughFeeder>();
		}
		troughFeeder.SetVariant(variant);
		PieceManager.Instance.AddPiece(val3);
	}
}
[HarmonyPatch(typeof(ZNetScene), "CreateObject")]
internal static class TroughPrefabHashMigration
{
	private const int PreviousPrefabHash = 160077371;

	private static void Prefix(ZDO zdo)
	{
		if (zdo != null && zdo.GetPrefab() == 160077371)
		{
			zdo.SetPrefab(StringExtensionMethods.GetStableHashCode("xneliox_FeedingTrough"));
		}
	}
}
[HarmonyPatch(typeof(ZNetScene), "GetPrefab", new Type[] { typeof(int) })]
internal static class TroughPrefabHashLookup
{
	private const int PreviousPrefabHash = 160077371;

	private static void Prefix(ref int hash)
	{
		if (hash == 160077371)
		{
			hash = StringExtensionMethods.GetStableHashCode("xneliox_FeedingTrough");
		}
	}
}
internal static class AssetBundleTroughModel
{
	private const string BundleResource = "animalfeedingtrough_v4";

	private const string PrefabAsset = "Assets/AnimalFeedingTrough/FeedingTroughV4.prefab";

	private static AssetBundle _bundle;

	private static GameObject _prefab;

	internal static GameObject Instantiate(Transform parent, TroughVariant variant)
	{
		//IL_0108: Unknown result type (might be due to invalid IL or missing references)
		//IL_010d: Unknown result type (might be due to invalid IL or missing references)
		//IL_011d: 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_012b: Unknown result type (might be due to invalid IL or missing references)
		//IL_013b: Unknown result type (might be due to invalid IL or missing references)
		if (!Object.op_Implicit((Object)(object)_bundle))
		{
			Assembly assembly = typeof(AnimalFeedingTroughPlugin).Assembly;
			using Stream stream = assembly.GetManifestResourceStream("animalfeedingtrough_v4");
			if (stream == null)
			{
				throw new InvalidOperationException("The embedded feeding trough AssetBundle resource is missing.");
			}
			using MemoryStream memoryStream = new MemoryStream();
			stream.CopyTo(memoryStream);
			_bundle = AssetBundle.LoadFromMemory(memoryStream.ToArray());
		}
		if (!Object.op_Implicit((Object)(object)_bundle))
		{
			throw new InvalidOperationException("The embedded feeding trough AssetBundle could not be loaded.");
		}
		if (!Object.op_Implicit((Object)(object)_prefab))
		{
			_prefab = _bundle.LoadAsset<GameObject>("Assets/AnimalFeedingTrough/FeedingTroughV4.prefab");
		}
		if (!Object.op_Implicit((Object)(object)_prefab))
		{
			throw new InvalidOperationException("The feeding trough prefab is missing from the AssetBundle.");
		}
		GameObject val = Object.Instantiate<GameObject>(_prefab, parent, false);
		((Object)val).name = "AnimalFeedingTroughModelV3";
		TroughVariantGeometry.Apply(val, variant);
		Transform[] componentsInChildren = ((Component)parent).GetComponentsInChildren<Transform>(true);
		foreach (Transform val2 in componentsInChildren)
		{
			if (variant == TroughVariant.ChickenBowl)
			{
				break;
			}
			if (((Object)val2).name.EndsWith(" foot", StringComparison.Ordinal))
			{
				Vector3 localPosition = val2.localPosition;
				localPosition.y = 0.16f;
				val2.localPosition = localPosition;
				Vector3 localScale = val2.localScale;
				localScale.y = 0.36f;
				val2.localScale = localScale;
			}
		}
		return val;
	}
}
internal static class TroughVariantGeometry
{
	internal static Vector3 ColliderCenter(TroughVariant variant)
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		return (Vector3)(variant switch
		{
			TroughVariant.ChickenBowl => new Vector3(0f, 0.17f, 0f), 
			TroughVariant.Corner => new Vector3(-0.55f, 0.42f, 0.55f), 
			_ => new Vector3(0f, (variant == TroughVariant.Small) ? 0.34f : 0.5f, 0f), 
		});
	}

	internal static Vector3 ColliderSize(TroughVariant variant)
	{
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: 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_00ab: 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_00d5: 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)
		return (Vector3)(variant switch
		{
			TroughVariant.Compact => new Vector3(3.41f, 1f, 1.12f), 
			TroughVariant.Small => new Vector3(2.05f, 0.65f, 1.06f), 
			TroughVariant.Curved => new Vector3(4.55f, 1f, 2.05f), 
			TroughVariant.Corner => new Vector3(3.55f, 1f, 3.55f), 
			TroughVariant.CurvedCompact => new Vector3(3.35f, 1f, 1.72f), 
			TroughVariant.CurvedTiny => new Vector3(2.3f, 0.72f, 1.26f), 
			TroughVariant.ChickenBowl => new Vector3(1.55f, 0.34f, 1.55f), 
			_ => new Vector3(5.24f, 1f, 1.34f), 
		});
	}

	internal static float LengthScale(TroughVariant variant)
	{
		return variant switch
		{
			TroughVariant.Compact => 0.65f, 
			TroughVariant.Small => 0.38f, 
			TroughVariant.Corner => 0.48f, 
			TroughVariant.CornerCompact => 0.34f, 
			TroughVariant.CornerTiny => 0.23f, 
			TroughVariant.Curved => 1f, 
			TroughVariant.CurvedCompact => 0.7f, 
			TroughVariant.CurvedTiny => 0.46f, 
			_ => 1f, 
		};
	}

	internal static void Apply(GameObject model, TroughVariant variant)
	{
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0112: 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)
		float num = LengthScale(variant);
		Vector3 one = default(Vector3);
		((Vector3)(ref one))..ctor(num, 1f, 1f);
		if (variant == TroughVariant.Compact)
		{
			((Vector3)(ref one))..ctor(num, 1f, 0.82f);
		}
		if (variant == TroughVariant.Small)
		{
			((Vector3)(ref one))..ctor(num, 0.6f, 0.78f);
		}
		if (variant == TroughVariant.CurvedCompact)
		{
			one = Vector3.one;
		}
		if (variant == TroughVariant.CurvedTiny)
		{
			((Vector3)(ref one))..ctor(1f, 0.72f, 0.8f);
		}
		model.transform.localScale = one;
		if (variant == TroughVariant.Small || variant == TroughVariant.CurvedTiny)
		{
			RemoveMiddleSupportPair(model.transform);
		}
		switch (variant)
		{
		case TroughVariant.Curved:
		case TroughVariant.CurvedCompact:
		case TroughVariant.CurvedTiny:
			switch (variant)
			{
			case TroughVariant.CurvedCompact:
				ShortenAlongX(model.transform, 0.7f);
				break;
			case TroughVariant.CurvedTiny:
				ShortenAlongX(model.transform, 0.46f);
				break;
			}
			Bend(model.transform, variant switch
			{
				TroughVariant.CurvedCompact => 4.8f, 
				TroughVariant.CurvedTiny => 3.25f, 
				_ => 6.5f, 
			});
			break;
		case TroughVariant.Corner:
		case TroughVariant.CornerCompact:
		case TroughVariant.CornerTiny:
			MakeCorner(model);
			switch (variant)
			{
			case TroughVariant.CornerCompact:
				model.transform.localScale = new Vector3(0.72f, 0.85f, 0.72f);
				break;
			case TroughVariant.CornerTiny:
				model.transform.localScale = new Vector3(0.52f, 0.68f, 0.52f);
				break;
			}
			break;
		case TroughVariant.ChickenBowl:
			MakeChickenBowl(model);
			break;
		}
	}

	private static void MakeChickenBowl(GameObject model)
	{
		//IL_0179: Unknown result type (might be due to invalid IL or missing references)
		//IL_0184: Unknown result type (might be due to invalid IL or missing references)
		//IL_018f: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d1: 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_026d: 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_0295: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0313: Unknown result type (might be due to invalid IL or missing references)
		//IL_037f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0390: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0430: Unknown result type (might be due to invalid IL or missing references)
		//IL_0444: Unknown result type (might be due to invalid IL or missing references)
		//IL_0449: Unknown result type (might be due to invalid IL or missing references)
		//IL_0498: Unknown result type (might be due to invalid IL or missing references)
		//IL_04b8: Unknown result type (might be due to invalid IL or missing references)
		Transform transform = model.transform;
		Material val = null;
		Material val2 = null;
		Material val3 = null;
		Material val4 = null;
		Transform[] componentsInChildren = ((Component)transform).GetComponentsInChildren<Transform>(true);
		foreach (Transform val5 in componentsInChildren)
		{
			Renderer component = ((Component)val5).GetComponent<Renderer>();
			if (Object.op_Implicit((Object)(object)component) && Object.op_Implicit((Object)(object)component.sharedMaterial))
			{
				if (((Object)val5).name.EndsWith(" outward rim", StringComparison.Ordinal))
				{
					val = component.sharedMaterial;
				}
				else if (((Object)val5).name == "Basin bottom")
				{
					val2 = component.sharedMaterial;
				}
				else if (((Object)val5).name.EndsWith(" iron leg and band", StringComparison.Ordinal))
				{
					val3 = component.sharedMaterial;
				}
				else if (((Object)val5).name == "VisibleFeed")
				{
					val4 = component.sharedMaterial;
				}
			}
		}
		if (!Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)val2) || !Object.op_Implicit((Object)(object)val3) || !Object.op_Implicit((Object)(object)val4))
		{
			return;
		}
		List<GameObject> list = new List<GameObject>();
		Transform[] componentsInChildren2 = ((Component)transform).GetComponentsInChildren<Transform>(true);
		foreach (Transform val6 in componentsInChildren2)
		{
			if ((Object)(object)val6 != (Object)(object)transform && (Object)(object)val6.parent == (Object)(object)transform)
			{
				list.Add(((Component)val6).gameObject);
			}
		}
		foreach (GameObject item in list)
		{
			Object.DestroyImmediate((Object)(object)item);
		}
		transform.localPosition = Vector3.zero;
		transform.localRotation = Quaternion.identity;
		transform.localScale = Vector3.one;
		GameObject val7 = GameObject.CreatePrimitive((PrimitiveType)2);
		((Object)val7).name = "Round chicken bowl bottom";
		val7.transform.SetParent(transform, false);
		val7.transform.localPosition = new Vector3(0f, 0.105f, 0f);
		val7.transform.localScale = new Vector3(1.2f, 0.035f, 1.2f);
		Object.DestroyImmediate((Object)(object)val7.GetComponent<Collider>());
		val7.GetComponent<Renderer>().sharedMaterial = val2;
		float num = 1.3f * Mathf.Sin((float)Math.PI / 20f) + 0.025f;
		for (int k = 0; k < 20; k++)
		{
			float num2 = (float)k * (float)Math.PI * 2f / 20f;
			AddJointCube(transform, "Round wooden wall", new Vector3(Mathf.Sin(num2) * 0.65f, 0.19f, Mathf.Cos(num2) * 0.65f), new Vector3(num, 0.2f, 0.16f), Quaternion.Euler(0f, num2 * 57.29578f, 0f), val);
		}
		for (int l = 0; l < 4; l++)
		{
			float num3 = (float)l * (float)Math.PI * 0.5f;
			AddJointCube(transform, "Round bowl iron band", new Vector3(Mathf.Sin(num3) * 0.735f, 0.19f, Mathf.Cos(num3) * 0.735f), new Vector3(0.1f, 0.22f, 0.035f), Quaternion.Euler(0f, num3 * 57.29578f, 0f), val3);
		}
		Vector3 position = default(Vector3);
		for (int m = 0; m < 4; m++)
		{
			float num4 = (45f + (float)m * 90f) * ((float)Math.PI / 180f);
			((Vector3)(ref position))..ctor(Mathf.Sin(num4) * 0.737f, 0.19f, Mathf.Cos(num4) * 0.737f);
			float num5 = num4 * 57.29578f;
			AddJointCube(transform, "Round bowl X brace A", position, new Vector3(0.045f, 0.19f, 0.025f), Quaternion.Euler(0f, num5, 38f), val3);
			AddJointCube(transform, "Round bowl X brace B", position, new Vector3(0.045f, 0.19f, 0.025f), Quaternion.Euler(0f, num5, -38f), val3);
		}
		for (int n = 0; n < 4; n++)
		{
			float num6 = (45f + (float)n * 90f) * ((float)Math.PI / 180f);
			AddJointCube(transform, "Chicken bowl foot", new Vector3(Mathf.Sin(num6) * 0.48f, 0.055f, Mathf.Cos(num6) * 0.48f), new Vector3(0.22f, 0.11f, 0.22f), Quaternion.identity, val2);
		}
		GameObject val8 = GameObject.CreatePrimitive((PrimitiveType)2);
		((Object)val8).name = "VisibleFeed";
		val8.transform.SetParent(transform, false);
		val8.transform.localPosition = new Vector3(0f, 0.255f, 0f);
		val8.transform.localScale = new Vector3(1.08f, 0.018f, 1.08f);
		Object.DestroyImmediate((Object)(object)val8.GetComponent<Collider>());
		val8.GetComponent<Renderer>().sharedMaterial = val4;
		val8.SetActive(false);
	}

	private static void RemoveMiddleSupportPair(Transform root)
	{
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		Transform[] componentsInChildren = ((Component)root).GetComponentsInChildren<Transform>(true);
		foreach (Transform val in componentsInChildren)
		{
			if (!((Object)(object)val == (Object)(object)root) && !((Object)(object)val.parent != (Object)(object)root) && !(Mathf.Abs(val.localPosition.x) > 0.01f) && (((Object)val).name == "Front foot" || ((Object)val).name == "Rear foot" || ((Object)val).name == "Front iron leg and band" || ((Object)val).name == "Rear iron leg and band" || ((Object)val).name == "Cross support"))
			{
				((Component)val).gameObject.SetActive(false);
			}
		}
	}

	private static void Bend(Transform root, float radius)
	{
		//IL_0052: 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_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_009d: 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_00bd: 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)
		ConvertLongTimbersToContinuousCurves(root, radius);
		Transform[] componentsInChildren = ((Component)root).GetComponentsInChildren<Transform>(true);
		foreach (Transform val in componentsInChildren)
		{
			if (!((Object)(object)val == (Object)(object)root) && !((Object)(object)val.parent != (Object)(object)root) && !((Object)val).name.EndsWith(" continuous curved", StringComparison.Ordinal))
			{
				float x = val.localPosition.x;
				float z = val.localPosition.z;
				float num = x / radius;
				Vector3 localPosition = val.localPosition;
				float num2 = radius - z;
				localPosition.x = Mathf.Sin(num) * num2;
				localPosition.z = radius - Mathf.Cos(num) * num2;
				val.localPosition = localPosition;
				val.localRotation = Quaternion.Euler(0f, (0f - num) * 57.29578f, 0f) * val.localRotation;
				MeshFilter component = ((Component)val).GetComponent<MeshFilter>();
				if (((Object)val).name == "VisibleFeed" && Object.op_Implicit((Object)(object)component) && Object.op_Implicit((Object)(object)component.sharedMesh))
				{
					component.sharedMesh = BendMesh(component.sharedMesh, radius);
				}
			}
		}
	}

	private static void ShortenAlongX(Transform root, float factor)
	{
		//IL_0035: 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_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		Transform[] componentsInChildren = ((Component)root).GetComponentsInChildren<Transform>(true);
		foreach (Transform val in componentsInChildren)
		{
			if ((Object)(object)val == (Object)(object)root || (Object)(object)val.parent != (Object)(object)root)
			{
				continue;
			}
			Vector3 localPosition = val.localPosition;
			localPosition.x *= factor;
			val.localPosition = localPosition;
			if (((Object)val).name.EndsWith(" outward rim", StringComparison.Ordinal) || ((Object)val).name == "Basin bottom")
			{
				Vector3 localScale = val.localScale;
				localScale.x *= factor;
				val.localScale = localScale;
			}
			if (!(((Object)val).name == "VisibleFeed"))
			{
				continue;
			}
			MeshFilter component = ((Component)val).GetComponent<MeshFilter>();
			if (Object.op_Implicit((Object)(object)component) && Object.op_Implicit((Object)(object)component.sharedMesh))
			{
				Mesh val2 = Object.Instantiate<Mesh>(component.sharedMesh);
				Vector3[] vertices = val2.vertices;
				for (int j = 0; j < vertices.Length; j++)
				{
					ref Vector3 reference = ref vertices[j];
					reference.x *= factor;
				}
				val2.vertices = vertices;
				val2.RecalculateBounds();
				component.sharedMesh = val2;
			}
		}
	}

	private static void ConvertLongTimbersToContinuousCurves(Transform root, float radius)
	{
		//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_00ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
		List<Transform> list = new List<Transform>();
		Transform[] componentsInChildren = ((Component)root).GetComponentsInChildren<Transform>(true);
		foreach (Transform val in componentsInChildren)
		{
			if ((Object)(object)val.parent == (Object)(object)root && (((Object)val).name.EndsWith(" outward rim", StringComparison.Ordinal) || ((Object)val).name == "Basin bottom"))
			{
				list.Add(val);
			}
		}
		foreach (Transform item in list)
		{
			MeshFilter component = ((Component)item).GetComponent<MeshFilter>();
			if (Object.op_Implicit((Object)(object)component))
			{
				component.sharedMesh = CreateContinuousCurvedBeam(item.localPosition, item.localScale, radius, 32, ((Object)item).name);
				((Object)item).name = ((Object)item).name + " continuous curved";
				item.localPosition = Vector3.zero;
				item.localRotation = Quaternion.identity;
				item.localScale = Vector3.one;
			}
		}
	}

	private static Mesh CreateContinuousCurvedBeam(Vector3 center, Vector3 size, float radius, int sections, string sourceName)
	{
		//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_010e: 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_0129: Unknown result type (might be due to invalid IL or missing references)
		//IL_012e: 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_018f: Unknown result type (might be due to invalid IL or missing references)
		//IL_019d: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cf: 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_01eb: 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_01fc: Expected O, but got Unknown
		List<Vector3> vertices = new List<Vector3>((sections + 1) * 8 + 8);
		List<Vector2> list = new List<Vector2>((sections + 1) * 8 + 8);
		List<int> list2 = new List<int>(sections * 24 + 12);
		float num = center.x - size.x * 0.5f;
		float y = center.y - size.y * 0.5f;
		float y2 = center.y + size.y * 0.5f;
		float z = center.z - size.z * 0.5f;
		float z2 = center.z + size.z * 0.5f;
		Vector3[,] array = new Vector3[sections + 1, 4];
		for (int i = 0; i <= sections; i++)
		{
			float num2 = (float)i / (float)sections;
			float x = Mathf.Lerp(num, num + size.x, num2);
			ref Vector3 reference = ref array[i, 0];
			reference = BendPoint(x, y, z, radius);
			ref Vector3 reference2 = ref array[i, 1];
			reference2 = BendPoint(x, y2, z, radius);
			ref Vector3 reference3 = ref array[i, 2];
			reference3 = BendPoint(x, y2, z2, radius);
			ref Vector3 reference4 = ref array[i, 3];
			reference4 = BendPoint(x, y, z2, radius);
		}
		AddCurvedBeamStrip(vertices, list, list2, array, sections, 0, 1);
		AddCurvedBeamStrip(vertices, list, list2, array, sections, 1, 2);
		AddCurvedBeamStrip(vertices, list, list2, array, sections, 2, 3);
		AddCurvedBeamStrip(vertices, list, list2, array, sections, 3, 0);
		AddBeamCap(vertices, list, list2, array[0, 0], array[0, 3], array[0, 2], array[0, 1]);
		AddBeamCap(vertices, list, list2, array[sections, 0], array[sections, 1], array[sections, 2], array[sections, 3]);
		Mesh val = new Mesh();
		((Object)val).name = sourceName + " continuous curved mesh";
		Mesh val2 = val;
		val2.SetVertices(vertices);
		val2.SetUVs(0, list);
		val2.SetTriangles(list2, 0);
		val2.RecalculateNormals();
		val2.RecalculateBounds();
		return val2;
	}

	private static Vector3 BendPoint(float x, float y, float z, float radius)
	{
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		float num = x / radius;
		float num2 = radius - z;
		return new Vector3(Mathf.Sin(num) * num2, y, radius - Mathf.Cos(num) * num2);
	}

	private static void AddCurvedBeamStrip(List<Vector3> vertices, List<Vector2> uv, List<int> triangles, Vector3[,] rings, int sections, int first, int second)
	{
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: 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_0052: Unknown result type (might be due to invalid IL or missing references)
		int count = vertices.Count;
		for (int i = 0; i <= sections; i++)
		{
			float num = (float)i / (float)sections;
			vertices.Add(rings[i, first]);
			vertices.Add(rings[i, second]);
			uv.Add(new Vector2(num, 0f));
			uv.Add(new Vector2(num, 1f));
		}
		for (int j = 0; j < sections; j++)
		{
			int num2 = count + j * 2;
			int num3 = num2 + 2;
			AddQuad(triangles, num2, num2 + 1, num3 + 1, num3);
		}
	}

	private static void AddBeamCap(List<Vector3> vertices, List<Vector2> uv, List<int> triangles, Vector3 a, Vector3 b, Vector3 c, Vector3 d)
	{
		//IL_0008: 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_0017: 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_0046: 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_0070: Unknown result type (might be due to invalid IL or missing references)
		int count = vertices.Count;
		vertices.Add(a);
		vertices.Add(b);
		vertices.Add(c);
		vertices.Add(d);
		uv.Add(new Vector2(0f, 0f));
		uv.Add(new Vector2(1f, 0f));
		uv.Add(new Vector2(1f, 1f));
		uv.Add(new Vector2(0f, 1f));
		AddQuad(triangles, count, count + 1, count + 2, count + 3);
	}

	private static void AddQuad(List<int> triangles, int a, int b, int c, int d)
	{
		triangles.Add(a);
		triangles.Add(b);
		triangles.Add(c);
		triangles.Add(a);
		triangles.Add(c);
		triangles.Add(d);
	}

	private static Mesh BendMesh(Mesh source, float radius)
	{
		Mesh val = Object.Instantiate<Mesh>(source);
		((Object)val).name = ((Object)source).name + " curved";
		Vector3[] vertices = val.vertices;
		for (int i = 0; i < vertices.Length; i++)
		{
			float num = vertices[i].x / radius;
			float z = vertices[i].z;
			vertices[i].x = Mathf.Sin(num) * (radius - z);
			vertices[i].z = radius - Mathf.Cos(num) * (radius - z);
		}
		val.vertices = vertices;
		val.RecalculateNormals();
		val.RecalculateBounds();
		return val;
	}

	private static void MakeCorner(GameObject first)
	{
		BuildFinalCornerModel(first.transform);
	}

	private static void BuildFinalCornerModel(Transform root)
	{
		//IL_016f: Unknown result type (might be due to invalid IL or missing references)
		//IL_017a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0185: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_020a: Unknown result type (might be due to invalid IL or missing references)
		//IL_020f: 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_0244: Unknown result type (might be due to invalid IL or missing references)
		//IL_0249: Unknown result type (might be due to invalid IL or missing references)
		//IL_026e: Unknown result type (might be due to invalid IL or missing references)
		//IL_027f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0284: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02be: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0329: Unknown result type (might be due to invalid IL or missing references)
		//IL_033a: Unknown result type (might be due to invalid IL or missing references)
		//IL_033f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0360: Unknown result type (might be due to invalid IL or missing references)
		//IL_0374: Unknown result type (might be due to invalid IL or missing references)
		//IL_0379: Unknown result type (might be due to invalid IL or missing references)
		//IL_039a: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d4: 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_03ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_040f: Unknown result type (might be due to invalid IL or missing references)
		//IL_042d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0459: Unknown result type (might be due to invalid IL or missing references)
		//IL_046d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0472: Unknown result type (might be due to invalid IL or missing references)
		//IL_0491: Unknown result type (might be due to invalid IL or missing references)
		//IL_04a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_04aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_04c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_04dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_04e2: 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_0514: Unknown result type (might be due to invalid IL or missing references)
		//IL_0519: Unknown result type (might be due to invalid IL or missing references)
		//IL_0537: Unknown result type (might be due to invalid IL or missing references)
		//IL_054b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0550: Unknown result type (might be due to invalid IL or missing references)
		//IL_056e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0582: Unknown result type (might be due to invalid IL or missing references)
		//IL_0587: Unknown result type (might be due to invalid IL or missing references)
		//IL_05cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0621: Unknown result type (might be due to invalid IL or missing references)
		//IL_0677: Unknown result type (might be due to invalid IL or missing references)
		//IL_06cd: Unknown result type (might be due to invalid IL or missing references)
		Material val = null;
		Material val2 = null;
		Material val3 = null;
		Material val4 = null;
		Transform[] componentsInChildren = ((Component)root).GetComponentsInChildren<Transform>(true);
		foreach (Transform val5 in componentsInChildren)
		{
			Renderer component = ((Component)val5).GetComponent<Renderer>();
			if (Object.op_Implicit((Object)(object)component) && Object.op_Implicit((Object)(object)component.sharedMaterial))
			{
				if (((Object)val5).name.EndsWith(" outward rim", StringComparison.Ordinal))
				{
					val = component.sharedMaterial;
				}
				else if (((Object)val5).name == "Basin bottom")
				{
					val2 = component.sharedMaterial;
				}
				else if (((Object)val5).name.EndsWith(" foot", StringComparison.Ordinal))
				{
					val3 = component.sharedMaterial;
				}
				else if (((Object)val5).name == "VisibleFeed")
				{
					val4 = component.sharedMaterial;
				}
			}
		}
		if (!Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)val2) || !Object.op_Implicit((Object)(object)val3) || !Object.op_Implicit((Object)(object)val4))
		{
			return;
		}
		List<GameObject> list = new List<GameObject>();
		Transform[] componentsInChildren2 = ((Component)root).GetComponentsInChildren<Transform>(true);
		foreach (Transform val6 in componentsInChildren2)
		{
			if ((Object)(object)val6 != (Object)(object)root && (Object)(object)val6.parent == (Object)(object)root)
			{
				list.Add(((Component)val6).gameObject);
			}
		}
		foreach (GameObject item in list)
		{
			Object.DestroyImmediate((Object)(object)item);
		}
		root.localPosition = Vector3.zero;
		root.localRotation = Quaternion.identity;
		root.localScale = Vector3.one;
		float num = 2.6f;
		float num2 = num - 0.65f;
		float num3 = 2.5f;
		AddJointCube(root, "Corner floor X", new Vector3(-1.375f, 0.385f, 0f), new Vector3(2.75f, 0.16f, 0.79f), Quaternion.identity, val2);
		AddJointCube(root, "Corner floor Z", new Vector3(0f, 0.385f, 1.375f), new Vector3(0.79f, 0.16f, 2.75f), Quaternion.identity, val2);
		AddJointCube(root, "Corner floor elbow", new Vector3(0.1975f, 0.385f, -0.1975f), new Vector3(0.395f, 0.16f, 0.395f), Quaternion.identity, val2);
		AddJointCube(root, "Outer wall X", new Vector3((0f - num) * 0.5f, 0.625f, -0.505f), new Vector3(num, 0.55f, 0.23f), Quaternion.identity, val);
		AddJointCube(root, "Outer wall Z", new Vector3(0.505f, 0.625f, num * 0.5f), new Vector3(0.23f, 0.55f, num), Quaternion.identity, val);
		AddJointCube(root, "Inner wall X", new Vector3((0f - (num + 0.65f)) * 0.5f, 0.625f, 0.505f), new Vector3(num2, 0.55f, 0.23f), Quaternion.identity, val);
		AddJointCube(root, "Inner wall Z", new Vector3(-0.505f, 0.625f, (num + 0.65f) * 0.5f), new Vector3(0.23f, 0.55f, num2), Quaternion.identity, val);
		AddJointCube(root, "Inner elbow structural post", new Vector3(-0.52f, 0.405f, 0.52f), new Vector3(0.26f, 0.99f, 0.26f), Quaternion.identity, val);
		AddJointCube(root, "Closed end X", new Vector3(-2.75f, 0.62f, 0f), new Vector3(0.3f, 0.58f, 1.3f), Quaternion.identity, val);
		AddJointCube(root, "Closed end Z", new Vector3(0f, 0.62f, 2.75f), new Vector3(1.3f, 0.58f, 0.3f), Quaternion.identity, val);
		AddMiteredOuterElbow(root, val);
		AddCornerSupportX(root, new Vector3(0f - num3, 0f, -0.39f), val3, val2, "Left end");
		AddCornerSupportZ(root, new Vector3(0.39f, 0f, num3), val3, val2, "Right end");
		AddCornerSupportElbow(root, val3, val2);
		AddJointCube(root, "Left inner end foot", new Vector3(0f - num3, 0.16f, 0.39f), new Vector3(0.34f, 0.36f, 0.27f), Quaternion.identity, val2);
		AddJointCube(root, "Left end cross support", new Vector3(0f - num3, 0.25f, 0f), new Vector3(0.25f, 0.16f, 1.05f), Quaternion.identity, val2);
		AddJointCube(root, "Left inner end iron band", new Vector3(0f - num3, 0.6f, 0.626f), new Vector3(0.1f, 0.58f, 0.025f), Quaternion.identity, val3);
		AddJointCube(root, "Right inner end foot", new Vector3(-0.39f, 0.16f, num3), new Vector3(0.27f, 0.36f, 0.34f), Quaternion.identity, val2);
		AddJointCube(root, "Right end cross support", new Vector3(0f, 0.25f, num3), new Vector3(1.05f, 0.16f, 0.25f), Quaternion.identity, val2);
		AddJointCube(root, "Right inner end iron band", new Vector3(-0.626f, 0.6f, num3), new Vector3(0.025f, 0.58f, 0.1f), Quaternion.identity, val3);
		float[] array = new float[2] { -0.65f, -2.05f };
		foreach (float num4 in array)
		{
			AddExteriorCrossX(root, new Vector3(num4, 0.66f, -0.626f), val3, "Outer X wall brace");
		}
		float[] array2 = new float[2] { -1.1f, -1.92f };
		foreach (float num5 in array2)
		{
			AddExteriorCrossX(root, new Vector3(num5, 0.66f, 0.626f), val3, "Inner wall outer-face brace");
		}
		float[] array3 = new float[2] { 0.65f, 2.05f };
		foreach (float num6 in array3)
		{
			AddExteriorCrossZ(root, new Vector3(0.626f, 0.66f, num6), val3, "Outer Z wall brace");
		}
		float[] array4 = new float[2] { 1.1f, 1.92f };
		foreach (float num7 in array4)
		{
			AddExteriorCrossZ(root, new Vector3(-0.626f, 0.66f, num7), val3, "Inner wall outer-face brace");
		}
		CreateLFeedSurface(root, val4).SetActive(false);
	}

	private static GameObject CreateLFeedSurface(Transform root, Material material)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Expected O, but got Unknown
		//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_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_0079: 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_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0102: Unknown result type (might be due to invalid IL or missing references)
		//IL_011e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0123: Unknown result type (might be due to invalid IL or missing references)
		//IL_0145: Unknown result type (might be due to invalid IL or missing references)
		//IL_014a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0161: 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_017d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0182: Unknown result type (might be due to invalid IL or missing references)
		//IL_0199: Unknown result type (might be due to invalid IL or missing references)
		//IL_019e: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0209: Unknown result type (might be due to invalid IL or missing references)
		//IL_020e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0229: Unknown result type (might be due to invalid IL or missing references)
		//IL_0230: Expected O, but got Unknown
		GameObject val = new GameObject("VisibleFeed");
		val.transform.SetParent(root, false);
		Vector3[] vertices = (Vector3[])(object)new Vector3[8]
		{
			new Vector3(-2.6f, 0.75f, -0.37f),
			new Vector3(0.37f, 0.75f, -0.37f),
			new Vector3(0.37f, 0.75f, 0.37f),
			new Vector3(-2.6f, 0.75f, 0.37f),
			new Vector3(-0.37f, 0.75f, 0.37f),
			new Vector3(0.37f, 0.75f, 0.37f),
			new Vector3(0.37f, 0.75f, 2.6f),
			new Vector3(-0.37f, 0.75f, 2.6f)
		};
		Vector2[] uv = (Vector2[])(object)new Vector2[8]
		{
			new Vector2(0f, 0f),
			new Vector2(4f, 0f),
			new Vector2(4f, 1f),
			new Vector2(0f, 1f),
			new Vector2(0f, 0f),
			new Vector2(1f, 0f),
			new Vector2(1f, 4f),
			new Vector2(0f, 4f)
		};
		int[] triangles = new int[12]
		{
			0, 2, 1, 0, 3, 2, 4, 6, 5, 4,
			7, 6
		};
		Mesh val2 = new Mesh();
		((Object)val2).name = "AFT continuous L-shaped feed surface";
		Mesh val3 = val2;
		val3.vertices = vertices;
		val3.uv = uv;
		val3.triangles = triangles;
		val3.RecalculateNormals();
		val3.RecalculateBounds();
		val.AddComponent<MeshFilter>().sharedMesh = val3;
		((Renderer)val.AddComponent<MeshRenderer>()).sharedMaterial = material;
		return val;
	}

	private static GameObject AddMiteredOuterElbow(Transform root, Material material)
	{
		//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_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_008a: 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_00ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_0105: 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_0178: Unknown result type (might be due to invalid IL or missing references)
		//IL_0219: Unknown result type (might be due to invalid IL or missing references)
		//IL_0243: 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_0297: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ac: 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)
		//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_02eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0319: Unknown result type (might be due to invalid IL or missing references)
		//IL_0320: Expected O, but got Unknown
		//IL_035d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0364: Expected O, but got Unknown
		Vector2[] array = (Vector2[])(object)new Vector2[5]
		{
			new Vector2(0f, -0.62f),
			new Vector2(0.62f, -0.62f),
			new Vector2(0.62f, 0f),
			new Vector2(0.39f, 0f),
			new Vector2(0f, -0.39f)
		};
		List<Vector3> list = new List<Vector3>();
		List<Vector2> list2 = new List<Vector2>();
		List<int> list3 = new List<int>();
		for (int i = 0; i < array.Length; i++)
		{
			list.Add(new Vector3(array[i].x, 0.35f, array[i].y));
			list2.Add(new Vector2(array[i].x / 0.62f, (array[i].y + 0.62f) / 0.62f));
		}
		for (int j = 0; j < array.Length; j++)
		{
			list.Add(new Vector3(array[j].x, 0.9f, array[j].y));
			list2.Add(new Vector2(array[j].x / 0.62f, (array[j].y + 0.62f) / 0.62f));
		}
		for (int k = 1; k < array.Length - 1; k++)
		{
			list3.Add(0);
			list3.Add(k);
			list3.Add(k + 1);
			list3.Add(array.Length);
			list3.Add(array.Length + k + 1);
			list3.Add(array.Length + k);
		}
		for (int l = 0; l < array.Length; l++)
		{
			int num = (l + 1) % array.Length;
			int count = list.Count;
			list.Add(new Vector3(array[l].x, 0.9f, array[l].y));
			list.Add(new Vector3(array[num].x, 0.9f, array[num].y));
			list.Add(new Vector3(array[num].x, 0.35f, array[num].y));
			list.Add(new Vector3(array[l].x, 0.35f, array[l].y));
			list2.Add(new Vector2(0f, 1f));
			list2.Add(new Vector2(1f, 1f));
			list2.Add(new Vector2(1f, 0f));
			list2.Add(new Vector2(0f, 0f));
			AddQuad(list3, count, count + 1, count + 2, count + 3);
		}
		Mesh val = new Mesh();
		((Object)val).name = "AFT mitered outer elbow mesh";
		Mesh val2 = val;
		val2.SetVertices(list);
		val2.SetUVs(0, list2);
		val2.SetTriangles(list3, 0);
		val2.RecalculateNormals();
		val2.RecalculateBounds();
		GameObject val3 = new GameObject("Mitered outer elbow timber");
		val3.transform.SetParent(root, false);
		val3.AddComponent<MeshFilter>().sharedMesh = val2;
		((Renderer)val3.AddComponent<MeshRenderer>()).sharedMaterial = material;
		return val3;
	}

	private static void AddCornerSupportX(Transform root, Vector3 anchor, Material iron, Material support, string label)
	{
		//IL_001e: 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_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: 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)
		AddJointCube(root, label + " foot", new Vector3(anchor.x, 0.16f, -0.39f), new Vector3(0.34f, 0.36f, 0.27f), Quaternion.identity, support);
		AddJointCube(root, label + " flush iron band", new Vector3(anchor.x, 0.6f, -0.626f), new Vector3(0.1f, 0.58f, 0.025f), Quaternion.identity, iron);
	}

	private static void AddCornerSupportZ(Transform root, Vector3 anchor, Material iron, Material support, string label)
	{
		//IL_001e: 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_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: 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)
		AddJointCube(root, label + " foot", new Vector3(0.39f, 0.16f, anchor.z), new Vector3(0.27f, 0.36f, 0.34f), Quaternion.identity, support);
		AddJointCube(root, label + " flush iron band", new Vector3(0.626f, 0.6f, anchor.z), new Vector3(0.025f, 0.58f, 0.1f), Quaternion.identity, iron);
	}

	private static void AddCornerSupportElbow(Transform root, Material iron, Material support)
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: 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_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		AddJointCube(root, "Elbow foot", new Vector3(0.46f, 0.14f, -0.46f), new Vector3(0.28f, 0.34f, 0.28f), Quaternion.identity, iron);
		AddJointCube(root, "Elbow flush band X", new Vector3(0.39f, 0.6f, -0.626f), new Vector3(0.1f, 0.58f, 0.025f), Quaternion.identity, iron);
		AddJointCube(root, "Elbow flush band Z", new Vector3(0.626f, 0.6f, -0.39f), new Vector3(0.025f, 0.58f, 0.1f), Quaternion.identity, iron);
	}

	private static void AddExteriorCrossX(Transform root, Vector3 center, Material iron, string label)
	{
		//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_0030: 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_0058: 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)
		AddJointCube(root, label + " A", center, new Vector3(0.055f, 0.36f, 0.018f), Quaternion.Euler(0f, 0f, 38f), iron);
		AddJointCube(root, label + " B", center, new Vector3(0.055f, 0.36f, 0.018f), Quaternion.Euler(0f, 0f, -38f), iron);
	}

	private static void AddExteriorCrossZ(Transform root, Vector3 center, Material iron, string label)
	{
		//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_0030: 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_0058: 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)
		AddJointCube(root, label + " A", center, new Vector3(0.018f, 0.36f, 0.055f), Quaternion.Euler(38f, 0f, 0f), iron);
		AddJointCube(root, label + " B", center, new Vector3(0.018f, 0.36f, 0.055f), Quaternion.Euler(-38f, 0f, 0f), iron);
	}

	private static GameObject AddJointCube(Transform parent, string name, Vector3 position, Vector3 scale, Quaternion rotation, Material material)
	{
		//IL_0021: 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_0039: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = GameObject.CreatePrimitive((PrimitiveType)3);
		((Object)val).name = name;
		val.transform.SetParent(parent, false);
		val.transform.localPosition = position;
		val.transform.localScale = scale;
		val.transform.localRotation = rotation;
		Object.DestroyImmediate((Object)(object)val.GetComponent<Collider>());
		val.GetComponent<Renderer>().sharedMaterial = material;
		return val;
	}
}
internal static class TroughVariantIcons
{
	private static readonly Dictionary<TroughVariant, Sprite> Icons = new Dictionary<TroughVariant, Sprite>();

	internal static Sprite Create(TroughVariant variant)
	{
		//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0203: Expected O, but got Unknown
		//IL_034c: Unknown result type (might be due to invalid IL or missing references)
		//IL_035b: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0304: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fc: Unknown result type (might be due to invalid IL or missing references)
		if (Icons.TryGetValue(variant, out var value) && Object.op_Implicit((Object)(object)value))
		{
			return value;
		}
		switch (variant)
		{
		case TroughVariant.Standard:
			return Icons[variant] = TroughModelV3.CreateIcon();
		case TroughVariant.Compact:
			return Icons[variant] = TroughModelV3.CreateIcon("AnimalFeedingTroughV3.IconCompact", "Compact Feeding Trough build icon");
		case TroughVariant.Small:
			return Icons[variant] = TroughModelV3.CreateIcon("AnimalFeedingTroughV3.IconSmall", "Small Animal Feeding Trough build icon");
		case TroughVariant.Curved:
			return Icons[variant] = TroughModelV3.CreateIcon("AnimalFeedingTroughV3.IconCurved", "Curved Feeding Trough build icon");
		case TroughVariant.CurvedCompact:
			return Icons[variant] = TroughModelV3.CreateIcon("AnimalFeedingTroughV3.IconCurvedCompact", "Compact Curved Feeding Trough build icon");
		case TroughVariant.CurvedTiny:
			return Icons[variant] = TroughModelV3.CreateIcon("AnimalFeedingTroughV3.IconCurvedTiny", "Tiny Curved Feeding Trough build icon");
		case TroughVariant.Corner:
			return Icons[variant] = TroughModelV3.CreateIcon("AnimalFeedingTroughV3.IconCorner", "Corner Feeding Trough build icon");
		case TroughVariant.CornerCompact:
			return Icons[variant] = TroughModelV3.CreateIcon("AnimalFeedingTroughV3.IconCornerCompact", "Compact Corner Feeding Trough build icon");
		case TroughVariant.CornerTiny:
			return Icons[variant] = TroughModelV3.CreateIcon("AnimalFeedingTroughV3.IconCornerTiny", "Tiny Corner Feeding Trough build icon");
		case TroughVariant.ChickenBowl:
			return Icons[variant] = TroughModelV3.CreateIcon("AnimalFeedingTroughV3.IconChickenBowl", "Chicken Feeding Bowl build icon");
		default:
		{
			try
			{
				value = RenderModelIcon(variant);
				if (Object.op_Implicit((Object)(object)value))
				{
					Icons[variant] = value;
					return value;
				}
			}
			catch (Exception ex)
			{
				Debug.LogWarning((object)string.Concat("[Animal Feeding Trough] Could not render the ", variant, " build icon; using the safe embedded fallback. ", ex.Message));
			}
			Sprite val = TroughModelV3.CreateIcon();
			Texture2D texture = val.texture;
			int width = ((Texture)texture).width;
			int height = ((Texture)texture).height;
			Texture2D val2 = new Texture2D(width, height, (TextureFormat)4, false);
			((Object)val2).name = string.Concat("Animal Feeding Trough ", variant, " build icon");
			Color[] pixels = texture.GetPixels();
			Color val3 = default(Color);
			((Color)(ref val3))..ctor(0f, 0f, 0f, 0f);
			float num = TroughVariantGeometry.LengthScale(variant);
			float num2 = ((variant == TroughVariant.Small) ? 0.74f : 1f);
			for (int i = 0; i < height; i++)
			{
				for (int j = 0; j < width; j++)
				{
					float num3 = ((float)j - (float)width * 0.5f) / Mathf.Max(0.01f, num) + (float)width * 0.5f;
					float num4 = ((float)i - (float)height * 0.5f) / num2 + (float)height * 0.5f;
					Color val4 = val3;
					if (num3 >= 0f && num3 < (float)width && num4 >= 0f && num4 < (float)height)
					{
						val4 = pixels[Mathf.Clamp((int)num4, 0, height - 1) * width + Mathf.Clamp((int)num3, 0, width - 1)];
					}
					val2.SetPixel(j, i, val4);
				}
			}
			val2.Apply(false, false);
			((Texture)val2).wrapMode = (TextureWrapMode)1;
			value = Sprite.Create(val2, new Rect(0f, 0f, (float)width, (float)height), new Vector2(0.5f, 0.5f), (float)width);
			Icons[variant] = value;
			return value;
		}
		}
	}

	private static Sprite RenderModelIcon(TroughVariant variant)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Invalid comparison between Unknown and I4
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: 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_00a3: 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_00c6: Expected O, but got Unknown
		//IL_00f9: 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_0129: Unknown result type (might be due to invalid IL or missing references)
		//IL_0135: Unknown result type (might be due to invalid IL or missing references)
		//IL_0163: Unknown result type (might be due to invalid IL or missing references)
		//IL_0177: 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_018f: 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_019e: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0211: 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_022a: Unknown result type (might be due to invalid IL or missing references)
		//IL_023d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0242: Unknown result type (might be due to invalid IL or missing references)
		//IL_024c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0251: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0306: Expected O, but got Unknown
		//IL_0345: Unknown result type (might be due to invalid IL or missing references)
		//IL_035c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0363: Expected O, but got Unknown
		//IL_0395: Unknown result type (might be due to invalid IL or missing references)
		//IL_039c: Expected O, but got Unknown
		//IL_03ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_0264: Unknown result type (might be due to invalid IL or missing references)
		//IL_0276: Unknown result type (might be due to invalid IL or missing references)
		//IL_0282: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_044d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0454: Expected O, but got Unknown
		//IL_046a: Unknown result type (might be due to invalid IL or missing references)
		//IL_04f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0506: Unknown result type (might be due to invalid IL or missing references)
		if ((int)SystemInfo.graphicsDeviceType == 4)
		{
			return null;
		}
		GameObject val = new GameObject("xneliox_IconStage_" + variant);
		AssetBundleTroughModel.Instantiate(val.transform, variant);
		Transform[] componentsInChildren = val.GetComponentsInChildren<Transform>(true);
		foreach (Transform val2 in componentsInChildren)
		{
			((Component)val2).gameObject.layer = 31;
			if (((Object)val2).name == "VisibleFeed")
			{
				((Component)val2).gameObject.SetActive(true);
			}
		}
		Renderer[] componentsInChildren2 = val.GetComponentsInChildren<Renderer>(true);
		if (componentsInChildren2.Length == 0)
		{
			Object.DestroyImmediate((Object)(object)val);
			return null;
		}
		Bounds bounds = componentsInChildren2[0].bounds;
		for (int j = 1; j < componentsInChildren2.Length; j++)
		{
			((Bounds)(ref bounds)).Encapsulate(componentsInChildren2[j].bounds);
		}
		GameObject val3 = new GameObject("xneliox_IconCamera");
		Camera val4 = val3.AddComponent<Camera>();
		val4.cullingMask = int.MinValue;
		val4.clearFlags = (CameraClearFlags)2;
		val4.backgroundColor = new Color(0f, 0f, 0f, 0f);
		val4.orthographic = true;
		switch (variant)
		{
		case TroughVariant.ChickenBowl:
			val4.orthographicSize = Mathf.Max(((Bounds)(ref bounds)).extents.y * 2.1f, Mathf.Max(((Bounds)(ref bounds)).extents.x, ((Bounds)(ref bounds)).extents.z) * 0.88f) + 0.1f;
			((Component)val4).transform.position = ((Bounds)(ref bounds)).center + new Vector3(6f, 4f, -7f);
			((Component)val4).transform.LookAt(((Bounds)(ref bounds)).center + Vector3.up * 0.015f);
			break;
		case TroughVariant.Corner:
		case TroughVariant.CornerCompact:
		case TroughVariant.CornerTiny:
			val4.orthographicSize = Mathf.Max(((Bounds)(ref bounds)).extents.y * 1.9f, Mathf.Max(((Bounds)(ref bounds)).extents.x, ((Bounds)(ref bounds)).extents.z) * 0.96f) + 0.24f;
			((Component)val4).transform.position = ((Bounds)(ref bounds)).center + new Vector3(-6f, 4f, 7f);
			((Component)val4).transform.LookAt(((Bounds)(ref bounds)).center + Vector3.up * 0.035f);
			break;
		default:
			val4.orthographicSize = Mathf.Max(((Bounds)(ref bounds)).extents.y * 1.7f, Mathf.Max(((Bounds)(ref bounds)).extents.x, ((Bounds)(ref bounds)).extents.z) * 0.72f) + 0.18f;
			((Component)val4).transform.position = ((Bounds)(ref bounds)).center + new Vector3(6f, 4f, -7f);
			((Component)val4).transform.LookAt(((Bounds)(ref bounds)).center + Vector3.up * 0.04f);
			break;
		}
		GameObject val5 = new GameObject("xneliox_IconLight");
		Light val6 = val5.AddComponent<Light>();
		val6.type = (LightType)1;
		val6.intensity = 1.25f;
		val6.cullingMask = int.MinValue;
		val5.transform.rotation = Quaternion.Euler(42f, -35f, 0f);
		RenderTexture val7 = new RenderTexture(256, 256, 24, (RenderTextureFormat)0);
		val7.antiAliasing = 4;
		val4.targetTexture = val7;
		RenderTexture active = RenderTexture.active;
		val4.Render();
		RenderTexture.active = val7;
		Texture2D val8 = new Texture2D(256, 256, (TextureFormat)4, false);
		((Object)val8).name = string.Concat("Animal Feeding Trough ", variant, " current model icon v2");
		val8.ReadPixels(new Rect(0f, 0f, 256f, 256f), 0, 0);
		val8.Apply(false, false);
		bool[] array = new bool[componentsInChildren2.Length];
		for (int k = 0; k < componentsInChildren2.Length; k++)
		{
			array[k] = componentsInChildren2[k].enabled;
			componentsInChildren2[k].enabled = array[k] && IsDarkIconDetail(((Object)((Component)componentsInChildren2[k]).transform).name);
		}
		val4.Render();
		RenderTexture.active = val7;
		Texture2D val9 = new Texture2D(256, 256, (TextureFormat)4, false);
		val9.ReadPixels(new Rect(0f, 0f, 256f, 256f), 0, 0);
		val9.Apply(false, false);
		for (int l = 0; l < componentsInChildren2.Length; l++)
		{
			componentsInChildren2[l].enabled = array[l];
		}
		MatchNormalTroughIconColors(val8, val9);
		Object.DestroyImmediate((Object)(object)val9);
		((Texture)val8).wrapMode = (TextureWrapMode)1;
		RenderTexture.active = active;
		val4.targetTexture = null;
		Object.DestroyImmediate((Object)(object)val7);
		Object.DestroyImmediate((Object)(object)val5);
		Object.DestroyImmediate((Object)(object)val3);
		Object.DestroyImmediate((Object)(object)val);
		return Sprite.Create(val8, new Rect(0f, 0f, 256f, 256f), new Vector2(0.5f, 0.5f), 256f);
	}

	private static bool IsDarkIconDetail(string name)
	{
		string text = name.ToLowerInvariant();
		if (!text.Contains("foot") && !text.Contains("iron") && !text.Contains("band") && !text.Contains("brace") && !text.Contains("rune"))
		{
			return text.Contains("cross support");
		}
		return true;
	}

	private static void MatchNormalTroughIconColors(Texture2D texture, Texture2D detailMask)
	{
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_00da: Unknown result type (might be due to invalid IL or missing references)
		//IL_00df: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: 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)
		Color[] pixels = texture.GetPixels();
		Color[] pixels2 = detailMask.GetPixels();
		for (int i = 0; i < pixels.Length; i++)
		{
			Color val = pixels[i];
			if (!(val.a <= 0.01f))
			{
				float num = Mathf.Clamp01(val.r * 0.3f + val.g * 0.59f + val.b * 0.11f);
				if (pixels2[i].a > 0.02f)
				{
					pixels[i] = val;
					continue;
				}
				float num2 = Mathf.Pow(num, 0.98f);
				ref Color reference = ref pixels[i];
				reference = new Color(Mathf.Clamp01(0.055f + num2 * 0.76f), Mathf.Clamp01(0.035f + num2 * 0.46f), Mathf.Clamp01(0.02f + num2 * 0.25f), val.a);
			}
		}
		texture.SetPixels(pixels);
		texture.Apply(false, false);
	}
}
public sealed class TroughFeeder : MonoBehaviour
{
	private const float AttractionRange = 16f;

	private const string ServingMarker = "xneliox_trough_serving";

	private static readonly MethodInfo CanConsumeMethod = AccessTools.Method(typeof(MonsterAI), "CanConsume", (Type[])null, (Type[])null);

	private static readonly MethodInfo InventoryChangedMethod = AccessTools.Method(typeof(Inventory), "Changed", new Type[2]
	{
		typeof(bool),
		typeof(bool)
	}, (Type[])null);

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

	private static readonly FieldInfo ConsumeTargetField = AccessTools.Field(typeof(MonsterAI), "m_consumeTarget");

	private static readonly FieldInfo ConsumeSearchTimerField = AccessTools.Field(typeof(MonsterAI), "m_consumeSearchTimer");

	private Container _container;

	private ZNetView _view;

	private readonly List<GameObject> _visibleFeeds = new List<GameObject>();

	private float _nextSearch;

	private float _nextVisualRefresh;

	private TroughVariant _variant;

	private float _lengthScale = 1f;

	private ItemDrop _currentServing;

	internal void SetVariant(TroughVariant variant)
	{
		_variant = variant;
		_lengthScale = TroughVariantGeometry.LengthScale(variant);
	}

	private void Awake()
	{
		_container = ((Component)this).GetComponent<Container>();
		_view = ((Component)this).GetComponent<ZNetView>();
		_visibleFeeds.Clear();
		Transform[] componentsInChildren = ((Component)this).GetComponentsInChildren<Transform>(true);
		foreach (Transform val in componentsInChildren)
		{
			if (((Object)val).name == "VisibleFeed")
			{
				_visibleFeeds.Add(((Component)val).gameObject);
			}
		}
	}

	private void Update()
	{
		//IL_00d7: 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)
		RefreshFeedVisual();
		if (!Object.op_Implicit((Object)(object)_container) || !Object.op_Implicit((Object)(object)_view) || !_view.IsValid() || Time.time < _nextSearch)
		{
			return;
		}
		_nextSearch = Time.time + 2f;
		EnableTroughSearchForOwnedAnimals();
		if (!_view.IsOwner())
		{
			return;
		}
		if (Object.op_Implicit((Object)(object)_currentServing))
		{
			ZNetView component = ((Component)_currentServing).GetComponent<ZNetView>();
			if (_currentServing.m_itemData != null && _currentServing.m_itemData.m_stack > 0 && Object.op_Implicit((Object)(object)component) && component.IsValid())
			{
				return;
			}
			_currentServing = null;
		}
		List<Character> allCharacters = Character.GetAllCharacters();
		foreach (Character item in allCharacters)
		{
			if (!Object.op_Implicit((Object)(object)item))
			{
				continue;
			}
			float num = Vector3.Distance(((Component)this).transform.position, ((Component)item).transform.position);
			if (num > 16f)
			{
				continue;
			}
			Tameable component2 = ((Component)item).GetComponent<Tameable>();
			MonsterAI component3 = ((Component)item).GetComponent<MonsterAI>();
			if (Object.op_Implicit((Object)(object)component2) && Object.op_Implicit((Object)(object)component3) && CanUseTrough(item, component2))
			{
				ItemData val = FindFood(component3);
				if (val != null)
				{
					SpawnServing(val, item);
					break;
				}
			}
		}
	}

	private void EnableTroughSearchForOwnedAnimals()
	{
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		List<Character> allCharacters = Character.GetAllCharacters();
		foreach (Character item in allCharacters)
		{
			if (!Object.op_Implicit((Object)(object)item))
			{
				continue;
			}
			float num = Vector3.Distance(((Component)this).transform.position, ((Component)item).transform.position);
			if (num > 16f)
			{
				continue;
			}
			Tameable component = ((Component)item).GetComponent<Tameable>();
			MonsterAI component2 = ((Component)item).GetComponent<MonsterAI>();
			ZNetView component3 = ((Component)item).GetComponent<ZNetView>();
			if (Object.op_Implicit((Object)(object)component) && Object.op_Implicit((Object)(object)component2) && Object.op_Implicit((Object)(object)component3) && component3.IsValid() && CanUseTrough(item, component) && component3.IsOwner())
			{
				ItemData val = FindFood(component2);
				if (val != null && component2.m_consumeSearchRange < 16f)
				{
					component2.m_consumeSearchRange = 16f;
				}
			}
		}
	}

	private static bool CanUseTrough(Character character, Tameable tameable)
	{
		if (!Object.op_Implicit((Object)(object)character) || !Object.op_Implicit((Object)(object)tameable) || !tameable.IsHungry())
		{
			return false;
		}
		return true;
	}

	private void SpawnServing(ItemData food, Character animal)
	{
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0314: Unknown result type (might be due to invalid IL or missing references)
		//IL_0316: Unknown result type (might be due to invalid IL or missing references)
		//IL_031b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0330: Unknown result type (might be due to invalid IL or missing references)
		//IL_0332: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0300: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_02eb: Unknown result type (might be due to invalid IL or missing references)
		if (food == null || (Object)(object)animal == (Object)null || (Object)(object)_container == (Object)null || _container.GetInventory() == null)
		{
			return;
		}
		Vector3 val = ((Component)this).transform.InverseTransformPoint(((Component)animal).transform.position);
		float[] array = ((_variant == TroughVariant.Small || _variant == TroughVariant.CurvedTiny) ? new float[3]
		{
			-0.65f * _lengthScale,
			0f,
			0.65f * _lengthScale
		} : new float[4]
		{
			-1.65f * _lengthScale,
			-0.55f * _lengthScale,
			0.55f * _lengthScale,
			1.65f * _lengthScale
		});
		float num = array[0];
		float num2 = Mathf.Abs(val.x - num);
		float[] array2 = array;
		foreach (float num3 in array2)
		{
			float num4 = Mathf.Abs(val.x - num3);
			if (num4 < num2)
			{
				num2 = num4;
				num = num3;
			}
		}
		float num5 = ((!(val.z < 0f)) ? 1f : (-1f));
		Vector3 val2 = default(Vector3);
		((Vector3)(ref val2))..ctor(num, 0.12f, num5 * 0.95f);
		if (_variant == TroughVariant.Compact)
		{
			val2.z = num5 * 0.78f;
		}
		if (_variant == TroughVariant.Small)
		{
			val2.z = num5 * 0.7f;
		}
		if (_variant == TroughVariant.Curved || _variant == TroughVariant.CurvedCompact || _variant == TroughVariant.CurvedTiny)
		{
			float num6 = ((_variant == TroughVariant.CurvedTiny) ? 3.25f : ((_variant == TroughVariant.CurvedCompact) ? 4.8f : 6.5f));
			if (_variant == TroughVariant.CurvedTiny)
			{
				val2.z = num5 * 0.68f;
			}
			float num7 = num / num6;
			val2.x = Mathf.Sin(num7) * (num6 - val2.z);
			val2.z = num6 - Mathf.Cos(num7) * (num6 - val2.z);
		}
		if (_variant == TroughVariant.Corner || _variant == TroughVariant.CornerCompact || _variant == TroughVariant.CornerTiny)
		{
			float num8 = ((_variant == TroughVariant.Corner) ? 0.95f : ((_variant == TroughVariant.CornerCompact) ? 0.68f : 0.49f));
			float num9 = ((_variant == TroughVariant.Corner) ? 1.25f : ((_variant == TroughVariant.CornerCompact) ? 0.9f : 0.65f));
			val2.z = num5 * num8;
			if (Mathf.Abs(val.z) > Mathf.Abs(val.x))
			{
				((Vector3)(ref val2))..ctor(num5 * num8, 0.12f, num + num9);
			}
		}
		if (_variant == TroughVariant.ChickenBowl)
		{
			Vector3 forward = default(Vector3);
			((Vector3)(ref forward))..ctor(val.x, 0f, val.z);
			if (((Vector3)(ref forward)).sqrMagnitude < 0.001f)
			{
				forward = Vector3.forward;
			}
			((Vector3)(ref forward)).Normalize();
			val2 = forward * 0.78f;
			val2.y = 0.08f;
		}
		Vector3 val3 = ((Component)this).transform.TransformPoint(val2);
		ItemData val4 = food.Clone();
		val4.m_stack = 1;
		ItemDrop val5 = ItemDrop.DropItem(val4, 1, val3, Quaternion.identity);
		if (!Object.op_Implicit((Object)(object)val5))
		{
			Debug.LogWarning((object)"[Animal Feeding Trough] Could not create a food serving.");
			return;
		}
		_currentServing = val5;
		MonsterAI component = ((Component)animal).GetComponent<MonsterAI>();
		ZNetView component2 = ((Component)animal).GetComponent<ZNetView>();
		if (Object.op_Implicit((Object)(object)component) && Object.op_Implicit((Object)(object)component2) && component2.IsValid() && component2.IsOwner())
		{
			component.m_consumeSearchRange = Mathf.Max(component.m_consumeSearchRange, 16f);
			if (ConsumeTargetField != null)
			{
				ConsumeTargetField.SetValue(component, val5);
			}
			if (ConsumeSearchTimerField != null)
			{
				ConsumeSearchTimerField.SetValue(component, 0f);
			}
		}
		ZNetView component3 = ((Component)val5).GetComponent<ZNetView>();
		if (Object.op_Implicit((Object)(object)component3) && component3.IsValid() && component3.IsOwner())
		{
			component3.GetZDO().Set("xneliox_trough_serving", true);
		}
		Renderer[] componentsInChildren = ((Component)val5).GetComponentsInChildren<Renderer>(true);
		foreach (Renderer val6 in componentsInChildren)
		{
			val6.enabled = false;
		}
		ParticleSystem[] componentsInChildren2 = ((Component)val5).GetComponentsInChildren<ParticleSystem>(true);
		foreach (ParticleSystem val7 in componentsInChildren2)
		{
			val7.Stop(true, (ParticleSystemStopBehavior)0);
			Renderer component4 = ((Component)val7).GetComponent<Renderer>();
			if (Object.op_Implicit((Object)(object)component4))
			{
				component4.enabled = false;
			}
		}
		Light[] componentsInChildren3 = ((Component)val5).GetComponentsInChildren<Light>(true);
		foreach (Light val8 in componentsInChildren3)
		{
			((Behaviour)val8).enabled = false;
		}
		Inventory inventory = _container.GetInventory();
		inventory.RemoveItem(food, 1);
		if (InventoryChangedMethod != null)
		{
			InventoryChangedMethod.Invoke(inventory, new object[2] { false, false });
		}
		if (ContainerSaveMethod != null)
		{
			ContainerSaveMethod.Invoke(_container, null);
		}
	}

	private void RefreshFeedVisual()
	{
		if (_visibleFeeds.Count == 0 || Time.time < _nextVisualRefresh)
		{
			return;
		}
		_nextVisualRefresh = Time.time + 0.35f;
		bool active = false;
		if (Object.op_Implicit((Object)(object)_container) && _container.GetInventory() != null)
		{
			foreach (ItemData allItem in _container.GetInventory().GetAllItems())
			{
				if (allItem != null && allItem.m_stack > 0 && TroughFoodRules.IsFood(allItem))
				{
					active = true;
					break;
				}
			}
		}
		if (Object.op_Implicit((Object)(object)_currentServing) && _currentServing.m_itemData != null && _currentServing.m_itemData.m_stack > 0)
		{
			active = true;
		}
		foreach (GameObject visibleFeed in _visibleFeeds)
		{
			if (Object.op_Implicit((Object)(object)visibleFeed))
			{
				visibleFeed.SetActive(active);
			}
		}
	}

	private ItemData FindFood(MonsterAI ai)
	{
		if ((Object)(object)ai == (Object)null || (Object)(object)_container == (Object)null)
		{
			return null;
		}
		Inventory inventory = _container.GetInventory();
		if (inventory == null)
		{
			return null;
		}
		foreach (ItemData allItem in inventory.GetAllItems())
		{
			if (allItem != null && allItem.m_stack > 0 && !(CanConsumeMethod == null))
			{
				object obj = CanConsumeMethod.Invoke(ai, new object[1] { allItem });
				if (obj is bool && (bool)obj)
				{
					return allItem;
				}
			}
		}
		return null;
	}
}
internal static class TroughModelV3
{
	internal const string RootName = "AnimalFeedingTroughModelV3";

	internal const string FeedName = "VisibleFeed";

	private const string WoodResource = "AnimalFeedingTroughV3.Wood";

	private const string MetalResource = "AnimalFeedingTroughV3.Metal";

	private const string FeedResource = "AnimalFeedingTroughV3.Feed";

	private const string IconResource = "AnimalFeedingTroughV3.Icon";

	private static Material _wood;

	private static Material _darkWood;

	private static Material _iron;

	private static Material _feed;

	internal static void Build(Transform parent, Shader fallbackShader)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Expected O, but got Unknown
		//IL_001b: 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_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: 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_00bf: 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_00e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0115: Unknown result type (might be due to invalid IL or missing references)
		//IL_0124: Unknown result type (might be due to invalid IL or missing references)
		//IL_0129: Unknown result type (might be due to invalid IL or missing references)
		//IL_0143: Unknown result type (might be due to invalid IL or missing references)
		//IL_0152: 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_017b: 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_01be: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d7: 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_021a: Unknown result type (might be due to invalid IL or missing references)
		//IL_023e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0243: Unknown result type (might be due to invalid IL or missing references)
		//IL_0259: Unknown result type (might be due to invalid IL or missing references)
		//IL_0272: Unknown result type (might be due to invalid IL or missing references)
		//IL_0298: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_031a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0333: Unknown result type (might be due to invalid IL or missing references)
		//IL_0388: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_0413: Unknown result type (might be due to invalid IL or missing references)
		//IL_043b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0462: 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_04b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_04d9: 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_0519: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject("AnimalFeedingTroughModelV3");
		Transform transform = val.transform;
		transform.SetParent(parent, false);
		transform.localPosition = Vector3.zero;
		transform.localRotation = Quaternion.identity;
		transform.localScale = Vector3.one;
		Shader val2 = Shader.Find("Standard") ?? fallbackShader;
		if (!Object.op_Implicit((Object)(object)val2))
		{
			throw new InvalidOperationException("No supported shader is available for the feeding trough.");
		}
		_wood = CreateMaterial("AFT V3 - aged oak", val2, "AnimalFeedingTroughV3.Wood", Color.white, 0f, 0.22f, new Vector2(2.15f, 0.135f), new Vector2(0f, 0.335f));
		_darkWood = CreateMaterial("AFT V3 - carved oak", val2, "AnimalFeedingTroughV3.Wood", new Color(0.47f, 0.39f, 0.31f, 1f), 0f, 0.16f, new Vector2(2.15f, 0.135f), new Vector2(0f, 0.335f));
		_iron = CreateMaterial("AFT V3 - forged iron", val2, "AnimalFeedingTroughV3.Metal", new Color(0.58f, 0.6f, 0.61f, 1f), 0.72f, 0.28f, Vector2.one, Vector2.zero);
		_feed = CreateMaterial("AFT V3 - straw vegetables and berries", val2, "AnimalFeedingTroughV3.Feed", Color.white, 0f, 0.12f, Vector2.one, Vector2.zero);
		CreateBeam(transform, "Front solid oak wall", new Vector3(0f, 0.625f, -0.505f), 4.92f, 0.55f, 0.23f, 0.045f, Quaternion.identity, _wood, 3.6f);
		CreateBeam(transform, "Rear solid oak wall", new Vector3(0f, 0.625f, 0.505f), 4.92f, 0.55f, 0.23f, 0.045f, Quaternion.identity, _wood, 3.6f);
		CreateBeam(transform, "Solid basin floor", new Vector3(0f, 0.385f, 0f), 4.72f, 0.16f, 0.79f, 0.035f, Quaternion.identity, _darkWood, 3.5f);
		Quaternion rotation = Quaternion.Euler(0f, 90f, 0f);
		CreateBeam(transform, "Closed left end", new Vector3(-2.48f, 0.62f, 0f), 1.18f, 0.58f, 0.3f, 0.05f, rotation, _wood, 0.9f);
		CreateBeam(transform, "Closed right end", new Vector3(2.48f, 0.62f, 0f), 1.18f, 0.58f, 0.3f, 0.05f, rotation, _wood, 0.9f);
		CreateBeam(transform, "Left wooden locking peg", new Vector3(-2.665f, 0.61f, 0f), 0.13f, 0.17f, 0.17f, 0.025f, Quaternion.identity, _darkWood, 0.25f);
		CreateBeam(transform, "Right wooden locking peg", new Vector3(2.665f, 0.61f, 0f), 0.13f, 0.17f, 0.17f, 0.025f, Quaternion.identity, _darkWood, 0.25f);
		float[] array = new float[3] { -2.02f, 0f, 2.02f };
		foreach (float num in array)
		{
			CreateBeam(transform, "Cross support", new Vector3(num, 0.255f, 0f), 1.17f, 0.15f, 0.23f, 0.025f, rotation, _darkWood, 0.9f);
			CreateBeam(transform, "Front foot", new Vector3(num, 0.13f, -0.4f), 0.43f, 0.28f, 0.31f, 0.035f, Quaternion.Euler(-7f, 0f, 0f), _wood, 0.7f);
			CreateBeam(transform, "Rear foot", new Vector3(num, 0.13f, 0.4f), 0.43f, 0.28f, 0.31f, 0.035f, Quaternion.Euler(7f, 0f, 0f), _wood, 0.7f);
			CreateBeam(transform, "Front flush iron band", new Vector3(num, 0.625f, -0.626f), 0.54f, 0.105f, 0.028f, 0.012f, Quaternion.Euler(0f, 0f, 90f), _iron, 0.55f);
			CreateBeam(transform, "Rear flush iron band", new Vector3(num, 0.625f, 0.626f), 0.54f, 0.105f, 0.028f, 0.012f, Quaternion.Euler(0f, 0f, 90f), _iron, 0.55f);
			CreateBeam(transform, "Top flush iron band", new Vector3(num, 0.905f, 0f), 1.15f, 0.055f, 0.105f, 0.012f, rotation, _iron, 0.9f);
		}
		AddCarvedRunes(transform, -0.626f, reverse: false);
		AddCarvedRunes(transform, 0.626f, reverse: true);
		GameObject val3 = CreateFeedSurface(transform);
		val3.SetActive(false);
	}

	private static void AddCarvedRunes(Transform root, float z, bool reverse)
	{
		//IL_003b: 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_0087: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
		float[] array = new float[6] { -1.54f, -1.12f, -0.7f, 0.7f, 1.12f, 1.54f };
		foreach (float num in array)
		{
			float num2 = (reverse ? (-1f) : 1f);
			CreateBeam(root, "Shallow carved rune", new Vector3(num, 0.61f, z), 0.26f, 0.042f, 0.016f, 0.006f, Quaternion.Euler(0f, 0f, 38f * num2), _darkWood, 0.25f);
			CreateBeam(root, "Shallow carved rune", new Vector3(num, 0.61f, z), 0.26f, 0.042f, 0.016f, 0.006f, Quaternion.Euler(0f, 0f, -38f * num2), _darkWood, 0.25f);
		}
	}

	private static GameObject CreateFeedSurface(Transform root)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Expected O, but got Unknown
		//IL_00f6: 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_0117: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b3: Expected O, but got Unknown
		GameObject val = new GameObject("VisibleFeed");
		val.transform.SetParent(root, false);
		int num = 49;
		List<Vector3> list = new List<Vector3>(539);
		List<Vector3> list2 = new List<Vector3>(539);
		List<Vector2> list3 = new List<Vector2>(539);
		List<int> list4 = new List<int>(2880);
		for (int i = 0; i <= 10; i++)
		{
			float num2 = (float)i / 10f;
			for (int j = 0; j <= 48; j++)
			{
				float num3 = (float)j / 48f;
				float num4 = Mathf.Sin(num3 * (float)Math.PI) * Mathf.Sin(num2 * (float)Math.PI);
				float num5 = 0.012f * num4 * (Mathf.Sin((float)j * 1.31f + (float)i * 0.73f) + Mathf.Sin((float)j * 0.43f - (float)i * 1.19f));
				list.Add(new Vector3((num3 - 0.5f) * 4.53f, 0.76f + 0.1f * num4 + num5, (num2 - 0.5f) * 0.69f));
				list2.Add(Vector3.up);
				list3.Add(new Vector2(num3 * 6.55f, num2));
			}
		}
		for (int k = 0; k < 10; k++)
		{
			for (int l = 0; l < 48; l++)
			{
				int num6 = k * num + l;
				int num7 = num6 + num;
				list4.Add(num6);
				list4.Add(num7);
				list4.Add(num6 + 1);
				list4.Add(num6 + 1);
				list4.Add(num7);
				list4.Add(num7 + 1);
			}
		}
		Mesh val2 = new Mesh();
		((Object)val2).name = "AFT V3 continuous feed surface";
		Mesh val3 = val2;
		val3.SetVertices(list);
		val3.SetNormals(list2);
		val3.SetUVs(0, list3);
		val3.SetTriangles(list4, 0);
		val3.RecalculateNormals();
		val3.RecalculateBounds();
		val.AddComponent<MeshFilter>().sharedMesh = val3;
		((Renderer)val.AddComponent<MeshRenderer>()).sharedMaterial = _feed;
		return val;
	}

	private static GameObject CreateBeam(Transform parent, string name, Vector3 position, float length, float height, float depth, float bevel, Quaternion rotation, Material material, float uvLength)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Expected O, but got Unknown
		//IL_001a: 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)
		GameObject val = new GameObject(name);
		val.transform.SetParent(parent, false);
		val.transform.localPosition = position;
		val.transform.localRotation = rotation;
		val.AddComponent<MeshFilter>().sharedMesh = BuildBevelledBeamMesh(name + " mesh", length, height, depth, bevel, uvLength);
		((Renderer)val.AddComponent<MeshRenderer>()).sharedMaterial = material;
		return val;
	}

	private static Mesh BuildBevelledBeamMesh(string name, float length, float height, float depth, float bevel, float uvLength)
	{
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: 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_008c: 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_00a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d3: 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_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)
		//IL_0147: Unknown result type (might be due to invalid IL or missing references)
		//IL_016e: 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_01bd: 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_01e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_020f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0283: Unknown result type (might be due to invalid IL or missing references)
		//IL_028a: Expected O, but got Unknown
		float num =

plugins/AutoRepairFix/AutoRepairFix.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Bootstrap;
using HarmonyLib;
using UnityEngine;

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

[BepInPlugin("ninefinger.valheim.autorepairfix", "Auto Repair Fix", "1.2.4")]
[BepInProcess("valheim.exe")]
public class AutoRepairFixPlugin : BaseUnityPlugin
{
	private readonly Harmony harmony = new Harmony("ninefinger.valheim.autorepairfix");

	public static Coroutine repairRoutine = null;

	public static AutoRepairFixPlugin instance = null;

	public static MethodInfo onRepairPressedMethodToken;

	public static WaitForSeconds waitForPacingInterval;

	public static bool firstPersonEnginePresent = false;

	private void Awake()
	{
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Expected O, but got Unknown
		instance = this;
		waitForPacingInterval = new WaitForSeconds(0.1f);
		onRepairPressedMethodToken = AccessTools.Method(typeof(InventoryGui), "OnRepairPressed", (Type[])null, (Type[])null);
		firstPersonEnginePresent = Chainloader.PluginInfos.ContainsKey("FirstPersonPerspective.Core");
		harmony.PatchAll();
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Auto Repair Fix v1.2.4: Zero-Allocation Master Build Loaded Successfully!");
	}

	private void OnDestroy()
	{
		harmony.UnpatchSelf();
		StopActiveRepair();
	}

	public static void StopActiveRepair()
	{
		if ((Object)(object)instance != (Object)null && repairRoutine != null)
		{
			((MonoBehaviour)instance).StopCoroutine(repairRoutine);
		}
		repairRoutine = null;
	}
}
[HarmonyPatch(typeof(InventoryGui), "Show")]
internal static class AutoRepair_Open_Patch
{
	[HarmonyPostfix]
	private static void Postfix(InventoryGui __instance)
	{
		if (!((Object)(object)__instance == (Object)null) && !((Object)(object)AutoRepairFixPlugin.instance == (Object)null) && AutoRepairFixPlugin.repairRoutine == null)
		{
			Player localPlayer = Player.m_localPlayer;
			if (!((Object)(object)localPlayer == (Object)null) && !((Object)(object)localPlayer.GetCurrentCraftingStation() == (Object)null))
			{
				AutoRepairFixPlugin.repairRoutine = ((MonoBehaviour)AutoRepairFixPlugin.instance).StartCoroutine(AutoRepair_Loop_Engine.RepairRoutineLoop(__instance));
			}
		}
	}
}
[HarmonyPatch(typeof(InventoryGui), "Hide")]
internal static class AutoRepair_Close_Patch
{
	[HarmonyPostfix]
	private static void Postfix()
	{
		AutoRepairFixPlugin.StopActiveRepair();
	}
}
public static class AutoRepair_Loop_Engine
{
	public static IEnumerator RepairRoutineLoop(InventoryGui gui)
	{
		if ((Object)(object)gui == (Object)null || AutoRepairFixPlugin.onRepairPressedMethodToken == null)
		{
			yield break;
		}
		yield return null;
		while ((Object)(object)gui.m_repairButtonGlow != (Object)null && ((Component)((Component)gui.m_repairButtonGlow).transform).gameObject.activeSelf)
		{
			AutoRepairFixPlugin.onRepairPressedMethodToken.Invoke(gui, null);
			yield return AutoRepairFixPlugin.waitForPacingInterval;
			if ((Object)(object)gui == (Object)null || (Object)(object)gui.m_repairButtonGlow == (Object)null)
			{
				yield break;
			}
		}
		AutoRepairFixPlugin.repairRoutine = null;
	}
}

plugins/Build_Camera/Build Camera.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("Atze's Build Camera")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Atze Tools")]
[assembly: AssemblyProduct("Atze's Build Camera")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e3302621-009c-4bfc-872c-e1107b202d3d")]
[assembly: AssemblyFileVersion("2.4.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("2.4.0.0")]
namespace Valheim_Build_Camera;

[HarmonyPatch]
public class cam
{
	[HarmonyPatch(typeof(GameCamera), "UpdateCamera")]
	[HarmonyPrefix]
	public static void updateCamera(ref GameCamera __instance, ref bool __runOriginal)
	{
		if (gosub.isInBuildMode())
		{
			gosub.updateBuildCamera(Time.unscaledDeltaTime, ref __instance);
			__runOriginal = false;
		}
		else
		{
			__runOriginal = true;
		}
	}
}
[HarmonyPatch]
public class drop
{
	[HarmonyPatch(typeof(Piece), "DropResources")]
	[HarmonyPrefix]
	public static void dropToPlayer(ref Piece __instance)
	{
		//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_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: 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_0075: Unknown result type (might be due to invalid IL or missing references)
		if (gosub.isInBuildMode() && (Object)(object)Player.m_localPlayer != (Object)null && load.getCfg.boolResourceToPlayer)
		{
			Vector3 position = ((Component)Player.m_localPlayer).transform.position;
			float num = 0.2f;
			Vector3 position2 = default(Vector3);
			((Vector3)(ref position2))..ctor(position.x + Random.Range(0f - num, num), position.y + 0.1f, position.z + Random.Range(0f - num, num));
			((Component)__instance).transform.position = position2;
		}
	}
}
public class gosub
{
	private struct BuildCameraView
	{
		public float x;

		public float y;
	}

	public struct nearbyCraftingStation
	{
		public Vector3 position;

		public float distance;

		public float rangeBuild;
	}

	public static bool isBuildMode = false;

	private static GameObject gadgetBuildCamera;

	private static BuildCameraView viewCam = new BuildCameraView
	{
		x = 0f,
		y = 0f
	};

	public static bool isInBuildMode()
	{
		return Object.op_Implicit((Object)(object)Player.m_localPlayer) && isBuildMode;
	}

	public static void disableBuildMode(bool showInfo)
	{
		isBuildMode = false;
		GameCamera gc = GameCamera.instance;
		if ((Object)(object)GameCamera.instance != (Object)null)
		{
			setBuildGadget(ref gc);
		}
		if (showInfo && (Object)(object)Player.m_localPlayer != (Object)null)
		{
			ui.stateMessage.disableBuildCam();
		}
	}

	public static void enableBuildMode()
	{
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		isBuildMode = true;
		GameCamera gc = GameCamera.instance;
		if ((Object)(object)GameCamera.instance != (Object)null)
		{
			setBuildGadget(ref gc);
		}
		if ((Object)(object)Player.m_localPlayer != (Object)null && (Object)(object)((Character)Player.m_localPlayer).m_eye != (Object)null)
		{
			Quaternion rotation = ((Component)((Character)Player.m_localPlayer).m_eye).transform.rotation;
			float x = ((((Quaternion)(ref rotation)).eulerAngles.x > 180f) ? (-360f) : ((Quaternion)(ref rotation)).eulerAngles.x);
			viewCam.x = x;
			viewCam.y = ((Quaternion)(ref rotation)).eulerAngles.y;
		}
		if ((Object)(object)Player.m_localPlayer != (Object)null)
		{
			ui.stateMessage.enableBuildCam();
		}
	}

	public static bool isLocalPlayer(in Player player)
	{
		return Object.op_Implicit((Object)(object)Player.m_localPlayer) && (Object)(object)player == (Object)(object)Player.m_localPlayer;
	}

	private static bool isTool(in ItemData itemData)
	{
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Invalid comparison between Unknown and I4
		int result;
		if (tools.toolSet.Contains(itemData?.m_shared.m_name))
		{
			ItemData obj = itemData;
			result = ((obj != null && (int)obj.m_shared.m_itemType == 19) ? 1 : 0);
		}
		else
		{
			result = 0;
		}
		return (byte)result != 0;
	}

	public static bool isToolEquipped(in Player player)
	{
		FieldInfo field = typeof(Player).GetField("m_rightItem", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy);
		object? value = field.GetValue(player);
		return isTool((ItemData)((value is ItemData) ? value : null));
	}

	public static bool noToolEquipped(in Player player)
	{
		return !isToolEquipped(in player);
	}

	private static nearbyCraftingStation? getNearestBuildStation(in Vector3 playerOrCamera)
	{
		//IL_0079: 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_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0092: Unknown result type (might be due to invalid IL or missing references)
		FieldInfo field = typeof(CraftingStation).GetField("m_allStations", BindingFlags.Static | BindingFlags.NonPublic);
		if (!(field.GetValue(null) is List<CraftingStation> { Count: not 0 } list))
		{
			return null;
		}
		List<nearbyCraftingStation> list2 = new List<nearbyCraftingStation>();
		foreach (CraftingStation item in list)
		{
			list2.Add(new nearbyCraftingStation
			{
				position = ((Component)item).transform.position,
				distance = Vector3.Distance(((Component)item).transform.position, playerOrCamera),
				rangeBuild = item.m_rangeBuild
			});
		}
		return list2.OrderBy((nearbyCraftingStation x) => x.distance).First();
	}

	public static bool isBuildStationInRange(in Player player)
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		nearbyCraftingStation? nearestBuildStation = getNearestBuildStation(((Component)player).transform.position);
		if (nearestBuildStation.HasValue)
		{
			nearbyCraftingStation valueOrDefault = nearestBuildStation.GetValueOrDefault();
			if (true)
			{
				return valueOrDefault.distance <= valueOrDefault.rangeBuild;
			}
		}
		return false;
	}

	private static void stayNearWorkbench(ref GameCamera __instance)
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: 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_007a: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: 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_008a: 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_0094: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a9: 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)
		nearbyCraftingStation? nearestBuildStation = getNearestBuildStation(((Component)__instance).transform.position);
		if (nearestBuildStation.HasValue)
		{
			nearbyCraftingStation valueOrDefault = nearestBuildStation.GetValueOrDefault();
			if (true)
			{
				if (valueOrDefault.distance > valueOrDefault.rangeBuild * load.getCfg.floatCamRangeMultier)
				{
					float num = valueOrDefault.distance - valueOrDefault.rangeBuild * load.getCfg.floatCamRangeMultier;
					Vector3 val = valueOrDefault.position - ((Component)__instance).transform.position;
					Vector3 val2 = num * ((Vector3)(ref val)).normalized;
					((Component)__instance).transform.position = ((Component)__instance).transform.position + val2;
				}
				return;
			}
		}
		disableBuildMode(showInfo: true);
	}

	private static void stayNearGround(ref GameCamera __instance)
	{
		//IL_000d: 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_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		float num = default(float);
		if (ZoneSystem.instance.GetGroundHeight(((Component)__instance).transform.position, ref num) && ((Component)__instance).transform.position.y < num - load.getCfg.floatMaxGroundDive)
		{
			Vector3 position = ((Component)__instance).transform.position;
			position.y = num - load.getCfg.floatMaxGroundDive;
			((Component)__instance).transform.position = position;
		}
	}

	private static Quaternion updateBuildCameraViewDirection(float dt)
	{
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_017a: 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_0198: Unknown result type (might be due to invalid IL or missing references)
		//IL_019d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0093: Unknown result type (might be due to invalid IL or missing references)
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a1: 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)
		if (ZInput.IsMouseActive())
		{
			float num = PlatformPrefs.GetFloat("MouseSensitivity", PlayerController.m_mouseSens);
			bool flag = PlatformPrefs.GetInt("InvertMouse", 0) == 1;
			Vector2 mouseDelta = ZInput.GetMouseDelta();
			viewCam.y += num * mouseDelta.x;
			float num2 = ((!flag) ? 1 : (-1));
			float num3 = viewCam.x - num2 * (num * mouseDelta.y);
			viewCam.x = Mathf.Clamp(num3, -89f, 89f);
		}
		if (ZInput.IsGamepadActive())
		{
			PlayerController.cameraDirectionLock = Vector2.zero;
			float num4 = PlatformPrefs.GetFloat("GamepadSensitivity", PlayerController.m_gamepadSens);
			bool flag2 = PlatformPrefs.GetInt("InvertMouse", 0) == 1;
			bool flag3 = PlatformPrefs.GetInt("InvertCameraX", 0) == 1;
			bool flag4 = PlatformPrefs.GetInt("InvertCameraY", flag2 ? 1 : 0) == 1;
			float num5 = (flag3 ? (-1f) : 1f);
			float num6 = (flag4 ? 1f : (-1f));
			viewCam.y += ZInput.GetJoyRightStickX() * 110f * dt * num4 * num5;
			float num7 = viewCam.x - ZInput.GetJoyRightStickY() * 110f * dt * num4 * num6;
			viewCam.x = Mathf.Clamp(num7, -89f, 89f);
		}
		return Quaternion.Euler(0f, viewCam.y, 0f) * Quaternion.Euler(viewCam.x, 0f, 0f);
	}

	private static Vector3 untransformedMovementVector(float dt)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0021: 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_0027: 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_003d: 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_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: 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_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: 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_006f: 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_0095: 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_009c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a8: 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_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_0086: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: 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_00d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00da: Unknown result type (might be due to invalid IL or missing references)
		//IL_00df: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ff: 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_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_0137: 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_014c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0150: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = Vector3.zero;
		Vector3 forward = ((Component)GameCamera.instance).transform.forward;
		Vector3 right = ((Component)GameCamera.instance).transform.right;
		Vector3 up = Vector3.up;
		if (ZInput.GetButton("Left"))
		{
			val -= right;
		}
		if (ZInput.GetButton("Right"))
		{
			val += right;
		}
		if (ZInput.GetButton("Forward"))
		{
			val += forward;
		}
		if (ZInput.GetButton("Backward"))
		{
			val -= forward;
		}
		((Vector3)(ref val)).Normalize();
		val += right * ZInput.GetJoyLeftStickX();
		val -= forward * ZInput.GetJoyLeftStickY();
		if (ZInput.GetButton("Jump") || ZInput.GetButton("JoyJump"))
		{
			val += up;
		}
		if (ZInput.GetButton("Crouch") || ZInput.GetButton("JoyCrouch"))
		{
			val -= up;
		}
		float num = ((ZInput.GetButton("Run") || ZInput.GetButton("JoyRun")) ? ((Character)Player.m_localPlayer).m_runSpeed : ((Character)Player.m_localPlayer).m_walkSpeed);
		return val * (dt * num * load.getCfg.floatCamSpeedMultiplier);
	}

	public static void updateBuildCamera(float dt, ref GameCamera __instance)
	{
		//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_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: 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)
		if (!ui.windowConfigs.isOpen && !Game.IsPaused() && !Menu.IsActive() && !Menu.IsVisible() && !Console.IsVisible() && !Hud.IsPieceSelectionVisible())
		{
			Vector3 val = untransformedMovementVector(dt);
			Transform transform = ((Component)__instance).transform;
			transform.position += val;
			stayNearWorkbench(ref __instance);
			stayNearGround(ref __instance);
			((Component)__instance).transform.rotation = updateBuildCameraViewDirection(dt);
		}
	}

	public static bool playerIsBlocked(Player p)
	{
		return ((Character)p).IsTeleporting() || p.IsSleeping() || ((Character)p).IsDead() || ((Character)p).InCutscene();
	}

	private static void setBuildGadget(ref GameCamera gc)
	{
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Expected O, but got Unknown
		//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dc: Expected O, but got Unknown
		//IL_010a: Unknown result type (might be due to invalid IL or missing references)
		if (isBuildMode && (load.getCfg.boolBuildLight || load.getCfg.boolBuildDemist))
		{
			if ((Object)(object)gadgetBuildCamera == (Object)null)
			{
				gadgetBuildCamera = new GameObject("BuildCamGadget");
				gadgetBuildCamera.transform.SetParent(((Component)gc).transform, false);
				if (load.getCfg.boolBuildLight)
				{
					Light val = gadgetBuildCamera.AddComponent<Light>();
					val.type = (LightType)0;
					val.spotAngle = load.getCfg.floatBuildLightFOV;
					val.intensity = load.getCfg.floatBuildLightIntensity;
					val.range = load.getCfg.floatBuildLightRange;
				}
				if (load.getCfg.boolBuildDemist)
				{
					GameObject val2 = new GameObject("BuildCamDemist");
					val2.transform.SetParent(gadgetBuildCamera.transform, false);
					val2.transform.localPosition = new Vector3(0f, 0f, 1.5f);
					ParticleSystemForceField val3 = val2.AddComponent<ParticleSystemForceField>();
					val3.shape = (ParticleSystemForceFieldShape)0;
					val3.startRange = Mathf.Clamp(load.getCfg.floatBuildDemistRange, 5f, 255f);
					val3.endRange = Mathf.Clamp(load.getCfg.floatBuildDemistRange, 5f, 255f) + 5f;
					val3.gravityFocus = 0.5f;
					Demister val4 = val2.AddComponent<Demister>();
					val4.m_disableForcefieldDelay = 0f;
				}
			}
		}
		else if ((Object)(object)gadgetBuildCamera != (Object)null)
		{
			Object.Destroy((Object)(object)gadgetBuildCamera);
			gadgetBuildCamera = null;
		}
	}
}
[HarmonyPatch]
public class menu
{
	[HarmonyPatch(typeof(Menu), "IsVisible")]
	[HarmonyPrefix]
	public static bool isVisible(ref bool __result, ref bool __runOriginal)
	{
		if (ui.windowConfigs.isOpen)
		{
			__result = true;
			__runOriginal = false;
			return false;
		}
		return true;
	}

	[HarmonyPatch(typeof(Menu), "IsActive")]
	[HarmonyPrefix]
	public static bool isActive(ref bool __result, ref bool __runOriginal)
	{
		if (ui.windowConfigs.isOpen)
		{
			__result = true;
			__runOriginal = false;
			return false;
		}
		return true;
	}
}
public class pad
{
	public class stateController
	{
		public static bool switchByController => (ZInput.GetButtonDown("JoyLBumper") && ZInput.GetButton("JoyLTrigger")) || (ZInput.GetButtonDown("JoyLTrigger") && ZInput.GetButton("JoyLBumper"));

		public static string txtButton => ((int)ZInput.CurrentGlyph == 2) ? "L1 + L2" : (((int)ZInput.CurrentGlyph == 3) ? "L + ZL" : (((int)ZInput.CurrentGlyph == 1) ? "LB + LT" : (((int)ZInput.ConnectedGamepadType == 5 || (int)ZInput.ConnectedGamepadType == 4) ? "L1 + L2" : (((int)ZInput.ConnectedGamepadType == 6) ? "L + ZL" : "LB + LT"))));
	}

	[HarmonyPatch]
	public class gameController
	{
		[HarmonyPatch(typeof(ZInput), "GetButtonDown")]
		[HarmonyPrefix]
		public static bool menuControllerHandle(string name, ref bool __result)
		{
			if (ui.windowConfigs.isOpen && name.StartsWith("Joy"))
			{
				__result = false;
				return false;
			}
			return true;
		}
	}
}
[HarmonyPatch]
public class player
{
	[HarmonyPrefix]
	[HarmonyPatch(typeof(Player), "UpdatePlacement")]
	public static void setRangePlayer(ref Player __instance)
	{
		__instance.m_maxPlaceDistance = load.getCfg.floatRangeBuildAvatar;
	}

	[HarmonyPatch(typeof(Player), "SetLocalPlayer")]
	[HarmonyPostfix]
	public static void initNotInBuildMode()
	{
		gosub.disableBuildMode(showInfo: false);
	}

	[HarmonyPatch(typeof(Player), "Update")]
	[HarmonyPrefix]
	public static void getPlayerItem(ref Player __instance, ref bool __runOriginal)
	{
		//IL_0225: Unknown result type (might be due to invalid IL or missing references)
		//IL_022c: Unknown result type (might be due to invalid IL or missing references)
		//IL_048e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0493: Unknown result type (might be due to invalid IL or missing references)
		//IL_04b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f7: Unknown result type (might be due to invalid IL or missing references)
		if (gosub.isLocalPlayer(in __instance) && gosub.isInBuildMode())
		{
			if (gosub.noToolEquipped(in __instance))
			{
				gosub.disableBuildMode(showInfo: true);
				__runOriginal = true;
				return;
			}
			__runOriginal = false;
			if (!Traverse.Create((object)__instance).Method("TakeInput", Array.Empty<object>()).GetValue<bool>())
			{
				return;
			}
			if (Input.GetKeyDown((KeyCode)49))
			{
				__instance.UseHotbarItem(1);
			}
			if (Input.GetKeyDown((KeyCode)50))
			{
				__instance.UseHotbarItem(2);
			}
			if (Input.GetKeyDown((KeyCode)51))
			{
				__instance.UseHotbarItem(3);
			}
			if (Input.GetKeyDown((KeyCode)52))
			{
				__instance.UseHotbarItem(4);
			}
			if (Input.GetKeyDown((KeyCode)53))
			{
				__instance.UseHotbarItem(5);
			}
			if (Input.GetKeyDown((KeyCode)54))
			{
				__instance.UseHotbarItem(6);
			}
			if (Input.GetKeyDown((KeyCode)55))
			{
				__instance.UseHotbarItem(7);
			}
			if (Input.GetKeyDown((KeyCode)56))
			{
				__instance.UseHotbarItem(8);
			}
			if (ZInput.GetButton("Hide") || ZInput.GetButton("JoyHide"))
			{
				MethodInfo methodInfo = AccessTools.Method(typeof(Player), "GetRightItem", (Type[])null, (Type[])null);
				MethodInfo methodInfo2 = AccessTools.Method(typeof(Player), "GetLeftItem", (Type[])null, (Type[])null);
				object? obj = methodInfo.Invoke(__instance, null);
				ItemData val = (ItemData)((obj is ItemData) ? obj : null);
				object? obj2 = methodInfo2.Invoke(__instance, null);
				ItemData val2 = (ItemData)((obj2 is ItemData) ? obj2 : null);
				if ((val != null || val2 != null) && !((Character)__instance).InAttack())
				{
					((Humanoid)__instance).HideHandItems(false, true);
				}
			}
			if (load.getCfg.boolCamInteractEnable && (Object)(object)GameCamera.instance != (Object)null)
			{
				Traverse<GameObject> val3 = Traverse.Create((object)__instance).Field<GameObject>("m_hovering");
				Traverse<Character> val4 = Traverse.Create((object)__instance).Field<Character>("m_hoveringCreature");
				int value = Traverse.Create((object)__instance).Field<int>("m_interactMask").Value;
				val3.Value = null;
				val4.Value = null;
				Transform transform = ((Component)GameCamera.instance).transform;
				RaycastHit val5 = default(RaycastHit);
				if (Physics.Raycast(transform.position, transform.forward, ref val5, 50f, value) && (!Object.op_Implicit((Object)(object)((RaycastHit)(ref val5)).collider.attachedRigidbody) || (Object)(object)((Component)((RaycastHit)(ref val5)).collider.attachedRigidbody).gameObject != (Object)(object)((Component)__instance).gameObject))
				{
					GameObject gameObject = ((Component)((RaycastHit)(ref val5)).collider).gameObject;
					if ((Object)(object)gameObject.GetComponentInParent<Pickable>() != (Object)null || (Object)(object)gameObject.GetComponentInParent<ItemDrop>() != (Object)null)
					{
						Hoverable componentInParent = gameObject.GetComponentInParent<Hoverable>();
						if (componentInParent != null)
						{
							float floatCamInteractDistance = load.getCfg.floatCamInteractDistance;
							float hoverOffset = componentInParent.GetHoverOffset();
							if (Vector3.Distance(transform.position, ((RaycastHit)(ref val5)).point) < floatCamInteractDistance + hoverOffset)
							{
								if (((Component)((RaycastHit)(ref val5)).collider).GetComponent<Hoverable>() != null)
								{
									val3.Value = ((Component)((RaycastHit)(ref val5)).collider).gameObject;
								}
								else if (Object.op_Implicit((Object)(object)((RaycastHit)(ref val5)).collider.attachedRigidbody))
								{
									val3.Value = ((Component)((RaycastHit)(ref val5)).collider.attachedRigidbody).gameObject;
								}
								else
								{
									val3.Value = ((Component)((RaycastHit)(ref val5)).collider).gameObject;
								}
							}
						}
					}
				}
			}
			if ((ZInput.GetButtonDown("Use") || ZInput.GetButtonDown("JoyUse")) && !Hud.InRadial() && load.getCfg.boolCamInteractEnable)
			{
				GameObject hoverObject = ((Humanoid)__instance).GetHoverObject();
				if ((Object)(object)hoverObject != (Object)null)
				{
					bool flag = ZInput.GetButton("AltPlace") || ZInput.GetButton("JoyAltPlace");
					Interactable componentInParent2 = hoverObject.GetComponentInParent<Interactable>();
					if (componentInParent2 != null && componentInParent2.Interact((Humanoid)(object)__instance, false, flag))
					{
						AccessTools.Method(typeof(Player), "DoInteractAnimation", (Type[])null, (Type[])null).Invoke(__instance, new object[1] { ((Component)((componentInParent2 is MonoBehaviour) ? componentInParent2 : null)).gameObject });
					}
				}
			}
			if (load.getCfg.boolCamAutoPickupEnable && (Object)(object)GameCamera.instance != (Object)null && !((Character)__instance).IsTeleporting())
			{
				Vector3 position = ((Component)GameCamera.instance).transform.position;
				float floatCamAutoPickupRadius = load.getCfg.floatCamAutoPickupRadius;
				int mask = LayerMask.GetMask(new string[1] { "item" });
				Collider[] array = Physics.OverlapSphere(position, floatCamAutoPickupRadius, mask);
				Collider[] array2 = array;
				foreach (Collider val6 in array2)
				{
					if (!Object.op_Implicit((Object)(object)val6.attachedRigidbody))
					{
						continue;
					}
					ItemDrop component = ((Component)val6.attachedRigidbody).GetComponent<ItemDrop>();
					if ((Object)(object)component == (Object)null || !component.m_autoPickup || component.IsPiece())
					{
						continue;
					}
					if (!component.CanPickup(true))
					{
						component.RequestOwn();
						continue;
					}
					component.Load();
					if (((Humanoid)__instance).GetInventory().CanAddItem(component.m_itemData, -1) && component.m_itemData.GetWeight(-1) + ((Humanoid)__instance).GetInventory().GetTotalWeight() <= __instance.GetMaxCarryWeight())
					{
						((Humanoid)__instance).Pickup(((Component)component).gameObject, true, true);
					}
				}
			}
			AccessTools.Method(typeof(Player), "UpdatePlacement", (Type[])null, (Type[])null).Invoke(__instance, new object[2]
			{
				true,
				Time.deltaTime
			});
		}
		else
		{
			__runOriginal = true;
		}
	}

	[HarmonyPatch(typeof(Player), "Update")]
	[HarmonyPostfix]
	public static void switchController(ref Player __instance)
	{
		//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
		if (!gosub.isLocalPlayer(in __instance))
		{
			return;
		}
		float value = Traverse.Create((object)__instance).Field<float>("m_hitWorldTime").Value;
		if (gosub.isInBuildMode() && value > 0f && !((Character)__instance).IsDebugFlying() && !((Character)__instance).IsFlying())
		{
			gosub.disableBuildMode(showInfo: true);
			ui.stateMessage.warnAttack();
		}
		if ((!((Object)(object)Menu.instance != (Object)null) || !((Component)Menu.instance.m_root).gameObject.activeSelf) && !gosub.playerIsBlocked(__instance) && (Input.GetKey((KeyCode)304) || Input.GetKey((KeyCode)303)) && Input.GetKeyDown((KeyCode)8))
		{
			ui.windowConfigs.toggleMenu();
			return;
		}
		ui.windowHint.hintBuildCamera.setBuildCamHint(gosub.isToolEquipped(in __instance), __instance);
		if (ui.windowConfigs.isOpen)
		{
			return;
		}
		KeyboardShortcut ksKeyBuildModeSwitch = load.getCfg.ksKeyBuildModeSwitch;
		if ((((KeyboardShortcut)(ref ksKeyBuildModeSwitch)).IsDown() || pad.stateController.switchByController) && Traverse.Create((object)__instance).Method("TakeInput", Array.Empty<object>()).GetValue<bool>())
		{
			if (!gosub.isInBuildMode() && gosub.isToolEquipped(in __instance) && gosub.isBuildStationInRange(in __instance))
			{
				gosub.enableBuildMode();
			}
			else if (gosub.isInBuildMode())
			{
				gosub.disableBuildMode(showInfo: true);
			}
		}
	}

	[HarmonyPatch(typeof(PlayerController), "TakeInput")]
	[HarmonyPrefix]
	public static bool inputPlayerController(ref bool __result, ref bool __runOriginal)
	{
		if (ui.windowConfigs.isOpen)
		{
			__result = false;
			__runOriginal = false;
			return false;
		}
		if (gosub.isInBuildMode())
		{
			__result = false;
			__runOriginal = false;
			return false;
		}
		__runOriginal = true;
		return true;
	}
}
[BepInPlugin("AtzesBuildCamMod", "Atze's Build Camera", "2.4")]
[BepInProcess("valheim.exe")]
[HarmonyPatch]
public class Atzes_Build_Camera : BaseUnityPlugin
{
	private void Awake()
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Expected O, but got Unknown
		values.getValues();
		((Component)this).gameObject.AddComponent<ui.windowConfigs>();
		Harmony val = new Harmony("AtzesBuildCamMod");
		val.PatchAll(Assembly.GetExecutingAssembly());
	}
}
public class config
{
	public float floatRangeBuildAvatar { get; set; }

	public float floatRangeBuildWorkbench { get; set; }

	public float floatCamRangeMultier { get; set; }

	public float floatCamSpeedMultiplier { get; set; }

	public float floatMaxGroundDive { get; set; }

	public KeyboardShortcut ksKeyBuildModeSwitch { get; set; }

	public KeyboardShortcut ksKeyBuildModeSettings { get; set; }

	public bool boolBuildLight { get; set; }

	public bool boolBuildDemist { get; set; }

	public float floatBuildLightIntensity { get; set; }

	public float floatBuildLightRange { get; set; }

	public float floatBuildLightFOV { get; set; }

	public float floatBuildDemistRange { get; set; }

	public bool boolResourceToPlayer { get; set; }

	public bool boolCamInteractEnable { get; set; }

	public bool boolCamAutoPickupEnable { get; set; }

	public float floatCamAutoPickupRadius { get; set; }

	public float floatCamInteractDistance { get; set; }

	public config(float _floatRangeBuildAvatar, float _floatRangeBuildWorkbench, float _floatCamRangeMultier, float _floatCamSpeedMultiplier, float _floatMaxGroundDive, KeyboardShortcut _ksKeyBuildModeSwitch, KeyboardShortcut _ksKeyBuildModeSettings, bool _boolBuildLight, bool _boolBuildDemist, float _floatBuildLightIntensity, float _floatBuildLightRange, float _floatBuildLightFOV, float _floatBuildDemistRange, bool _boolResourceToPlayer, bool _boolCamInteractEnable, bool _boolCamAutoPickupEnable, float _floatCamAutoPickupRadius, float _floatCamInteractDistance)
	{
		//IL_0033: 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)
		floatRangeBuildAvatar = _floatRangeBuildAvatar;
		floatRangeBuildWorkbench = _floatRangeBuildWorkbench;
		floatCamRangeMultier = _floatCamRangeMultier;
		floatCamSpeedMultiplier = _floatCamSpeedMultiplier;
		floatMaxGroundDive = _floatMaxGroundDive;
		ksKeyBuildModeSwitch = _ksKeyBuildModeSwitch;
		ksKeyBuildModeSettings = _ksKeyBuildModeSettings;
		boolBuildLight = _boolBuildLight;
		boolBuildDemist = _boolBuildDemist;
		floatBuildLightIntensity = _floatBuildLightIntensity;
		floatBuildLightRange = _floatBuildLightRange;
		floatBuildLightFOV = _floatBuildLightFOV;
		floatBuildDemistRange = _floatBuildDemistRange;
		boolResourceToPlayer = _boolResourceToPlayer;
		boolCamInteractEnable = _boolCamInteractEnable;
		boolCamAutoPickupEnable = _boolCamAutoPickupEnable;
		floatCamAutoPickupRadius = _floatCamAutoPickupRadius;
		floatCamInteractDistance = _floatCamInteractDistance;
	}
}
public static class load
{
	public static config getCfg = kernal.sys64738._(getCfg);

	public static uitext txtUI = kernal.sys64738._(txtUI);

	public static ConfigFile configFile = new ConfigFile(Path.Combine(Paths.ConfigPath, "Atze's Build Camera.cfg"), true);

	public static ConfigEntry<float> distanceCanBuildFromAvatar = configFile.Bind<float>(kernal.sys52.sectionGeneral, kernal.sys53.keyCharBuildRange, getCfg.floatRangeBuildAvatar, new ConfigDescription(kernal.sys54.strCharBuildRange, (AcceptableValueBase)(object)new AcceptableValueRange<float>(kernal.sys47.min.RangeBuildChar, kernal.sys47.max.RangeBuildChar), Array.Empty<object>()));

	public static ConfigEntry<float> distanceCanBuildFromWorkbench = configFile.Bind<float>(kernal.sys52.sectionGeneral, kernal.sys53.keyBenchBuildRange, getCfg.floatRangeBuildWorkbench, new ConfigDescription(kernal.sys54.strBenchBuildRange, (AcceptableValueBase)(object)new AcceptableValueRange<float>(kernal.sys47.min.RangeBuildBench, kernal.sys47.max.RangeBuildBench), Array.Empty<object>()));

	public static ConfigEntry<bool> recourceToPlayer = configFile.Bind<bool>(kernal.sys52.sectionGeneral, kernal.sys53.keyResourceToPlayer, getCfg.boolResourceToPlayer, kernal.sys54.strResourceToPlayer);

	public static ConfigEntry<float> cameraMaxGroundDive = configFile.Bind<float>(kernal.sys52.sectionCamera, kernal.sys53.keyGroundDive, getCfg.floatMaxGroundDive, new ConfigDescription(kernal.sys54.strGroundDive, (AcceptableValueBase)(object)new AcceptableValueRange<float>(kernal.sys47.min.RangeDive, kernal.sys47.max.RangeDive), Array.Empty<object>()));

	public static ConfigEntry<float> cameraRangeMultiplier = configFile.Bind<float>(kernal.sys52.sectionCamera, kernal.sys53.keyCamRangeMulti, getCfg.floatCamRangeMultier, new ConfigDescription(kernal.sys54.strCamRangeMulti, (AcceptableValueBase)(object)new AcceptableValueRange<float>(kernal.sys47.min.RangeCamMulti, kernal.sys47.max.RangeCamMulti), Array.Empty<object>()));

	public static ConfigEntry<float> cameraMoveSpeedMultiplier = configFile.Bind<float>(kernal.sys52.sectionCamera, kernal.sys53.keyCamSpeedMulti, getCfg.floatCamSpeedMultiplier, new ConfigDescription(kernal.sys54.strCamSpeedMulti, (AcceptableValueBase)(object)new AcceptableValueRange<float>(kernal.sys47.min.IntensityLight, kernal.sys47.max.IntensityLight), Array.Empty<object>()));

	public static ConfigEntry<KeyboardShortcut> keyBuildMode = configFile.Bind<KeyboardShortcut>(kernal.sys52.sectionHotkeys, kernal.sys53.keySwitchBuildCam, getCfg.ksKeyBuildModeSwitch, kernal.sys54.strSwitchBuildCam);

	public static ConfigEntry<KeyboardShortcut> keyBuildModeSet = configFile.Bind<KeyboardShortcut>(kernal.sys52.sectionHotkeys, kernal.sys53.keySwitchCamSet, getCfg.ksKeyBuildModeSettings, kernal.sys54.strSwitchCamSet);

	public static ConfigEntry<string> txtuiBuildModeOff = configFile.Bind<string>(kernal.sys52.sectionTextUI, kernal.sys53.keyTextCamOff, txtUI.txtIsDisabled, kernal.sys54.strTextCamOff);

	public static ConfigEntry<string> txtuiBuildModeOn = configFile.Bind<string>(kernal.sys52.sectionTextUI, kernal.sys53.keyTextCamOn, txtUI.txtIsEnabled, kernal.sys54.strTextCamOn);

	public static ConfigEntry<string> txtuiWarnDangerNearby = configFile.Bind<string>(kernal.sys52.sectionTextUI, kernal.sys53.keyTextDanger, txtUI.txtWarnDangerNearby, kernal.sys54.strTextDanger);

	public static ConfigEntry<string> txtuiWarnBeingAttacked = configFile.Bind<string>(kernal.sys52.sectionTextUI, kernal.sys53.keyTextAttacked, txtUI.txtWarnBeingAttacked, kernal.sys54.strTextAttacked);

	public static ConfigEntry<string> txtuiWarnOutOfRange = configFile.Bind<string>(kernal.sys52.sectionTextUI, kernal.sys53.keyTextNoBench, txtUI.txtWarnOutOfRange, kernal.sys54.strTextNoBench);

	public static ConfigEntry<bool> wantBuildLight = configFile.Bind<bool>(kernal.sys52.sectionBuildLight, kernal.sys53.keySwitchBuildLight, getCfg.boolBuildLight, kernal.sys54.strSwitchBuildLight);

	public static ConfigEntry<float> fovBuildLight = configFile.Bind<float>(kernal.sys52.sectionBuildLight, kernal.sys53.keyFOVBuildLight, getCfg.floatBuildLightFOV, new ConfigDescription(kernal.sys54.strFOVBuildLight, (AcceptableValueBase)(object)new AcceptableValueRange<float>(kernal.sys47.min.FOVLight, kernal.sys47.max.FOVLight), Array.Empty<object>()));

	public static ConfigEntry<float> rangeBuildLight = configFile.Bind<float>(kernal.sys52.sectionBuildLight, kernal.sys53.keyRangeBuildLight, getCfg.floatBuildLightRange, new ConfigDescription(kernal.sys54.strRangeBuildLight, (AcceptableValueBase)(object)new AcceptableValueRange<float>(kernal.sys47.min.RangeLight, kernal.sys47.max.RangeLight), Array.Empty<object>()));

	public static ConfigEntry<float> intesityBuildLight = configFile.Bind<float>(kernal.sys52.sectionBuildLight, kernal.sys53.keyIntensityBuildLight, getCfg.floatBuildLightIntensity, new ConfigDescription(kernal.sys54.strIntensityBuildLight, (AcceptableValueBase)(object)new AcceptableValueRange<float>(kernal.sys47.min.IntensityLight, kernal.sys47.max.IntensityLight), Array.Empty<object>()));

	public static ConfigEntry<bool> wantBuildDemist = configFile.Bind<bool>(kernal.sys52.sectionBuildDemist, kernal.sys53.keySwitchDemist, getCfg.boolBuildDemist, kernal.sys54.strSwitchDemist);

	public static ConfigEntry<float> rangeBuildDemist = configFile.Bind<float>(kernal.sys52.sectionBuildDemist, kernal.sys53.keyRangeDemist, getCfg.floatBuildDemistRange, new ConfigDescription(kernal.sys54.strRangeDemist, (AcceptableValueBase)(object)new AcceptableValueRange<float>(kernal.sys47.min.RangeDemist, kernal.sys47.max.RangeDemist), Array.Empty<object>()));

	public static ConfigEntry<bool> isPickable = configFile.Bind<bool>(kernal.sys52.sectionPickUp, kernal.sys53.keySwitchInteract, getCfg.boolCamInteractEnable, kernal.sys54.strSwitchInteract);

	public static ConfigEntry<bool> isAutoPick = configFile.Bind<bool>(kernal.sys52.sectionPickUp, kernal.sys53.keySwitchAutoPickUp, getCfg.boolCamAutoPickupEnable, kernal.sys54.strSwitchAutoPickUp);

	public static ConfigEntry<float> rangeAutoPick = configFile.Bind<float>(kernal.sys52.sectionPickUp, kernal.sys53.keyRangeAutoPickUp, getCfg.floatCamAutoPickupRadius, new ConfigDescription(kernal.sys54.strRangeAutoPickUp, (AcceptableValueBase)(object)new AcceptableValueRange<float>(kernal.sys47.min.RangeAutoPick, kernal.sys47.max.RangeAutoPick), Array.Empty<object>()));

	public static ConfigEntry<float> rangeInteract = configFile.Bind<float>(kernal.sys52.sectionPickUp, kernal.sys53.keyRangeInteract, getCfg.floatCamInteractDistance, new ConfigDescription(kernal.sys54.strRangeInteract, (AcceptableValueBase)(object)new AcceptableValueRange<float>(kernal.sys47.min.RangeInteract, kernal.sys47.max.RangeInteract), Array.Empty<object>()));
}
internal class values
{
	public static void getValues()
	{
		//IL_0074: 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)
		load.getCfg.floatRangeBuildAvatar = load.distanceCanBuildFromAvatar.Value;
		load.getCfg.floatRangeBuildWorkbench = load.distanceCanBuildFromWorkbench.Value;
		load.getCfg.floatCamSpeedMultiplier = load.cameraMoveSpeedMultiplier.Value;
		load.getCfg.floatCamRangeMultier = load.cameraRangeMultiplier.Value;
		load.getCfg.floatMaxGroundDive = load.cameraMaxGroundDive.Value;
		load.getCfg.ksKeyBuildModeSwitch = load.keyBuildMode.Value;
		load.getCfg.ksKeyBuildModeSettings = load.keyBuildModeSet.Value;
		load.getCfg.boolBuildLight = load.wantBuildLight.Value;
		load.getCfg.boolBuildDemist = load.wantBuildDemist.Value;
		load.getCfg.floatBuildLightIntensity = load.intesityBuildLight.Value;
		load.getCfg.floatBuildLightRange = load.rangeBuildLight.Value;
		load.getCfg.floatBuildLightFOV = load.fovBuildLight.Value;
		load.getCfg.floatBuildDemistRange = load.rangeBuildDemist.Value;
		load.getCfg.boolResourceToPlayer = load.recourceToPlayer.Value;
		load.txtUI.txtIsEnabled = load.txtuiBuildModeOn.Value;
		load.txtUI.txtIsDisabled = load.txtuiBuildModeOff.Value;
		load.txtUI.txtWarnBeingAttacked = load.txtuiWarnBeingAttacked.Value;
		load.txtUI.txtWarnDangerNearby = load.txtuiWarnDangerNearby.Value;
		load.txtUI.txtWarnOutOfRange = load.txtuiWarnOutOfRange.Value;
		load.getCfg.boolCamInteractEnable = load.isPickable.Value;
		load.getCfg.boolCamAutoPickupEnable = load.isAutoPick.Value;
		load.getCfg.floatCamAutoPickupRadius = load.rangeAutoPick.Value;
		load.getCfg.floatCamInteractDistance = load.rangeInteract.Value;
	}

	public static void setValue()
	{
		load.distanceCanBuildFromAvatar.Value = load.getCfg.floatRangeBuildAvatar;
		load.distanceCanBuildFromWorkbench.Value = load.getCfg.floatRangeBuildWorkbench;
		load.cameraMoveSpeedMultiplier.Value = load.getCfg.floatCamSpeedMultiplier;
		load.cameraRangeMultiplier.Value = load.getCfg.floatCamRangeMultier;
		load.cameraMaxGroundDive.Value = load.getCfg.floatMaxGroundDive;
		load.wantBuildLight.Value = load.getCfg.boolBuildLight;
		load.wantBuildDemist.Value = load.getCfg.boolBuildDemist;
		load.intesityBuildLight.Value = load.getCfg.floatBuildLightIntensity;
		load.rangeBuildLight.Value = load.getCfg.floatBuildLightRange;
		load.fovBuildLight.Value = load.getCfg.floatBuildLightFOV;
		load.rangeBuildDemist.Value = load.getCfg.floatBuildDemistRange;
		load.recourceToPlayer.Value = load.getCfg.boolResourceToPlayer;
		load.txtuiBuildModeOn.Value = load.txtUI.txtIsEnabled;
		load.txtuiBuildModeOff.Value = load.txtUI.txtIsDisabled;
		load.txtuiWarnDangerNearby.Value = load.txtUI.txtWarnDangerNearby;
		load.txtuiWarnBeingAttacked.Value = load.txtUI.txtWarnBeingAttacked;
		load.txtuiWarnOutOfRange.Value = load.txtUI.txtWarnOutOfRange;
		load.isPickable.Value = load.getCfg.boolCamInteractEnable;
		load.isAutoPick.Value = load.getCfg.boolCamAutoPickupEnable;
		load.rangeAutoPick.Value = load.getCfg.floatCamAutoPickupRadius;
		load.rangeInteract.Value = load.getCfg.floatCamInteractDistance;
	}

	public static void resetValues()
	{
		load.getCfg.floatRangeBuildAvatar = kernal.sys49.rangeBuildAvatar;
		load.getCfg.floatRangeBuildWorkbench = kernal.sys49.rangeBuildWorkbench;
		load.getCfg.boolResourceToPlayer = kernal.sys49.resourceToPlayer;
		load.getCfg.floatMaxGroundDive = kernal.sys49.maxGroundDive;
		load.getCfg.floatCamRangeMultier = kernal.sys49.camRangeMultier;
		load.getCfg.floatCamSpeedMultiplier = kernal.sys49.camSpeedMultiplier;
		load.getCfg.boolBuildLight = kernal.sys49.buildLight;
		load.getCfg.floatBuildLightFOV = kernal.sys49.buildLightFOV;
		load.getCfg.floatBuildLightRange = kernal.sys49.buildLightRange;
		load.getCfg.floatBuildLightIntensity = kernal.sys49.buildLightIntensity;
		load.getCfg.boolBuildDemist = kernal.sys49.buildDemist;
		load.getCfg.floatBuildDemistRange = kernal.sys49.buildDemistRange;
		load.txtUI.txtIsEnabled = kernal.sys51.isEnabled;
		load.txtUI.txtIsDisabled = kernal.sys51.isDisabled;
		load.txtUI.txtWarnDangerNearby = kernal.sys51.warnDangerNearby;
		load.txtUI.txtWarnBeingAttacked = kernal.sys51.warnBeingAttacked;
		load.txtUI.txtWarnOutOfRange = kernal.sys51.warnOutOfRange;
		load.getCfg.boolCamInteractEnable = kernal.sys49.camInteractEnable;
		load.getCfg.boolCamAutoPickupEnable = kernal.sys49.camAutoPickupEnable;
		load.getCfg.floatCamAutoPickupRadius = kernal.sys49.camAutoPickupRadius;
		load.getCfg.floatCamInteractDistance = kernal.sys49.camInteractDistance;
	}
}
public class kernal
{
	public class sys17
	{
		public static readonly string lblHeader = "[ Atze's Build-Camera Settings ]";

		public static readonly string lblGeneral = "[ General ]";

		public static readonly string lblRangeChar = "Avatar Build Range:";

		public static readonly string lblRangeBench = "Station Build Range:";

		public static readonly string lblCamControl = "[ Camera Controls ]";

		public static readonly string lblCamDive = "Camera Ground Level:";

		public static readonly string lblCamRangeMulti = "Camera Range Multiplier:";

		public static readonly string lblCamSpeedMulti = "Camera Speed Multiplier:";

		public static readonly string lblCamLight = "[ Camera Build-Light ]";

		public static readonly string lblFOVLight = "Light Scattering Angle (FOV):";

		public static readonly string lblDistLight = "Light Distance/Range:";

		public static readonly string lblIntenseLight = "Light Brightness/Intensity:";

		public static readonly string lblDemist = "[ Demister / Fog Clearer ]";

		public static readonly string lblRangeDemist = "De-Misting Range:";

		public static readonly string lblPickUp = "[ Camera Interaction & Auto-Pickup ]";

		public static readonly string lblDistPickUp = "PickUp Distance:";

		public static readonly string lblRadiusAutoPick = "Auto-Pickup Radius:";

		public static readonly string lblTextSet = "[ Text UI Settings ]";

		public static readonly string lblAttacked = "Attacked:";

		public static readonly string lblDanger = "Danger:";

		public static readonly string lblBenchRange = "Range:";

		public static readonly string lblCamOn = "Cam On:";

		public static readonly string lblCamOff = "Cam Off:";

		public static readonly string cbxResToPlayer = "Drop Resources To Player";

		public static readonly string cbxBuildLight = "Enable Extra Light on Camera";

		public static readonly string cbxDemist = "Enable De-Misting (Clear Fog)";

		public static readonly string cbxInteract = "Enable Camera Interaction";

		public static readonly string cbxAutoPickUp = "Enable Camera Auto-Pickup";

		public static readonly string btnReset = "RESET";

		public static readonly string btnSave = "SAVE & CLOSE";
	}

	public class sys47
	{
		public class min
		{
			public static readonly float RangeInteract = 1f;

			public static readonly float RangeAutoPick = 1f;

			public static readonly float RangeDemist = 5f;

			public static readonly float FOVLight = 15f;

			public static readonly float RangeLight = 5f;

			public static readonly float IntensityLight = 0.1f;

			public static readonly float RangeBuildChar = 5f;

			public static readonly float RangeBuildBench = 5f;

			public static readonly float RangeDive = -5f;

			public static readonly float RangeCamMulti = 0.5f;

			public static readonly float SpeedCamMulti = 0.5f;
		}

		public class max
		{
			public static readonly float RangeInteract = 10f;

			public static readonly float RangeAutoPick = 25f;

			public static readonly float RangeDemist = 150f;

			public static readonly float FOVLight = 135f;

			public static readonly float RangeLight = 150f;

			public static readonly float IntensityLight = 5f;

			public static readonly float RangeBuildChar = 150f;

			public static readonly float RangeBuildBench = 150f;

			public static readonly float RangeDive = 2f;

			public static readonly float RangeCamMulti = 5f;

			public static readonly float SpeedCamMulti = 5f;
		}
	}

	public class sys49
	{
		public static readonly float rangeBuildAvatar = 100f;

		public static readonly float rangeBuildWorkbench = 100f;

		public static readonly float camRangeMultier = 1f;

		public static readonly float camSpeedMultiplier = 1.5f;

		public static readonly float maxGroundDive = 2f;

		public static readonly KeyboardShortcut keyBuildModeSwitch = new KeyboardShortcut((KeyCode)98, Array.Empty<KeyCode>());

		public static readonly KeyboardShortcut keyBuildModeSettings = new KeyboardShortcut((KeyCode)303, (KeyCode[])(object)new KeyCode[1] { (KeyCode)8 });

		public static readonly bool buildLight = true;

		public static readonly bool buildDemist = true;

		public static readonly float buildLightIntensity = 2f;

		public static readonly float buildLightRange = 40f;

		public static readonly float buildLightFOV = 90f;

		public static readonly float buildDemistRange = 100f;

		public static readonly bool resourceToPlayer = true;

		public static readonly bool camInteractEnable = true;

		public static readonly bool camAutoPickupEnable = true;

		public static readonly float camAutoPickupRadius = 10f;

		public static readonly float camInteractDistance = 5f;
	}

	public class sys51
	{
		public static readonly string isEnabled = "Build-Camera enabled";

		public static readonly string isDisabled = "Build-Camera disabled";

		public static readonly string warnDangerNearby = "Be careful, danger nearby!";

		public static readonly string warnBeingAttacked = "Build Mode off: Under Attack!";

		public static readonly string warnOutOfRange = "No workbench nearby";
	}

	public class sys52
	{
		public static readonly string sectionGeneral = "General";

		public static readonly string sectionCamera = "Camera";

		public static readonly string sectionHotkeys = "Hotkeys";

		public static readonly string sectionTextUI = "Text UI";

		public static readonly string sectionBuildLight = "BuildLight";

		public static readonly string sectionBuildDemist = "BuildDemist";

		public static readonly string sectionPickUp = "PickUp";
	}

	public class sys53
	{
		public static readonly string keyCharBuildRange = "Build_Range_Avatar";

		public static readonly string keyBenchBuildRange = "Build_Range_Workbench";

		public static readonly string keyResourceToPlayer = "Drop_Resources_Near_Player";

		public static readonly string keyGroundDive = "Camera_Ground_Dive_Limiter";

		public static readonly string keyCamRangeMulti = "Camera_Range_Multiplier";

		public static readonly string keyCamSpeedMulti = "Camera_Speed_Multiplier";

		public static readonly string keySwitchBuildCam = "Switch_Build_Camera";

		public static readonly string keySwitchCamSet = "Switch_Settings";

		public static readonly string keyTextCamOff = "Text_Build_Camera_Off";

		public static readonly string keyTextCamOn = "Text_Build_Camera_On";

		public static readonly string keyTextDanger = "Text_Warn_Danger_Nearby";

		public static readonly string keyTextAttacked = "Text_Warn_Being_Attacked";

		public static readonly string keyTextNoBench = "Text_Warn_Out_Of_Range";

		public static readonly string keySwitchBuildLight = "Switch_Build_Light";

		public static readonly string keyFOVBuildLight = "FOV_Build_Light";

		public static readonly string keyRangeBuildLight = "Distance_Build_Light";

		public static readonly string keyIntensityBuildLight = "Intensity_Build_Light";

		public static readonly string keySwitchDemist = "Switch_Build_Demist";

		public static readonly string keyRangeDemist = "Range_Build_Demist";

		public static readonly string keySwitchInteract = "Switch_Interactibility_PickUp";

		public static readonly string keyRangeInteract = "Switch_Auto_PickUp";

		public static readonly string keySwitchAutoPickUp = "Range_Auto_PickUp";

		public static readonly string keyRangeAutoPickUp = "Distance_To_PickUp";
	}

	public class sys54
	{
		public static readonly string strCharBuildRange = "Distance from your avatar that you can build or repair. (Valheim default is 8)";

		public static readonly string strBenchBuildRange = "Distance from nearest workbench/stonecutter/etc. that you can build or repair. (Valheim default is 20)";

		public static readonly string strResourceToPlayer = "Drops the resources near player from destroying build-items.";

		public static readonly string strGroundDive = "This allows to you dive into the ground by given value.";

		public static readonly string strCamRangeMulti = "Changes maximum range camera can move away from the build station. 1 means the build station's range, 2 means twice the build station range, etc.";

		public static readonly string strCamSpeedMulti = "Multiplies the speed at which the build camera pans (i.e. moves around WASD). Lower values make it slower.";

		public static readonly string strSwitchBuildCam = "Hotkey to toggle build camera. See also: https://docs.unity.com/en-us/engine/6000.6/script-reference/unityengine/keycode#fields";

		public static readonly string strSwitchCamSet = "Hotkey(s) to toggle build camera settings. See also: https://docs.unity.com/en-us/engine/6000.6/script-reference/unityengine/keycode#fields";

		public static readonly string strTextCamOff = "Info Text Build Camera Off";

		public static readonly string strTextCamOn = "Info Text Build Camera On";

		public static readonly string strTextDanger = "Info Text For Nearby Danger";

		public static readonly string strTextAttacked = "Info Text For Being Attacked";

		public static readonly string strTextNoBench = "Info Text For Workbench Range";

		public static readonly string strSwitchBuildLight = "Enabled gives an extra light attached to the camera.";

		public static readonly string strFOVBuildLight = "Sets the light-scattering angle";

		public static readonly string strRangeBuildLight = "Sets the distance of camera light.";

		public static readonly string strIntensityBuildLight = "Sets the brighness of camera light.";

		public static readonly string strSwitchDemist = "Enabled will de-mist a given range in Mistland";

		public static readonly string strRangeDemist = "Sets the range of de-misting";

		public static readonly string strSwitchInteract = "Sets the ability to pickup items while using build-camera";

		public static readonly string strRangeInteract = "Sets auto-pickup arround the camera to on/off";

		public static readonly string strSwitchAutoPickUp = "Range of auto-pickup arround the camera.";

		public static readonly string strRangeAutoPickUp = "Defines how far you can interact with items (pickup)";
	}

	public class sys58260
	{
		public const string appMID = "AtzesBuildCamMod";

		public const string appVER = "2.4";

		public const string appPLN = "Atze's Build Camera";

		public const string keyPage = "https://docs.unity.com/en-us/engine/6000.6/script-reference/unityengine/keycode#fields";

		public const string objHintText = "BuildCamHintText";

		public const string objHintFrame = "BuildCamHintFrame";

		public const string objGadget = "BuildCamGadget";

		public const string objDemist = "BuildCamDemist";
	}

	public static class sys64738
	{
		public static config _(config _)
		{
			//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)
			return _ = new config(sys49.rangeBuildAvatar, sys49.rangeBuildWorkbench, sys49.camRangeMultier, sys49.camSpeedMultiplier, sys49.maxGroundDive, sys49.keyBuildModeSwitch, sys49.keyBuildModeSettings, sys49.buildLight, sys49.buildDemist, sys49.buildLightIntensity, sys49.buildLightRange, sys49.buildLightFOV, sys49.buildDemistRange, sys49.resourceToPlayer, sys49.camInteractEnable, sys49.camAutoPickupEnable, sys49.camAutoPickupRadius, sys49.camInteractDistance);
		}

		public static uitext _(uitext _)
		{
			return _ = new uitext(sys51.isEnabled, sys51.isDisabled, sys51.warnDangerNearby, sys51.warnBeingAttacked, sys51.warnOutOfRange);
		}
	}
}
public class uitext
{
	public string txtIsEnabled { get; set; }

	public string txtIsDisabled { get; set; }

	public string txtWarnDangerNearby { get; set; }

	public string txtWarnBeingAttacked { get; set; }

	public string txtWarnOutOfRange { get; set; }

	public uitext(string _txtIsEnabled, string _txtIsDisabled, string _txtWarnDangerNearby, string _txtWarnBeingAttacked, string _warnOutOfRange)
	{
		txtIsEnabled = _txtIsEnabled;
		txtIsDisabled = _txtIsDisabled;
		txtWarnDangerNearby = _txtWarnDangerNearby;
		txtWarnBeingAttacked = _txtWarnBeingAttacked;
		txtWarnOutOfRange = _warnOutOfRange;
	}
}
public class tools
{
	public static readonly string[] toolSet = new string[6] { "$item_hammer", "$item_cultivator", "$item_hoe", "$PlumgaPlantItShovel", "$PlumgaClutterTool", "$ImprovedHammer" };
}
public class ui
{
	public class windowHint
	{
		public class hintBuildCamera
		{
			public static void setBuildCamHint(bool isToolEquipped, Player p)
			{
				//IL_008c: Unknown result type (might be due to invalid IL or missing references)
				//IL_011c: Unknown result type (might be due to invalid IL or missing references)
				if (isToolEquipped && hintConditions(p))
				{
					setHint.setComponents();
					if (!((Object)(object)wndHint != (Object)null))
					{
						return;
					}
					Text componentInChildren = wndHint.GetComponentInChildren<Text>();
					if ((Object)(object)componentInChildren != (Object)null)
					{
						componentInChildren.text = "Press '";
						if (ZInput.IsGamepadActive())
						{
							componentInChildren.text += pad.stateController.txtButton;
						}
						else
						{
							componentInChildren.text += $"{load.getCfg.ksKeyBuildModeSwitch}";
						}
						Text val = componentInChildren;
						val.text = val.text + "' to <color=" + (gosub.isBuildMode ? "#E65100" : "#00D700") + ">" + (gosub.isBuildMode ? "dis" : "en") + "able</color> Build-Camera";
						componentInChildren.text += $" or '{load.getCfg.ksKeyBuildModeSettings}' for settings.";
					}
					if (!gosub.isBuildStationInRange(in p))
					{
						componentInChildren.text = "<color=#9F9F00>" + load.txtUI.txtWarnOutOfRange + "</color>";
					}
					if (p.IsSensed() && p.IsTargeted())
					{
						componentInChildren.text = "<color=#FFFF00><b>" + load.txtUI.txtWarnDangerNearby + "</b></color>";
					}
				}
				else if ((Object)(object)wndHint != (Object)null)
				{
					Object.Destroy((Object)(object)wndHint);
					wndHint = null;
				}
			}
		}

		private class setHint
		{
			public static void setComponents()
			{
				//IL_0019: Unknown result type (might be due to invalid IL or missing references)
				//IL_0023: Expected O, but got Unknown
				//IL_005e: Unknown result type (might be due to invalid IL or missing references)
				//IL_007f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0095: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ed: Expected O, but got Unknown
				//IL_0133: 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_015e: 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)
				if ((Object)(object)wndHint == (Object)null)
				{
					wndHint = new GameObject("BuildCamHintFrame");
					wndHint.transform.SetParent(((Component)Hud.instance).transform, false);
					Image val = wndHint.AddComponent<Image>();
					((Graphic)val).color = new Color(0f, 0f, 0f, 0.5f);
					RectTransform component = wndHint.GetComponent<RectTransform>();
					component.anchorMin = new Vector2(0.5f, 0f);
					component.anchorMax = new Vector2(0.5f, 0f);
					component.pivot = new Vector2(0.5f, 0.5f);
					component.anchoredPosition = new Vector2(0f, 287f);
					component.sizeDelta = new Vector2(510f, 20f);
					GameObject val2 = new GameObject("BuildCamHintText");
					val2.transform.SetParent(wndHint.transform, false);
					Text val3 = val2.AddComponent<Text>();
					val3.font = Resources.GetBuiltinResource<Font>("LegacyRuntime.ttf");
					val3.fontSize = 12;
					val3.fontStyle = (FontStyle)1;
					((Graphic)val3).color = Color.white;
					val3.alignment = (TextAnchor)4;
					RectTransform component2 = val2.GetComponent<RectTransform>();
					component2.anchorMin = Vector2.zero;
					component2.anchorMax = Vector2.one;
					component2.sizeDelta = Vector2.zero;
				}
			}
		}

		private static GameObject wndHint;

		public static bool warnEnemiesNearBy { get; set; }

		private static bool hintConditions(Player p)
		{
			return (Object)(object)Hud.instance != (Object)null && Hud.instance.IsVisible() && !gosub.playerIsBlocked(p) && !Minimap.IsOpen() && !windowConfigs.isOpen;
		}
	}

	public class windowConfigs : MonoBehaviour
	{
		public static bool isOpen;

		private const float winWidth = 650f;

		private const float winHeight = 675f;

		private static Rect windowRect;

		private const int windowID = 9999;

		public static void toggleMenu()
		{
			//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)
			isOpen = !isOpen;
			if (isOpen)
			{
				windowRect = new Rect((float)Screen.width / 2f - 325f, (float)Screen.height / 2.4f - 337.5f, 650f, 675f);
				if (gosub.isInBuildMode())
				{
					gosub.disableBuildMode(showInfo: true);
				}
				Game.Pause();
				return;
			}
			Game.Unpause();
			if (!((Object)(object)Player.m_localPlayer != (Object)null))
			{
				return;
			}
			FieldInfo field = typeof(CraftingStation).GetField("m_allStations", BindingFlags.Static | BindingFlags.NonPublic);
			if (field.GetValue(null) is List<CraftingStation> list)
			{
				foreach (CraftingStation item in list)
				{
					if (item.m_rangeBuild < load.getCfg.floatRangeBuildWorkbench)
					{
						item.m_rangeBuild = load.getCfg.floatRangeBuildWorkbench;
					}
					Traverse.Create((object)item).Field("m_buildRange").SetValue((object)load.getCfg.floatRangeBuildWorkbench);
				}
			}
			if ((Object)(object)Hud.instance != (Object)null)
			{
				MethodInfo method = typeof(Hud).GetMethod("UpdateBuild", BindingFlags.Instance | BindingFlags.NonPublic);
				if (method != null)
				{
					method.Invoke(Hud.instance, new object[2]
					{
						Player.m_localPlayer,
						true
					});
				}
			}
		}

		private void OnGUI()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Invalid comparison between Unknown and I4
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Invalid comparison between Unknown and I4
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Expected O, but got Unknown
			//IL_00cf: 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_00eb: Unknown result type (might be due to invalid IL or missing references)
			if (isOpen)
			{
				if (((int)Event.current.type == 4 && (int)Event.current.keyCode == 27) || Console.IsVisible())
				{
					Event.current.Use();
					load.configFile.Reload();
					values.getValues();
					toggleMenu();
					return;
				}
				Color backgroundColor = GUI.backgroundColor;
				Color contentColor = GUI.contentColor;
				GUI.backgroundColor = new Color(0.1f, 0.1f, 0.1f, 1f);
				GUI.contentColor = Color.white;
				Cursor.lockState = (CursorLockMode)0;
				Cursor.visible = true;
				windowRect = GUI.Window(9999, windowRect, new WindowFunction(setComponents), "<color=yellow>" + kernal.sys17.lblHeader + "</color>");
				GUI.FocusWindow(9999);
				GUI.backgroundColor = backgroundColor;
				GUI.contentColor = contentColor;
			}
		}

		private void setComponents(int id)
		{
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Expected O, but got Unknown
			//IL_0254: Unknown result type (might be due to invalid IL or missing references)
			//IL_0259: Unknown result type (might be due to invalid IL or missing references)
			//IL_026b: Expected O, but got Unknown
			//IL_03d7: 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_03ee: Expected O, but got Unknown
			//IL_0568: Unknown result type (might be due to invalid IL or missing references)
			//IL_056d: Unknown result type (might be due to invalid IL or missing references)
			//IL_057f: Expected O, but got Unknown
			//IL_064b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0650: Unknown result type (might be due to invalid IL or missing references)
			//IL_0662: Expected O, but got Unknown
			//IL_0ac6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0acb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ad3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b00: Expected O, but got Unknown
			//IL_0b37: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b3c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b44: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b71: Expected O, but got Unknown
			int fontSize = GUI.skin.label.fontSize;
			int fontSize2 = GUI.skin.toggle.fontSize;
			int fontSize3 = GUI.skin.textField.fontSize;
			GUI.skin.label.fontSize = 11;
			GUI.skin.toggle.fontSize = 11;
			GUI.skin.textField.fontSize = 11;
			if (GUI.Button(new Rect(625f, 1f, 20f, 18f), "X"))
			{
				load.configFile.Reload();
				values.getValues();
				toggleMenu();
				GUI.skin.label.fontSize = fontSize;
				GUI.skin.toggle.fontSize = fontSize2;
				GUI.skin.textField.fontSize = fontSize3;
				return;
			}
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.BeginVertical((GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(300f) });
			GUILayout.Label("<color=yellow><b>" + kernal.sys17.lblGeneral + "</b></color>", new GUIStyle(GUI.skin.label)
			{
				richText = true
			}, Array.Empty<GUILayoutOption>());
			GUILayout.Space(5f);
			GUILayout.Label($"{kernal.sys17.lblRangeChar} {load.getCfg.floatRangeBuildAvatar:F1} (Default: 8.0)", Array.Empty<GUILayoutOption>());
			load.getCfg.floatRangeBuildAvatar = GUILayout.HorizontalSlider(load.getCfg.floatRangeBuildAvatar, kernal.sys47.min.RangeBuildChar, kernal.sys47.max.RangeBuildChar, Array.Empty<GUILayoutOption>());
			GUILayout.Space(10f);
			GUILayout.Label($"{kernal.sys17.lblRangeBench} {load.getCfg.floatRangeBuildWorkbench:F1} (Default: 20.0)", Array.Empty<GUILayoutOption>());
			load.getCfg.floatRangeBuildWorkbench = GUILayout.HorizontalSlider(load.getCfg.floatRangeBuildWorkbench, kernal.sys47.min.RangeBuildBench, kernal.sys47.max.RangeBuildBench, Array.Empty<GUILayoutOption>());
			GUILayout.Space(10f);
			load.getCfg.boolResourceToPlayer = GUILayout.Toggle(load.getCfg.boolResourceToPlayer, " " + kernal.sys17.cbxResToPlayer, Array.Empty<GUILayoutOption>());
			GUILayout.Space(20f);
			GUILayout.Label("<color=yellow><b>" + kernal.sys17.lblCamControl + "</b></color>", new GUIStyle(GUI.skin.label)
			{
				richText = true
			}, Array.Empty<GUILayoutOption>());
			GUILayout.Space(5f);
			GUILayout.Label(kernal.sys17.lblCamDive + " " + (0f - load.getCfg.floatMaxGroundDive).ToString("+0.0;-0.0;0.0"), Array.Empty<GUILayoutOption>());
			load.getCfg.floatMaxGroundDive = 0f - GUILayout.HorizontalSlider(0f - load.getCfg.floatMaxGroundDive, kernal.sys47.min.RangeDive, kernal.sys47.max.RangeDive, Array.Empty<GUILayoutOption>());
			GUILayout.Space(10f);
			GUILayout.Label($"{kernal.sys17.lblCamRangeMulti} {load.getCfg.floatCamRangeMultier:F1}x", Array.Empty<GUILayoutOption>());
			load.getCfg.floatCamRangeMultier = GUILayout.HorizontalSlider(load.getCfg.floatCamRangeMultier, kernal.sys47.min.RangeCamMulti, kernal.sys47.max.RangeCamMulti, Array.Empty<GUILayoutOption>());
			GUILayout.Space(10f);
			GUILayout.Label($"{kernal.sys17.lblCamSpeedMulti} {load.getCfg.floatCamSpeedMultiplier:F1}x", Array.Empty<GUILayoutOption>());
			load.getCfg.floatCamSpeedMultiplier = GUILayout.HorizontalSlider(load.getCfg.floatCamSpeedMultiplier, kernal.sys47.min.SpeedCamMulti, kernal.sys47.max.SpeedCamMulti, Array.Empty<GUILayoutOption>());
			GUILayout.EndVertical();
			GUILayout.Space(25f);
			GUILayout.BeginVertical((GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(300f) });
			GUILayout.Label("<color=yellow><b>" + kernal.sys17.lblCamLight + "</b></color>", new GUIStyle(GUI.skin.label)
			{
				richText = true
			}, Array.Empty<GUILayoutOption>());
			GUILayout.Space(5f);
			load.getCfg.boolBuildLight = GUILayout.Toggle(load.getCfg.boolBuildLight, " " + kernal.sys17.cbxBuildLight, Array.Empty<GUILayoutOption>());
			GUILayout.Space(5f);
			GUILayout.Label($"{kernal.sys17.lblFOVLight} {load.getCfg.floatBuildLightFOV:F0}°", Array.Empty<GUILayoutOption>());
			load.getCfg.floatBuildLightFOV = GUILayout.HorizontalSlider(load.getCfg.floatBuildLightFOV, kernal.sys47.min.FOVLight, kernal.sys47.max.FOVLight, Array.Empty<GUILayoutOption>());
			GUILayout.Space(10f);
			GUILayout.Label($"{kernal.sys17.lblDistLight} {load.getCfg.floatBuildLightRange:F1}", Array.Empty<GUILayoutOption>());
			load.getCfg.floatBuildLightRange = GUILayout.HorizontalSlider(load.getCfg.floatBuildLightRange, kernal.sys47.min.RangeLight, kernal.sys47.max.RangeLight, Array.Empty<GUILayoutOption>());
			GUILayout.Space(10f);
			GUILayout.Label($"{kernal.sys17.lblIntenseLight}  {load.getCfg.floatBuildLightIntensity:F1}", Array.Empty<GUILayoutOption>());
			load.getCfg.floatBuildLightIntensity = GUILayout.HorizontalSlider(load.getCfg.floatBuildLightIntensity, kernal.sys47.min.IntensityLight, kernal.sys47.max.IntensityLight, Array.Empty<GUILayoutOption>());
			GUILayout.Space(20f);
			GUILayout.Label("<color=yellow><b>" + kernal.sys17.lblDemist + "</b></color>", new GUIStyle(GUI.skin.label)
			{
				richText = true
			}, Array.Empty<GUILayoutOption>());
			GUILayout.Space(5f);
			load.getCfg.boolBuildDemist = GUILayout.Toggle(load.getCfg.boolBuildDemist, " " + kernal.sys17.cbxDemist, Array.Empty<GUILayoutOption>());
			GUILayout.Space(5f);
			GUILayout.Label($"{kernal.sys17.lblRangeDemist} {load.getCfg.floatBuildDemistRange:F1}", Array.Empty<GUILayoutOption>());
			load.getCfg.floatBuildDemistRange = GUILayout.HorizontalSlider(load.getCfg.floatBuildDemistRange, kernal.sys47.min.RangeDemist, kernal.sys47.max.RangeDemist, Array.Empty<GUILayoutOption>());
			GUILayout.EndVertical();
			GUILayout.EndHorizontal();
			GUILayout.Space(15f);
			GUILayout.Label("<color=yellow><b>" + kernal.sys17.lblPickUp + "</b></color>", new GUIStyle(GUI.skin.label)
			{
				richText = true
			}, Array.Empty<GUILayoutOption>());
			GUILayout.Space(5f);
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.BeginVertical((GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(300f) });
			load.getCfg.boolCamInteractEnable = GUILayout.Toggle(load.getCfg.boolCamInteractEnable, " " + kernal.sys17.cbxInteract, Array.Empty<GUILayoutOption>());
			GUILayout.Space(4f);
			GUILayout.Label($"{kernal.sys17.lblDistPickUp} {load.getCfg.floatCamInteractDistance:F1} (Default: 5.0)", Array.Empty<GUILayoutOption>());
			load.getCfg.floatCamInteractDistance = GUILayout.HorizontalSlider(load.getCfg.floatCamInteractDistance, kernal.sys47.min.RangeInteract, kernal.sys47.max.RangeInteract, Array.Empty<GUILayoutOption>());
			GUILayout.EndVertical();
			GUILayout.Space(25f);
			GUILayout.BeginVertical((GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(300f) });
			load.getCfg.boolCamAutoPickupEnable = GUILayout.Toggle(load.getCfg.boolCamAutoPickupEnable, " " + kernal.sys17.cbxAutoPickUp, Array.Empty<GUILayoutOption>());
			GUILayout.Space(4f);
			GUILayout.Label($"{kernal.sys17.lblRadiusAutoPick} {load.getCfg.floatCamAutoPickupRadius:F1} (Default: 2.0)", Array.Empty<GUILayoutOption>());
			load.getCfg.floatCamAutoPickupRadius = GUILayout.HorizontalSlider(load.getCfg.floatCamAutoPickupRadius, kernal.sys47.min.RangeAutoPick, kernal.sys47.max.RangeAutoPick, Array.Empty<GUILayoutOption>());
			GUILayout.EndVertical();
			GUILayout.EndHorizontal();
			GUILayout.Space(15f);
			GUILayout.Label("<color=yellow><b>" + kernal.sys17.lblTextSet + "</b></color>", Array.Empty<GUILayoutOption>());
			GUILayout.Space(5f);
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.BeginVertical((GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(300f) });
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label(kernal.sys17.lblAttacked + " ", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(80f) });
			load.txtUI.txtWarnBeingAttacked = GUILayout.TextField(load.txtUI.txtWarnBeingAttacked, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(210f) });
			GUILayout.EndHorizontal();
			GUILayout.Space(5f);
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label(kernal.sys17.lblDanger + " ", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(80f) });
			load.txtUI.txtWarnDangerNearby = GUILayout.TextField(load.txtUI.txtWarnDangerNearby, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(210f) });
			GUILayout.EndHorizontal();
			GUILayout.Space(5f);
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label(kernal.sys17.lblBenchRange + " ", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(80f) });
			load.txtUI.txtWarnOutOfRange = GUILayout.TextField(load.txtUI.txtWarnOutOfRange, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(210f) });
			GUILayout.EndHorizontal();
			GUILayout.EndVertical();
			GUILayout.Space(25f);
			GUILayout.BeginVertical((GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(300f) });
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label(kernal.sys17.lblCamOff + " ", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(60f) });
			load.txtUI.txtIsDisabled = GUILayout.TextField(load.txtUI.txtIsDisabled, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(230f) });
			GUILayout.EndHorizontal();
			GUILayout.Space(5f);
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label(kernal.sys17.lblCamOn + " ", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(60f) });
			load.txtUI.txtIsEnabled = GUILayout.TextField(load.txtUI.txtIsEnabled, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(230f) });
			GUILayout.EndHorizontal();
			GUILayout.EndVertical();
			GUILayout.EndHorizontal();
			GUILayout.Space(10f);
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.FlexibleSpace();
			if (GUILayout.Button("<color=#AAAA00><b>" + kernal.sys17.btnReset + "</b></color>", new GUIStyle(GUI.skin.button)
			{
				richText = true,
				fontStyle = (FontStyle)1
			}, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.Width(180f),
				GUILayout.Height(30f)
			}))
			{
				values.resetValues();
			}
			GUILayout.Space(40f);
			if (GUILayout.Button("<color=green><b>" + kernal.sys17.btnSave + "</b></color>", new GUIStyle(GUI.skin.button)
			{
				richText = true,
				fontStyle = (FontStyle)1
			}, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.Width(180f),
				GUILayout.Height(30f)
			}))
			{
				values.setValue();
				values.getValues();
				load.configFile.Save();
				toggleMenu();
			}
			GUILayout.FlexibleSpace();
			GUILayout.EndHorizontal();
			GUI.skin.label.fontSize = fontSize;
			GUI.skin.toggle.fontSize = fontSize2;
			GUI.skin.textField.fontSize = fontSize3;
		}
	}

	public class stateMessage
	{
		public static void disableBuildCam()
		{
			((Character)Player.m_localPlayer).Message((MessageType)2, load.txtUI.txtIsDisabled, 0, (Sprite)null, false);
		}

		public static void enableBuildCam()
		{
			((Character)Player.m_localPlayer).Message((MessageType)2, load.txtUI.txtIsEnabled, 0, (Sprite)null, false);
		}

		public static void warnAttack()
		{
			MessageHud.instance.ShowMessage((MessageType)1, "<color=red>" + load.txtUI.txtWarnBeingAttacked + "</color>", 0, (Sprite)null, false, true);
		}
	}
}
[HarmonyPatch]
public class wbench
{
	[HarmonyPrefix]
	[HarmonyPatch(typeof(CraftingStation), "Start")]
	public static void setRangeWorkbench_(ref CraftingStation __instance, ref float ___m_rangeBuild)
	{
		if (___m_rangeBuild < load.getCfg.floatRangeBuildWorkbench)
		{
			___m_rangeBuild = load.getCfg.floatRangeBuildWorkbench;
		}
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(CraftingStation), "GetStationBuildRange")]
	public static void setRangeWorkbench(ref CraftingStation __instance)
	{
		__instance.m_rangeBuild = load.getCfg.floatRangeBuildWorkbench;
	}
}

plugins/CraftingStationExtensionRadius/CraftingStationExtensionRadius.dll

Decompiled a day ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("JotunnModStub")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("JotunnModStub")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e3243d22-4307-4008-ba36-9f326008cde5")]
[assembly: AssemblyFileVersion("0.0.1.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.1.0")]
namespace CraftingStationExtensionRadius;

[BepInPlugin("blumaye.craftingstationextensionradius", "CraftingStationExtensionRadius", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
	[HarmonyPatch(typeof(StationExtension), "Awake")]
	public static class StationExtension_Awake_Prefix
	{
		public static void Prefix(ref float ___m_maxStationDistance)
		{
			___m_maxStationDistance = connectionDistance.Value;
		}
	}

	[HarmonyPatch(typeof(StationExtension), "OtherExtensionInRange")]
	public static class StationExtension_OtherExtensionInRange_Patch
	{
		public static void Postfix(ref bool __result)
		{
			if (disableCollison.Value)
			{
				__result = false;
			}
		}
	}

	public const string PluginGUID = "blumaye.craftingstationextensionradius";

	public const string PluginName = "CraftingStationExtensionRadius";

	public const string PluginVersion = "1.0.0";

	private Harmony harmony = new Harmony("blumaye.craftingstationextensionradius");

	public static ConfigEntry<float> connectionDistance;

	public static ConfigEntry<bool> disableCollison;

	public void Awake()
	{
		((BaseUnityPlugin)this).Config.SaveOnConfigSet = true;
		connectionDistance = ((BaseUnityPlugin)this).Config.Bind<float>("Station Extension", "Max connection distance", 30f, "Max connection distance (5f - original game)");
		disableCollison = ((BaseUnityPlugin)this).Config.Bind<bool>("Station Extension", "Removes collision between extension stations", true, "Removes collision between extension stations");
		Harmony obj = harmony;
		if (obj != null)
		{
			obj.PatchAll();
		}
	}

	public void OnDestroy()
	{
		Harmony obj = harmony;
		if (obj != null)
		{
			obj.UnpatchSelf();
		}
	}
}

plugins/NoRainDamage/NoRainDamage.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: IgnoresAccessChecksTo("assembly_valheim")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("NoRainDamage")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+c4ccf3b6ff7a7b3d8c3fc4a836851696fe695e26")]
[assembly: AssemblyProduct("NoRainDamage")]
[assembly: AssemblyTitle("NoRainDamage")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace NoRainDamage
{
	[BepInPlugin("uk.co.oliapps.valheim.noraindamage", "No Rain Damage", "1.3.1")]
	public class NoRainDamage : BaseUnityPlugin
	{
		private enum DamageFilter
		{
			ALL,
			INCLUSIVE,
			EXCLUSIVE
		}

		private static readonly ManualLogSource MyLogger = Logger.CreateLogSource("NoRainDamage");

		private static ConfigEntry<float> damagePerMinute;

		private static ConfigEntry<float> maxRainDamagePercentage;

		private static ConfigEntry<DamageFilter> damageFilter;

		private static ConfigEntry<string> damageFilterValues;

		private static ConfigEntry<bool> modEnabled;

		private static ConfigEntry<bool> debugLogsEnabled;

		private static Dictionary<int, float> minHealths;

		private static float minHealthPercentage;

		public void Awake()
		{
			modEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Set whether the mod is enabled");
			maxRainDamagePercentage = ((BaseUnityPlugin)this).Config.Bind<float>("Rain Damage", "Max Damage", 0f, "Maximum damage rain can do to uncovered structures between 0.0 and 1.0");
			damagePerMinute = ((BaseUnityPlugin)this).Config.Bind<float>("Rain Damage", "Damage Per Minute", 5f, "Damage per minute rain deals to uncovered structures");
			damageFilter = ((BaseUnityPlugin)this).Config.Bind<DamageFilter>("Damage Filter", "Filter Type", DamageFilter.ALL, "Set whether everything should be protected (ALL), certain things should be protected (INCLUSIVE) or certain things should not be protected (EXCLUSIVE)");
			damageFilterValues = ((BaseUnityPlugin)this).Config.Bind<string>("Damage Filter", "Filter List", "", "If Filter type is INCLUSIVE or EXCLUSIVE, this list of comma-separated values will be used as a filter (will protect or damage if piece name contains value). Piece list included in mod download.");
			debugLogsEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Debugging", "Enabled", false, "Enable debug logging");
			((BaseUnityPlugin)this).Config.Save();
			if (modEnabled.Value)
			{
				Harmony.CreateAndPatchAll(typeof(NoRainDamage), (string)null);
				minHealths = new Dictionary<int, float>();
				Log($"Config loaded: damageFilter={damageFilter.Value}, damagePerMinute={damagePerMinute.Value}, damageFilterValues={damageFilterValues.Value}, maxRainDamagePercentage={maxRainDamagePercentage.Value}");
			}
		}

		private static void Log(string message)
		{
			if (debugLogsEnabled.Value)
			{
				MyLogger.LogDebug((object)message);
			}
		}

		[HarmonyPatch(typeof(WearNTear), "Awake")]
		[HarmonyPostfix]
		public static void WearNTear_Awake(ref WearNTear __instance)
		{
			minHealthPercentage = 1f - Mathf.Clamp(maxRainDamagePercentage.Value, 0f, 1f);
			minHealths[((Object)__instance).GetInstanceID()] = __instance.m_health * minHealthPercentage;
		}

		[HarmonyPatch(typeof(WearNTear), "UpdateWear")]
		[HarmonyPrefix]
		[HarmonyPriority(0)]
		public static bool Prefix(WearNTear __instance, float time, ZNetView ___m_nview, ref int ___m_shieldChangeID, ref bool ___m_rainWet, ref bool ___m_haveRoof, bool ___m_noRoofWear, GameObject ___m_wet, ref float ___m_rainTimer, bool ___m_noSupportWear, string ___m_requiredPersistentEvent, bool ___m_takeDamageIfInsideEvent, float ___m_eventDamage, float ___m_eventDamageDeviation, ref Biome ___m_biome, ref bool ___m_heavySnow, ref bool ___m_addPreSnow, ref float ___m_snowBuildup, bool ___m_snowDamageImmune, ref float ___m_lastSupportColorValue, ref float ___m_snowDamageTimer, ref bool ___m_inAshlands, bool ___m_ashDamageImmune, bool ___m_haveAshRoof, bool ___m_ashDamageResist, ref float ___m_ashTimer, bool ___m_staticPosition, ref float ___m_lavaValue, Heightmap ___m_heightmap, float ___m_groundDist, ref float ___m_lavaTimer, Biome ___m_requiredBiome, float ___m_outsideRequiredBiomeDamage, ref float ___m_ashDamageTime, GameObject ___m_snow)
		{
			//IL_007c: 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_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_024b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0623: Unknown result type (might be due to invalid IL or missing references)
			//IL_0627: Unknown result type (might be due to invalid IL or missing references)
			//IL_057a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0477: Unknown result type (might be due to invalid IL or missing references)
			//IL_0479: Unknown result type (might be due to invalid IL or missing references)
			//IL_048c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0492: Unknown result type (might be due to invalid IL or missing references)
			if (!OverrideWearNTear(ref __instance))
			{
				return true;
			}
			if (!Object.op_Implicit((Object)(object)___m_nview) || !___m_nview.IsValid())
			{
				return false;
			}
			ZDO zDO = ___m_nview.GetZDO();
			float currentHealth = ((zDO != null) ? zDO.GetFloat(ZDOVars.s_health, __instance.m_health) : __instance.m_health);
			if (___m_nview.IsOwner() && __instance.ShouldUpdate(time))
			{
				Vector3 position = ((Component)__instance).transform.position;
				if (ZNetScene.instance.OutsideActiveArea(position))
				{
					float maxSupport = __instance.GetMaxSupport();
					if (__instance.m_support.Equals(maxSupport))
					{
						return false;
					}
					___m_nview.GetZDO().Set(ZDOVars.s_support, maxSupport);
					return false;
				}
				bool flag = ShieldGenerator.IsInsideShieldCached(position, ref ___m_shieldChangeID);
				float num = 0f;
				___m_rainWet = !flag && !___m_haveRoof && ___m_noRoofWear && EnvMan.IsWet();
				if (Object.op_Implicit((Object)(object)___m_wet))
				{
					___m_wet.SetActive(___m_rainWet);
				}
				if (___m_noRoofWear && !flag && (double)__instance.GetHealthPercentage() > 0.5)
				{
					if (__instance.IsWet())
					{
						Log(((Object)((Component)__instance).gameObject).name + " is wet");
						if ((double)___m_rainTimer == 0.0)
						{
							___m_rainTimer = time;
						}
						else if ((double)time - (double)___m_rainTimer > 60.0)
						{
							___m_rainTimer = time;
							num += damagePerMinute.Value;
							if (IsTooMuchDamage(ref __instance, currentHealth, num))
							{
								float num2 = HowMuchIsTooMuch(ref __instance, currentHealth, num);
								Log($"{((Object)((Component)__instance).gameObject).name}: incoming rain damage ({num}) reduced by ({num2}");
								num -= num2;
							}
						}
					}
					else
					{
						___m_rainTimer = 0f;
					}
				}
				if (___m_noSupportWear)
				{
					__instance.UpdateSupport();
					if (!__instance.HaveSupport())
					{
						num = 100f;
					}
				}
				if (!string.IsNullOrEmpty(___m_requiredPersistentEvent))
				{
					PersistentEvent activeEvent = PersistentEventSystem.instance.GetActiveEvent(position);
					if (___m_takeDamageIfInsideEvent && activeEvent != null && activeEvent.internalName == ___m_requiredPersistentEvent)
					{
						num += ___m_eventDamage + Random.Range(0f - ___m_eventDamageDeviation, ___m_eventDamageDeviation);
					}
					else if ((activeEvent != null && activeEvent.internalName != ___m_requiredPersistentEvent) || activeEvent == null)
					{
						num += ___m_eventDamage + Random.Range(0f - ___m_eventDamageDeviation, ___m_eventDamageDeviation);
					}
				}
				bool flag2 = false;
				__instance.UpdateBiome();
				if ((int)___m_biome == 64)
				{
					bool flag3 = __instance.CanHaveSnow(flag);
					if (flag3 && (double)___m_snowBuildup < 1.0)
					{
						___m_heavySnow = false;
						float num3 = (___m_addPreSnow ? 1f : EnvMan.instance.GetSnowBuildup());
						if ((double)num3 > 0.0)
						{
							if (___m_addPreSnow)
							{
								___m_snowBuildup = 1f;
								___m_addPreSnow = false;
								___m_nview.GetZDO().Set(ZDOVars.s_preSnow, false);
							}
							else
							{
								___m_snowBuildup += num3 * Time.deltaTime * Game.instance.m_snowBuildupSpeed;
							}
							___m_nview.GetZDO().Set(ZDOVars.s_snow, ___m_snowBuildup);
						}
					}
					else if ((!___m_snowDamageImmune || ZoneSystem.instance.GetGlobalKey((GlobalKeys)39)) && !ZoneSystem.instance.GetGlobalKey((GlobalKeys)38))
					{
						___m_heavySnow = flag3;
						if (___m_heavySnow)
						{
							___m_lastSupportColorValue = __instance.GetSupportColorValue();
							if ((double)___m_lastSupportColorValue != -1.0 && (double)___m_lastSupportColorValue < (double)Game.instance.m_snowSupportLevel)
							{
								___m_heavySnow = true;
								num += Game.instance.m_snowDamage;
								if (ZNet.instance.GetTimeSeconds() >= (double)___m_snowDamageTimer)
								{
									___m_snowDamageTimer = (float)ZNet.instance.GetTimeSeconds() + Random.Range(Game.instance.m_snowDamageEffectIntervalRange.x, Game.instance.m_snowDamageEffectIntervalRange.y);
									Game.instance.m_snowDamageEffect.Create(position, Quaternion.identity, ((Component)__instance).transform, 1f, -1, default(ZDOID));
								}
							}
						}
					}
				}
				if ((int)___m_biome == 32)
				{
					___m_inAshlands = true;
					if ((double)Game.instance.m_ashDamage > 0.0 && !flag && !___m_ashDamageImmune)
					{
						flag2 = !___m_haveAshRoof && (!___m_ashDamageResist || (double)__instance.GetHealthPercentage() > 0.1);
						if (flag2)
						{
							if ((double)___m_ashTimer == 0.0)
							{
								___m_ashTimer = time;
							}
							else if ((double)time - (double)___m_ashTimer > 5.0)
							{
								___m_ashTimer = time;
								num += Game.instance.m_ashDamage;
							}
						}
						else
						{
							___m_ashTimer = 0f;
						}
					}
					if (!___m_staticPosition && (Object)(object)___m_heightmap != (Object)null)
					{
						___m_lavaValue = ___m_heightmap.GetLava(position);
					}
					if ((double)___m_lavaValue > 0.2 && (double)___m_groundDist < 1.5 && !___m_ashDamageImmune)
					{
						if ((double)___m_lavaTimer == 0.0)
						{
							___m_lavaTimer = time;
						}
						else if ((double)time - (double)___m_lavaTimer > 2.0)
						{
							___m_lavaTimer = time;
							float num4 = (flag ? 30f : 70f) * ___m_lavaValue;
							num += num4 * (___m_ashDamageResist ? 0.33f : 1f);
						}
					}
					else
					{
						___m_lavaTimer = 0f;
					}
				}
				if ((int)___m_requiredBiome != 0 && !((Enum)___m_requiredBiome).HasFlag((Enum)(object)___m_biome))
				{
					num += ___m_outsideRequiredBiomeDamage;
				}
				___m_ashDamageTime = (flag2 ? 5f : 0f);
				if ((double)num > 0.0 && !__instance.CanBeRemoved())
				{
					num = 0f;
				}
				if ((double)num > 0.0)
				{
					float num5 = num / 100f * __instance.m_health;
					if (!ZoneSystem.instance.GetGlobalKey((GlobalKeys)37))
					{
						__instance.ApplyDamage(num5, (HitData)null);
					}
				}
			}
			if (Object.op_Implicit((Object)(object)___m_snow) && ___m_nview.IsValid())
			{
				___m_snowBuildup = ___m_nview.GetZDO().GetFloat(ZDOVars.s_snow, 0f);
			}
			__instance.UpdateVisual(true);
			return false;
		}

		private static bool OverrideWearNTear(ref WearNTear instance)
		{
			if (DamageFilter.ALL.Equals(damageFilter.Value))
			{
				return true;
			}
			string[] array = damageFilterValues.Value.Split(new char[1] { ',' });
			string[] array2 = array;
			foreach (string text in array2)
			{
				string value = text.Trim();
				if (!string.IsNullOrEmpty(value) && ((Object)((Component)instance).gameObject).name.Contains(value))
				{
					return damageFilter.Value switch
					{
						DamageFilter.INCLUSIVE => true, 
						DamageFilter.EXCLUSIVE => false, 
						_ => true, 
					};
				}
			}
			return DamageFilter.EXCLUSIVE.Equals(damageFilter.Value);
		}

		private static bool IsTooMuchDamage(ref WearNTear instance, float currentHealth, float damage)
		{
			int instanceID = ((Object)instance).GetInstanceID();
			if (!minHealths.TryGetValue(instanceID, out var value))
			{
				minHealthPercentage = 1f - Mathf.Clamp(maxRainDamagePercentage.Value, 0f, 1f);
				value = instance.m_health * minHealthPercentage;
				minHealths[instanceID] = value;
			}
			float num = currentHealth - damage / 100f * instance.m_health;
			return num < value;
		}

		private static float HowMuchIsTooMuch(ref WearNTear instance, float currentHealth, float damage)
		{
			int instanceID = ((Object)instance).GetInstanceID();
			if (!minHealths.TryGetValue(instanceID, out var value))
			{
				minHealthPercentage = 1f - Mathf.Clamp(maxRainDamagePercentage.Value, 0f, 1f);
				value = instance.m_health * minHealthPercentage;
				minHealths[instanceID] = value;
			}
			float num = currentHealth - damage / 100f * instance.m_health;
			float num2 = Mathf.Abs(value - num);
			return num2 / instance.m_health * 100f;
		}

		[HarmonyPatch(typeof(WearNTear), "OnDestroy")]
		[HarmonyPostfix]
		public static void WearNTear_OnDestroy(ref WearNTear __instance)
		{
			minHealths.Remove(((Object)__instance).GetInstanceID());
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}

plugins/NordicRugs/NordicRugs.dll

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

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("NordicRugs")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0")]
[assembly: AssemblyProduct("NordicRugs")]
[assembly: AssemblyTitle("NordicRugs")]
[assembly: AssemblyVersion("1.1.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 NordicRugs
{
	[BepInPlugin("sosal.nordicrugs", "Nordic Rugs", "1.1.0")]
	[BepInDependency("com.jotunn.jotunn", "2.30.2")]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	public sealed class NordicRugsPlugin : BaseUnityPlugin
	{
		public const string Guid = "sosal.nordicrugs";

		public const string Version = "1.1.0";

		private void Awake()
		{
			AddLocalization();
			PrefabManager.OnVanillaPrefabsAvailable += RegisterRugs;
			PieceManager.OnPiecesRegistered += VerifyRecipes;
			((BaseUnityPlugin)this).Logger.LogInfo((object)string.Format("Nordic Rugs {0}: {1} independent decorative rugs in Furniture.", "1.1.0", RugCatalog.All.Length));
		}

		private void AddLocalization()
		{
			CustomLocalization localization = LocalizationManager.Instance.GetLocalization();
			Dictionary<string, string> dictionary = new Dictionary<string, string>
			{
				["nr_description"] = "Декоративный тканевый ковёр. Комфорт: 1 (общая категория ковров).",
				["nr_fur_description"] = "Меховой ковёр с объёмным ворсом. Комфорт: 1 (общая категория ковров)."
			};
			Dictionary<string, string> dictionary2 = new Dictionary<string, string>
			{
				["nr_description"] = "A decorative woven rug. Comfort: 1 (shared carpet group).",
				["nr_fur_description"] = "A thick fur rug. Comfort: 1 (shared carpet group)."
			};
			RugDefinition[] all = RugCatalog.All;
			foreach (RugDefinition rugDefinition in all)
			{
				dictionary[rugDefinition.NameToken] = rugDefinition.NameRu;
				dictionary2[rugDefinition.NameToken] = rugDefinition.NameEn;
			}
			string text = "English";
			localization.AddTranslation(ref text, dictionary2);
			text = "Russian";
			localization.AddTranslation(ref text, dictionary);
		}

		private void RegisterRugs()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Expected O, but got Unknown
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			PrefabManager.OnVanillaPrefabsAvailable -= RegisterRugs;
			int num = 0;
			RugDefinition[] all = RugCatalog.All;
			foreach (RugDefinition rugDefinition in all)
			{
				try
				{
					PieceConfig val = new PieceConfig();
					val.Name = "$" + rugDefinition.NameToken;
					val.Description = (rugDefinition.Fur ? "$nr_fur_description" : "$nr_description");
					val.PieceTable = "Hammer";
					val.Category = "Furniture";
					val.Usage = new string[1] { "Furniture" };
					val.CraftingStation = "piece_workbench";
					PieceConfig val2 = val;
					foreach (KeyValuePair<string, int> item in rugDefinition.Recipe)
					{
						val2.AddRequirement(item.Key, item.Value, true);
					}
					CustomPiece val3 = new CustomPiece(rugDefinition.PrefabName, "rug_deer", val2);
					if (!Object.op_Implicit((Object)(object)val3.PiecePrefab))
					{
						throw new InvalidOperationException("Vanilla rug_deer is unavailable.");
					}
					SetVisuals(val3, rugDefinition);
					val3.Piece.m_enabled = true;
					val3.Piece.m_comfort = 1;
					val3.Piece.m_comfortGroup = (ComfortGroup)6;
					val3.Piece.m_comfortObject = null;
					val3.Piece.m_groundOnly = false;
					val3.Piece.m_notOnWood = false;
					val3.Piece.m_notOnFloor = false;
					val3.Piece.m_noClipping = false;
					val3.Piece.m_clipEverything = true;
					val3.Piece.m_noInWater = true;
					val3.Piece.m_canBeRemoved = true;
					val3.PiecePrefab.GetComponent<ZNetView>().m_persistent = true;
					if (!PieceManager.Instance.AddPiece(val3))
					{
						throw new InvalidOperationException("Piece registration rejected.");
					}
					num++;
				}
				catch (Exception arg)
				{
					((BaseUnityPlugin)this).Logger.LogError((object)$"Failed to register {rugDefinition.PrefabName}: {arg}");
				}
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)$"Registered {num}/{RugCatalog.All.Length} Nordic Rugs in Furniture.");
		}

		private void SetVisuals(CustomPiece custom, RugDefinition rug)
		{
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Expected O, but got Unknown
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_025f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0266: Expected O, but got Unknown
			//IL_028e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0293: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ab: Expected O, but got Unknown
			//IL_031c: Unknown result type (might be due to invalid IL or missing references)
			//IL_039f: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_046c: Unknown result type (might be due to invalid IL or missing references)
			//IL_047b: Unknown result type (might be due to invalid IL or missing references)
			GameObject piecePrefab = custom.PiecePrefab;
			Material sharedMaterial = (PrefabManager.Instance.GetPrefab("jute_carpet") ?? PrefabManager.Instance.GetPrefab("rug_deer")).GetComponentsInChildren<Renderer>(true).First((Renderer r) => Object.op_Implicit((Object)(object)r.sharedMaterial)).sharedMaterial;
			LODGroup[] componentsInChildren = piecePrefab.GetComponentsInChildren<LODGroup>(true);
			for (int num = 0; num < componentsInChildren.Length; num++)
			{
				Object.DestroyImmediate((Object)(object)componentsInChildren[num]);
			}
			Transform[] array = ((IEnumerable)piecePrefab.transform).Cast<Transform>().ToArray();
			for (int num = 0; num < array.Length; num++)
			{
				Object.DestroyImmediate((Object)(object)((Component)array[num]).gameObject);
			}
			Renderer[] components = piecePrefab.GetComponents<Renderer>();
			for (int num = 0; num < components.Length; num++)
			{
				Object.DestroyImmediate((Object)(object)components[num]);
			}
			MeshFilter[] components2 = piecePrefab.GetComponents<MeshFilter>();
			for (int num = 0; num < components2.Length; num++)
			{
				Object.DestroyImmediate((Object)(object)components2[num]);
			}
			Collider[] components3 = piecePrefab.GetComponents<Collider>();
			for (int num = 0; num < components3.Length; num++)
			{
				Object.DestroyImmediate((Object)(object)components3[num]);
			}
			Texture2D val = LoadTexture(rug.Id);
			Material val2 = new Material(sharedMaterial)
			{
				name = "nr_material_" + rug.Id
			};
			val2.mainTexture = (Texture)(object)val;
			val2.mainTextureScale = Vector2.one;
			val2.mainTextureOffset = Vector2.zero;
			SetColor(val2, "_Color", Color.white);
			SetColor(val2, "_EmissionColor", Color.black);
			string[] array2 = new string[6] { "_BumpMap", "_MetallicGlossMap", "_EmissionMap", "_OcclusionMap", "_DetailAlbedoMap", "_DetailNormalMap" };
			foreach (string text in array2)
			{
				if (val2.HasProperty(text))
				{
					val2.SetTexture(text, (Texture)null);
				}
			}
			SetFloat(val2, "_Glossiness", 0.03f);
			SetFloat(val2, "_Metallic", 0f);
			SetFloat(val2, "_Cutoff", 0.45f);
			SetFloat(val2, "_BumpScale", 0f);
			val2.DisableKeyword("_NORMALMAP");
			val2.DisableKeyword("_METALLICGLOSSMAP");
			val2.DisableKeyword("_EMISSION");
			val2.EnableKeyword("_ALPHATEST_ON");
			GameObject val3 = new GameObject("NordicRugMesh");
			val3.layer = piecePrefab.layer;
			val3.transform.SetParent(piecePrefab.transform, false);
			RugMeshData rugMeshData = RugGeometry.Build(rug);
			Mesh val4 = new Mesh
			{
				name = rug.PrefabName + "_mesh"
			};
			val4.SetVertices(((IEnumerable<RugVertex>)rugMeshData.Vertices).Select((Func<RugVertex, Vector3>)((RugVertex v) => new Vector3(v.X, v.Y, v.Z))).ToList());
			val4.SetUVs(0, ((IEnumerable<RugVertex>)rugMeshData.Vertices).Select((Func<RugVertex, Vector2>)((RugVertex v) => new Vector2(v.U, v.V))).ToList());
			val4.SetColors(Enumerable.Repeat<Color>(Color.white, rugMeshData.Vertices.Count).ToList());
			val4.SetTriangles(rugMeshData.Indices, 0);
			val4.RecalculateNormals();
			val4.RecalculateTangents();
			val4.RecalculateBounds();
			val3.AddComponent<MeshFilter>().sharedMesh = val4;
			MeshRenderer obj = val3.AddComponent<MeshRenderer>();
			((Renderer)obj).sharedMaterial = val2;
			((Renderer)obj).shadowCastingMode = (ShadowCastingMode)1;
			((Renderer)obj).receiveShadows = true;
			BoxCollider obj2 = piecePrefab.AddComponent<BoxCollider>();
			obj2.center = new Vector3(0f, 0.025f, 0f);
			obj2.size = new Vector3(rug.Width * 0.9f, 0.05f, rug.Length * 0.9f);
			WearNTear component = piecePrefab.GetComponent<WearNTear>();
			component.m_new = val3;
			component.m_worn = val3;
			component.m_broken = val3;
			component.m_wet = null;
			component.m_snow = null;
			component.m_snowWorn = null;
			component.m_snowBroken = null;
			component.m_fragmentRoots = (GameObject[])(object)new GameObject[1] { val3 };
			component.m_nonSolidRenderers = new List<Renderer>();
			component.m_health = 50f;
			component.m_noRoofWear = false;
			component.m_supports = true;
			custom.Piece.m_icon = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 100f);
			((BaseUnityPlugin)this).Logger.LogInfo((object)$"{rug.PrefabName}: {rugMeshData.Indices.Count / 3} triangles; {((Texture)val).width}x{((Texture)val).height}; shader={((Object)val2.shader).name}");
		}

		private Texture2D LoadTexture(string id)
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Expected O, but got Unknown
			using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("NordicRugs.Textures." + id + ".png") ?? throw new FileNotFoundException("Missing embedded rug texture: " + id);
			using MemoryStream memoryStream = new MemoryStream();
			stream.CopyTo(memoryStream);
			Texture2D val = new Texture2D(2, 2, (TextureFormat)4, true, false)
			{
				name = "nr_texture_" + id,
				wrapMode = (TextureWrapMode)1,
				filterMode = (FilterMode)2,
				anisoLevel = 4
			};
			if (!ImageConversion.LoadImage(val, memoryStream.ToArray(), false))
			{
				throw new InvalidDataException("Invalid PNG: " + id);
			}
			if (SystemInfo.SupportsTextureFormat((TextureFormat)12))
			{
				val.Compress(true);
			}
			val.Apply(true, true);
			return val;
		}

		private void VerifyRecipes()
		{
			int num = 0;
			RugDefinition[] all = RugCatalog.All;
			foreach (RugDefinition rug in all)
			{
				CustomPiece piece = PieceManager.Instance.GetPiece(rug.PrefabName);
				Piece val = ((piece != null) ? piece.Piece : null);
				if (Object.op_Implicit((Object)(object)val))
				{
					if (val.m_resources.Length != rug.Recipe.Count || !val.m_resources.All((Requirement r) => Object.op_Implicit((Object)(object)r.m_resItem) && rug.Recipe.TryGetValue(((Object)((Component)r.m_resItem).gameObject).name, out var value) && value == r.m_amount && (Object)(object)ObjectDB.instance.GetItemPrefab(((Object)((Component)r.m_resItem).gameObject).name) == (Object)(object)((Component)r.m_resItem).gameObject) || !Object.op_Implicit((Object)(object)val.m_craftingStation) || !((Object)val.m_craftingStation).name.StartsWith("piece_workbench", StringComparison.Ordinal))
					{
						val.m_enabled = false;
						((BaseUnityPlugin)this).Logger.LogError((object)("Disabled " + rug.PrefabName + ": unresolved crafting resources or workbench. Target Valheim 1.0.16."));
					}
					else
					{
						num++;
					}
				}
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)$"Validated {num}/{RugCatalog.All.Length} rug recipes and workbench references.");
		}

		private static void SetFloat(Material mat, string key, float value)
		{
			if (mat.HasProperty(key))
			{
				mat.SetFloat(key, value);
			}
		}

		private static void SetColor(Material mat, string key, Color value)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			if (mat.HasProperty(key))
			{
				mat.SetColor(key, value);
			}
		}

		private void OnDestroy()
		{
			PrefabManager.OnVanillaPrefabsAvailable -= RegisterRugs;
			PieceManager.OnPiecesRegistered -= VerifyRecipes;
		}
	}
	public sealed class RugDefinition
	{
		public string Id { get; }

		public string NameRu { get; }

		public string NameEn { get; }

		public float Width { get; }

		public float Length { get; }

		public bool Fur { get; }

		public IReadOnlyDictionary<string, int> Recipe { get; }

		public string PrefabName => "nr_rug_" + Id;

		public string NameToken => "nr_" + Id;

		public RugDefinition(string id, string ru, string en, float width, float length, bool fur, Dictionary<string, int> recipe)
		{
			Id = id;
			NameRu = ru;
			NameEn = en;
			Width = width;
			Length = length;
			Fur = fur;
			Recipe = recipe;
		}
	}
	public static class RugCatalog
	{
		public static readonly RugDefinition[] All = new RugDefinition[17]
		{
			new RugDefinition("forest", "Дремучий бор", "Ancient Woodland", 2f, 3f, fur: false, new Dictionary<string, int>
			{
				["Flax"] = 5,
				["DeerHide"] = 4,
				["Thistle"] = 2,
				["Resin"] = 2
			}),
			new RugDefinition("raven", "Вороны Одина", "Odin's Ravens", 2f, 3f, fur: false, new Dictionary<string, int>
			{
				["Flax"] = 5,
				["DeerHide"] = 4,
				["Feathers"] = 6,
				["Coal"] = 2
			}),
			new RugDefinition("meadows", "Летнее цветение", "Summer Bloom", 2f, 3f, fur: false, new Dictionary<string, int>
			{
				["Flax"] = 5,
				["DeerHide"] = 4,
				["Dandelion"] = 4
			}),
			new RugDefinition("swamp", "Шёпот трясины", "Whisper of the Mire", 2f, 3f, fur: false, new Dictionary<string, int>
			{
				["Flax"] = 5,
				["LeatherScraps"] = 6,
				["Root"] = 2,
				["Guck"] = 2
			}),
			new RugDefinition("sea", "Путь драккара", "Path of the Longship", 2f, 3f, fur: false, new Dictionary<string, int>
			{
				["Flax"] = 5,
				["DeerHide"] = 4,
				["Blueberries"] = 4,
				["Chitin"] = 2
			}),
			new RugDefinition("plains", "Золотая жатва", "Golden Harvest", 2f, 3f, fur: false, new Dictionary<string, int>
			{
				["Flax"] = 5,
				["LinenThread"] = 6,
				["Barley"] = 4,
				["LoxPelt"] = 1
			}),
			new RugDefinition("mistlands", "Завеса туманов", "Veil of Mist", 1.5f, 3.2f, fur: false, new Dictionary<string, int>
			{
				["Flax"] = 5,
				["JuteBlue"] = 4,
				["Sap"] = 2
			}),
			new RugDefinition("mountain", "Волчья лежанка", "Wolf's Rest", 1.8f, 3f, fur: true, new Dictionary<string, int>
			{
				["Flax"] = 5,
				["WolfPelt"] = 6,
				["JuteRed"] = 2
			}),
			new RugDefinition("ashlands", "Пепельное солнце", "Ashen Sun", 1.6f, 3.2f, fur: false, new Dictionary<string, int>
			{
				["Flax"] = 5,
				["AskHide"] = 4,
				["LinenThread"] = 2,
				["SulfurStone"] = 2
			}),
			new RugDefinition("north", "Полярная ночь", "Polar Night", 1.8f, 3f, fur: true, new Dictionary<string, int>
			{
				["Flax"] = 5,
				["SealHide"] = 4,
				["WolfPelt"] = 2
			}),
			new RugDefinition("hunter", "Зов охоты", "Call of the Hunt", 2f, 3f, fur: false, new Dictionary<string, int>
			{
				["Flax"] = 5,
				["DeerHide"] = 6,
				["BoneFragments"] = 4,
				["Feathers"] = 4
			}),
			new RugDefinition("witch", "Ковёр ведьмы", "Witch Rug", 1.8f, 3f, fur: false, new Dictionary<string, int>
			{
				["Flax"] = 5,
				["TrollHide"] = 4,
				["Crystal"] = 2,
				["Dandelion"] = 4
			}),
			new RugDefinition("feast", "Ковёр празднества", "Feast Rug", 1.8f, 3f, fur: false, new Dictionary<string, int>
			{
				["Flax"] = 5,
				["JuteRed"] = 4,
				["Dandelion"] = 4,
				["Coins"] = 10
			}),
			new RugDefinition("runic", "Рунический круг", "Runic Circle", 2f, 3f, fur: false, new Dictionary<string, int>
			{
				["Flax"] = 5,
				["DeerHide"] = 4,
				["Feathers"] = 4,
				["Coal"] = 2
			}),
			new RugDefinition("blue", "Синяя вязь", "Blue Interlace", 2f, 3f, fur: false, new Dictionary<string, int>
			{
				["Flax"] = 5,
				["JuteBlue"] = 4,
				["Crystal"] = 2
			}),
			new RugDefinition("yggdrasil", "Древо туманов", "Tree of Mists", 4.5f, 3f, fur: false, new Dictionary<string, int>
			{
				["LinenThread"] = 15,
				["Wisp"] = 1
			}),
			new RugDefinition("rings", "Кольца туманов", "Rings of Mist", 4.5f, 3f, fur: false, new Dictionary<string, int>
			{
				["LinenThread"] = 15,
				["Wisp"] = 1
			})
		};
	}
	public readonly struct RugVertex
	{
		public readonly float X;

		public readonly float Y;

		public readonly float Z;

		public readonly float U;

		public readonly float V;

		public RugVertex(float x, float y, float z, float u, float v)
		{
			X = x;
			Y = y;
			Z = z;
			U = u;
			V = v;
		}
	}
	public sealed class RugMeshData
	{
		public readonly List<RugVertex> Vertices = new List<RugVertex>();

		public readonly List<int> Indices = new List<int>();

		public void Triangle(RugVertex a, RugVertex b, RugVertex c, bool twoSided = false)
		{
			int count = Vertices.Count;
			Vertices.Add(a);
			Vertices.Add(b);
			Vertices.Add(c);
			Indices.Add(count);
			Indices.Add(count + 1);
			Indices.Add(count + 2);
			if (twoSided)
			{
				Vertices.Add(c);
				Vertices.Add(b);
				Vertices.Add(a);
				Indices.Add(count + 3);
				Indices.Add(count + 4);
				Indices.Add(count + 5);
			}
		}

		public void Quad(RugVertex a, RugVertex b, RugVertex c, RugVertex d)
		{
			Triangle(a, b, c);
			Triangle(a, c, d);
		}
	}
	public static class RugGeometry
	{
		public static RugMeshData Build(RugDefinition rug)
		{
			RugMeshData rugMeshData = new RugMeshData();
			float thickness = (rug.Fur ? 0.038f : 0.016f);
			for (int i = 0; i < 18; i++)
			{
				for (int j = 0; j < 12; j++)
				{
					rugMeshData.Quad(Point(j, i, top: true), Point(j, i + 1, top: true), Point(j + 1, i + 1, top: true), Point(j + 1, i, top: true));
					rugMeshData.Quad(Point(j, i, top: false), Point(j + 1, i, top: false), Point(j + 1, i + 1, top: false), Point(j, i + 1, top: false));
				}
			}
			for (int k = 0; k < 12; k++)
			{
				rugMeshData.Quad(Point(k, 0, top: false), Point(k, 0, top: true), Point(k + 1, 0, top: true), Point(k + 1, 0, top: false));
				rugMeshData.Quad(Point(k, 18, top: false), Point(k + 1, 18, top: false), Point(k + 1, 18, top: true), Point(k, 18, top: true));
			}
			for (int l = 0; l < 18; l++)
			{
				rugMeshData.Quad(Point(0, l, top: false), Point(0, l + 1, top: false), Point(0, l + 1, top: true), Point(0, l, top: true));
				rugMeshData.Quad(Point(12, l, top: false), Point(12, l, top: true), Point(12, l + 1, top: true), Point(12, l + 1, top: false));
			}
			if (rug.Fur)
			{
				AddFur(rugMeshData, rug, thickness);
			}
			return rugMeshData;
			RugVertex Point(int x, int z, bool top)
			{
				float num = (float)x / 12f;
				float num2 = (float)z / 18f;
				float num3 = 0.0025f * (float)(Math.Sin((double)num * 17.0) * Math.Sin((double)num2 * 13.0));
				return new RugVertex((num - 0.5f) * rug.Width, top ? (thickness + num3) : 0.002f, (num2 - 0.5f) * rug.Length, num, num2);
			}
		}

		private static void AddFur(RugMeshData mesh, RugDefinition rug, float baseY)
		{
			Random random = new Random((rug.Id == "north") ? 7197 : 2217);
			int num = (int)(rug.Width * rug.Length * 70f);
			float num2 = ((rug.Id == "north") ? 0.105f : 0.065f);
			for (int i = 0; i < num; i++)
			{
				float num3 = 0.075f + (float)random.NextDouble() * 0.85f;
				float num4 = 0.075f + (float)random.NextDouble() * 0.85f;
				float num5 = (num3 - 0.5f) * rug.Width;
				float num6 = (num4 - 0.5f) * rug.Length;
				float num7 = 0.012f + (float)random.NextDouble() * 0.025f;
				float num8 = num2 * (0.45f + (float)random.NextDouble() * 0.55f);
				float num9 = 0.03f + (float)random.NextDouble() * 0.045f;
				RugVertex a = new RugVertex(num5 - num7, baseY, num6, num3 - num7 / rug.Width, num4);
				RugVertex b = new RugVertex(num5, baseY + num8, num6 + num9, num3, num4 + num9 / rug.Length);
				RugVertex c = new RugVertex(num5 + num7, baseY, num6, num3 + num7 / rug.Width, num4);
				mesh.Triangle(a, b, c, twoSided: true);
				mesh.Triangle(new RugVertex(num5, baseY, num6 - num7, num3, num4 - num7 / rug.Length), b, new RugVertex(num5, baseY, num6 + num7, num3, num4 + num7 / rug.Length), twoSided: true);
			}
		}
	}
}

plugins/TailwindSailing/TailwindSailing.dll

Decompiled a day ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: AssemblyCompany("TailwindSailing")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+805089108949c537f727de0fca873d9fc2f69769")]
[assembly: AssemblyProduct("TailwindSailing")]
[assembly: AssemblyTitle("TailwindSailing")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace TailwindSailing
{
	[HarmonyPatch(typeof(Minimap), "UpdateExplore")]
	internal static class ExplorePatch
	{
		private static void Prefix(Minimap __instance, Player player, out float __state)
		{
			__state = __instance.m_exploreRadius;
			if ((Object)(object)((Character)player).GetStandingOnShip() != (Object)null || (Object)(object)player.GetControlledShip() != (Object)null)
			{
				__instance.m_exploreRadius *= Plugin.ExploreRadiusMultiplier.Value;
			}
		}

		private static void Postfix(Minimap __instance, float __state)
		{
			__instance.m_exploreRadius = __state;
		}
	}
	[HarmonyPatch(typeof(Ship), "CustomFixedUpdate")]
	internal static class HideSailPatch
	{
		private static readonly FieldInfo s_sailClothField = AccessTools.Field(typeof(Ship), "m_sailCloth");

		private static readonly ConditionalWeakTable<Ship, Renderer> s_sailRenderers = new ConditionalWeakTable<Ship, Renderer>();

		private static void Postfix(Ship __instance)
		{
			Renderer value = s_sailRenderers.GetValue(__instance, FindSailRenderer);
			if (!((Object)(object)value == (Object)null))
			{
				bool flag = Plugin.HideSail.Value && __instance.IsSailUp() && IsLocalPlayerOnShip(__instance);
				if (value.enabled == flag)
				{
					value.enabled = !flag;
				}
			}
		}

		private static Renderer FindSailRenderer(Ship ship)
		{
			object? value = s_sailClothField.GetValue(ship);
			Component val = (Component)((value is Component) ? value : null);
			if (!((Object)(object)val != (Object)null))
			{
				return null;
			}
			return (Renderer)(object)val.GetComponentInChildren<SkinnedMeshRenderer>(true);
		}

		private static bool IsLocalPlayerOnShip(Ship ship)
		{
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer != (Object)null)
			{
				if (!((Object)(object)((Character)localPlayer).GetStandingOnShip() == (Object)(object)ship))
				{
					return (Object)(object)localPlayer.GetControlledShip() == (Object)(object)ship;
				}
				return true;
			}
			return false;
		}
	}
	[BepInPlugin("runo4.valheim.tailwindsailing", "Tailwind Sailing", "1.0.1")]
	public class Plugin : BaseUnityPlugin
	{
		public const string ModGuid = "runo4.valheim.tailwindsailing";

		public const string ModName = "Tailwind Sailing";

		public const string ModVersion = "1.0.1";

		private const string FeaturesSection = "1 - Features";

		private const string MultipliersSection = "2 - Multipliers";

		internal static ManualLogSource Log;

		internal static ConfigEntry<bool> AlwaysTailwind;

		internal static ConfigEntry<bool> DisableWaveDamage;

		internal static ConfigEntry<bool> StrongerPush;

		internal static ConfigEntry<bool> HideSail;

		internal static ConfigEntry<float> SailingSpeedMultiplier;

		internal static ConfigEntry<float> RowingSpeedMultiplier;

		internal static ConfigEntry<float> ExploreRadiusMultiplier;

		private void Awake()
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Expected O, but got Unknown
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Expected O, but got Unknown
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Expected O, but got Unknown
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Expected O, but got Unknown
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Expected O, but got Unknown
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Expected O, but got Unknown
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Expected O, but got Unknown
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			AlwaysTailwind = ((BaseUnityPlugin)this).Config.Bind<bool>("1 - Features", "AlwaysTailwind", true, new ConfigDescription("While you are steering a ship, the wind always blows from behind.", (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes
				{
					Order = 3
				}
			}));
			DisableWaveDamage = ((BaseUnityPlugin)this).Config.Bind<bool>("1 - Features", "DisableWaveDamage", true, new ConfigDescription("Ships no longer take damage when slamming into waves. Capsizing and Ashlands ocean damage still apply.", (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes
				{
					Order = 2
				}
			}));
			StrongerPush = ((BaseUnityPlugin)this).Config.Bind<bool>("1 - Features", "StrongerPush", true, new ConfigDescription("Walking into a ship from outside pushes it much harder, so you can turn or launch large ships by hand.", (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes
				{
					Order = 1
				}
			}));
			HideSail = ((BaseUnityPlugin)this).Config.Bind<bool>("1 - Features", "HideSail", false, new ConfigDescription("Hide the unfurled sail of the ship you are on, so it does not block your view. Visual only; sailing speed is unchanged.", (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes
				{
					Order = 0
				}
			}));
			SailingSpeedMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("2 - Multipliers", "SailingSpeedMultiplier", 2f, new ConfigDescription("Multiplier for sailing force (half or full sail). Water drag grows with speed, so top speed rises less than this value.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 10f), new object[1]
			{
				new ConfigurationManagerAttributes
				{
					Order = 3
				}
			}));
			RowingSpeedMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("2 - Multipliers", "RowingSpeedMultiplier", 2f, new ConfigDescription("Multiplier for rowing force (paddling forward or backward). Water drag grows with speed, so top speed rises less than this value (x5 is about x3.5 top speed).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 10f), new object[1]
			{
				new ConfigurationManagerAttributes
				{
					Order = 2
				}
			}));
			ExploreRadiusMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("2 - Multipliers", "ExploreRadiusMultiplier", 2f, new ConfigDescription("Multiplier for the map exploration radius while on a ship.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 10f), new object[1]
			{
				new ConfigurationManagerAttributes
				{
					Order = 1
				}
			}));
			new Harmony("runo4.valheim.tailwindsailing").PatchAll();
			Log.LogInfo((object)"Tailwind Sailing 1.0.1 loaded.");
		}
	}
	internal sealed class ConfigurationManagerAttributes
	{
		public int? Order;
	}
	[HarmonyPatch(typeof(Character), "OnCollisionStay")]
	internal static class PushPatch
	{
		private const float PushAcceleration = 4f;

		private static void Postfix(Character __instance, Collision collision)
		{
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//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_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: 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)
			if (!Plugin.StrongerPush.Value || (Object)(object)__instance != (Object)(object)Player.m_localPlayer)
			{
				return;
			}
			Rigidbody rigidbody = collision.rigidbody;
			Ship val = (((Object)(object)rigidbody != (Object)null) ? ((Component)rigidbody).GetComponent<Ship>() : null);
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			Player localPlayer = Player.m_localPlayer;
			if (!((Object)(object)((Character)localPlayer).GetStandingOnShip() == (Object)(object)val) && !((Object)(object)localPlayer.GetControlledShip() == (Object)(object)val) && val.IsOwner())
			{
				Vector3 moveDir = ((Character)localPlayer).GetMoveDir();
				moveDir.y = 0f;
				Vector3 val2 = ((Component)val).transform.position - ((Component)localPlayer).transform.position;
				val2.y = 0f;
				if (!(((Vector3)(ref moveDir)).sqrMagnitude < 0.01f) && !(Vector3.Dot(moveDir, val2) <= 0f) && collision.contactCount != 0)
				{
					ContactPoint contact = collision.GetContact(0);
					Vector3 point = ((ContactPoint)(ref contact)).point;
					rigidbody.AddForceAtPosition(((Vector3)(ref moveDir)).normalized * (4f * rigidbody.mass), point, (ForceMode)0);
				}
			}
		}
	}
	[HarmonyPatch(typeof(Ship), "CustomFixedUpdate")]
	internal static class RowingPatch
	{
		private static void Prefix(Ship __instance, out float __state)
		{
			__state = __instance.m_backwardForce;
			__instance.m_backwardForce *= Plugin.RowingSpeedMultiplier.Value;
		}

		private static void Postfix(Ship __instance, float __state)
		{
			__instance.m_backwardForce = __state;
		}
	}
	[HarmonyPatch(typeof(Ship), "GetSailForce")]
	internal static class SailingPatch
	{
		private static void Postfix(ref Vector3 __result)
		{
			//IL_0002: 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)
			__result *= Plugin.SailingSpeedMultiplier.Value;
		}
	}
	[HarmonyPatch(typeof(Ship), "CustomFixedUpdate")]
	internal static class SailingTiltPatch
	{
		private static void Prefix(Ship __instance, out float __state)
		{
			__state = __instance.m_sailForceOffset;
			__instance.m_sailForceOffset /= Plugin.SailingSpeedMultiplier.Value;
		}

		private static void Postfix(Ship __instance, float __state)
		{
			__instance.m_sailForceOffset = __state;
		}
	}
	[HarmonyPatch(typeof(EnvMan), "GetWindDir")]
	internal static class TailwindPatch
	{
		private static void Postfix(ref Vector3 __result)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			Ship steeredShip = GetSteeredShip();
			if (!((Object)(object)steeredShip == (Object)null))
			{
				Vector3 forward = ((Component)steeredShip).transform.forward;
				forward.y = 0f;
				if (((Vector3)(ref forward)).sqrMagnitude > 0.0001f)
				{
					__result = ((Vector3)(ref forward)).normalized;
				}
			}
		}

		private static Ship GetSteeredShip()
		{
			if (!Plugin.AlwaysTailwind.Value)
			{
				return null;
			}
			Player localPlayer = Player.m_localPlayer;
			if (!((Object)(object)localPlayer != (Object)null))
			{
				return null;
			}
			return localPlayer.GetControlledShip();
		}
	}
	[HarmonyPatch(typeof(Ship), "UpdateWaterForce")]
	internal static class WaveDamagePatch
	{
		private static bool Prefix(Ship __instance, float depth, float time, ref float ___m_lastDepth, ref float ___m_lastUpdateWaterForceTime, ref float ___m_lastWaterImpactTime)
		{
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			if (!Plugin.DisableWaveDamage.Value)
			{
				return true;
			}
			float num = depth - ___m_lastDepth;
			float num2 = time - ___m_lastUpdateWaterForceTime;
			___m_lastDepth = depth;
			___m_lastUpdateWaterForceTime = time;
			float num3 = num / num2;
			if (!(num3 > 0f) && Mathf.Abs(num3) > __instance.m_minWaterImpactForce && time - ___m_lastWaterImpactTime > __instance.m_minWaterImpactInterval)
			{
				___m_lastWaterImpactTime = time;
				__instance.m_waterImpactEffect.Create(((Component)__instance).transform.position, ((Component)__instance).transform.rotation, (Transform)null, 1f, -1, default(ZDOID));
			}
			return false;
		}
	}
}

plugins/ValheimRecycle/ValheimRecycle.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("ValheimRecycle")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ValheimRecycle")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("fb50dee1-4008-48a0-a8c1-721c194137b1")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace ValheimRecycle
{
	public static class RecycleConfig
	{
		public enum TabPositions
		{
			Left,
			Middle,
			Right
		}
	}
	[HarmonyPatch(typeof(InventoryGui))]
	public class InventoryGuiPatch
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static Func<ItemData, int> <>9__5_0;

			public static Func<ItemData, int> <>9__5_1;

			public static Func<ItemData, int> <>9__8_0;

			public static Func<ItemData, int> <>9__8_1;

			public static PopupButtonCallback <>9__8_3;

			internal int <PostfixUpdateRecipeList>b__5_0(ItemData item)
			{
				return ((object)item).GetHashCode();
			}

			internal int <PostfixUpdateRecipeList>b__5_1(ItemData item)
			{
				return ((object)item).GetHashCode();
			}

			internal int <PrefixOnCraftPressed>b__8_0(ItemData item)
			{
				return ((object)item).GetHashCode();
			}

			internal int <PrefixOnCraftPressed>b__8_1(ItemData item)
			{
				return ((object)item).GetHashCode();
			}

			internal void <PrefixOnCraftPressed>b__8_3()
			{
				UnifiedPopup.Pop();
			}
		}

		internal static bool skipPopup;

		[HarmonyPostfix]
		[HarmonyPatch("Update")]
		internal static void PostfixUpdate(InventoryGui __instance)
		{
			ValheimRecycle.instance?.RebuildRecycleTab();
		}

		[HarmonyPrefix]
		[HarmonyPatch("OnTabCraftPressed")]
		internal static bool PrefixOnTabCraftPressed(InventoryGui __instance)
		{
			ValheimRecycle.IsRecycleTabActive = false;
			((Selectable)ValheimRecycle.instance.recycleButton).interactable = true;
			return true;
		}

		[HarmonyPrefix]
		[HarmonyPatch("OnTabUpgradePressed")]
		internal static bool PrefixOnTabUpgradePressed(InventoryGui __instance)
		{
			ValheimRecycle.IsRecycleTabActive = false;
			((Selectable)ValheimRecycle.instance.recycleButton).interactable = true;
			return true;
		}

		[HarmonyPostfix]
		[HarmonyPatch("SetupRequirement")]
		internal static void PostfixSetupRequirement(Transform elementRoot, Requirement req, int quality)
		{
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			if (!((Component)elementRoot).gameObject.activeSelf)
			{
				((Component)elementRoot).gameObject.SetActive(true);
			}
			if (ValheimRecycle.instance.InTabDeconstruct())
			{
				TMP_Text component = ((Component)((Component)elementRoot).transform.Find("res_amount")).GetComponent<TMP_Text>();
				component.text = Utils.GetModifiedAmount(quality, req).ToString();
				((Graphic)component).color = Color.green;
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch("UpdateCraftingPanel")]
		internal static void PostfixUpdateCraftingPanel(InventoryGui __instance, bool focusView)
		{
			if ((Object)(object)ValheimRecycle.instance == (Object)null || (Object)(object)ValheimRecycle.instance.recycleObject == (Object)null)
			{
				return;
			}
			Player localPlayer = Player.m_localPlayer;
			if (Object.op_Implicit((Object)(object)localPlayer.GetCurrentCraftingStation()) && ((Object)((Component)localPlayer.GetCurrentCraftingStation()).gameObject).name.Contains("cauldron"))
			{
				ValheimRecycle.instance.recycleObject.SetActive(false);
				if ((Object)(object)ValheimRecycle.instance.toggleEquippedObject != (Object)null)
				{
					ValheimRecycle.instance.toggleEquippedObject.SetActive(false);
				}
				((Selectable)ValheimRecycle.instance.recycleButton).interactable = true;
				if (ValheimRecycle.IsRecycleTabActive)
				{
					ValheimRecycle.IsRecycleTabActive = false;
				}
				return;
			}
			ValheimRecycle.instance.recycleObject.SetActive(((Component)__instance.m_tabUpgrade).gameObject.activeSelf);
			if (ValheimRecycle.IsRecycleTabActive)
			{
				((Selectable)__instance.m_tabUpgrade).interactable = true;
				((Selectable)__instance.m_tabCraft).interactable = true;
				((Selectable)ValheimRecycle.instance.recycleButton).interactable = false;
				if ((Object)(object)ValheimRecycle.instance.toggleEquippedObject != (Object)null)
				{
					ValheimRecycle.instance.toggleEquippedObject.SetActive(true);
				}
			}
			else
			{
				((Selectable)ValheimRecycle.instance.recycleButton).interactable = true;
				if ((Object)(object)ValheimRecycle.instance.toggleEquippedObject != (Object)null)
				{
					ValheimRecycle.instance.toggleEquippedObject.SetActive(false);
				}
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch("UpdateRecipeList")]
		internal static void PostfixUpdateRecipeList(InventoryGui __instance, List<Recipe> recipes)
		{
			//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_039a: Unknown result type (might be due to invalid IL or missing references)
			//IL_039f: Unknown result type (might be due to invalid IL or missing references)
			if (!ValheimRecycle.instance.InTabDeconstruct())
			{
				return;
			}
			Player localPlayer = Player.m_localPlayer;
			Inventory inventory = ((Humanoid)localPlayer).GetInventory();
			foreach (RecipeDataPair availableRecipe in __instance.m_availableRecipes)
			{
				RecipeDataPair current = availableRecipe;
				Object.Destroy((Object)(object)((RecipeDataPair)(ref current)).InterfaceElement);
			}
			__instance.m_availableRecipes.Clear();
			List<KeyValuePair<Recipe, ItemData>> list = new List<KeyValuePair<Recipe, ItemData>>();
			for (int i = 0; i < recipes.Count; i++)
			{
				Recipe val = recipes[i];
				if (val.m_item.m_itemData.m_shared.m_maxQuality < 1)
				{
					continue;
				}
				__instance.m_tempItemList.Clear();
				if (val.m_item.m_itemData.m_shared.m_maxStackSize == 1)
				{
					inventory.GetAllItems(val.m_item.m_itemData.m_shared.m_name, __instance.m_tempItemList);
				}
				else
				{
					for (int j = 0; j < inventory.m_inventory.Count; j++)
					{
						if (inventory.m_inventory[j].m_shared.m_name.Equals(val.m_item.m_itemData.m_shared.m_name) && inventory.m_inventory[j].m_stack >= val.m_amount)
						{
							__instance.m_tempItemList.Add(inventory.m_inventory[j]);
							break;
						}
					}
				}
				foreach (ItemData tempItem in __instance.m_tempItemList)
				{
					if (tempItem.m_quality >= 1)
					{
						list.Add(new KeyValuePair<Recipe, ItemData>(val, tempItem));
					}
				}
			}
			List<int> equipped = (from item in inventory.GetEquippedItems()
				select ((object)item).GetHashCode()).ToList();
			List<ItemData> list2 = new List<ItemData>();
			inventory.GetBoundItems(list2);
			List<int> hotbarItemsHashes = list2.Select((ItemData item) => ((object)item).GetHashCode()).ToList();
			if (!ValheimRecycle.instance.showEquippedAndHotbar.Value)
			{
				list.RemoveAll((KeyValuePair<Recipe, ItemData> x) => equipped.Contains(((object)x.Value).GetHashCode()) || hotbarItemsHashes.Contains(((object)x.Value).GetHashCode()));
			}
			list.Sort(delegate(KeyValuePair<Recipe, ItemData> a, KeyValuePair<Recipe, ItemData> b)
			{
				bool flag4 = equipped.Contains(((object)a.Value).GetHashCode()) || hotbarItemsHashes.Contains(((object)a.Value).GetHashCode());
				bool value2 = equipped.Contains(((object)b.Value).GetHashCode()) || hotbarItemsHashes.Contains(((object)b.Value).GetHashCode());
				return flag4.CompareTo(value2);
			});
			CraftingStation currentCraftingStation = localPlayer.GetCurrentCraftingStation();
			foreach (KeyValuePair<Recipe, ItemData> item in list)
			{
				Recipe key = item.Key;
				ItemData value = item.Value;
				int num = value?.m_quality ?? 1;
				CraftingStation requiredStation = key.GetRequiredStation(num);
				int requiredStationLevel = key.GetRequiredStationLevel(num);
				bool num2 = (Object)(object)requiredStation == (Object)null || ((Object)(object)currentCraftingStation != (Object)null && currentCraftingStation.CheckUsable(localPlayer, false) && currentCraftingStation.GetLevel(true) >= requiredStationLevel);
				int num3 = ((value == null) ? 1 : ((value.m_quality >= 1) ? (value.m_quality - 1) : 0));
				bool flag = Utils.HaveEmptySlotsForRecipe(inventory, key, num3 + 1);
				bool flag2 = equipped.Contains(((object)value).GetHashCode()) || hotbarItemsHashes.Contains(((object)value).GetHashCode());
				bool flag3 = (num2 || localPlayer.NoCostCheat()) && flag;
				__instance.AddRecipeToList(localPlayer, key, value, flag3);
				if (value == null || __instance.m_availableRecipes.Count <= 0)
				{
					continue;
				}
				RecipeDataPair val2 = __instance.m_availableRecipes[__instance.m_availableRecipes.Count - 1];
				Image component = ((Component)((RecipeDataPair)(ref val2)).InterfaceElement.transform.Find("icon")).GetComponent<Image>();
				if ((Object)(object)component != (Object)null)
				{
					component.sprite = value.GetIcon();
				}
				if (!flag2)
				{
					continue;
				}
				TMP_Text component2 = ((Component)((RecipeDataPair)(ref val2)).InterfaceElement.transform.Find("name")).GetComponent<TMP_Text>();
				if ((Object)(object)component2 != (Object)null)
				{
					if (equipped.Contains(((object)value).GetHashCode()))
					{
						component2.text += " <color=yellow>(Equipped)</color>";
					}
					else
					{
						component2.text += " <color=yellow>(Hotbar)</color>";
					}
				}
			}
			float num4 = (float)__instance.m_availableRecipes.Count * __instance.m_recipeListSpace;
			num4 = Mathf.Max(__instance.m_recipeListBaseSize, num4);
			__instance.m_recipeListRoot.SetSizeWithCurrentAnchors((Axis)1, num4);
		}

		[HarmonyPostfix]
		[HarmonyPatch("UpdateRecipe")]
		internal static void PostfixUpdateRecipe(InventoryGui __instance, Player player, float dt)
		{
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			if (ValheimRecycle.instance.InTabDeconstruct() && Object.op_Implicit((Object)(object)((RecipeDataPair)(ref __instance.m_selectedRecipe)).Recipe))
			{
				ItemData itemData = ((RecipeDataPair)(ref __instance.m_selectedRecipe)).ItemData;
				int num = ((itemData == null) ? 1 : ((itemData.m_quality >= 1) ? (itemData.m_quality - 1) : 0));
				bool flag = num <= ((RecipeDataPair)(ref __instance.m_selectedRecipe)).Recipe.m_item.m_itemData.m_shared.m_maxQuality;
				bool flag2 = Utils.HaveEmptySlotsForRecipe(((Humanoid)player).GetInventory(), ((RecipeDataPair)(ref __instance.m_selectedRecipe)).Recipe, num + 1);
				CraftingStation currentCraftingStation = player.GetCurrentCraftingStation();
				int num2 = itemData?.m_quality ?? 1;
				CraftingStation requiredStation = ((RecipeDataPair)(ref __instance.m_selectedRecipe)).Recipe.GetRequiredStation(num2);
				int requiredStationLevel = ((RecipeDataPair)(ref __instance.m_selectedRecipe)).Recipe.GetRequiredStationLevel(num2);
				bool flag3 = (Object)(object)requiredStation == (Object)null || ((Object)(object)currentCraftingStation != (Object)null && currentCraftingStation.CheckUsable(player, false) && currentCraftingStation.GetLevel(true) >= requiredStationLevel);
				if ((Object)(object)requiredStation != (Object)null && flag)
				{
					((Component)__instance.m_minStationLevelIcon).gameObject.SetActive(true);
					__instance.m_minStationLevelText.text = requiredStationLevel.ToString();
					if ((Object)(object)currentCraftingStation == (Object)null || currentCraftingStation.GetLevel(true) < requiredStationLevel)
					{
						((Graphic)__instance.m_minStationLevelText).color = ((Mathf.Sin(Time.time * 10f) > 0f) ? Color.red : __instance.m_minStationLevelBasecolor);
					}
					else
					{
						((Graphic)__instance.m_minStationLevelText).color = __instance.m_minStationLevelBasecolor;
					}
				}
				else
				{
					((Component)__instance.m_minStationLevelIcon).gameObject.SetActive(false);
				}
				if (itemData != null && itemData.m_quality == 1)
				{
					((Behaviour)__instance.m_recipeDecription).enabled = false;
				}
				string text = Localization.instance.Localize(((RecipeDataPair)(ref __instance.m_selectedRecipe)).Recipe.m_item.m_itemData.m_shared.m_name);
				if (((RecipeDataPair)(ref __instance.m_selectedRecipe)).Recipe.m_amount > 1)
				{
					text = text + " x" + ((RecipeDataPair)(ref __instance.m_selectedRecipe)).Recipe.m_amount;
				}
				__instance.m_recipeName.text = text;
				if (itemData != null)
				{
					((Component)__instance.m_itemCraftType).gameObject.SetActive(true);
					if (itemData.m_quality <= 1)
					{
						__instance.m_itemCraftType.text = "Item will be recycled";
					}
					else
					{
						string text2 = Localization.instance.Localize(itemData.m_shared.m_name);
						__instance.m_itemCraftType.text = "Downgrade " + text2 + " quality to " + (itemData.m_quality - 1);
					}
				}
				Recipe recipe = ((RecipeDataPair)(ref __instance.m_selectedRecipe)).Recipe;
				Requirement[] resources = recipe.m_resources;
				List<Requirement> list = new List<Requirement>();
				bool flag4 = false;
				Requirement[] array = resources;
				foreach (Requirement val in array)
				{
					if (!val.m_upgraderResource && !(recipe.m_requireOnlyOneIngredient && flag4))
					{
						list.Add(val);
						flag4 = true;
					}
				}
				recipe.m_resources = list.ToArray();
				__instance.SetupRequirementList(num + 1, player, flag, 1);
				recipe.m_resources = resources;
				((Selectable)__instance.m_craftButton).interactable = (flag3 || player.NoCostCheat()) && flag2 && flag;
				((Component)__instance.m_craftButton).GetComponentInChildren<TMP_Text>().text = "Recycle";
				TMP_Text componentInChildren = ((Component)__instance.m_craftProgressPanel).GetComponentInChildren<TMP_Text>();
				if ((Object)(object)componentInChildren != (Object)null)
				{
					componentInChildren.text = "Recycling...";
				}
				UITooltip component = ((Component)__instance.m_craftButton).GetComponent<UITooltip>();
				if (!flag2)
				{
					component.m_text = Localization.instance.Localize("$inventory_full");
				}
				else if (!flag3)
				{
					if ((Object)(object)currentCraftingStation != (Object)null && currentCraftingStation.CheckUsable(player, false) && currentCraftingStation.GetLevel(true) < requiredStationLevel)
					{
						component.m_text = "Workstation level too low";
					}
					else
					{
						component.m_text = Localization.instance.Localize("$msg_missingstation");
					}
				}
				else
				{
					component.m_text = "";
				}
			}
			else if ((Object)(object)__instance.m_craftProgressPanel != (Object)null)
			{
				TMP_Text componentInChildren2 = ((Component)__instance.m_craftProgressPanel).GetComponentInChildren<TMP_Text>();
				if ((Object)(object)componentInChildren2 != (Object)null && componentInChildren2.text == "Recycling...")
				{
					componentInChildren2.text = Localization.instance.Localize("$inventory_crafting");
				}
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch("OnCraftPressed")]
		internal static bool PrefixOnCraftPressed(InventoryGui __instance)
		{
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Expected O, but got Unknown
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Expected O, but got Unknown
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Expected O, but got Unknown
			if (ValheimRecycle.instance.InTabDeconstruct() && !skipPopup)
			{
				if ((Object)(object)((RecipeDataPair)(ref __instance.m_selectedRecipe)).Recipe == (Object)null || ((RecipeDataPair)(ref __instance.m_selectedRecipe)).ItemData == null)
				{
					return true;
				}
				Player localPlayer = Player.m_localPlayer;
				ItemData itemData = ((RecipeDataPair)(ref __instance.m_selectedRecipe)).ItemData;
				List<int> list = (from item in ((Humanoid)localPlayer).GetInventory().GetEquippedItems()
					select ((object)item).GetHashCode()).ToList();
				List<ItemData> list2 = new List<ItemData>();
				((Humanoid)localPlayer).GetInventory().GetBoundItems(list2);
				List<int> list3 = list2.Select((ItemData item) => ((object)item).GetHashCode()).ToList();
				if (list.Contains(((object)itemData).GetHashCode()) || list3.Contains(((object)itemData).GetHashCode()))
				{
					PopupButtonCallback val = delegate
					{
						skipPopup = true;
						((UnityEvent)__instance.m_craftButton.onClick).Invoke();
						skipPopup = false;
						UnifiedPopup.Pop();
					};
					object obj = <>c.<>9__8_3;
					if (obj == null)
					{
						PopupButtonCallback val2 = delegate
						{
							UnifiedPopup.Pop();
						};
						<>c.<>9__8_3 = val2;
						obj = (object)val2;
					}
					UnifiedPopup.Push((PopupBase)new YesNoPopup("Recycle Item", "This item is currently equipped or in your hotbar.\nAre you sure you want to recycle it?", val, (PopupButtonCallback)obj, false, false));
					return false;
				}
			}
			return true;
		}

		[HarmonyPrefix]
		[HarmonyPatch("DoCrafting")]
		internal static bool PrefixDoCrafting(InventoryGui __instance, Player player)
		{
			if (ValheimRecycle.instance.InTabDeconstruct())
			{
				Utils.DoRecycle(player, __instance);
				return false;
			}
			return true;
		}
	}
	public class Utils
	{
		public static int GetModifiedAmount(int quality, Requirement requirement)
		{
			return (int)Math.Round(ValheimRecycle.instance.resourceMultiplier.Value * (float)requirement.GetAmount(quality), 0);
		}

		public static bool HaveEmptySlotsForRecipe(Inventory inventory, Recipe recipe, int quality)
		{
			int emptySlots = inventory.GetEmptySlots();
			int num = 0;
			Requirement[] resources = recipe.m_resources;
			foreach (Requirement val in resources)
			{
				if (!Object.op_Implicit((Object)(object)val.m_resItem) || val.m_upgraderResource)
				{
					continue;
				}
				int modifiedAmount = GetModifiedAmount(quality, val);
				if (modifiedAmount > 0)
				{
					int num2 = inventory.FindFreeStackSpace(val.m_resItem.m_itemData.m_shared.m_name, (float)val.m_resItem.m_itemData.m_worldLevel);
					int num3 = Mathf.Max(0, modifiedAmount - num2);
					if (num3 > 0)
					{
						int maxStackSize = val.m_resItem.m_itemData.m_shared.m_maxStackSize;
						num += Mathf.CeilToInt((float)num3 / (float)maxStackSize);
					}
				}
				if (recipe.m_requireOnlyOneIngredient)
				{
					break;
				}
			}
			return emptySlots >= num;
		}

		public static void AddResources(Inventory inventory, Recipe recipe, int qualityLevel)
		{
			Requirement[] resources = recipe.m_resources;
			foreach (Requirement val in resources)
			{
				if (Object.op_Implicit((Object)(object)val.m_resItem) && !val.m_upgraderResource)
				{
					int modifiedAmount = GetModifiedAmount(qualityLevel + 1, val);
					if (modifiedAmount > 0)
					{
						Debug.Log((object)("Adding item: " + ((Object)val.m_resItem).name));
						Debug.Log((object)("Amount: " + val.GetAmount(qualityLevel + 1)));
						inventory.AddItem(((Object)val.m_resItem).name, modifiedAmount, val.m_resItem.m_itemData.m_quality, val.m_resItem.m_itemData.m_variant, 0L, "", false, false);
					}
					if (recipe.m_requireOnlyOneIngredient)
					{
						break;
					}
				}
			}
		}

		internal static void DoRecycle(Player player, InventoryGui __instance)
		{
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: 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_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)__instance.m_craftRecipe == (Object)null)
			{
				return;
			}
			int num = ((__instance.m_craftUpgradeItem != null) ? (__instance.m_craftUpgradeItem.m_quality - 1) : 0);
			if ((__instance.m_craftUpgradeItem != null && !((Humanoid)player).GetInventory().ContainsItem(__instance.m_craftUpgradeItem)) || (__instance.m_craftUpgradeItem == null && HaveEmptySlotsForRecipe(((Humanoid)player).GetInventory(), __instance.m_craftRecipe, num + 1)))
			{
				return;
			}
			int variant = __instance.m_craftUpgradeItem.m_variant;
			long playerID = player.GetPlayerID();
			string playerName = player.GetPlayerName();
			if (__instance.m_craftUpgradeItem != null)
			{
				if (num >= 1)
				{
					((Humanoid)player).UnequipItem(__instance.m_craftUpgradeItem, true);
					if (ValheimRecycle.instance.preserveOriginalItem.Value)
					{
						__instance.m_craftUpgradeItem.m_quality = num;
					}
					else
					{
						((Humanoid)player).GetInventory().RemoveItem(__instance.m_craftUpgradeItem);
						((Humanoid)player).GetInventory().AddItem(((Object)((Component)__instance.m_craftRecipe.m_item).gameObject).name, __instance.m_craftRecipe.m_amount, num, variant, playerID, playerName, false, false);
					}
				}
				else
				{
					((Humanoid)player).UnequipItem(__instance.m_craftUpgradeItem, true);
					((Humanoid)player).GetInventory().RemoveItem(__instance.m_craftUpgradeItem, __instance.m_craftRecipe.m_amount);
				}
			}
			AddResources(((Humanoid)player).GetInventory(), __instance.m_craftRecipe, num);
			__instance.UpdateCraftingPanel(true);
			CraftingStation currentCraftingStation = Player.m_localPlayer.GetCurrentCraftingStation();
			if (Object.op_Implicit((Object)(object)currentCraftingStation))
			{
				currentCraftingStation.m_craftItemDoneEffects.Create(((Component)player).transform.position, Quaternion.identity, (Transform)null, 1f, -1, default(ZDOID));
			}
			else
			{
				__instance.m_craftItemDoneEffects.Create(((Component)player).transform.position, Quaternion.identity, (Transform)null, 1f, -1, default(ZDOID));
			}
		}
	}
	[BepInPlugin("org.lafchi.plugins.valheim_recycle", "Valheim Recycle", "5.0.6")]
	[BepInProcess("valheim.exe")]
	public class ValheimRecycle : BaseUnityPlugin
	{
		internal static ValheimRecycle instance;

		internal GameObject recycleObject;

		internal Button recycleButton;

		internal GameObject toggleEquippedObject;

		internal Button toggleEquippedButton;

		internal float width;

		private Vector3 craftingPos;

		private Harmony harmony;

		internal ConfigEntry<RecycleConfig.TabPositions> tabPosition;

		internal ConfigEntry<float> resourceMultiplier;

		internal ConfigEntry<bool> preserveOriginalItem;

		internal ConfigEntry<int> nexusID;

		internal ConfigEntry<bool> showEquippedAndHotbar;

		internal static bool IsRecycleTabActive;

		internal bool InTabDeconstruct()
		{
			return IsRecycleTabActive;
		}

		internal void Awake()
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Expected O, but got Unknown
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Expected O, but got Unknown
			((BaseUnityPlugin)this).Logger.LogInfo((object)"AWAKE - ValheimRecycle 5.0.6");
			instance = this;
			harmony = new Harmony("org.lafchi.plugins.valheim_recycle");
			harmony.PatchAll();
			tabPosition = ((BaseUnityPlugin)this).Config.Bind<RecycleConfig.TabPositions>("General", "TabPosition", RecycleConfig.TabPositions.Left, "The Recycle tab's position in the crafting menu after Upgrade. (Requires restart)");
			resourceMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("General", "ResourceMultiplier", 1f, new ConfigDescription("The amount of resources to return from recycling (0 to 1, where 1 returns 100% of the resources and 0 returns 0%)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			preserveOriginalItem = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "PreserveOriginalItem", true, "Whether the original item's data should be preserved when downgrading. Useful for mods which add extra properties to items like EpicLoot.\nTurn off if experiencing problems.");
			nexusID = ((BaseUnityPlugin)this).Config.Bind<int>("General", "NexusID", 425, "Nexus mod ID for updates");
			showEquippedAndHotbar = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ShowEquippedAndHotbar", true, "Whether to show equipped and hotbar items in the recycle list.");
		}

		internal void OnDestroy()
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"DESTROY");
			Object.Destroy((Object)(object)recycleObject);
			harmony.UnpatchSelf();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Unpatched InventoryGui");
		}

		internal GameObject GetOrCreateRecycleTab()
		{
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Expected O, but got Unknown
			//IL_019d: 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_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Expected O, but got Unknown
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ad: Expected O, but got Unknown
			//IL_02bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c9: Expected O, but got Unknown
			//IL_02e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0302: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)instance.recycleObject != (Object)null)
			{
				return instance.recycleObject;
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)"CreateRecycleButton");
			recycleObject = Object.Instantiate<GameObject>(((Component)InventoryGui.instance.m_tabUpgrade).gameObject, ((Component)InventoryGui.instance.m_tabUpgrade).gameObject.transform.parent, false);
			if (recycleObject == null)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"RecycletButton couldn't be instantiated.");
				return null;
			}
			((Object)recycleObject).name = "Recycle";
			recycleObject.GetComponentInChildren<TMP_Text>().text = "RECYCLE";
			Rect rect = recycleObject.GetComponent<RectTransform>().rect;
			width = ((Rect)(ref rect)).width;
			float num = ((Component)InventoryGui.instance.m_tabUpgrade).transform.localPosition.x;
			foreach (Transform item in ((Component)InventoryGui.instance.m_tabUpgrade).transform.parent)
			{
				Transform val = item;
				if (!((Object)(object)val == (Object)(object)recycleObject.transform) && ((Component)val).gameObject.activeSelf && (Object)(object)((Component)val).GetComponent<Button>() != (Object)null)
				{
					num = Mathf.Max(num, val.localPosition.x);
				}
			}
			float num2 = (float)tabPosition.Value * (width + 10f);
			craftingPos = new Vector3(num + width + 10f + num2, ((Component)InventoryGui.instance.m_tabUpgrade).transform.localPosition.y, ((Component)InventoryGui.instance.m_tabUpgrade).transform.localPosition.z);
			recycleButton = recycleObject.GetComponent<Button>();
			((UnityEventBase)recycleButton.onClick).RemoveAllListeners();
			((UnityEvent)recycleButton.onClick).AddListener(new UnityAction(SelectRecycleTab));
			((Component)recycleButton).transform.localPosition = craftingPos;
			((Selectable)recycleButton).interactable = true;
			((Object)recycleButton).name = "RecycleButton";
			recycleObject.SetActive(false);
			if ((Object)(object)toggleEquippedObject == (Object)null)
			{
				toggleEquippedObject = Object.Instantiate<GameObject>(recycleObject, ((Component)InventoryGui.instance.m_craftButton).transform.parent, false);
				((Object)toggleEquippedObject).name = "ToggleEquipped";
				toggleEquippedButton = toggleEquippedObject.GetComponent<Button>();
				toggleEquippedButton.onClick = new ButtonClickedEvent();
				((UnityEvent)toggleEquippedButton.onClick).AddListener(new UnityAction(ToggleEquipped));
				toggleEquippedObject.transform.localPosition = new Vector3(140f, -45f, 0f);
				toggleEquippedObject.GetComponent<RectTransform>().sizeDelta = new Vector2(160f, 30f);
			}
			UpdateToggleText();
			toggleEquippedObject.SetActive(false);
			return recycleObject;
		}

		internal void SelectRecycleTab()
		{
			((BaseUnityPlugin)this).Logger.LogDebug((object)"Selected recycle");
			IsRecycleTabActive = true;
			((Selectable)recycleButton).interactable = false;
			((Selectable)InventoryGui.m_instance.m_tabCraft).interactable = true;
			((Selectable)InventoryGui.m_instance.m_tabUpgrade).interactable = true;
			InventoryGui.m_instance.UpdateCraftingPanel(false);
		}

		internal void ToggleEquipped()
		{
			showEquippedAndHotbar.Value = !showEquippedAndHotbar.Value;
			((BaseUnityPlugin)this).Config.Save();
			UpdateToggleText();
			InventoryGui.m_instance.UpdateCraftingPanel(false);
		}

		internal void UpdateToggleText()
		{
			if ((Object)(object)toggleEquippedObject != (Object)null)
			{
				TMP_Text componentInChildren = toggleEquippedObject.GetComponentInChildren<TMP_Text>();
				if ((Object)(object)componentInChildren != (Object)null)
				{
					componentInChildren.text = (showEquippedAndHotbar.Value ? "[X] Include Equipped" : "[ ] Include Equipped");
					componentInChildren.fontSize = 16f;
					componentInChildren.alignment = (TextAlignmentOptions)516;
				}
			}
		}

		internal void RebuildRecycleTab()
		{
			GetOrCreateRecycleTab();
		}
	}
}
namespace ValheimRecycle.GameClasses
{
	[HarmonyPatch(typeof(Humanoid))]
	internal class HumanoidPatch
	{
		[HarmonyPatch("EquipItem")]
		[HarmonyPostfix]
		private static void EquipItem(Humanoid __instance, ItemData item, bool triggerEquipEffects = true)
		{
			if (((Character)__instance).IsPlayer())
			{
				InventoryGui instance = InventoryGui.instance;
				if (instance != null)
				{
					instance.UpdateCraftingPanel(false);
				}
			}
		}

		[HarmonyPatch("UnequipItem")]
		[HarmonyPostfix]
		private static void UnequipItem(Humanoid __instance, ItemData item, bool triggerEquipEffects = true)
		{
			if (((Character)__instance).IsPlayer())
			{
				InventoryGui instance = InventoryGui.instance;
				if (instance != null)
				{
					instance.UpdateCraftingPanel(false);
				}
			}
		}
	}
}

plugins/VeinMining/VeinMining.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.InputSystem.LowLevel;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyCompany("LL")]
[assembly: AssemblyVersion("1.0.8.0")]
[BepInPlugin("local.valheim.veinmining", "VeinMining", "1.0.8")]
[BepInIncompatibility("com.wisehorror.Veinmine")]
public sealed class VeinMining : BaseUnityPlugin
{
	private sealed class DropContext
	{
		public Component Rock;

		public Player Player;

		public bool Located;

		public bool HasPosition;

		public Vector3 Position;

		public long Sender;
	}

	private sealed class Part
	{
		public int Index;

		public Collider Collider;

		public float Distance;
	}

	private sealed class NodeIntent
	{
		public Component Rock;

		public HitData Hit;

		public int Primary;

		public float Time;
	}

	private sealed class NodeState
	{
		public Component Rock;

		public HitData Hit;

		public long Sender;

		public int Anchor;

		public DropContext Previous;

		public bool NativeHit;
	}

	private sealed class Intent
	{
		public Destructible Rock;

		public HitData Hit;

		public long Sender;

		public float Time;
	}

	private const string Rpc = "LL_VeinMining_109_Extra";

	private const string NodePrepareRpc = "LL_VeinMining_109_PrepareNode";

	private const string AnchorKey = "LL.VeinMining.SharedSection.v1";

	private const string PendingKey = "LL.VeinMining.FinishPending.v1";

	private const string PrepareRpc = "LL_VeinMining_109_Prepare";

	private static VeinMining self;

	private static ConfigEntry<bool> always;

	private static ConfigEntry<bool> nearPlayer;

	private static ConfigEntry<bool> verbose;

	private static ConfigEntry<bool> breakTogether;

	private static ConfigEntry<KeyCode> key;

	private static ConfigEntry<int> limit;

	private static Harmony harmony;

	private static DropContext context;

	private static readonly Dictionary<int, float> recent = new Dictionary<int, float>();

	private static readonly Dictionary<string, float> received = new Dictionary<string, float>();

	private static readonly FieldInfo areas5 = AccessTools.Field(typeof(MineRock5), "m_hitAreas");

	private static readonly FieldInfo areas1 = AccessTools.Field(typeof(MineRock), "m_hitAreas");

	private static readonly MethodInfo hit5 = AccessTools.Method(typeof(MineRock5), "RPC_Damage", (Type[])null, (Type[])null);

	private static readonly MethodInfo hit1 = AccessTools.Method(typeof(MineRock), "RPC_Hit", (Type[])null, (Type[])null);

	private static readonly MethodInfo load5 = AccessTools.Method(typeof(MineRock5), "LoadHealth", (Type[])null, (Type[])null);

	private static readonly MethodInfo mesh5 = AccessTools.Method(typeof(MineRock5), "UpdateMesh", (Type[])null, (Type[])null);

	private static float lastWarning = -100f;

	private static readonly Dictionary<string, NodeIntent> nodeIntents = new Dictionary<string, NodeIntent>();

	private static readonly Dictionary<int, Intent> intents = new Dictionary<int, Intent>();

	private static readonly HashSet<int> unknown = new HashSet<int>();

	private static readonly Collider[] hitCandidates = (Collider[])(object)new Collider[128];

	private static readonly Dictionary<string, float> diagnosticTimes = new Dictionary<string, float>();

	private static readonly Dictionary<int, string> catalog = MakeCatalog();

	private void Awake()
	{
		//IL_0135: Unknown result type (might be due to invalid IL or missing references)
		//IL_013f: Expected O, but got Unknown
		//IL_014f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0155: Expected O, but got Unknown
		//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c9: Expected O, but got Unknown
		//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0203: Expected O, but got Unknown
		//IL_0272: Unknown result type (might be due to invalid IL or missing references)
		//IL_0280: Expected O, but got Unknown
		self = this;
		try
		{
			string text = Path.Combine(Paths.ConfigPath, "VeinMining.cfg");
			string text2 = Path.Combine(Paths.ConfigPath, "local.valheim.veinmining.cfg");
			if (!File.Exists(text) && File.Exists(text2))
			{
				File.Copy(text2, text);
			}
			ConfigFile val = PluginConfig.Attach((BaseUnityPlugin)(object)this, text);
			always = val.Bind<bool>("General", "AlwaysEnabled", false, "Vein mine without holding an activation button.");
			key = val.Bind<KeyCode>("General", "ActivationKey", (KeyCode)308, "Hold until the pickaxe hits.");
			nearPlayer = val.Bind<bool>("Drops", "NearPlayer", true, "Group vein-mined drops near the attacker when safe ground is found. BreakTogether includes the finishing primary hit. Legacy mode keeps native primary placement. Install the same version and settings on all peers.");
			limit = PluginConfig.BindLimit(val);
			breakTogether = PluginConfig.BindTogether(val);
			verbose = val.Bind<bool>("Diagnostics", "VerboseLogging", false, "Log successful activation and owner processing as well as rate-limited fallback reasons. Enable on all peers when investigating a report.");
			VeinMinerControllerInput.Initialize(val);
			val.Save();
			if (areas5 == null || areas1 == null || hit5 == null || hit1 == null || load5 == null || mesh5 == null)
			{
				throw new MissingMemberException("Mining API changed");
			}
			harmony = new Harmony("local.valheim.veinmining");
			HarmonyMethod val2 = new HarmonyMethod(typeof(VeinMining), "DropTranspiler", (Type[])null);
			harmony.Patch((MethodBase)AccessTools.Method(typeof(MineRock5), "DamageArea", (Type[])null, (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, val2, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)hit1, (HarmonyMethod)null, (HarmonyMethod)null, val2, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)AccessTools.Method(typeof(MineRock5), "Awake", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(VeinMining), "Register", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)AccessTools.Method(typeof(MineRock), "Start", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(VeinMining), "Register", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			Type[] array = new Type[2]
			{
				typeof(MineRock5),
				typeof(MineRock)
			};
			foreach (Type type in array)
			{
				harmony.Patch((MethodBase)AccessTools.Method(type, "Damage", new Type[1] { typeof(HitData) }, (Type[])null), new HarmonyMethod(typeof(VeinMining), "BeforeDamage", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
			PatchShellSupport();
			PatchTogether();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"VeinMining 1.0.8 by LL loaded. Config: VeinMining.cfg. Hold LeftAlt or L3. Install the same version on all players and the server.");
		}
		catch (Exception ex)
		{
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			self = null;
			((BaseUnityPlugin)this).Logger.LogError((object)("VeinMining disabled; normal mining remains available. " + ex));
		}
	}

	private void OnDestroy()
	{
		if (harmony != null)
		{
			harmony.UnpatchSelf();
		}
		recent.Clear();
		received.Clear();
		intents.Clear();
		nodeIntents.Clear();
		unknown.Clear();
		diagnosticTimes.Clear();
		context = null;
		self = null;
	}

	private static void Register(Component __instance)
	{
		try
		{
			if (!Supported(__instance))
			{
				DiagnoseUnknown(__instance);
				return;
			}
			ZNetView component = __instance.GetComponent<ZNetView>();
			if ((Object)(object)component == (Object)null || !component.IsValid())
			{
				return;
			}
			component.Register<HitData, int>("LL_VeinMining_109_Extra", (Action<long, HitData, int>)delegate(long sender, HitData hit, int primary)
			{
				try
				{
					Receive(__instance, sender, hit, primary);
				}
				catch (Exception ex2)
				{
					Warn("Extra request rejected: " + ex2.Message);
				}
			});
			component.Register<HitData, int>("LL_VeinMining_109_PrepareNode", (Action<long, HitData, int>)delegate(long sender, HitData hit, int primary)
			{
				try
				{
					PrepareNode(__instance, sender, hit, primary);
				}
				catch (Exception ex2)
				{
					Warn("Node preparation rejected: " + ex2.Message);
				}
			});
		}
		catch (Exception ex)
		{
			Warn("Extra mining unavailable on this deposit: " + ex.Message);
		}
	}

	private static bool BeforeDamage(Component __instance, HitData hit)
	{
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		bool flag = false;
		try
		{
			if ((Object)(object)self == (Object)null || hit == null || !Finite(hit.m_damage.m_pickaxe) || hit.m_damage.m_pickaxe <= 0f || (Object)(object)Player.m_localPlayer == (Object)null || (Object)(object)hit.GetAttacker() != (Object)(object)Player.m_localPlayer || (!always.Value && !VeinMinerControllerInput.Held(key.Value)))
			{
				return true;
			}
			if (!Supported(__instance))
			{
				Diagnostic(__instance, "unsupported-target", detail: false);
				return true;
			}
			ZNetView component = __instance.GetComponent<ZNetView>();
			if ((Object)(object)component == (Object)null || !component.IsValid())
			{
				return true;
			}
			IList list = (IList)((__instance is MineRock5) ? areas5 : areas1).GetValue(__instance);
			if (list == null)
			{
				return true;
			}
			int num = ResolvePrimary(__instance, list, hit);
			if (num < 0)
			{
				Diagnostic(__instance, "no-matching-hit-area", detail: false);
				return true;
			}
			Diagnostic(__instance, "resolved-hit-area", detail: true);
			int instanceID = ((Object)__instance).GetInstanceID();
			if (recent.TryGetValue(instanceID, out var value) && Time.time - value >= 0f && Time.time - value < 0.15f)
			{
				return false;
			}
			if (recent.Count > 256)
			{
				recent.Clear();
			}
			recent[instanceID] = Time.time;
			HitData val = hit.Clone();
			val.m_radius = 0f;
			if (TogetherEnabled())
			{
				component.InvokeRPC("LL_VeinMining_109_PrepareNode", new object[2]
				{
					hit.Clone(),
					num
				});
				flag = true;
				component.InvokeRPC((__instance is MineRock5) ? "RPC_Damage" : "Hit", new object[2] { val, num });
				return false;
			}
			flag = true;
			component.InvokeRPC((__instance is MineRock5) ? "RPC_Damage" : "Hit", new object[2] { val, num });
			if ((Object)(object)component != (Object)null && component.IsValid())
			{
				component.InvokeRPC("LL_VeinMining_109_Extra", new object[2]
				{
					hit.Clone(),
					num
				});
			}
			return false;
		}
		catch (Exception ex)
		{
			Warn("Mining dispatch: " + ex.Message);
			return !flag;
		}
	}

	private static bool Finite(float value)
	{
		if (!float.IsNaN(value))
		{
			return !float.IsInfinity(value);
		}
		return false;
	}

	private static Collider AreaCollider(object area, bool modern)
	{
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Expected O, but got Unknown
		if (area == null)
		{
			return null;
		}
		if (!modern)
		{
			return (Collider)((area is Collider) ? area : null);
		}
		return (Collider)AccessTools.Field(area.GetType(), "m_collider").GetValue(area);
	}

	private static void Warn(string text)
	{
		if ((Object)(object)self != (Object)null && (Time.time - lastWarning > 10f || Time.time < lastWarning))
		{
			lastWarning = Time.time;
			((BaseUnityPlugin)self).Logger.LogWarning((object)text);
		}
	}

	private static void Receive(Component rock, long sender, HitData hit, int primary)
	{
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cc: 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_0263: Unknown result type (might be due to invalid IL or missing references)
		//IL_026a: Expected O, but got Unknown
		//IL_02dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_02eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0474: Unknown result type (might be due to invalid IL or missing references)
		//IL_0479: Unknown result type (might be due to invalid IL or missing references)
		//IL_047d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0482: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)self == (Object)null || (Object)(object)rock == (Object)null || !Supported(rock) || hit == null || !Finite(hit.m_damage.m_pickaxe) || hit.m_damage.m_pickaxe <= 0f)
		{
			return;
		}
		ZNetView component = rock.GetComponent<ZNetView>();
		Character attacker = hit.GetAttacker();
		Player val = (Player)(object)((attacker is Player) ? attacker : null);
		if ((Object)(object)component == (Object)null || !component.IsValid() || !component.IsOwner() || (Object)(object)val == (Object)null)
		{
			Diagnostic(rock, "extra-invalid-owner-or-attacker", detail: false);
			return;
		}
		ZNetView component2 = ((Component)val).GetComponent<ZNetView>();
		if ((Object)(object)component2 == (Object)null || !component2.IsValid() || component2.GetZDO().GetOwner() != sender)
		{
			Diagnostic(rock, "extra-sender-mismatch", detail: false);
			return;
		}
		Vector3 val2 = ((Component)val).transform.position - hit.m_point;
		float sqrMagnitude = ((Vector3)(ref val2)).sqrMagnitude;
		if (!Finite(sqrMagnitude) || sqrMagnitude > 100f)
		{
			Diagnostic(rock, "extra-outside-attacker-range", detail: false);
			return;
		}
		string text = ((Object)rock).GetInstanceID() + ":" + sender;
		if (received.TryGetValue(text, out var value) && Time.time - value >= 0f && Time.time - value < 0.15f)
		{
			return;
		}
		if (received.Count > 512)
		{
			received.Clear();
		}
		received[text] = Time.time;
		Diagnostic(rock, "owner-processing-extra-sections", detail: true);
		DropContext dropContext = context;
		try
		{
			bool flag = rock is MineRock5;
			if (flag)
			{
				load5.Invoke(rock, null);
			}
			IList list = (IList)(flag ? areas5 : areas1).GetValue(rock);
			if (list == null || primary < 0 || primary >= list.Count)
			{
				Diagnostic(rock, "extra-invalid-area-index", detail: false);
				return;
			}
			List<Part> list2 = new List<Part>();
			for (int i = 0; i < list.Count; i++)
			{
				if (i == primary)
				{
					continue;
				}
				object obj = list[i];
				if (obj == null)
				{
					continue;
				}
				Collider val3 = (Collider)((obj is Collider) ? obj : null);
				if (flag)
				{
					Type type = obj.GetType();
					float num = (float)AccessTools.Field(type, "m_health").GetValue(obj);
					if (!Finite(num) || num <= 0f)
					{
						continue;
					}
					val3 = (Collider)AccessTools.Field(type, "m_collider").GetValue(obj);
				}
				if (!((Object)(object)val3 == (Object)null) && val3.enabled && ((Component)val3).gameObject.activeInHierarchy && (flag || !(component.GetZDO().GetFloat("Health" + i, 1f) <= 0f)))
				{
					Part part = new Part
					{
						Index = i,
						Collider = val3
					};
					Bounds bounds = val3.bounds;
					Vector3 val4 = ((Bounds)(ref bounds)).center - hit.m_point;
					part.Distance = ((Vector3)(ref val4)).sqrMagnitude;
					list2.Add(part);
				}
			}
			list2.Sort((Part a, Part b) => a.Distance.CompareTo(b.Distance));
			DropContext dropContext3;
			if (dropContext == null || !((Object)(object)dropContext.Rock == (Object)(object)rock) || !((Object)(object)dropContext.Player == (Object)(object)val))
			{
				DropContext dropContext2 = new DropContext();
				dropContext2.Rock = rock;
				dropContext2.Player = val;
				dropContext2.Sender = sender;
				dropContext3 = dropContext2;
			}
			else
			{
				dropContext3 = dropContext;
			}
			context = dropContext3;
			int num2 = ((limit.Value == 0) ? list2.Count : Math.Max(0, Math.Min(128, limit.Value) - 1));
			int num3 = 0;
			for (int num4 = 0; num4 < list2.Count; num4++)
			{
				if (num3 >= num2)
				{
					break;
				}
				if ((Object)(object)rock == (Object)null)
				{
					break;
				}
				if ((Object)(object)component == (Object)null)
				{
					break;
				}
				if (!component.IsValid())
				{
					break;
				}
				if (!component.IsOwner())
				{
					break;
				}
				Part part2 = list2[num4];
				if (!((Object)(object)part2.Collider == (Object)null) && part2.Collider.enabled && ((Component)part2.Collider).gameObject.activeInHierarchy && !(SectionHealth(rock, part2.Index) <= 0f))
				{
					HitData val5 = hit.Clone();
					val5.m_hitCollider = part2.Collider;
					Bounds bounds2 = part2.Collider.bounds;
					val5.m_point = ((Bounds)(ref bounds2)).center;
					val5.m_radius = 0f;
					num3++;
					(flag ? hit5 : hit1).Invoke(rock, new object[3] { sender, val5, part2.Index });
				}
			}
		}
		catch (Exception ex)
		{
			Warn("Extra mining interrupted; no damage retry. " + ex);
		}
		finally
		{
			context = dropContext;
			if (rock is MineRock5 && (Object)(object)component != (Object)null && component.IsValid() && component.IsOwner())
			{
				try
				{
					load5.Invoke(rock, null);
					mesh5.Invoke(rock, null);
				}
				catch (Exception ex2)
				{
					Warn("Could not refresh rock mesh: " + ex2.Message);
				}
			}
		}
	}

	private static IEnumerable<CodeInstruction> DropTranspiler(IEnumerable<CodeInstruction> original)
	{
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: Expected O, but got Unknown
		List<CodeInstruction> list = new List<CodeInstruction>(original);
		int num = 0;
		for (int i = 0; i < list.Count; i++)
		{
			MethodInfo methodInfo = list[i].operand as MethodInfo;
			if (!(methodInfo == null) && !(methodInfo.DeclaringType != typeof(Object)) && !(methodInfo.Name != "Instantiate") && methodInfo.IsGenericMethod && !(methodInfo.GetGenericArguments()[0] != typeof(GameObject)) && methodInfo.GetParameters().Length == 3)
			{
				CodeInstruction val = new CodeInstruction(OpCodes.Ldarg_0, (object)null);
				val.labels.AddRange(list[i].labels);
				list[i].labels.Clear();
				val.blocks.AddRange(list[i].blocks);
				list[i].blocks.Clear();
				list.Insert(i, val);
				i++;
				list[i].opcode = OpCodes.Call;
				list[i].operand = AccessTools.Method(typeof(VeinMining), "SpawnDrop", (Type[])null, (Type[])null);
				num++;
			}
		}
		if (num != 1)
		{
			throw new InvalidOperationException("Expected one native mining drop site, found " + num);
		}
		return list;
	}

	private static GameObject SpawnDrop(GameObject prefab, Vector3 nativePosition, Quaternion rotation, Component rock)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: 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_0094: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = nativePosition;
		DropContext dropContext = context;
		if (dropContext != null && nearPlayer.Value && ((Object)(object)dropContext.Rock == (Object)(object)rock || ((Object)(object)dropContext.Rock != (Object)null && (Object)(object)dropContext.Rock.gameObject == (Object)(object)rock.gameObject)) && (Object)(object)dropContext.Player != (Object)null)
		{
			try
			{
				if (!dropContext.Located)
				{
					dropContext.Located = true;
					dropContext.HasPosition = FindGround(dropContext.Player, 0, out dropContext.Position);
				}
				if (dropContext.HasPosition)
				{
					val = dropContext.Position;
				}
			}
			catch (Exception ex)
			{
				Warn("Using native drop position: " + ex.Message);
			}
		}
		return Object.Instantiate<GameObject>(prefab, val, rotation);
	}

	private static bool FindGround(Player player, int sequence, out Vector3 position)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: 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_00a3: 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_00b0: 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_00b6: 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_00c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d3: 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_00d6: 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_00dd: 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)
		//IL_010b: Unknown result type (might be due to invalid IL or missing references)
		//IL_011e: Unknown result type (might be due to invalid IL or missing references)
		//IL_013e: 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_014d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0152: 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_0159: Unknown result type (might be due to invalid IL or missing references)
		//IL_0169: 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_0174: Unknown result type (might be due to invalid IL or missing references)
		//IL_0179: Unknown result type (might be due to invalid IL or missing references)
		//IL_017e: Unknown result type (might be due to invalid IL or missing references)
		//IL_018a: Unknown result type (might be due to invalid IL or missing references)
		//IL_018c: Unknown result type (might be due to invalid IL or missing references)
		position = Vector3.zero;
		int mask = LayerMask.GetMask(new string[5] { "Default", "static_solid", "Default_small", "terrain", "piece" });
		if (mask == 0)
		{
			return false;
		}
		Vector3 position2 = ((Component)player).transform.position;
		Vector3 forward = ((Component)player).transform.forward;
		forward.y = 0f;
		((Vector3)(ref forward)).Normalize();
		RaycastHit val2 = default(RaycastHit);
		for (int i = 0; i < 12; i++)
		{
			float num = (float)(sequence + i) * 137.50777f * ((float)Math.PI / 180f);
			float num2 = ((i < 6) ? 1f : 1.6f);
			Vector3 val = (forward * Mathf.Cos(num) + Vector3.Cross(Vector3.up, forward) * Mathf.Sin(num)) * num2;
			if (Physics.Raycast(position2 + val + Vector3.up * 2f, Vector3.down, ref val2, 4f, mask, (QueryTriggerInteraction)1) && !(((RaycastHit)(ref val2)).normal.y < 0.65f) && !(Mathf.Abs(((RaycastHit)(ref val2)).point.y - position2.y) > 1.5f))
			{
				Vector3 val3 = ((RaycastHit)(ref val2)).point + Vector3.up * 0.45f;
				if (!Physics.CheckSphere(val3, 0.3f, mask, (QueryTriggerInteraction)1) && !Physics.Linecast(position2 + Vector3.up * 0.7f, val3, mask, (QueryTriggerInteraction)1))
				{
					position = val3;
					return true;
				}
			}
		}
		return false;
	}

	private static HitData CompletionHit(Component rock, HitData original, int areaIndex)
	{
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: 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)
		HitData val = original.Clone();
		if (!Supported(rock) || !Finite(original.m_damage.m_pickaxe) || original.m_damage.m_pickaxe <= 0f)
		{
			return val;
		}
		Type type = ((object)rock).GetType();
		DamageModifiers val2 = (DamageModifiers)AccessTools.Field(type, (rock is Destructible) ? "m_damages" : "m_damageModifiers").GetValue(rock);
		HitData val3 = original.Clone();
		val3.m_damage = default(DamageTypes);
		val3.m_damage.m_pickaxe = 1f;
		DamageModifier val4 = default(DamageModifier);
		val3.ApplyResistance(val2, ref val4);
		float totalDamage = val3.GetTotalDamage();
		if (!Finite(totalDamage) || totalDamage <= 0f)
		{
			return val;
		}
		ZNetView component = rock.GetComponent<ZNetView>();
		float val5;
		if (rock is MineRock5)
		{
			load5.Invoke(rock, null);
			IList list = (IList)areas5.GetValue(rock);
			if (areaIndex < 0 || areaIndex >= list.Count)
			{
				return val;
			}
			val5 = (float)AccessTools.Field(list[areaIndex].GetType(), "m_health").GetValue(list[areaIndex]);
			float num = (float)AccessTools.Field(typeof(MineRock5), "m_health").GetValue(rock);
			if ((Object)(object)Game.instance != (Object)null)
			{
				num += (float)Game.m_worldLevel * num * Game.instance.m_worldLevelMineHPMultiplier;
			}
			val5 = Math.Max(val5, num);
		}
		else if (rock is MineRock)
		{
			float num2 = (float)AccessTools.Method(typeof(MineRock), "GetHealth", (Type[])null, (Type[])null).Invoke(rock, null);
			val5 = Math.Max(component.GetZDO().GetFloat("Health" + areaIndex, num2), num2);
		}
		else
		{
			float num3 = (float)AccessTools.Field(typeof(Destructible), "m_health").GetValue(rock);
			if ((Object)(object)Game.instance != (Object)null)
			{
				num3 += (float)Game.m_worldLevel * num3 * Game.instance.m_worldLevelMineHPMultiplier;
			}
			val5 = component.GetZDO().GetFloat(ZDOVars.s_health, num3);
		}
		if (!Finite(val5) || val5 <= 0f)
		{
			return val;
		}
		double num4 = ((double)val5 + Math.Max(1.0, (double)val5 * 0.01)) / (double)totalDamage;
		if (num4 > 3.4028234663852886E+38 || double.IsNaN(num4) || double.IsInfinity(num4))
		{
			return val;
		}
		val.m_damage.m_pickaxe = Math.Max(val.m_damage.m_pickaxe, (float)num4);
		return val;
	}

	private static bool TogetherEnabled()
	{
		if (breakTogether != null)
		{
			return breakTogether.Value;
		}
		return false;
	}

	private static void ExecutePreparedNode(Component rock, long sender, HitData hit, int index)
	{
		PrepareNode(rock, sender, hit, index);
		HitData __ = hit.Clone();
		NodeState __state;
		bool flag = BeginNode(rock, sender, ref __, ref index, out __state);
		Exception _exception = null;
		try
		{
			if (flag)
			{
				((rock is MineRock5) ? hit5 : hit1).Invoke(rock, new object[3] { sender, __, index });
			}
		}
		catch (Exception ex)
		{
			_exception = ex;
			throw;
		}
		finally
		{
			EndNode(_exception, __state);
		}
	}

	private static void PatchTogether()
	{
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Expected O, but got Unknown
		//IL_0059: Expected O, but got Unknown
		MethodInfo[] array = new MethodInfo[2] { hit5, hit1 };
		foreach (MethodInfo methodInfo in array)
		{
			harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(VeinMining), "BeginNode", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(typeof(VeinMining), "EndNode", (Type[])null), (HarmonyMethod)null);
		}
	}

	private static IList NodeAreas(Component rock)
	{
		return (IList)((rock is MineRock5) ? areas5 : areas1).GetValue(rock);
	}

	private static float SectionHealth(Component rock, int index)
	{
		IList list = NodeAreas(rock);
		if (list == null || index < 0 || index >= list.Count || list[index] == null)
		{
			return 0f;
		}
		float num;
		if (rock is MineRock5)
		{
			num = (float)AccessTools.Field(list[index].GetType(), "m_health").GetValue(list[index]);
		}
		else
		{
			Collider val = AreaCollider(list[index], modern: false);
			if ((Object)(object)val == (Object)null || !((Component)val).gameObject.activeInHierarchy)
			{
				return 0f;
			}
			float num2 = (float)AccessTools.Method(typeof(MineRock), "GetHealth", (Type[])null, (Type[])null).Invoke(rock, null);
			num = rock.GetComponent<ZNetView>().GetZDO().GetFloat("Health" + index, num2);
		}
		if (!Finite(num))
		{
			return 0f;
		}
		return Math.Max(0f, num);
	}

	private static void PrepareNode(Component rock, long sender, HitData hit, int primary)
	{
		if (!TogetherEnabled() || !ValidIntent(rock, sender, hit))
		{
			return;
		}
		IList list = NodeAreas(rock);
		if (list != null && primary >= 0 && primary < list.Count)
		{
			if (nodeIntents.Count >= 512)
			{
				nodeIntents.Clear();
			}
			nodeIntents[((Object)rock).GetInstanceID() + ":" + sender] = new NodeIntent
			{
				Rock = rock,
				Hit = hit.Clone(),
				Primary = primary,
				Time = Time.time
			};
		}
	}

	private static bool BeginNode(Component __instance, long __0, ref HitData __1, ref int __2, out NodeState __state)
	{
		//IL_00e0: 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)
		__state = null;
		try
		{
			if (!TogetherEnabled())
			{
				return true;
			}
			string text = ((Object)__instance).GetInstanceID() + ":" + __0;
			if (!nodeIntents.TryGetValue(text, out var value))
			{
				return true;
			}
			nodeIntents.Remove(text);
			if ((Object)(object)value.Rock != (Object)(object)__instance || value.Primary != __2 || Time.time - value.Time < 0f || Time.time - value.Time > 2f || !ValidIntent(__instance, __0, __1))
			{
				return true;
			}
			if (!((Object)(object)value.Hit.GetAttacker() != (Object)(object)__1.GetAttacker()) && value.Hit.m_damage.m_pickaxe == __1.m_damage.m_pickaxe)
			{
				Vector3 val = value.Hit.m_point - __1.m_point;
				if (!(((Vector3)(ref val)).sqrMagnitude > 0.0001f))
				{
					ZNetView component = __instance.GetComponent<ZNetView>();
					if (__instance is MineRock5)
					{
						load5.Invoke(__instance, null);
					}
					IList list = NodeAreas(__instance);
					NodeState nodeState = new NodeState();
					nodeState.Rock = __instance;
					nodeState.Hit = __1.Clone();
					nodeState.Sender = __0;
					nodeState.Previous = context;
					NodeState nodeState2 = (__state = nodeState);
					DropContext dropContext = new DropContext();
					dropContext.Rock = __instance;
					ref Player player = ref dropContext.Player;
					Character attacker = __1.GetAttacker();
					player = (Player)(object)((attacker is Player) ? attacker : null);
					dropContext.Sender = __0;
					context = dropContext;
					if (component.GetZDO().GetBool("LL.VeinMining.FinishPending.v1", false))
					{
						FinishDeposit(__instance, __0, nodeState2.Hit);
						return false;
					}
					int num = component.GetZDO().GetInt("LL.VeinMining.SharedSection.v1", -1);
					if (num < 0 || num >= list.Count || SectionHealth(__instance, num) <= 0f || (Object)(object)AreaCollider(list[num], __instance is MineRock5) == (Object)null)
					{
						num = __2;
					}
					if (SectionHealth(__instance, num) <= 0f)
					{
						return true;
					}
					component.GetZDO().Set("LL.VeinMining.SharedSection.v1", num);
					nodeState2.Anchor = num;
					nodeState2.NativeHit = true;
					__2 = num;
					__1 = __1.Clone();
					__1.m_hitCollider = AreaCollider(list[num], __instance is MineRock5);
					__1.m_radius = 0f;
					Diagnostic(__instance, "shared-section-hit", detail: true);
					return true;
				}
			}
			return true;
		}
		catch (Exception ex)
		{
			Warn("Shared mining preparation: " + ex.Message);
			return true;
		}
	}

	private static Exception EndNode(Exception __exception, NodeState __state)
	{
		if (__state == null)
		{
			return __exception;
		}
		try
		{
			Component rock = __state.Rock;
			if (__exception != null || !__state.NativeHit || (Object)(object)rock == (Object)null)
			{
				return __exception;
			}
			ZNetView component = rock.GetComponent<ZNetView>();
			if ((Object)(object)component == (Object)null || !component.IsValid() || !component.IsOwner())
			{
				return __exception;
			}
			if (rock is MineRock5)
			{
				load5.Invoke(rock, null);
			}
			if (SectionHealth(rock, __state.Anchor) <= 0f)
			{
				component.GetZDO().Set("LL.VeinMining.FinishPending.v1", true);
				FinishDeposit(rock, __state.Sender, __state.Hit);
			}
		}
		catch (Exception ex)
		{
			Warn("Shared mining completion interrupted: " + ex.Message);
		}
		finally
		{
			context = __state.Previous;
		}
		return __exception;
	}

	private static void FinishDeposit(Component rock, long sender, HitData hit)
	{
		//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
		ZNetView component = rock.GetComponent<ZNetView>();
		if ((Object)(object)component == (Object)null || !component.IsValid() || !component.IsOwner())
		{
			return;
		}
		if (rock is MineRock5)
		{
			load5.Invoke(rock, null);
		}
		IList list = NodeAreas(rock);
		if (list == null)
		{
			return;
		}
		int count = list.Count;
		for (int i = 0; i < count; i++)
		{
			if ((Object)(object)rock == (Object)null || (Object)(object)component == (Object)null || !component.IsValid() || !component.IsOwner())
			{
				return;
			}
			if (!(SectionHealth(rock, i) <= 0f))
			{
				Collider val = AreaCollider(list[i], rock is MineRock5);
				if (!((Object)(object)val == (Object)null))
				{
					HitData val2 = CompletionHit(rock, hit, i);
					val2.m_hitCollider = val;
					Bounds bounds = val.bounds;
					val2.m_point = ((Bounds)(ref bounds)).center;
					val2.m_radius = 0f;
					((rock is MineRock5) ? hit5 : hit1).Invoke(rock, new object[3] { sender, val2, i });
				}
			}
		}
		if (!((Object)(object)rock != (Object)null) || !((Object)(object)component != (Object)null) || !component.IsValid() || !component.IsOwner())
		{
			return;
		}
		if (rock is MineRock5)
		{
			load5.Invoke(rock, null);
		}
		bool flag = false;
		for (int j = 0; j < count; j++)
		{
			if (SectionHealth(rock, j) > 0f)
			{
				flag = true;
				break;
			}
		}
		component.GetZDO().Set("LL.VeinMining.FinishPending.v1", flag);
		if (rock is MineRock5)
		{
			mesh5.Invoke(rock, null);
		}
		Diagnostic(rock, flag ? "completion-pending" : "deposit-completed", !flag);
	}

	private static void AuditPrefabCatalog(ZNetScene __instance)
	{
		try
		{
			int num = 0;
			int num2 = 0;
			foreach (KeyValuePair<int, string> item in catalog)
			{
				GameObject prefab = __instance.GetPrefab(item.Key);
				if (!((Object)(object)prefab == (Object)null))
				{
					num++;
					if (!((item.Value == "MineRock5") ? ((Object)(object)prefab.GetComponent<MineRock5>() != (Object)null) : ((item.Value == "MineRock") ? ((Object)(object)prefab.GetComponent<MineRock>() != (Object)null) : ((Object)(object)prefab.GetComponent<Destructible>() != (Object)null))))
					{
						num2++;
						((BaseUnityPlugin)self).Logger.LogWarning((object)("Vanilla mining component changed: " + ((Object)prefab).name + ". Normal damage will be used; compatibility review needed."));
					}
				}
			}
			((BaseUnityPlugin)self).Logger.LogInfo((object)("Vanilla mining catalog (audited on 1.0.16): " + num + " registered prefabs, " + num2 + " component mismatches. This is a data check, not a gameplay test."));
		}
		catch (Exception ex)
		{
			Warn("Prefab compatibility check unavailable: " + ex.Message);
		}
	}

	private static void DiagnoseUnknown(Component rock)
	{
		ZNetView component = rock.GetComponent<ZNetView>();
		if ((Object)(object)component == (Object)null || !component.IsValid())
		{
			return;
		}
		int prefab = component.GetZDO().GetPrefab();
		if (catalog.ContainsKey(prefab) || unknown.Count >= 16 || !unknown.Add(prefab))
		{
			return;
		}
		string[] array = new string[7] { "StumpHut_frac", "stoneblock_fracture", "Ashlands_Fortress_Wall_PillarTopStone_frac", "Ashlands_Fortress_Wall_PillarTop_frac", "Ashlands_Fortress_Wall_Pillar_base_frac", "Ashlands_Fortress_Wall_Pillar_frac", "Ashlands_floor_large_fractured" };
		string[] array2 = array;
		foreach (string s in array2)
		{
			if (StableHash(s) == prefab)
			{
				return;
			}
		}
		if ((Object)(object)self != (Object)null)
		{
			((BaseUnityPlugin)self).Logger.LogWarning((object)("Uncatalogued mining prefab hash " + prefab + " (" + ((Object)rock.gameObject).name + "). Normal mining retained; please include this line in a compatibility report."));
		}
	}

	private static bool Supported(Component rock)
	{
		try
		{
			if ((Object)(object)rock == (Object)null)
			{
				return false;
			}
			ZNetView component = rock.GetComponent<ZNetView>();
			if ((Object)(object)component == (Object)null || !component.IsValid())
			{
				return false;
			}
			if (!catalog.TryGetValue(component.GetZDO().GetPrefab(), out var value))
			{
				return false;
			}
			return (rock is MineRock5) ? (value == "MineRock5") : ((rock is MineRock) ? (value == "MineRock") : (rock is Destructible && (value == "Shell" || value == "Single")));
		}
		catch (Exception ex)
		{
			Warn("Could not identify deposit; using normal mining: " + ex.Message);
			return false;
		}
	}

	private static void PatchShellSupport()
	{
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Expected O, but got Unknown
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Expected O, but got Unknown
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c1: Expected O, but got Unknown
		//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_0104: Unknown result type (might be due to invalid IL or missing references)
		//IL_010f: Expected O, but got Unknown
		//IL_010f: Expected O, but got Unknown
		//IL_0151: Unknown result type (might be due to invalid IL or missing references)
		//IL_015d: Expected O, but got Unknown
		//IL_018b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0197: Expected O, but got Unknown
		harmony.Patch((MethodBase)AccessTools.Method(typeof(ZNetScene), "Awake", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(VeinMining), "AuditPrefabCatalog", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		harmony.Patch((MethodBase)AccessTools.Method(typeof(Destructible), "Awake", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(VeinMining), "RegisterShell", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		harmony.Patch((MethodBase)AccessTools.Method(typeof(Destructible), "Damage", new Type[1] { typeof(HitData) }, (Type[])null), new HarmonyMethod(typeof(VeinMining), "PrepareShell", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		harmony.Patch((MethodBase)AccessTools.Method(typeof(Destructible), "RPC_Damage", (Type[])null, (Type[])null), new HarmonyMethod(typeof(VeinMining), "BeginShell", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(typeof(VeinMining), "EndShell", (Type[])null), (HarmonyMethod)null);
		harmony.Patch((MethodBase)AccessTools.Method(typeof(Destructible), "Destroy", new Type[1] { typeof(HitData) }, (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(typeof(VeinMining), "ShellTranspiler", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null);
		harmony.Patch((MethodBase)AccessTools.Method(typeof(DropOnDestroyed), "OnDestroyed", (Type[])null, (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(typeof(VeinMining), "DropTranspiler", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null);
	}

	private static void RegisterShell(Destructible __instance)
	{
		try
		{
			if (!Supported((Component)(object)__instance))
			{
				return;
			}
			Destructible rock = __instance;
			ZNetView component = ((Component)rock).GetComponent<ZNetView>();
			component.Register<HitData>("LL_VeinMining_109_Prepare", (Action<long, HitData>)delegate(long sender, HitData hit)
			{
				try
				{
					RememberIntent(rock, sender, hit);
				}
				catch (Exception ex2)
				{
					Warn("Preparation rejected: " + ex2.Message);
				}
			});
		}
		catch (Exception ex)
		{
			Warn("Single-rock setup skipped: " + ex.Message);
		}
	}

	private static bool ValidIntent(Component rock, long sender, HitData hit)
	{
		//IL_0092: 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_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)self == (Object)null || !Supported(rock) || hit == null || !Finite(hit.m_damage.m_pickaxe) || hit.m_damage.m_pickaxe <= 0f)
		{
			return false;
		}
		ZNetView component = rock.GetComponent<ZNetView>();
		Character attacker = hit.GetAttacker();
		Player val = (Player)(object)((attacker is Player) ? attacker : null);
		if (!component.IsOwner() || (Object)(object)val == (Object)null)
		{
			return false;
		}
		ZNetView component2 = ((Component)val).GetComponent<ZNetView>();
		if ((Object)(object)component2 == (Object)null || !component2.IsValid() || component2.GetZDO().GetOwner() != sender)
		{
			return false;
		}
		Vector3 val2 = ((Component)val).transform.position - hit.m_point;
		float sqrMagnitude = ((Vector3)(ref val2)).sqrMagnitude;
		if (Finite(sqrMagnitude))
		{
			return sqrMagnitude <= 100f;
		}
		return false;
	}

	private static void RememberIntent(Destructible rock, long sender, HitData hit)
	{
		if (ValidIntent((Component)(object)rock, sender, hit))
		{
			if (intents.Count >= 256)
			{
				intents.Clear();
			}
			intents[((Object)rock).GetInstanceID()] = new Intent
			{
				Rock = rock,
				Hit = hit.Clone(),
				Sender = sender,
				Time = Time.time
			};
		}
	}

	private static void PrepareShell(Destructible __instance, HitData hit)
	{
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			if (!((Object)(object)self == (Object)null) && hit != null && !((Object)(object)Player.m_localPlayer == (Object)null) && !((Object)(object)hit.GetAttacker() != (Object)(object)Player.m_localPlayer) && Finite(hit.m_damage.m_pickaxe) && !(hit.m_damage.m_pickaxe <= 0f) && (always.Value || VeinMinerControllerInput.Held(key.Value)))
			{
				if (!Supported((Component)(object)__instance))
				{
					Diagnostic((Component)(object)__instance, "unsupported-shell", detail: false);
					return;
				}
				Diagnostic((Component)(object)__instance, "shell-preparation-sent", detail: true);
				((Component)__instance).GetComponent<ZNetView>().InvokeRPC("LL_VeinMining_109_Prepare", new object[1] { hit.Clone() });
			}
		}
		catch (Exception ex)
		{
			Warn("Preparation unavailable; using normal mining: " + ex.Message);
		}
	}

	private static void BeginShell(Destructible __instance, long __0, HitData __1, out DropContext __state)
	{
		//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
		__state = context;
		context = null;
		try
		{
			int instanceID = ((Object)__instance).GetInstanceID();
			if (!intents.TryGetValue(instanceID, out var value))
			{
				return;
			}
			intents.Remove(instanceID);
			if ((Object)(object)value.Rock != (Object)(object)__instance || value.Sender != __0 || Time.time - value.Time < 0f || Time.time - value.Time > 1f || !ValidIntent((Component)(object)__instance, __0, __1))
			{
				Diagnostic((Component)(object)__instance, "shell-intent-expired-or-invalid", detail: false);
				return;
			}
			if (!((Object)(object)value.Hit.GetAttacker() != (Object)(object)__1.GetAttacker()) && value.Hit.m_damage.m_pickaxe == __1.m_damage.m_pickaxe)
			{
				Vector3 val = value.Hit.m_point - __1.m_point;
				if (!(((Vector3)(ref val)).sqrMagnitude > 0.0001f))
				{
					Diagnostic((Component)(object)__instance, "shell-owner-accepted", detail: true);
					DropContext dropContext = new DropContext();
					dropContext.Rock = (Component)(object)__instance;
					ref Player player = ref dropContext.Player;
					Character attacker = __1.GetAttacker();
					player = (Player)(object)((attacker is Player) ? attacker : null);
					dropContext.Sender = __0;
					context = dropContext;
					return;
				}
			}
			Diagnostic((Component)(object)__instance, "shell-intent-hit-mismatch", detail: false);
		}
		catch (Exception ex)
		{
			Warn("Normal mining used: " + ex.Message);
		}
	}

	private static Exception EndShell(Exception __exception, DropContext __state)
	{
		context = __state;
		return __exception;
	}

	private static IEnumerable<CodeInstruction> ShellTranspiler(IEnumerable<CodeInstruction> original)
	{
		//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f0: Expected O, but got Unknown
		List<CodeInstruction> list = new List<CodeInstruction>(original);
		int num = 0;
		int num2 = 0;
		for (int i = 0; i < list.Count; i++)
		{
			MethodInfo methodInfo = list[i].operand as MethodInfo;
			if (!(methodInfo == null))
			{
				string text = null;
				if (methodInfo.DeclaringType == typeof(MineRock5) && methodInfo.Name == "Damage" && methodInfo.GetParameters().Length == 1)
				{
					text = "ForwardShellHit";
					num++;
				}
				if (methodInfo.DeclaringType == typeof(Object) && methodInfo.Name == "Instantiate" && methodInfo.IsGenericMethod && methodInfo.GetGenericArguments()[0] == typeof(GameObject) && methodInfo.GetParameters().Length == 3)
				{
					text = "SpawnReplacement";
					num2++;
				}
				if (text != null)
				{
					CodeInstruction val = new CodeInstruction(OpCodes.Ldarg_0, (object)null);
					val.labels.AddRange(list[i].labels);
					list[i].labels.Clear();
					val.blocks.AddRange(list[i].blocks);
					list[i].blocks.Clear();
					list.Insert(i, val);
					i++;
					list[i].opcode = OpCodes.Call;
					list[i].operand = AccessTools.Method(typeof(VeinMining), text, (Type[])null, (Type[])null);
				}
			}
		}
		if (num != 1 || num2 != 1)
		{
			throw new InvalidOperationException("Shell API changed; expected one forwarded hit and one replacement spawn.");
		}
		return list;
	}

	private static GameObject SpawnReplacement(GameObject prefab, Vector3 position, Quaternion rotation, Destructible source)
	{
		//IL_0022: 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)
		//IL_0018: 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)
		if ((Object)(object)prefab != (Object)null && (Object)(object)prefab.GetComponent<ItemDrop>() != (Object)null)
		{
			return SpawnDrop(prefab, position, rotation, (Component)(object)source);
		}
		return Object.Instantiate<GameObject>(prefab, position, rotation);
	}

	private static void ForwardShellHit(MineRock5 child, HitData hit, Destructible source)
	{
		//IL_00b0: 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_032d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0332: 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_011e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0123: Unknown result type (might be due to invalid IL or missing references)
		//IL_0128: Unknown result type (might be due to invalid IL or missing references)
		//IL_012e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0133: Unknown result type (might be due to invalid IL or missing references)
		//IL_0138: Unknown result type (might be due to invalid IL or missing references)
		//IL_0240: Unknown result type (might be due to invalid IL or missing references)
		//IL_0245: Unknown result type (might be due to invalid IL or missing references)
		//IL_024a: Unknown result type (might be due to invalid IL or missing references)
		//IL_024f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0255: Unknown result type (might be due to invalid IL or missing references)
		//IL_025a: Unknown result type (might be due to invalid IL or missing references)
		//IL_025f: Unknown result type (might be due to invalid IL or missing references)
		DropContext dropContext = context;
		if (dropContext == null || (Object)(object)dropContext.Rock != (Object)(object)source)
		{
			child.Damage(hit);
			return;
		}
		if (!Supported((Component)(object)child))
		{
			Diagnostic((Component)(object)child, "unsupported-shell-replacement", detail: false);
			child.Damage(hit);
			return;
		}
		ZNetView component = ((Component)child).GetComponent<ZNetView>();
		if (!component.IsOwner())
		{
			Diagnostic((Component)(object)child, "replacement-ownership-changed", detail: false);
			child.Damage(hit);
			return;
		}
		bool flag = false;
		try
		{
			if (TogetherEnabled())
			{
				DropContext dropContext2 = new DropContext();
				dropContext2.Rock = (Component)(object)child;
				dropContext2.Player = dropContext.Player;
				dropContext2.Sender = dropContext.Sender;
				dropContext2.Located = dropContext.Located;
				dropContext2.HasPosition = dropContext.HasPosition;
				dropContext2.Position = dropContext.Position;
				context = dropContext2;
				load5.Invoke(child, null);
				IList list = (IList)areas5.GetValue(child);
				int num = -1;
				float num2 = float.PositiveInfinity;
				for (int i = 0; i < list.Count; i++)
				{
					Collider val = AreaCollider(list[i], modern: true);
					if (!((Object)(object)val == (Object)null) && !(SectionHealth((Component)(object)child, i) <= 0f))
					{
						Bounds bounds = val.bounds;
						Vector3 val2 = ((Bounds)(ref bounds)).ClosestPoint(hit.m_point) - hit.m_point;
						float sqrMagnitude = ((Vector3)(ref val2)).sqrMagnitude;
						if (Finite(sqrMagnitude) && sqrMagnitude < num2)
						{
							num = i;
							num2 = sqrMagnitude;
						}
					}
				}
				if (num < 0)
				{
					flag = true;
					child.Damage(hit);
				}
				else
				{
					flag = true;
					ExecutePreparedNode((Component)(object)child, dropContext.Sender, hit, num);
				}
				return;
			}
			load5.Invoke(child, null);
			IList list2 = (IList)areas5.GetValue(child);
			int num3 = -1;
			float num4 = float.PositiveInfinity;
			for (int j = 0; j < list2.Count; j++)
			{
				Collider val3 = AreaCollider(list2[j], modern: true);
				if ((Object)(object)val3 == (Object)null || !val3.enabled || !((Component)val3).gameObject.activeInHierarchy)
				{
					continue;
				}
				float num5 = (float)AccessTools.Field(list2[j].GetType(), "m_health").GetValue(list2[j]);
				if (Finite(num5) && !(num5 <= 0f))
				{
					Bounds bounds2 = val3.bounds;
					Vector3 val4 = ((Bounds)(ref bounds2)).ClosestPoint(hit.m_point) - hit.m_point;
					float sqrMagnitude2 = ((Vector3)(ref val4)).sqrMagnitude;
					if (Finite(sqrMagnitude2) && sqrMagnitude2 < num4)
					{
						num3 = j;
						num4 = sqrMagnitude2;
					}
				}
			}
			if (num3 < 0 || num4 > 4f)
			{
				Diagnostic((Component)(object)child, "replacement-outside-safe-hit-range", detail: false);
				flag = true;
				child.Damage(hit);
				return;
			}
			HitData val5 = hit.Clone();
			val5.m_hitCollider = AreaCollider(list2[num3], modern: true);
			val5.m_radius = 0f;
			DropContext dropContext3 = new DropContext();
			dropContext3.Rock = (Component)(object)child;
			dropContext3.Player = dropContext.Player;
			dropContext3.Sender = dropContext.Sender;
			dropContext3.Located = dropContext.Located;
			dropContext3.HasPosition = dropContext.HasPosition;
			dropContext3.Position = dropContext.Position;
			context = dropContext3;
			flag = true;
			hit5.Invoke(child, new object[3] { dropContext.Sender, val5, num3 });
			if ((Object)(object)component != (Object)null && component.IsValid() && component.IsOwner())
			{
				Receive((Component)(object)child, dropContext.Sender, hit, num3);
			}
		}
		catch (Exception ex)
		{
			Warn("Replacement mining interrupted: " + ex.Message);
			if (!flag)
			{
				child.Damage(hit);
			}
		}
		finally
		{
			context = dropContext;
		}
	}

	private static int ResolvePrimary(Component rock, IList areas, HitData hit)
	{
		//IL_0111: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
		if (areas == null || hit == null)
		{
			return -1;
		}
		bool flag = rock is MineRock5;
		for (int i = 0; i < areas.Count; i++)
		{
			Collider val = AreaCollider(areas[i], flag);
			if ((Object)(object)val != (Object)null && (Object)(object)val == (Object)(object)hit.m_hitCollider && val.enabled && ((Component)val).gameObject.activeInHierarchy)
			{
				return i;
			}
		}
		if (!flag || !Finite(hit.m_point.x) || !Finite(hit.m_point.y) || !Finite(hit.m_point.z) || !Finite(hit.m_radius))
		{
			return -1;
		}
		float num = ((hit.m_radius > 0f) ? hit.m_radius : 0.05f);
		if (num > 10f)
		{
			return -1;
		}
		int mask = LayerMask.GetMask(new string[5] { "piece", "Default", "static_solid", "Default_small", "terrain" });
		if (mask == 0)
		{
			return -1;
		}
		try
		{
			int num2 = Physics.OverlapSphereNonAlloc(hit.m_point, num, hitCandidates, mask);
			if (num2 >= hitCandidates.Length)
			{
				Diagnostic(rock, "hit-query-buffer-full", detail: false);
				return -1;
			}
			int result = -1;
			float num3 = float.PositiveInfinity;
			for (int j = 0; j < areas.Count; j++)
			{
				Collider val2 = AreaCollider(areas[j], modern: true);
				if ((Object)(object)val2 == (Object)null || !val2.enabled || !((Component)val2).gameObject.activeInHierarchy)
				{
					continue;
				}
				bool flag2 = false;
				for (int k = 0; k < num2; k++)
				{
					if ((Object)(object)hitCandidates[k] == (Object)(object)val2)
					{
						flag2 = true;
						break;
					}
				}
				if (flag2)
				{
					Bounds bounds = val2.bounds;
					Vector3 val3 = ((Bounds)(ref bounds)).ClosestPoint(hit.m_point) - hit.m_point;
					float sqrMagnitude = ((Vector3)(ref val3)).sqrMagnitude;
					if (Finite(sqrMagnitude) && sqrMagnitude < num3)
					{
						result = j;
						num3 = sqrMagnitude;
					}
				}
			}
			return result;
		}
		finally
		{
			Array.Clear(hitCandidates, 0, hitCandidates.Length);
		}
	}

	private static void Diagnostic(Component rock, string reason, bool detail)
	{
		if ((Object)(object)self == (Object)null || (detail && (verbose == null || !verbose.Value)))
		{
			return;
		}
		try
		{
			ZNetView val = (((Object)(object)rock == (Object)null) ? null : rock.GetComponent<ZNetView>());
			int num = (((Object)(object)val != (Object)null && val.IsValid()) ? val.GetZDO().GetPrefab() : 0);
			string text = num + ":" + reason;
			if (!diagnosticTimes.TryGetValue(text, out var value) || !(Time.time - value >= 0f) || !(Time.time - value < 10f))
			{
				if (diagnosticTimes.Count >= 256)
				{
					diagnosticTimes.Clear();
				}
				diagnosticTimes[text] = Time.time;
				string text2 = "VeinMining 1.0.8 [" + reason + "] prefab=" + num + ", object=" + (((Object)(object)rock == (Object)null) ? "null" : ((Object)rock.gameObject).name) + ", owner=" + ((Object)(object)val != (Object)null && val.IsValid() && val.IsOwner()) + ". " + (detail ? "Diagnostic trace." : "Normal mining retained; include this line and startup log in a report.");
				if (detail)
				{
					((BaseUnityPlugin)self).Logger.LogInfo((object)text2);
				}
				else
				{
					((BaseUnityPlugin)self).Logger.LogWarning((object)text2);
				}
			}
		}
		catch (Exception)
		{
		}
	}

	private static Dictionary<int, string> MakeCatalog()
	{
		Dictionary<int, string> dictionary = new Dictionary<int, string>();
		dictionary.Add(StableHash("Leviathan"), "MineRock");
		dictionary.Add(StableHash("LeviathanLava"), "MineRock");
		dictionary.Add(StableHash("TrollFrost_Dead"), "Shell");
		dictionary.Add(StableHash("Pickable_MountainCaveCrystal"), "Single");
		dictionary.Add(StableHash("Pickable_MountainCaveObsidian"), "Single");
		dictionary.Add(StableHash("Pickable_SulfurRock"), "Single");
		dictionary.Add(StableHash("UnstableLavaRock"), "Single");
		dictionary.Add(StableHash("cliff_ashlands4"), "Shell");
		dictionary.Add(StableHash("cliff_ashlands4_frac"), "MineRock5");
		dictionary.Add(StableHash("cliff_ashlands5"), "Shell");
		dictionary.Add(StableHash("cliff_ashlands6"), "Shell");
		dictionary.Add(StableHash("cliff_ashlands6_frac"), "MineRock5");
		dictionary.Add(StableHash("cliff_ashlands7_HalfArch"), "Shell");
		dictionary.Add(StableHash("cliff_ashlands7_HalfArch_frac"), "MineRock5");
		dictionary.Add(StableHash("cliff_ashlands8"), "Shell");
		dictionary.Add(StableHash("cliff_ashlands_Arch_frac"), "MineRock5");
		dictionary.Add(StableHash("cliff_ashlandsflowrock_frac"), "MineRock5");
		dictionary.Add(StableHash("lavarock_ashlands1"), "Shell");
		dictionary.Add(StableHash("Ashlands_rock1"), "Shell");
		dictionary.Add(StableHash("Ice_floor_fractured"), "MineRock5");
		dictionary.Add(StableHash("caverock_ice_pillar_wall"), "Single");
		dictionary.Add(StableHash("caverock_ice_stalagmite"), "Single");
		dictionary.Add(StableHash("caverock_ice_stalagmite_broken"), "Single");
		dictionary.Add(StableHash("caverock_ice_stalagtite"), "Single");
		dictionary.Add(StableHash("BlackIce_Core"), "Single");
		dictionary.Add(StableHash("BlackIce_Core_outer"), "Single");
		dictionary.Add(StableHash("BlackIce_Start"), "Single");
		dictionary.Add(StableHash("FrozenGD"), "Single");
		dictionary.Add(StableHash("FrozenSkeleton_Pose1"), "Single");
		dictionary.Add(StableHash("FrozenSkeleton_Pose2"), "Single");
		dictionary.Add(StableHash("FlametalRockstand"), "Shell");
		dictionary.Add(StableHash("FlametalRockstand_frac"), "MineRock5");
		dictionary.Add(StableHash("HeathRockPillar"), "Shell");
		dictionary.Add(StableHash("HeathRockPillar_frac"), "MineRock5");
		dictionary.Add(StableHash("ice1"), "Single");
		dictionary.Add(StableHash("ice_rock1"), "Shell");
		dictionary.Add(StableHash("ice_rock1_frac"), "MineRock5");
		dictionary.Add(StableHash("BlackIceShard_01"), "Single");
		dictionary.Add(StableHash("BlackIceShard_02"), "Single");
		dictionary.Add(StableHash("IceShard_01"), "Single");
		dictionary.Add(StableHash("IceShard_02"), "Single");
		dictionary.Add(StableHash("IceShard_03"), "Single");
		dictionary.Add(StableHash("IceShard_04"), "Single");
		dictionary.Add(StableHash("IceShard_05"), "Single");
		dictionary.Add(StableHash("IceShard_06"), "Single");
		dictionary.Add(StableHash("MineRock_Copper"), "MineRock");
		dictionary.Add(StableHash("MineRock_Iron"), "MineRock");
		dictionary.Add(StableHash("MineRock_Meteorite"), "MineRock");
		dictionary.Add(StableHash("MineRock_Obsidian"), "Single");
		dictionary.Add(StableHash("MineRock_Stone"), "MineRock");
		dictionary.Add(StableHash("MineRock_Tin"), "Single");
		dictionary.Add(StableHash("Rock_destructible_test"), "MineRock");
		dictionary.Add(StableHash("ancient_skull"), "Shell");
		dictionary.Add(StableHash("cliff_ashlands1"), "Shell");
		dictionary.Add(StableHash("cliff_ashlands1_frac"), "MineRock5");
		dictionary.Add(StableHash("cliff_ashlands2"), "Shell");
		dictionary.Add(StableHash("cliff_ashlands2_frac"), "MineRock5");
		dictionary.Add(StableHash("cliff_ashlands3_Arch_1"), "Shell");
		dictionary.Add(StableHash("cliff_mistlands1"), "Shell");
		dictionary.Add(StableHash("cliff_mistlands1_creep"), "Shell");
		dictionary.Add(StableHash("cliff_mistlands1_creep_frac"), "MineRock5");
		dictionary.Add(StableHash("cliff_mistlands1_frac"), "MineRock5");
		dictionary.Add(StableHash("cliff_mistlands2"), "Shell");
		dictionary.Add(StableHash("cliff_mistlands2_frac"), "MineRock5");
		dictionary.Add(StableHash("flying_core"), "Shell");
		dictionary.Add(StableHash("giant_arm"), "Shell");
		dictionary.Add(StableHash("giant_brain"), "Shell");
		dictionary.Add(StableHash("giant_brain_frac"), "MineRock5");
		dictionary.Add(StableHash("giant_helmet1"), "Shell");
		dictionary.Add(StableHash("giant_helmet1_destruction"), "MineRock5");
		dictionary.Add(StableHash("giant_helmet2"), "Shell");
		dictionary.Add(StableHash("giant_helmet2_destruction"), "MineRock5");
		dictionary.Add(StableHash("giant_ribs"), "Shell");
		dictionary.Add(StableHash("giant_ribs_frac"), "MineRock5");
		dictionary.Add(StableHash("giant_skull"), "Shell");
		dictionary.Add(StableHash("giant_skull_frac"), "MineRock5");
		dictionary.Add(StableHash("giant_sword1"), "Shell");
		dictionary.Add(StableHash("giant_sword1_destruction"), "MineRock5");
		dictionary.Add(StableHash("giant_sword2"), "Shell");
		dictionary.Add(StableHash("giant_sword2_destruction"), "MineRock5");
		dictionary.Add(StableHash("rock_mistlands1"), "Shell");
		dictionary.Add(StableHash("rock_mistlands1_frac"), "MineRock5");
		dictionary.Add(StableHash("rock_mistlands2"), "Shell");
		dictionary.Add(StableHash("MountainGraveStone01"), "Single");
		dictionary.Add(StableHash("mudpile"), "Shell");
		dictionary.Add(StableHash("mudpile2"), "Shell");
		dictionary.Add(StableHash("mudpile2_frac"), "MineRock5");
		dictionary.Add(StableHash("mudpile_beacon"), "Shell");
		dictionary.Add(StableHash("mudpile_frac"), "MineRock5");
		dictionary.Add(StableHash("mudpile_old"), "MineRock");
		dictionary.Add(StableHash("RockDolmen_1"), "Single");
		dictionary.Add(StableHash("RockDolmen_2"), "Single");
		dictionary.Add(StableHash("RockDolmen_3"), "Single");
		dictionary.Add(StableHash("Rock_3"), "Shell");
		dictionary.Add(StableHash("Rock_3_deepnorth"), "Shell");
		dictionary.Add(StableHash("Rock_3_deepnorth_frac"), "MineRock5");
		dictionary.Add(StableHash("Rock_3_frac"), "MineRock5");
		dictionary.Add(StableHash("Rock_4"), "Single");
		dictionary.Add(StableHash("Rock_4_deepnorth"), "Single");
		dictionary.Add(StableHash("Rock_4_plains"), "Single");
		dictionary.Add(StableHash("Rock_7"), "Single");
		dictionary.Add(StableHash("Rock_7_deepnorth"), "Single");
		dictionary.Add(StableHash("Rock_7_meadows"), "Single");
		dictionary.Add(StableHash("Rock_destructible"), "Single");
		dictionary.Add(StableHash("Ashlands_rock2"), "Shell");
		dictionary.Add(StableHash("BigRock"), "Shell");
		dictionary.Add(StableHash("IcePond_rock"), "Shell");
		dictionary.Add(StableHash("IcePond_rock_frac"), "MineRock5");
		dictionary.Add(StableHash("IceShore"), "MineRock5");
		dictionary.Add(StableHash("IceShoreShard"), "Single");
		dictionary.Add(StableHash("IceShore_1"), "Shell");
		dictionary.Add(StableHash("IceShore_frac"), "MineRock5");
		dictionary.Add(StableHash("ShimmeringSand_rock"), "Shell");
		dictionary.Add(StableHash("ShimmeringSand_rock_frac"), "MineRock5");
		dictionary.Add(StableHash("TrollFrost_Frac"), "MineRock5");
		dictionary.Add(StableHash("TrollFrost_Frac_arm"), "MineRock5");
		dictionary.Add(StableHash("TrollFrost_Frac_legs"), "MineRock5");
		dictionary.Add(StableHash("goldvein"), "Shell");
		dictionary.Add(StableHash("goldvein_frac"), "MineRock5");
		dictionary.Add(StableHash("highstone"), "Shell");
		dictionary.Add(StableHash("highstone_2"), "Shell");
		dictionary.Add(StableHash("highstone_2_frac"), "MineRock5");
		dictionary.Add(StableHash("highstone_frac"), "MineRock5");
		dictionary.Add(StableHash("rock1_mistlands"), "Shell");
		dictionary.Add(StableHash("rock1_mountain"), "Shell");
		dictionary.Add(StableHash("rock1_mountain_frac"), "MineRock5");
		dictionary.Add(StableHash("rock2_heath"), "Shell");
		dictionary.Add(StableHash("rock2_heath_frac"), "MineRock5");
		dictionary.Add(StableHash("rock2_mountain"), "Shell");
		dictionary.Add(StableHash("rock2_mountain_frac"), "MineRock5");
		dictionary.Add(StableHash("rock3_ice"), "Shell");
		dictionary.Add(StableHash("rock3_ice_frac"), "MineRock5");
		dictionary.Add(StableHash("rock3_mountain"), "Shell");
		dictionary.Add(StableHash("rock3_mountain_1"), "Shell");
		dictionary.Add(StableHash("rock3_mountain_1_frac"), "MineRock5");
		dictionary.Add(StableHash("rock3_mountain_frac"), "MineRock5");
		dictionary.Add(StableHash("rock3_silver"), "Shell");
		dictionary.Add(StableHash("rock3_silver_frac"), "MineRock5");
		dictionary.Add(StableHash("rock4_ashlands_frac"), "MineRock5");
		dictionary.Add(StableHash("rock4_bigrock_frac"), "MineRock5");
		dictionary.Add(StableHash("rock4_coast"), "Shell");
		dictionary.Add(StableHash("rock4_coast_frac"), "MineRock5");
		dictionary.Add(StableHash("rock4_copper"), "Shell");
		dictionary.Add(StableHash("rock4_copper_frac"), "MineRock5");
		dictionary.Add(StableHash("rock4_forest"), "Shell");
		dictionary.Add(StableHash("rock4_forest_frac"), "MineRock5");
		dictionary.Add(StableHash("rock4_heath"), "Shell");
		dictionary.Add(StableHash("rock4_heath_frac"), "MineRock5");
		dictionary.Add(StableHash("silvervein"), "Shell");
		dictionary.Add(StableHash("silvervein_frac"), "MineRock5");
		dictionary.Add(StableHash("tarlump1"), "Shell");
		dictionary.Add(StableHash("tarlump1_frac"), "MineRock5");
		dictionary.Add(StableHash("widestone"), "Shell");
		dictionary.Add(StableHash("widestone_2"), "Shell");
		dictionary.Add(StableHash("widestone_2_frac"), "MineRock5");
		dictionary.Add(StableHash("widestone_frac"), "MineRock5");
		dictionary.Add(StableHash("RockFinger"), "Shell");
		dictionary.Add(StableHash("RockFingerBroken"), "Shell");
		dictionary.Add(StableHash("RockFingerBroken_frac"), "MineRock5");
		dictionary.Add(StableHash("RockFinger_frac"), "MineRock5");
		dictionary.Add(StableHash("RockThumb"), "Shell");
		dictionary.Add(StableHash("RockThumb_frac"), "MineRock5");
		dictionary.Add(StableHash("MemorialStone_Large"), "Single");
		dictionary.Add(StableHash("MemorialStone_Medium"), "Single");
		dictionary.Add(StableHash("MemorialStone_Small"), "Single");
		dictionary.Add(StableHash("marker01"), "Single");
		dictionary.Add(StableHash("marker02"), "Single");
		dictionary.Add(StableHash("stonewall_2"), "Single");
		dictionary.Add(StableHash("stonewall_3"), "Single");
		return dictionary;
	}

	private static int StableHash(string s)
	{
		int num = 5381;
		int num2 = num;
		for (int i = 0; i < s.Length && s[i] != 0; i += 2)
		{
			num = ((num << 5) + num) ^ s[i];
			if (i == s.Length - 1 || s[i + 1] == '\0')
			{
				break;
			}
			num2 = ((num2 << 5) + num2) ^ s[i + 1];
		}
		return num + num2 * 1566083941;
	}
}
internal static class PluginConfig
{
	internal static ConfigEntry<bool> BindTogether(ConfigFile cfg)
	{
		return cfg.Bind<bool>("General", "BreakTogether", true, "Repeated normal-strength hits work on one shared section of the deposit. When that section breaks, finish the remaining deposit in the same action. Requires the correct pickaxe tier. Ignores MaxSectionsPerHit while enabled. The obsolete InstantBreak setting is not used.");
	}

	internal static ConfigEntry<int> BindLimit(ConfigFile cfg)
	{
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Expected O, but got Unknown
		return cfg.Bind<int>("Balance", "MaxSectionsPerHit", 32, new ConfigDescription("Only used when BreakTogether is disabled. 0 damages all remaining sections normally; 1-128 caps sections per swing. Existing values are preserved.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 128), new object[0]));
	}

	internal static ConfigFile Attach(BaseUnityPlugin plugin, string path)
	{
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Expected O, but got Unknown
		if (object.ReferenceEquals(plugin, null))
		{
			throw new ArgumentNullException("plugin");
		}
		FieldInfo field = typeof(BaseUnityPlugin).GetField("<Config>k__BackingField", BindingFlags.Instance | BindingFlags.NonPublic);
		if (field == null || field.FieldType != typeof(ConfigFile))
		{
			throw new MissingMemberException("BepInEx Config API changed; cannot expose the named config to configuration managers.");
		}
		ConfigFile val = new ConfigFile(path, true);
		field.SetValue(plugin, val);
		if (!object.ReferenceEquals(plugin.Config, val))
		{
			throw new InvalidOperationException("Configuration manager and plugin would use different config instances.");
		}
		return plugin.Config;
	}
}
public static class VeinMinerControllerInput
{
	private static ConfigEntry<string> mode;

	private static ConfigEntry<GamepadButton> button;

	public static void Initialize(ConfigFile config)
	{
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Expected O, but got Unknown
		mode = config.Bind<string>("Controller", "ActivationMode", "Hold", new ConfigDescription("Automatic: veinmine when a gamepad is the active input. Hold: hold ActivationButton until the pickaxe hits. Disabled: keyboard only. General.AlwaysEnabled overrides both input methods.", (AcceptableValueBase)(object)new AcceptableValueList<string>(new string[3] { "Automatic", "Hold", "Disabled" }), new object[0]));
		button = config.Bind<GamepadButton>("Controller", "ActivationButton", (GamepadButton)8, "Used in Hold mode. LeftStick means clicking/holding the left stick (L3). Other choices include LeftShoulder, RightStick and RightShoulder. Normal game actions are not suppressed; choose a button compatible with your layout. Restart after editing the config.");
	}

	public static bool Held(KeyCode keyboardKey)
	{
		//IL_0000: 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_009a: Unknown result type (might be due to invalid IL or missing references)
		if (Input.GetKey(keyboardKey))
		{
			return true;
		}
		if (mode == null || mode.Value == "Disabled" || !ZInput.IsGamepadActive())
		{
			return false;
		}
		Gamepad current = Gamepad.current;
		if (current == null)
		{
			return false;
		}
		if (mode.Value == "Automatic")
		{
			return true;
		}
		if (mode.Value != "Hold" || button == null)
		{
			return false;
		}
		if (!Enum.IsDefined(typeof(GamepadButton), button.Value))
		{
			return false;
		}
		ButtonControl val = current[button.Value];
		if (val != null)
		{
			return val.isPressed;
		}
		return false;
	}
}