Decompiled source of Ironroad Motorworks v1.1.1

BepInEx/plugins/DrivableCar/DrivableCar.dll

Decompiled 2 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using Microsoft.CodeAnalysis;
using Surik.Assets;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("DrivableCar")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.1.1.0")]
[assembly: AssemblyInformationalVersion("1.1.1+eab6c7e89f658012dfcf541fd5b3c00fa1ebd550")]
[assembly: AssemblyProduct("DrivableCar")]
[assembly: AssemblyTitle("DrivableCar")]
[assembly: AssemblyVersion("1.1.1.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace Surik.Assets
{
	internal static class ModAssets
	{
		internal static AssetBundle OpenBundle(Assembly assembly, string prefix)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Invalid comparison between Unknown and I4
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Invalid comparison between Unknown and I4
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Invalid comparison between Unknown and I4
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Invalid comparison between Unknown and I4
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Invalid comparison between Unknown and I4
			//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)
			RuntimePlatform platform = Application.platform;
			if ((int)platform <= 13)
			{
				if ((int)platform == 2)
				{
					goto IL_0020;
				}
				if ((int)platform == 13)
				{
					goto IL_0028;
				}
			}
			else
			{
				if ((int)platform == 43)
				{
					goto IL_0028;
				}
				if ((int)platform == 44)
				{
					goto IL_0020;
				}
			}
			throw new PlatformNotSupportedException(((object)Application.platform/*cast due to .constrained prefix*/).ToString());
			IL_0028:
			string text = "linux";
			goto IL_004a;
			IL_0020:
			text = "windows";
			goto IL_004a;
			IL_004a:
			using Stream stream = Resource(assembly, "Bundles." + prefix + "-" + text);
			using MemoryStream memoryStream = new MemoryStream();
			stream.CopyTo(memoryStream);
			return AssetBundle.LoadFromMemory(memoryStream.ToArray()) ?? throw new InvalidDataException(prefix + " bundle");
		}

		internal static Sprite Icon(Assembly assembly, string id)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			using Stream stream = Resource(assembly, "Icons." + id + ".png");
			using MemoryStream memoryStream = new MemoryStream();
			stream.CopyTo(memoryStream);
			Texture2D val = new Texture2D(2, 2);
			if (!AssetUtils.LoadImage(val, memoryStream.ToArray()))
			{
				throw new InvalidDataException(id);
			}
			((Texture)val).wrapMode = (TextureWrapMode)1;
			return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
		}

		private static Stream Resource(Assembly assembly, string suffix)
		{
			string text = assembly.GetName().Name + "." + suffix;
			return assembly.GetManifestResourceStream(text) ?? throw new FileNotFoundException(text);
		}
	}
}
namespace DrivableCar
{
	public sealed class CarController : MonoBehaviour, Interactable, Hoverable, IDoodadController
	{
		private const string Request = "VMCar.Request";

		private const string Grant = "VMCar.Grant";

		private const string Release = "VMCar.Release";

		private const string Drive = "VMCar.Drive";

		private static readonly int DriverKey = StringExtensionMethods.GetStableHashCode("VMCar.driver");

		private static readonly int PeerKey = StringExtensionMethods.GetStableHashCode("VMCar.peer");

		private static readonly int SteerKey = StringExtensionMethods.GetStableHashCode("VMCar.steer");

		private readonly WheelCollider[] wheels = (WheelCollider[])(object)new WheelCollider[4];

		private readonly Transform[] rims = (Transform[])(object)new Transform[4];

		private readonly Quaternion[] rimOffsets = (Quaternion[])(object)new Quaternion[4];

		private readonly Vector3[] hubs = (Vector3[])(object)new Vector3[4];

		internal static readonly int PassengerKey = StringExtensionMethods.GetStableHashCode("Surik.ScreeGoat.passenger");

		private static readonly int CargoLease = StringExtensionMethods.GetStableHashCode("Surik.ScreeGoat.cargoUntil");

		private static readonly int PassengerPeer = StringExtensionMethods.GetStableHashCode("Surik.ScreeGoat.passengerPeer");

		public string DisplayName = "Barrow King Sedan";

		public float TopSpeed = 14f;

		public float DriveTorque = 1300f;

		public float SlowSteer = 32f;

		public float FastSteer = 16f;

		public float MaxUphillFrontShare = 0.5f;

		public bool FourWheelDrive;

		private PassengerSeat passenger;

		private Container stash;

		private float passengerRequest;

		private float passengerInput;

		private float nextPassengerSend;

		private float passengerMount;

		private ZNetView view;

		private Rigidbody body;

		private Transform seat;

		private Transform leftExit;

		private Transform rightExit;

		private Vector3 input;

		private float lastInput;

		private float nextSend;

		private float requestUntil;

		private float mountTime;

		private float nextDriverCheck;

		private float wheelSpin;

		private float lastSteer;

		private bool wasOwner;

		private bool initializedOwnership;

		private long Driver
		{
			get
			{
				if (!IsValid())
				{
					return 0L;
				}
				return view.GetZDO().GetLong(DriverKey, 0L);
			}
		}

