Decompiled source of Drivable Excavator v0.1.31

plugins/DrivableExcavator.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text;
using AzNean.SotfCommon;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using Bolt;
using DrivableExcavator.Logic;
using Endnight.Rendering;
using FMOD;
using FMOD.Studio;
using FMODUnity;
using HarmonyLib;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using Sons.Ai.Vail.StimuliTypes;
using Sons.Crafting.Structures;
using Sons.Gameplay;
using Sons.Gameplay.GPS;
using Sons.Gameplay.GameSetup;
using Sons.Gameplay.TreeCutting;
using Sons.Input;
using Sons.Inventory;
using Sons.Items.Core;
using Sons.Multiplayer;
using Sons.Save;
using Sons.Utilities;
using Steamworks;
using TheForest.Utils;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Events;
using UnityEngine.InputSystem;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("DrivableExcavator")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.31.0")]
[assembly: AssemblyInformationalVersion("0.1.31+694be676bb68c91c61500a5c974d2775a57a7c45")]
[assembly: AssemblyProduct("DrivableExcavator")]
[assembly: AssemblyTitle("DrivableExcavator")]
[assembly: AssemblyVersion("0.1.31.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

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

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

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
internal static class SettingMove
{
	internal static void Move(ConfigFile config, string oldSection, string oldKey, ConfigEntryBase to)
	{
		bool saveOnConfigSet = config.SaveOnConfigSet;
		config.SaveOnConfigSet = false;
		try
		{
			ConfigEntry<string> val = config.Bind<string>(oldSection, oldKey, "\u0001", "Old place of a moved setting.");
			bool num = val.Value != "\u0001";
			if (num)
			{
				to.SetSerializedValue(((ConfigEntryBase)val).GetSerializedValue());
			}
			config.Remove(((ConfigEntryBase)val).Definition);
			if (num)
			{
				config.Save();
			}
		}
		finally
		{
			config.SaveOnConfigSet = saveOnConfigSet;
		}
	}
}
namespace AzNean.SotfCommon
{
	internal static class ModLog
	{
		private static ManualLogSource _log;

		private static ConfigEntry<bool> _full;

		private static readonly HashSet<string> _once = new HashSet<string>();

		private static readonly Dictionary<(int, string), int> _state = new Dictionary<(int, string), int>();

		internal static bool Full => _full.Value;

		internal static void Init(ManualLogSource log, ConfigEntry<bool> full)
		{
			_log = log;
			_full = full;
		}

		internal static void Trace(string message)
		{
			if (_full.Value)
			{
				_log.LogInfo((object)message);
			}
		}

		internal static bool Changed(int id, string what, int state)
		{
			if (!_full.Value || (_state.TryGetValue((id, what), out var value) && value == state))
			{
				return false;
			}
			_state[(id, what)] = state;
			return true;
		}

		internal static void Once(string key, string message, LogLevel level = (LogLevel)16)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			if (_once.Add(key))
			{
				_log.Log(level, (object)message);
			}
		}
	}
}
namespace DrivableExcavator
{
	public class ArmNear : MonoBehaviour
	{
		internal readonly Dictionary<int, Collider> Near = new Dictionary<int, Collider>();

		public ArmNear(IntPtr ptr)
			: base(ptr)
		{
		}

		private void OnTriggerEnter(Collider other)
		{
			Near[((Object)other).GetInstanceID()] = other;
		}

		private void OnTriggerStay(Collider other)
		{
			int instanceID = ((Object)other).GetInstanceID();
			if (!Near.ContainsKey(instanceID))
			{
				Near[instanceID] = other;
			}
		}

		private void OnTriggerExit(Collider other)
		{
			Near.Remove(((Object)other).GetInstanceID());
		}
	}
	internal sealed class CabScreen
	{
		private static readonly Vector3 TopLeft = new Vector3(-1.254f, 1.391f, -1.409f);

		private static readonly Vector3 TopRight = new Vector3(-0.959f, 1.391f, -1.529f);

		private static readonly Vector3 BottomLeft = new Vector3(-1.183f, 0.907f, -1.216f);

		private static readonly Vector3 BottomRight = new Vector3(-0.888f, 0.903f, -1.333f);

		private const int Width = 96;

		private const int Height = 160;

		private readonly ScreenPicture _picture = new ScreenPicture(96, 160);

		private readonly Texture2D _texture;

		private readonly Material _material;

		private readonly GameObject _quad;

		private float _next;

		private bool _on;

		private bool _blankDone;

		private CabScreen(GameObject quad, Material material, Texture2D texture)
		{
			_quad = quad;
			_material = material;
			_texture = texture;
		}

		internal static CabScreen Make(Transform cab)
		{
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Expected O, but got Unknown
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			//IL_00ea: 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_00f0: 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_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Expected O, but got Unknown
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: 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_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: 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_01a8: 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_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: Unknown result type (might be due to invalid IL or missing references)
			//IL_0228: 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_0243: Unknown result type (might be due to invalid IL or missing references)
			//IL_0254: Unknown result type (might be due to invalid IL or missing references)
			//IL_0259: Unknown result type (might be due to invalid IL or missing references)
			//IL_026a: Unknown result type (might be due to invalid IL or missing references)
			//IL_026f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e0: Expected O, but got Unknown
			//IL_02e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ec: Expected O, but got Unknown
			//IL_0304: Unknown result type (might be due to invalid IL or missing references)
			//IL_031b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0320: Unknown result type (might be due to invalid IL or missing references)
			//IL_032d: Expected O, but got Unknown
			//IL_036b: Unknown result type (might be due to invalid IL or missing references)
			//IL_039e: Unknown result type (might be due to invalid IL or missing references)
			//IL_03eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			if (!Plugin.ScreenOn.Value)
			{
				ModLog.Trace("Excavator cab screen: off ([Screen] Enabled)");
				return null;
			}
			MeshRenderer val = (((Object)(object)cab != (Object)null) ? ((Component)cab).GetComponent<MeshRenderer>() : null);
			if ((Object)(object)val == (Object)null || (Object)(object)((Renderer)val).sharedMaterial == (Object)null)
			{
				Plugin.Logger.LogWarning((object)"Excavator cab screen: the cab has no material to copy, the screen stays dark");
				return null;
			}
			GameObject val2 = new GameObject("DrivableExcavatorScreen");
			val2.SetActive(false);
			val2.transform.SetParent(cab, false);
			val2.layer = ((Component)cab).gameObject.layer;
			Vector3 val3 = Vector3.Cross(TopRight - TopLeft, BottomLeft - TopLeft);
			Vector3 val4 = ((Vector3)(ref val3)).normalized;
			if (val4.z > 0f)
			{
				val4 = -val4;
			}
			Vector3 val5 = val4 * 0.004f;
			Vector3[] array = (Vector3[])(object)new Vector3[4]
			{
				TopLeft + val5,
				TopRight + val5,
				BottomRight + val5,
				BottomLeft + val5
			};
			Mesh val6 = new Mesh
			{
				name = "DrivableExcavatorScreen"
			};
			val6.vertices = Il2CppStructArray<Vector3>.op_Implicit((Vector3[])(object)new Vector3[8]
			{
				array[0],
				array[1],
				array[2],
				array[3],
				array[0],
				array[1],
				array[2],
				array[3]
			});
			val6.uv = Il2CppStructArray<Vector2>.op_Implicit((Vector2[])(object)new Vector2[8]
			{
				new Vector2(0f, 1f),
				new Vector2(1f, 1f),
				new Vector2(1f, 0f),
				new Vector2(0f, 0f),
				new Vector2(0f, 1f),
				new Vector2(1f, 1f),
				new Vector2(1f, 0f),
				new Vector2(0f, 0f)
			});
			val6.triangles = Il2CppStructArray<int>.op_Implicit(new int[12]
			{
				0, 1, 2, 0, 2, 3, 4, 6, 5, 4,
				7, 6
			});
			val6.RecalculateNormals();
			val6.RecalculateTangents();
			val6.RecalculateBounds();
			val2.AddComponent<MeshFilter>().sharedMesh = val6;
			Texture2D val7 = new Texture2D(96, 160, (TextureFormat)4, false)
			{
				name = "DrivableExcavatorScreen",
				wrapMode = (TextureWrapMode)1
			};
			Texture2D val8 = new Texture2D(1, 1, (TextureFormat)4, false, true);
			val8.SetPixel(0, 0, new Color(0f, 1f, 0f, 0.7f));
			val8.Apply();
			Material val9 = new Material(((Renderer)val).sharedMaterial)
			{
				name = "DrivableExcavatorScreen"
			};
			val9.SetTexture("_BaseColorMap", (Texture)(object)val7);
			val9.SetTexture("_MainTex", (Texture)(object)val7);
			val9.SetTexture("_MaskMap", (Texture)(object)val8);
			val9.SetTexture("_NormalMap", (Texture)null);
			val9.SetColor("_BaseColor", Color.white);
			val9.SetFloat("_AlbedoAffectEmissive", 1f);
			val9.SetFloat("_EmissiveExposureWeight", 0f);
			val9.SetColor("_EmissiveColor", Color.black);
			MeshRenderer obj = val2.AddComponent<MeshRenderer>();
			((Renderer)obj).sharedMaterial = val9;
			((Renderer)obj).shadowCastingMode = (ShadowCastingMode)0;
			val2.SetActive(true);
			CabScreen cabScreen = new CabScreen(val2, val9, val7);
			cabScreen.Blank();
			DefaultInterpolatedStringHandler defaultInterpolatedStringHandler = new DefaultInterpolatedStringHandler(67, 2);
			defaultInterpolatedStringHandler.AppendLiteral("Excavator cab screen made on the cab's monitor (normal ");
			defaultInterpolatedStringHandler.AppendFormatted<Vector3>(val4);
			defaultInterpolatedStringHandler.AppendLiteral(", shader '");
			Shader shader = val9.shader;
			defaultInterpolatedStringHandler.AppendFormatted((shader != null) ? ((Object)shader).name : null);
			defaultInterpolatedStringHandler.AppendLiteral("')");
			ModLog.Trace(defaultInterpolatedStringHandler.ToStringAndClear());
			return cabScreen;
		}

		internal bool Due(bool occupied, bool near)
		{
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_quad == (Object)null)
			{
				return false;
			}
			if (!(occupied && near) || !Plugin.ScreenOn.Value)
			{
				if (_on || !_blankDone)
				{
					Blank();
				}
				_on = false;
				return false;
			}
			if (!_on)
			{
				_on = true;
				_next = 0f;
			}
			_material.SetColor("_EmissiveColor", Color.white * Plugin.ScreenBrightness.Value);
			if (Time.time < _next)
			{
				return false;
			}
			_next = Time.time + 1f / Mathf.Max(Plugin.ScreenRefresh.Value, 0.5f);
			return true;
		}

		internal void Draw(ScreenState state)
		{
			_picture.Draw(state, Plugin.ScreenScale.Value);
			Upload();
		}

		private void Blank()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			_picture.Clear(ScreenPicture.Back);
			Upload();
			_material.SetColor("_EmissiveColor", Color.black);
			_blankDone = true;
		}

		private void Upload()
		{
			_texture.LoadRawTextureData(Il2CppStructArray<byte>.op_Implicit(_picture.Pixels));
			_texture.Apply(false);
		}
	}
	public class Excavators : MonoBehaviour
	{
		private class Live
		{
			public Entry Entry;

			public GolfCartController Cart;

			public ModelRig Rig;

			public Joints Shown;

			public bool Driving;

			public bool Working;

			public int Seat = -1;

			public float TopSpeed;

			public List<TrackBelt> Belts;

			public Transform Model;

			public TrackContact.Vehicle Contact;

			public Vector3 LastPos;

			public GameObject Scary;

			public float NextScare;

			public bool ScareLogged;

			public Fittings.Seating Seating;

			public Collider[] BodyBoxes = (Collider[])(object)new Collider[0];

			public Collider[] ArmBoxes = (Collider[])(object)new Collider[0];

			public ShapePart[] ArmParts = new ShapePart[0];

			public ShapePart[] CabParts = new ShapePart[0];

			public int Bumps;

			public int GroundBumps;

			public int Debris;

			public int WorkRefused;

			public bool Refused;

			public readonly Sounds Sounds = new Sounds();

			public float Top;

			public readonly List<Fittings.Zone> Zones = new List<Fittings.Zone>();

			public int Face;

			public bool Aboard;

			public bool Holding;

			public float LastForward;

			public int Held;

			public float AskedGain;

			public float ShoveAt;

			public float ShoveFrom;

			public int Shoves;

			public int ZoneStarts;

			public int PressStops;

			public int ObstacleStops;

			public int Pushes;

			public int MouseMoves;

			public string FirstObstacle;

			public string FirstPushed;

			public float Press = float.MinValue;

			public float NextPushCheck;

			public float DeepestPress;

			public bool Pressing;

			public bool DeepLogged;

			public Vector3 Anchor;

			public int AnchorBox = -1;

			public int AnchorCorner = -1;

			public readonly HashSet<int> Pinned = new HashSet<int>();

			public Fittings.Shape[] ArmShapes = new Fittings.Shape[0];

			public Fittings.Shape[] CabBoxes = new Fittings.Shape[0];

			public float Speed;

			public float SignedSpeed;

			public readonly MouseStick Stick = new MouseStick();

			public int MouseSideways;

			public int MouseUpDown;

			public CabScreen Screen;

			public Collider[] GameBoxes = (Collider[])(object)new Collider[0];

			public int MovingPieces;

			public int MovingBoxes;

			public bool? ShapeOn;

			public bool? ContactsOn;

			public float IdleContactSince = -1f;
		}

		internal sealed class ShapePart
		{
			public Transform Part;

			public Vector3 Center;

			public Vector3 Half;

			public int From;

			public int To;

			public ArmNear Near;
		}

		private class Scenery
		{
			public AssetReferenceRenderable Holder;

			public Transform Model;
		}

		[HarmonyPatch(typeof(GolfCartController), "PlayImpactAudio")]
		private static class CartBumpSound
		{
			private static bool Prefix(GolfCartController __instance)
			{
				if (Plugin.CartSounds.Value || (Object)(object)_instance == (Object)null)
				{
					return true;
				}
				Live live = _instance._lives.FirstOrDefault((Live l) => (Object)(object)l.Cart == (Object)(object)__instance);
				if (live == null)
				{
					return true;
				}
				live.Bumps++;
				return false;
			}

			private static void Postfix(GolfCartController __instance, bool __runOriginal)
			{
				if (__runOriginal && !Plugin.CartSounds.Value && !((Object)(object)_instance == (Object)null) && _instance._lives.Any((Live l) => (Object)(object)l.Cart == (Object)(object)__instance))
				{
					ModLog.Once("bump leak", "Excavator: the golf cart's bump sound played on an excavator despite [Sounds] CartSounds off (written once per game)", (LogLevel)4);
				}
			}
		}

		[HarmonyPatch(typeof(GolfCartController), "TriggerShove")]
		private static class HandPush
		{
			private static void Postfix(GolfCartController __instance)
			{
				//IL_0082: Unknown result type (might be due to invalid IL or missing references)
				//IL_0087: Unknown result type (might be due to invalid IL or missing references)
				Live live = (((Object)(object)_instance == (Object)null) ? null : _instance._lives.FirstOrDefault((Live l) => (Object)(object)l.Cart == (Object)(object)__instance));
				if (live == null)
				{
					return;
				}
				live.Shoves++;
				if (!(live.ShoveAt > 0f))
				{
					Rigidbody val = Body(__instance);
					live.ShoveAt = Time.time;
					float shoveFrom;
					if (!((Object)(object)val != (Object)null))
					{
						shoveFrom = 0f;
					}
					else
					{
						Vector3 velocity = val.velocity;
						shoveFrom = ((Vector3)(ref velocity)).magnitude;
					}
					live.ShoveFrom = shoveFrom;
				}
			}
		}

		[HarmonyPatch(typeof(GolfCartController), "OnCollisionEnter")]
		private static class Bumps
		{
			private static bool Prefix(GolfCartController __instance, Collision collision)
			{
				//IL_0125: Unknown result type (might be due to invalid IL or missing references)
				//IL_012c: Expected O, but got Unknown
				if ((Object)(object)_instance == (Object)null || collision == null)
				{
					return true;
				}
				Live live = _instance._lives.FirstOrDefault((Live l) => (Object)(object)l.Cart == (Object)(object)__instance);
				if (live == null)
				{
					return true;
				}
				try
				{
					Collider collider = collision.collider;
					if ((Object)(object)collider == (Object)null)
					{
						return true;
					}
					if (TrackContact.IsGround(collider))
					{
						if (!Grounds.Contains(collider))
						{
							Grounds.Add(collider);
						}
						IgnoreGround(live, collider);
						live.GroundBumps++;
						return false;
					}
					if (_debrisLayer == -2)
					{
						_debrisLayer = LayerMask.NameToLayer("SmallDynamic");
					}
					Rigidbody attachedRigidbody = collider.attachedRigidbody;
					if (live.Contact != null && (((Object)(object)attachedRigidbody != (Object)null && !attachedRigidbody.isKinematic && ((Component)collider).gameObject.layer == _debrisLayer) || TrackContact.TreeBits(collider) || TrackContact.Loose(collider)))
					{
						TrackContact.LetThrough(live.Contact, collider);
						live.Debris++;
					}
				}
				catch (Exception ex)
				{
					if (!_bumpErrorLogged)
					{
						_bumpErrorLogged = true;
						ManualLogSource logger = Plugin.Logger;
						bool flag = default(bool);
						BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(47, 1, ref flag);
						if (flag)
						{
							((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Excavator contact check failed (written once): ");
							((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
						}
						logger.LogError(val);
					}
				}
				return true;
			}
		}

		private struct Contact
		{
			public float Depth;

			public Vector3 Normal;

			public Vector3 Point;

			public int Box;

			public int Corner;

			public string Name;
		}

		[HarmonyPatch(typeof(SaveGameManager), "Load", new Type[]
		{
			typeof(string),
			typeof(SaveGameType)
		})]
		private static class GameLoadStart
		{
			private static void Prefix(string dir, SaveGameType saveGameType)
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				//IL_0002: Invalid comparison between Unknown and I4
				//IL_001a: Unknown result type (might be due to invalid IL or missing references)
				//IL_001c: Invalid comparison between Unknown and I4
				//IL_0053: Unknown result type (might be due to invalid IL or missing references)
				if ((int)saveGameType == 2)
				{
					ModLog.Trace("Game load of a guest's own character: not a world, excavator save slot kept");
					return;
				}
				_slot = EntryText.SlotOf(dir);
				_slotIsMultiplayer = (int)saveGameType == 1;
				ModLog.Trace($"Game loads save slot {_slot} ({saveGameType}): its excavator file is read on entering the world");
			}
		}

		[HarmonyPatch(typeof(SaveGameManager), "Save", new Type[]
		{
			typeof(string),
			typeof(string),
			typeof(bool)
		})]
		private static class GameSaveDone
		{
			private static void Postfix(string dir, bool savePlayerOnly)
			{
				if (savePlayerOnly)
				{
					ModLog.Trace("Game saved a guest's own character only: excavators not written");
				}
				else if ((Object)(object)_instance != (Object)null)
				{
					_instance.WriteSave(dir);
				}
			}
		}

		[HarmonyPatch(typeof(GolfCartController), "OnDriverInteraction")]
		private static class RetuneOnDrive
		{
			[HarmonyPriority(0)]
			private static void Postfix(GolfCartController __instance)
			{
				if (!((Object)(object)_instance == (Object)null) && _instance._lives.Any((Live l) => (Object)(object)l.Cart == (Object)(object)__instance))
				{
					Tune(__instance);
				}
			}
		}

		private const string LobbyKey = "aznan.drivableexcavator";

		private const string DriverKey = "aznan.drivableexcavator.driver";

		private const string Normal = "Normal";

		private const string Raised = "Raised";

		private static readonly Dictionary<string, string> ModelAddress = new Dictionary<string, string>
		{
			["Normal"] = "ExcavatorAddressable",
			["Raised"] = "ExcavatorRaisedArm"
		};

		private readonly List<Entry> _entries = new List<Entry>();

		private readonly List<Live> _lives = new List<Live>();

		private readonly Dictionary<string, GameObject> _templates = new Dictionary<string, GameObject>();

		private readonly HashSet<string> _failedModels = new HashSet<string>();

		private bool _inWorld;

		private bool _loaded;

		private static Excavators _instance;

		private float _nextScan;

		private float _nextSync;

		private string _lastLobbyValue;

		private string _lastDriverValue;

		private float _lobbySince = -1f;

		private readonly HashSet<string> _linksLogged = new HashSet<string>();

		private (Live live, float at) _exitCheck;

		private const string SceneryGroup = "Excavators";

		private readonly List<Scenery> _scenery = new List<Scenery>();

		private bool _groupMissingLogged;

		private const float NearMargin = 0.5f;

		private static readonly List<Collider> Grounds = new List<Collider>();

		private static int _debrisLayer = -2;

		private static bool _bumpErrorLogged;

		private static GolfCartControllerDefinition _pristine;

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

		private static Vector3? _cartCom;

		private static float _cartMass;

		private static GameObject _profileHolder;

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

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

		private static string _newHit;

		private static readonly List<int> _gone = new List<int>();

		private static readonly List<KeyValuePair<int, Collider>> _things = new List<KeyValuePair<int, Collider>>();

		private static readonly List<Bounds> _thingBoxes = new List<Bounds>();

		private readonly Stopwatch _pushWatch = new Stopwatch();

		private int _pushSteps;

		private bool _holdLook;

		private static bool _lookBlocked;

		private static bool _camWas;

		private static bool _mainWas;

		private readonly Stopwatch _beltWatch = new Stopwatch();

		private float _beltMax;

		private int _beltFrames;

		private static uint _slot;

		private static bool _slotIsMultiplayer;

		private static readonly string[] OldPrefixes = new string[2] { "mp", "sp" };

		private static bool IsHost => BoltNetwork.isServerOrNotRunning;

		public Excavators(IntPtr ptr)
			: base(ptr)
		{
		}

		private bool LogLinkOnce(string link, string message)
		{
			if (!_linksLogged.Add(link))
			{
				return false;
			}
			Plugin.Logger.LogInfo((object)message);
			return true;
		}

		private void Update()
		{
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Expected O, but got Unknown
			bool flag;
			try
			{
				flag = (Object)(object)LocalPlayer.Inventory != (Object)null;
			}
			catch
			{
				flag = false;
			}
			if (!flag)
			{
				if (_inWorld)
				{
					Leave();
				}
			}
			else
			{
				if (!Plugin.Enabled.Value)
				{
					return;
				}
				if (!_inWorld)
				{
					_inWorld = true;
					_nextScan = Time.time + Plugin.ScanSeconds.Value;
				}
				try
				{
					if (Time.time >= _nextScan)
					{
						_nextScan = Time.time + Plugin.ScanSeconds.Value;
						bool flag2 = !_loaded;
						if (flag2)
						{
							LoadSave();
						}
						if (_scenery.Count == 0 || (Object)(object)_scenery[0].Holder == (Object)null)
						{
							FindScenery();
						}
						else if (flag2)
						{
							ReplaceLoaded();
						}
					}
					if (Time.time >= _nextSync)
					{
						_nextSync = Time.time + 1f / Plugin.SyncPerSecond.Value;
						Sync();
					}
					_holdLook = false;
					foreach (Live life in _lives)
					{
						Drive(life, Time.deltaTime);
					}
					BlockLook(_holdLook);
				}
				catch (Exception ex)
				{
					ManualLogSource logger = Plugin.Logger;
					bool flag3 = default(bool);
					BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(26, 1, ref flag3);
					if (flag3)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Excavators update failed: ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
					}
					logger.LogError(val);
					_nextScan = Time.time + 30f;
				}
			}
		}

		private void LateUpdate()
		{
			foreach (Live life in _lives)
			{
				if (life.Working && !((Object)(object)life.Cart == (Object)null))
				{
					life.Cart._accelerationFactorGoal = 0f;
					life.Cart._steeringFactorGoal = 0f;
					life.Cart._handBrakeInput = !life.Pressing;
				}
			}
		}

		private static void LogExit(Live live)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: 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_004f: 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)
			Transform transform = LocalPlayer.Transform;
			if ((Object)(object)transform == (Object)null || (Object)(object)live.Cart == (Object)null)
			{
				return;
			}
			int num = 0;
			foreach (Collider item in (Il2CppArrayBase<Collider>)(object)Physics.OverlapCapsule(transform.position + Vector3.up * 0.3f, transform.position + Vector3.up * 1.5f, 0.3f))
			{
				if (((Component)item).transform.IsChildOf(((Component)live.Cart).transform) && !item.isTrigger)
				{
					num++;
				}
			}
			ModLog.Trace($"Excavator: you got out at {transform.position}, {((num == 0) ? "clear of the excavator" : (num + " of its colliders overlap you (stuck)"))}");
		}

		private void FixedUpdate()
		{
			foreach (Live life in _lives)
			{
				Push(life);
			}
			foreach (Live life2 in _lives)
			{
				Hold(life2, Time.fixedDeltaTime);
			}
		}

		private void Hold(Live live, float dt)
		{
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: 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_0150: 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_0100: 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_0184: 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_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: 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_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			Rigidbody val = ((live.Driving && (Object)(object)live.Cart != (Object)null) ? live.Cart._rigidbody : null);
			if ((Object)(object)val == (Object)null || val.isKinematic)
			{
				live.Holding = false;
				return;
			}
			Transform transform = ((Component)live.Cart).transform;
			Vector3 val2 = Vector3.ProjectOnPlane(transform.forward, Vector3.up);
			if (((Vector3)(ref val2)).sqrMagnitude > 0.01f)
			{
				((Vector3)(ref val2)).Normalize();
				float num = Vector3.Dot(val.velocity, val2);
				if (!live.Holding)
				{
					live.Holding = true;
					live.LastForward = num;
				}
				float num2 = (live.Pressing ? num : Handling.HeldSpeed(live.LastForward, num, Plugin.Acceleration.Value * dt));
				if (num2 != num)
				{
					live.Held++;
					live.AskedGain = Mathf.Max(live.AskedGain, (Mathf.Abs(num) - Mathf.Abs(live.LastForward)) / dt);
					val.velocity += val2 * (num2 - num);
				}
				live.LastForward = num2;
			}
			if (!(Plugin.TurnSpeed.Value <= 0f) && !live.Working && !live.Pressing)
			{
				float x = PlayerGolfCartDriverAction.GetMovementInput().x;
				float num3 = Vector3.Dot(val.velocity, transform.forward);
				float num4 = x * Plugin.TurnSpeed.Value * ((float)Math.PI / 180f) * ((num3 < -0.5f) ? (-1f) : 1f);
				Vector3 angularVelocity = val.angularVelocity;
				float num5 = Vector3.Dot(angularVelocity, transform.up);
				float num6 = ((Plugin.TurnAcceleration.Value > 0f) ? Mathf.MoveTowards(num5, num4, Plugin.TurnAcceleration.Value * ((float)Math.PI / 180f) * dt) : num4);
				val.angularVelocity = angularVelocity + transform.up * (num6 - num5);
			}
		}

		private void Leave()
		{
			ModLog.Trace($"Left the world: {_lives.Count} excavators forgotten");
			_linksLogged.Clear();
			_exitCheck = (live: null, at: 0f);
			_failedModels.Clear();
			_groupMissingLogged = false;
			foreach (Live life in _lives)
			{
				life.Sounds.Stop();
			}
			BlockLook(on: false);
			_slot = 0u;
			_inWorld = (_loaded = false);
			_entries.Clear();
			_lives.Clear();
			_lastLobbyValue = (_lastDriverValue = null);
			_lobbySince = -1f;
		}

		private void FindScenery()
		{
			//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_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Expected O, but got Unknown
			Stopwatch stopwatch = Stopwatch.StartNew();
			_scenery.Clear();
			for (int i = 0; i < SceneManager.sceneCount; i++)
			{
				if (_scenery.Count != 0)
				{
					break;
				}
				Scene sceneAt = SceneManager.GetSceneAt(i);
				foreach (GameObject item in (Il2CppArrayBase<GameObject>)(object)((Scene)(ref sceneAt)).GetRootGameObjects())
				{
					if (((Object)item).name != "Excavators")
					{
						continue;
					}
					for (int j = 0; j < item.transform.childCount; j++)
					{
						AssetReferenceRenderable component = ((Component)item.transform.GetChild(j)).GetComponent<AssetReferenceRenderable>();
						if (!((Object)(object)component == (Object)null))
						{
							Scenery s = new Scenery
							{
								Holder = component
							};
							_scenery.Add(s);
							component.AddOnRenderableLoadedListener(UnityAction<Transform>.op_Implicit((Action<Transform>)delegate(Transform model)
							{
								s.Model = model;
								Replace(s);
							}), true);
						}
					}
					break;
				}
			}
			if (_scenery.Count == 0 && !_groupMissingLogged)
			{
				_groupMissingLogged = true;
				ManualLogSource logger = Plugin.Logger;
				bool flag = default(bool);
				BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(79, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Scenery excavators: no '");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("Excavators");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("' object in the loaded scenes yet, tried again every ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<float>(Plugin.ScanSeconds.Value);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" s");
				}
				logger.LogWarning(val);
			}
			ModLog.Trace($"Excavator search: {_scenery.Count} scenery excavators found in the world scene, {stopwatch.Elapsed.TotalMilliseconds:0.00} ms (once per game)");
		}

		private void Replace(Scenery s)
		{
			//IL_027b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0282: Expected O, but got Unknown
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: 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_0176: 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)
			try
			{
				Transform model = s.Model;
				int num = ((!Plugin.Enabled.Value) ? 1 : ((!_loaded) ? 2 : (((Object)(object)model == (Object)null) ? 3 : ((!((Component)model).gameObject.activeSelf) ? 4 : 0))));
				switch (num)
				{
				default:
					if (ModLog.Changed(s.GetHashCode(), "scenery", num))
					{
						ModLog.Trace("A scenery excavator is left as it is: " + num switch
						{
							2 => "this game's excavator list is not read yet (done after ScanSeconds)", 
							1 => "[General] Enabled is off", 
							_ => "its model was unloaded by the game", 
						});
					}
					break;
				case 4:
					break;
				case 0:
				{
					Vector3 position = model.position;
					string key = EntryText.KeyOf(position.x, position.y, position.z);
					string text = (((Object)s.Holder).name.Contains("RaisedArm") ? "Raised" : "Normal");
					if (!((Object)(object)Template(text) == (Object)null))
					{
						Entry entry = _entries.FirstOrDefault((Entry e) => e.Key == key);
						if (entry == null && IsHost)
						{
							Quaternion rotation = model.rotation;
							entry = new Entry
							{
								Key = key,
								Model = text,
								X = position.x,
								Y = position.y,
								Z = position.z,
								RotX = rotation.x,
								RotY = rotation.y,
								RotZ = rotation.z,
								RotW = rotation.w
							};
							_entries.Add(entry);
							ModLog.Trace($"Scenery excavator '{((Object)s.Holder).name}' at {key} made drivable ({text})");
							Spawn(entry);
						}
						if (entry != null)
						{
							((Component)model).gameObject.SetActive(false);
							ModLog.Trace("Scenery excavator at " + key + " hidden");
						}
						else if (ModLog.Changed(s.GetHashCode(), "scenery", 5))
						{
							ModLog.Trace("Scenery excavator at " + key + " kept: not in the host's list (yet), a host without the mod changes nothing");
						}
					}
					break;
				}
				}
			}
			catch (Exception ex)
			{
				ManualLogSource logger = Plugin.Logger;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(31, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Scenery excavator not handled: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
				}
				logger.LogError(val);
			}
		}

		private void ReplaceLoaded()
		{
			foreach (Scenery item in _scenery)
			{
				Replace(item);
			}
		}

		private void Spawn(Entry e)
		{
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Expected O, but got Unknown
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)Template(e.Model) == (Object)null)
			{
				return;
			}
			Vector3 val = default(Vector3);
			((Vector3)(ref val))..ctor(e.X, e.Y, e.Z);
			Quaternion val2 = default(Quaternion);
			((Quaternion)(ref val2))..ctor(e.RotX, e.RotY, e.RotZ, e.RotW);
			GameObject val4;
			if (BoltNetwork.isRunning)
			{
				BoltEntity val3 = BoltNetwork.Instantiate(BoltPrefabs.GolfCart, val, val2);
				e.NetId = val3.networkId.Packed;
				val4 = ((Component)val3).gameObject;
			}
			else
			{
				val4 = Object.Instantiate<GameObject>(PrefabDatabase.Find(BoltPrefabs.GolfCart), val, val2);
			}
			GolfCartController component = val4.GetComponent<GolfCartController>();
			if ((Object)(object)component == (Object)null)
			{
				ManualLogSource logger = Plugin.Logger;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val5 = new BepInExErrorLogInterpolatedStringHandler(75, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val5).AppendLiteral("Excavator at ");
					((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<string>(e.Key);
					((BepInExLogInterpolatedStringHandler)val5).AppendLiteral(": the game's golf cart has no GolfCartController, not drivable");
				}
				logger.LogError(val5);
				return;
			}
			if ((Object)(object)component._saver != (Object)null)
			{
				WorldItemManager.UnregisterItem(component._saver, true);
				ModLog.Trace("Excavator at " + e.Key + ": vehicle left out of the game's world item save");
			}
			ModLog.Trace($"Excavator at {e.Key}: vehicle created at {val} (network id {e.NetId}, Bolt {(BoltNetwork.isRunning ? "on" : "off")})");
			Attach(e, component);
		}

		private void AttachListed()
		{
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			foreach (Entry e in _entries)
			{
				if (e.NetId == 0L)
				{
					continue;
				}
				Live live = _lives.FirstOrDefault((Live l) => l.Entry.NetId == e.NetId);
				if (live != null && (Object)(object)live.Cart != (Object)null)
				{
					continue;
				}
				BoltEntity val = BoltNetwork.FindEntity(new NetworkId
				{
					Packed = e.NetId
				});
				GolfCartController val2 = (((Object)(object)val == (Object)null) ? null : ((Component)val).GetComponent<GolfCartController>());
				if ((Object)(object)val2 == (Object)null)
				{
					if (ModLog.Changed(e.NetId.GetHashCode(), "guest vehicle", 0))
					{
						ModLog.Trace($"Multiplayer guest: the vehicle of the excavator at {e.Key} (network id {e.NetId}) is not here yet (out of range), looked for at each sync");
					}
					continue;
				}
				if (live != null)
				{
					live.Sounds.Stop();
					_lives.Remove(live);
					ModLog.Trace("Multiplayer guest: the vehicle of the excavator at " + e.Key + " came back in range, made an excavator again");
				}
				int count = _lives.Count;
				Attach(e, val2);
				if (_lives.Count > count)
				{
					LogLinkOnce("attached", "Multiplayer guest: an excavator's vehicle found by its network id and made an excavator (at " + e.Key + "); written once per game");
				}
			}
		}

		private void Attach(Entry e, GolfCartController cart)
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_0376: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = Template(e.Model);
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			Rigidbody val2 = Body(cart);
			if (!_cartCom.HasValue && (Object)(object)val2 != (Object)null)
			{
				_cartCom = val2.centerOfMass;
				_cartMass = val2.mass;
			}
			foreach (Renderer componentsInChild in ((Component)cart).GetComponentsInChildren<Renderer>(true))
			{
				componentsInChild.enabled = false;
			}
			GameObject val3 = Object.Instantiate<GameObject>(val, ((Component)cart).transform);
			((Object)val3).name = "DrivableExcavatorModel";
			val3.transform.localPosition = new Vector3(Plugin.ModelX.Value, Plugin.ModelY.Value, Plugin.ModelZ.Value);
			val3.transform.localRotation = Quaternion.Euler(0f, Plugin.ModelYaw.Value, 0f);
			ModelRig rig = new ModelRig(val3.transform);
			Live live = new Live
			{
				Entry = e,
				Cart = cart,
				Rig = rig,
				Shown = e.Joints,
				Model = val3.transform,
				LastPos = ((Component)cart).transform.position
			};
			List<Fittings.Shape> list = new List<Fittings.Shape>();
			if (!Plugin.ModelCollides.Value)
			{
				foreach (Collider componentsInChild2 in val3.GetComponentsInChildren<Collider>(true))
				{
					Object.Destroy((Object)(object)componentsInChild2);
				}
			}
			else
			{
				list = Fittings.Shapes(val3.transform);
				live.ArmBoxes = (from s in list
					where (Object)(object)rig.Boom != (Object)null && s.Transform.IsChildOf(rig.Boom)
					select s.Collider).ToArray();
				live.BodyBoxes = list.Select((Fittings.Shape s) => s.Collider).Except(live.ArmBoxes).ToArray();
				TurretBoxes(rig, val3.transform);
				live.ArmShapes = list.Where((Fittings.Shape s) => (Object)(object)rig.Boom != (Object)null && s.Transform.IsChildOf(rig.Boom)).ToArray();
				live.CabBoxes = list.Where((Fittings.Shape s) => (Object)(object)rig.Turret != (Object)null && s.Transform.IsChildOf(rig.Turret) && (!((Object)(object)rig.Boom != (Object)null) || !s.Transform.IsChildOf(rig.Boom))).ToArray();
				live.ArmParts = Parts(live.ArmShapes);
				live.CabParts = Parts(live.CabBoxes);
				if (list.Count > 0)
				{
					live.GameBoxes = (from b in (IEnumerable<BoxCollider>)val3.GetComponentsInChildren<BoxCollider>(true)
						where !((Collider)b).isTrigger
						select (Collider)(object)b).ToArray();
					live.MovingBoxes = live.GameBoxes.Count((Collider b) => (Object)(object)rig.Turret != (Object)null && ((Component)b).transform.IsChildOf(rig.Turret));
					live.MovingPieces = live.ArmShapes.Length + live.CabBoxes.Length;
				}
				ApplyGround(live, log: true);
			}
			live.Contact = Fittings.Fit(cart, val3.transform, list, out live.Seating, live.Zones);
			if (live.Seating != null)
			{
				SpreadWheels(cart, live.Seating.TrackBox);
				live.Screen = CabScreen.Make(live.Seating.Cab);
			}
			live.Belts = TrackBelt.For(((Component)cart).transform, val3.transform);
			Tune(cart);
			live.Top = TopSpeed(cart);
			live.Rig.Apply(live.Shown);
			_lives.Add(live);
			ModLog.Trace($"Excavator at {e.Key}: model {e.Model} put on its vehicle, joints {Describe(e.Joints)}{(Plugin.ModelCollides.Value ? "" : ", its colliders removed ([Model] Collides off)")}");
		}

		private static ShapePart[] Parts(Fittings.Shape[] shapes)
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Expected O, but got Unknown
			//IL_011d: 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_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: 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_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			List<ShapePart> list = new List<ShapePart>();
			int i = 0;
			Bounds val = default(Bounds);
			while (i < shapes.Length)
			{
				Transform parent = shapes[i].Transform.parent;
				ShapePart shapePart = new ShapePart
				{
					Part = parent,
					From = i
				};
				((Bounds)(ref val))..ctor(shapes[i].Piece.Center, shapes[i].Piece.Half * 2f);
				for (; i < shapes.Length && (Object)(object)shapes[i].Transform.parent == (Object)(object)parent; i++)
				{
					((Bounds)(ref val)).Encapsulate(new Bounds(shapes[i].Piece.Center, shapes[i].Piece.Half * 2f));
				}
				shapePart.To = i;
				shapePart.Center = ((Bounds)(ref val)).center;
				shapePart.Half = ((Bounds)(ref val)).extents;
				GameObject val2 = new GameObject("DrivableExcavatorNear");
				val2.SetActive(false);
				val2.layer = 0;
				val2.transform.SetParent(parent, false);
				BoxCollider obj = val2.AddComponent<BoxCollider>();
				((Collider)obj).isTrigger = true;
				float num = Mathf.Max(Mathf.Abs(parent.lossyScale.x), 0.01f);
				obj.center = ((Bounds)(ref val)).center;
				obj.size = ((Bounds)(ref val)).size + Vector3.one * (1f / num);
				shapePart.Near = val2.AddComponent<ArmNear>();
				val2.SetActive(true);
				list.Add(shapePart);
			}
			return list.ToArray();
		}

		private static void TurretBoxes(ModelRig rig, Transform model)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: 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_009c: 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_00e3: 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_0110: 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)
			if ((Object)(object)rig.Turret == (Object)null || (Object)(object)rig.Tracks == (Object)null)
			{
				return;
			}
			Bounds val = Fittings.LocalBox(model, rig.Tracks);
			float num = ((Bounds)(ref val)).max.y - 0.15f;
			int num2 = 0;
			int num3 = 0;
			foreach (BoxCollider componentsInChild in ((Component)model).GetComponentsInChildren<BoxCollider>(true))
			{
				if (!((Collider)componentsInChild).isTrigger && !((Component)componentsInChild).transform.IsChildOf(rig.Turret))
				{
					num3++;
					float num4 = float.MaxValue;
					for (int i = 0; i < 8; i++)
					{
						num4 = Mathf.Min(num4, model.InverseTransformPoint(Corner(componentsInChild, i)).y);
					}
					if (!(num4 < num))
					{
						GameObject val2 = new GameObject(((Object)((Component)componentsInChild).gameObject).name)
						{
							layer = ((Component)componentsInChild).gameObject.layer
						};
						val2.transform.SetParent(((Component)componentsInChild).transform, false);
						val2.transform.SetParent(rig.Turret, true);
						BoxCollider obj = val2.AddComponent<BoxCollider>();
						obj.center = componentsInChild.center;
						obj.size = componentsInChild.size;
						((Collider)obj).sharedMaterial = ((Collider)componentsInChild).sharedMaterial;
						((Collider)obj).enabled = ((Collider)componentsInChild).enabled;
						Object.DestroyImmediate((Object)(object)componentsInChild);
						num2++;
					}
				}
			}
			ModLog.Trace($"Excavator: {num2} body boxes over the tracks now turn with the cab, {num3 - num2} stay on the tracks");
		}

		private static void SpreadWheels(GolfCartController cart, Bounds trackBox)
		{
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: 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_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			float num = Mathf.Clamp01(Plugin.WheelSpread.Value);
			Transform transform = ((Component)cart).transform;
			List<string> list = new List<string>();
			WheelCollider[] array = (WheelCollider[])(object)new WheelCollider[4] { cart._frontLeftWheelCollider, cart._frontRightWheelCollider, cart._rearLeftWheelCollider, cart._rearRightWheelCollider };
			Vector3 val3 = default(Vector3);
			foreach (WheelCollider val in array)
			{
				if (!((Object)(object)val == (Object)null))
				{
					Vector3 val2 = transform.InverseTransformPoint(((Component)val).transform.position);
					((Vector3)(ref val3))..ctor(((Bounds)(ref trackBox)).center.x + Mathf.Sign(val2.x) * ((Bounds)(ref trackBox)).extents.x, val2.y, (val2.z >= 0f) ? ((Bounds)(ref trackBox)).max.z : ((Bounds)(ref trackBox)).min.z);
					Vector3 val4 = Vector3.Lerp(val2, val3, num);
					((Component)val).transform.position = transform.TransformPoint(val4);
					list.Add($"({val4.x:0.00}, {val4.z:0.00})");
				}
			}
			ModLog.Trace($"Excavator wheels moved toward the track corners ([Physics] WheelSpread {num}): {string.Join(" ", list)}");
		}

		private static void ApplyGround(Live live, bool log)
		{
			Grounds.RemoveAll((Collider g) => (Object)(object)g == (Object)null);
			foreach (Terrain item in (Il2CppArrayBase<Terrain>)(object)Terrain.activeTerrains)
			{
				TerrainCollider val = (((Object)(object)item != (Object)null) ? ((Component)item).GetComponent<TerrainCollider>() : null);
				if ((Object)(object)val != (Object)null && !Grounds.Contains((Collider)(object)val))
				{
					Grounds.Add((Collider)(object)val);
				}
			}
			foreach (Collider ground in Grounds)
			{
				IgnoreGround(live, ground);
			}
			if (Grounds.Count == 0)
			{
				Plugin.Logger.LogWarning((object)"Excavator: no terrain found yet, the model may scrape the ground once before it is ignored");
			}
			else if (log)
			{
				ModLog.Trace($"Excavator: {live.BodyBoxes.Length} body pieces and {live.ArmBoxes.Length} boom/arm/bucket pieces ignore {Grounds.Count} ground(s): the wheels carry it, the boom/arm/bucket push it by the mod's own force (Push)");
			}
		}

		private static void IgnoreGround(Live live, Collider ground)
		{
			Collider[] bodyBoxes = live.BodyBoxes;
			foreach (Collider val in bodyBoxes)
			{
				if ((Object)(object)val != (Object)null)
				{
					Physics.IgnoreCollision(val, ground, true);
				}
			}
			bodyBoxes = live.ArmBoxes;
			foreach (Collider val2 in bodyBoxes)
			{
				if ((Object)(object)val2 != (Object)null)
				{
					Physics.IgnoreCollision(val2, ground, true);
				}
			}
			bodyBoxes = live.GameBoxes;
			foreach (Collider val3 in bodyBoxes)
			{
				if ((Object)(object)val3 != (Object)null)
				{
					Physics.IgnoreCollision(val3, ground, true);
				}
			}
		}

		private static void ApplyCollision(Live live, CollisionSet set)
		{
			bool flag = false;
			if (live.GameBoxes.Length != 0 && set.Shape != live.ShapeOn)
			{
				flag = true;
				live.ShapeOn = set.Shape;
				Collider[] bodyBoxes = live.BodyBoxes;
				foreach (Collider val in bodyBoxes)
				{
					if ((Object)(object)val != (Object)null)
					{
						val.enabled = set.Shape;
					}
				}
				bodyBoxes = live.ArmBoxes;
				foreach (Collider val2 in bodyBoxes)
				{
					if ((Object)(object)val2 != (Object)null)
					{
						val2.enabled = set.Shape;
					}
				}
				bodyBoxes = live.GameBoxes;
				foreach (Collider val3 in bodyBoxes)
				{
					if ((Object)(object)val3 != (Object)null)
					{
						val3.enabled = !set.Shape;
					}
				}
				foreach (ShapePart item in live.ArmParts.Concat(live.CabParts))
				{
					if ((Object)(object)item.Near != (Object)null)
					{
						item.Near.Near.Clear();
						((Component)item.Near).gameObject.SetActive(set.Shape);
					}
				}
				ApplyGround(live, log: false);
				if (live.Contact != null)
				{
					live.Contact.Ignored.RemoveAll((Collider o) => (Object)(object)o == (Object)null);
					foreach (Collider item2 in live.Contact.Ignored)
					{
						if (set.Shape)
						{
							bodyBoxes = live.BodyBoxes;
							foreach (Collider val4 in bodyBoxes)
							{
								if ((Object)(object)val4 != (Object)null)
								{
									Physics.IgnoreCollision(val4, item2, true);
								}
							}
							bodyBoxes = live.ArmBoxes;
							foreach (Collider val5 in bodyBoxes)
							{
								if ((Object)(object)val5 != (Object)null)
								{
									Physics.IgnoreCollision(val5, item2, true);
								}
							}
							continue;
						}
						bodyBoxes = live.GameBoxes;
						foreach (Collider val6 in bodyBoxes)
						{
							if ((Object)(object)val6 != (Object)null)
							{
								Physics.IgnoreCollision(val6, item2, true);
							}
						}
					}
				}
			}
			if (live.Contact != null && set.Contacts != live.ContactsOn)
			{
				flag = true;
				live.ContactsOn = set.Contacts;
				foreach (GameObject trigger in live.Contact.Triggers)
				{
					if ((Object)(object)trigger != (Object)null)
					{
						trigger.SetActive(set.Contacts);
					}
				}
			}
			if (flag)
			{
				(int, int, int) tuple = CollisionPlan.Cost(set, live.BodyBoxes.Length + live.ArmBoxes.Length, live.MovingPieces, live.GameBoxes.Length, live.MovingBoxes, live.ArmParts.Length + live.CabParts.Length, (live.Contact != null) ? live.Contact.Triggers.Count : 0);
				string text = (set.Shape ? "driven here" : (set.Contacts ? "driven by someone else or moving" : "parked or driven slowly by someone else"));
				ModLog.Once("collision " + text, $"Excavator collision here while {text}: {tuple.Item1} solid colliders and {tuple.Item2} triggers switched on ({(set.Shape ? "the model's own shape" : "the game's boxes")}); written once per game and state", (LogLevel)16);
			}
		}

		internal static void PlacePassengers()
		{
			if ((Object)(object)_instance == (Object)null)
			{
				return;
			}
			foreach (Live life in _instance._lives)
			{
				Fittings.PlacePassengers(life.Seating);
			}
		}

		private GameObject Template(string modelId)
		{
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Expected O, but got Unknown
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Expected O, but got Unknown
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Expected O, but got Unknown
			if (_templates.TryGetValue(modelId, out var value) && (Object)(object)value != (Object)null)
			{
				return value;
			}
			if (_failedModels.Contains(modelId))
			{
				return null;
			}
			bool flag = default(bool);
			if (!ModelAddress.TryGetValue(modelId, out var value2))
			{
				_failedModels.Add(modelId);
				ManualLogSource logger = Plugin.Logger;
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(38, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Unknown excavator model '");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(modelId);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("' in the list");
				}
				logger.LogError(val);
				return null;
			}
			try
			{
				value = Addressables.LoadAssetAsync<GameObject>((Object)(object)String.op_Implicit(value2)).WaitForCompletion();
				if ((Object)(object)value == (Object)null)
				{
					_failedModels.Add(modelId);
					ManualLogSource logger2 = Plugin.Logger;
					BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(80, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Excavator model '");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(value2);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("' not loaded by the game: excavators of this model stay scenery");
					}
					logger2.LogError(val);
					return null;
				}
				_templates[modelId] = value;
				ModLog.Trace("Excavator model '" + value2 + "' loaded from the game");
				return value;
			}
			catch (Exception ex)
			{
				_failedModels.Add(modelId);
				ManualLogSource logger3 = Plugin.Logger;
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(31, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Excavator model '");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(value2);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("' not loaded: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
				}
				logger3.LogError(val);
				return null;
			}
		}

		internal static Rigidbody Body(GolfCartController cart)
		{
			if (!((Object)(object)cart._rigidbody != (Object)null))
			{
				return ((Component)cart).GetComponent<Rigidbody>();
			}
			return cart._rigidbody;
		}

		private static void Tune(GolfCartController cart)
		{
			//IL_025e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0263: Unknown result type (might be due to invalid IL or missing references)
			//IL_0275: Unknown result type (might be due to invalid IL or missing references)
			//IL_028b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0290: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cb: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_pristine == (Object)null)
			{
				_pristine = Object.Instantiate<GolfCartControllerDefinition>(cart._definition);
				((Object)_pristine).hideFlags = (HideFlags)32;
			}
			GolfCartControllerDefinition definition = cart._definition;
			GolfCartControllerDefinition val = Object.Instantiate<GolfCartControllerDefinition>(_pristine);
			OurDefinitions.Add(((Object)val).GetInstanceID());
			if ((Object)(object)definition != (Object)null && OurDefinitions.Remove(((Object)definition).GetInstanceID()))
			{
				DropProfiles(definition);
				Object.Destroy((Object)(object)definition);
			}
			float num = ((Plugin.Speed.Value == SpeedMode.Fun) ? 1f : Plugin.RealisticSpeedFactor.Value);
			float value = Plugin.MassFactor.Value;
			val.TorqueCurveMultiplier *= value * Plugin.PowerFactor.Value;
			val.TorqueCurve = Slower(_pristine.TorqueCurve, num);
			val.BoostTorqueCurve = Slower(_pristine.BoostTorqueCurve, num);
			val.MaxBrakeTorque *= value;
			val.HandBrakeTorque *= value;
			val.AccelerationBrakeTorque *= value;
			val.MinPowerUsage = 0f;
			val.MaxPowerUsage = 0f;
			float knockdownDamageMinSpeed = (val.BushBreakerMinSpeed = Plugin.DestroyMinSpeed.Value);
			val.KnockdownDamageMinSpeed = knockdownDamageMinSpeed;
			float num2 = Mathf.Max(Plugin.HandPush.Value, 0f) / value;
			val.ShoveForce = _pristine.ShoveForce * num2;
			val.ShoveUpForce = _pristine.ShoveUpForce * num2;
			val.ShoveAccelerationFactor = _pristine.ShoveAccelerationFactor * num2 / Mathf.Max(Plugin.PowerFactor.Value, 0.01f);
			val.FrontWheelBaseProfile = Profile(_pristine.FrontWheelBaseProfile, value);
			val.FrontWheelHighSpeedProfile = Profile(_pristine.FrontWheelHighSpeedProfile, value);
			val.FrontWheelDeepWaterProfile = Profile(_pristine.FrontWheelDeepWaterProfile, value);
			val.RearWheelBaseProfile = Profile(_pristine.RearWheelBaseProfile, value);
			val.RearWheelHighSpeedProfile = Profile(_pristine.RearWheelHighSpeedProfile, value);
			val.RearWheelDeepWaterProfile = Profile(_pristine.RearWheelDeepWaterProfile, value);
			cart._definition = val;
			cart._currentPower = val.MaxPower;
			Rigidbody val2 = Body(cart);
			if ((Object)(object)val2 != (Object)null)
			{
				Vector3? cartCom = _cartCom;
				if (cartCom.HasValue)
				{
					Vector3 valueOrDefault = cartCom.GetValueOrDefault();
					val2.mass = _cartMass * value;
					val2.centerOfMass = valueOrDefault + new Vector3(0f, Plugin.CenterOfMassY.Value, 0f);
				}
			}
			if (ModLog.Full)
			{
				string text = $"Vehicle tuned: speed x{num} ({Plugin.Speed.Value}), mass {(((Object)(object)val2 != (Object)null) ? val2.mass : 0f)} kg (x{value}), power x{Plugin.PowerFactor.Value}, hand push {val.ShoveForce:0.00} m/s forward and {val.ShoveUpForce:0.00} m/s up (x{Plugin.HandPush.Value}), damping x{Plugin.Damping.Value}, weight centre {(((Object)(object)val2 != (Object)null) ? val2.centerOfMass : Vector3.zero)}, battery {val.MaxPower} with no use (has power: {cart.HasPower})";
				if (ModLog.Changed(((Object)cart).GetInstanceID(), "tune", text.GetHashCode()))
				{
					ModLog.Trace(text);
				}
			}
		}

		private static AnimationCurve Slower(AnimationCurve game, float factor)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Expected O, but got Unknown
			if (game == null || factor <= 0f)
			{
				return game;
			}
			Il2CppStructArray<Keyframe> keys = game.keys;
			Keyframe[] array = (Keyframe[])(object)new Keyframe[((Il2CppArrayBase<Keyframe>)(object)keys).Length];
			for (int i = 0; i < ((Il2CppArrayBase<Keyframe>)(object)keys).Length; i++)
			{
				Keyframe val = ((Il2CppArrayBase<Keyframe>)(object)keys)[i];
				array[i] = new Keyframe(((Keyframe)(ref val)).time * factor, ((Keyframe)(ref val)).value, ((Keyframe)(ref val)).inTangent / factor, ((Keyframe)(ref val)).outTangent / factor);
			}
			return new AnimationCurve(array)
			{
				preWrapMode = game.preWrapMode,
				postWrapMode = game.postWrapMode
			};
		}

		private static float TopSpeed(GolfCartController cart)
		{
			//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)
			GolfCartControllerDefinition definition = cart._definition;
			AnimationCurve val = (((Object)(object)definition != (Object)null) ? definition.TorqueCurve : null);
			WheelCollider rearLeftWheelCollider = cart._rearLeftWheelCollider;
			if (val == null || (Object)(object)rearLeftWheelCollider == (Object)null || val.length == 0)
			{
				return 0f;
			}
			Keyframe val2 = ((Il2CppArrayBase<Keyframe>)(object)val.keys)[val.length - 1];
			return ((Keyframe)(ref val2)).time * 2f * (float)Math.PI * rearLeftWheelCollider.radius / 60f;
		}

		private static WheelCollider Profile(WheelCollider game, float mass)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)game == (Object)null)
			{
				return game;
			}
			if ((Object)(object)_profileHolder == (Object)null)
			{
				_profileHolder = new GameObject("DrivableExcavatorWheelProfiles");
				_profileHolder.SetActive(false);
				Object.DontDestroyOnLoad((Object)(object)_profileHolder);
				((Object)_profileHolder).hideFlags = (HideFlags)61;
			}
			Il2CppArrayBase<WheelCollider> components = ((Component)game).GetComponents<WheelCollider>();
			int i;
			for (i = 0; i < components.Length && ((Il2CppObjectBase)components[i]).Pointer != ((Il2CppObjectBase)game).Pointer; i++)
			{
			}
			WheelCollider obj = Object.Instantiate<GameObject>(((Component)game).gameObject, _profileHolder.transform).GetComponents<WheelCollider>()[i];
			JointSpring suspensionSpring = obj.suspensionSpring;
			suspensionSpring.spring *= mass;
			suspensionSpring.damper *= mass * Plugin.Damping.Value;
			obj.suspensionSpring = suspensionSpring;
			obj.mass *= mass;
			return obj;
		}

		private static void DropProfiles(GolfCartControllerDefinition def)
		{
			WheelCollider[] array = (WheelCollider[])(object)new WheelCollider[6] { def.FrontWheelBaseProfile, def.FrontWheelHighSpeedProfile, def.FrontWheelDeepWaterProfile, def.RearWheelBaseProfile, def.RearWheelHighSpeedProfile, def.RearWheelDeepWaterProfile };
			foreach (WheelCollider val in array)
			{
				if ((Object)(object)val != (Object)null && (Object)(object)_profileHolder != (Object)null && (Object)(object)((Component)val).transform.parent == (Object)(object)_profileHolder.transform)
				{
					Object.Destroy((Object)(object)((Component)val).gameObject);
				}
			}
		}

		private void Drive(Live live, float dt)
		{
			//IL_058c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0591: Unknown result type (might be due to invalid IL or missing references)
			//IL_068e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0693: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b21: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b26: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b27: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b29: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b2e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b33: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b38: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b3d: Unknown result type (might be due to invalid IL or missing references)
			//IL_06a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b57: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b64: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b84: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b86: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b8b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b90: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ba8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ba9: Unknown result type (might be due to invalid IL or missing references)
			//IL_07e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_07ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_07b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_07bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_082b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0832: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a20: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e95: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e9a: Unknown result type (might be due to invalid IL or missing references)
			//IL_10bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_10c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_10c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_10c8: Unknown result type (might be due to invalid IL or missing references)
			bool flag = (Object)(object)live.Cart == (Object)null;
			if (ModLog.Changed(live.GetHashCode(), "vehicle", flag ? 1 : 0) && flag)
			{
				ModLog.Trace("Excavator at " + live.Entry.Key + ": its vehicle is gone (out of range or destroyed), the excavator waits for it");
			}
			if (flag)
			{
				live.Sounds.Stop();
				return;
			}
			bool flag2 = live.Cart.HasLocalConnected(live.Cart.GetDriverSlotIndex());
			if (flag2 != live.Driving)
			{
				live.Driving = flag2;
				if (!flag2)
				{
					Rigidbody val = Body(live.Cart);
					ModLog.Trace($"Excavator at {live.Entry.Key}: you left the cab; this drive: top speed {live.TopSpeed:0.0} m/s (no pull left at {live.Top:0.0} m/s, mass {(((Object)(object)val != (Object)null) ? val.mass : 0f):0} kg); {live.Bumps} golf cart bump sound(s) silenced, {live.Debris} small debris let through on contact, {((live.Contact != null) ? live.Contact.Loose : 0)} loose thing(s) and tree bit(s) let through in all, {live.GroundBumps} ground contact(s); work buttons held {live.WorkRefused} time(s) over {Plugin.WorkMaxSpeed.Value} m/s (braked or boosted instead); mouse work {live.MouseMoves} frame(s), directions chosen {live.MouseSideways} sideways / {live.MouseUpDown} up-down ({Plugin.Mouse.Value}); {live.Sounds.DriveReport()}; part moves refused deeper than GroundDepth {live.PressStops} time(s), cab body stopped by a solid obstacle {live.ObstacleStops} time(s){((live.FirstObstacle != null) ? (" (first: '" + live.FirstObstacle + "')") : "")}; boom/arm/bucket pushed the machine {live.Pushes} physics step(s){((live.FirstPushed != null) ? $" (first against '{live.FirstPushed}', deepest {live.DeepestPress:0.00} m)" : "")}, {PushCost()}; damage zones switched on {live.ZoneStarts} time(s) (from {Plugin.DestroyMinSpeed.Value} m/s); speed gain held {live.Held} physics step(s) to {Plugin.Acceleration.Value} m/s² (the engine asked up to {live.AskedGain:0.0} m/s²); {BeltCost()}");
				}
				else
				{
					ModLog.Trace("Excavator at " + live.Entry.Key + ": you sat in the cab");
					if ((Object)(object)live.Model != (Object)null && Plugin.ModelCollides.Value)
					{
						ApplyGround(live, log: false);
					}
				}
				live.Top = TopSpeed(live.Cart);
				live.TopSpeed = 0f;
				live.Bumps = (live.GroundBumps = (live.Debris = (live.WorkRefused = (live.ZoneStarts = (live.PressStops = (live.ObstacleStops = (live.Pushes = (live.MouseMoves = (live.MouseSideways = (live.MouseUpDown = 0))))))))));
				live.FirstObstacle = (live.FirstPushed = null);
				live.DeepestPress = 0f;
				live.DeepLogged = false;
				live.Held = 0;
				live.AskedGain = 0f;
				_pushWatch.Reset();
				_pushSteps = 0;
				if (live.Contact != null)
				{
					live.Contact.Loose = 0;
				}
				_beltWatch.Reset();
				_beltFrames = 0;
				_beltMax = 0f;
			}
			Vector3 val2;
			if (flag2 && (Object)(object)live.Cart._rigidbody != (Object)null)
			{
				float topSpeed = live.TopSpeed;
				val2 = live.Cart._rigidbody.velocity;
				live.TopSpeed = Mathf.Max(topSpeed, ((Vector3)(ref val2)).magnitude);
			}
			int num = -1;
			for (int i = 0; i < 4; i++)
			{
				if (num >= 0)
				{
					break;
				}
				if (live.Cart.HasLocalConnected(i))
				{
					num = i;
				}
			}
			if (num != live.Seat)
			{
				if (num < 0 && live.Seat >= 0)
				{
					_exitCheck = (live: live, at: Time.time + 1f);
				}
				live.Seat = num;
			}
			if (_exitCheck.live == live && Time.time >= _exitCheck.at)
			{
				_exitCheck = (live: null, at: 0f);
				LogExit(live);
			}
			live.Working = false;
			Joints shown = live.Shown;
			VehicleActions vehicle;
			if (flag2)
			{
				vehicle = InputSystem.InputMapping.Vehicle;
				bool flag3 = Held(Plugin.TurretBoomButton.Value);
				bool flag4 = Held(Plugin.ArmBucketButton.Value);
				Rigidbody rigidbody = live.Cart._rigidbody;
				Vector2 movementInput = PlayerGolfCartDriverAction.GetMovementInput();
				int working;
				if (flag3 || flag4)
				{
					if (!((Object)(object)rigidbody == (Object)null))
					{
						val2 = rigidbody.velocity;
						working = ((((Vector3)(ref val2)).magnitude < Plugin.WorkMaxSpeed.Value) ? 1 : 0);
					}
					else
					{
						working = 1;
					}
				}
				else
				{
					working = 0;
				}
				live.Working = (byte)working != 0;
				bool flag5 = (flag3 || flag4) && !live.Working;
				if (flag5 && !live.Refused)
				{
					live.WorkRefused++;
				}
				live.Refused = flag5;
				if (live.Working && !_linksLogged.Contains("work"))
				{
					LogLinkOnce("work", $"Excavator work mode: {(flag3 ? "cab/boom" : "arm/bucket")} moved with the game's {(flag3 ? Plugin.TurretBoomButton.Value : Plugin.ArmBucketButton.Value)} button, standing still; written once per game");
				}
				Joints joints = live.Shown;
				if (live.Working)
				{
					joints = WorkInput.Step(live.Shown, flag3, flag4, movementInput.x, movementInput.y, dt, Plugin.Yaw, Plugin.Boom, Plugin.Arm, Plugin.Bucket);
				}
				bool flag6 = false;
				bool cab = false;
				bool arm = false;
				Vector2 delta = Vector2.zero;
				if (!live.Working && Plugin.MouseWork.Value)
				{
					flag6 = MouseHeld(out cab, out arm, out delta);
				}
				MouseAxis axis = live.Stick.Axis;
				live.Stick.Update(flag6 && cab, flag6 && arm, delta.x, delta.y, Plugin.MouseLockDistance.Value, Plugin.MouseFullSpeedDistance.Value);
				if (axis == MouseAxis.None && live.Stick.Axis != MouseAxis.None)
				{
					if (live.Stick.Axis == MouseAxis.Sideways)
					{
						live.MouseSideways++;
					}
					else
					{
						live.MouseUpDown++;
					}
				}
				if (flag6)
				{
					_holdLook |= Plugin.LockCamera.Value;
					MouseAxis axis2 = live.Stick.Axis;
					joints = ((Plugin.Mouse.Value == MouseMode.HoldSpeed) ? WorkInput.Stick(live.Shown, live.Stick.Button, axis2, live.Stick.Deflection, dt, Plugin.Yaw, Plugin.Boom, Plugin.Arm, Plugin.Bucket) : WorkInput.Mouse(live.Shown, cab, arm, (axis2 == MouseAxis.Sideways) ? live.Stick.FrameAlong : 0f, (axis2 == MouseAxis.UpDown) ? live.Stick.FrameAlong : 0f, Plugin.MouseSpeed.Value, dt, Plugin.Yaw, Plugin.Boom, Plugin.Arm, Plugin.Bucket));
					if (!SameJoints(joints, live.Shown))
					{
						live.MouseMoves++;
						LogLinkOnce("mouse", $"Excavator mouse work ({Plugin.Mouse.Value}): cab/boom (left button) or arm/bucket (right button), one direction at a time, moved while driving{(Plugin.LockCamera.Value ? ", camera held still" : "")}; written once per game");
					}
				}
				live.Entry.Joints = (live.Shown = OffGround(live, joints));
				if (live.Contact != null)
				{
					live.Contact.Pushing = Mathf.Abs(movementInput.y) > 0.1f && !live.Working;
				}
			}
			else
			{
				if (live.Contact != null)
				{
					live.Contact.Pushing = false;
				}
				Joints joints2 = live.Entry.Joints;
				Joints shown2 = live.Shown;
				shown2.Yaw = WorkInput.Toward(shown2.Yaw, joints2.Yaw, Plugin.TurretSpeed.Value * dt, wraps: true);
				shown2.Boom = WorkInput.Toward(shown2.Boom, joints2.Boom, Plugin.BoomSpeed.Value * dt, wraps: false);
				shown2.Arm = WorkInput.Toward(shown2.Arm, joints2.Arm, Plugin.ArmSpeed.Value * dt, wraps: false);
				shown2.Bucket = WorkInput.Toward(shown2.Bucket, joints2.Bucket, Plugin.BucketSpeed.Value * dt, wraps: false);
				live.Shown = shown2;
			}
			Vector3 position = ((Component)live.Cart).transform.position;
			Vector3 val3 = Vector3.ProjectOnPlane(position - live.LastPos, Vector3.up);
			float frameSpeed = ((dt > 0f) ? (((Vector3)(ref val3)).magnitude / dt * ((Vector3.Dot(val3, ((Component)live.Cart).transform.forward) < 0f) ? (-1f) : 1f)) : 0f);
			val2 = position - live.LastPos;
			if (((Vector3)(ref val2)).sqrMagnitude > 100f)
			{
				frameSpeed = 0f;
			}
			live.LastPos = position;
			live.SignedSpeed = SpeedAverage.Step(live.SignedSpeed, frameSpeed, dt, Plugin.SpeedSmoothing.Value);
			float num2 = (live.Speed = Mathf.Abs(live.SignedSpeed));
			bool flag7 = !SameJoints(shown, live.Shown);
			bool flag8 = flag2 || live.Cart.HasNetworkConnectedDriver();
			int num3 = Handling.DamageFace(flag8, live.SignedSpeed, Plugin.DestroyMinSpeed.Value);
			bool flag9 = live.Seat >= 0;
			if (num3 != live.Face || flag9 != live.Aboard)
			{
				if (num3 != 0 && live.Face == 0)
				{
					live.ZoneStarts++;
				}
				live.Face = num3;
				live.Aboard = flag9;
				foreach (Fittings.Zone zone in live.Zones)
				{
					if ((Object)(object)zone.Go == (Object)null)
					{
						continue;
					}
					foreach (BoxCollider item in zone.Front)
					{
						if ((Object)(object)item != (Object)null)
						{
							((Collider)item).enabled = num3 > 0;
						}
					}
					foreach (BoxCollider item2 in zone.Back)
					{
						if ((Object)(object)item2 != (Object)null)
						{
							((Collider)item2).enabled = num3 < 0;
						}
					}
					zone.Go.SetActive(num3 != 0 && !(zone.Players && flag9));
				}
			}
			if (num3 == 0)
			{
				foreach (Fittings.Zone zone2 in live.Zones)
				{
					if ((Object)(object)zone2.Go != (Object)null && zone2.Go.activeSelf)
					{
						ModLog.Once("zone leak", "Excavator damage zone '" + ((Object)zone2.Go).name + "' switched on under [Destruction] MinSpeed by something else: it can hit creatures standing still (written once per game)", (LogLevel)4);
						break;
					}
				}
			}
			if (live.ShoveAt > 0f && Time.time >= live.ShoveAt + 0.5f)
			{
				Rigidbody val4 = Body(live.Cart);
				DefaultInterpolatedStringHandler defaultInterpolatedStringHandler = new DefaultInterpolatedStringHandler(106, 5);
				defaultInterpolatedStringHandler.AppendLiteral("Excavator at ");
				defaultInterpolatedStringHandler.AppendFormatted(live.Entry.Key);
				defaultInterpolatedStringHandler.AppendLiteral(": pushed by hand ");
				defaultInterpolatedStringHandler.AppendFormatted(live.Shoves);
				defaultInterpolatedStringHandler.AppendLiteral(" time(s), speed ");
				defaultInterpolatedStringHandler.AppendFormatted(live.ShoveFrom, "0.00");
				defaultInterpolatedStringHandler.AppendLiteral(" to ");
				float value;
				if (!((Object)(object)val4 != (Object)null))
				{
					value = 0f;
				}
				else
				{
					val2 = val4.velocity;
					value = ((Vector3)(ref val2)).magnitude;
				}
				defaultInterpolatedStringHandler.AppendFormatted(value, "0.00");
				defaultInterpolatedStringHandler.AppendLiteral(" m/s half a second after the first ([Physics] HandPush ");
				defaultInterpolatedStringHandler.AppendFormatted(Plugin.HandPush.Value);
				defaultInterpolatedStringHandler.AppendLiteral(")");
				ModLog.Trace(defaultInterpolatedStringHandler.ToStringAndClear());
				live.ShoveAt = 0f;
				live.Shoves = 0;
			}
			if (live.Contact != null)
			{
				live.Contact.Speed = num2;
				if (flag7)
				{
					live.Contact.PartsMovingUntil = Time.time + 0.5f;
				}
			}
			if (flag7)
			{
				Rigidbody val5 = Body(live.Cart);
				if ((Object)(object)val5 != (Object)null)
				{
					val5.WakeUp();
				}
			}
			bool flag10 = num2 >= 0.1f;
			live.Sounds.Update(((Object)(object)live.Model != (Object)null) ? live.Model : ((Component)live.Cart).transform, flag8, (flag10 && live.Top > 0f) ? Mathf.Clamp01(num2 / live.Top) : 0f, flag7, dt);
			if (flag8 || flag10)
			{
				CartVolume(live.Cart);
			}
			CollisionSet set = CollisionPlan.For(flag2, live.Contact != null && live.Contact.Moving, flag7);
			ApplyCollision(live, set);
			if (set.Contacts && !flag8)
			{
				if (live.IdleContactSince < 0f)
				{
					live.IdleContactSince = Time.time;
				}
				else if (Time.time - live.IdleContactSince > 5f)
				{
					ModLog.Once("idle contacts", $"Excavator cost with nobody in it: contact triggers on for 5 s (speed {num2:0.00} m/s, parts moving {flag7}); written once per game", (LogLevel)4);
				}
			}
			else
			{
				live.IdleContactSince = -1f;
			}
			if (set.PoseWrites)
			{
				live.Rig.Apply(live.Shown);
			}
			if (live.Screen != null)
			{
				Transform transform = LocalPlayer.Transform;
				int num4;
				if ((Object)(object)transform != (Object)null)
				{
					val2 = transform.position - position;
					num4 = ((((Vector3)(ref val2)).sqrMagnitude < Plugin.ScreenDistance.Value * Plugin.ScreenDistance.Value) ? 1 : 0);
				}
				else
				{
					num4 = 0;
				}
				bool near = (byte)num4 != 0;
				if (live.Screen.Due(flag8, near))
				{
					live.Screen.Draw(ScreenOf(live));
				}
			}
			RunBelts(live, dt);
			Scare(live);
			bool Held(VehicleButton b)
			{
				return ((b == VehicleButton.HandBrake) ? vehicle.HandBrake : vehicle.Boost).IsPressed();
			}
		}

		private static ScreenState ScreenOf(Live live)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: 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_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d9: 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_02fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0304: Unknown result type (might be due to invalid IL or missing references)
			//IL_0309: Unknown result type (might be due to invalid IL or missing references)
			//IL_030e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: 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_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0287: Unknown result type (might be due to invalid IL or missing references)
			//IL_0289: Unknown result type (might be due to invalid IL or missing references)
			//IL_028e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0290: Unknown result type (might be due to invalid IL or missing references)
			//IL_0293: Unknown result type (might be due to invalid IL or missing references)
			//IL_0298: Unknown result type (might be due to invalid IL or missing references)
			//IL_029e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0342: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_021d: 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_022e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0235: Unknown result type (might be due to invalid IL or missing references)
			//IL_023e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0245: Unknown result type (might be due to invalid IL or missing references)
			//IL_0368: Unknown result type (might be due to invalid IL or missing references)
			//IL_0371: Unknown result type (might be due to invalid IL or missing references)
			//IL_0385: Unknown result type (might be due to invalid IL or missing references)
			//IL_025a: Unknown result type (might be due to invalid IL or missing references)
			//IL_025c: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fa: 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_03e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0426: Unknown result type (might be due to invalid IL or missing references)
			//IL_0435: Unknown result type (might be due to invalid IL or missing references)
			//IL_045b: Unknown result type (might be due to invalid IL or missing references)
			//IL_046a: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0489: 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_049a: Unknown result type (might be due to invalid IL or missing references)
			Transform model = live.Model;
			ModelRig rig = live.Rig;
			Vector3 f = model.TransformDirection(Quaternion.Euler(0f, live.Shown.Yaw, 0f) * Vector3.forward);
			Vector3 up = model.up;
			Vector3 o = model.position;
			ScreenState result = new ScreenState
			{
				SpeedKmh = live.SignedSpeed * 3.6f,
				ActivePart = ActivePart(live),
				ActiveShare = ((Plugin.Mouse.Value == MouseMode.HoldSpeed) ? live.Stick.Deflection : float.NaN),
				CabYaw = live.Shown.Yaw,
				TipHeight = float.NaN,
				GroundUnderTipY = float.NaN
			};
			ref float boomX = ref result.BoomX;
			ref float boomY = ref result.BoomY;
			(float, float) tuple = P(rig.Boom.position);
			boomX = tuple.Item1;
			boomY = tuple.Item2;
			ref float armX = ref result.ArmX;
			boomY = ref result.ArmY;
			tuple = P(rig.Arm.position);
			armX = tuple.Item1;
			boomY = tuple.Item2;
			ref float bucketX = ref result.BucketX;
			boomY = ref result.BucketY;
			tuple = P(rig.Bucket.position);
			bucketX = tuple.Item1;
			boomY = tuple.Item2;
			Vector3 val = rig.Bucket.position;
			float num = float.MaxValue;
			ShapePart[] armParts = live.ArmParts;
			foreach (ShapePart shapePart in armParts)
			{
				if ((Object)(object)shapePart.Part == (Object)null || !shapePart.Part.IsChildOf(rig.Bucket))
				{
					continue;
				}
				Vector3 val2 = shapePart.Part.InverseTransformVector(up);
				Vector3 val3 = Vector3.zero;
				float num2 = float.MaxValue;
				for (int j = shapePart.From; j < shapePart.To; j++)
				{
					Vector3[] corners = live.ArmShapes[j].Piece.Corners;
					foreach (Vector3 val4 in corners)
					{
						float num3 = val4.x * val2.x + val4.y * val2.y + val4.z * val2.z;
						if (num3 < num2)
						{
							num2 = num3;
							val3 = val4;
						}
					}
				}
				Vector3 val5 = shapePart.Part.TransformPoint(val3);
				float num4 = Vector3.Dot(val5 - o, up);
				if (num4 < num)
				{
					num = num4;
					val = val5;
				}
			}
			ref float tipX = ref result.TipX;
			boomY = ref result.TipY;
			(tipX, boomY) = P(val);
			Ray val6 = default(Ray);
			((Ray)(ref val6))..ctor(val + Vector3.up * 20f, Vector3.down);
			float num5 = float.MaxValue;
			RaycastHit val7 = default(RaycastHit);
			foreach (Collider ground in Grounds)
			{
				if ((Object)(object)ground != (Object)null && ground.Raycast(val6, ref val7, 40f) && ((RaycastHit)(ref val7)).distance < num5)
				{
					num5 = ((RaycastHit)(ref val7)).distance;
					result.TipHeight = val.y - ((RaycastHit)(ref val7)).point.y;
					result.GroundUnderTipY = P(((RaycastHit)(ref val7)).point).Item2;
				}
			}
			result.TipOnGround = !float.IsNaN(result.TipHeight) && result.TipHeight <= 0.02f;
			Bounds val8 = (Bounds)((live.Seating != null) ? live.Seating.TrackBox : new Bounds(Vector3.zero, Vector3.one));
			float num6 = float.MaxValue;
			float num7 = float.MinValue;
			Transform transform = ((Component)live.Cart).transform;
			float[] array = new float[2]
			{
				((Bounds)(ref val8)).min.x,
				((Bounds)(ref val8)).max.x
			};
			foreach (float num8 in array)
			{
				float[] array2 = new float[2]
				{
					((Bounds)(ref val8)).min.z,
					((Bounds)(ref val8)).max.z
				};
				foreach (float num9 in array2)
				{
					float item = P(transform.TransformPoint(new Vector3(num8, ((Bounds)(ref val8)).min.y, num9))).Item1;
					num6 = Mathf.Min(num6, item);
					num7 = Mathf.Max(num7, item);
				}
			}
			result.TrackBack = num6;
			result.TrackFront = num7;
			result.TrackTop = ((Bounds)(ref val8)).size.y;
			return result;
			(float, float) P(Vector3 p)
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				//IL_000d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0017: Unknown result type (might be due to invalid IL or missing references)
				//IL_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_0024: Unknown result type (might be due to invalid IL or missing references)
				return (Vector3.Dot(p - o, f), Vector3.Dot(p - o, up));
			}
		}

		private static int ActivePart(Live live)
		{
			MouseStick stick = live.Stick;
			if (!live.Driving || stick.Axis == MouseAxis.None)
			{
				return 0;
			}
			if (stick.Button != 1)
			{
				if (stick.Axis != MouseAxis.Sideways)
				{
					return 3;
				}
				return 4;
			}
			if (stick.Axis != MouseAxis.Sideways)
			{
				return 2;
			}
			return 1;
		}

		private static void CartVolume(GolfCartController cart)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: 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_0042: Unknown result type (might be due to invalid IL or missing references)
			float volume = (Plugin.CartSounds.Value ? 1f : 0f);
			EventInstance val = cart._engineAudioEventInstance;
			((EventInstance)(ref val)).setVolume(volume);
			List<EventInstance> wheelEventInstances = cart._wheelEventInstances;
			if (wheelEventInstances != null)
			{
				for (int i = 0; i < wheelEventInstances.Count; i++)
				{
					val = wheelEventInstances[i];
					((EventInstance)(ref val)).setVolume(volume);
				}
			}
		}

		private static bool MouseHeld(out bool cab, out bool arm, out Vector2 delta)
		{
			//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_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)
			cab = (arm = false);
			delta = Vector2.zero;
			Mouse current = Mouse.current;
			if (current == null)
			{
				return false;
			}
			cab = current.leftButton.isPressed;
			arm = current.rightButton.isPressed;
			if (!cab && !arm)
			{
				return false;
			}
			delta = ((InputControl<Vector2>)(object)((Pointer)current).delta).ReadValue();