Decompiled source of LynxVarcis v1.0.17

plugins/LynxVarcis.dll

Decompiled an hour ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Jotunn.Managers;
using Jotunn.Utils;
using LynxVarcis.Patches;
using Splatform;
using TMPro;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = "")]
[assembly: AssemblyVersion("0.0.0.0")]
namespace LynxVarcis
{
	internal static class Benches
	{
		internal struct Shape
		{
			internal float X;

			internal float Y;

			internal float Z;

			internal float Scale;

			internal float Yaw;
		}

		internal const string Root = "LV_Benches";

		private static readonly string[] Sources = new string[4] { "piece_bench01", "piece_logbench01", "piece_chair02", "piece_chair" };

		internal static string SourceName = "";

		internal static float Length = 2f;

		private static readonly List<(Vector3 pos, Quaternion rot, Vector3 detach, string anim)> _seats = new List<(Vector3, Quaternion, Vector3, string)>();

		internal static readonly Shape AutoShape = new Shape
		{
			X = 0.8f,
			Y = 2f,
			Z = 0.75f,
			Scale = 1f,
			Yaw = 0f
		};

		internal static Shape Current
		{
			get
			{
				if (!Intake.TryParse(Cfg.BenchPlacement.Value, out var s))
				{
					return AutoShape;
				}
				return new Shape
				{
					X = s.X,
					Y = s.Y,
					Z = s.Z,
					Scale = s.Scale,
					Yaw = s.Yaw
				};
			}
		}

		internal static string Line(Shape s)
		{
			return Intake.Line(new Intake.BoxShape
			{
				X = s.X,
				Y = s.Y,
				Z = s.Z,
				Scale = s.Scale,
				Yaw = s.Yaw
			});
		}

		internal static string Describe(Shape s)
		{
			return "side " + s.X.ToString("0.00") + " m, height " + s.Y.ToString("0.00") + " m, along " + s.Z.ToString("0.00") + " m, scale " + s.Scale.ToString("0.00") + ", turn " + s.Yaw.ToString("0") + "°";
		}

		internal static void AddTo(GameObject trailer)
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Expected O, but got Unknown
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Expected O, but got Unknown
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Unknown result type (might be due to invalid IL or missing references)
			//IL_020c: 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_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_029e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a5: Expected O, but got Unknown
			//IL_0344: Unknown result type (might be due to invalid IL or missing references)
			//IL_034b: Expected O, but got Unknown
			//IL_0368: Unknown result type (might be due to invalid IL or missing references)
			//IL_037b: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b7: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = null;
			string[] sources = Sources;
			foreach (string text in sources)
			{
				val = Prefabs.FindPrefab(text);
				if ((Object)(object)val != (Object)null)
				{
					SourceName = text;
					break;
				}
			}
			GameObject val2 = new GameObject("LV_Benches");
			val2.layer = trailer.layer;
			val2.transform.SetParent(trailer.transform, false);
			Bounds bounds = default(Bounds);
			((Bounds)(ref bounds))..ctor(Vector3.zero, new Vector3(2f, 0.5f, 0.6f));
			_seats.Clear();
			if ((Object)(object)val != (Object)null)
			{
				GameObject val3 = new GameObject("proto");
				Prefabs.CopyMeshes(val, val3.transform, out bounds);
				Length = Mathf.Max(0.6f, ((Bounds)(ref bounds)).size.x);
				Matrix4x4 worldToLocalMatrix = val.transform.worldToLocalMatrix;
				Chair[] componentsInChildren = val.GetComponentsInChildren<Chair>(true);
				foreach (Chair val4 in componentsInChildren)
				{
					if (!((Object)(object)val4.m_attachPoint == (Object)null))
					{
						Matrix4x4 val5 = worldToLocalMatrix * val4.m_attachPoint.localToWorldMatrix;
						_seats.Add((Vector4.op_Implicit(((Matrix4x4)(ref val5)).GetColumn(3)), ((Matrix4x4)(ref val5)).rotation, val4.m_detachOffset, string.IsNullOrEmpty(val4.m_attachAnimation) ? "attach_chair" : val4.m_attachAnimation));
					}
				}
				Object.DestroyImmediate((Object)(object)val3);
			}
			if (_seats.Count == 0)
			{
				float num = ((((Bounds)(ref bounds)).max.y > 0.2f) ? ((Bounds)(ref bounds)).max.y : 0.5f);
				_seats.Add((new Vector3((0f - Length) * 0.25f, num, 0f), Quaternion.identity, new Vector3(0f, 0.5f, 0.7f), "attach_chair"));
				_seats.Add((new Vector3(Length * 0.25f, num, 0f), Quaternion.identity, new Vector3(0f, 0.5f, 0.7f), "attach_chair"));
			}
			int num2 = Mathf.Clamp(Cfg.BenchesPerSide.Value, 1, 3);
			int num3 = 0;
			float[] array = new float[2] { 1f, -1f };
			foreach (float num4 in array)
			{
				for (int j = 0; j < num2; j++)
				{
					GameObject val6 = new GameObject("bench_" + ((num4 > 0f) ? "r" : "l") + j);
					val6.layer = trailer.layer;
					val6.transform.SetParent(val2.transform, false);
					if ((Object)(object)val != (Object)null)
					{
						Prefabs.CopyMeshes(val, val6.transform, out var _);
					}
					Transform[] componentsInChildren2 = val6.GetComponentsInChildren<Transform>(true);
					for (int k = 0; k < componentsInChildren2.Length; k++)
					{
						((Component)componentsInChildren2[k]).gameObject.layer = trailer.layer;
					}
					foreach (var seat in _seats)
					{
						GameObject val7 = new GameObject("seat" + num3++);
						val7.transform.SetParent(val6.transform, false);
						val7.transform.localPosition = seat.pos;
						val7.transform.localRotation = seat.rot;
						Chair obj = val7.AddComponent<Chair>();
						obj.m_name = "Bench";
						obj.m_useDistance = 8f;
						obj.m_attachPoint = val7.transform;
						obj.m_detachOffset = seat.detach;
						obj.m_attachAnimation = seat.anim;
						obj.m_inShip = true;
					}
				}
			}
			Apply(trailer.transform, Current);
			Plugin.Diag("passenger trailer: " + num2 * 2 + " bench(es) from '" + (((Object)(object)val != (Object)null) ? SourceName : "nothing (no bench model found)") + "', " + _seats.Count * num2 * 2 + " seat(s); " + Describe(Current) + ((Cfg.BenchPlacement.Value.Trim().ToLowerInvariant() == "auto") ? " (auto)" : " (from config)"));
		}

		internal static void Apply(Transform trailer, Shape s)
		{
			//IL_0027: 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)
			//IL_009b: 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_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			Transform val = trailer.Find("LV_Benches");
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			int num = 0;
			foreach (Transform item in val)
			{
				if (((Object)item).name.StartsWith("bench_r"))
				{
					num++;
				}
			}
			float num2 = Length * s.Scale + 0.15f;
			foreach (Transform item2 in val)
			{
				bool flag = ((Object)item2).name.StartsWith("bench_r");
				int result;
				int num3 = (int.TryParse(((Object)item2).name.Substring(7), out result) ? result : 0);
				float num4 = (flag ? 1f : (-1f));
				float num5 = s.Z + ((float)num3 - (float)(num - 1) * 0.5f) * num2;
				item2.localPosition = new Vector3(num4 * s.X, s.Y, num5);
				item2.localRotation = Quaternion.Euler(0f, (flag ? (-90f) : 90f) + num4 * s.Yaw, 0f);
				item2.localScale = Vector3.one * s.Scale;
			}
		}

		internal static void ApplyEverywhere(Shape s)
		{
			if ((Object)(object)Prefabs.Passenger != (Object)null)
			{
				Apply(Prefabs.Passenger.transform, s);
			}
			foreach (VarcisTrailer item in VarcisTrailer.All)
			{
				if ((Object)(object)item != (Object)null && item.Passenger)
				{
					Apply(((Component)item).transform, s);
				}
			}
		}