		internal bool CargoAvailable
		{
			get
			{
				//IL_0016: Unknown result type (might be due to invalid IL or missing references)
				//IL_001b: Unknown result type (might be due to invalid IL or missing references)
				if (IsValid() && Driver == 0L)
				{
					Vector3 linearVelocity = body.linearVelocity;
					return ((Vector3)(ref linearVelocity)).sqrMagnitude < 0.25f;
				}
				return false;
			}
		}

		internal bool CanDismantle
		{
			get
			{
				if (Driver == 0L && Occupant(guest: true) == 0L)
				{
					if (Object.op_Implicit((Object)(object)stash))
					{
						if (!stash.IsInUse())
						{
							Inventory inventory = stash.GetInventory();
							return inventory == null || inventory.NrOfItems() == 0;
						}
						return false;
					}
					return true;
				}
				return false;
			}
		}

		private void Awake()
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			view = ((Component)this).GetComponent<ZNetView>();
			body = ((Component)this).GetComponent<Rigidbody>();
			body.centerOfMass = new Vector3(0f, 0.48f, 0f);
			seat = ((Component)this).transform.Find("Rig/Seat");
			leftExit = ((Component)this).transform.Find("Rig/ExitL");
			rightExit = ((Component)this).transform.Find("Rig/ExitR");
			Transform[] componentsInChildren = ((Component)((Component)this).transform.Find("Visual")).GetComponentsInChildren<Transform>(true);
			string[] ids = new string[4] { "FL", "FR", "RL", "RR" };
			int i;
			for (i = 0; i < ids.Length; i++)
			{
				wheels[i] = ((Component)((Component)this).transform.Find("Rig/" + ids[i])).GetComponent<WheelCollider>();
				rims[i] = componentsInChildren.Single((Transform t) => ((Object)t).name == "Wheel" + ids[i]);
				rimOffsets[i] = Quaternion.Inverse(((Component)this).transform.rotation) * rims[i].rotation;
				hubs[i] = ((Component)this).transform.InverseTransformPoint(rims[i].position);
			}
			passenger = ((Component)this).GetComponentInChildren<PassengerSeat>(true);
			stash = ((Component)this).GetComponentInChildren<Container>(true);
			if (Object.op_Implicit((Object)(object)passenger))
			{
				view.Register<long>("Surik.Passenger.Request", (Action<long, long>)delegate(long sender, long id)
				{
					Claim(sender, id, guest: true);
				});
				view.Register<bool>("Surik.Passenger.Grant", (Action<long, bool>)delegate(long sender, bool ok)
				{
					Respond(sender, ok, guest: true);
				});
				view.Register<long>("Surik.Passenger.Release", (Action<long, long>)delegate(long sender, long id)
				{
					ReleasePassenger(sender, id);
				});
				view.Register("Surik.Passenger.Present", (Action<long>)delegate(long sender)
				{
					if (view.IsOwner() && Occupant(guest: true) != 0L && view.GetZDO().GetLong(PassengerPeer, 0L) == sender)
					{
						passengerInput = Time.unscaledTime;
					}
				});
			}
			view.Register<long>("VMCar.Request", (Action<long, long>)RequestSeat);
			view.Register<bool>("VMCar.Grant", (Action<long, bool>)SeatResponse);
			view.Register<long>("VMCar.Release", (Action<long, long>)ReleaseSeat);
			view.Register<Vector3>("VMCar.Drive", (Action<long, Vector3>)ReceiveInput);
		}

		public bool IsValid()
		{
			if (Object.op_Implicit((Object)(object)this) && Object.op_Implicit((Object)(object)view))
			{
				return view.IsValid();
			}
			return false;
		}

		public Component GetControlledComponent()
		{
			return (Component)(object)this;
		}

