Decompiled source of AnimalFeedingTrough v1.0.5

AnimalFeedingTrough.dll

Decompiled a month 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 =