		internal static bool Sit(VarcisTrailer t, Player player)
		{
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			Transform val = ((Component)t).transform.Find("LV_Benches");
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			List<Chair> list = new List<Chair>(((Component)val).GetComponentsInChildren<Chair>(true));
			list.Sort((Chair a, Chair b) => Vector3.Distance(((Component)a).transform.position, ((Component)player).transform.position).CompareTo(Vector3.Distance(((Component)b).transform.position, ((Component)player).transform.position)));
			List<Player> allPlayers = Player.GetAllPlayers();
			foreach (Chair item in list)
			{
				bool flag = false;
				foreach (Player item2 in allPlayers)
				{
					if ((Object)(object)item2 != (Object)null && (Object)(object)item2 != (Object)(object)player && Vector3.Distance(((Component)item2).transform.position, ((Component)item).transform.position) < 0.35f)
					{
						flag = true;
					}
				}
				if (!flag)
				{
					item.Interact((Humanoid)(object)player, false, false);
					return true;
				}
			}
			((Character)player).Message((MessageType)2, "Every seat is taken", 0, (Sprite)null, false);
			return true;
		}
	}
	internal static class Shapes
	{
		private static Texture2D _canvasTex;

		private static readonly Dictionary<string, Texture> _woodTex = new Dictionary<string, Texture>();

		internal static readonly Color WoodTint = new Color(0.85f, 0.72f, 0.55f);

		internal static readonly Color PlainWood = new Color(0.45f, 0.3f, 0.17f);

		private static Shader Diffuse => Shader.Find("Legacy Shaders/Diffuse") ?? Shader.Find("Standard");

		internal static Texture2D CanvasTexture
		{
			get
			{
				//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_002f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0036: Unknown result type (might be due to invalid IL or missing references)
				//IL_003e: Expected O, but got Unknown
				//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
				//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)_canvasTex != (Object)null)
				{
					return _canvasTex;
				}
				Texture2D val = new Texture2D(128, 128, (TextureFormat)4, true)
				{
					name = "lv_canvas",
					wrapMode = (TextureWrapMode)0,
					filterMode = (FilterMode)1
				};
				Random random = new Random(1234);
				Color[] array = (Color[])(object)new Color[16384];
				Color val2 = default(Color);
				((Color)(ref val2))..ctor(0.84f, 0.78f, 0.64f);
				for (int i = 0; i < 128; i++)
				{
					for (int j = 0; j < 128; j++)
					{
						float num = ((((j & 1) ^ (i & 1)) == 0) ? 0.97f : 1.02f);
						float num2 = ((j % 8 == 0 || i % 8 == 0) ? 0.93f : 1f);
						float num3 = 0.94f + (float)random.NextDouble() * 0.08f;
						float num4 = num * num2 * num3;
						array[i * 128 + j] = new Color(val2.r * num4, val2.g * num4, val2.b * num4, 1f);
					}
				}
				val.SetPixels(array);
				val.Apply(true);
				Object.DontDestroyOnLoad((Object)(object)val);
				return _canvasTex = val;
			}
		}

		internal static Texture PieceTexture(string prefabName)
		{
			if (_woodTex.TryGetValue(prefabName, out var value) && (Object)(object)value != (Object)null)
			{
				return value;
			}
			Texture val = null;
			GameObject val2 = Prefabs.FindPrefab(prefabName);
			if ((Object)(object)val2 != (Object)null)
			{
				MeshRenderer[] componentsInChildren = val2.GetComponentsInChildren<MeshRenderer>(true);
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					Material sharedMaterial = ((Renderer)componentsInChildren[i]).sharedMaterial;
					if ((Object)(object)sharedMaterial != (Object)null && sharedMaterial.HasProperty("_MainTex") && (Object)(object)sharedMaterial.mainTexture != (Object)null)
					{
						val = sharedMaterial.mainTexture;
						break;
					}
				}
			}
			if (!_woodTex.ContainsKey(prefabName) || (Object)(object)val != (Object)null)
			{
				Plugin.Diag("texture: " + (((Object)(object)val != (Object)null) ? ("'" + ((Object)val).name + "' from " + prefabName) : ("none found on " + prefabName + (((Object)(object)val2 == (Object)null) ? " (prefab not found)" : ""))));
			}
			_woodTex[prefabName] = val;
			return val;
		}

		internal static Material Mat(string name, Texture tex, Color tint, Vector2 tiling)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//IL_002a: 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)
			Material val = new Material(Diffuse)
			{
				name = name
			};
			if ((Object)(object)tex != (Object)null)
			{
				val.mainTexture = tex;
				val.mainTextureScale = tiling;
			}
			val.color = tint;
			return val;
		}

		internal static Material Wood(string prefab, Vector2 tiling)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			Texture val = PieceTexture(prefab) ?? PieceTexture("wood_floor");
			return Mat("lv_wood_" + prefab, val, ((Object)(object)val != (Object)null) ? WoodTint : PlainWood, tiling);
		}

		internal static Material Canvas(Vector2 tiling)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			return Mat("lv_canvas", (Texture)(object)CanvasTexture, Color.white, tiling);
		}

		internal static Material OutsideCanvas(Vector2 tiling)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			return Mat("lv_canvas_out", (Texture)(object)CanvasTexture, new Color(0.72f, 0.66f, 0.55f), tiling);
		}

		internal static GameObject Box(Transform parent, string name, Vector3 center, Vector3 size, Material mat)
		{
			//IL_002b: 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)
			GameObject obj = GameObject.CreatePrimitive((PrimitiveType)3);
			((Object)obj).name = name;
			Object.DestroyImmediate((Object)(object)obj.GetComponent<Collider>());
			obj.transform.SetParent(parent, false);
			obj.transform.localPosition = center;
			obj.transform.localScale = size;
			((Renderer)obj.GetComponent<MeshRenderer>()).sharedMaterial = mat;
			return obj;
		}

		internal static GameObject MeshObject(Transform parent, string name, Mesh mesh, Material mat, bool castShadows)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: 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_003a: Expected O, but got Unknown
			GameObject val = new GameObject(name);
			val.transform.SetParent(parent, false);
			val.AddComponent<MeshFilter>().sharedMesh = mesh;
			MeshRenderer obj = val.AddComponent<MeshRenderer>();
			((Renderer)obj).sharedMaterial = mat;
			((Renderer)obj).shadowCastingMode = (ShadowCastingMode)(castShadows ? 2 : 0);
			return val;
		}

		private static Vector3 Arc(float hw, float baseY, float rise, float t)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			return new Vector3(0f, baseY + rise * Mathf.Sin(t), hw * Mathf.Cos(t));
		}

		internal static Mesh Vault(float length, float hw, float baseY, float rise, int seg = 24)
		{
			//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_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: 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_0060: 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_0088: 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_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: 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)
			List<Vector3> list = new List<Vector3>();
			List<Vector2> list2 = new List<Vector2>();
			List<int> list3 = new List<int>();
			float num = 0f;
			Vector3 val = Arc(hw, baseY, rise, 0f);
			float[] array = new float[seg + 1];
			for (int i = 1; i <= seg; i++)
			{
				Vector3 val2 = Arc(hw, baseY, rise, (float)Math.PI * (float)i / (float)seg);
				num = (array[i] = num + Vector3.Distance(val, val2));
				val = val2;
			}
			for (int j = 0; j <= seg; j++)
			{
				Vector3 val3 = Arc(hw, baseY, rise, (float)Math.PI * (float)j / (float)seg);
				list.Add(new Vector3((0f - length) / 2f, val3.y, val3.z));
				list2.Add(new Vector2(0f, array[j]));
				list.Add(new Vector3(length / 2f, val3.y, val3.z));
				list2.Add(new Vector2(length, array[j]));
			}
			for (int k = 0; k < seg; k++)
			{
				int num2 = k * 2;
				int num3 = num2 + 1;
				int num4 = num2 + 2;
				int num5 = num2 + 3;
				list3.AddRange(new int[6] { num2, num4, num3, num3, num4, num5 });
			}
			return Finish("lv_vault", list, list2, list3);
		}

		internal static Mesh EndCap(float hw, float baseY, float rise, int seg = 24)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			List<Vector3> list = new List<Vector3>
			{
				new Vector3(0f, baseY, 0f)
			};
			List<Vector2> list2 = new List<Vector2>
			{
				new Vector2(0f, 0f)
			};
			List<int> list3 = new List<int>();
			for (int i = 0; i <= seg; i++)
			{
				Vector3 val = Arc(hw, baseY, rise, (float)Math.PI * (float)i / (float)seg);
				list.Add(val);
				list2.Add(new Vector2(val.z, val.y - baseY));
			}
			for (int j = 1; j <= seg; j++)
			{
				list3.AddRange(new int[3]
				{
					0,
					j,
					j + 1
				});
			}
			return Finish("lv_endcap", list, list2, list3);
		}

		internal static Mesh EndRing(float hw, float baseY, float rise, float open, float depth, int seg = 24)
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: 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_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			List<Vector3> list = new List<Vector3>();
			List<Vector2> list2 = new List<Vector2>();
			List<int> list3 = new List<int>();
			float hw2 = hw * open;
			float rise2 = rise * open;
			for (int i = 0; i <= seg; i++)
			{
				float t = (float)Math.PI * (float)i / (float)seg;
				Vector3 val = Arc(hw, baseY, rise, t);
				Vector3 val2 = Arc(hw2, baseY, rise2, t);
				list.Add(new Vector3(0f, val.y, val.z));
				list2.Add(new Vector2(val.z, val.y));
				list.Add(new Vector3(depth, val2.y, val2.z));
				list2.Add(new Vector2(val2.z, val2.y + depth));
			}
			for (int j = 0; j < seg; j++)
			{
				int num = j * 2;
				int num2 = num + 1;
				int num3 = num + 2;
				int num4 = num + 3;
				list3.AddRange(new int[6] { num, num3, num2, num2, num3, num4 });
			}
			return Finish("lv_endring", list, list2, list3);
		}

		internal static Mesh Hoop(float hw, float baseY, float rise, float width, int seg = 24)
		{
			//IL_0028: 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)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: 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_007b: 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_009e: Unknown result type (might be due to invalid IL or missing references)
			List<Vector3> list = new List<Vector3>();
			List<Vector2> list2 = new List<Vector2>();
			List<int> list3 = new List<int>();
			for (int i = 0; i <= seg; i++)
			{
				Vector3 val = Arc(hw, baseY, rise, (float)Math.PI * (float)i / (float)seg);
				list.Add(new Vector3((0f - width) / 2f, val.y, val.z));
				list2.Add(new Vector2(0f, (float)i / (float)seg * 4f));
				list.Add(new Vector3(width / 2f, val.y, val.z));
				list2.Add(new Vector2(0.25f, (float)i / (float)seg * 4f));
			}
			for (int j = 0; j < seg; j++)
			{
				int num = j * 2;
				int num2 = num + 1;
				int num3 = num + 2;
				int num4 = num + 3;
				list3.AddRange(new int[6] { num, num3, num2, num2, num3, num4 });
			}
			return Finish("lv_hoop", list, list2, list3);
		}

		private static Mesh Finish(string name, List<Vector3> v, List<Vector2> uv, List<int> tri)
		{
			//IL_0017: 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_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Expected O, but got Unknown
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			int count = v.Count;
			int count2 = tri.Count;
			for (int i = 0; i < count; i++)
			{
				v.Add(v[i]);
				uv.Add(uv[i]);
			}
			for (int j = 0; j < count2; j += 3)
			{
				tri.AddRange(new int[3]
				{
					tri[j] + count,
					tri[j + 2] + count,
					tri[j + 1] + count
				});
			}
			Mesh val = new Mesh
			{
				name = name
			};
			val.SetVertices(v);
			val.SetUVs(0, uv);
			val.SetTriangles(tri, 0);
			val.RecalculateNormals();
			val.RecalculateBounds();
			Vector3[] normals = val.normals;
			for (int k = 0; k < count && k + count < normals.Length; k++)
			{
				normals[k + count] = -normals[k];
			}
			val.normals = normals;
			return val;
		}
	}
	internal static class WagonCanopy
	{
		internal struct Shape
		{
			public float Width;

			public float Length;

			public float CenterZ;

			public float BaseY;
		}

		internal const string ChildName = "LV_Canopy";

		internal static Shape Current;

		internal static Shape AutoShape;

		internal static Shape Auto(GameObject wagon, string modelName = null)
		{
			//IL_025b: Unknown result type (might be due to invalid IL or missing references)
			//IL_026f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0274: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_0286: Unknown result type (might be due to invalid IL or missing references)
			//IL_028c: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a5: 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_02d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0281: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: 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_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			Shape shape = default(Shape);
			if (modelName == "trader_wagon_destructable")
			{
				shape = new Shape
				{
					Width = 3.5f,
					Length = 5.4f,
					CenterZ = 0.6f,
					BaseY = 3f
				};
				Plugin.Diag("wagon canopy: using the shape measured for " + modelName + ": " + Describe(shape));
				return shape;
			}
			bool flag = false;
			MeshFilter componentInChildren = wagon.GetComponentInChildren<MeshFilter>(true);
			if ((Object)(object)componentInChildren != (Object)null && (Object)(object)componentInChildren.sharedMesh != (Object)null && componentInChildren.sharedMesh.isReadable)
			{
				Matrix4x4 val = wagon.transform.worldToLocalMatrix * ((Component)componentInChildren).transform.localToWorldMatrix;
				Vector3[] vertices = componentInChildren.sharedMesh.vertices;
				float num = float.MinValue;
				Vector3[] array = vertices;
				foreach (Vector3 val2 in array)
				{
					num = Mathf.Max(num, ((Matrix4x4)(ref val)).MultiplyPoint3x4(val2).y);
				}
				float num2 = float.MaxValue;
				float num3 = float.MinValue;
				float num4 = float.MaxValue;
				float num5 = float.MinValue;
				int num6 = 0;
				array = vertices;
				foreach (Vector3 val3 in array)
				{
					Vector3 val4 = ((Matrix4x4)(ref val)).MultiplyPoint3x4(val3);
					if (!(val4.y < num * 0.45f))
					{
						num2 = Mathf.Min(num2, val4.x);
						num3 = Mathf.Max(num3, val4.x);
						num4 = Mathf.Min(num4, val4.z);
						num5 = Mathf.Max(num5, val4.z);
						num6++;
					}
				}
				if (num6 > 20 && num3 > num2 && num5 > num4)
				{
					shape.Width = (num3 - num2) * 1.02f;
					shape.Length = (num5 - num4) * 0.95f;
					shape.CenterZ = (num4 + num5) / 2f;
					shape.BaseY = Mathf.Max(1f, num - shape.Width * 0.5f * 0.85f);
					flag = true;
				}
			}
			if (!flag)
			{
				Bounds val5 = (Bounds)(((Object)(object)wagon.GetComponentInChildren<MeshRenderer>(true) != (Object)null && (Object)(object)componentInChildren != (Object)null && (Object)(object)componentInChildren.sharedMesh != (Object)null) ? componentInChildren.sharedMesh.bounds : new Bounds(new Vector3(0f, 1.6f, 0f), new Vector3(3f, 3.2f, 8f)));
				shape.Width = ((Bounds)(ref val5)).size.x * 0.85f;
				shape.Length = ((Bounds)(ref val5)).size.z * 0.6f;
				shape.CenterZ = ((Bounds)(ref val5)).center.z;
				shape.BaseY = Mathf.Max(1f, ((Bounds)(ref val5)).max.y - shape.Width * 0.5f * 0.85f);
			}
			Plugin.Diag("wagon canopy: " + (flag ? "fitted to the wagon bed" : "estimated from the model's size (its mesh can't be read)") + ": " + Describe(shape));
			return shape;
		}

		internal static string Describe(Shape s)
		{
			return s.Width.ToString("0.0#") + " " + s.Length.ToString("0.0#") + " " + s.CenterZ.ToString("0.0#") + " " + s.BaseY.ToString("0.0#") + "  (width, length, centre Z, base height)";
		}

		internal static bool TryParse(string text, out Shape s)
		{
			s = default(Shape);
			string[] array = (text ?? "").Replace(",", " ").Split(new char[1] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
			if (array.Length != 4)
			{
				return false;
			}
			float[] array2 = new float[4];
			for (int i = 0; i < 4; i++)
			{
				if (!float.TryParse(array[i], NumberStyles.Float, CultureInfo.InvariantCulture, out array2[i]))
				{
					return false;
				}
			}
			if (array2[0] < 0.5f || array2[1] < 0.5f || array2[0] > 20f || array2[1] > 40f)
			{
				return false;
			}
			s = new Shape
			{
				Width = array2[0],
				Length = array2[1],
				CenterZ = array2[2],
				BaseY = array2[3]
			};
			return true;
		}

		internal static void Apply(GameObject wagon, Shape s)
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Expected O, but got Unknown
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: 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_02c4: 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)
			Transform val = wagon.transform.Find("LV_Canopy");
			if ((Object)(object)val != (Object)null)
			{
				Object.DestroyImmediate((Object)(object)((Component)val).gameObject);
			}
			if (Cfg.WagonCanopy.Value)
			{
				GameObject val2 = new GameObject("LV_Canopy");
				val2.layer = wagon.layer;
				val2.transform.SetParent(wagon.transform, false);
				val2.transform.localPosition = new Vector3(0f, 0f, s.CenterZ);
				val2.transform.localRotation = Quaternion.Euler(0f, 90f, 0f);
				float num = s.Width / 2f;
				float num2 = num * 0.95f;
				Mesh val3 = Shapes.Vault(s.Length, num, s.BaseY, num2);
				Material mat = Shapes.OutsideCanvas(new Vector2(0.5f, 0.5f));
				GameObject val4 = Shapes.MeshObject(val2.transform, "canvas", val3, mat, castShadows: true);
				Mesh mesh = Shapes.EndRing(num, s.BaseY, num2, 0.55f, 0.35f);
				Shapes.MeshObject(val2.transform, "canvas_end", mesh, mat, castShadows: true).transform.localPosition = new Vector3((0f - s.Length) / 2f, 0f, 0f);
				GameObject obj = Shapes.MeshObject(val2.transform, "canvas_end", mesh, mat, castShadows: true);
				obj.transform.localPosition = new Vector3(s.Length / 2f, 0f, 0f);
				obj.transform.localRotation = Quaternion.Euler(0f, 180f, 0f);
				val4.layer = wagon.layer;
				val4.AddComponent<MeshCollider>().sharedMesh = val3;
				Material mat2 = Shapes.Wood("wood_pole2", new Vector2(1f, 1f));
				int num3 = Mathf.Max(2, Mathf.RoundToInt(s.Length / 1.6f) + 1);
				Mesh mesh2 = Shapes.Hoop(num + 0.03f, s.BaseY, num2 + 0.03f, 0.14f);
				for (int i = 0; i < num3; i++)
				{
					Shapes.MeshObject(val2.transform, "hoop", mesh2, mat2, castShadows: true).transform.localPosition = new Vector3((0f - s.Length) / 2f + 0.07f + (s.Length - 0.14f) * (float)i / (float)(num3 - 1), 0f, 0f);
				}
				if (Cfg.Tailgate.Value)
				{
					Mesh mesh3 = Shapes.EndCap(num * 0.97f, s.BaseY, (0f - num) * 0.72f);
					Shapes.MeshObject(val2.transform, "tailgate", mesh3, Shapes.Wood("wood_floor", new Vector2(0.5f, 0.5f)), castShadows: true).transform.localPosition = new Vector3((0f - s.Length) / 2f + 0.08f, 0f, 0f);
				}
				Transform[] componentsInChildren = val2.GetComponentsInChildren<Transform>(true);
				for (int j = 0; j < componentsInChildren.Length; j++)
				{
					((Component)componentsInChildren[j]).gameObject.layer = wagon.layer;
				}
			}
		}

		internal static void ApplyEverywhere(Shape s)
		{
			Current = s;
			if ((Object)(object)Prefabs.Wagon != (Object)null)
			{
				Apply(Prefabs.Wagon, s);
			}
			VarcisWagon[] array = Object.FindObjectsByType<VarcisWagon>((FindObjectsInactive)1, (FindObjectsSortMode)0);
			foreach (VarcisWagon varcisWagon in array)
			{
				if ((Object)(object)varcisWagon != (Object)null && (Object)(object)((Component)varcisWagon).gameObject != (Object)(object)Prefabs.Wagon)
				{
					Apply(((Component)varcisWagon).gameObject, s);
				}
			}
		}
	}
	internal static class Crate
	{
		internal const string PrefabName = "LV_PackedCaravan";

		internal const string DisplayName = "Packed Caravan";

		internal static readonly int Hash = StringExtensionMethods.GetStableHashCode("LV_PackedCaravan");

		internal static GameObject Prefab;

		private static bool _iconDone;

		private static readonly FieldRef<Trader, List<TradeItem>> _items = AccessTools.FieldRefAccess<Trader, List<TradeItem>>("m_items");

		internal const string DPid = "lv_pid";

		internal const string DSerial = "lv_serial";

		internal const string DName = "lv_name";

		internal const string DTrailers = "lv_trailers";

		internal const string DLox = "lv_lox";

		internal const string DData = "lv_data";

		internal static SharedData Shared
		{
			get
			{
				if (!((Object)(object)Prefab != (Object)null))
				{
					return null;
				}
				return Prefab.GetComponent<ItemDrop>().m_itemData.m_shared;
			}
		}

		internal static bool Is(ItemData item)
		{
			if (item == null)
			{
				return false;
			}
			if ((Object)(object)item.m_dropPrefab != (Object)null)
			{
				return ((Object)item.m_dropPrefab).name == "LV_PackedCaravan";
			}
			if ((Object)(object)Prefab != (Object)null)
			{
				return item.m_shared == Prefab.GetComponent<ItemDrop>().m_itemData.m_shared;
			}
			return false;
		}

		internal static GameObject Build(ZNetScene zs, Transform holder)
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Expected O, but got Unknown
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Expected O, but got Unknown
			//IL_00e9: 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_0247: Unknown result type (might be due to invalid IL or missing references)
			//IL_0259: Unknown result type (might be due to invalid IL or missing references)
			//IL_026d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0285: Unknown result type (might be due to invalid IL or missing references)
			//IL_0291: 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)
			//IL_02d1: Expected O, but got Unknown
			//IL_02f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: 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_01c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_0210: 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_0345: Unknown result type (might be due to invalid IL or missing references)
			//IL_034d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0354: Unknown result type (might be due to invalid IL or missing references)
			//IL_035b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0367: Expected O, but got Unknown
			if ((Object)(object)Prefab != (Object)null)
			{
				return Prefab;
			}
			GameObject obj = Prefabs.FindPrefab("Wood");
			ItemDrop val = ((obj != null) ? obj.GetComponent<ItemDrop>() : null);
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Error("packed caravan item: the vanilla Wood item wasn't found to copy item settings from; packing is unavailable");
				return null;
			}
			GameObject val2 = new GameObject("LV_PackedCaravan");
			val2.transform.SetParent(holder, false);
			val2.layer = LayerMask.NameToLayer("item");
			ZNetView obj2 = val2.AddComponent<ZNetView>();
			obj2.m_persistent = true;
			obj2.m_type = (ObjectType)0;
			val2.AddComponent<Rigidbody>().mass = 30f;
			ZSyncTransform obj3 = val2.AddComponent<ZSyncTransform>();
			obj3.m_syncPosition = true;
			obj3.m_syncRotation = true;
			obj3.m_syncBodyVelocity = true;
			GameObject val3 = new GameObject("visual");
			val3.layer = val2.layer;
			val3.transform.SetParent(val2.transform, false);
			GameObject val4 = Prefabs.FindPrefab("piece_chest_wood");
			Bounds val5 = default(Bounds);
			((Bounds)(ref val5))..ctor(new Vector3(0f, 0.3f, 0f), new Vector3(0.9f, 0.6f, 0.6f));
			GameObject val6 = ((!((Object)(object)val4 != (Object)null)) ? null : val4.GetComponent<Container>()?.m_open);
			if ((Object)(object)val4 != (Object)null && Prefabs.CopyMeshes(val4, val3.transform, out var bounds, ((Object)(object)val6 != (Object)null) ? val6.transform : null) > 0)
			{
				float num = 0.9f / Mathf.Max(0.1f, Mathf.Max(((Bounds)(ref bounds)).size.x, ((Bounds)(ref bounds)).size.z));
				val3.transform.localScale = Vector3.one * num;
				val3.transform.localPosition = new Vector3((0f - ((Bounds)(ref bounds)).center.x) * num, (0f - ((Bounds)(ref bounds)).min.y) * num, (0f - ((Bounds)(ref bounds)).center.z) * num);
				((Bounds)(ref val5))..ctor(new Vector3(0f, ((Bounds)(ref bounds)).size.y * num * 0.5f, 0f), ((Bounds)(ref bounds)).size * num);
			}
			else
			{
				GameObject obj4 = GameObject.CreatePrimitive((PrimitiveType)3);
				Object.DestroyImmediate((Object)(object)obj4.GetComponent<Collider>());
				obj4.transform.SetParent(val3.transform, false);
				obj4.transform.localPosition = ((Bounds)(ref val5)).center;
				obj4.transform.localScale = ((Bounds)(ref val5)).size;
				((Renderer)obj4.GetComponent<MeshRenderer>()).sharedMaterial = Shapes.Wood("wood_floor", Vector2.one);
			}
			BoxCollider obj5 = val2.AddComponent<BoxCollider>();
			obj5.center = ((Bounds)(ref val5)).center;
			obj5.size = ((Bounds)(ref val5)).size;
			ItemDrop val7 = val2.AddComponent<ItemDrop>();
			SharedData val8 = (SharedData)AccessTools.Method(typeof(object), "MemberwiseClone", (Type[])null, (Type[])null).Invoke(val.m_itemData.m_shared, null);
			val8.m_name = "Packed Caravan";
			val8.m_description = "A whole caravan packed into one crate: the varcis, its trailers and its draft lox. Use it to set the caravan up again. Its rooms are untouched while it's packed.";
			val8.m_maxStackSize = 1;
			val8.m_itemType = (ItemType)16;
			val8.m_value = 0;
			Sprite val9 = ((!((Object)(object)val4 != (Object)null)) ? null : val4.GetComponent<Piece>()?.m_icon);
			if ((Object)(object)val9 != (Object)null)
			{
				val8.m_icons = (Sprite[])(object)new Sprite[1] { val9 };
			}
			val7.m_itemData = new ItemData
			{
				m_shared = val8,
				m_stack = 1,
				m_quality = 1,
				m_dropPrefab = val2
			};
			ApplySettings();
			Prefab = val2;
			return val2;
		}

		internal static void ApplySettings()
		{
			SharedData val = (((Object)(object)Prefab != (Object)null) ? Shared : null);
			if (val != null)
			{
				val.m_weight = Cfg.PackedWeight.Value;
				val.m_teleportable = Cfg.PackedPortals.Value;
			}
		}

		internal static void Register(ObjectDB odb)
		{
			if ((Object)(object)Prefab == (Object)null || (Object)(object)odb == (Object)null)
			{
				return;
			}
			if (!odb.m_items.Contains(Prefab))
			{
				odb.m_items.Add(Prefab);
				try
				{
					AccessTools.Method(typeof(ObjectDB), "UpdateRegisters", (Type[])null, (Type[])null)?.Invoke(odb, null);
				}
				catch (Exception ex)
				{
					Plugin.Warn("packed caravan item: couldn't refresh the item list (" + ex.Message + ")");
				}
			}
			ApplySettings();
			RenderIcon();
		}

		private static void RenderIcon()
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Invalid comparison between Unknown and I4
			if (_iconDone || ((Object)(object)ZNet.instance != (Object)null && ZNet.instance.IsDedicated()) || (int)SystemInfo.graphicsDeviceType == 4)
			{
				return;
			}
			_iconDone = true;
			try
			{
				Sprite val = Prefabs.RenderIconPublic(Prefab);
				if ((Object)(object)val != (Object)null)
				{
					Shared.m_icons = (Sprite[])(object)new Sprite[1] { val };
					Plugin.Diag("packed caravan icon rendered");
				}
			}
			catch (Exception ex)
			{
				Plugin.Warn("packed caravan icon: render failed (" + ex.Message + "), keeping the chest's icon");
			}
		}

		internal static void AddToHaldor()
		{
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: 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_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Expected O, but got Unknown
			if ((Object)(object)Prefab == (Object)null)
			{
				return;
			}
			GameObject obj = Prefabs.FindPrefab("Haldor");
			Trader val = ((obj != null) ? obj.GetComponent<Trader>() : null);
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Warn("replacement crates: Haldor wasn't found; he won't sell them");
				return;
			}
			List<TradeItem> list = _items.Invoke(val);
			foreach (TradeItem item in list)
			{
				if ((Object)(object)item.m_prefab != (Object)null && (Object)(object)((Component)item.m_prefab).gameObject == (Object)(object)Prefab)
				{
					item.m_price = Cfg.ReplacementPrice.Value;
					return;
				}
			}
			list.Add(new TradeItem
			{
				m_prefab = Prefab.GetComponent<ItemDrop>(),
				m_stack = 1,
				m_price = Cfg.ReplacementPrice.Value,
				m_requiredGlobalKey = ""
			});
			Plugin.Info("replacement crates: Haldor sells a Packed Caravan replacement for " + Cfg.ReplacementPrice.Value + " coins");
		}

		internal static int Pid(ItemData item)
		{
			if (item?.m_customData == null || !item.m_customData.TryGetValue("lv_pid", out var value) || !int.TryParse(value, out var result))
			{
				return 0;
			}
			return result;
		}

		internal static int Serial(ItemData item)
		{
			if (item?.m_customData == null || !item.m_customData.TryGetValue("lv_serial", out var value) || !int.TryParse(value, out var result))
			{
				return 0;
			}
			return result;
		}

		internal static string Name(ItemData item)
		{
			if (item?.m_customData == null || !item.m_customData.TryGetValue("lv_name", out var value))
			{
				return "";
			}
			return value;
		}

		internal static void Fill(ItemData item, Payload p, int serial)
		{
			if (item.m_customData == null)
			{
				item.m_customData = new Dictionary<string, string>();
			}
			item.m_customData["lv_pid"] = p.Pid.ToString(K.Inv);
			item.m_customData["lv_serial"] = serial.ToString(K.Inv);
			item.m_customData["lv_name"] = p.Name;
			StringBuilder stringBuilder = new StringBuilder();
			foreach (Payload.Car car in p.Cars)
			{
				stringBuilder.Append((stringBuilder.Length > 0) ? ";" : "").Append(car.RoomId).Append(':')
					.Append(car.Name.Replace(";", ","))
					.Append(car.Large ? " (Large)" : "");
			}
			item.m_customData["lv_trailers"] = stringBuilder.ToString();
			item.m_customData["lv_lox"] = p.LoxName + "|level " + p.LoxLevel + "|" + (p.LoxTamed ? "tame" : "wild") + "|" + (p.LoxSaddle ? "saddled" : "no saddle");
			item.m_customData["lv_data"] = p.ToBase64();
		}
	}
	internal sealed class Payload
	{
		internal sealed class Car
		{
			internal int RoomId;

			internal string Name = "";

			internal bool Large;

			internal bool Side;

			internal bool Passenger;

			internal float RoomSize;

			internal Vector3 RoomPos;
		}

		internal int Pid;

		internal int LoxSerial;

		internal int LoxLevel = 1;

		internal string Name = "";

		internal string LoxName = "";

		internal long Creator;

		internal bool LoxTamed = true;

		internal bool LoxSaddle = true;

		internal readonly List<Car> Cars = new List<Car>();

		internal string ToBase64()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			ZPackage val = new ZPackage();
			val.Write(2);
			val.Write(Pid);
			val.Write(Name);
			val.Write(Creator);
			val.Write(LoxSerial);
			val.Write(LoxName);
			val.Write(LoxLevel);
			val.Write(LoxTamed);
			val.Write(LoxSaddle);
			val.Write(Cars.Count);
			foreach (Car car in Cars)
			{
				val.Write(car.RoomId);
				val.Write(car.Name);
				val.Write(car.Large);
				val.Write(car.Side);
				val.Write(car.RoomSize);
				val.Write(car.RoomPos);
				val.Write(car.Passenger);
			}
			return val.GetBase64();
		}

		internal static Payload FromBase64(string s)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			if (string.IsNullOrEmpty(s))
			{
				return null;
			}
			try
			{
				ZPackage val = new ZPackage(s);
				int num = val.ReadInt();
				if (num < 1)
				{
					return null;
				}
				Payload payload = new Payload
				{
					Pid = val.ReadInt(),
					Name = val.ReadString(),
					Creator = val.ReadLong(),
					LoxSerial = val.ReadInt(),
					LoxName = val.ReadString(),
					LoxLevel = val.ReadInt(),
					LoxTamed = val.ReadBool(),
					LoxSaddle = val.ReadBool()
				};
				int num2 = val.ReadInt();
				for (int i = 0; i < num2; i++)
				{
					Car car = new Car
					{
						RoomId = val.ReadInt(),
						Name = val.ReadString(),
						Large = val.ReadBool(),
						Side = val.ReadBool(),
						RoomSize = val.ReadSingle(),
						RoomPos = val.ReadVector3()
					};
					if (num >= 2)
					{
						car.Passenger = val.ReadBool();
					}
					payload.Cars.Add(car);
				}
				return payload;
			}
			catch (Exception ex)
			{
				Plugin.Warn("packed caravan data unreadable: " + ex.Message);
				return null;
			}
		}
	}
	internal static class CropWatch
	{
		internal sealed class Follow : MonoBehaviour
		{
			private Pickable _p;

			private ZNetView _nv;

			private float _t0;

			private float _nextLine;

			private string _last = "";

			private void Start()
			{
				_p = ((Component)this).GetComponent<Pickable>();
				_nv = ((Component)this).GetComponent<ZNetView>();
				_t0 = Time.time;
				_nextLine = 0f;
				((MonoBehaviour)this).InvokeRepeating("Tick", 0.5f, 1f);
			}

			private void Tick()
			{
				//IL_0112: Unknown result type (might be due to invalid IL or missing references)
				//IL_0117: Unknown result type (might be due to invalid IL or missing references)
				//IL_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_0237: Unknown result type (might be due to invalid IL or missing references)
				//IL_023c: Unknown result type (might be due to invalid IL or missing references)
				//IL_032e: Unknown result type (might be due to invalid IL or missing references)
				float num = Time.time - _t0;
				if ((Object)(object)_p == (Object)null)
				{
					Plugin.Info("crop watch: following " + ((Object)this).name.Replace("(Clone)", "") + ": the Pickable component is gone after " + num.ToString("0") + " s");
					((MonoBehaviour)this).CancelInvoke();
					return;
				}
				if (num > 62f)
				{
					((MonoBehaviour)this).CancelInvoke();
					Object.Destroy((Object)(object)this);
					return;
				}
				int num2 = 0;
				int num3 = 0;
				int num4 = 0;
				Renderer[] componentsInChildren = ((Component)this).GetComponentsInChildren<Renderer>(true);
				foreach (Renderer val in componentsInChildren)
				{
					num3++;
					if (val.enabled && ((Component)val).gameObject.activeInHierarchy)
					{
						num2++;
					}
				}
				Collider[] componentsInChildren2 = ((Component)this).GetComponentsInChildren<Collider>(true);
				foreach (Collider val2 in componentsInChildren2)
				{
					if (val2.enabled && ((Component)val2).gameObject.activeInHierarchy)
					{
						num4++;
					}
				}
				Vector3 position = ((Component)this).transform.position;
				string text = "-";
				if ((Object)(object)_nv != (Object)null && _nv.IsValid())
				{
					text = _nv.GetZDO().GetPosition().y.ToString("0.00");
				}
				string text2 = "y " + position.y.ToString("0.00") + " (zdo " + text + "), drawn " + num2 + "/" + num3 + ", colliders " + num4 + ", picked=" + ((_picked != null) ? _picked.GetValue(_p) : "?")?.ToString() + ", active=" + ((Component)this).gameObject.activeInHierarchy + ", scale " + ((Component)this).transform.lossyScale.x.ToString("0.00") + ", parent " + (((Object)(object)((Component)this).transform.parent != (Object)null) ? ((Object)((Component)this).transform.parent).name : "none") + ((!((Object)(object)_nv != (Object)null) || !_nv.IsValid()) ? ", no zdo" : (_nv.IsOwner() ? ", owned here" : ", owned elsewhere"));
				bool flag = num >= _nextLine;
				if (text2 != _last || flag)
				{
					if (flag)
					{
						_nextLine = num + 20f;
					}
					Plugin.Info("crop watch: following " + ((Object)this).name.Replace("(Clone)", "") + " at " + K.V(position) + " +" + num.ToString("0") + " s: " + text2);
					_last = text2;
				}
			}
		}

		private static float _lastBurst = -100f;

		private static int _inBurst;

		private static readonly FieldInfo _picked = AccessTools.Field(typeof(Pickable), "m_picked");

		private static bool Wanted(GameObject go, out string kind)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			kind = null;
			if ((Object)(object)go == (Object)null || !K.InPocketBand(go.transform.position))
			{
				return false;
			}
			if ((Object)(object)go.GetComponent<Plant>() != (Object)null)
			{
				kind = "plant";
			}
			else if ((Object)(object)go.GetComponent<Pickable>() != (Object)null)
			{
				kind = "pickable";
			}
			return kind != null;
		}

		private static string Who()
		{
			try
			{
				StackFrame[] frames = new StackTrace(3, fNeedFileInfo: false).GetFrames();
				if (frames == null)
				{
					return "?";
				}
				IEnumerable<string> values = from m in (from f in frames
						select f.GetMethod() into m
						where m != null && m.DeclaringType != null && !m.DeclaringType.FullName.StartsWith("HarmonyLib") && !m.Name.StartsWith("DMD<") && !m.Name.StartsWith("Prefix") && !m.Name.StartsWith("Postfix")
						select m).Take(7)
					select m.DeclaringType.Name + "." + m.Name;
				return string.Join(" < ", values);
			}
			catch
			{
				return "?";
			}
		}

		private static void Note(string line, bool withWho)
		{
			if (Time.time - _lastBurst > 5f)
			{
				if (_inBurst > 1)
				{
					Plugin.Info("crop watch: previous burst was " + _inBurst + " removals");
				}
				_inBurst = 0;
				withWho = true;
			}
			_lastBurst = Time.time;
			_inBurst++;
			Plugin.Info("crop watch: " + line + (withWho ? (" | asked by: " + Who()) : ""));
		}

		public static void DestroyPrefix(GameObject go)
		{
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			if (Cfg.CropWatch.Value && Wanted(go, out var kind))
			{
				ZNetView component = go.GetComponent<ZNetView>();
				Plant component2 = go.GetComponent<Plant>();
				Note("removed " + kind + " " + ((Object)go).name.Replace("(Clone)", "") + " at " + K.V(go.transform.position) + (((Object)(object)component2 != (Object)null) ? (" (status " + ((object)component2.GetStatus()/*cast due to .constrained prefix*/).ToString() + ")") : "") + ((!((Object)(object)component != (Object)null) || !component.IsValid()) ? "" : (component.IsOwner() ? " [owned here]" : " [not owned here]")), withWho: false);
			}
		}

		public static void RemoteDestroyPrefix(ZDO zdo)
		{
			//IL_0010: 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 (Cfg.CropWatch.Value && zdo != null && K.InPocketBand(zdo.GetPosition()))
			{
				GameObject val = (((Object)(object)ZNetScene.instance != (Object)null) ? ZNetScene.instance.GetPrefab(zdo.GetPrefab()) : null);
				if (!((Object)(object)val == (Object)null) && (!((Object)(object)val.GetComponent<Plant>() == (Object)null) || !((Object)(object)val.GetComponent<Pickable>() == (Object)null)))
				{
					Note("destroyed by another machine: " + ((Object)val).name + " at " + K.V(zdo.GetPosition()), withWho: true);
				}
			}
		}

		public static void PickableAwakePostfix(Pickable __instance)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			if (!Cfg.CropWatch.Value || (Object)(object)__instance == (Object)null || !K.InPocketBand(((Component)__instance).transform.position))
			{
				return;
			}
			ZNetView component = ((Component)__instance).GetComponent<ZNetView>();
			int num = 0;
			int num2 = 0;
			Renderer[] componentsInChildren = ((Component)__instance).GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val in componentsInChildren)
			{
				num2++;
				if (val.enabled && ((Component)val).gameObject.activeInHierarchy)
				{
					num++;
				}
			}
			if ((Object)(object)((Component)__instance).GetComponent<Follow>() == (Object)null)
			{
				((Component)__instance).gameObject.AddComponent<Follow>();
			}
			Plugin.Info("crop watch: harvestable " + ((Object)__instance).name.Replace("(Clone)", "") + " appeared at " + K.V(((Component)__instance).transform.position) + " | picked=" + ((_picked != null) ? _picked.GetValue(__instance) : "?")?.ToString() + ", scale " + ((Component)__instance).transform.localScale.x.ToString("0.00") + ", drawn parts " + num + "/" + num2 + ((!((Object)(object)component != (Object)null) || !component.IsValid()) ? ", no zdo" : (component.IsOwner() ? ", owned here" : ", owned elsewhere")));
		}

		public static void PickableGonePrefix(ZNetView __instance)
		{
			//IL_0029: 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)
			if (Cfg.CropWatch.Value && !((Object)(object)__instance == (Object)null) && !((Object)(object)((Component)__instance).GetComponent<Pickable>() == (Object)null) && K.InPocketBand(((Component)__instance).transform.position))
			{
				Plugin.Info("crop watch: harvestable " + ((Object)__instance).name.Replace("(Clone)", "") + " at " + K.V(((Component)__instance).transform.position) + " is gone from the scene (zdo " + (__instance.IsValid() ? "still there" : "gone") + ")");
			}
		}

		public static void GrowPostfix(Plant __instance, GameObject __result)
		{
			//IL_001b: 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_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			if (Cfg.CropWatch.Value && !((Object)(object)__instance == (Object)null) && K.InPocketBand(((Component)__instance).transform.position))
			{
				Plugin.Info("crop watch: " + ((Object)__instance).name.Replace("(Clone)", "") + " finished growing at " + K.V(((Component)__instance).transform.position) + " -> " + (((Object)(object)__result != (Object)null) ? ((Object)__result).name.Replace("(Clone)", "") : "nothing") + " (status " + ((object)__instance.GetStatus()/*cast due to .constrained prefix*/).ToString() + ")");
			}
		}
	}
	public class DraftLox : MonoBehaviour
	{
		internal static readonly List<DraftLox> All = new List<DraftLox>();

		private ZNetView _view;

		internal Character Character;

		internal Tameable Tame;

		internal Sadle Saddle;

		private float _next;

		private float _wagonMissingSince = -1f;

		private float _awayFrom = -1f;

		private bool _ignoredWagonCollisions;

		private static readonly MethodInfo _setSaddle = AccessTools.Method(typeof(Tameable), "SetSaddle", new Type[1] { typeof(bool) }, (Type[])null);

		private static readonly FieldInfo _speedF = AccessTools.Field(typeof(Sadle), "m_speed");

		internal bool HaveHitch;

		internal bool InShaftsNow = true;

		internal Vector3 HitchPos;

		internal Quaternion HitchRot;

		private float _wanderSince = -1f;

		internal float ReverseAt = -10f;

		private static readonly int ReverseKey = StringExtensionMethods.GetStableHashCode("lv_reversing");

		private Animator _anim;

		private bool _revOn;

		private int _revHash;

		private float _revT;

		private float _nextTrample;

		private static readonly List<VarcisTrailer> _cars = new List<VarcisTrailer>();

		private ZDO Zdo
		{
			get
			{
				if (!((Object)(object)_view != (Object)null) || !_view.IsValid())
				{
					return null;
				}
				return _view.GetZDO();
			}
		}

		internal int Serial
		{
			get
			{
				ZDO zdo = Zdo;
				if (zdo == null)
				{
					return 0;
				}
				return zdo.GetInt("lv_loxserial", 0);
			}
		}

		internal VarcisWagon Wagon => VarcisWagon.ForSerial(Serial);

		internal ZDOID Uid => Zdo?.m_uid ?? ZDOID.None;

		internal bool Ridden
		{
			get
			{
				if ((Object)(object)Saddle != (Object)null)
				{
					return Saddle.HaveValidUser();
				}
				return false;
			}
		}

		internal bool IsOwnedHere
		{
			get
			{
				if ((Object)(object)_view != (Object)null && _view.IsValid())
				{
					return _view.IsOwner();
				}
				return false;
			}
		}

		internal bool ReversingHere => Time.time - ReverseAt < 0.25f;

		internal bool Reversing
		{
			get
			{
				ZDO zdo = Zdo;
				if (zdo == null)
				{
					return false;
				}
				if (_view.IsOwner())
				{
					bool reversingHere = ReversingHere;
					if (zdo.GetBool(ReverseKey, false) != reversingHere)
					{
						zdo.Set(ReverseKey, reversingHere);
					}
					return reversingHere;
				}
				return zdo.GetBool(ReverseKey, false);
			}
		}

		private void Awake()
		{
			_view = ((Component)this).GetComponent<ZNetView>();
			Character = ((Component)this).GetComponent<Character>();
			Tame = ((Component)this).GetComponent<Tameable>();
			Saddle = (((Object)(object)Tame != (Object)null) ? Tame.m_saddle : ((Component)this).GetComponentInChildren<Sadle>(true));
			ApplySpeed();
			if ((Object)(object)Tame != (Object)null)
			{
				try
				{
					_setSaddle?.Invoke(Tame, new object[1] { true });
				}
				catch
				{
				}
			}
			All.Add(this);
		}

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

		internal void ApplySpeed()
		{
			if (!((Object)(object)Character == (Object)null))
			{
				float num = (Cfg.Driving.Value ? (Mathf.Clamp(Cfg.PullLoad.Value, 0f, 80f) / 100f) : 0f);
				float num2 = Mathf.Clamp(Cfg.LoxSpeed.Value, 1f, 12f) * (1f - num);
				Character.m_walkSpeed = num2 * 0.5f;
				Character.m_speed = num2;
				Character.m_runSpeed = num2;
				Character.m_canSwim = false;
				float num3 = Mathf.Clamp(Cfg.LoxTurnSpeed.Value, 20f, 360f);
				Character.m_turnSpeed = num3;
				Character.m_runTurnSpeed = num3 * 0.8f;
			}
		}

		internal static bool Before(DraftLox a, DraftLox b)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			ZDOID uid = a.Uid;
			ZDOID uid2 = b.Uid;
			if (((ZDOID)(ref uid)).UserID == ((ZDOID)(ref uid2)).UserID)
			{
				return ((ZDOID)(ref uid)).ID < ((ZDOID)(ref uid2)).ID;
			}
			return ((ZDOID)(ref uid)).UserID < ((ZDOID)(ref uid2)).UserID;
		}

		internal bool ReverseHeld()
		{
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null || (Object)(object)Saddle == (Object)null || (object)localPlayer.GetDoodadController() != Saddle)
			{
				return false;
			}
			if (((Object)(object)Chat.instance != (Object)null && Chat.instance.HasFocus()) || Console.IsVisible() || InventoryGui.IsVisible() || Menu.IsVisible())
			{
				return false;
			}
			if (!ZInput.GetButton("Backward") && !(ZInput.GetJoyLeftStickY() > 0.5f))
			{
				return false;
			}
			return !(_speedF != null) || Convert.ToInt32(_speedF.GetValue(Saddle)) == 0;
		}

		internal void HoldAt(Vector3 pos)
		{
			//IL_0067: 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_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: 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_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			Rigidbody component = ((Component)this).GetComponent<Rigidbody>();
			if ((Object)(object)component != (Object)null && !component.isKinematic)
			{
				Vector3 linearVelocity = component.linearVelocity;
				linearVelocity.x = 0f;
				linearVelocity.z = 0f;
				component.linearVelocity = linearVelocity;
				component.position = new Vector3(pos.x, component.position.y, pos.z);
			}
			else
			{
				((Component)this).transform.position = new Vector3(pos.x, ((Component)this).transform.position.y, pos.z);
			}
		}

		private void AnimateReverse()
		{
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			if (!Reversing)
			{
				_revOn = false;
				return;
			}
			if ((Object)(object)_anim == (Object)null)
			{
				_anim = ((Component)this).GetComponentInChildren<Animator>();
			}
			if ((Object)(object)_anim == (Object)null || !((Behaviour)_anim).isActiveAndEnabled)
			{
				return;
			}
			if (_anim.IsInTransition(0))
			{
				_revOn = false;
				return;
			}
			AnimatorStateInfo currentAnimatorStateInfo = _anim.GetCurrentAnimatorStateInfo(0);
			if (!_revOn || ((AnimatorStateInfo)(ref currentAnimatorStateInfo)).fullPathHash != _revHash)
			{
				_revOn = true;
				_revHash = ((AnimatorStateInfo)(ref currentAnimatorStateInfo)).fullPathHash;
				_revT = ((AnimatorStateInfo)(ref currentAnimatorStateInfo)).normalizedTime;
			}
			_revT -= Time.deltaTime / Mathf.Max(0.2f, ((AnimatorStateInfo)(ref currentAnimatorStateInfo)).length);
			_revT = Mathf.Repeat(_revT, 1f);
			_anim.Play(_revHash, 0, _revT);
		}

		private void LateUpdate()
		{
			if ((Object)(object)_view != (Object)null && _view.IsValid())
			{
				AnimateReverse();
			}
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null || (Object)(object)Saddle == (Object)null || (Object)(object)_view == (Object)null || !_view.IsValid() || (object)localPlayer.GetDoodadController() != Saddle)
			{
				return;
			}
			if (!_view.IsOwner())
			{
				_view.ClaimOwnership();
			}
			VarcisWagon wagon = Wagon;
			ZNetView val = (((Object)(object)wagon != (Object)null) ? ((Component)wagon).GetComponent<ZNetView>() : null);
			if ((Object)(object)val != (Object)null && val.IsValid() && !val.IsOwner())
			{
				val.ClaimOwnership();
			}
			if ((Object)(object)wagon != (Object)null && Systems.Caravan)
			{
				ZDO zdoPublic = wagon.ZdoPublic;
				VarcisTrailer.LinkedTo((zdoPublic != null) ? zdoPublic.GetInt("lv_pid", 0) : 0, _cars);
				foreach (VarcisTrailer car in _cars)
				{
					if ((Object)(object)car.View != (Object)null && car.View.IsValid() && !car.View.IsOwner())
					{
						car.View.ClaimOwnership();
					}
				}
			}
			if (Time.time >= _nextTrample)
			{
				_nextTrample = Time.time + 0.2f;
				Trampler.Run(this, wagon);
			}
		}

		internal static bool Is(Component c)
		{
			if ((Object)(object)c != (Object)null)
			{
				return (Object)(object)c.GetComponent<DraftLox>() != (Object)null;
			}
			return false;
		}

		private unsafe void Update()
		{
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0215: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: Unknown result type (might be due to invalid IL or missing references)
			//IL_021c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0221: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			ZDO zdo = Zdo;
			if (zdo == null || Time.time < _next)
			{
				return;
			}
			_next = Time.time + 1f;
			if (_view.IsOwner() && !zdo.GetBool(ZDOVars.s_haveSaddleHash, false))
			{
				zdo.Set(ZDOVars.s_haveSaddleHash, true);
				_view.InvokeRPC(ZNetView.Everybody, "SetSaddle", new object[1] { true });
			}
			VarcisWagon wagon = Wagon;
			if ((Object)(object)wagon == (Object)null)
			{
				if (_wagonMissingSince < 0f)
				{
					_wagonMissingSince = Time.time;
				}
				else if (Time.time - _wagonMissingSince > 10f && _view.IsOwner())
				{
					Plugin.Diag("draft lox at " + K.V(((Component)this).transform.position) + ((Serial == 0) ? " is from an older build (no wagon link)" : " has no wagon any more") + "; removed");
					ZNetScene.instance.Destroy(((Component)this).gameObject);
				}
				return;
			}
			_wagonMissingSince = -1f;
			GameObject gameObject = ((Component)wagon).gameObject;
			DraftLox draftLox = wagon.FindLox();
			if ((Object)(object)draftLox != (Object)null && (Object)(object)draftLox != (Object)(object)this && _view.IsOwner())
			{
				string[] obj = new string[5] { "draft lox ", null, null, null, null };
				ZDOID uid = zdo.m_uid;
				obj[1] = ((object)(*(ZDOID*)(&uid))/*cast due to .constrained prefix*/).ToString();
				obj[2] = " is a duplicate for '";
				obj[3] = wagon.WagonName;
				obj[4] = "'; removed";
				Plugin.Diag(string.Concat(obj));
				ZNetScene.instance.Destroy(((Component)this).gameObject);
				return;
			}
			if (!_ignoredWagonCollisions)
			{
				_ignoredWagonCollisions = true;
				IgnoreCollisions(gameObject);
			}
			wagon.HitchPose(out var pos, out var rot);
			HitchPos = pos;
			HitchRot = rot;
			HaveHitch = true;
			InShaftsNow = wagon.InShafts(((Component)this).transform.position, ((Component)this).transform.forward);
			if (Ridden || !_view.IsOwner())
			{
				return;
			}
			Vector3 val = ((Component)this).transform.position - pos;
			val.y = 0f;
			if (!InShaftsNow && ((Vector3)(ref val)).magnitude > 1.5f)
			{
				if (_awayFrom < 0f)
				{
					_awayFrom = Time.time;
					_wanderSince = ((Vector3)(ref val)).magnitude;
				}
				bool flag = Time.time - _awayFrom > 12f;
				if (((Vector3)(ref val)).magnitude > 40f || flag)
				{
					string[] obj2 = new string[7] { "draft lox ", null, null, null, null, null, null };
					ZDOID uid = zdo.m_uid;
					obj2[1] = ((object)(*(ZDOID*)(&uid))/*cast due to .constrained prefix*/).ToString();
					obj2[2] = " was ";
					obj2[3] = ((Vector3)(ref val)).magnitude.ToString("0.0");
					obj2[4] = " m from its shafts";
					obj2[5] = (flag ? " and not getting closer" : "");
					obj2[6] = "; put back";
					Plugin.Diag(string.Concat(obj2));
					SnapTo(pos, rot);
				}
			}
			else
			{
				_awayFrom = -1f;
			}
		}

		internal void IgnoreCollisions(GameObject wagon)
		{
			Collider[] componentsInChildren = ((Component)this).GetComponentsInChildren<Collider>(true);
			Collider[] componentsInChildren2 = wagon.GetComponentsInChildren<Collider>(true);
			Collider[] array = componentsInChildren;
			foreach (Collider val in array)
			{
				Collider[] array2 = componentsInChildren2;
				foreach (Collider val2 in array2)
				{
					if ((Object)(object)val != (Object)null && (Object)(object)val2 != (Object)null)
					{
						Physics.IgnoreCollision(val, val2, true);
					}
				}
			}
		}

		internal void SnapTo(Vector3 pos, Quaternion rot)
		{
			//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_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_view == (Object)null || !_view.IsValid() || Ridden)
			{
				return;
			}
			if (!_view.IsOwner())
			{
				_view.ClaimOwnership();
			}
			Rigidbody component = ((Component)this).GetComponent<Rigidbody>();
			((Component)this).transform.SetPositionAndRotation(pos, rot);
			if ((Object)(object)component != (Object)null)
			{
				component.position = pos;
				component.rotation = rot;
				if (!component.isKinematic)
				{
					component.linearVelocity = Vector3.zero;
					component.angularVelocity = Vector3.zero;
				}
			}
			_awayFrom = -1f;
		}
	}
	internal static class LoxPatches
	{
		private static readonly int ForwardSpeed = ZSyncAnimation.GetHash("forward_speed");

		private static DraftLox Lox(Component c)
		{
			if (!((Object)(object)c != (Object)null) || DraftLox.All.Count <= 0)
			{
				return null;
			}
			return c.GetComponent<DraftLox>();
		}

		public static bool UpdateAIPrefix(MonsterAI __instance, float __0, ref bool __result)
		{
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: Unknown result type (might be due to invalid IL or missing references)
			//IL_021c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			//IL_0235: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_024b: Unknown result type (might be due to invalid IL or missing references)
			DraftLox draftLox = Lox((Component)(object)__instance);
			if ((Object)(object)draftLox == (Object)null)
			{
				return true;
			}
			ZNetView component = ((Component)__instance).GetComponent<ZNetView>();
			if ((Object)(object)component == (Object)null || !component.IsValid() || !component.IsOwner())
			{
				return true;
			}
			bool flag = (Object)(object)draftLox.Saddle != (Object)null && draftLox.Saddle.HaveValidUser();
			if (flag && draftLox.ReverseHeld())
			{
				VarcisWagon wagon = draftLox.Wagon;
				Vector3 val = (((Object)(object)wagon != (Object)null) ? (-((Component)wagon).transform.forward) : ((Component)draftLox).transform.forward);
				val.y = 0f;
				((Vector3)(ref val)).Normalize();
				draftLox.Character.SetLookDir(val, 0f);
				draftLox.Character.SetMoveDir(-val * 0.6f);
				draftLox.Character.SetRun(false);
				draftLox.ReverseAt = Time.time;
				__result = true;
				return false;
			}
			if ((Object)(object)draftLox.Saddle != (Object)null && draftLox.Saddle.UpdateRiding(__0))
			{
				Vector3 moveDir = draftLox.Character.GetMoveDir();
				moveDir.y = 0f;
				if (((Vector3)(ref moveDir)).sqrMagnitude > 0.01f && (Object)(object)ZoneSystem.instance != (Object)null)
				{
					Vector3 val2 = ((Component)draftLox).transform.position + ((Vector3)(ref moveDir)).normalized * 2.5f;
					if (ZoneSystem.instance.m_waterLevel - ZoneSystem.instance.GetGroundHeight(val2) > 0.9f)
					{
						((BaseAI)__instance).StopMoving();
					}
				}
				__result = true;
				return false;
			}
			if (flag)
			{
				((BaseAI)__instance).StopMoving();
				__result = true;
				return false;
			}
			if (draftLox.HaveHitch && !draftLox.InShaftsNow)
			{
				Vector3 val3 = draftLox.HitchPos - ((Component)draftLox).transform.position;
				val3.y = 0f;
				if (((Vector3)(ref val3)).magnitude > 0.6f)
				{
					((BaseAI)__instance).MoveTowards(((Vector3)(ref val3)).normalized, ((Vector3)(ref val3)).magnitude > 4f);
					__result = true;
					return false;
				}
				((BaseAI)__instance).StopMoving();
				Vector3 val4 = draftLox.HitchRot * Vector3.forward;
				val4.y = 0f;
				if (Vector3.Angle(((Component)draftLox).transform.forward, val4) > 10f)
				{
					draftLox.Character.SetLookDir(((Vector3)(ref val4)).normalized, 0.5f);
				}
			}
			else
			{
				((BaseAI)__instance).StopMoving();
			}
			__result = true;
			return false;
		}

		public static void AnimFloatPrefix(ZSyncAnimation __instance, int __0, ref float __1)
		{
			if (__0 == ForwardSpeed && !(__1 >= 0f) && DraftLox.All.Count != 0)
			{
				DraftLox draftLox = ((Component)__instance).GetComponent<DraftLox>() ?? ((Component)__instance).GetComponentInParent<DraftLox>();
				if ((Object)(object)draftLox != (Object)null && draftLox.ReversingHere)
				{
					__1 = 0f - __1;
				}
			}
		}

		public static void IsEnemyStaticPostfix(Character __0, Character __1, ref bool __result)
		{
			if (__result && ((Object)(object)Lox((Component)(object)__0) != (Object)null || (Object)(object)Lox((Component)(object)__1) != (Object)null))
			{
				__result = false;
			}
		}

		public static void IsEnemyPostfix(BaseAI __instance, Character __0, ref bool __result)
		{
			if (__result && ((Object)(object)Lox((Component)(object)__instance) != (Object)null || (Object)(object)Lox((Component)(object)__0) != (Object)null))
			{
				__result = false;
			}
		}

		public static bool DamagePrefix(Character __instance)
		{
			if (Cfg.LoxInvulnerable.Value)
			{
				return !((Object)(object)Lox((Component)(object)__instance) != (Object)null);
			}
			return true;
		}

		public static bool TameUseItemPrefix(Tameable __instance, ref bool __result)
		{
			if ((Object)(object)Lox((Component)(object)__instance) == (Object)null)
			{
				return true;
			}
			__result = false;
			return false;
		}

		public static void IsHungryPostfix(Tameable __instance, ref bool __result)
		{
			if (__result && (Object)(object)Lox((Component)(object)__instance) != (Object)null)
			{
				__result = false;
			}
		}

		public static void TameHoverPostfix(Tameable __instance, ref string __result)
		{
			DraftLox draftLox = Lox((Component)(object)__instance);
			if (!((Object)(object)draftLox == (Object)null))
			{
				VarcisWagon wagon = draftLox.Wagon;
				if ((Object)(object)wagon != (Object)null)
				{
					__result = __result + "\n<color=#a0a0a0>Pulls " + wagon.WagonName.Replace("<", "‹").Replace(">", "›") + "</color>";
				}
			}
		}

		public static bool SaddleInteractPrefix(Sadle __instance, bool __1, bool __2, ref bool __result)
		{
			if (!__2 || (Object)(object)Lox((Component)(object)((Component)__instance).GetComponentInParent<Character>()) == (Object)null)
			{
				return true;
			}
			__result = true;
			return false;
		}

		public static void SaddleHoverPostfix(Sadle __instance, ref string __result)
		{
			if (!((Object)(object)Lox((Component)(object)((Component)__instance).GetComponentInParent<Character>()) == (Object)null) && !string.IsNullOrEmpty(__result))
			{
				List<string> list = new List<string>(__result.Split('\n'));
				if (list.Count > 2)
				{
					list.RemoveRange(2, list.Count - 2);
				}
				__result = string.Join("\n", list);
			}
		}

		public static bool RemoveSaddlePrefix(Sadle __instance)
		{
			return (Object)(object)Lox((Component)(object)((Component)__instance).GetComponentInParent<Character>()) == (Object)null;
		}

		public static bool SetFollowPrefix(MonsterAI __instance)
		{
			return (Object)(object)Lox((Component)(object)__instance) == (Object)null;
		}
	}
	internal static class Trampler
	{
		private static readonly Collider[] _hits = (Collider[])(object)new Collider[64];

		private static readonly HashSet<Destructible> _done = new HashSet<Destructible>();

		private static int _mask;

		private static int _count;

		private static int _logged;

		internal static void Run(DraftLox lox, VarcisWagon wagon)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: 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_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: 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)
			if (!Cfg.Trample.Value || (Object)(object)lox == (Object)null || (Object)(object)lox.Character == (Object)null)
			{
				return;
			}
			Vector3 velocity = lox.Character.GetVelocity();
			velocity.y = 0f;
			if (!(((Vector3)(ref velocity)).magnitude < 0.3f))
			{
				if (_mask == 0)
				{
					_mask = LayerMask.GetMask(new string[5] { "Default", "static_solid", "Default_small", "piece_nonsolid", "vehicle" });
				}
				_done.Clear();
				Vector3 normalized = ((Vector3)(ref velocity)).normalized;
				Sweep(Physics.OverlapSphereNonAlloc(((Component)lox).transform.position + normalized * 1.8f + Vector3.up, 2.2f, _hits, _mask, (QueryTriggerInteraction)1), normalized, lox);
				if ((Object)(object)wagon != (Object)null)
				{
					Transform transform = ((Component)wagon).transform;
					Sweep(Physics.OverlapBoxNonAlloc(transform.TransformPoint(Prefabs.WagonCenterLocal), Prefabs.WagonHalfExtents, _hits, transform.rotation, _mask, (QueryTriggerInteraction)1), normalized, lox);
				}
			}
		}

		private static void Sweep(int n, Vector3 dir, DraftLox lox)
		{
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: 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_0070: 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_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Expected O, but got Unknown
			for (int i = 0; i < n; i++)
			{
				Collider val = _hits[i];
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				Destructible componentInParent = ((Component)val).GetComponentInParent<Destructible>();
				if (!((Object)(object)componentInParent == (Object)null) && !_done.Contains(componentInParent) && Tramplable(componentInParent))
				{
					_done.Add(componentInParent);
					HitData val2 = new HitData();
					Bounds bounds = val.bounds;
					val2.m_point = ((Bounds)(ref bounds)).center;
					val2.m_dir = dir;
					val2.m_toolTier = 0;
					val2.m_hitType = (HitType)13;
					HitData val3 = val2;
					val3.m_damage.m_chop = 1000f;
					val3.m_damage.m_blunt = 1000f;
					componentInParent.Damage(val3);
					_count++;
					if (_logged++ < 20)
					{
						Plugin.Diag("trample: " + Utils.GetPrefabName(((Component)componentInParent).gameObject) + " (health " + componentInParent.m_health.ToString("0") + "), " + _count + " so far");
					}
				}
			}
		}

		internal static bool Tramplable(Destructible d)
		{
			//IL_001e: 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)
			if (d.m_minToolTier > 0 || d.m_health > Cfg.TrampleMaxHealth.Value)
			{
				return false;
			}
			if ((d.m_destructibleType & 2) == 0)
			{
				return false;
			}
			GameObject gameObject = ((Component)d).gameObject;
			string text = Utils.GetPrefabName(gameObject).ToLowerInvariant();
			if (text.Contains("stub") || text.Contains("stump") || text.Contains("log"))
			{
				return false;
			}
			if ((Object)(object)gameObject.GetComponentInParent<WearNTear>() != (Object)null || (Object)(object)gameObject.GetComponentInParent<Plant>() != (Object)null || (Object)(object)gameObject.GetComponentInParent<Pickable>() != (Object)null || (Object)(object)gameObject.GetComponentInParent<Character>() != (Object)null || (Object)(object)gameObject.GetComponentInParent<MineRock>() != (Object)null || (Object)(object)gameObject.GetComponentInParent<MineRock5>() != (Object)null || (Object)(object)gameObject.GetComponentInParent<TreeBase>() != (Object)null || (Object)(object)gameObject.GetComponentInParent<Container>() != (Object)null)
			{
				return false;
			}
			ZNetView componentInParent = gameObject.GetComponentInParent<ZNetView>();
			if ((Object)(object)componentInParent != (Object)null)
			{
				return componentInParent.IsValid();
			}
			return false;
		}
	}
	internal static class LoxCamera
	{
		private static FieldInfo _distF;

		private static float _savedMax = -1f;

		private static bool _wasRiding;

		private static float _ease;

		internal static Transform Ignore;

		internal static int Swapped;

		private static RaycastHit[] _many;

		private static float Dist(GameCamera c)
		{
			if ((object)_distF == null)
			{
				_distF = AccessTools.Field(typeof(GameCamera), "m_distance");
			}
			if (!(_distF != null))
			{
				return 0f;
			}
			return (float)_distF.GetValue(c);
		}

		private static void SetDist(GameCamera c, float v)
		{
			if ((object)_distF == null)
			{
				_distF = AccessTools.Field(typeof(GameCamera), "m_distance");
			}
			_distF?.SetValue(c, v);
		}

		private static DraftLox Riding()
		{
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null || DraftLox.All.Count == 0)
			{
				return null;
			}
			IDoodadController doodadController = localPlayer.GetDoodadController();
			Component val = (Component)(object)((doodadController is Component) ? doodadController : null);
			if (val == null || !((Object)(object)val != (Object)null))
			{
				return null;
			}
			return val.GetComponentInParent<DraftLox>();
		}

		public static void UpdateCameraPrefix(GameCamera __instance)
		{
			float value = Cfg.LoxCamera.Value;
			DraftLox draftLox = ((value > 0f) ? Riding() : null);
			if ((Object)(object)draftLox == (Object)null)
			{
				Ignore = null;
				if (_wasRiding)
				{
					_wasRiding = false;
					if (Dist(__instance) > __instance.m_maxDistance)
					{
						_ease = 1f;
					}
				}
				if (_ease > 0f)
				{
					_ease -= Time.deltaTime;
					float num = Dist(__instance);
					if (num > __instance.m_maxDistance + 0.05f)
					{
						_savedMax = __instance.m_maxDistance;
						__instance.m_maxDistance = Mathf.Lerp(num, _savedMax, Time.deltaTime * 4f);
						SetDist(__instance, __instance.m_maxDistance);
					}
					else
					{
						_ease = 0f;
					}
				}
				return;
			}
			VarcisWagon wagon = draftLox.Wagon;
			Ignore = (((Object)(object)wagon != (Object)null) ? ((Component)wagon).transform : null);
			_savedMax = __instance.m_maxDistance;
			__instance.m_maxDistance = Mathf.Max(_savedMax, value);
			if (!_wasRiding)
			{
				_wasRiding = true;
				_ease = 1.5f;
			}
			if (_ease > 0f)
			{
				_ease -= Time.deltaTime;
				float num2 = Dist(__instance);
				if (num2 < value)
				{
					SetDist(__instance, Mathf.MoveTowards(num2, value, Time.deltaTime * 10f));
				}
				else
				{
					_ease = 0f;
				}
			}
		}

		public static void UpdateCameraPostfix(GameCamera __instance)
		{
			if (_savedMax >= 0f)
			{
				__instance.m_maxDistance = _savedMax;
				_savedMax = -1f;
			}
		}

		public static IEnumerable<CodeInstruction> RayTestTranspiler(IEnumerable<CodeInstruction> instructions)
		{
			MethodInfo _sphere = AccessTools.Method(typeof(Physics), "SphereCast", new Type[6]
			{
				typeof(Vector3),
				typeof(float),
				typeof(Vector3),
				typeof(RaycastHit).MakeByRefType(),
				typeof(float),
				typeof(int)
			}, (Type[])null);
			MethodInfo _ray = AccessTools.Method(typeof(Physics), "Raycast", new Type[5]
			{
				typeof(Vector3),
				typeof(Vector3),
				typeof(RaycastHit).MakeByRefType(),
				typeof(float),
				typeof(int)
			}, (Type[])null);
			MethodInfo sp = AccessTools.Method(typeof(LoxCamera), "SphereCast", (Type[])null, (Type[])null);
			MethodInfo rp = AccessTools.Method(typeof(LoxCamera), "Raycast", (Type[])null, (Type[])null);
			foreach (CodeInstruction instruction in instructions)
			{
				if (instruction.opcode == OpCodes.Call && instruction.operand is MethodInfo methodInfo && (methodInfo == _sphere || methodInfo == _ray))
				{
					Swapped++;
					yield return new CodeInstruction(OpCodes.Call, (object)((methodInfo == _sphere) ? sp : rp))
					{
						labels = instruction.labels,
						blocks = instruction.blocks
					};
				}
				else
				{
					yield return instruction;
				}
			}
		}

		public static bool SphereCast(Vector3 origin, float radius, Vector3 dir, out RaycastHit hit, float maxDist, int mask)
		{
			//IL_000d: 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_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)Ignore == (Object)null)
			{
				return Physics.SphereCast(origin, radius, dir, ref hit, maxDist, mask);
			}
			if (_many == null)
			{
				_many = (RaycastHit[])(object)new RaycastHit[32];
			}
			return Nearest(Physics.SphereCastNonAlloc(origin, radius, dir, _many, maxDist, mask), out hit);
		}

		public static bool Raycast(Vector3 origin, Vector3 dir, out RaycastHit hit, float maxDist, int mask)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: 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)
			if ((Object)(object)Ignore == (Object)null)
			{
				return Physics.Raycast(origin, dir, ref hit, maxDist, mask);
			}
			if (_many == null)
			{
				_many = (RaycastHit[])(object)new RaycastHit[32];
			}
			return Nearest(Physics.RaycastNonAlloc(origin, dir, _many, maxDist, mask), out hit);
		}

		private static bool Nearest(int n, out RaycastHit hit)
		{
			//IL_0001: 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)
			hit = default(RaycastHit);
			float num = float.MaxValue;
			for (int i = 0; i < n; i++)
			{
				Collider collider = ((RaycastHit)(ref _many[i])).collider;
				if (!((Object)(object)collider == (Object)null) && !((Component)collider).transform.IsChildOf(Ignore) && ((RaycastHit)(ref _many[i])).distance < num)
				{
					num = ((RaycastHit)(ref _many[i])).distance;
					hit = _many[i];
				}
			}
			return num < float.MaxValue;
		}
	}
	internal static class IconCamera
	{
		private static int _layer = -1;

		private static int Layer()
		{
			if (_layer >= 0)
			{
				return _layer;
			}
			for (int num = 31; num >= 8; num--)
			{
				if (string.IsNullOrEmpty(LayerMask.LayerToName(num)))
				{
					return _layer = num;
				}
			}
			return _layer = 31;
		}

		private static void SetLayer(Transform t, int layer)
		{
			((Component)t).gameObject.layer = layer;
			for (int i = 0; i < t.childCount; i++)
			{
				SetLayer(t.GetChild(i), layer);
			}
		}

		internal static Sprite Render(GameObject model, Quaternion view, int size = 128)
		{
			//IL_0398: Unknown result type (might be due to invalid IL or missing references)
			//IL_039f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Expected O, but got Unknown
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Expected O, but got Unknown
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Expected O, but got Unknown
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_0252: 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_0267: Unknown result type (might be due to invalid IL or missing references)
			//IL_0286: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bf: Expected O, but got Unknown
			//IL_02cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0374: Unknown result type (might be due to invalid IL or missing references)
			//IL_0383: Unknown result type (might be due to invalid IL or missing references)
			int num = Layer();
			SetLayer(model.trans