		public Vector3 GetPosition()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			return seat.position;
		}

		public string GetHoverName()
		{
			return DisplayName;
		}

		public float GetHoverOffset()
		{
			return 0.8f;
		}

		public string GetHoverText()
		{
			Player localPlayer = Player.m_localPlayer;
			string text = ((Driver == 0L) ? "Drive" : ((Object.op_Implicit((Object)(object)localPlayer) && (object)localPlayer.GetDoodadController() == this) ? "Exit" : "Occupied"));
			return GetHoverName() + "\n" + ((text == "Occupied") ? text : Localization.instance.Localize("[<color=yellow><b>$KEY_Use</b></color>] " + text));
		}

		public bool UseItem(Humanoid user, ItemData item)
		{
			return false;
		}

		public bool Interact(Humanoid user, bool hold, bool alt)
		{
			return Board(user, hold, guest: false);
		}

		internal long Occupant(bool guest)
		{
			if (!IsValid())
			{
				return 0L;
			}
			return view.GetZDO().GetLong(guest ? PassengerKey : DriverKey, 0L);
		}

		private Transform Seat(bool guest)
		{
			if (!guest)
			{
				return seat;
			}
			return ((Component)passenger).transform;
		}

		internal void ReserveCargoTransfer()
		{
			view.GetZDO().Set(CargoLease, ZNet.instance.GetTime().AddSeconds(1.5).Ticks);
		}

		internal bool Board(Humanoid user, bool hold, bool guest)
		{
			Player val = (Player)(object)((user is Player) ? user : null);
			if (hold || !IsValid() || !Object.op_Implicit((Object)(object)val) || (Object)(object)val != (Object)(object)Player.m_localPlayer)
			{
				return false;
			}
			if ((Object)(object)val.GetAttachPoint() == (Object)(object)Seat(guest))
			{
				val.StopDoodadControl();
			}
			else if (!((Character)val).IsAttached() && !((Character)val).IsDead() && InReach(val, guest))
			{
				if (guest)
				{
					passengerRequest = Time.unscaledTime + 3f;
				}
				else
				{
					requestUntil = Time.unscaledTime + 3f;
				}
				view.InvokeRPC(guest ? "Surik.Passenger.Request" : "VMCar.Request", new object[1] { val.GetPlayerID() });
			}
			return false;
		}

		private bool InReach(Player player, bool guest = false)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			return Vector3.Distance(((Component)player).transform.position, Seat(guest).position) <= player.m_maxInteractDistance;
		}

		private bool MayBoard(long sender, long playerId, bool guest)
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			if (playerId == 0L)
			{
				return false;
			}
			Player player = Player.GetPlayer(playerId);
			if (Object.op_Implicit((Object)(object)player))
			{
				if (((Character)player).GetOwner() == sender && !((Character)player).IsDead())
				{
					return InReach(player, guest);
				}
				return false;
			}
			ZNetPeer val = (ZNet.instance.IsServer() ? ZNet.instance.GetPeer(sender) : null);
			ZDO val2 = ((val == null) ? null : ZDOMan.instance.GetZDO(val.m_characterID));
			if (val2 != null && val2.GetOwner() == sender && val2.GetLong(ZDOVars.s_playerID, 0L) == playerId)
			{
				return Vector3.Distance(val2.GetPosition(), Seat(guest).position) <= 5f;
			}
			return false;
		}

		private void RequestSeat(long sender, long playerId)
		{
			Claim(sender, playerId, guest: false);
		}

		private void SeatResponse(long sender, bool granted)
		{
			Respond(sender, granted, guest: false);
		}

		private void Claim(long sender, long playerId, bool guest)
		{
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			if (!view.IsOwner())
			{
				return;
			}
			bool flag = (Occupant(guest) == 0L || Occupant(guest) == playerId) && Occupant(!guest) != playerId && MayBoard(sender, playerId, guest) && (guest || !Object.op_Implicit((Object)(object)stash) || (!stash.IsInUse() && ZNet.instance.GetTime().Ticks >= view.GetZDO().GetLong(CargoLease, 0L)));
			if (flag)
			{
				view.GetZDO().Set(guest ? PassengerKey : DriverKey, playerId);
				view.GetZDO().Set(guest ? PassengerPeer : PeerKey, sender);
				if (guest)
				{
					passengerInput = Time.unscaledTime;
				}
				else
				{
					input = Vector3.zero;
					lastInput = Time.unscaledTime;
				}
			}
			view.InvokeRPC(sender, guest ? "Surik.Passenger.Grant" : "VMCar.Grant", new object[1] { flag });
		}

		private void Respond(long sender, bool granted, bool guest)
		{
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			Player localPlayer = Player.m_localPlayer;
			if (!Object.op_Implicit((Object)(object)localPlayer) || !IsValid() || sender != view.GetZDO().GetOwner())
			{
				return;
			}
			if (!granted)
			{
				((Character)localPlayer).Message((MessageType)2, "$msg_inuse", 0, (Sprite)null, false);
				return;
			}
			Transform val = Seat(guest);
			if ((Object)(object)localPlayer.GetAttachPoint() == (Object)(object)val)
			{
				return;
			}
			float num = (guest ? passengerRequest : requestUntil);
			if (num <= 0f || Time.unscaledTime > num || ((Character)localPlayer).IsDead() || ((Character)localPlayer).IsAttached() || !InReach(localPlayer, guest))
			{
				view.InvokeRPC(guest ? "Surik.Passenger.Release" : "VMCar.Release", new object[1] { localPlayer.GetPlayerID() });
				return;
			}
			if (guest)
			{
				passengerRequest = 0f;
				passengerMount = Time.unscaledTime;
			}
			else
			{
				requestUntil = 0f;
				mountTime = Time.unscaledTime;
			}
			IDoodadController obj;
			if (!guest)
			{
				IDoodadController val2 = (IDoodadController)(object)this;
				obj = val2;
			}
			else
			{
				IDoodadController val2 = (IDoodadController)(object)passenger;
				obj = val2;
			}
			IDoodadController val3 = obj;
			localPlayer.StartDoodadControl(val3);
			((Character)localPlayer).AttachStart(val, ((Component)this).gameObject, false, false, false, "attach_chair", val.InverseTransformPoint((guest ? rightExit : leftExit).position), (Transform)null);
		}

		internal void PassengerHeartbeat()
		{
			if (IsValid() && !(Time.unscaledTime < nextPassengerSend))
			{
				nextPassengerSend = Time.unscaledTime + 0.45f;
				view.InvokeRPC("Surik.Passenger.Present", Array.Empty<object>());
			}
		}

		private void ReleasePassenger(long sender, long id)
		{
			if (view.IsOwner() && Occupant(guest: true) == id && view.GetZDO().GetLong(PassengerPeer, 0L) == sender)
			{
				ClearPassenger(view.GetZDO());
			}
		}

		private static void ClearPassenger(ZDO zdo)
		{
			zdo.Set(PassengerKey, 0L);
			zdo.Set(PassengerPeer, 0L);
		}

		public void ApplyControlls(Vector3 moveDir, Vector3 lookDir, bool run, bool autoRun, bool block)
		{
			//IL_000b: 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_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			if (IsValid())
			{
				Vector3 val = default(Vector3);
				((Vector3)(ref val))..ctor(Mathf.Clamp(moveDir.x, -1f, 1f), (float)(block ? 1 : 0), Mathf.Clamp(moveDir.z, -1f, 1f));
				if (view.IsOwner())
				{
					ReceiveInput(ZDOMan.GetSessionID(), val);
				}
				else if (Time.unscaledTime >= nextSend)
				{
					nextSend = Time.unscaledTime + 0.08f;
					view.InvokeRPC("VMCar.Drive", new object[1] { val });
				}
			}
		}

		private void ReceiveInput(long sender, Vector3 axes)
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			if (view.IsOwner() && Driver != 0L && view.GetZDO().GetLong(PeerKey, 0L) == sender && !float.IsNaN(((Vector3)(ref axes)).sqrMagnitude) && !float.IsInfinity(((Vector3)(ref axes)).sqrMagnitude))
			{
				input = new Vector3(Mathf.Clamp(axes.x, -1f, 1f), Mathf.Clamp01(axes.y), Mathf.Clamp(axes.z, -1f, 1f));
				lastInput = Time.unscaledTime;
			}
		}

		private void ReleaseSeat(long sender, long playerId)
		{
			if (view.IsOwner() && Driver == playerId && view.GetZDO().GetLong(PeerKey, 0L) == sender)
			{
				Park();
			}
		}

		private void Park()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			ClearDriver(view.GetZDO());
			input = Vector3.zero;
		}

		private static void ClearDriver(ZDO car)
		{
			car.Set(DriverKey, 0L);
			car.Set(PeerKey, 0L);
		}

		internal static void DriverDisconnected(ZNet server, ZNetPeer peer)
		{
			//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_00e6: Unknown result type (might be due to invalid IL or missing references)
			if (!server.IsServer() || peer.m_uid == 0L || !Object.op_Implicit((Object)(object)ZoneSystem.instance) || ZDOMan.instance == null)
			{
				return;
			}
			List<ZDO> list = new List<ZDO>();
			ZDOMan.instance.FindSectorObjects(ZoneSystem.GetZone(peer.GetRefPos()), server.GetSyncedSimulationDistance(), list, (List<ZDO>)null);
			foreach (ZDO item in list)
			{
				if (!CarPlugin.VehicleHashes.Contains(item.GetPrefab()))
				{
					continue;
				}
				bool flag = item.GetLong(PeerKey, 0L) == peer.m_uid;
				bool flag2 = item.GetLong(PassengerPeer, 0L) == peer.m_uid;
				if (!flag && !flag2)
				{
					continue;
				}
				if (!item.HasOwner() || item.GetOwner() == peer.m_uid)
				{
					item.SetOwner(ZDOMan.GetSessionID());
				}
				if (item.IsOwner())
				{
					if (flag)
					{
						ClearDriver(item);
					}
					if (flag2)
					{
						ClearPassenger(item);
					}
					ZDOMan.instance.ForceSendZDO(item.m_uid);
				}
			}
		}

		public void OnUseStop(Player player)
		{
			if (IsValid())
			{
				view.InvokeRPC("VMCar.Release", new object[1] { player.GetPlayerID() });
			}
			Detach(player);
		}

		internal void LeavePassenger(Player player)
		{
			if (IsValid())
			{
				view.InvokeRPC("Surik.Passenger.Release", new object[1] { player.GetPlayerID() });
			}
			Detach(player, guest: true);
		}

		internal void Detach(Player player, bool guest = false)
		{
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			ZNetView component = ((Component)player).GetComponent<ZNetView>();
			if (Object.op_Implicit((Object)(object)component) && component.IsValid() && ((Character)player).IsAttached() && (!guest || Object.op_Implicit((Object)(object)passenger)) && !((Object)(object)player.GetAttachPoint() != (Object)(object)Seat(guest)))
			{
				Vector3 position = ChooseExit(guest);
				((Character)player).AttachStop();
				((Component)player).transform.position = position;
				Rigidbody component2 = ((Component)player).GetComponent<Rigidbody>();
				component2.position = position;
				component2.linearVelocity = Vector3.zero;
			}
		}

		private Vector3 ChooseExit(bool guest)
		{
			//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_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: 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_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: 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_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			int mask = LayerMask.GetMask(new string[6] { "terrain", "Default", "static_solid", "piece", "vehicle", "Default_small" });
			Vector3[] array = (Vector3[])(object)new Vector3[5]
			{
				(guest ? rightExit : leftExit).position,
				(guest ? leftExit : rightExit).position,
				((Component)this).transform.TransformPoint(0f, 0.2f, -2.45f),
				((Component)this).transform.TransformPoint(0f, 0.2f, 2.45f),
				((Component)this).transform.position + Vector3.up * 1.5f
			};
			RaycastHit val = default(RaycastHit);
			for (int i = 0; i < array.Length; i++)
			{
				if (Physics.Raycast(array[i] + Vector3.up * 1.2f, Vector3.down, ref val, 4f, mask, (QueryTriggerInteraction)1))
				{
					Vector3 val2 = ((RaycastHit)(ref val)).point + Vector3.up * 0.08f;
					if (!Physics.CheckCapsule(val2 + Vector3.up * 0.36f, val2 + Vector3.up * 1.5f, 0.32f, mask, (QueryTriggerInteraction)1))
					{
						return val2;
					}
				}
			}
			return ((Component)this).transform.position + Vector3.up * 1.6f;
		}

		private void FixedUpdate()
		{
			//IL_0027: 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_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_022f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0234: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0301: Unknown result type (might be due to invalid IL or missing references)
			//IL_0306: Unknown result type (might be due to invalid IL or missing references)
			//IL_0308: Unknown result type (might be due to invalid IL or missing references)
			//IL_030d: Unknown result type (might be due to invalid IL or missing references)
			if (!IsValid())
			{
				return;
			}
			bool flag = view.IsOwner();
			WheelCollider[] array;
			if (!initializedOwnership || wasOwner != flag)
			{
				input = Vector3.zero;
				lastInput = Time.unscaledTime;
				passengerInput = Time.unscaledTime;
				wasOwner = flag;
				initializedOwnership = true;
				array = wheels;
				for (int i = 0; i < array.Length; i++)
				{
					((Collider)array[i]).enabled = flag;
				}
			}
			if (!flag)
			{
				return;
			}
			if (Object.op_Implicit((Object)(object)passenger) && Occupant(guest: true) != 0L && Time.unscaledTime - passengerInput > 4f)
			{
				ClearPassenger(view.GetZDO());
			}
			long num = Driver;
			float num2 = Time.unscaledTime - lastInput;
			if (num != 0L && Time.unscaledTime >= nextDriverCheck)
			{
				nextDriverCheck = Time.unscaledTime + 0.5f;
				Player player = Player.GetPlayer(num);
				if (num2 > 4f || (Object.op_Implicit((Object)(object)player) && (((Character)player).IsDead() || !InReach(player))))
				{
					Park();
					num = 0L;
				}
			}
			float num3 = Vector3.Dot(body.linearVelocity, ((Component)this).transform.forward);
			bool flag2 = num == 0L || num2 > 0.65f;
			bool flag3 = flag2 || input.y > 0.5f || (input.z < -0.05f && num3 > 0.6f);
			Vector3 val = Vector3.zero;
			int num4 = 0;
			array = wheels;
			WheelHit val2 = default(WheelHit);
			for (int i = 0; i < array.Length; i++)
			{
				if (array[i].GetGroundHit(ref val2))
				{
					val += ((WheelHit)(ref val2)).normal;
					num4++;
				}
			}
			((Vector3)(ref val)).Normalize();
			Vector3 val3;
			float num5;
			if (num4 >= 2)
			{
				val3 = Vector3.ProjectOnPlane(((Component)this).transform.forward, val);
				num5 = ((Vector3)(ref val3)).normalized.y;
			}
			else
			{
				num5 = 0f;
			}
			float num6 = num5;
			float num7 = Mathf.Max(0f, num6 * Mathf.Sign(input.z));
			float mass = body.mass;
			val3 = Physics.gravity;
			float num8 = mass * ((Vector3)(ref val3)).magnitude * num7 * wheels[0].radius;
			float num9 = ((flag3 || (num3 > TopSpeed && input.z > 0f) || (num3 < -5f && input.z < 0f)) ? 0f : (input.z * (DriveTorque + num8 * 1.15f)));
			float num10 = (FourWheelDrive ? 0.5f : (MaxUphillFrontShare * Mathf.InverseLerp(0.03f, 0.18f, num7)));
			if (flag3 && num4 >= 2)
			{
				val3 = body.linearVelocity;
				if (((Vector3)(ref val3)).magnitude < 0.85f)
				{
					body.AddForce(-Vector3.ProjectOnPlane(Physics.gravity, val), (ForceMode)5);
				}
			}
			float num11 = (flag2 ? 0f : (input.x * Mathf.Lerp(SlowSteer, FastSteer, Mathf.Abs(num3) / TopSpeed)));
			if (Mathf.Abs(num11 - lastSteer) > 2f || (num11 == 0f && lastSteer != 0f))
			{
				view.GetZDO().Set(SteerKey, num11);
				lastSteer = num11;
			}
			for (int j = 0; j < wheels.Length; j++)
			{
				wheels[j].steerAngle = ((j < 2) ? num11 : 0f);
				wheels[j].motorTorque = num9 * 0.5f * ((j < 2) ? num10 : (1f - num10));
				wheels[j].brakeTorque = (flag3 ? 2500 : ((Mathf.Abs(input.z) < 0.03f) ? 25 : 0));
			}
		}

		private void LateUpdate()
		{
			//IL_00c8: 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_01cf: 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_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: 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_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			if (!IsValid())
			{
				return;
			}
			Player localPlayer = Player.m_localPlayer;
			if (Object.op_Implicit((Object)(object)localPlayer) && (object)localPlayer.GetDoodadController() == this && (((Character)localPlayer).IsDead() || !((Character)localPlayer).IsAttached() || (Time.unscaledTime - mountTime > 2f && Driver != localPlayer.GetPlayerID())))
			{
				localPlayer.StopDoodadControl();
			}
			if (Object.op_Implicit((Object)(object)passenger) && Object.op_Implicit((Object)(object)localPlayer) && (object)localPlayer.GetDoodadController() == passenger && (((Character)localPlayer).IsDead() || !((Character)localPlayer).IsAttached() || (Time.unscaledTime - passengerMount > 2f && Occupant(guest: true) != localPlayer.GetPlayerID())))
			{
				localPlayer.StopDoodadControl();
			}
			if (!view.IsOwner())
			{
				float num = Vector3.Dot(body.linearVelocity, ((Component)this).transform.forward);
				wheelSpin = Mathf.Repeat(wheelSpin + num * Time.deltaTime / wheels[0].radius * 57.29578f, 360f);
				float num2 = view.GetZDO().GetFloat(SteerKey, 0f);
				for (int i = 0; i < rims.Length; i++)
				{
					rims[i].SetPositionAndRotation(((Component)this).transform.TransformPoint(hubs[i]), ((Component)this).transform.rotation * Quaternion.AngleAxis((i < 2) ? num2 : 0f, Vector3.up) * Quaternion.AngleAxis(wheelSpin, Vector3.right) * rimOffsets[i]);
				}
			}
			else
			{
				Vector3 val = default(Vector3);
				Quaternion val2 = default(Quaternion);
				for (int j = 0; j < wheels.Length; j++)
				{
					wheels[j].GetWorldPose(ref val, ref val2);
					rims[j].SetPositionAndRotation(val, val2 * rimOffsets[j]);
				}
			}
		}

		private void OnDisable()
		{
			Player localPlayer = Player.m_localPlayer;
			if (Object.op_Implicit((Object)(object)localPlayer) && (object)localPlayer.GetDoodadController() == this)
			{
				localPlayer.StopDoodadControl();
				Detach(localPlayer);
			}
		}
	}
	[BepInPlugin("valheimcollection.drivablecar", "Ironroad Motorworks", "1.1.1")]
	[BepInDependency("com.jotunn.jotunn", "2.30.2")]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	public sealed class CarPlugin : BaseUnityPlugin
	{
		internal const string Id = "valheimcollection.drivablecar";

		public const string PrefabName = "VM_DrivableCar";

		private const string SedanSpawnName = "Surik_BarrowKingSedan";

		private static readonly int SedanSpawnHash = StringExtensionMethods.GetStableHashCode("Surik_BarrowKingSedan");

		private static readonly int SavedSedanHash = StringExtensionMethods.GetStableHashCode("VM_DrivableCar");

		private Harmony patches;

		internal const string Jeep = "Surik_ScreeGoat";

		internal const string Sports = "Surik_BifrostGT";

		internal static readonly HashSet<int> VehicleHashes = new HashSet<int>
		{
			StringExtensionMethods.GetStableHashCode("VM_DrivableCar"),
			StringExtensionMethods.GetStableHashCode("Surik_ScreeGoat"),
			StringExtensionMethods.GetStableHashCode("Surik_BifrostGT")
		};

		private void Awake()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			patches = new Harmony("valheimcollection.drivablecar");
			patches.PatchAll(typeof(CarPlugin));
			PrefabManager.OnVanillaPrefabsAvailable += Register;
		}

		private void Register()
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			PrefabManager.OnVanillaPrefabsAvailable -= Register;
			AssetBundle bundle = ModAssets.OpenBundle(Assembly.GetExecutingAssembly(), "car");
			GameObject staging = new GameObject("Ironroad registration");
			staging.SetActive(false);
			try
			{
				Add("VM_DrivableCar", "Barrow King Sedan", "A finned touring sedan.", "piece_workbench", (RequirementConfig[])(object)new RequirementConfig[4]
				{
					Cost("Bronze", 12),
					Cost("FineWood", 20),
					Cost("DeerHide", 8),
					Cost("SurtlingCore", 2)
				});
				Add("Surik_ScreeGoat", "Scree Goat 4×4", "Four-wheel drive, two seats and a twelve-slot tailgate stash.", "forge", (RequirementConfig[])(object)new RequirementConfig[4]
				{
					Cost("Iron", 16),
					Cost("ElderBark", 20),
					Cost("Chain", 4),
					Cost("DeerHide", 8)
				});
				Add("Surik_BifrostGT", "Bifröst GT", "A low and nimble grand tourer.", "piece_artisanstation", (RequirementConfig[])(object)new RequirementConfig[4]
				{
					Cost("BlackMetal", 20),
					Cost("FineWood", 16),
					Cost("LinenThread", 12),
					Cost("Tar", 6)
				});
			}
			finally
			{
				Object.Destroy((Object)(object)staging);
				bundle.Unload(false);
			}
			void Add(string id, string title, string description, string station, RequirementConfig[] costs)
			{
				//IL_0050: 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_00d6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
				//IL_0131: Unknown result type (might be due to invalid IL or missing references)
				//IL_014a: Unknown result type (might be due to invalid IL or missing references)
				//IL_017e: Unknown result type (might be due to invalid IL or missing references)
				//IL_025d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0262: Unknown result type (might be due to invalid IL or missing references)
				//IL_0269: Unknown result type (might be due to invalid IL or missing references)
				//IL_0270: Unknown result type (might be due to invalid IL or missing references)
				//IL_027b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0283: Unknown result type (might be due to invalid IL or missing references)
				//IL_028b: Unknown result type (might be due to invalid IL or missing references)
				//IL_029e: Expected O, but got Unknown
				//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
				//IL_02b1: Expected O, but got Unknown
				GameObject obj = bundle.LoadAsset<GameObject>(id);
				if (!Object.op_Implicit((Object)(object)obj))
				{
					throw new InvalidDataException("Missing vehicle " + id);
				}
				GameObject val = Object.Instantiate<GameObject>(obj, staging.transform, false);
				((Object)val).name = id;
				ZNetView val2 = val.AddComponent<ZNetView>();
				val2.m_persistent = true;
				val2.m_type = (ObjectType)1;
				ZSyncTransform obj2 = val.AddComponent<ZSyncTransform>();
				obj2.m_syncPosition = (obj2.m_syncRotation = (obj2.m_syncBodyVelocity = true));
				CarController carController = val.AddComponent<CarController>();
				carController.DisplayName = title;
				if (id == "Surik_ScreeGoat")
				{
					carController.TopSpeed = 12f;
					carController.DriveTorque = 1430f;
					carController.SlowSteer = 39f;
					carController.FourWheelDrive = true;
					WheelCollider[] componentsInChildren = val.GetComponentsInChildren<WheelCollider>(true);
					foreach (WheelCollider obj3 in componentsInChildren)
					{
						WheelFrictionCurve forwardFriction = obj3.forwardFriction;
						((WheelFrictionCurve)(ref forwardFriction)).stiffness = ((WheelFrictionCurve)(ref forwardFriction)).stiffness * 1.3f;
						obj3.forwardFriction = forwardFriction;
					}
					GameObject gameObject = ((Component)val.transform.Find("Rig/Passenger")).gameObject;
					gameObject.AddComponent<PassengerSeat>();
					BoxCollider obj4 = gameObject.AddComponent<BoxCollider>();
					obj4.center = new Vector3(0.2f, 0.24f, 0f);
					obj4.size = new Vector3(0.69f, 0.52f, 0.6f);
					GameObject gameObject2 = ((Component)val.transform.Find("Rig/Tailgate")).gameObject;
					gameObject2.AddComponent<BoxCollider>().size = new Vector3(1.12f, 0.49f, 0.24f);
					Container obj5 = gameObject2.AddComponent<Container>();
					obj5.m_rootObjectOverride = val2;
					obj5.m_name = "Scree Goat stash";
					obj5.m_width = 4;
					obj5.m_height = 3;
					obj5.m_checkGuardStone = true;
					Container component = PrefabManager.Instance.GetPrefab("piece_chest_wood").GetComponent<Container>();
					obj5.m_bkg = component.m_bkg;
				}
				if (id == "Surik_BifrostGT")
				{
					carController.TopSpeed = 21f;
					carController.DriveTorque = 1790f;
					carController.SlowSteer = 35f;
					carController.FastSteer = 11f;
					carController.MaxUphillFrontShare = 0.32f;
				}
				int layer = LayerMask.NameToLayer("vehicle");
				Collider[] componentsInChildren2 = val.GetComponentsInChildren<Collider>(true);
				for (int i = 0; i < componentsInChildren2.Length; i++)
				{
					((Component)componentsInChildren2[i]).gameObject.layer = layer;
				}
				val.AddComponent<Piece>().m_canBeRemoved = true;
				PieceConfig val3 = new PieceConfig
				{
					Name = title,
					Description = description,
					PieceTable = "Hammer",
					CraftingStation = station,
					Requirements = costs,
					Icon = ModAssets.Icon(Assembly.GetExecutingAssembly(), id)
				};
				if (!PieceManager.Instance.AddPiece(new CustomPiece(val, false, val3)))
				{
					throw new InvalidDataException("Could not register " + id);
				}
				((BaseUnityPlugin)this).Logger.LogInfo((object)("Registered " + id));
			}
		}

		private static RequirementConfig Cost(string id, int amount)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Expected O, but got Unknown
			return new RequirementConfig(id, amount, 0, true);
		}

		[HarmonyPatch(typeof(ZNetScene), "GetPrefab", new Type[] { typeof(int) })]
		[HarmonyPrefix]
		private static void ResolveSedanAlias(ref int hash)
		{
			if (hash == SedanSpawnHash)
			{
				hash = SavedSedanHash;
			}
		}

		[HarmonyPatch(typeof(ZNetScene), "GetPrefabNames")]
		[HarmonyPostfix]
		private static void ShowSedanSpawnName(List<string> __result)
		{
			int num = __result.IndexOf("VM_DrivableCar");
			if (num >= 0)
			{
				__result[num] = "Surik_BarrowKingSedan";
			}
		}

		[HarmonyPatch(typeof(Container), "RPC_RequestOpen")]
		[HarmonyPrefix]
		private static bool ParkForOpen(Container __instance, long uid)
		{
			return AllowCargo(__instance, uid, "RPC_OpenResponse");
		}

		[HarmonyPatch(typeof(Container), "RPC_RequestStack")]
		[HarmonyPrefix]
		private static bool ParkForStack(Container __instance, long uid)
		{
			return AllowCargo(__instance, uid, "RPC_StackResponse");
		}

		[HarmonyPatch(typeof(Container), "RPC_RequestTakeAll")]
		[HarmonyPrefix]
		private static bool ParkForTake(Container __instance, long uid)
		{
			return AllowCargo(__instance, uid, "RPC_TakeAllResponse");
		}

		private static bool AllowCargo(Container chest, long uid, string response)
		{
			CarController carController = default(CarController);
			if (!Object.op_Implicit((Object)(object)chest.m_rootObjectOverride) || !((Component)chest.m_rootObjectOverride).TryGetComponent<CarController>(ref carController))
			{
				return true;
			}
			if (!chest.m_rootObjectOverride.IsOwner())
			{
				return false;
			}
			if (carController.CargoAvailable)
			{
				carController.ReserveCargoTransfer();
				return true;
			}
			chest.m_rootObjectOverride.InvokeRPC(uid, response, new object[1] { false });
			return false;
		}

		[HarmonyPatch(typeof(Container), "GetHoverText")]
		[HarmonyPostfix]
		private static void ParkPrompt(Container __instance, ref string __result)
		{
			CarController carController = default(CarController);
			if (Object.op_Implicit((Object)(object)__instance.m_rootObjectOverride) && ((Component)__instance.m_rootObjectOverride).TryGetComponent<CarController>(ref carController) && !carController.CargoAvailable)
			{
				__result = "Scree Goat stash\nPark and leave the driver's seat to open";
			}
		}

		[HarmonyPatch(typeof(Piece), "CanBeRemoved")]
		[HarmonyPostfix]
		private static void OccupiedPiece(Piece __instance, ref bool __result)
		{
			CarController carController = default(CarController);
			if (__result && ((Component)__instance).TryGetComponent<CarController>(ref carController))
			{
				__result = carController.CanDismantle;
			}
		}

		[HarmonyPatch(typeof(Player), "Interact")]
		[HarmonyPrefix]
		private static bool UseWhileSeated(Player __instance, bool hold)
		{
			if (!(__instance.GetDoodadController() is CarController) && !(__instance.GetDoodadController() is PassengerSeat))
			{
				return true;
			}
			if (!hold)
			{
				__instance.StopDoodadControl();
			}
			return false;
		}

		[HarmonyPatch(typeof(ZNet), "Disconnect")]
		[HarmonyPrefix]
		private static void ReleaseDisconnectedDriver(ZNet __instance, ZNetPeer peer)
		{
			CarController.DriverDisconnected(__instance, peer);
		}

		private void OnDestroy()
		{
			PrefabManager.OnVanillaPrefabsAvailable -= Register;
			Harmony obj = patches;
			if (obj != null)
			{
				obj.UnpatchSelf();
			}
		}
	}
	public sealed class PassengerSeat : MonoBehaviour, IDoodadController, Hoverable, Interactable
	{
		private CarController Car => ((Component)this).GetComponentInParent<CarController>();

		public string GetHoverName()
		{
			return "Scree Goat passenger seat";
		}

		public float GetHoverOffset()
		{
			return 0.35f;
		}

		public string GetHoverText()
		{
			return GetHoverName() + "\n" + ((Car.Occupant(guest: true) == 0L) ? Localization.instance.Localize("[<color=yellow><b>$KEY_Use</b></color>] Ride") : Localization.instance.Localize("$msg_inuse"));
		}

		public bool Interact(Humanoid user, bool hold, bool alt)
		{
			return Car.Board(user, hold, guest: true);
		}

		public bool UseItem(Humanoid user, ItemData item)
		{
			return false;
		}

		public void ApplyControlls(Vector3 move, Vector3 look, bool run, bool autoRun, bool block)
		{
			Car.PassengerHeartbeat();
		}

		public void OnUseStop(Player player)
		{
			Car.LeavePassenger(player);
		}

		public bool IsValid()
		{
			if (Object.op_Implicit((Object)(object)Car))
			{
				return Car.IsValid();
			}
			return false;
		}

		public Vector3 GetPosition()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			return ((Component)this).transform.position;
		}

		public Component GetControlledComponent()
		{
			return (Component)(object)Car;
		}

		private void OnDisable()
		{
			Player localPlayer = Player.m_localPlayer;
			if (Object.op_Implicit((Object)(object)localPlayer) && (object)localPlayer.GetDoodadController() == this)
			{
				localPlayer.StopDoodadControl();
				CarController car = Car;
				if (Object.op_Implicit((Object)(object)car))
				{
					car.Detach(localPlayer, guest: true);
				}
			}
		}
	}
}