Decompiled source of Conveyor Belts v0.7.0

ConveyorBelts.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Jotunn;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.Rendering;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("ConveyorBelts")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.7.0.0")]
[assembly: AssemblyInformationalVersion("0.7.0+b8edd2a07334f4ad8895ac17d8349c6bcdd8a8de")]
[assembly: AssemblyProduct("ConveyorBelts")]
[assembly: AssemblyTitle("ConveyorBelts")]
[assembly: InternalsVisibleTo("ConveyorBelts.Tests")]
[assembly: AssemblyMetadata("AI_Assisted_Creation", "Claude Opus 5.5 and Claude Fable 5.1, through Claude Code")]
[assembly: AssemblyMetadata("AI_Model_Vendor", "Anthropic")]
[assembly: AssemblyVersion("0.7.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace ConveyorBelts
{
	internal sealed class Arch
	{
		public bool Stands = true;
	}
	internal sealed class Belt
	{
		public BeltPaths Piece;

		public Path[] Paths = new Path[0];

		public float Speed;

		public bool Moved;

		public RidingItem Coming;

		public float ComingAt = -1f;

		public Func<RidingItem, int> Choice;

		public Func<ItemKind, ItemData, bool> Fit;

		public bool IsFilter => Paths.Length > 1;

		public bool Narrow => Fit != null;

		public int Choose(RidingItem item)
		{
			if (Choice == null)
			{
				return 0;
			}
			return Choice(item);
		}

		public bool Takes(ItemKind kind, ItemData data)
		{
			if (Fit != null)
			{
				return Fit(kind, data);
			}
			return true;
		}

		public bool Takes(RidingItem item)
		{
			return Takes(item.Kind, item.Item);
		}
	}
	public class BeltAnimator : MonoBehaviour
	{
		internal static readonly HashSet<BeltAnimator> Loaded = new HashSet<BeltAnimator>();

		public Transform[] Slats;

		public Transform[] Marks;

		public Transform[] Rollers;

		public Transform Wheel;

		public float Span;

		public float Direction = 1f;

		private float _travel;

		private float _spin;

		private PowerNode _power;

		private BeltMover _mover;

		private bool _on;

		internal const float Far = 80f;

		private const float Reach = 4f;

		internal static bool Everywhere;

		private static readonly List<Camera> Cameras = new List<Camera>();

		private static readonly List<Plane[]> Views = new List<Plane[]>();

		private static Camera[] _all = (Camera[])(object)new Camera[4];

		private static int _viewsFrame = -1;

		internal float LoopLength => BeltPiece.LoopLength(Span);

		internal float Travel => _travel;

		internal float Spin => _spin;

		private void Awake()
		{
			_power = ((Component)this).GetComponent<PowerNode>();
			_mover = ((Component)this).GetComponentInParent<BeltMover>();
			ShowMarks();
		}

		private void Start()
		{
			ZNetView component = ((Component)this).GetComponent<ZNetView>();
			if (Object.op_Implicit((Object)(object)component) && component.IsValid())
			{
				CheapDraw.Add(this);
			}
		}

		private void OnDestroy()
		{
			CheapDraw.Remove(this);
		}

		private void OnEnable()
		{
			Loaded.Add(this);
			_on = true;
		}

		private void OnDisable()
		{
			Loaded.Remove(this);
			_on = false;
		}

		public void ShowMarks()
		{
			if (Marks != null && Marks.Length != 0)
			{
				int num = BeltLook.ChevronEvery?.Value ?? 4;
				for (int i = 0; i < Marks.Length; i++)
				{
					((Component)Marks[i]).gameObject.SetActive(num > 0 && i % num == 0);
				}
			}
		}

		internal void Advance(float dt)
		{
			if (_on && Object.op_Implicit((Object)(object)_power) && _power.Powered)
			{
				float num = Direction * (Object.op_Implicit((Object)(object)_mover) ? _mover.Speed : 0.6f) * dt;
				_travel = Mathf.Repeat(_travel + num, LoopLength);
				_spin = Mathf.Repeat(_spin + num, (float)Math.PI * 17f / 50f);
			}
		}

		internal static void AnimateAll(bool advance)
		{
			float deltaTime = Time.deltaTime;
			foreach (BeltAnimator item in Loaded)
			{
				if (Object.op_Implicit((Object)(object)item._power) && item._power.Powered && item.Seen())
				{
					if (advance)
					{
						item.Advance(deltaTime);
					}
					item.Layout(item._travel, item._spin);
				}
			}
		}

		private bool Seen()
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			if (Everywhere)
			{
				return true;
			}
			if (_viewsFrame != Time.frameCount)
			{
				FindViews();
			}
			Vector3 position = ((Component)this).transform.position;
			int num = 1 << ((Component)this).gameObject.layer;
			for (int i = 0; i < Cameras.Count; i++)
			{
				Camera val = Cameras[i];
				if (!Object.op_Implicit((Object)(object)val) || (val.cullingMask & num) == 0)
				{
					continue;
				}
				Vector3 val2 = ((Component)val).transform.position - position;
				if (!(((Vector3)(ref val2)).sqrMagnitude > 6400f))
				{
					Plane[] array = Views[i];
					bool flag = true;
					for (int j = 0; j < array.Length && flag; j++)
					{
						flag = ((Plane)(ref array[j])).GetDistanceToPoint(position) >= -4f;
					}
					if (flag)
					{
						return true;
					}
				}
			}
			return false;
		}

		private static void FindViews()
		{
			_viewsFrame = Time.frameCount;
			if (_all.Length < Camera.allCamerasCount)
			{
				_all = (Camera[])(object)new Camera[Camera.allCamerasCount * 2];
			}
			int allCameras = Camera.GetAllCameras(_all);
			Cameras.Clear();
			for (int i = 0; i < allCameras; i++)
			{
				if (Views.Count <= i)
				{
					Views.Add((Plane[])(object)new Plane[6]);
				}
				Cameras.Add(_all[i]);
				GeometryUtility.CalculateFrustumPlanes(_all[i], Views[i]);
			}
		}

		public void Layout(float travel, float spin)
		{
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			float num = LoopLength / (float)Slats.Length;
			for (int i = 0; i < Slats.Length; i++)
			{
				Place(Slats[i], (travel + (float)i * num) % LoopLength);
				if (Marks != null && Marks.Length > i)
				{
					Marks[i].SetLocalPositionAndRotation(Slats[i].localPosition, Slats[i].localRotation);
				}
			}
			Turn(spin);
		}

		internal void Turn(float spin)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: 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)
			Quaternion localRotation = Quaternion.Euler(spin / 0.17f * 57.29578f, 0f, 0f);
			Transform[] rollers = Rollers;
			for (int i = 0; i < rollers.Length; i++)
			{
				rollers[i].localRotation = localRotation;
			}
			Wheel.localRotation = localRotation;
		}

		private void Place(Transform slat, float s)
		{
			//IL_0005: 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)
			slat.localPosition = Pose(s, out var angle);
			slat.localRotation = Quaternion.Euler(angle * 57.29578f, 0f, 0f);
		}

		internal Vector3 Pose(float s, out float angle)
		{
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			float num = Span / 2f;
			float num2 = 0.17f;
			float num3 = 0.25f;
			float num4 = (float)Math.PI * num2;
			float num5;
			if (s < Span)
			{
				angle = 0f;
				num5 = 0f - num + s;
			}
			else if ((s -= Span) < num4)
			{
				angle = s / num2;
				num5 = num;
			}
			else if ((s -= num4) < Span)
			{
				angle = (float)Math.PI;
				num5 = num - s;
			}
			else
			{
				s -= Span;
				angle = (float)Math.PI + s / num2;
				num5 = 0f - num;
			}
			return new Vector3(0f, num3 + num2 * Mathf.Cos(angle), num5 + num2 * Mathf.Sin(angle));
		}
	}
	internal static class BeltFull
	{
		private delegate void SpawnCall(Smelter smelter, string ore, int stack);

		private delegate ItemConversion ConversionCall(Smelter smelter, string ore);

		private sealed class Spotted
		{
			public readonly Wait Wait = new Wait();

			public string Held;
		}

		private const string HeldKey = "conveyorbelts_held";

		private const string HeldCountKey = "conveyorbelts_heldn";

		private const float BeltBelow = 4f;

		public const string HoverText = "Belt full: waiting";

		private static readonly FieldRef<Smelter, ZNetView> View = AccessTools.FieldRefAccess<Smelter, ZNetView>("m_nview");

		private static readonly HashSet<Smelter> Holding = new HashSet<Smelter>();

		private static readonly Dictionary<Smelter, Spotted> Spots = new Dictionary<Smelter, Spotted>();

		private static readonly List<Smelter> Gone = new List<Smelter>();

		private static readonly List<Smelter> Looked = new List<Smelter>();

		private static readonly RaycastHit[] Below = (RaycastHit[])(object)new RaycastHit[16];

		private static int _groundMask;

		private static bool _dropping;

		private static readonly SpawnCall Spawn = AccessTools.MethodDelegate<SpawnCall>(AccessTools.Method(typeof(Smelter), "Spawn", (Type[])null, (Type[])null), (object)null, true);

		private static readonly ConversionCall Conversion = AccessTools.MethodDelegate<ConversionCall>(AccessTools.Method(typeof(Smelter), "GetItemConversion", (Type[])null, (Type[])null), (object)null, true);

		public static void Patch(Harmony harmony)
		{
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Expected O, but got Unknown
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Expected O, but got Unknown
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Expected O, but got Unknown
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Expected O, but got Unknown
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Expected O, but got Unknown
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Expected O, but got Unknown
			_groundMask = ~LayerMask.GetMask(new string[10] { "item", "character", "character_net", "character_noenv", "character_trigger", "character_ghost", "viewblock", "WaterVolume", "Water", "smoke" });
			harmony.Patch((MethodBase)AccessTools.Method(typeof(Smelter), "UpdateSmelter", (Type[])null, (Type[])null), new HarmonyMethod(typeof(BeltFull), "BeforeUpdate", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)AccessTools.Method(typeof(Smelter), "Spawn", (Type[])null, (Type[])null), new HarmonyMethod(typeof(BeltFull), "BeforeSpawn", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)AccessTools.Method(typeof(Smelter), "DropAllItems", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(BeltFull), "DropHeld", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)AccessTools.Method(typeof(Smelter), "IsActive", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(BeltFull), "NotActive", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)AccessTools.Method(typeof(Smelter), "OnHoverAddOre", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(BeltFull), "Hover", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)AccessTools.Method(typeof(Smelter), "OnHoverAddFuel", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(BeltFull), "Hover", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}

		public static bool Waiting(Smelter smelter)
		{
			ZNetView val = View.Invoke(smelter);
			if (Object.op_Implicit((Object)(object)val) && val.IsValid())
			{
				return val.GetZDO().GetInt("conveyorbelts_heldn", 0) > 0;
			}
			return false;
		}

		private static void BeforeUpdate(Smelter __instance)
		{
			ZNetView val = View.Invoke(__instance);
			if (!Object.op_Implicit((Object)(object)val) || !val.IsValid() || __instance.m_spawnStack)
			{
				return;
			}
			Path path;
			float place;
			bool flag = Spot(__instance, out path, out place);
			if (!flag)
			{
				Spots.Remove(__instance);
			}
			else
			{
				if (!Spots.TryGetValue(__instance, out var value))
				{
					value = (Spots[__instance] = new Spotted());
				}
				if (value.Wait.Path != path || value.Wait.Place != place)
				{
					value.Held = null;
				}
				value.Wait.Path = path;
				value.Wait.Place = place;
			}
			if (!val.IsOwner())
			{
				return;
			}
			List<string> list = Held(val.GetZDO());
			if (list.Count == 0)
			{
				return;
			}
			if (!flag)
			{
				foreach (string item in list)
				{
					DropReal(__instance, item);
				}
				SetHeld(val.GetZDO(), new List<string>());
			}
			else
			{
				Holding.Add(__instance);
				val.GetZDO().Set(ZDOVars.s_startTime, ZNet.instance.GetTime().Ticks);
			}
		}

		internal static void Holds()
		{
			List<Wait> waits = Runs.Waits;
			waits.Clear();
			if (Spots.Count == 0)
			{
				return;
			}
			Gone.Clear();
			foreach (KeyValuePair<Smelter, Spotted> spot in Spots)
			{
				Smelter key = spot.Key;
				Spotted value = spot.Value;
				ZNetView val = (Object.op_Implicit((Object)(object)key) ? View.Invoke(key) : null);
				if (!Object.op_Implicit((Object)(object)val) || !val.IsValid())
				{
					Gone.Add(key);
					continue;
				}
				ZDO zDO = val.GetZDO();
				if (zDO.GetInt("conveyorbelts_heldn", 0) > 0)
				{
					string text = zDO.GetString("conveyorbelts_held", "");
					if (text != value.Held)
					{
						value.Held = text;
						value.Wait.Half = Half(key, text, value.Wait);
					}
					if (value.Wait.Half > 0f)
					{
						waits.Add(value.Wait);
					}
				}
			}
			foreach (Smelter item in Gone)
			{
				Spots.Remove(item);
			}
		}

		internal static void Step()
		{
			if (Holding.Count == 0)
			{
				return;
			}
			Looked.Clear();
			Looked.AddRange(Holding);
			foreach (Smelter item in Looked)
			{
				ZNetView val = (Object.op_Implicit((Object)(object)item) ? View.Invoke(item) : null);
				if (!Object.op_Implicit((Object)(object)val) || !val.IsValid() || !val.IsOwner())
				{
					Holding.Remove(item);
					continue;
				}
				List<string> list = Held(val.GetZDO());
				if (list.Count > 0 && Spot(item, out var path, out var place) && PutOn(item, list[0], path, place))
				{
					list.RemoveAt(0);
				}
				else if (list.Count > 0)
				{
					continue;
				}
				SetHeld(val.GetZDO(), list);
				if (list.Count == 0)
				{
					Holding.Remove(item);
				}
			}
		}

		private static bool BeforeSpawn(Smelter __instance, string ore, int stack)
		{
			if (_dropping || __instance.m_spawnStack)
			{
				return true;
			}
			ZNetView val = View.Invoke(__instance);
			if (!Object.op_Implicit((Object)(object)val) || !val.IsValid() || !val.IsOwner() || !Spot(__instance, out var path, out var place))
			{
				return true;
			}
			List<string> list = Held(val.GetZDO());
			for (int i = 0; i < stack; i++)
			{
				if (list.Count > 0 || !PutOn(__instance, ore, path, place))
				{
					list.Add(ore);
				}
			}
			if (list.Count > 0)
			{
				SetHeld(val.GetZDO(), list);
				Holding.Add(__instance);
			}
			return false;
		}

		private static void DropHeld(Smelter __instance)
		{
			ZNetView val = View.Invoke(__instance);
			if (!Object.op_Implicit((Object)(object)val) || !val.IsValid())
			{
				return;
			}
			List<string> list = Held(val.GetZDO());
			foreach (string item in list)
			{
				DropReal(__instance, item);
			}
			if (list.Count > 0)
			{
				SetHeld(val.GetZDO(), new List<string>());
			}
			Holding.Remove(__instance);
		}

		private static void NotActive(Smelter __instance, ref bool __result)
		{
			if (__result && Waiting(__instance))
			{
				__result = false;
			}
		}

		private static void Hover(Smelter __instance, ref string __result)
		{
			if (__result != null && Waiting(__instance))
			{
				int num = __result.IndexOf('\n');
				string text = " <color=yellow>Belt full: waiting</color>";
				__result = ((num < 0) ? (__result + text) : __result.Insert(num, text));
			}
		}

		private static void DropReal(Smelter smelter, string ore)
		{
			_dropping = true;
			try
			{
				Spawn(smelter, ore, 1);
			}
			finally
			{
				_dropping = false;
			}
		}

		private static bool PutOn(Smelter smelter, string ore, Path path, float place)
		{
			//IL_00f7: 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_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			ItemConversion val = Conversion(smelter, ore);
			if (val == null || !Object.op_Implicit((Object)(object)val.m_to))
			{
				return true;
			}
			GameObject gameObject = ((Component)val.m_to).gameObject;
			Transform outputPoint = smelter.m_outputPoint;
			ItemData val2 = val.m_to.m_itemData.Clone();
			val2.m_dropPrefab = (Object.op_Implicit((Object)(object)ObjectDB.instance) ? ObjectDB.instance.GetItemPrefab(((Object)gameObject).name) : null);
			if (!Object.op_Implicit((Object)(object)val2.m_dropPrefab))
			{
				val2.m_dropPrefab = gameObject;
			}
			val2.m_stack = 1;
			ZDO zDO = View.Invoke(smelter).GetZDO();
			val2.m_worldLevel = (byte)Game.m_worldLevel;
			val2.m_cheated = (zDO.GetBool(ZDOVars.s_cheatedQueued, false) || zDO.GetBool(ZDOVars.s_cheated, false)) && !PlayerProfile.s_bypassCheatChecks;
			if (!path.Belt.Takes(ItemKind.Of(val2.m_dropPrefab), val2))
			{
				DropReal(smelter, ore);
				return true;
			}
			if (Runs.PutOn(val2, path, place, outputPoint.position, outputPoint.rotation, ZDOID.None, room: true) == null)
			{
				return false;
			}
			smelter.m_produceEffects.Create(((Component)smelter).transform.position, ((Component)smelter).transform.rotation, (Transform)null, 1f, -1, default(ZDOID));
			return true;
		}

		private static float Half(Smelter smelter, string held, Wait wait)
		{
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			int num = held.IndexOf(';');
			ItemConversion val = Conversion(smelter, (num < 0) ? held : held.Substring(0, num));
			if (val == null || !Object.op_Implicit((Object)(object)val.m_to))
			{
				return 0f;
			}
			return Runs.HalfOf(((Component)val.m_to).gameObject, val.m_to.m_itemData, wait.Path, wait.Place, smelter.m_outputPoint.rotation);
		}

		private static bool Spot(Smelter smelter, out Path path, out float place)
		{
			//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_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: 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_0100: 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_0118: Unknown result type (might be due to invalid IL or missing references)
			path = null;
			place = 0f;
			Transform outputPoint = smelter.m_outputPoint;
			if (!Object.op_Implicit((Object)(object)outputPoint))
			{
				return false;
			}
			int num = Physics.RaycastNonAlloc(outputPoint.position, Vector3.down, Below, 4f, _groundMask, (QueryTriggerInteraction)1);
			float num2 = float.MaxValue;
			Collider val = null;
			Vector3 val2 = Vector3.zero;
			for (int i = 0; i < num; i++)
			{
				if (!(((RaycastHit)(ref Below[i])).distance >= num2) && !((Object)(object)((Component)((RaycastHit)(ref Below[i])).collider).GetComponentInParent<Smelter>() == (Object)(object)smelter))
				{
					num2 = ((RaycastHit)(ref Below[i])).distance;
					val = ((RaycastHit)(ref Below[i])).collider;
					val2 = ((RaycastHit)(ref Below[i])).point;
				}
			}
			if (!Object.op_Implicit((Object)(object)val))
			{
				return false;
			}
			BeltPaths componentInParent = ((Component)val).GetComponentInParent<BeltPaths>();
			if (!Object.op_Implicit((Object)(object)componentInParent) || componentInParent.Paths.Length == 0 || !Object.op_Implicit((Object)(object)componentInParent.Frame))
			{
				return false;
			}
			if (componentInParent.Frame.InverseTransformPoint(val2).y > 0.74f)
			{
				return false;
			}
			path = Runs.PathOf(componentInParent, val2, out place);
			return path != null;
		}

		private static List<string> Held(ZDO zdo)
		{
			int num = zdo.GetInt("conveyorbelts_heldn", 0);
			List<string> list = new List<string>(num);
			if (num <= 0)
			{
				return list;
			}
			string[] array = zdo.GetString("conveyorbelts_held", "").Split(new char[1] { ';' });
			for (int i = 0; i < num; i++)
			{
				list.Add((i < array.Length) ? array[i] : array[^1]);
			}
			return list;
		}

		private static void SetHeld(ZDO zdo, List<string> held)
		{
			zdo.Set("conveyorbelts_held", string.Join(";", held));
			zdo.Set("conveyorbelts_heldn", held.Count);
		}
	}
	internal static class BeltLook
	{
		public static ConfigEntry<int> ChevronEvery;

		public static void Bind(ConfigFile config)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			ChevronEvery = config.Bind<int>("Look", "ChevronEvery", 4, new ConfigDescription("Every how many slats one carries a dark chevron that points the way the belt runs. 0 shows none.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 16), Array.Empty<object>()));
			ChevronEvery.SettingChanged += delegate
			{
				foreach (BeltAnimator item in BeltAnimator.Loaded)
				{
					item.ShowMarks();
				}
			};
		}
	}
	internal sealed class BeltLoop
	{
		public const float Gap = 0.1f;

		public const float EndReach = 0.1f;

		private const float HoldFor = 30f;

		internal readonly List<Belt> Belts = new List<Belt>();

		internal readonly List<Run> All = new List<Run>();

		internal bool Merging = true;

		internal readonly List<Wait> Waits = new List<Wait>();

		private readonly ILoopGame _game;

		private int _step;

		private float _now;

		private long _clock;

		private static readonly List<(RidingItem item, float ahead)> Nearby = new List<(RidingItem, float)>();

		internal int StepCount => _step;

		internal BeltLoop(ILoopGame game)
		{
			_game = game;
		}

		internal void Chain()
		{
			Dictionary<Path, Path> feeder = new Dictionary<Path, Path>();
			foreach (Belt belt in Belts)
			{
				Path[] paths = belt.Paths;
				for (int i = 0; i < paths.Length; i++)
				{
					paths[i].Feeders = 0;
				}
			}
			foreach (Belt belt2 in Belts)
			{
				Path[] paths = belt2.Paths;
				foreach (Path path in paths)
				{
					if (path.End != null && !path.End.Side)
					{
						Path path2 = path.End.To.Belt.Paths[0];
						path2.Feeders++;
						feeder[path2] = path;
					}
				}
			}
			All.Clear();
			HashSet<Path> hashSet = new HashSet<Path>();
			foreach (Belt belt3 in Belts)
			{
				Path[] paths = belt3.Paths;
				foreach (Path path3 in paths)
				{
					if (hashSet.Contains(path3))
					{
						continue;
					}
					Path path4 = path3;
					bool loop = false;
					for (int j = 0; j < 100000; j++)
					{
						Path path5 = Prev(path4);
						if (path5 == null)
						{
							break;
						}
						if (path5 == path3)
						{
							loop = true;
							path4 = path3;
							break;
						}
						path4 = path5;
					}
					Run run = new Run
					{
						Loop = loop
					};
					Path path6 = path4;
					while (path6 != null && !hashSet.Contains(path6))
					{
						hashSet.Add(path6);
						path6.Run = run;
						path6.RunIndex = run.Paths.Count;
						run.Paths.Add(path6);
						path6 = Next(path6);
					}
					run.Offsets = new float[run.Paths.Count];
					for (int k = 0; k < run.Paths.Count; k++)
					{
						run.Offsets[k] = run.Total;
						foreach (Hold hold in run.Paths[k].Holds)
						{
							run.Holds.Add(new Hold
							{
								Arch = hold.Arch,
								At = run.Total + hold.At
							});
						}
						run.Total += run.Paths[k].Length;
					}
					if (!run.Loop && Next(run.Paths[run.Paths.Count - 1]) == run.Paths[0])
					{
						run.Loop = true;
					}
					All.Add(run);
				}
			}
			static Path Next(Path p)
			{
				Join end = p.End;
				if (end != null && !end.Side && end.Filter == null && end.To.Feeders == 1 && (!end.To.Belt.Narrow || p.Belt.Narrow))
				{
					return end.To;
				}
				return null;
			}
			Path Prev(Path p)
			{
				if (p.Belt.Paths.Length != 1 || p.Feeders != 1 || !feeder.TryGetValue(p, out var value) || Next(value) != p)
				{
					return null;
				}
				return value;
			}
		}

		internal void Step(float dt, float now, long clock)
		{
			_step++;
			_now = now;
			_clock = clock;
			foreach (Wait wait in Waits)
			{
				wait.On = wait.Path.Run != null && FrontRides(wait);
			}
			foreach (Run item in All)
			{
				if (!item.Loop && item.Kind != End.Join && now >= item.CheckAt)
				{
					_game.Look(item);
				}
				Move(item, dt);
			}
		}

		private void Move(Run run, float dt)
		{
			//IL_0422: Unknown result type (might be due to invalid IL or missing references)
			//IL_0427: Unknown result type (might be due to invalid IL or missing references)
			//IL_0392: Unknown result type (might be due to invalid IL or missing references)
			//IL_0399: Unknown result type (might be due to invalid IL or missing references)
			//IL_04cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_04da: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_04fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0520: Unknown result type (might be due to invalid IL or missing references)
			int count = run.Paths.Count;
			RidingItem ridingItem = null;
			float num = 0f;
			if (run.Loop)
			{
				for (int i = 0; i < count; i++)
				{
					if (ridingItem != null)
					{
						break;
					}
					if (run.Paths[i].Items.Count > 0)
					{
						ridingItem = run.Paths[i].Items[0];
						num = run.Offsets[i] + ridingItem.Place + run.Total;
					}
				}
				if (ridingItem == null)
				{
					return;
				}
			}
			for (int num2 = count - 1; num2 >= 0; num2--)
			{
				Path path = run.Paths[num2];
				List<RidingItem> items = path.Items;
				if (items.Count != 0)
				{
					float num3 = run.Offsets[num2];
					float speed = path.Belt.Speed;
					for (int num4 = items.Count - 1; num4 >= 0; num4--)
					{
						if (num4 >= items.Count)
						{
							continue;
						}
						RidingItem ridingItem2 = items[num4];
						float num5 = num3 + ridingItem2.Place;
						if (ridingItem2.Step == _step)
						{
							ridingItem = ridingItem2;
							num = num5;
							continue;
						}
						ridingItem2.Step = _step;
						float num6 = num5 + speed * dt;
						ridingItem2.WaitsOn = null;
						ridingItem2.AtJoin = false;
						bool flag = ridingItem == null || ridingItem == ridingItem2;
						if (!flag)
						{
							bool flag2 = ridingItem.Held && Joins(ridingItem2, ridingItem);
							float num7 = num - (ridingItem.Half + ridingItem2.Half + (flag2 ? 0f : 0.1f));
							if (num6 > num7 || (flag2 && num6 >= num7))
							{
								if (flag2 && _game.Speaks(ridingItem2.Path) && Merge(ridingItem2, ridingItem))
								{
									continue;
								}
								num6 = num7;
								ridingItem2.WaitsOn = ridingItem;
							}
						}
						if (num2 == 0 && path.Belt.IsFilter)
						{
							num6 = Sibling(path, ridingItem2, num6);
						}
						if (run.Holds.Count > 0)
						{
							num6 = HoldAt(run, ridingItem2, num5, num6, num2, num4);
						}
						else
						{
							ridingItem2.HeldBy = (ridingItem2.LeftBy = null);
						}
						if (Waits.Count > 0)
						{
							num6 = WaitAt(run, ridingItem2, num5, num6);
						}
						if (flag && !run.Loop && run.Kind == End.Join)
						{
							Belt filter = run.Join.Filter;
							if (filter != null && run.Total - num6 - ridingItem2.Half <= 0.4f)
							{
								filter.Coming = ridingItem2;
								filter.ComingAt = _now;
							}
						}
						if (flag && !run.Loop && num6 > EndLimit(run, ridingItem2))
						{
							if (run.Kind == End.Join)
							{
								if (HandOver(ridingItem2, run.Join, num6 - run.Total))
								{
									continue;
								}
								ridingItem2.AtJoin = true;
							}
							else if (run.Kind == End.Air && num6 > run.Total + 0.1f && !_game.Speaks(path))
							{
								num6 = run.Total + 0.1f;
								if (ridingItem2.EndSince < 0f)
								{
									ridingItem2.EndSince = _now;
								}
								else if (_now - ridingItem2.EndSince > 3f)
								{
									_game.Dropped(ridingItem2);
									items.Remove(ridingItem2);
									continue;
								}
							}
							else if (run.Kind == End.Air && num6 > run.Total + 0.1f)
							{
								ridingItem2.Speed = speed;
								_game.Fell(ridingItem2, run, path.Tangent(path.Length) * speed);
								items.Remove(ridingItem2);
								continue;
							}
							if (run.Kind != End.Air)
							{
								num6 = EndLimit(run, ridingItem2);
							}
						}
						if (num6 < num5)
						{
							num6 = num5;
						}
						ridingItem2.Speed = (num6 - num5) / dt;
						if (num6 != num5)
						{
							path.Belt.Moved = true;
						}
						float num8 = num6 - num3;
						if (num8 > path.Length && (num2 < count - 1 || run.Loop))
						{
							items.RemoveAt(num4);
							Vector3 rideMiddle = ridingItem2.RideMiddle;
							int num9 = num2;
							do
							{
								num8 -= run.Paths[num9].Length;
								num9 = (num9 + 1) % count;
							}
							while (num8 > run.Paths[num9].Length && num9 != num2);
							ridingItem2.Path = run.Paths[num9];
							ridingItem2.Place = num8;
							ridingItem2.Path.Items.Insert(0, ridingItem2);
							ridingItem2.Path.Belt.Moved = true;
							if (ridingItem2.Path.Belt != path.Belt)
							{
								_game.Crossed(ridingItem2, path);
								Vector3 off = rideMiddle + path.Tangent(path.Length) * (num6 - num5) - ridingItem2.RideMiddle;
								if (((Vector3)(ref off)).sqrMagnitude > 2.5E-05f && ((Vector3)(ref off)).sqrMagnitude < 0.09f)
								{
									_game.Ease(ridingItem2, off);
								}
							}
							ridingItem = ridingItem2;
							num = num6;
						}
						else
						{
							ridingItem2.Place = num8;
							ridingItem = ridingItem2;
							num = num6;
						}
					}
				}
			}
		}

		private float WaitAt(Run run, RidingItem item, float at, float to)
		{
			foreach (Wait wait in Waits)
			{
				if (wait.On && wait.Path.Run == run)
				{
					float num = run.Offsets[wait.Path.RunIndex] + wait.Place - (wait.Half + item.Half + 0.1f) - 0.001f;
					if (run.Loop && num < at - 0.0001f)
					{
						num += run.Total;
					}
					if (at <= num + 0.0001f && to > num)
					{
						to = Mathf.Max(at, num);
					}
				}
			}
			return to;
		}

		private static bool FrontRides(Wait wait)
		{
			Near(wait.Path, wait.Place, 4f, Nearby);
			foreach (var (ridingItem, num) in Nearby)
			{
				if (num >= 0f && num < ridingItem.Half + wait.Half + 0.1f && !Rides(ridingItem))
				{
					return false;
				}
			}
			return true;
		}

		private static float EndLimit(Run run, RidingItem item)
		{
			if (run.Kind != End.Wall)
			{
				return run.Total;
			}
			return run.Total + Mathf.Min(0f, run.Wall - item.Half);
		}

		private static float Sibling(Path path, RidingItem item, float to)
		{
			if (item.Place >= 1f)
			{
				return to;
			}
			foreach (RidingItem item2 in path.Belt.Paths[1 - path.Index].Items)
			{
				if (item2.Place - item2.Half >= 1f)
				{
					break;
				}
				if (!(item2.Place < item.Place) && (item2.Place != item.Place || item2.Id >= item.Id))
				{
					float num = item2.Place - (item2.Half + item.Half + 0.1f);
					if (to > num)
					{
						to = num;
						item.WaitsOn = item2;
					}
					break;
				}
			}
			return to;
		}

		internal static Path Pick(Path path, float place, RidingItem item)
		{
			if (!path.Belt.IsFilter || !(place < 1f))
			{
				return path;
			}
			return path.Belt.Paths[path.Belt.Choose(item)];
		}

		private float HoldAt(Run run, RidingItem item, float at, float to, int i, int k)
		{
			Hold hold = null;
			float num = 0f;
			float num2 = Mathf.Max(at, to);
			foreach (Hold hold2 in run.Holds)
			{
				float num3 = hold2.At;
				if (run.Loop && num3 < at - 0.001f)
				{
					num3 += run.Total;
				}
				if (!(at > num3 + 0.001f) && !(num2 < num3))
				{
					hold = hold2;
					num = num3;
					break;
				}
			}
			if (hold == null || !hold.Arch.Stands || !Merging)
			{
				item.HeldBy = null;
				if (hold == null)
				{
					item.LeftBy = null;
				}
				return to;
			}
			if (hold.Arch == item.LeftBy)
			{
				return to;
			}
			float now = _now;
			if (item.HeldBy != hold.Arch)
			{
				item.HeldBy = null;
				if (!HasRoom(item) || !Joins(Behind(run, i, k), item))
				{
					return to;
				}
				item.HeldBy = hold.Arch;
				item.HeldAt = now;
			}
			else if (!HasRoom(item) || now - item.HeldAt >= 30f || !Joins(Behind(run, i, k), item))
			{
				item.HeldBy = null;
				item.LeftBy = hold.Arch;
				return to;
			}
			return Mathf.Max(at, Mathf.Min(to, num));
		}

		private static RidingItem Behind(Run run, int i, int k)
		{
			List<RidingItem> items = run.Paths[i].Items;
			if (k > 0)
			{
				return items[k - 1];
			}
			int count = run.Paths.Count;
			for (int j = 1; j <= count; j++)
			{
				int num = i - j;
				if (num < 0)
				{
					if (!run.Loop)
					{
						return null;
					}
					num += count;
				}
				List<RidingItem> items2 = run.Paths[num].Items;
				if (items2.Count > 0)
				{
					if (items2[items2.Count - 1] != items[k])
					{
						return items2[items2.Count - 1];
					}
					return null;
				}
			}
			return null;
		}

		private static bool HasRoom(RidingItem item)
		{
			return item.Item.m_stack < item.Item.m_shared.m_maxStackSize;
		}

		private bool Joins(RidingItem item, RidingItem stack)
		{
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			if (item == null || item == stack || !Merging)
			{
				return false;
			}
			ItemData item2 = item.Item;
			ItemData item3 = stack.Item;
			if (item2.m_shared.m_maxStackSize > 1 && item2.m_shared.m_name == item3.m_shared.m_name && item2.m_quality == item3.m_quality && item2.m_worldLevel == item3.m_worldLevel && item3.m_stack < item3.m_shared.m_maxStackSize)
			{
				return item.From == stack.From;
			}
			return false;
		}

		private bool Merge(RidingItem item, RidingItem into)
		{
			ItemData item2 = into.Item;
			int num = Mathf.Min(item2.m_shared.m_maxStackSize - item2.m_stack, item.Item.m_stack);
			item2.m_stack += num;
			into.HeldAt = _now;
			_game.Stacked(into);
			if (num < item.Item.m_stack)
			{
				ItemData item3 = item.Item;
				item3.m_stack -= num;
				_game.Stacked(item);
				return false;
			}
			Path path = item.Path;
			_game.Merged(item, into);
			path.Items.Remove(item);
			return true;
		}

		private bool HandOver(RidingItem item, Join join, float over)
		{
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: 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_0118: 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)
			Path to = join.To;
			float num = join.Place + Mathf.Max(over, 0f);
			Belt filter = join.Filter;
			if (filter != null)
			{
				to = filter.Paths[Mathf.Clamp(filter.Choose(item), 0, filter.Paths.Length - 1)];
				num = Mathf.Max(over, 0f);
			}
			else
			{
				to = Pick(to, num, item);
			}
			num = Mathf.Min(num, to.Length);
			if (!to.Belt.Takes(item) || !Room(to, num, item.Half, item))
			{
				return false;
			}
			if (to.Belt.IsFilter && num < 1f && !Clear(to.Belt.Paths[1 - to.Index], num, item.Half, item))
			{
				return false;
			}
			Vector3 rideMiddle = item.RideMiddle;
			Path path = item.Path;
			path.Items.Remove(item);
			path.Belt.Moved = true;
			Put(item, to, num, _clock);
			item.Step = _step;
			item.Offset += rideMiddle - item.RideMiddle;
			if (to.Belt != path.Belt)
			{
				_game.Crossed(item, path);
			}
			return true;
		}

		internal static bool Room(Path path, float place, float half, RidingItem not = null)
		{
			Run run = path.Run;
			if (run == null)
			{
				return Clear(path, place, half, not);
			}
			float num = run.Offsets[path.RunIndex] + place;
			for (int i = 0; i < run.Paths.Count; i++)
			{
				float num2 = run.Offsets[i];
				if (num2 + run.Paths[i].Length >= num - 6f && num2 <= num + 6f && !Clear(run.Paths[i], num - num2, half, not))
				{
					return false;
				}
				if (run.Loop && (!Clear(run.Paths[i], num - num2 + run.Total, half, not) || !Clear(run.Paths[i], num - num2 - run.Total, half, not)))
				{
					return false;
				}
			}
			return true;
		}

		private static bool Clear(Path path, float place, float half, RidingItem not)
		{
			foreach (RidingItem item in path.Items)
			{
				if (item != not && Mathf.Abs(item.Place - place) < item.Half + half + 0.1f)
				{
					return false;
				}
			}
			return true;
		}

		internal static void Put(RidingItem item, Path path, float place, long clock)
		{
			if (item.Path == null || item.Path.Belt != path.Belt)
			{
				item.EnteredAt = clock;
			}
			item.Path = path;
			item.Place = place;
			List<RidingItem> items = path.Items;
			int num = items.Count;
			while (num > 0 && items[num - 1].Place > place)
			{
				num--;
			}
			items.Insert(num, item);
			path.Belt.Moved = true;
		}

		internal static float MoveOn(Path path, float place, float half, float way)
		{
			float num = Mathf.Min(place + way, path.Length);
			RidingItem ridingItem = null;
			foreach (RidingItem item in path.Items)
			{
				if (item.Place > place && (ridingItem == null || item.Place < ridingItem.Place))
				{
					ridingItem = item;
				}
			}
			if (ridingItem != null)
			{
				num = Mathf.Min(num, ridingItem.Place - (ridingItem.Half + half + 0.1f));
			}
			return Mathf.Max(num, place);
		}

		internal static float FreePlace(Path path, float place, float half)
		{
			for (int i = 0; (float)i * 0.05f <= path.Length; i++)
			{
				float num = place - (float)i * 0.05f;
				float num2 = place + (float)i * 0.05f;
				if (num >= 0f && Room(path, num, half))
				{
					return num;
				}
				if (num2 <= path.Length && Room(path, num2, half))
				{
					return num2;
				}
			}
			return place;
		}

		internal static bool RideRoom(Path path, ref float place, float half)
		{
			Near(path, place, 4f, Nearby);
			float num = 0f;
			foreach (var (ridingItem, num2) in Nearby)
			{
				if (!(num2 < 0f) && !(num2 >= ridingItem.Half + half + 0.1f))
				{
					if (!Rides(ridingItem))
					{
						return false;
					}
					num = Mathf.Min(num, num2 - (ridingItem.Half + half + 0.1f));
				}
			}
			foreach (var (ridingItem2, num3) in Nearby)
			{
				if (num3 < 0f && Mathf.Abs(num3 - num) < ridingItem2.Half + half + 0.1f)
				{
					return false;
				}
			}
			place += num;
			return true;
		}

		private static bool Rides(RidingItem item)
		{
			Belt belt = item.Path.Belt;
			if (belt.Speed > 0f)
			{
				return item.Speed >= 0.5f * belt.Speed;
			}
			return false;
		}

		internal static void Near(Path path, float place, float reach, List<(RidingItem item, float ahead)> found)
		{
			found.Clear();
			Run run = path.Run;
			if (run == null)
			{
				foreach (RidingItem item in path.Items)
				{
					if (Mathf.Abs(item.Place - place) < reach)
					{
						found.Add((item, item.Place - place));
					}
				}
				return;
			}
			float num = run.Offsets[path.RunIndex] + place;
			for (int i = 0; i < run.Paths.Count; i++)
			{
				foreach (RidingItem item2 in run.Paths[i].Items)
				{
					float num2 = run.Offsets[i] + item2.Place - num;
					if (run.Loop && num2 > run.Total / 2f)
					{
						num2 -= run.Total;
					}
					else if (run.Loop && num2 < (0f - run.Total) / 2f)
					{
						num2 += run.Total;
					}
					if (Mathf.Abs(num2) < reach)
					{
						found.Add((item2, num2));
					}
				}
			}
		}
	}
	internal static class BeltMerge
	{
		public static ConfigEntry<bool> Items;

		public static bool On
		{
			get
			{
				if (Items != null)
				{
					return Items.Value;
				}
				return false;
			}
		}

		public static void Bind(ConfigFile config)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Expected O, but got Unknown
			Items = config.Bind<bool>("Belts", "MergeItems", true, new ConfigDescription("On: a merger holds the item under it while items of the same kind behind it ride up and stack into it, so fewer items ride and the game runs faster. Off: mergers hold nothing, and every item rides on its own.", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
		}
	}
	public class BeltMover : MonoBehaviour
	{
		private static readonly Vector3 ZoneCenter = new Vector3(0f, 0.74f, 0f);

		public Transform Frame;

		public Vector3 HalfSize;

		public int Turn;

		public float Direction = 1f;

		public bool Creatures = true;

		public bool Narrow;

		public float Speed = 0.6f;

		private const float LanePull = 1.5f;

		private const float WallSkin = 0.02f;

		private const float HeadOn = 0.8f;

		private const float ExitReach = 0.3f;

		private static readonly Collider[] Hits = (Collider[])(object)new Collider[32];

		private static int _creatureMask;

		private static int _groundMask;

		private static readonly HashSet<BeltMover> All = new HashSet<BeltMover>();

		private readonly List<BeltMover> _near = new List<BeltMover>();

		private float _nearAt = -1f;

		private const float NearFor = 5f;

		private const float NearReach = 5f;

		private static readonly HashSet<Character> Pushed = new HashSet<Character>();

		private static float _pushedStep = -1f;

		private const int IdleEvery = 5;

		private const float AwakeFor = 0.5f;

		private static int _step;

		private float _awakeUntil;

		private float _wokeNearAt = -1f;

		private int _idleTurn;

		private ZNetView _nview;

		private ItemFilter _filter;

		private PowerNode _power;

		private void Awake()
		{
			_nview = ((Component)this).GetComponent<ZNetView>();
			_filter = ((Component)this).GetComponent<ItemFilter>();
			_power = ((Component)this).GetComponent<PowerNode>();
			if (_creatureMask == 0)
			{
				_creatureMask = LayerMask.GetMask(new string[3] { "character", "character_net", "character_noenv" });
				_groundMask = LayerMask.GetMask(new string[5] { "piece", "piece_nonsolid", "Default", "static_solid", "terrain" });
			}
		}

		private void Start()
		{
			if (Object.op_Implicit((Object)(object)_nview) && _nview.IsValid())
			{
				All.Add(this);
			}
			_idleTurn = (((Object)this).GetInstanceID() & 0x7FFFFFFF) % 5;
		}

		public void Stop(bool stop)
		{
			((Behaviour)this).enabled = !stop;
		}

		private void OnDestroy()
		{
			All.Remove(this);
		}

		private void FixedUpdate()
		{
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			if (!Object.op_Implicit((Object)(object)_nview) || !_nview.IsValid() || !_power.Powered || !Creatures)
			{
				return;
			}
			if (Time.fixedTime != _pushedStep)
			{
				Pushed.Clear();
				_pushedStep = Time.fixedTime;
				_step++;
			}
			if (Time.fixedTime >= _awakeUntil && _step % 5 != _idleTurn)
			{
				return;
			}
			Transform val = (Object.op_Implicit((Object)(object)Frame) ? Frame : ((Component)this).transform);
			int num = Physics.OverlapBoxNonAlloc(val.TransformPoint(ZoneCenter), HalfSize + new Vector3(0.3f, 0f, 0.3f), Hits, val.rotation, _creatureMask, (QueryTriggerInteraction)1);
			if (num > 0)
			{
				Wake();
			}
			Character creature = default(Character);
			for (int i = 0; i < num; i++)
			{
				Rigidbody attachedRigidbody = Hits[i].attachedRigidbody;
				if (Object.op_Implicit((Object)(object)attachedRigidbody) && ((Component)attachedRigidbody).TryGetComponent<Character>(ref creature))
				{
					CarryCreature(val, creature, attachedRigidbody);
				}
			}
		}

		private void Wake()
		{
			float num = (_awakeUntil = Time.fixedTime + 0.5f);
			if (Time.fixedTime < _wokeNearAt + 0.1f)
			{
				return;
			}
			_wokeNearAt = Time.fixedTime;
			foreach (BeltMover item in Near())
			{
				if (Object.op_Implicit((Object)(object)item))
				{
					item._awakeUntil = Mathf.Max(item._awakeUntil, num);
				}
			}
		}

		private List<BeltMover> Near()
		{
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			if (Time.fixedTime < _nearAt)
			{
				return _near;
			}
			_nearAt = Time.fixedTime + 5f;
			_near.Clear();
			foreach (BeltMover item in All)
			{
				if (Object.op_Implicit((Object)(object)item) && (Object)(object)item != (Object)(object)this)
				{
					Vector3 val = ((Component)item).transform.position - ((Component)this).transform.position;
					if (((Vector3)(ref val)).sqrMagnitude <= 25f)
					{
						_near.Add(item);
					}
				}
			}
			return _near;
		}

		private void CarryCreature(Transform frame, Character creature, Rigidbody body)
		{
			//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_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: 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_0062: 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)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: 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_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c9: 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_02e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ef: 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_02f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fe: 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_0305: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0205: 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_033e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0340: Unknown result type (might be due to invalid IL or missing references)
			//IL_0348: Unknown result type (might be due to invalid IL or missing references)
			//IL_0358: Unknown result type (might be due to invalid IL or missing references)
			//IL_035d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0362: Unknown result type (might be due to invalid IL or missing references)
			//IL_0367: Unknown result type (might be due to invalid IL or missing references)
			//IL_0369: Unknown result type (might be due to invalid IL or missing references)
			//IL_036b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0373: 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_038f: Unknown result type (might be due to invalid IL or missing references)
			//IL_039b: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_030b: Unknown result type (might be due to invalid IL or missing references)
			//IL_030d: Unknown result type (might be due to invalid IL or missing references)
			//IL_030f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0311: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_031f: Unknown result type (might be due to invalid IL or missing references)
			//IL_032b: 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_0335: 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_0233: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_0243: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0220: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ac: 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_03b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c2: 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_03c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0248: 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_024c: 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_03da: Unknown result type (might be due to invalid IL or missing references)
			//IL_03df: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0296: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bc: 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_02c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ca: Unknown result type (might be due to invalid IL or missing references)
			if (creature.IsPlayer() || creature.IsDead() || creature.HaveRider() || Pushed.Contains(creature) || Grinder.Holds(creature))
			{
				return;
			}
			Vector3 val = frame.InverseTransformPoint(((Component)creature).transform.position) - ZoneCenter;
			float num = Mathf.Abs(val.x) - HalfSize.x;
			float num2 = Mathf.Abs(val.z) - HalfSize.z;
			bool flag = num > 0f || num2 > 0f;
			if ((num > 0f && num2 > 0f) || (!flag && Mathf.Abs(val.y) > HalfSize.y))
			{
				return;
			}
			if (flag)
			{
				Vector3 val2 = frame.TransformPoint(new Vector3(Mathf.Clamp(val.x, 0f - HalfSize.x, HalfSize.x), 0.44f, Mathf.Clamp(val.z, 0f - HalfSize.z, HalfSize.z)));
				float num3 = ((Component)creature).transform.position.y - val2.y;
				if (num3 < -0.3f || num3 > 2f * HalfSize.y)
				{
					return;
				}
			}
			ZNetView component = ((Component)creature).GetComponent<ZNetView>();
			if (!Object.op_Implicit((Object)(object)component) || !component.IsValid() || !component.IsOwner())
			{
				return;
			}
			Vector3 pull = Vector3.zero;
			bool flag2 = Turn == 0 || (Object.op_Implicit((Object)(object)_filter) && _filter.CreatureGoesStraight(creature));
			Vector3 val3 = (flag2 ? (frame.forward * Direction) : CornerDirection(body.position, out pull));
			if (Turn == 0 && Mathf.Abs(val.x) + creature.GetRadius() > HalfSize.x)
			{
				pull = frame.right * ((0f - val.x) * 1.5f);
			}
			Vector3 val5;
			if (flag)
			{
				Vector3 val4 = ((num > 0f) ? (frame.right * Mathf.Sign(val.x)) : (frame.forward * Mathf.Sign(val.z)));
				bool flag3 = Vector3.Dot(val3, val4) >= 0.8f;
				bool flag4 = Turn == 0 && Mathf.Max(num, num2) <= 0.5f * creature.GetRadius();
				if (flag3 ? OtherBeltBelow(((Component)creature).transform.position) : (!flag4))
				{
					return;
				}
				if (flag3)
				{
					if (val3.y < 0f)
					{
						val5 = Vector3.ProjectOnPlane(val3, Vector3.up);
						val3 = ((Vector3)(ref val5)).normalized;
					}
					pull = Vector3.zero;
				}
			}
			Pushed.Add(creature);
			Vector3 walk = Vector3.ProjectOnPlane(body.linearVelocity, Vector3.up);
			Vector3 val6 = Speed * val3 + pull;
			if (flag2)
			{
				Vector3 val7 = val6;
				val5 = Vector3.ProjectOnPlane(val3, Vector3.up);
				val6 = val7 + Back(walk, ((Vector3)(ref val5)).normalized) * ((Vector3)(ref val3)).normalized;
			}
			else
			{
				val6 += Back(walk, ((Component)this).transform.forward) * ((Component)this).transform.forward;
				val6 += Back(walk, ((Component)this).transform.right * (float)Turn) * (((Component)this).transform.right * (float)Turn);
			}
			val6 *= Time.fixedDeltaTime;
			val6 = CreatureStep(body, val6);
			if (!(val6 == Vector3.zero) && !TrashBin.Blocks(body.position, body.position + val6, creature.GetRadius()))
			{
				body.position += val6;
			}
		}

		private static float Back(Vector3 walk, Vector3 way)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			return Mathf.Max(0f - Vector3.Dot(walk, way), 0f);
		}

		private bool OtherBeltBelow(Vector3 point)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			RaycastHit val = default(RaycastHit);
			if (!Physics.Raycast(point + Vector3.up * 0.5f, Vector3.down, ref val, 0.65f, _groundMask, (QueryTriggerInteraction)1))
			{
				return false;
			}
			BeltMover componentInParent = ((Component)((RaycastHit)(ref val)).collider).GetComponentInParent<BeltMover>();
			if (Object.op_Implicit((Object)(object)componentInParent))
			{
				return (Object)(object)componentInParent != (Object)(object)this;
			}
			return false;
		}

		private static bool Blocked(Rigidbody body, Vector3 step, out RaycastHit hit)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			if (!body.SweepTest(((Vector3)(ref step)).normalized, ref hit, ((Vector3)(ref step)).magnitude + 0.02f, (QueryTriggerInteraction)1))
			{
				return false;
			}
			if (Object.op_Implicit((Object)(object)((Component)((RaycastHit)(ref hit)).collider).GetComponentInParent<BeltMover>()) && !Object.op_Implicit((Object)(object)((Component)((RaycastHit)(ref hit)).collider).GetComponent<BeltWall>()))
			{
				return false;
			}
			if (Object.op_Implicit((Object)(object)((RaycastHit)(ref hit)).rigidbody))
			{
				return !Object.op_Implicit((Object)(object)((Component)((RaycastHit)(ref hit)).rigidbody).GetComponent<ItemDrop>());
			}
			return true;
		}

		private static Vector3 CreatureStep(Rigidbody body, Vector3 step)
		{
			//IL_0005: 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_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: 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_0055: 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_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < 2; i++)
			{
				if (!Blocked(body, step, out var hit))
				{
					return step;
				}
				Vector3 val = Vector3.ProjectOnPlane(((RaycastHit)(ref hit)).normal, Vector3.up);
				if (((Vector3)(ref val)).magnitude < 0.5f)
				{
					return Vector3.zero;
				}
				((Vector3)(ref val)).Normalize();
				float num = 0f - Vector3.Dot(((Vector3)(ref step)).normalized, val);
				if (num > 0.8f)
				{
					return Vector3.zero;
				}
				if (num > 0f)
				{
					step += num * ((Vector3)(ref step)).magnitude * val;
				}
			}
			return step;
		}

		public static bool Road(Vector3 worldPos)
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: 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_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			foreach (BeltMover item in All)
			{
				if (Object.op_Implicit((Object)(object)item))
				{
					Vector3 val = (Object.op_Implicit((Object)(object)item.Frame) ? item.Frame : ((Component)item).transform).InverseTransformPoint(worldPos);
					if (Mathf.Abs(val.x) <= item.HalfSize.x + 0.3f && Mathf.Abs(val.z - ZoneCenter.z) <= item.HalfSize.z && val.y >= -0.16000003f && val.y <= 2.94f)
					{
						return true;
					}
				}
			}
			return false;
		}

		public Vector3 FlowAt(Vector3 worldPos)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: 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)
			Vector3 pull;
			if (Turn != 0)
			{
				return CornerDirection(worldPos, out pull);
			}
			return (Object.op_Implicit((Object)(object)Frame) ? Frame : ((Component)this).transform).forward * Direction;
		}

		private Vector3 CornerDirection(Vector3 worldPos, out Vector3 pull)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: 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_0095: 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)
			Vector3 val = ((Component)this).transform.InverseTransformPoint(worldPos);
			float z = HalfSize.z;
			float num = val.x - (float)Turn * z;
			float num2 = val.z + z;
			float num3 = Mathf.Max(Mathf.Sqrt(num * num + num2 * num2), 0.2f);
			pull = ((Component)this).transform.TransformDirection(new Vector3(num, 0f, num2) / num3 * ((z - num3) * 1.5f));
			return ((Component)this).transform.TransformDirection(new Vector3(num2, 0f, 0f - num) * ((float)Turn / num3));
		}

		private static Vector3 StraightPull(Transform frame, Vector3 worldPos)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			return frame.right * ((0f - frame.InverseTransformPoint(worldPos).x) * 1.5f);
		}
	}
	public class BeltPaths : MonoBehaviour
	{
		internal const string Key = "conveyorbelts_riding";

		private static readonly int KeyHash = StringExtensionMethods.GetStableHashCode("conveyorbelts_riding");

		private static readonly Vector3 ZoneCenter = new Vector3(0f, 0.74f, 0f);

		private const float SideReach = 0.3f;

		internal ZNetView View;

		internal BeltMover Mover;

		internal PowerNode Power;

		internal Transform Frame;

		internal readonly Belt Belt = new Belt();

		internal float SavedAt = -100f;

		internal float SoonAt;

		internal readonly List<int> SavedIds = new List<int>();

		internal Vector3 Middle;

		private ZDO _zdo;

		private bool _gone;

		private ItemFilter _filter;

		internal const float Shared = 1f;

		internal uint Revision;

		internal long CopyStamp;

		private static readonly List<Runs.Record> Records = new List<Runs.Record>();

		private static readonly List<Runs.Record> Saving = new List<Runs.Record>();

		internal Path[] Paths
		{
			get
			{
				return Belt.Paths;
			}
			set
			{
				Belt.Paths = value;
			}
		}

		internal float Speed
		{
			get
			{
				return Belt.Speed;
			}
			set
			{
				Belt.Speed = value;
			}
		}

		internal bool Moved
		{
			get
			{
				return Belt.Moved;
			}
			set
			{
				Belt.Moved = value;
			}
		}

		internal bool IsFilter => Belt.IsFilter;

		internal RidingItem Coming => Belt.Coming;

		internal float ComingAt => Belt.ComingAt;

		internal bool Owner
		{
			get
			{
				if (_zdo != null)
				{
					return _zdo.IsOwner();
				}
				return false;
			}
		}

		internal bool HasOwner
		{
			get
			{
				if (_zdo != null)
				{
					return _zdo.HasOwner();
				}
				return false;
			}
		}

		internal ZDO Zdo => _zdo;

		private void Awake()
		{
			View = ((Component)this).GetComponent<ZNetView>();
			Mover = ((Component)this).GetComponent<BeltMover>();
			Power = ((Component)this).GetComponent<PowerNode>();
			_filter = ((Component)this).GetComponent<ItemFilter>();
			Belt.Piece = this;
			Belt.Choice = Choose;
		}

		private void Start()
		{
			//IL_006b: 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)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)View) && View.IsValid() && Object.op_Implicit((Object)(object)Mover))
			{
				_zdo = View.GetZDO();
				Frame = (Object.op_Implicit((Object)(object)Mover.Frame) ? Mover.Frame : ((Component)this).transform);
				Middle = Frame.TransformPoint(ZoneCenter);
				if (Mover.Narrow)
				{
					Belt.Fit = NarrowFit.Fits;
				}
				BuildPaths();
				Runs.Register(this);
				Hands.Register(this);
				Sync.Register(this);
				Load();
			}
		}

		private void OnDestroy()
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			if (_zdo != null)
			{
				if (!_gone && ZDOMan.instance != null && ZDOMan.instance.GetZDO(_zdo.m_uid) == _zdo && _zdo.IsOwner() && Moved)
				{
					Save();
				}
				Runs.Unregister(this);
				_zdo = null;
			}
		}

		private void BuildPaths()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: 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_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: 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_01d8: 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_01eb: 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_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: 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_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: 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_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0187: Unknown result type (might be due to invalid IL or missing references)
			float num = 0.44f;
			Vector3 up = Frame.up;
			int turn = Mover.Turn;
			if (turn == 0)
			{
				float z = Mover.HalfSize.z;
				float direction = Mover.Direction;
				Paths = new Path[1] { Path.Line(Belt, 0, up, Frame.TransformPoint(new Vector3(0f, num, (0f - direction) * z)), Frame.TransformPoint(new Vector3(0f, num, direction * z))) };
			}
			else if (Object.op_Implicit((Object)(object)_filter))
			{
				Paths = new Path[2]
				{
					Path.Line(Belt, 0, up, Frame.TransformPoint(new Vector3(0f, num, -1f)), Frame.TransformPoint(new Vector3(0f, num, 1f))),
					Path.Line(Belt, 1, up, Frame.TransformPoint(new Vector3(0f, num, -1f)), Frame.TransformPoint(new Vector3(0f, num, 0f)), Frame.TransformPoint(new Vector3((float)turn, num, 0f)))
				};
			}
			else
			{
				Paths = new Path[1] { Path.Quarter(Belt, up, Frame.TransformPoint(new Vector3((float)turn * Mover.HalfSize.z, num, 0f - Mover.HalfSize.z)), Frame.right * (float)(-turn), Frame.forward, Mover.HalfSize.z) };
			}
		}

		internal bool InZone(Vector3 point, float endReach = 0f, float over = 1.25f)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: 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_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: 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_0066: 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)
			Vector3 val = Frame.InverseTransformPoint(point) - ZoneCenter;
			Vector3 halfSize = Mover.HalfSize;
			if (Mathf.Abs(val.x) <= halfSize.x + 0.3f && Mathf.Abs(val.z) <= halfSize.z + endReach && val.y >= 0f - halfSize.y - 0.3f)
			{
				return val.y <= Mathf.Min(halfSize.y + 0.6f, over - 0.3f);
			}
			return false;
		}

		internal Bounds ZoneBounds()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: 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_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_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: 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_0078: 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)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = Mover.HalfSize + new Vector3(0.3f, 0f, 0.3f);
			Bounds result = default(Bounds);
			((Bounds)(ref result))..ctor(Frame.TransformPoint(ZoneCenter), Vector3.zero);
			for (int i = 0; i < 4; i++)
			{
				((Bounds)(ref result)).Encapsulate(Frame.TransformPoint(ZoneCenter + new Vector3(((i & 1) == 0) ? (0f - val.x) : val.x, 0f, ((i & 2) == 0) ? (0f - val.z) : val.z)));
			}
			return result;
		}

		internal int Choose(RidingItem item)
		{
			return Choose(item.Kind.Name);
		}

		internal int Choose(string kind)
		{
			if (!Object.op_Implicit((Object)(object)_filter) || !_filter.Valid || _filter.KindGoesStraight(kind))
			{
				return 0;
			}
			return 1;
		}

		internal bool Turning()
		{
			if (!IsFilter)
			{
				return false;
			}
			if (Paths[1].Items.Count > 0)
			{
				return true;
			}
			if (Coming != null && Coming.Path != null && Time.time - ComingAt < 0.25f)
			{
				return Choose(Coming) == 1;
			}
			return false;
		}

		internal void TakenDown()
		{
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			if (_zdo == null)
			{
				return;
			}
			_gone = true;
			if (Object.op_Implicit((Object)(object)View) && View.IsValid() && View.IsOwner())
			{
				Path[] paths = Paths;
				foreach (Path path in paths)
				{
					for (int num = path.Items.Count - 1; num >= 0; num--)
					{
						Runs.MakeReal(path.Items[num], Vector3.zero, asShown: true);
					}
				}
			}
			Runs.Unregister(this);
			_zdo = null;
		}

		internal void Save()
		{
			//IL_013c: 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)
			if (_zdo == null || !_zdo.IsOwner())
			{
				return;
			}
			int num = 0;
			Path[] paths = Paths;
			foreach (Path path in paths)
			{
				num += path.Items.Count;
			}
			Moved = false;
			SavedAt = Time.time;
			if (SoonAt > 0f && Time.time >= SoonAt)
			{
				SoonAt = 0f;
			}
			if (num == 0 && SavedIds.Count == 0 && _zdo.GetByteArray(KeyHash, (byte[])null) == null)
			{
				return;
			}
			long num2 = Runs.Stamp();
			Runs.Unlist(this);
			SavedIds.Clear();
			Saving.Clear();
			paths = Paths;
			foreach (Path path2 in paths)
			{
				foreach (RidingItem item in path2.Items)
				{
					Saving.Add(new Runs.Record
					{
						Id = item.Id,
						Path = path2.Index,
						Place = item.Place,
						Moving = (item.Speed > 0.001f),
						From = item.From,
						Data = item.Item
					});
					item.Stamp = num2;
					SavedIds.Add(item.Id);
				}
			}
			Runs.List(this);
			_zdo.Set(KeyHash, Snapshot.Write(num2, Saving));
			Saving.Clear();
			Revision = _zdo.DataRevision;
			CopyStamp = num2;
		}

		private void Load()
		{
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			Revision = _zdo.DataRevision;
			if (!Read(out var stamp, Records))
			{
				return;
			}
			CopyStamp = stamp;
			long local = Runs.Local(stamp, _zdo.GetOwner());
			foreach (Runs.Record record in Records)
			{
				Runs.Load(record.Id, record.Data, record.From, Paths[(record.Path == 1 && Paths.Length > 1) ? 1 : 0], record.Place, stamp, local);
				SavedIds.Add(record.Id);
			}
			Runs.List(this);
			if (!_zdo.IsOwner() && _zdo.HasOwner())
			{
				View.InvokeRPC("conveyorbelts_fresh", Array.Empty<object>());
			}
		}

		internal bool Read(out long stamp, List<Runs.Record> records)
		{
			ZDO zdo = _zdo;
			if (!Snapshot.Read((zdo != null) ? zdo.GetByteArray(KeyHash, (byte[])null) : null, out stamp, records))
			{
				return false;
			}
			ItemDrop val2 = default(ItemDrop);
			for (int num = records.Count - 1; num >= 0; num--)
			{
				Runs.Record value = records[num];
				GameObject val = (Object.op_Implicit((Object)(object)ObjectDB.instance) ? ObjectDB.instance.GetItemPrefab(value.Prefab) : null);
				if (!Object.op_Implicit((Object)(object)val) || !val.TryGetComponent<ItemDrop>(ref val2))
				{
					Logger.LogWarning((object)$"A riding item on {((Object)this).name} is of a kind this game does not know (hash {value.Prefab}): left out");
					records.RemoveAt(num);
				}
				else
				{
					value.Data.m_dropPrefab = val;
					value.Data.m_shared = val2.m_itemData.m_shared;
					if (Paths.Length == 1)
					{
						value.Path = 0;
					}
					records[num] = value;
				}
			}
			return true;
		}
	}
	internal static class BeltPickup
	{
		public static ConfigEntry<bool> FromBelts;

		public static void Bind(ConfigFile config)
		{
			FromBelts = config.Bind<bool>("Pickup", "AutoPickupFromBelts", false, "Off: your auto-pickup leaves items alone that ride on a belt, ramp, corner, item filter, grinder or link. E still picks them up. On: it takes them, as in vanilla. Only your own game reads this.");
		}
	}
	internal static class BeltPiece
	{
		private enum Kind
		{
			Straight,
			Corner,
			Ramp,
			Grinder,
			Filter,
			Link,
			Kitchen
		}

		private class Spec
		{
			public string Name;

			public string Label;

			public string Description = "A wooden conveyor belt. Moves dropped items and creatures.";

			public Kind Kind;

			public float Size = 2f;

			public float Width = 2f;

			public int Turn;

			public int Rise;

			public int Dir = 1;

			public bool Pillars = true;
		}

		private class Parts
		{
			public Mesh BoxMesh;

			public Mesh LogMesh;

			public Mesh WheelMesh;

			public Mesh StoneMesh;

			public Mesh StakeMesh;

			public Mesh WallMesh;

			public Material Wood;

			public Material LogMat;

			public Material Dark;

			public Material Mark;

			public Material[] WheelMats;

			public Material[] StoneMats;

			public Material[] StakeMats;

			public Material[] WallMats;

			public Vector3 WheelCenter;

			public Vector3 WallScale;

			public Quaternion WallRot;

			public Bounds WallBounds;
		}

		public const float EndInset = 0.1f;

		public const float RollerY = 0.25f;

		public const float RollerRadius = 0.15f;

		public const float SlatThickness = 0.04f;

		public const float SlatWidth = 1.6f;

		public const float SlatDepth = 0.24f;

		public static readonly float SlatSpacing = LoopLength(1.8f) / 16f;

		public const float Speed = 0.6f;

		public const float PathRadius = 0.17f;

		public const float TopY = 0.44f;

		public const float WheelRadius = 0.25f;

		private const float RailX = 0.86f;

		private const float WheelNotch = 0.3f;

		public const float SnapDrop = 0.1f;

		private static readonly PowerKind[] PowerKinds = new PowerKind[7]
		{
			PowerKind.Belt,
			PowerKind.Corner,
			PowerKind.Ramp,
			PowerKind.Grinder,
			PowerKind.ItemFilter,
			PowerKind.Link,
			PowerKind.Link
		};

		private const string FilterText = "A conveyor belt with a side exit. What it is set to turns to the side, the rest goes straight on. Set it with a hotbar key; a trophy sets a creature kind. Shift+E swaps: the set kind goes straight, the rest turns.";

		private static readonly Spec[] Specs = new Spec[26]
		{
			new Spec
			{
				Name = "piece_conveyorbelt_1m",
				Label = "Conveyor belt (1 m)",
				Size = 1f
			},
			new Spec
			{
				Name = "piece_conveyorbelt",
				Label = "Conveyor belt (2 m)"
			},
			new Spec
			{
				Name = "piece_conveyorbelt_4m",
				Label = "Conveyor belt (4 m)",
				Size = 4f
			},
			new Spec
			{
				Name = "piece_conveyorcorner_right",
				Label = "Conveyor corner (right)",
				Kind = Kind.Corner,
				Turn = 1
			},
			new Spec
			{
				Name = "piece_conveyorcorner_left",
				Label = "Conveyor corner (left)",
				Kind = Kind.Corner,
				Turn = -1
			},
			new Spec
			{
				Name = "piece_conveyorramp_up_1m",
				Label = "Conveyor ramp (up, 1 m rise)",
				Kind = Kind.Ramp,
				Rise = 1
			},
			new Spec
			{
				Name = "piece_conveyorramp_down_1m",
				Label = "Conveyor ramp (down, 1 m rise)",
				Kind = Kind.Ramp,
				Rise = 1,
				Dir = -1
			},
			new Spec
			{
				Name = "piece_conveyorramp_up_2m",
				Label = "Conveyor ramp (up, 2 m rise)",
				Kind = Kind.Ramp,
				Rise = 2
			},
			new Spec
			{
				Name = "piece_conveyorramp_down_2m",
				Label = "Conveyor ramp (down, 2 m rise)",
				Kind = Kind.Ramp,
				Rise = 2,
				Dir = -1
			},
			new Spec
			{
				Name = "piece_conveyorramp_up_1m_nopillars",
				Label = "Conveyor ramp (up, 1 m rise, no pillars)",
				Kind = Kind.Ramp,
				Rise = 1,
				Pillars = false
			},
			new Spec
			{
				Name = "piece_conveyorramp_down_1m_nopillars",
				Label = "Conveyor ramp (down, 1 m rise, no pillars)",
				Kind = Kind.Ramp,
				Rise = 1,
				Dir = -1,
				Pillars = false
			},
			new Spec
			{
				Name = "piece_conveyorramp_up_2m_nopillars",
				Label = "Conveyor ramp (up, 2 m rise, no pillars)",
				Kind = Kind.Ramp,
				Rise = 2,
				Pillars = false
			},
			new Spec
			{
				Name = "piece_conveyorramp_down_2m_nopillars",
				Label = "Conveyor ramp (down, 2 m rise, no pillars)",
				Kind = Kind.Ramp,
				Rise = 2,
				Dir = -1,
				Pillars = false
			},
			new Spec
			{
				Name = "piece_conveyorgrinder",
				Label = "Conveyor grinder",
				Kind = Kind.Grinder,
				Description = "Kills every creature that rides in. Its loot rides on to the next belt. Hurts players who stand in it."
			},
			new Spec
			{
				Name = "piece_conveyorfilter_right",
				Label = "Item filter (right)",
				Kind = Kind.Filter,
				Turn = 1,
				Description = "A conveyor belt with a side exit. What it is set to turns to the side, the rest goes straight on. Set it with a hotbar key; a trophy sets a creature kind. Shift+E swaps: the set kind goes straight, the rest turns."
			},
			new Spec
			{
				Name = "piece_conveyorfilter_left",
				Label = "Item filter (left)",
				Kind = Kind.Filter,
				Turn = -1,
				Description = "A conveyor belt with a side exit. What it is set to turns to the side, the rest goes straight on. Set it with a hotbar key; a trophy sets a creature kind. Shift+E swaps: the set kind goes straight, the rest turns."
			},
			new Spec
			{
				Name = "piece_conveyorlink",
				Label = "Conveyor link",
				Kind = Kind.Link,
				Description = "A conveyor belt in a stone box. Smelters, kilns and chests snap on top or beside it. It feeds them what they take and fills or empties chests."
			},
			new Spec
			{
				Name = "piece_conveyorbelt_05m",
				Label = "Conveyor belt (0.5 m)",
				Size = 0.5f
			},
			new Spec
			{
				Name = "piece_conveyorbelt_narrow_05m",
				Label = "Conveyor belt (0.5 m, narrow)",
				Size = 0.5f,
				Width = 1f
			},
			new Spec
			{
				Name = "piece_conveyorbelt_narrow_1m",
				Label = "Conveyor belt (1 m, narrow)",
				Size = 1f,
				Width = 1f
			},
			new Spec
			{
				Name = "piece_conveyorbelt_narrow_2m",
				Label = "Conveyor belt (2 m, narrow)",
				Size = 2f,
				Width = 1f
			},
			new Spec
			{
				Name = "piece_conveyorcorner_narrow_right",
				Label = "Conveyor corner (right, narrow)",
				Kind = Kind.Corner,
				Turn = 1,
				Width = 1f
			},
			new Spec
			{
				Name = "piece_conveyorcorner_narrow_left",
				Label = "Conveyor corner (left, narrow)",
				Kind = Kind.Corner,
				Turn = -1,
				Width = 1f
			},
			new Spec
			{
				Name = "piece_conveyorlink_narrow",
				Label = "Conveyor link (narrow)",
				Kind = Kind.Link,
				Width = 1f,
				Description = "A narrow conveyor belt in a stone box. Chests snap on top or beside it. It fills or empties them."
			},
			new Spec
			{
				Name = "piece_conveyorkitchenlink",
				Label = "Kitchen link",
				Kind = Kind.Kitchen,
				Description = "A conveyor belt in a stone tunnel, with a greydwarf chef in a small kitchen behind it. Build a cooking station, an iron cooking station, an oven or a fermenter on the open side of the chef's room, behind the belt: it snaps into place. The chef puts raw food on, keeps the fire fed with wood, and takes the food off cooked before it burns."
			},
			new Spec
			{
				Name = "piece_conveyorkitchenlink_narrow",
				Label = "Kitchen link (narrow)",
				Kind = Kind.Kitchen,
				Width = 1f,
				Description = "A narrow conveyor belt in a stone tunnel, with a greydwarf chef in a small kitchen behind it. Build a cooking station, an iron cooking station, an oven or a fermenter on the open side of the chef's room, behind the belt: it snaps into place. The chef puts raw food on, keeps the fire fed with wood, and takes the food off cooked before it burns."
			}
		};

		public static readonly string[] PieceNames = Array.ConvertAll(Specs, (Spec s) => s.Name);

		private static readonly float[] DrumZ = new float[2] { -0.5f, 0.4f };

		private const float DrumY = 0.48f;

		private const float SignStroke = 0.06f;

		private const float SignHead = 0.16f;

		private const float MarkThickness = 0.01f;

		public static float LoopLength(float span)
		{
			return 2f * span + (float)Math.PI * 17f / 50f;
		}

		private static float SlatsOf(float width)
		{
			return width - 0.4f;
		}

		private static float RailOf(float width)
		{
			return SlatsOf(width) / 2f + 0.06f;
		}

		public static void Register()
		{
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: 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_01ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_020e: Expected O, but got Unknown
			//IL_021a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: Unknown result type (might be due to invalid IL or missing references)
			//IL_023b: 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_0255: Unknown result type (might be due to invalid IL or missing references)
			//IL_025a: Unknown result type (might be due to invalid IL or missing references)
			//IL_025c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0261: Unknown result type (might be due to invalid IL or missing references)
			//IL_0263: Unknown result type (might be due to invalid IL or missing references)
			//IL_0268: Unknown result type (might be due to invalid IL or missing references)
			//IL_0273: Unknown result type (might be due to invalid IL or missing references)
			//IL_028b: 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_029a: Unknown result type (might be due to invalid IL or missing references)
			//IL_029f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bc: 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_02c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02df: 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_02e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f2: 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_02f6: 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)
			Mesh box;
			Material[] wood;
			bool num = PieceBuilder.Beam(out box, out wood);
			Mesh log;
			Material[] mats;
			bool flag = PieceBuilder.Log(out log, out mats);
			GameObject val = PieceBuilder.Find("piece_spinningwheel", "SpinningWheel_Destruction/SpinningWheel_Destruction.002_SpinningWheel_Broken.018");
			GameObject val2 = PieceBuilder.Find("piece_spinningwheel", "New/High/SpinningWheel");
			GameObject val3 = PieceBuilder.Find("windmill", "grindstone/high");
			GameObject val4 = PieceBuilder.Find("piece_sharpstakes", "New/high/Stake");
			MeshRenderer val5 = FindRenderer("stone_wall_1x1", "Stone for the link");
			MeshRenderer val6 = FindRenderer("darkwood_beam", "Dark wood for the direction marks");
			if (!num || !flag || !Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)val2) || !Object.op_Implicit((Object)(object)val3) || !Object.op_Implicit((Object)(object)val4) || !Object.op_Implicit((Object)(object)val5))
			{
				Logger.LogError((object)"Belt not registered: a vanilla part is missing (see warnings above)");
				return;
			}
			Parts obj = new Parts
			{
				BoxMesh = box,
				Wood = wood[0],
				LogMesh = log,
				LogMat = mats[0],
				WheelMesh = val.GetComponent<MeshFilter>().sharedMesh
			};
			Bounds bounds = val.GetComponent<MeshFilter>().sharedMesh.bounds;
			obj.WheelCenter = ((Bounds)(ref bounds)).center;
			obj.WheelMats = ((Renderer)val2.GetComponent<SkinnedMeshRenderer>()).sharedMaterials;
			obj.StoneMesh = val3.GetComponent<MeshFilter>().sharedMesh;
			obj.StoneMats = ((Renderer)val3.GetComponent<MeshRenderer>()).sharedMaterials;
			obj.StakeMesh = val4.GetComponent<MeshFilter>().sharedMesh;
			obj.StakeMats = ((Renderer)val4.GetComponent<MeshRenderer>()).sharedMaterials;
			obj.WallMesh = ((Component)val5).GetComponent<MeshFilter>().sharedMesh;
			obj.WallMats = ((Renderer)val5).sharedMaterials;
			Parts parts = obj;
			parts.Dark = (Material)(Object.op_Implicit((Object)(object)val6) ? ((object)((Renderer)val6).sharedMaterial) : ((object)new Material(parts.Wood)
			{
				color = Color.Lerp(Color.black, parts.Wood.color, 0.3f)
			}));
			parts.Mark = new Material(parts.Dark)
			{
				name = "ConveyorBelts_mark",
				color = Color.Lerp(Color.black, parts.Dark.color, 0.35f)
			};
			Matrix4x4 val7 = ((Component)val5).transform.root.worldToLocalMatrix * ((Component)val5).transform.localToWorldMatrix;
			parts.WallRot = ((Matrix4x4)(ref val7)).rotation;
			parts.WallScale = ((Matrix4x4)(ref val7)).lossyScale;
			Bounds bounds2 = parts.WallMesh.bounds;
			Vector3 val8 = Vector3.positiveInfinity;
			Vector3 val9 = Vector3.negativeInfinity;
			for (int i = 0; i < 8; i++)
			{
				Vector3 val10 = ((Matrix4x4)(ref val7)).MultiplyVector(Vector3.Scale(((Bounds)(ref bounds2)).extents, new Vector3((float)(i & 1), (float)((i >> 1) & 1), (float)((i >> 2) & 1)) * 2f - Vector3.one) + ((Bounds)(ref bounds2)).center);
				val8 = Vector3.Min(val8, val10);
				val9 = Vector3.Max(val9, val10);
			}
			parts.WallBounds = new Bounds((val8 + val9) / 2f, val9 - val8);
			Spec[] specs = Specs;
			for (int j = 0; j < specs.Length; j++)
			{
				Add(specs[j], parts);
			}
		}

		private static void Add(Spec spec, Parts parts)
		{
			//IL_00a6: 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_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_048a: Unknown result type (might be due to invalid IL or missing references)
			//IL_048f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0223: Unknown result type (might be due to invalid IL or missing references)
			//IL_0249: Unknown result type (might be due to invalid IL or missing references)
			//IL_024e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0262: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d2: 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)
			//IL_02f0: 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_0320: Unknown result type (might be due to invalid IL or missing references)
			//IL_0331: Unknown result type (might be due to invalid IL or missing references)
			//IL_0358: Unknown result type (might be due to invalid IL or missing references)
			//IL_038f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0394: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03da: Unknown result type (might be due to invalid IL or missing references)
			//IL_03df: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0434: Unknown result type (might be due to invalid IL or missing references)
			//IL_0439: Unknown result type (might be due to invalid IL or missing references)
			//IL_044c: Unknown result type (might be due to invalid IL or missing references)
			CustomPiece val = PieceBuilder.New(spec.Name, spec.Label, spec.Description);
			GameObject piecePrefab = val.PiecePrefab;