Decompiled source of LoxWagon v0.6.1

LoxWagon.dll

Decompiled 3 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace HaldorWagonMod
{
	internal static class WagonCargo
	{
		private sealed class MeshPart
		{
			internal Mesh Mesh;

			internal Material[] Materials;

			internal Matrix4x4 Matrix;
		}

		private sealed class Model
		{
			internal string Name;

			internal List<MeshPart> Parts = new List<MeshPart>();

			internal List<Vector3> Corners = new List<Vector3>();
		}

		private sealed class Packed
		{
			internal Bounds Bounds;

			internal int Stage;
		}

		internal static float InteriorFloor(float x)
		{
			x = Mathf.Abs(x);
			float[] array = new float[5] { 0f, 0.5044f, 1.0087f, 1.3835f, 1.6927f };
			float[] array2 = new float[5] { 1.91f, 1.995f, 2.245f, 2.605f, 3.065f };
			for (int i = 1; i < array.Length; i++)
			{
				if (x <= array[i])
				{
					return Mathf.Lerp(array2[i - 1], array2[i], (x - array[i - 1]) / (array[i] - array[i - 1]));
				}
			}
			return array2[^1] + (x - array[^1]) * 2f;
		}

		internal static void Build(GameObject wagon, GameObject vanillaCart)
		{
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Expected O, but got Unknown
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Expected O, but got Unknown
			//IL_00ef: 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_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Expected O, but got Unknown
			Vagon component = wagon.GetComponent<Vagon>();
			Vagon source = vanillaCart.GetComponent<Vagon>();
			Func<string, Model> obj = (string name) => Read(source.m_loadVis.First((LoadData x) => (Object)(object)x.m_gameobject != (Object)null && ((Object)x.m_gameobject).name == name).m_gameobject);
			Model model = obj("default");
			Model model2 = obj("barrel");
			Model model3 = obj("bucket");
			GameObject val = new GameObject("WagonVisibleCargo");
			val.transform.SetParent(wagon.transform, false);
			val.SetActive(false);
			List<LoadData> list = new List<LoadData>(component.m_loadVis);
			Transform[] array = (Transform[])(object)new Transform[7];
			float[] array2 = new float[7] { 1f, 10f, 20f, 40f, 60f, 80f, 95f };
			List<Packed> list2 = new List<Packed>();
			try
			{
				for (int num = 0; num < 7; num++)
				{
					GameObject val2 = new GameObject("CargoAt" + array2[num] + "Percent");
					val2.transform.SetParent(val.transform, false);
					val2.SetActive(false);
					array[num] = val2.transform;
					list.Add(new LoadData
					{
						m_gameobject = val2,
						m_minPercentage = array2[num]
					});
				}
				Place(model2, array, list2, 0, -0.64f, 2.35f, 1.16f, 1.16f, 1.44f, 0f, 90f);
				Place(model2, array, list2, 0, 0.64f, 2.35f, 1.16f, 1.16f, 1.44f, 0f, 90f);
				Place(model2, array, list2, 1, -0.62f, -1.14f, 1.04f, 1.13f, 1.08f, 0f, 0f);
				Place(model, array, list2, 1, 0.56f, -1.17f, 1.1f, 1f, 1.13f, 2f, 0f);
				Place(model, array, list2, 2, -0.59f, 0.04f, 1.1f, 1.1f, 1.12f, -2f, 0f);
				Place(model, array, list2, 2, 0.6f, -0.01f, 1.12f, 1.04f, 1.08f, 1f, 0f);
				Place(model, array, list2, 2, -0.63f, 1.08f, 1.15f, 1.03f, 0.88f, 1f, 0f);
				Place(model, array, list2, 2, 0.62f, 1.04f, 1.13f, 1f, 0.91f, -2f, 0f);
				Place(model, array, list2, 3, -1.38f, -0.94f, 0.26f, 0.65f, 0.67f, 0f, 0f);
				Place(model, array, list2, 3, 1.37f, -0.52f, 0.27f, 0.67f, 0.68f, 0f, 0f);
				Place(model, array, list2, 3, -1.38f, 0.31f, 0.26f, 0.68f, 0.6f, 0f, 0f);
				Place(model, array, list2, 3, 1.38f, 0.62f, 0.26f, 0.7f, 0.64f, 0f, 0f);
				Place(model, array, list2, 3, -1.38f, 1.91f, 0.26f, 0.62f, 0.72f, 0f, 0f);
				Place(model, array, list2, 3, 1.38f, 2.37f, 0.26f, 0.58f, 0.73f, 0f, 0f);
				Place(model, array, list2, 4, -0.56f, -1.11f, 0.84f, 0.62f, 0.81f, -5f, 0f, 2);
				Place(model, array, list2, 4, 0.5f, -1.16f, 0.93f, 0.71f, 0.96f, 4f, 0f, 3);
				Place(model, array, list2, 4, -0.51f, 0.04f, 0.91f, 0.82f, 0.93f, 3f, 0f, 4);
				Place(model2, array, list2, 4, 0.61f, -0.04f, 0.91f, 0.75f, 0.94f, 0f, 90f, 5);
				Place(model, array, list2, 4, -0.6f, 1.08f, 0.99f, 0.73f, 0.72f, -4f, 0f, 6);
				Place(model, array, list2, 4, 0.59f, 1.03f, 0.97f, 0.69f, 0.75f, 3f, 0f, 7);
				Place(model, array, list2, 5, -0.61f, 2.3f, 0.8f, 0.48f, 0.87f, -3f, 0f, 0);
				Place(model, array, list2, 5, 0.59f, 2.27f, 0.85f, 0.52f, 0.83f, 4f, 0f, 1);
				Place(model, array, list2, 5, -0.49f, 0.04f, 0.72f, 0.34f, 0.67f, -7f, 0f, 16);
				Place(model, array, list2, 5, -0.57f, 1.07f, 0.68f, 0.39f, 0.55f, 6f, 0f, 18);
				Place(model, array, list2, 5, 0.54f, 1.02f, 0.71f, 0.36f, 0.59f, -5f, 0f, 19);
				Place(model3, array, list2, 5, 0.48f, -1.17f, 0.4f, 0.42f, 0.4f, 0f, 0f, 15);
				Place(model, array, list2, 6, -0.57f, -1.12f, 0.6f, 0.27f, 0.54f, 5f, 0f, 14);
				Place(model, array, list2, 6, 0.58f, -0.03f, 0.63f, 0.35f, 0.66f, -4f, 0f, 17);
				Place(model, array, list2, 6, -0.63f, 2.29f, 0.54f, 0.27f, 0.54f, 6f, 0f, 20);
				Place(model3, array, list2, 6, 0.59f, 2.27f, 0.38f, 0.39f, 0.38f, 0f, 0f, 21);
				try
				{
					FillFloorGaps(model, array, list2);
				}
				catch (Exception ex)
				{
					HaldorWagonPlugin.Log.LogWarning((object)("Optional gap fillers incomplete; existing cargo retained: " + ex.Message));
				}
				try
				{
					BuildTarp(array[6], list2.Select((Packed p) => p.Bounds).ToList());
				}
				catch (Exception ex2)
				{
					HaldorWagonPlugin.Log.LogWarning((object)("Canvas unavailable; existing cargo retained: " + ex2.Message));
				}
				component.m_loadVis = list;
				val.SetActive(true);
				HaldorWagonPlugin.Log.LogInfo((object)("Cargo ready: " + list2.Count + " authored props; full-load cover stage is 95% (31-32 occupied slots). See canvas log for construction status."));
			}
			catch
			{
				Object.DestroyImmediate((Object)(object)val);
				throw;
			}
		}

		private static float OverlapArea(Bounds a, Bounds b)
		{
			//IL_0007: 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_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: 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_0069: 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)
			return Mathf.Max(0f, Mathf.Min(((Bounds)(ref a)).max.x, ((Bounds)(ref b)).max.x) - Mathf.Max(((Bounds)(ref a)).min.x, ((Bounds)(ref b)).min.x)) * Mathf.Max(0f, Mathf.Min(((Bounds)(ref a)).max.z, ((Bounds)(ref b)).max.z) - Mathf.Max(((Bounds)(ref a)).min.z, ((Bounds)(ref b)).min.z));
		}

		private static void Place(Model model, Transform[] stages, List<Packed> packed, int stage, float x, float z, float width, float height, float depth, float yaw, float pitch, int support = -1)
		{
			//IL_0009: 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_0011: 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_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: 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_0048: 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_0080: 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_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: 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_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: Unknown result type (might be due to invalid IL or missing references)
			//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b1: Expected O, but got Unknown
			//IL_02ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_02df: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_0307: Unknown result type (might be due to invalid IL or missing references)
			//IL_0311: Unknown result type (might be due to invalid IL or missing references)
			//IL_031d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0329: Unknown result type (might be due to invalid IL or missing references)
			//IL_022d: Unknown result type (might be due to invalid IL or missing references)
			//IL_023e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0358: Unknown result type (might be due to invalid IL or missing references)
			//IL_035d: Unknown result type (might be due to invalid IL or missing references)
			//IL_036b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0379: Unknown result type (might be due to invalid IL or missing references)
			//IL_037e: 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)
			//IL_0384: Unknown result type (might be due to invalid IL or missing references)
			//IL_0389: Unknown result type (might be due to invalid IL or missing references)
			//IL_038b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0390: Unknown result type (might be due to invalid IL or missing references)
			//IL_039a: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_03dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0408: Unknown result type (might be due to invalid IL or missing references)
			//IL_040d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0416: Unknown result type (might be due to invalid IL or missing references)
			//IL_0420: Unknown result type (might be due to invalid IL or missing references)
			//IL_0466: Unknown result type (might be due to invalid IL or missing references)
			//IL_0468: Unknown result type (might be due to invalid IL or missing references)
			Quaternion val = Quaternion.Euler(pitch, yaw, 0f);
			Bounds val2 = default(Bounds);
			((Bounds)(ref val2))..ctor(val * model.Corners[0], Vector3.zero);
			foreach (Vector3 corner in model.Corners)
			{
				((Bounds)(ref val2)).Encapsulate(val * corner);
			}
			Vector3 val3 = default(Vector3);
			((Vector3)(ref val3))..ctor(width, height, depth);
			Vector3 localScale = default(Vector3);
			((Vector3)(ref localScale))..ctor(width / ((Bounds)(ref val2)).size.x, height / ((Bounds)(ref val2)).size.y, depth / ((Bounds)(ref val2)).size.z);
			float num = InteriorFloor(Mathf.Abs(x) + width * 0.5f) + 0.025f;
			float num2 = num;
			if (support >= 0)
			{
				num2 = ((Bounds)(ref packed[support].Bounds)).max.y + 0.008f;
			}
			Bounds val4 = default(Bounds);
			((Bounds)(ref val4))..ctor(new Vector3(x, num2 + height * 0.5f, z), val3);
			if (((Bounds)(ref val4)).min.x < -1.551f || ((Bounds)(ref val4)).max.x > 1.551f || ((Bounds)(ref val4)).min.z < -1.841f || ((Bounds)(ref val4)).max.z > 3.101f || num2 < num - 0.001f)
			{
				throw new Exception("Authored cargo outside curved interior at " + packed.Count);
			}
			if (support >= 0 && (packed[support].Stage > stage || OverlapArea(val4, packed[support].Bounds) < width * depth * 0.85f))
			{
				throw new Exception("Authored cargo lacks earlier support at " + packed.Count);
			}
			foreach (Packed item in packed)
			{
				if (OverlapArea(val4, item.Bounds) > 1E-05f && ((Bounds)(ref val4)).min.y < ((Bounds)(ref item.Bounds)).max.y - 0.001f && ((Bounds)(ref val4)).max.y > ((Bounds)(ref item.Bounds)).min.y + 0.001f)
				{
					throw new Exception("Authored cargo overlaps at " + packed.Count);
				}
			}
			GameObject val5 = new GameObject(model.Name + "_Cargo_" + packed.Count);
			val5.transform.SetParent(stages[stage], false);
			val5.transform.localPosition = new Vector3(x, num2, z);
			val5.transform.localScale = localScale;
			Transform transform = new GameObject("Orientation").transform;
			transform.SetParent(val5.transform, false);
			transform.localRotation = val;
			Vector3 val6 = default(Vector3);
			((Vector3)(ref val6))..ctor(((Bounds)(ref val2)).center.x, ((Bounds)(ref val2)).min.y, ((Bounds)(ref val2)).center.z);
			foreach (MeshPart part in model.Parts)
			{
				GameObject val7 = new GameObject("Mesh");
				val7.transform.SetParent(transform, false);
				val7.transform.localPosition = Vector4.op_Implicit(((Matrix4x4)(ref part.Matrix)).GetColumn(3)) - Quaternion.Inverse(val) * val6;
				val7.transform.localRotation = Quaternion.LookRotation(Vector4.op_Implicit(((Matrix4x4)(ref part.Matrix)).GetColumn(2)), Vector4.op_Implicit(((Matrix4x4)(ref part.Matrix)).GetColumn(1)));
				Transform transform2 = val7.transform;
				Vector4 column = ((Matrix4x4)(ref part.Matrix)).GetColumn(0);
				float magnitude = ((Vector4)(ref column)).magnitude;
				column = ((Matrix4x4)(ref part.Matrix)).GetColumn(1);
				float magnitude2 = ((Vector4)(ref column)).magnitude;
				column = ((Matrix4x4)(ref part.Matrix)).GetColumn(2);
				transform2.localScale = new Vector3(magnitude, magnitude2, ((Vector4)(ref column)).magnitude);
				val7.AddComponent<MeshFilter>().sharedMesh = part.Mesh;
				((Renderer)val7.AddComponent<MeshRenderer>()).sharedMaterials = part.Materials;
			}
			packed.Add(new Packed
			{
				Bounds = val4,
				Stage = stage
			});
		}

		private static void FillFloorGaps(Model crate, Transform[] stages, List<Packed> packed)
		{
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: 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)
			float[] array = new float[7] { 2.73f, 2.04f, 1.31f, 0.59f, -0.13f, -0.85f, -1.5f };
			Bounds a = default(Bounds);
			for (int i = 0; i < array.Length; i++)
			{
				float num = array[i];
				float[] array2 = new float[4] { -0.75f, -0.25f, 0.25f, 0.75f };
				for (int j = 0; j < array2.Length; j++)
				{
					float num2 = array2[j];
					float num3 = InteriorFloor(Mathf.Abs(num2) + 0.225f) + 0.025f;
					((Bounds)(ref a))..ctor(new Vector3(num2, num3, num), new Vector3(0.45f, 0f, 0.62f));
					if (((Bounds)(ref a)).min.x < -1.551f || ((Bounds)(ref a)).max.x > 1.551f || ((Bounds)(ref a)).min.z < -1.841f || ((Bounds)(ref a)).max.z > 3.101f)
					{
						HaldorWagonPlugin.Log.LogWarning((object)("Skipped optional floor filler outside bed at x=" + num2 + " z=" + num));
						continue;
					}
					float num4 = float.MaxValue;
					int stage = 6;
					foreach (Packed item in packed)
					{
						if (OverlapArea(a, item.Bounds) > 1E-05f && ((Bounds)(ref item.Bounds)).min.y < num4)
						{
							num4 = ((Bounds)(ref item.Bounds)).min.y;
							stage = item.Stage;
						}
					}
					float num5 = Mathf.Min(0.65f, num4 - num3 - 0.014f);
					if (num4 != float.MaxValue && !(num5 < 0.14f))
					{
						Place(crate, stages, packed, stage, num2, num, 0.45f, num5, 0.62f, 0f, 0f);
					}
				}
			}
		}

		private static void Bridge(float[] heights)
		{
			List<int> list = new List<int>();
			for (int i = 0; i < heights.Length; i++)
			{
				while (list.Count >= 2)
				{
					int num = list[list.Count - 2];
					int num2 = list[list.Count - 1];
					if ((heights[num2] - heights[num]) / (float)(num2 - num) > (heights[i] - heights[num2]) / (float)(i - num2))
					{
						break;
					}
					list.RemoveAt(list.Count - 1);
				}
				list.Add(i);
			}
			for (int j = 1; j < list.Count; j++)
			{
				int num3 = list[j - 1];
				int num4 = list[j];
				float num5 = heights[num3];
				float num6 = heights[num4];
				for (int k = num3 + 1; k < num4; k++)
				{
					heights[k] = Mathf.Lerp(num5, num6, (float)(k - num3) / (float)(num4 - num3));
				}
			}
		}

		private static void Rope(Transform parent, string name, IEnumerable<Vector3> points, Material material, float width)
		{
			//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)
			GameObject val = new GameObject(name);
			val.transform.SetParent(parent, false);
			LineRenderer obj = val.AddComponent<LineRenderer>();
			obj.useWorldSpace = false;
			((Renderer)obj).sharedMaterial = material;
			float startWidth = (obj.endWidth = width);
			obj.startWidth = startWidth;
			obj.numCornerVertices = 3;
			obj.numCapVertices = 3;
			Vector3[] array = points.ToArray();
			obj.positionCount = array.Length;
			obj.SetPositions(array);
		}

		private static Model Read(GameObject source)
		{
			//IL_0051: 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_0066: 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_008f: 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_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: 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_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_00e3: Unknown result type (might be due to invalid IL or missing references)
			Model model = new Model
			{
				Name = ((Object)source).name
			};
			MeshFilter[] componentsInChildren = source.GetComponentsInChildren<MeshFilter>(true);
			foreach (MeshFilter val in componentsInChildren)
			{
				MeshRenderer component = ((Component)val).GetComponent<MeshRenderer>();
				if ((Object)(object)val.sharedMesh == (Object)null || (Object)(object)component == (Object)null)
				{
					continue;
				}
				Matrix4x4 matrix = source.transform.worldToLocalMatrix * ((Component)val).transform.localToWorldMatrix;
				model.Parts.Add(new MeshPart
				{
					Mesh = val.sharedMesh,
					Materials = ((Renderer)component).sharedMaterials,
					Matrix = matrix
				});
				Bounds bounds = val.sharedMesh.bounds;
				for (int j = -1; j <= 1; j += 2)
				{
					for (int k = -1; k <= 1; k += 2)
					{
						for (int l = -1; l <= 1; l += 2)
						{
							model.Corners.Add(((Matrix4x4)(ref matrix)).MultiplyPoint3x4(((Bounds)(ref bounds)).center + Vector3.Scale(((Bounds)(ref bounds)).extents, new Vector3((float)j, (float)k, (float)l))));
						}
					}
				}
			}
			if (model.Corners.Count == 0)
			{
				throw new Exception("No mesh for cargo " + ((Object)source).name);
			}
			return model;
		}

		private static void BuildTarp(Transform parent, List<Bounds> loads)
		{
			//IL_02de: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ef: Expected O, but got Unknown
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: 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_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: 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_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_033f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0355: Unknown result type (might be due to invalid IL or missing references)
			//IL_035a: Unknown result type (might be due to invalid IL or missing references)
			//IL_035f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0373: Unknown result type (might be due to invalid IL or missing references)
			//IL_0389: Unknown result type (might be due to invalid IL or missing references)
			//IL_038e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0393: Unknown result type (might be due to invalid IL or missing references)
			//IL_0399: Unknown result type (might be due to invalid IL or missing references)
			//IL_039b: Unknown result type (might be due to invalid IL or missing references)
			//IL_039d: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_040d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0412: Unknown result type (might be due to invalid IL or missing references)
			//IL_041f: Expected O, but got Unknown
			//IL_0435: Unknown result type (might be due to invalid IL or missing references)
			//IL_0464: Unknown result type (might be due to invalid IL or missing references)
			//IL_046b: Expected O, but got Unknown
			//IL_0526: Unknown result type (might be due to invalid IL or missing references)
			//IL_0535: Unknown result type (might be due to invalid IL or missing references)
			//IL_053a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0547: Unknown result type (might be due to invalid IL or missing references)
			//IL_0577: Unknown result type (might be due to invalid IL or missing references)
			//IL_057c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0589: Expected O, but got Unknown
			//IL_059f: Unknown result type (might be due to invalid IL or missing references)
			//IL_04df: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_060b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0610: Unknown result type (might be due to invalid IL or missing references)
			//IL_061a: Unknown result type (might be due to invalid IL or missing references)
			//IL_061f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0643: Unknown result type (might be due to invalid IL or missing references)
			Vector3[] array = (Vector3[])(object)new Vector3[1225];
			Vector2[] array2 = (Vector2[])(object)new Vector2[array.Length];
			List<int> list = new List<int>();
			for (int i = 0; i <= 48; i++)
			{
				for (int j = 0; j <= 24; j++)
				{
					float num = (float)j / 24f;
					float num2 = (float)i / 48f;
					float num3 = Mathf.Lerp(-1.62f, 1.62f, num);
					float num4 = Mathf.Lerp(-1.73f, 2.86f, num2);
					float num5 = 2.82f;
					foreach (Bounds load in loads)
					{
						Bounds current = load;
						float num6 = Mathf.Max(new float[3]
						{
							((Bounds)(ref current)).min.x - num3,
							0f,
							num3 - ((Bounds)(ref current)).max.x
						});
						float num7 = Mathf.Max(new float[3]
						{
							((Bounds)(ref current)).min.z - num4,
							0f,
							num4 - ((Bounds)(ref current)).max.z
						});
						num5 = Mathf.Max(num5, ((Bounds)(ref current)).max.y + 0.12f - 1.65f * Mathf.Sqrt(num6 * num6 + num7 * num7));
					}
					int num8 = i * 25 + j;
					array[num8] = new Vector3(num3, num5, num4);
					array2[num8] = new Vector2(num * 2f, num2 * 4f);
					if (j < 24 && i < 48)
					{
						int num9 = num8 + 24 + 1;
						list.AddRange(new int[12]
						{
							num8,
							num9,
							num8 + 1,
							num8 + 1,
							num9,
							num9 + 1,
							num8 + 1,
							num9,
							num8,
							num9 + 1,
							num9,
							num8 + 1
						});
					}
				}
			}
			for (int k = 0; k <= 24; k++)
			{
				float[] array3 = new float[49];
				for (int l = 0; l <= 48; l++)
				{
					array3[l] = array[l * 25 + k].y;
				}
				Bridge(array3);
				for (int m = 0; m <= 48; m++)
				{
					array[m * 25 + k].y = array3[m];
				}
			}
			for (int n = 0; n <= 48; n++)
			{
				float[] array4 = new float[25];
				for (int num10 = 0; num10 <= 24; num10++)
				{
					array4[num10] = array[n * 25 + num10].y;
				}
				Bridge(array4);
				for (int num11 = 0; num11 <= 24; num11++)
				{
					array[n * 25 + num11].y = array4[num11];
				}
			}
			Mesh val = new Mesh
			{
				name = "LoxWagon_TensionedCanvas"
			};
			val.vertices = array;
			val.uv = array2;
			val.triangles = list.ToArray();
			Vector3[] array5 = (Vector3[])(object)new Vector3[array.Length];
			for (int num12 = 0; num12 <= 48; num12++)
			{
				for (int num13 = 0; num13 <= 24; num13++)
				{
					int num14 = num12 * 25 + num13;
					Vector3 val2 = array[num12 * 25 + Mathf.Min(24, num13 + 1)] - array[num12 * 25 + Mathf.Max(0, num13 - 1)];
					Vector3 val3 = array[Mathf.Min(48, num12 + 1) * 25 + num13] - array[Mathf.Max(0, num12 - 1) * 25 + num13];
					Vector3 val4 = Vector3.Cross(val3, val2);
					array5[num14] = ((Vector3)(ref val4)).normalized;
				}
			}
			val.normals = array5;
			val.RecalculateBounds();
			Shader val5 = Shader.Find("Standard") ?? Shader.Find("Legacy Shaders/Diffuse");
			if ((Object)(object)val5 == (Object)null)
			{
				throw new Exception("No supported canvas shader");
			}
			Material val6 = new Material(val5)
			{
				name = "LoxWagon_WhiteCanvas"
			};
			val6.color = new Color(0.97f, 0.97f, 0.95f, 1f);
			if (val6.HasProperty("_Glossiness"))
			{
				val6.SetFloat("_Glossiness", 0f);
			}
			Texture2D val7 = new Texture2D(32, 32, (TextureFormat)4, false);
			((Object)val7).name = "LoxWagon_CanvasWeave";
			((Texture)val7).wrapMode = (TextureWrapMode)0;
			Color[] array6 = (Color[])(object)new Color[1024];
			for (int num15 = 0; num15 < 32; num15++)
			{
				for (int num16 = 0; num16 < 32; num16++)
				{
					float num17 = 0.94f + 0.025f * (float)((num16 + num15) % 2) + 0.015f * Mathf.Sin((float)num16 * 1.7f + (float)num15 * 2.3f);
					array6[num15 * 32 + num16] = new Color(num17, num17, num17, 1f);
				}
			}
			val7.SetPixels(array6);
			val7.Apply();
			val6.mainTexture = (Texture)(object)val7;
			val6.mainTextureScale = new Vector2(8f, 8f);
			GameObject val8 = new GameObject("FullLoadCanvas");
			val8.transform.SetParent(parent, false);
			val8.AddComponent<MeshFilter>().sharedMesh = val;
			MeshRenderer val9 = val8.AddComponent<MeshRenderer>();
			((Renderer)val9).sharedMaterial = val6;
			WagonTarpTexture.Add(((Component)parent.root).gameObject, (Renderer)(object)val9);
			Material val10 = new Material(val5)
			{
				name = "LoxWagon_CanvasLashings"
			};
			val10.color = new Color(0.3f, 0.22f, 0.12f, 1f);
			int[] array7 = new int[4] { 3, 17, 32, 45 };
			for (int num18 = 0; num18 < array7.Length; num18++)
			{
				int num19 = array7[num18];
				float z = array[num19 * 25].z;
				List<Vector3> list2 = new List<Vector3>
				{
					new Vector3(-1.69f, 3.06f, z)
				};
				for (int num20 = 0; num20 <= 24; num20++)
				{
					list2.Add(array[num19 * 25 + num20] + Vector3.up * 0.022f);
				}
				list2.Add(new Vector3(1.69f, 3.06f, z));
				Rope(parent, "CanvasLashing" + num19, list2, val10, 0.035f);
			}
			HaldorWagonPlugin.Log.LogInfo((object)("White canvas mesh ready: " + array.Length + " vertices; shader=" + ((Object)val5).name + "; stage=" + ((Object)parent).name));
		}
	}
	[BepInPlugin("greypoint.loxwagon", "LoxWagon", "0.6.1")]
	public sealed class HaldorWagonPlugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(ZNetScene), "Awake")]
		private static class RegisterNetworkPrefab
		{
			private static void Postfix(ZNetScene __instance)
			{
				try
				{
					if ((Object)(object)_prefab == (Object)null)
					{
						_prefab = CreatePrefab(__instance);
					}
					if (!((Object)(object)_prefab == (Object)null))
					{
						if (!__instance.m_prefabs.Contains(_prefab))
						{
							__instance.m_prefabs.Add(_prefab);
						}
						((Dictionary<int, GameObject>)AccessTools.Field(typeof(ZNetScene), "m_namedPrefabs").GetValue(__instance))[StringExtensionMethods.GetStableHashCode("greypoint_LoxWagon")] = _prefab;
						PatchBeasts();
						RegisterBuildPiece(ObjectDB.instance);
					}
				}
				catch (Exception ex)
				{
					Log.LogError((object)("Network prefab registration failed: " + ex));
				}
			}
		}

		[HarmonyPatch(typeof(ZNetScene), "Awake")]
		private static class FinishBuildRegistration
		{
			private static void Postfix()
			{
				RegisterBuildPiece(ObjectDB.instance);
			}
		}

		[HarmonyPatch(typeof(Player), "PlacePiece")]
		private static class ActivatePlacedWagon
		{
			private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
			{
				return InsertActivation(instructions, "Player.PlacePiece");
			}
		}

		[HarmonyPatch(typeof(ZNetScene), "CreateObject")]
		private static class ActivateLoadedWagon
		{
			private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
			{
				return InsertActivation(instructions, "ZNetScene.CreateObject");
			}
		}

		[HarmonyPatch(typeof(ObjectDB), "Awake")]
		private static class RegisterHammerPiece
		{
			private static void Postfix(ObjectDB __instance)
			{
				RegisterBuildPiece(__instance);
			}
		}

		[HarmonyPatch(typeof(ObjectDB), "CopyOtherDB")]
		private static class RegisterHammerPieceAfterCopy
		{
			private static void Postfix(ObjectDB __instance)
			{
				RegisterBuildPiece(__instance);
			}
		}

		[HarmonyPatch(typeof(Vagon), "CanAttach")]
		private static class LoxAttachmentCheck
		{
			private static void Postfix(Vagon __instance, GameObject go, ref bool __result)
			{
				//IL_0091: 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_00ae: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)((Component)__instance).GetComponent<LoxWagonController>() == (Object)null)
				{
					return;
				}
				Character val = (((Object)(object)go != (Object)null) ? go.GetComponent<Character>() : null);
				if (HumanPullTest.Value)
				{
					__result = __result && val is Player;
					if (!__result)
					{
						((Component)__instance).GetComponent<LoxWagonController>().LogCheckFailure(go);
					}
				}
				else
				{
					__result = (Object)(object)val != (Object)null && val.IsTamed() && !val.IsDead() && Utils.GetPrefabName(go) == "Lox" && (Object)(object)go.GetComponent<Rigidbody>() != (Object)null && ((Component)__instance).transform.up.y >= 0.1f && Vector3.Distance(go.transform.TransformPoint(__instance.m_attachOffset), __instance.m_attachPoint.position) < __instance.m_detachDistance;
					if (!__result)
					{
						((Component)__instance).GetComponent<LoxWagonController>().LogCheckFailure(go);
					}
				}
			}
		}

		[HarmonyPatch(typeof(Vagon), "Detach")]
		private static class TraceDetach
		{
			private static void Prefix(Vagon __instance)
			{
				LoxWagonController component = ((Component)__instance).GetComponent<LoxWagonController>();
				if ((Object)(object)component != (Object)null)
				{
					component.LogDetach();
					component.ReleaseCollisionPairs();
				}
			}
		}

		[HarmonyPatch(typeof(ImpactEffect), "OnCollisionEnter")]
		private static class NoWagonImpactDamage
		{
			private static bool Prefix(ImpactEffect __instance, Collision info)
			{
				if ((Object)(object)((Component)__instance).GetComponentInParent<LoxWagonController>() == (Object)null)
				{
					if (info != null && !((Object)(object)info.collider == (Object)null))
					{
						return (Object)(object)((Component)info.collider).GetComponentInParent<LoxWagonController>() == (Object)null;
					}
					return true;
				}
				return false;
			}
		}

		[HarmonyPatch(typeof(Player), "FindHoverObject")]
		private static class IncludeWagonTriggers
		{
			private static void Postfix(ref GameObject hover)
			{
				if ((Object)(object)hover == (Object)null || (Object)(object)hover.GetComponent<WagonHotspot>() != (Object)null || (Object)(object)hover.GetComponent<WagonSeat>() != (Object)null)
				{
					return;
				}
				LoxWagonController componentInParent = hover.GetComponentInParent<LoxWagonController>();
				if (!((Object)(object)componentInParent == (Object)null))
				{
					if ((Object)(object)hover != (Object)(object)((Component)componentInParent).gameObject)
					{
						hover = null;
						return;
					}
					Transform val = ((Component)componentInParent).transform.Find("CargoAccess-1");
					hover = (((Object)(object)val != (Object)null) ? ((Component)val).gameObject : null);
				}
			}

			private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
			{
				MethodInfo original = AccessTools.Method(typeof(Physics), "RaycastNonAlloc", new Type[5]
				{
					typeof(Vector3),
					typeof(Vector3),
					typeof(RaycastHit[]),
					typeof(float),
					typeof(int)
				}, (Type[])null);
				foreach (CodeInstruction instruction in instructions)
				{
					if (CodeInstructionExtensions.Calls(instruction, original))
					{
						instruction.operand = AccessTools.Method(typeof(HaldorWagonPlugin), "RaycastWithWagonTriggers", (Type[])null, (Type[])null);
					}
					yield return instruction;
				}
			}
		}

		[HarmonyPatch(typeof(Vagon), "SetMass")]
		private static class ReportWagonMass
		{
			private static void Postfix(Vagon __instance, float __0)
			{
				LoxWagonController component = ((Component)__instance).GetComponent<LoxWagonController>();
				if ((Object)(object)component != (Object)null && ((Behaviour)component).enabled)
				{
					component.ReportMass(__0);
				}
			}
		}

		[HarmonyPatch(typeof(Vagon), "UpdateAudio")]
		private static class CleanWheelAudioReferences
		{
			private static void Prefix(Vagon __instance)
			{
				if ((Object)(object)((Component)__instance).GetComponent<LoxWagonController>() == (Object)null)
				{
					return;
				}
				if (__instance.m_wheels == null)
				{
					__instance.m_wheels = (Rigidbody[])(object)new Rigidbody[0];
				}
				else if (__instance.m_wheels.Any((Rigidbody w) => (Object)(object)w == (Object)null))
				{
					__instance.m_wheels = __instance.m_wheels.Where((Rigidbody w) => (Object)(object)w != (Object)null).ToArray();
				}
			}
		}

		[HarmonyPatch(typeof(Hud), "SetupPieceInfo")]
		private static class EnsureRecipeDisplaySlots
		{
			private static readonly FieldInfo Slots = AccessTools.Field(typeof(Hud), "m_requirementItems");

			private static void Prefix(Hud __instance, Piece piece)
			{
				//IL_00ab: 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_0118: Unknown result type (might be due to invalid IL or missing references)
				//IL_011d: Unknown result type (might be due to invalid IL or missing references)
				//IL_012c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0131: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)piece == (Object)null || (Object)(object)((Component)piece).GetComponent<LoxWagonController>() == (Object)null)
				{
					return;
				}
				GameObject[] array = (GameObject[])Slots.GetValue(__instance);
				int num = piece.m_resources.Length + (((Object)(object)piece.m_craftingStation != (Object)null) ? 1 : 0);
				if (array == null || array.Length == 0 || array.Length >= num)
				{
					return;
				}
				List<GameObject> list = new List<GameObject>(array);
				GameObject val = array[^1];
				RectTransform component = val.GetComponent<RectTransform>();
				Vector2 val2 = default(Vector2);
				((Vector2)(ref val2))..ctor(0f, -40f);
				if (array.Length > 1 && (Object)(object)component != (Object)null)
				{
					RectTransform component2 = array[^2].GetComponent<RectTransform>();
					if ((Object)(object)component2 != (Object)null)
					{
						val2 = component.anchoredPosition - component2.anchoredPosition;
					}
				}
				while (list.Count < num)
				{
					GameObject val3 = Object.Instantiate<GameObject>(val, val.transform.parent, false);
					((Object)val3).name = "LoxWagonRequirement" + list.Count;
					RectTransform component3 = val3.GetComponent<RectTransform>();
					if ((Object)(object)component != (Object)null && (Object)(object)component3 != (Object)null)
					{
						component3.anchoredPosition = component.anchoredPosition + val2 * (float)(list.Count - array.Length + 1);
					}
					val3.SetActive(false);
					list.Add(val3);
				}
				Slots.SetValue(__instance, list.ToArray());
				Log.LogInfo((object)("Expanded recipe display slots to " + num));
			}
		}

		[HarmonyPatch(typeof(Vagon), "Interact")]
		private static class BlockHandPull
		{
			private static bool Prefix(Vagon __instance, Humanoid character, bool hold, ref bool __result)
			{
				//IL_003b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0040: Unknown result type (might be due to invalid IL or missing references)
				LoxWagonController component = ((Component)__instance).GetComponent<LoxWagonController>();
				if ((Object)(object)component == (Object)null)
				{
					return true;
				}
				if (HumanPullTest.Value)
				{
					if (!(character is Player))
					{
						__result = false;
						return false;
					}
					__instance.m_attachOffset = new Vector3(0f, 0.8f, 0f);
					__instance.m_detachDistance = 2f;
					if (!hold)
					{
						component.BeginHumanTrace(character);
					}
					return true;
				}
				__result = component.Interact(character, hold);
				return false;
			}
		}

		[HarmonyPatch(typeof(Vagon), "GetHoverText")]
		private static class HitchHoverText
		{
			private static bool Prefix(Vagon __instance, ref string __result)
			{
				if ((Object)(object)((Component)__instance).GetComponent<LoxWagonController>() == (Object)null)
				{
					return true;
				}
				__result = Localization.instance.Localize("Wagon\n[<color=yellow><b>$KEY_Use</b></color>] " + ((!__instance.IsAttached()) ? (HumanPullTest.Value ? "Pull wagon (player test)" : "Attach Lox") : (HumanPullTest.Value ? "Detach player (test)" : "Detach Lox")));
				return false;
			}
		}

		internal const string PrefabName = "greypoint_LoxWagon";

		internal static ManualLogSource Log;

		private Harmony _harmony;

		internal static ConfigEntry<bool> HumanPullTest;

		internal static ConfigEntry<bool> ArticulatedChassisTest;

		internal static ConfigEntry<float> CargoMassScale;

		internal static ConfigEntry<float> BaseChassisMass;

		private static GameObject _prefab;

		private static bool _beastsPatched;

		private void Awake()
		{
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			HumanPullTest = ((BaseUnityPlugin)this).Config.Bind<bool>("Diagnostics", "HumanPullTest", false, "Temporary diagnostic: allow vanilla player pulling instead of lox hitching. Restart after changing. Production wagon remains lox-only.");
			ArticulatedChassisTest = ((BaseUnityPlugin)this).Config.Bind<bool>("Diagnostics", "ArticulatedChassisTest", false, "Experimental four-wheel chassis with steering/pitching shafts and hitch. Restart required; use identical settings on all peers. False isolates the white-tarp/cargo test on existing Cart physics.");
			BaseChassisMass = ((BaseUnityPlugin)this).Config.Bind<float>("Wagon", "BaseChassisMass", 65f, "Empty chassis mass, distributed across the existing assembly. Previous builds used 50. Restart required; match across peers.");
			CargoMassScale = ((BaseUnityPlugin)this).Config.Bind<float>("Wagon", "CargoMassScale", 0.1f, "Multiplier on vanilla cargo mass contribution. Previous builds used 0.35. Empty mass is unchanged. Restart required; use matching settings on all peers.");
			_harmony = new Harmony("greypoint.loxwagon");
			_harmony.PatchAll(typeof(HaldorWagonPlugin).Assembly);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"LoxWagon 0.6.1 loading");
		}

		private void OnDestroy()
		{
			if (_harmony != null)
			{
				_harmony.UnpatchSelf();
			}
		}

		private static IEnumerable<CodeInstruction> InsertActivation(IEnumerable<CodeInstruction> instructions, string target)
		{
			bool found = false;
			foreach (CodeInstruction instruction in instructions)
			{
				yield return instruction;
				MethodInfo methodInfo = instruction.operand as MethodInfo;
				if (!(instruction.opcode != OpCodes.Call) && !(methodInfo == null) && !(methodInfo.Name != "Instantiate") && methodInfo.IsGenericMethod && !(methodInfo.GetGenericArguments()[0] != typeof(GameObject)) && methodInfo.GetParameters().Length == 3)
				{
					found = true;
					yield return new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(HaldorWagonPlugin), "ActivateInstance", (Type[])null, (Type[])null));
				}
			}
			if (!found)
			{
				Log.LogError((object)("Could not patch wagon activation in " + target));
			}
		}

		private static GameObject ActivateInstance(GameObject instance)
		{
			if ((Object)(object)instance != (Object)null && ((Object)instance).name.StartsWith("greypoint_LoxWagon(", StringComparison.Ordinal))
			{
				instance.SetActive(true);
				Log.LogInfo((object)("Activated wagon instance; network view valid: " + ((Object)(object)instance.GetComponent<ZNetView>() != (Object)null && instance.GetComponent<ZNetView>().IsValid())));
			}
			return instance;
		}

		private static void RegisterBuildPiece(ObjectDB db)
		{
			//IL_013a: 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_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Expected O, but got Unknown
			if ((Object)(object)db == (Object)null || (Object)(object)_prefab == (Object)null)
			{
				return;
			}
			GameObject itemPrefab = db.GetItemPrefab("Hammer");
			if ((Object)(object)itemPrefab == (Object)null)
			{
				return;
			}
			ItemDrop component = itemPrefab.GetComponent<ItemDrop>();
			if ((Object)(object)component == (Object)null || (Object)(object)component.m_itemData.m_shared.m_buildPieces == (Object)null)
			{
				return;
			}
			PieceTable buildPieces = component.m_itemData.m_shared.m_buildPieces;
			Piece component2 = _prefab.GetComponent<Piece>();
			KeyValuePair<string, int>[] obj = new KeyValuePair<string, int>[6]
			{
				new KeyValuePair<string, int>("FineWood", 40),
				new KeyValuePair<string, int>("IronNails", 20),
				new KeyValuePair<string, int>("BlackMetal", 10),
				new KeyValuePair<string, int>("LoxPelt", 10),
				new KeyValuePair<string, int>("LinenThread", 10),
				new KeyValuePair<string, int>("Tar", 10)
			};
			List<Requirement> list = new List<Requirement>();
			KeyValuePair<string, int>[] array = obj;
			for (int i = 0; i < array.Length; i++)
			{
				KeyValuePair<string, int> keyValuePair = array[i];
				GameObject itemPrefab2 = db.GetItemPrefab(keyValuePair.Key);
				if ((Object)(object)itemPrefab2 == (Object)null)
				{
					Log.LogWarning((object)("Missing recipe item " + keyValuePair.Key));
					return;
				}
				list.Add(new Requirement
				{
					m_resItem = itemPrefab2.GetComponent<ItemDrop>(),
					m_amount = keyValuePair.Value,
					m_recover = true
				});
			}
			component2.m_craftingStation = null;
			component2.m_resources = list.ToArray();
			if (!buildPieces.m_pieces.Any((GameObject p) => (Object)(object)p != (Object)null && ((Object)p).name == "greypoint_LoxWagon"))
			{
				buildPieces.m_pieces.Add(_prefab);
			}
			Log.LogInfo((object)"Hammer recipe registered");
		}

		private static GameObject CreatePrefab(ZNetScene scene)
		{
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = ((IEnumerable<GameObject>)scene.m_prefabs).FirstOrDefault((Func<GameObject, bool>)((GameObject p) => (Object)(object)p != (Object)null && ((Object)p).name == "Cart"));
			GameObject val2 = ((IEnumerable<GameObject>)scene.m_prefabs).FirstOrDefault((Func<GameObject, bool>)((GameObject p) => (Object)(object)p != (Object)null && ((Object)p).name == "trader_wagon_destructable"));
			if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null)
			{
				Log.LogError((object)"Missing vanilla Cart or trader_wagon_destructable prefab");
				return null;
			}
			bool activeSelf = val.activeSelf;
			val.SetActive(false);
			GameObject val3;
			try
			{
				val3 = Object.Instantiate<GameObject>(val);
			}
			finally
			{
				val.SetActive(activeSelf);
			}
			((Object)val3).name = "greypoint_LoxWagon";
			val3.SetActive(false);
			Piece component = val3.GetComponent<Piece>();
			Vagon component2 = val3.GetComponent<Vagon>();
			Container componentInChildren = val3.GetComponentInChildren<Container>(true);
			if ((Object)(object)component == (Object)null || (Object)(object)component2 == (Object)null || (Object)(object)componentInChildren == (Object)null)
			{
				Log.LogError((object)"Cart prefab lacks Piece, Vagon, or Container");
				Object.Destroy((Object)(object)val3);
				return null;
			}
			component.m_name = "Wagon";
			component.m_description = "A merchant wagon drawn by a tamed lox.";
			component2.m_name = "Wagon";
			component2.m_container = componentInChildren;
			component2.m_playerExtraPullMass = 0f;
			component2.m_detachDistance = (HumanPullTest.Value ? 2f : 8f);
			component2.m_attachOffset = (HumanPullTest.Value ? new Vector3(0f, 0.8f, 0f) : new Vector3(0f, 0.3f, -1.4f));
			component2.m_baseMass = Mathf.Clamp(BaseChassisMass.Value, 30f, 200f);
			component2.m_itemWeightMassFactor *= Mathf.Clamp(CargoMassScale.Value, 0f, 1f);
			componentInChildren.m_name = "Wagon";
			componentInChildren.m_width = 8;
			componentInChildren.m_height = 4;
			Renderer[] componentsInChildren = val3.GetComponentsInChildren<Renderer>(true);
			for (int num = 0; num < componentsInChildren.Length; num++)
			{
				componentsInChildren[num].enabled = false;
			}
			CopyVisualMeshes(val2.transform, val3.transform);
			AddBodyColliderAndInteractionPoints(val3, component2, componentInChildren);
			try
			{
				WheelMeshBuilder.Build(val3);
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)("Visual wheels unavailable: " + ex.Message));
			}
			WagonThumbnail.Apply(val3);
			if (ArticulatedChassisTest.Value)
			{
				try
				{
					ArticulatedChassis.Build(val3, ((IEnumerable<GameObject>)scene.m_prefabs).FirstOrDefault((Func<GameObject, bool>)((GameObject p) => (Object)(object)p != (Object)null && ((Object)p).name == "BatteringRam")));
				}
				catch (Exception ex2)
				{
					Log.LogError((object)("Articulated chassis failed: " + ex2));
					Object.DestroyImmediate((Object)(object)val3);
					return null;
				}
			}
			try
			{
				WagonBench.Build(val3);
			}
			catch (Exception ex3)
			{
				Log.LogWarning((object)("Raised bench unavailable: " + ex3.Message));
			}
			WagonSeat.Build(val3);
			try
			{
				WagonCargo.Build(val3, val);
			}
			catch (Exception ex4)
			{
				Log.LogWarning((object)("Visible cargo unavailable: " + ex4.Message));
			}
			Floating[] componentsInChildren2 = val3.GetComponentsInChildren<Floating>(true);
			for (int num = 0; num < componentsInChildren2.Length; num++)
			{
				Object.DestroyImmediate((Object)(object)componentsInChildren2[num]);
			}
			ImpactEffect[] componentsInChildren3 = val3.GetComponentsInChildren<ImpactEffect>(true);
			for (int num = 0; num < componentsInChildren3.Length; num++)
			{
				Object.DestroyImmediate((Object)(object)componentsInChildren3[num]);
			}
			val3.AddComponent<LoxWagonController>();
			Log.LogInfo((object)("Built wagon with trader visuals; ArticulatedChassisTest=" + ArticulatedChassisTest.Value));
			return val3;
		}

		private static void CopyVisualMeshes(Transform source, Transform target)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: 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_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			Transform transform = new GameObject("HaldorWagonVisual").transform;
			transform.SetParent(target, false);
			int num = 0;
			MeshRenderer[] componentsInChildren = ((Component)source).GetComponentsInChildren<MeshRenderer>(true);
			foreach (MeshRenderer val in componentsInChildren)
			{
				MeshFilter component = ((Component)val).GetComponent<MeshFilter>();
				if (!((Object)(object)component == (Object)null) && !((Object)(object)component.sharedMesh == (Object)null))
				{
					GameObject val2 = new GameObject("visual_" + num++);
					val2.transform.SetParent(transform, false);
					Matrix4x4 val3 = source.worldToLocalMatrix * ((Component)val).transform.localToWorldMatrix;
					val2.transform.localPosition = Vector4.op_Implicit(((Matrix4x4)(ref val3)).GetColumn(3));
					val2.transform.localRotation = Quaternion.LookRotation(Vector4.op_Implicit(((Matrix4x4)(ref val3)).GetColumn(2)), Vector4.op_Implicit(((Matrix4x4)(ref val3)).GetColumn(1)));
					Transform transform2 = val2.transform;
					Vector4 column = ((Matrix4x4)(ref val3)).GetColumn(0);
					float magnitude = ((Vector4)(ref column)).magnitude;
					column = ((Matrix4x4)(ref val3)).GetColumn(1);
					float magnitude2 = ((Vector4)(ref column)).magnitude;
					column = ((Matrix4x4)(ref val3)).GetColumn(2);
					transform2.localScale = new Vector3(magnitude, magnitude2, ((Vector4)(ref column)).magnitude);
					val2.AddComponent<MeshFilter>().sharedMesh = component.sharedMesh;
					((Renderer)val2.AddComponent<MeshRenderer>()).sharedMaterials = ((Renderer)val).sharedMaterials;
				}
			}
			Log.LogInfo((object)("Copied " + num + " merchant wagon mesh parts"));
		}

		private unsafe static void AddBodyColliderAndInteractionPoints(GameObject wagon, Vagon cart, Container storage)
		{
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_021f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_0231: Unknown result type (might be due to invalid IL or missing references)
			//IL_0244: Unknown result type (might be due to invalid IL or missing references)
			//IL_024b: Unknown result type (might be due to invalid IL or missing references)
			//IL_025c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0273: Unknown result type (might be due to invalid IL or missing references)
			//IL_028a: Unknown result type (might be due to invalid IL or missing references)
			//IL_029c: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0309: Unknown result type (might be due to invalid IL or missing references)
			//IL_0313: Unknown result type (might be due to invalid IL or missing references)
			//IL_0330: Unknown result type (might be due to invalid IL or missing references)
			//IL_033a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0356: Unknown result type (might be due to invalid IL or missing references)
			//IL_0348: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0369: Unknown result type (might be due to invalid IL or missing references)
			//IL_0370: Expected O, but got Unknown
			//IL_038a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0391: 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_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: 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_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0412: Unknown result type (might be due to invalid IL or missing references)
			//IL_0452: Unknown result type (might be due to invalid IL or missing references)
			//IL_0457: Unknown result type (might be due to invalid IL or missing references)
			//IL_0476: Unknown result type (might be due to invalid IL or missing references)
			//IL_047d: Unknown result type (might be due to invalid IL or missing references)
			//IL_048b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0495: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b1: Unknown result type (might be due to invalid IL or missing references)
			Transform val = wagon.transform.Find("HaldorWagonVisual");
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			MeshFilter[] componentsInChildren = ((Component)val).GetComponentsInChildren<MeshFilter>(true);
			if (componentsInChildren.Length == 0)
			{
				return;
			}
			Vector3 val2 = default(Vector3);
			((Vector3)(ref val2))..ctor(float.MaxValue, float.MaxValue, float.MaxValue);
			Vector3 val3 = default(Vector3);
			((Vector3)(ref val3))..ctor(float.MinValue, float.MinValue, float.MinValue);
			MeshFilter[] array = componentsInChildren;
			foreach (MeshFilter val4 in array)
			{
				Bounds bounds = val4.sharedMesh.bounds;
				float[] array2 = new float[2]
				{
					((Bounds)(ref bounds)).min.x,
					((Bounds)(ref bounds)).max.x
				};
				foreach (float num in array2)
				{
					float[] array3 = new float[2]
					{
						((Bounds)(ref bounds)).min.y,
						((Bounds)(ref bounds)).max.y
					};
					foreach (float num2 in array3)
					{
						float[] array4 = new float[2]
						{
							((Bounds)(ref bounds)).min.z,
							((Bounds)(ref bounds)).max.z
						};
						foreach (float num3 in array4)
						{
							Vector3 val5 = wagon.transform.InverseTransformPoint(((Component)val4).transform.TransformPoint(new Vector3(num, num2, num3)));
							val2 = Vector3.Min(val2, val5);
							val3 = Vector3.Max(val3, val5);
						}
					}
				}
			}
			Vector3 val6 = (val2 + val3) * 0.5f;
			Vector3 val7 = val3 - val2;
			ManualLogSource log = Log;
			string[] obj = new string[6] { "Merchant visual bounds center=", null, null, null, null, null };
			Vector3 val8 = val6;
			obj[1] = ((object)(*(Vector3*)(&val8))/*cast due to .constrained prefix*/).ToString();
			obj[2] = " size=";
			val8 = val7;
			obj[3] = ((object)(*(Vector3*)(&val8))/*cast due to .constrained prefix*/).ToString();
			obj[4] = " cart attach=";
			obj[5] = ((object)cart.m_attachPoint.localPosition/*cast due to .constrained prefix*/).ToString();
			log.LogInfo((object)string.Concat(obj));
			BoxCollider val9 = wagon.AddComponent<BoxCollider>();
			val9.center = new Vector3(val6.x, val2.y + Mathf.Min(0.85f, val7.y * 0.35f), val6.z);
			val9.size = new Vector3(Mathf.Max(1.4f, val7.x * 0.72f), Mathf.Min(1.5f, val7.y * 0.42f), Mathf.Max(2f, val7.z * 0.6f));
			float num4 = val9.size.x * 0.5f + 0.1f;
			for (int m = -1; m <= 1; m += 2)
			{
				MakeHotspot(wagon, "CargoAccess" + m, new Vector3(val6.x + (float)m * num4, val2.y + 1.1f, val6.z), new Vector3(0.3f, 1.6f, val9.size.z), storage, null);
			}
			float num5 = ((cart.m_attachPoint.localPosition.z >= val6.z) ? (val2.z - 0.35f) : (val3.z + 0.35f));
			GameObject val10 = new GameObject("LoxHitchAnchor");
			val10.transform.SetParent(wagon.transform, false);
			val10.transform.localPosition = new Vector3(val6.x, val2.y + 0.9f, num5);
			cart.m_attachPoint = val10.transform;
			int[] array5 = new int[2] { -1, 1 };
			for (int i = 0; i < array5.Length; i++)
			{
				int num6 = array5[i];
				Transform transform = new GameObject("WagonRopeAnchor" + num6).transform;
				transform.SetParent(wagon.transform, false);
				transform.localPosition = new Vector3((float)num6 * 0.5169535f, 1.6571805f, -6.484933f);
				if (num6 < 0)
				{
					cart.m_lineAttachPoints0 = transform;
				}
				else
				{
					cart.m_lineAttachPoints1 = transform;
				}
			}
			Log.LogInfo((object)("Corrected wagon hitch local=" + ((object)val10.transform.localPosition/*cast due to .constrained prefix*/).ToString()));
			MakeHotspot(wagon, "LoxHitch", new Vector3(val6.x, val2.y + 1.1f, num5), new Vector3(Mathf.Min(2.4f, val7.x * 0.7f), 1.3f, 0.7f), null, cart);
		}

		private static void MakeHotspot(GameObject wagon, string name, Vector3 center, Vector3 size, Container storage, Vagon cart)
		{
			//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_0018: 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_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name);
			val.transform.SetParent(wagon.transform, false);
			val.transform.localPosition = center;
			val.layer = wagon.layer;
			BoxCollider obj = val.AddComponent<BoxCollider>();
			obj.size = size;
			((Collider)obj).isTrigger = true;
			WagonHotspot wagonHotspot = val.AddComponent<WagonHotspot>();
			wagonHotspot.Storage = storage;
			wagonHotspot.Cart = cart;
		}

		private static void PatchBeasts()
		{
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Expected O, but got Unknown
			if (_beastsPatched || AccessTools.TypeByName("BeastsOfBurden.BeastsOfBurden+Vagon_Update_Patch") == null)
			{
				return;
			}
			string[] array = new string[4] { "Vagon_Update_Patch", "Vagon_CanAttach_Patch", "LateUpdate_Vagon_Patch", "InUse_Vagon_Patch" };
			foreach (string text in array)
			{
				Type type = AccessTools.TypeByName("BeastsOfBurden.BeastsOfBurden+" + text);
				MethodInfo methodInfo = ((type != null) ? AccessTools.Method(type, "Prefix", (Type[])null, (Type[])null) : null);
				if (!(methodInfo == null))
				{
					MethodInfo methodInfo2 = AccessTools.Method(typeof(HaldorWagonPlugin), (!(methodInfo.ReturnType == typeof(bool))) ? "SkipBeastsPatch" : ((text == "InUse_Vagon_Patch") ? "SkipBeastsInUse" : "SkipBeastsBoolPatch"), (Type[])null, (Type[])null);
					new Harmony("greypoint.loxwagon.beasts").Patch((MethodBase)methodInfo, new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				}
			}
			_beastsPatched = true;
		}

		private static bool SkipBeastsPatch(Vagon __0)
		{
			if (!((Object)(object)__0 == (Object)null))
			{
				return (Object)(object)((Component)__0).GetComponent<LoxWagonController>() == (Object)null;
			}
			return true;
		}

		private static bool SkipBeastsBoolPatch(Vagon __0, ref bool __result)
		{
			if ((Object)(object)__0 == (Object)null || (Object)(object)((Component)__0).GetComponent<LoxWagonController>() == (Object)null)
			{
				return true;
			}
			__result = true;
			return false;
		}

		private static bool SkipBeastsInUse(Vagon __1, ref bool __result)
		{
			if ((Object)(object)__1 == (Object)null || (Object)(object)((Component)__1).GetComponent<LoxWagonController>() == (Object)null)
			{
				return true;
			}
			__result = true;
			return false;
		}

		private static int RaycastWithWagonTriggers(Vector3 origin, Vector3 direction, RaycastHit[] hits, float distance, int mask)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			int count = Physics.RaycastNonAlloc(origin, direction, hits, distance, mask);
			List<RaycastHit> list = hits.Take(count).ToList();
			RaycastHit[] array = Physics.RaycastAll(origin, direction, distance, mask, (QueryTriggerInteraction)2);
			for (int i = 0; i < array.Length; i++)
			{
				RaycastHit hit = array[i];
				if ((Object)(object)((RaycastHit)(ref hit)).collider != (Object)null && ((RaycastHit)(ref hit)).collider.isTrigger && ((Object)(object)((Component)((RaycastHit)(ref hit)).collider).GetComponent<WagonHotspot>() != (Object)null || (Object)(object)((Component)((RaycastHit)(ref hit)).collider).GetComponent<WagonSeat>() != (Object)null) && !list.Any((RaycastHit h) => (Object)(object)((RaycastHit)(ref h)).collider == (Object)(object)((RaycastHit)(ref hit)).collider))
				{
					list.Add(hit);
				}
			}
			RaycastHit[] array2 = list.OrderBy((RaycastHit h) => ((RaycastHit)(ref h)).distance).Take(hits.Length).ToArray();
			Array.Copy(array2, hits, array2.Length);
			return array2.Length;
		}
	}
	public sealed class WagonHotspot : MonoBehaviour, Hoverable, Interactable
	{
		public Container Storage;

		public Vagon Cart;

		public string GetHoverName()
		{
			if (!((Object)(object)Storage != (Object)null))
			{
				return "Wagon";
			}
			return Storage.GetHoverName();
		}

		public string GetHoverText()
		{
			if (!((Object)(object)Storage != (Object)null))
			{
				return Cart.GetHoverText();
			}
			return Storage.GetHoverText();
		}

		public float GetHoverOffset()
		{
			return 0f;
		}

		public bool Interact(Humanoid user, bool hold, bool alt)
		{
			if (!((Object)(object)Storage != (Object)null))
			{
				return Cart.Interact(user, hold, alt);
			}
			return Storage.Interact(user, hold, alt);
		}

		public bool UseItem(Humanoid user, ItemData item)
		{
			return false;
		}
	}
	public sealed class LoxWagonController : MonoBehaviour
	{
		private struct CollisionPair
		{
			public Collider A;

			public Collider B;

			public bool Previous;
		}

		private const string HitchRpc = "greypoint_LoxWagon_ToggleHitch";

		private static readonly MethodInfo Attach = AccessTools.Method(typeof(Vagon), "AttachTo", new Type[1] { typeof(GameObject) }, (Type[])null);

		private static readonly MethodInfo Detach = AccessTools.Method(typeof(Vagon), "Detach", (Type[])null, (Type[])null);

		private Vagon _cart;

		private ZNetView _net;

		private float _verifyAt;

		private ZDOID _verifyTarget;

		private readonly List<CollisionPair> _ignored = new List<CollisionPair>();

		private Rigidbody _collisionTarget;

		private float _nextPairScan;

		private bool _hadJoint;

		private float _reportedMass = -1f;

		private float _traceUntil;

		private bool _checkLogged;

		private bool _detachLogged;

		private static readonly FieldInfo JointField = AccessTools.Field(typeof(Vagon), "m_attachJoin");

		private ConfigurableJoint HitchJoint => (ConfigurableJoint)JointField.GetValue(_cart);

		internal unsafe void ReportMass(float total)
		{
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_net == (Object)null) && _net.IsValid() && _net.IsOwner() && !((Object)(object)_cart == (Object)null) && !(Mathf.Abs(total - _reportedMass) < 0.01f))
			{
				_reportedMass = total;
				ManualLogSource log = HaldorWagonPlugin.Log;
				string[] obj = new string[10] { "Wagon mass wagon=", null, null, null, null, null, null, null, null, null };
				ZDOID uid = _net.GetZDO().m_uid;
				obj[1] = ((object)(*(ZDOID*)(&uid))/*cast due to .constrained prefix*/).ToString();
				obj[2] = " inventoryWeight=";
				obj[3] = _cart.m_container.GetInventory().GetTotalWeight().ToString();
				obj[4] = " baseMass=";
				obj[5] = _cart.m_baseMass.ToString();
				obj[6] = " cargoFactor=";
				obj[7] = _cart.m_itemWeightMassFactor.ToString();
				obj[8] = " totalMass=";
				obj[9] = total.ToString();
				log.LogInfo((object)string.Concat(obj));
			}
		}

		public void ReleaseCollisionPairs()
		{
			foreach (CollisionPair item in _ignored)
			{
				if ((Object)(object)item.A != (Object)null && (Object)(object)item.B != (Object)null)
				{
					Physics.IgnoreCollision(item.A, item.B, item.Previous);
				}
			}
			_ignored.Clear();
			_collisionTarget = null;
		}

		private void OnDisable()
		{
			ReleaseCollisionPairs();
		}

		private void FixedUpdate()
		{
			if ((Object)(object)_cart == (Object)null || (Object)(object)_net == (Object)null || !_net.IsValid())
			{
				return;
			}
			ConfigurableJoint val = HitchJoint;
			Rigidbody val2 = (((Object)(object)val != (Object)null) ? ((Joint)val).connectedBody : null);
			Character val3 = (((Object)(object)val2 != (Object)null) ? ((Component)val2).GetComponent<Character>() : null);
			if ((((Object)(object)val != (Object)null && ((Object)(object)val2 == (Object)null || (Object)(object)val3 == (Object)null || val3.IsDead())) || ((_hadJoint || _cart.IsAttached()) && (Object)(object)val == (Object)null)) && _net.IsOwner())
			{
				ArticulatedChassis component = ((Component)this).GetComponent<ArticulatedChassis>();
				string text = (((Object)(object)val == (Object)null) ? "joint missing" : (((Object)(object)val2 == (Object)null) ? "connected body missing" : (((Object)(object)val3 == (Object)null) ? "character missing" : "character dead")));
				HaldorWagonPlugin.Log.LogWarning((object)("Hitch cleanup reason=" + text + (((Object)(object)component != (Object)null) ? component.LossContext() : "")));
				Detach.Invoke(_cart, null);
				val2 = null;
				val = null;
				val3 = null;
			}
			_hadJoint = (Object)(object)val != (Object)null;
			bool flag = (Object)(object)val3 != (Object)null && val3.IsTamed() && Utils.GetPrefabName(((Component)val3).gameObject) == "Lox";
			if (!flag || (Object)(object)val2 != (Object)(object)_collisionTarget)
			{
				ReleaseCollisionPairs();
				if (flag)
				{
					_collisionTarget = val2;
					_nextPairScan = 0f;
				}
			}
			if ((Object)(object)_collisionTarget == (Object)null || Time.time < _nextPairScan)
			{
				return;
			}
			_nextPairScan = Time.time + 0.5f;
			Collider[] componentsInChildren = ((Component)this).GetComponentsInChildren<Collider>(true);
			foreach (Collider a in componentsInChildren)
			{
				Collider[] componentsInChildren2 = ((Component)_collisionTarget).GetComponentsInChildren<Collider>(true);
				foreach (Collider b in componentsInChildren2)
				{
					if (!((Object)(object)a == (Object)null) && !((Object)(object)b == (Object)null) && !a.isTrigger && !b.isTrigger && a.enabled && b.enabled)
					{
						if (!_ignored.Any((CollisionPair pair) => (Object)(object)pair.A == (Object)(object)a && (Object)(object)pair.B == (Object)(object)b))
						{
							_ignored.Add(new CollisionPair
							{
								A = a,
								B = b,
								Previous = Physics.GetIgnoreCollision(a, b)
							});
						}
						Physics.IgnoreCollision(a, b, true);
					}
				}
			}
		}

		private unsafe string HitchState(GameObject target)
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: 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_0234: Unknown result type (might be due to invalid IL or missing references)
			//IL_0239: Unknown result type (might be due to invalid IL or missing references)
			//IL_023e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02df: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0305: Unknown result type (might be due to invalid IL or missing references)
			//IL_030a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0283: Unknown result type (might be due to invalid IL or missing references)
			//IL_0288: Unknown result type (might be due to invalid IL or missing references)
			//IL_028d: Unknown result type (might be due to invalid IL or missing references)
			ConfigurableJoint hitchJoint = HitchJoint;
			Character val = (((Object)(object)target != (Object)null) ? target.GetComponent<Character>() : null);
			float num = (((Object)(object)target != (Object)null && (Object)(object)_cart.m_attachPoint != (Object)null) ? Vector3.Distance(target.transform.TransformPoint(_cart.m_attachOffset), _cart.m_attachPoint.position) : (-1f));
			string[] obj = new string[32]
			{
				" owner=",
				((Object)(object)_net != (Object)null && _net.IsValid() && _net.IsOwner()).ToString(),
				" joint=",
				((Object)(object)hitchJoint != (Object)null).ToString(),
				" body=",
				((Object)(object)hitchJoint != (Object)null && (Object)(object)((Joint)hitchJoint).connectedBody != (Object)null).ToString(),
				" target=",
				((Object)(object)target != (Object)null) ? Utils.GetPrefabName(target) : "none",
				" tamed=",
				((Object)(object)val != (Object)null && val.IsTamed()).ToString(),
				" dead=",
				((Object)(object)val != (Object)null && val.IsDead()).ToString(),
				" radius=",
				(((Object)(object)val != (Object)null) ? val.GetRadius() : (-1f)).ToString(),
				" wagonAnchor=",
				null,
				null,
				null,
				null,
				null,
				null,
				null,
				null,
				null,
				null,
				null,
				null,
				null,
				null,
				null,
				null,
				null
			};
			object obj2;
			Vector3 val2;
			if (!((Object)(object)_cart.m_attachPoint != (Object)null))
			{
				obj2 = "none";
			}
			else
			{
				val2 = _cart.m_attachPoint.position;
				obj2 = ((Vector3)(ref val2)).ToString("F3");
			}
			obj[15] = (string)obj2;
			obj[16] = " targetAnchor=";
			object obj3;
			if (!((Object)(object)target != (Object)null))
			{
				obj3 = "none";
			}
			else
			{
				val2 = target.transform.TransformPoint(_cart.m_attachOffset);
				obj3 = ((Vector3)(ref val2)).ToString("F3");
			}
			obj[17] = (string)obj3;
			obj[18] = " actualJointAnchor=";
			object obj4;
			if (!((Object)(object)hitchJoint != (Object)null))
			{
				obj4 = "none";
			}
			else
			{
				val2 = ((Component)hitchJoint).transform.TransformPoint(((Joint)hitchJoint).anchor);
				obj4 = ((Vector3)(ref val2)).ToString("F3");
			}
			obj[19] = (string)obj4;
			obj[20] = " actualConnectedAnchor=";
			object obj5;
			if (!((Object)(object)hitchJoint != (Object)null) || !((Object)(object)((Joint)hitchJoint).connectedBody != (Object)null))
			{
				obj5 = "none";
			}
			else
			{
				val2 = ((Component)((Joint)hitchJoint).connectedBody).transform.TransformPoint(((Joint)hitchJoint).connectedAnchor);
				obj5 = ((Vector3)(ref val2)).ToString("F3");
			}
			obj[21] = (string)obj5;
			obj[22] = " gap=";
			obj[23] = num.ToString();
			obj[24] = " limit=";
			obj[25] = _cart.m_detachDistance.ToString();
			obj[26] = " upright=";
			val2 = ((Component)this).transform.up;
			obj[27] = val2.y.ToString();
			obj[28] = " offset=";
			val2 = _cart.m_attachOffset;
			obj[29] = ((object)(*(Vector3*)(&val2))/*cast due to .constrained prefix*/).ToString();
			obj[30] = " breakForce=";
			obj[31] = (((Object)(object)hitchJoint != (Object)null) ? ((Joint)hitchJoint).breakForce : _cart.m_breakForce).ToString();
			return string.Concat(obj);
		}

		public void LogCheckFailure(GameObject target)
		{
			if (!(Time.time > _traceUntil) && !_checkLogged)
			{
				_checkLogged = true;
				HaldorWagonPlugin.Log.LogWarning((object)("Hitch CanAttach rejected:" + HitchState(target)));
			}
		}

		public void LogDetach()
		{
			ArticulatedChassis component = ((Component)this).GetComponent<ArticulatedChassis>();
			if ((Object)(object)component != (Object)null && !component.Preview)
			{
				ConfigurableJoint hitchJoint = HitchJoint;
				GameObject target = (((Object)(object)hitchJoint != (Object)null && (Object)(object)((Joint)hitchJoint).connectedBody != (Object)null) ? ((Component)((Joint)hitchJoint).connectedBody).gameObject : null);
				StackFrame[] frames = new StackTrace(1, fNeedFileInfo: false).GetFrames();
				string text = ((frames != null) ? string.Join(" > ", (from f in frames.Take(5)
					select f.GetMethod().Name).ToArray()) : "unknown");
				HaldorWagonPlugin.Log.LogInfo((object)("Chassis detach callers=" + text + component.LossContext() + " " + HitchState(target)));
			}
			else if (!(Time.time > _traceUntil) && !_detachLogged)
			{
				_detachLogged = true;
				ConfigurableJoint hitchJoint2 = HitchJoint;
				GameObject target2 = (((Object)(object)hitchJoint2 != (Object)null && (Object)(object)((Joint)hitchJoint2).connectedBody != (Object)null) ? ((Component)((Joint)hitchJoint2).connectedBody).gameObject : null);
				HaldorWagonPlugin.Log.LogWarning((object)("Hitch Detach called:" + HitchState(target2) + "\n" + new StackTrace(1, fNeedFileInfo: false)));
			}
		}

		private void OnJointBreak(float force)
		{
			if (!(Time.time > _traceUntil))
			{
				HaldorWagonPlugin.Log.LogWarning((object)("Wagon OnJointBreak: force=" + force + " hitchJointPresent=" + ((Object)(object)HitchJoint != (Object)null)));
			}
		}

		private unsafe void Update()
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			if (!(_verifyAt <= 0f) && !(Time.time < _verifyAt))
			{
				_verifyAt = 0f;
				ConfigurableJoint hitchJoint = HitchJoint;
				ManualLogSource log = HaldorWagonPlugin.Log;
				string[] obj = new string[8] { "Hitch after 1s: target=", null, null, null, null, null, null, null };
				ZDOID verifyTarget = _verifyTarget;
				obj[1] = ((object)(*(ZDOID*)(&verifyTarget))/*cast due to .constrained prefix*/).ToString();
				obj[2] = " attached=";
				obj[3] = _cart.IsAttached().ToString();
				obj[4] = " joint=";
				obj[5] = ((Object)(object)hitchJoint != (Object)null).ToString();
				obj[6] = " connectedBody=";
				obj[7] = ((Object)(object)hitchJoint != (Object)null && (Object)(object)((Joint)hitchJoint).connectedBody != (Object)null).ToString();
				log.LogInfo((object)string.Concat(obj));
			}
		}

		public void BeginHumanTrace(Humanoid user)
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			_traceUntil = Time.time + 5f;
			_checkLogged = false;
			_detachLogged = false;
			_verifyAt = Time.time + 1f;
			_verifyTarget = ((Character)user).GetZDOID();
			HaldorWagonPlugin.Log.LogInfo((object)("Player hitch requested:" + HitchState(((Component)user).gameObject)));
		}

		private void Awake()
		{
			_cart = ((Component)this).GetComponent<Vagon>();
			_net = ((Component)this).GetComponent<ZNetView>();
			if ((Object)(object)_net != (Object)null)
			{
				_net.Register<ZDOID>("greypoint_LoxWagon_ToggleHitch", (Action<long, ZDOID>)ToggleHitch);
			}
		}

		public unsafe bool Interact(Humanoid user, bool hold)
		{
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			if (HaldorWagonPlugin.HumanPullTest.Value)
			{
				return false;
			}
			if (hold || (Object)(object)_net == (Object)null || !_net.IsValid())
			{
				return false;
			}
			Character val = (_cart.IsAttached() ? null : NearestLox());
			if (!_cart.IsAttached() && (Object)(object)val == (Object)null)
			{
				((Character)user).Message((MessageType)2, "No tamed lox nearby.", 0, (Sprite)null, false);
				return true;
			}
			ZDOID val2 = (((Object)(object)val != (Object)null) ? val.GetZDOID() : ZDOID.None);
			ManualLogSource log = HaldorWagonPlugin.Log;
			string[] obj = new string[6]
			{
				"Hitch interaction: attached=",
				_cart.IsAttached().ToString(),
				" selected=",
				null,
				null,
				null
			};
			ZDOID val3 = val2;
			obj[3] = ((object)(*(ZDOID*)(&val3))/*cast due to .constrained prefix*/).ToString();
			obj[4] = " owner=";
			obj[5] = _net.IsOwner().ToString();
			log.LogInfo((object)string.Concat(obj));
			_net.InvokeRPC("greypoint_LoxWagon_ToggleHitch", new object[1] { val2 });
			return true;
		}

		private Character NearestLox()
		{
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			Character result = null;
			float num = 12f;
			foreach (Character allCharacter in Character.GetAllCharacters())
			{
				if (!((Object)(object)allCharacter == (Object)null) && allCharacter.IsTamed() && !((Object)(object)((Component)allCharacter).GetComponent<ZNetView>() == (Object)null) && !(Utils.GetPrefabName(((Component)allCharacter).gameObject) != "Lox"))
				{
					float num2 = Vector3.Distance(((Component)allCharacter).transform.position, ((Component)this).transform.position);
					HaldorWagonPlugin.Log.LogInfo((object)("Candidate lox " + ((object)allCharacter.GetZDOID()/*cast due to .constrained prefix*/).ToString() + " distance=" + num2));
					if (!(num2 >= num))
					{
						num = num2;
						result = allCharacter;
					}
				}
			}
			return result;
		}

		private unsafe void ToggleHitch(long sender, ZDOID target)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_020a: Unknown result type (might be due to invalid IL or missing references)
			//IL_020f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0291: Unknown result type (might be due to invalid IL or missing references)
			//IL_0296: Unknown result type (might be due to invalid IL or missing references)
			if (HaldorWagonPlugin.HumanPullTest.Value)
			{
				return;
			}
			if ((Object)(object)_net == (Object)null || !_net.IsValid() || !_net.IsOwner())
			{
				HaldorWagonPlugin.Log.LogWarning((object)"Hitch request reached a non-owner or invalid network view");
			}
			else if (_cart.IsAttached())
			{
				Detach.Invoke(_cart, null);
			}
			else
			{
				if (target == ZDOID.None)
				{
					return;
				}
				Character val = ((IEnumerable<Character>)Character.GetAllCharacters()).FirstOrDefault((Func<Character, bool>)((Character c) => (Object)(object)c != (Object)null && c.GetZDOID() == target));
				if ((Object)(object)val == (Object)null || val.IsDead() || !val.IsTamed() || (Object)(object)((Component)val).GetComponent<ZNetView>() == (Object)null || Utils.GetPrefabName(((Component)val).gameObject) != "Lox")
				{
					HaldorWagonPlugin.Log.LogWarning((object)"Hitch rejected: selected character is unavailable or not a tamed lox");
					return;
				}
				float num = Vector3.Distance(((Component)val).transform.position, ((Component)this).transform.position);
				if (num > 12f)
				{
					HaldorWagonPlugin.Log.LogWarning((object)("Hitch rejected: lox distance " + num));
					return;
				}
				if (!((Object)(object)((Component)val).GetComponent<Rigidbody>() == (Object)null))
				{
					try
					{
						_cart.m_attachOffset = new Vector3(0f, 0.3f, -1.4f);
						_traceUntil = Time.time + 5f;
						_checkLogged = false;
						_detachLogged = false;
						HaldorWagonPlugin.Log.LogInfo((object)("Hitch before creation:" + HitchState(((Component)val).gameObject)));
						Attach.Invoke(_cart, new object[1] { ((Component)val).gameObject });
						_detachLogged = false;
						ConfigurableJoint hitchJoint = HitchJoint;
						bool flag = (Object)(object)hitchJoint != (Object)null && (Object)(object)((Joint)hitchJoint).connectedBody == (Object)(object)((Component)val).GetComponent<Rigidbody>();
						ManualLogSource log = HaldorWagonPlugin.Log;
						string[] obj = new string[6] { "Hitch result: lox=", null, null, null, null, null };
						ZDOID val2 = target;
						obj[1] = ((object)(*(ZDOID*)(&val2))/*cast due to .constrained prefix*/).ToString();
						obj[2] = " attached=";
						obj[3] = _cart.IsAttached().ToString();
						obj[4] = " connected=";
						obj[5] = flag.ToString();
						log.LogInfo((object)string.Concat(obj));
						HaldorWagonPlugin.Log.LogInfo((object)("Hitch created:" + HitchState(((Component)val).gameObject)));
						if (flag)
						{
							_verifyAt = Time.time + 1f;
							_verifyTarget = target;
						}
						return;
					}
					catch (Exception ex)
					{
						HaldorWagonPlugin.Log.LogError((object)("Hitch failed: " + ex));
						return;
					}
				}
				HaldorWagonPlugin.Log.LogWarning((object)"Hitch rejected: lox has no root rigidbody");
			}
		}
	}
	internal static class WagonThumbnail
	{
		private static Sprite cached;

		private static void Soften(Texture2D texture)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: 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_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: 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)
			int width = ((Texture)texture).width;
			int height = ((Texture)texture).height;
			Color[] pixels = texture.GetPixels();
			Color[] array = (Color[])(object)new Color[pixels.Length];
			for (int i = 0; i < height; i++)
			{
				for (int j = 0; j < width; j++)
				{
					Color clear = Color.clear;
					float num = 0f;
					float num2 = 0f;
					for (int k = -1; k <= 1; k++)
					{
						for (int l = -1; l <= 1; l++)
						{
							int num3 = Mathf.Clamp(j + l, 0, width - 1);
							int num4 = Mathf.Clamp(i + k, 0, height - 1);
							float num5 = ((l == 0) ? 2f : 1f) * ((k == 0) ? 2f : 1f);
							Color val = pixels[num4 * width + num3];
							clear.r += val.r * val.a * num5;
							clear.g += val.g * val.a * num5;
							clear.b += val.b * val.a * num5;
							num += val.a * num5;
							num2 += num5;
						}
					}
					Color val2 = pixels[i * width + j];
					float a = Mathf.Lerp(val2.a, num / num2, 0.3f);
					float num6 = val2.a * 0.7f + num / num2 * 0.3f;
					Color clear2 = Color.clear;
					if (num6 > 1E-05f)
					{
						clear2.r = (val2.r * val2.a * 0.7f + clear.r / num2 * 0.3f) / num6 * 0.9f;
						clear2.g = (val2.g * val2.a * 0.7f + clear.g / num2 * 0.3f) / num6 * 0.9f;
						clear2.b = (val2.b * val2.a * 0.7f + clear.b / num2 * 0.3f) / num6 * 0.9f;
						clear2.a = a;
					}
					array[i * width + j] = clear2;
				}
			}
			texture.SetPixels(array);
		}

		internal static void Apply(GameObject wagon)
		{
			//IL_06ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0706: 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_0024: Invalid comparison between Unknown and I4
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: 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_00c2: Expected O, but got Unknown
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: 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_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0392: Unknown result type (might be due to invalid IL or missing references)
			//IL_0397: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_041d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0431: Unknown result type (might be due to invalid IL or missing references)
			//IL_0436: Unknown result type (might be due to invalid IL or missing references)
			//IL_043a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0444: Unknown result type (might be due to invalid IL or missing references)
			//IL_0449: Unknown result type (might be due to invalid IL or missing references)
			//IL_045c: Unknown result type (might be due to invalid IL or missing references)
			//IL_022e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0235: Expected O, but got Unknown
			//IL_0522: Unknown result type (might be due to invalid IL or missing references)
			//IL_0527: Unknown result type (might be due to invalid IL or missing references)
			//IL_0576: Unknown result type (might be due to invalid IL or missing references)
			//IL_0595: Unknown result type (might be due to invalid IL or missing references)
			//IL_059b: Expected O, but got Unknown
			//IL_0363: Unknown result type (might be due to invalid IL or missing references)
			//IL_0353: Unknown result type (might be due to invalid IL or missing references)
			//IL_0358: Unknown result type (might be due to invalid IL or missing references)
			//IL_0272: 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_061a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0620: Expected O, but got Unknown
			//IL_0635: Unknown result type (might be due to invalid IL or missing references)
			//IL_0674: Unknown result type (might be due to invalid IL or missing references)
			//IL_0683: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0481: Unknown result type (might be due to invalid IL or missing references)
			//IL_0488: Unknown result type (might be due to invalid IL or missing references)
			//IL_0496: Unknown result type (might be due to invalid IL or missing references)
			//IL_049b: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a0: Unknown result type (might be du