Decompiled source of FroggosDrivingRevamped v1.0.1

Mods/FroggosDrivingRevamped.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text.RegularExpressions;
using FroggosDrivingRevamped;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppScheduleOne.AvatarFramework;
using Il2CppScheduleOne.DevUtilities;
using Il2CppScheduleOne.Map;
using Il2CppScheduleOne.NPCs;
using Il2CppScheduleOne.PlayerScripts;
using Il2CppScheduleOne.UI.Compass;
using Il2CppScheduleOne.UI.Phone;
using Il2CppScheduleOne.Vehicles;
using Il2CppSystem.Collections.Generic;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using S1API.PhoneApp;
using S1API.UI;
using S1API.Utils;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.Rendering;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(DriftMod), "FroggosDrivingRevamped", "1.0.1", "froggonater", null)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("FroggosDrivingRevamped")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1")]
[assembly: AssemblyProduct("FroggosDrivingRevamped")]
[assembly: AssemblyTitle("FroggosDrivingRevamped")]
[assembly: AssemblyVersion("1.0.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 FroggosDrivingRevamped
{
	internal static class AirLog
	{
		private const float LineEvery = 0.5f;

		private static bool _inAir;

		private static float _start;

		private static float _nextLine;

		private static float _maxHeight;

		private static Quaternion _startRot;

		private static bool _usedInput;

		private static bool _mismatchLogged;

		public static void Track(LandVehicle v, Rigidbody rb, bool air, int wheelsDown, int collidersDown, int wheelCount, float height, float pitch, float roll)
		{
			//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_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_0348: Unknown result type (might be due to invalid IL or missing references)
			//IL_034e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
			if (!DriftMod.Cfg.LogAir.Value)
			{
				return;
			}
			float time = Time.time;
			Vector3 velocity = rb.velocity;
			float value = ((Vector3)(ref velocity)).magnitude * 3.6f;
			if (air && collidersDown > 0 && !_mismatchLogged)
			{
				_mismatchLogged = true;
				DriftMod.Log.Msg($"[Air] Note: {collidersDown}/{wheelCount} wheel colliders still report ground contact in the air; using the wheel rays instead.");
			}
			if (air && !_inAir)
			{
				_inAir = true;
				_start = time;
				_nextLine = time + 0.5f;
				_maxHeight = height;
				_startRot = rb.rotation;
				_usedInput = false;
				DriftMod.Log.Msg($"[Air] Took off in {v.vehicleCode} at {value:0} km/h ({height:0.0} m above ground). Air control {(DriftMod.Cfg.AirControl.Value ? "on" : "off")}.");
			}
			else if (air)
			{
				if (height > _maxHeight)
				{
					_maxHeight = height;
				}
				if (pitch != 0f || roll != 0f)
				{
					_usedInput = true;
				}
				if (time >= _nextLine)
				{
					_nextLine = time + 0.5f;
					Transform transform = ((Component)v).transform;
					Vector3 angularVelocity = rb.angularVelocity;
					DriftMod.Log.Msg($"[Air] {time - _start:0.0}s: {height:0.0} m above ground, wheel rays {wheelsDown}/{wheelCount}, {value:0} km/h, input W/S {pitch:0} A/D {roll:0}, spin pitch {Vector3.Dot(angularVelocity, transform.right):0.00} roll {0f - Vector3.Dot(angularVelocity, transform.forward):0.00} rad/s, angular drag {rb.angularDrag:0.00}, kinematic {rb.isKinematic}.");
				}
			}
			else if (_inAir)
			{
				_inAir = false;
				_mismatchLogged = false;
				float value2 = Quaternion.Angle(_startRot, rb.rotation);
				DriftMod.Log.Msg($"[Air] Landed after {time - _start:0.0}s, max {_maxHeight:0.0} m above ground, turned {value2:0}° in the air, WASD {(_usedInput ? "used" : "not used")}.");
			}
		}
	}
	internal static class CarControl
	{
		private const float AirDelay = 0.1f;

		private const float AirMaxSpin = 3f;

		private const float FlipRise = 0.4f;

		private const float FlipHold = 1f;

		private const float FlipCooldown = 1.5f;

		private const float NitroRefillDelay = 0.6f;

		private static float _pitch;

		private static float _roll;

		private static bool _flipQueued;

		private static bool _nitroHeld;

		private static bool _jumpQueued;

		private static float _lastJump = -10f;

		private const float JumpCooldown = 1f;

		private const float DoubleTapWindow = 0.3f;

		private static float _lastJumpTap = -10f;

		private static int _airId;

		private static float _airTime;

		private static float _savedDrag = -1f;

		private static int _flipId;

		private static float _flipStart = -10f;

		private static Vector3 _flipFrom;

		private static Vector3 _flipTo;

		private static Quaternion _flipRot;

		private static float _fuel = -1f;

		private static float _lastBoost = -10f;

		private static bool _boostLogged;

		private static bool _failed;

		private static bool _jumpLogged;

		public static void Reset()
		{
			_airTime = 0f;
			_airId = 0;
			_savedDrag = -1f;
			_flipId = 0;
			_flipQueued = false;
			_fuel = -1f;
		}

		public static void ReadInput()
		{
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			Keyboard current = Keyboard.current;
			if (current == null)
			{
				_pitch = (_roll = 0f);
				_nitroHeld = false;
				return;
			}
			_pitch = (((ButtonControl)current.wKey).isPressed ? 1f : 0f) - (((ButtonControl)current.sKey).isPressed ? 1f : 0f);
			_roll = (((ButtonControl)current.dKey).isPressed ? 1f : 0f) - (((ButtonControl)current.aKey).isPressed ? 1f : 0f);
			if (((ButtonControl)current[DriftMod.Cfg.FlipKey]).wasPressedThisFrame)
			{
				_flipQueued = true;
			}
			if (((ButtonControl)current[DriftMod.Cfg.JumpKey]).wasPressedThisFrame)
			{
				float unscaledTime = Time.unscaledTime;
				if (unscaledTime - _lastJumpTap <= 0.3f)
				{
					_jumpQueued = true;
					_lastJumpTap = -10f;
				}
				else
				{
					_lastJumpTap = unscaledTime;
				}
			}
			_nitroHeld = ((ButtonControl)current[DriftMod.Cfg.NitroKey]).isPressed;
		}

		public static void Tick(LandVehicle v)
		{
			Rigidbody rb = v.Rb;
			if (!v.LocalPlayerIsDriver)
			{
				if (_airId == ((Object)v).GetInstanceID() && (Object)(object)rb != (Object)null)
				{
					SetAirDrag(rb, air: false);
					_airId = 0;
				}
			}
			else
			{
				if ((Object)(object)rb == (Object)null || rb.isKinematic)
				{
					return;
				}
				try
				{
					if (_flipQueued)
					{
						_flipQueued = false;
						StartFlip(v, rb);
					}
					if (Flipping(v))
					{
						_jumpQueued = false;
						StepFlip(rb);
						return;
					}
					if (_airId != ((Object)v).GetInstanceID())
					{
						_airId = ((Object)v).GetInstanceID();
						_airTime = 0f;
						_savedDrag = -1f;
					}
					int count;
					int collidersDown;
					int num = WheelsTouching(v, rb, out count, out collidersDown);
					bool flag = ((count == 0) ? (collidersDown > 0) : (num > 0));
					_airTime = (flag ? 0f : (_airTime + Time.fixedDeltaTime));
					bool flag2 = !flag && _airTime > 0.1f;
					if (_jumpQueued)
					{
						_jumpQueued = false;
						if (flag)
						{
							Jump(v, rb);
						}
					}
					AirLog.Track(v, rb, flag2, num, collidersDown, count, HeightAboveGround(rb), _pitch, _roll);
					bool flag3 = flag2 && DriftMod.Cfg.AirControl.Value;
					SetAirDrag(rb, flag3);
					if (flag3)
					{
						Air(v, rb);
					}
					Nitro(v, rb, flag);
					_failed = false;
				}
				catch (Exception ex)
				{
					if (!_failed)
					{
						DriftMod.Log.Error("Car control tick failed (logged once until it works again): " + ex);
					}
					_failed = true;
				}
			}
		}

		private static void Air(LandVehicle v, Rigidbody rb)
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: 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_008a: 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_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_00be: Unknown result type (might be due to invalid IL or missing references)
			if (_pitch != 0f || _roll != 0f)
			{
				Transform transform = ((Component)v).transform;
				float num = DriftMod.Cfg.AirControlStrength.Value * Time.fixedDeltaTime;
				Vector3 val = rb.angularVelocity;
				if (_pitch != 0f)
				{
					float num2 = Vector3.Dot(val, transform.right);
					val += transform.right * (Mathf.MoveTowards(num2, _pitch * 3f, num) - num2);
				}
				if (_roll != 0f)
				{
					float num3 = Vector3.Dot(val, transform.forward);
					val += transform.forward * (Mathf.MoveTowards(num3, (0f - _roll) * 3f, num) - num3);
				}
				rb.angularVelocity = val;
			}
		}

		private static int WheelsTouching(LandVehicle v, Rigidbody rb, out int count, out int collidersDown)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: 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_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			count = 0;
			collidersDown = 0;
			int num = 0;
			List<Wheel> wheels = v.wheels;
			if (wheels == null)
			{
				return 0;
			}
			Vector3 val = -((Component)v).transform.up;
			for (int i = 0; i < wheels.Count; i++)
			{
				WheelCollider val2 = (((Object)(object)wheels[i] != (Object)null) ? wheels[i].wheelCollider : null);
				if ((Object)(object)val2 == (Object)null)
				{
					continue;
				}
				count++;
				if (val2.isGrounded)
				{
					collidersDown++;
				}
				float num2 = val2.suspensionDistance + val2.radius + 0.25f;
				Il2CppStructArray<RaycastHit> val3 = Physics.RaycastAll(((Component)val2).transform.position, val, num2, -1, (QueryTriggerInteraction)1);
				for (int j = 0; j < ((Il2CppArrayBase<RaycastHit>)(object)val3).Length; j++)
				{
					RaycastHit val4 = ((Il2CppArrayBase<RaycastHit>)(object)val3)[j];
					Collider collider = ((RaycastHit)(ref val4)).collider;
					if ((Object)(object)collider != (Object)null && (Object)(object)collider.attachedRigidbody != (Object)(object)rb)
					{
						num++;
						break;
					}
				}
			}
			return num;
		}

		private static float HeightAboveGround(Rigidbody rb)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			Il2CppStructArray<RaycastHit> val = Physics.RaycastAll(rb.worldCenterOfMass, Vector3.down, 50f, -1, (QueryTriggerInteraction)1);
			float num = -1f;
			for (int i = 0; i < ((Il2CppArrayBase<RaycastHit>)(object)val).Length; i++)
			{
				RaycastHit val2 = ((Il2CppArrayBase<RaycastHit>)(object)val)[i];
				Collider collider = ((RaycastHit)(ref val2)).collider;
				if (!((Object)(object)collider == (Object)null) && !((Object)(object)collider.attachedRigidbody == (Object)(object)rb))
				{
					val2 = ((Il2CppArrayBase<RaycastHit>)(object)val)[i];
					float distance = ((RaycastHit)(ref val2)).distance;
					if (num < 0f || distance < num)
					{
						num = distance;
					}
				}
			}
			return num;
		}

		public static bool InAir(LandVehicle v)
		{
			if (_airId == ((Object)v).GetInstanceID())
			{
				return _airTime > 0.1f;
			}
			return false;
		}

		private static void SetAirDrag(Rigidbody rb, bool air)
		{
			if (air && _savedDrag < 0f)
			{
				_savedDrag = rb.angularDrag;
				rb.angularDrag = 0.05f;
			}
			else if (!air && _savedDrag >= 0f)
			{
				rb.angularDrag = _savedDrag;
				_savedDrag = -1f;
			}
		}

		private static void Jump(LandVehicle v, Rigidbody rb)
		{
			//IL_0036: 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_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			float value = DriftMod.Cfg.JumpStrength.Value;
			if (!(value <= 0f) && !(Time.time - _lastJump < 1f))
			{
				_lastJump = Time.time;
				Vector3 velocity = rb.velocity;
				if (velocity.y < 0f)
				{
					velocity.y = 0f;
				}
				rb.velocity = velocity + Vector3.up * value;
				if (!_jumpLogged)
				{
					_jumpLogged = true;
					DriftMod.Log.Msg($"Jump! ({value:0.#} m/s up, only logged the first time)");
				}
			}
		}

		private static bool Flipping(LandVehicle v)
		{
			if (_flipId == ((Object)v).GetInstanceID())
			{
				return Time.time - _flipStart < 1f;
			}
			return false;
		}

		private static void StartFlip(LandVehicle v, Rigidbody rb)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: 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_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			if (!(Time.time - _flipStart < 2.5f))
			{
				Transform transform = ((Component)v).transform;
				Vector3 val = Vector3.ProjectOnPlane(transform.forward, Vector3.up);
				if (((Vector3)(ref val)).sqrMagnitude < 0.05f)
				{
					val = Vector3.ProjectOnPlane(transform.up, Vector3.up);
				}
				if (((Vector3)(ref val)).sqrMagnitude < 0.0001f)
				{
					val = Vector3.forward;
				}
				_flipId = ((Object)v).GetInstanceID();
				_flipStart = Time.time;
				_flipFrom = rb.position;
				_flipTo = rb.position + Vector3.up * Mathf.Max(0.3f, DriftMod.Cfg.FlipHeight.Value);
				_flipRot = Quaternion.LookRotation(((Vector3)(ref val)).normalized, Vector3.up);
				DriftMod.Log.Msg("Flipping " + v.vehicleCode + " back onto its wheels.");
			}
		}

		private static void StepFlip(Rigidbody rb)
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: 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_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: 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_00ac: Unknown result type (might be due to invalid IL or missing references)
			float fixedDeltaTime = Time.fixedDeltaTime;
			float num = Mathf.SmoothStep(0f, 1f, Mathf.Clamp01((Time.time - _flipStart) / 0.4f));
			Vector3 val = Vector3.Lerp(_flipFrom, _flipTo, num);
			rb.velocity = Vector3.ClampMagnitude((val - rb.position) / fixedDeltaTime, 12f);
			rb.angularVelocity = Vector3.zero;
			rb.MoveRotation(Quaternion.Slerp(rb.rotation, _flipRot, Mathf.Clamp01(8f * fixedDeltaTime)));
			if (Time.time + fixedDeltaTime - _flipStart >= 1f)
			{
				rb.MoveRotation(_flipRot);
				rb.velocity = Vector3.zero;
			}
		}

		private static void Nitro(LandVehicle v, Rigidbody rb, bool grounded)
		{
			//IL_0053: 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_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			float value = DriftMod.Cfg.NitroPower.Value;
			float num = Mathf.Max(0.1f, DriftMod.Cfg.NitroSeconds.Value);
			if (value <= 0f)
			{
				return;
			}
			if (_fuel < 0f)
			{
				_fuel = num;
			}
			float fixedDeltaTime = Time.fixedDeltaTime;
			Transform transform = ((Component)v).transform;
			float num2 = Vector3.Dot(rb.velocity, transform.forward) * 3.6f;
			if (_nitroHeld && grounded && _fuel > 0f && num2 > -5f && num2 < DriftMod.Cfg.NitroMaxSpeed.Value)
			{
				rb.AddForce(transform.forward * value, (ForceMode)5);
				_fuel = Mathf.Max(0f, _fuel - fixedDeltaTime);
				_lastBoost = Time.time;
				if (!_boostLogged)
				{
					_boostLogged = true;
					DriftMod.Log.Msg("Nitro! (only logged the first time)");
				}
			}
			else if (Time.time - _lastBoost > 0.6f)
			{
				_fuel = Mathf.Min(num, _fuel + num / Mathf.Max(0.5f, DriftMod.Cfg.NitroRechargeSeconds.Value) * fixedDeltaTime);
			}
		}
	}
	[HarmonyPatch(typeof(LandVehicle), "UpdateTurnOver")]
	internal static class LandVehicleTurnOverPatch
	{
		private static bool Prefix(LandVehicle __instance)
		{
			if (__instance.LocalPlayerIsDriver)
			{
				return !CarControl.InAir(__instance);
			}
			return true;
		}
	}
	internal static class CarIcon
	{
		private static Sprite _app;

		private static Sprite _small;

		public static Sprite App()
		{
			//IL_00d0: 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_00f3: 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_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_app != (Object)null)
			{
				return _app;
			}
			Color32[] array = (Color32[])(object)new Color32[16384];
			Color32 val = default(Color32);
			((Color32)(ref val))..ctor(byte.MaxValue, (byte)150, (byte)40, byte.MaxValue);
			Color32 val2 = default(Color32);
			((Color32)(ref val2))..ctor((byte)230, (byte)80, (byte)30, byte.MaxValue);
			for (int i = 0; i < 128; i++)
			{
				for (int j = 0; j < 128; j++)
				{
					float num = (float)i / 128f;
					array[i * 128 + j] = (Color32)(RoundedTile(j, i, 128, 26f) ? Color32.Lerp(val2, val, num) : new Color32((byte)0, (byte)0, (byte)0, (byte)0));
				}
			}
			DrawCar(array, 128, 1f, new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue), new Color32((byte)230, (byte)80, (byte)30, byte.MaxValue), new Color32((byte)40, (byte)40, (byte)48, byte.MaxValue));
			return _app = Make(array, 128);
		}

		public static Sprite Small()
		{
			//IL_0030: 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_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: 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)
			if ((Object)(object)_small != (Object)null)
			{
				return _small;
			}
			Color32[] px = new Color32[4096];
			DrawCar((Color32[])(object)px, 64, 1.12f, new Color32((byte)20, (byte)20, (byte)24, (byte)230), new Color32((byte)20, (byte)20, (byte)24, (byte)230), new Color32((byte)20, (byte)20, (byte)24, (byte)230));
			DrawCar((Color32[])(object)px, 64, 1f, new Color32(byte.MaxValue, (byte)140, (byte)30, byte.MaxValue), new Color32(byte.MaxValue, (byte)225, (byte)190, byte.MaxValue), new Color32((byte)30, (byte)30, (byte)36, byte.MaxValue));
			return _small = Make((Color32[])(object)px, 64);
		}

		private static void DrawCar(Color32[] px, int n, float scale, Color32 body, Color32 glass, Color32 wheel)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: 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_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: 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_00e7: 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_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: 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_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			float u = (float)n / 128f * scale;
			Vector2 c = new Vector2((float)n * 0.5f, (float)n * 0.5f);
			Capsule(px, n, P(26f, 54f), P(102f, 54f), 13f * u, body);
			Box(px, n, P(26f, 46f), P(102f, 62f), body);
			Box(px, n, P(42f, 62f), P(86f, 80f), body);
			Capsule(px, n, P(46f, 76f), P(82f, 76f), 6f * u, body);
			Box(px, n, P(48f, 64f), P(62f, 76f), glass);
			Box(px, n, P(66f, 64f), P(80f, 76f), glass);
			Disc(px, n, P(44f, 42f), 12f * u, wheel);
			Disc(px, n, P(84f, 42f), 12f * u, wheel);
			Disc(px, n, P(44f, 42f), 4.5f * u, body);
			Disc(px, n, P(84f, 42f), 4.5f * u, body);
			Vector2 P(float x, float y)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0022: Unknown result type (might be due to invalid IL or missing references)
				//IL_0027: Unknown result type (might be due to invalid IL or missing references)
				return c + new Vector2((x - 64f) * u, (y - 64f) * u);
			}
		}

		private static bool RoundedTile(int x, int y, int n, float r)
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: 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)
			float num = Mathf.Clamp((float)x + 0.5f, r, (float)n - r);
			float num2 = Mathf.Clamp((float)y + 0.5f, r, (float)n - r);
			Vector2 val = new Vector2((float)x + 0.5f, (float)y + 0.5f) - new Vector2(num, num2);
			return ((Vector2)(ref val)).sqrMagnitude <= r * r;
		}

		private static void Disc(Color32[] px, int n, Vector2 c, float r, Color32 col)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: 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)
			Capsule(px, n, c, c, r, col);
		}

		private static void Capsule(Color32[] px, int n, Vector2 a, Vector2 b, float r, Color32 col)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: 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_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: 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_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00c1: 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_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: 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_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			int num = Mathf.Max(0, (int)(Mathf.Min(a.x, b.x) - r - 1f));
			int num2 = Mathf.Min(n - 1, (int)(Mathf.Max(a.x, b.x) + r + 1f));
			int num3 = Mathf.Max(0, (int)(Mathf.Min(a.y, b.y) - r - 1f));
			int num4 = Mathf.Min(n - 1, (int)(Mathf.Max(a.y, b.y) + r + 1f));
			Vector2 val = b - a;
			float num5 = Mathf.Max(((Vector2)(ref val)).sqrMagnitude, 0.0001f);
			for (int i = num3; i <= num4; i++)
			{
				for (int j = num; j <= num2; j++)
				{
					Vector2 val2 = new Vector2((float)j + 0.5f, (float)i + 0.5f);
					float num6 = Mathf.Clamp01(Vector2.Dot(val2 - a, val) / num5);
					float num7 = Vector2.Distance(val2, a + val * num6);
					Blend(px, i * n + j, col, Mathf.Clamp01(r - num7 + 0.5f));
				}
			}
		}

		private static void Box(Color32[] px, int n, Vector2 min, Vector2 max, Color32 col)
		{
			//IL_0001: 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_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			for (int i = Mathf.Max(0, (int)min.y); i < Mathf.Min(n, (int)max.y); i++)
			{
				for (int j = Mathf.Max(0, (int)min.x); j < Mathf.Min(n, (int)max.x); j++)
				{
					Blend(px, i * n + j, col, 1f);
				}
			}
		}

		private static void Blend(Color32[] px, int i, Color32 col, float a)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			if (!(a <= 0f))
			{
				Color32 val = px[i];
				byte a2 = (byte)Mathf.Max((float)(int)val.a, (float)(int)col.a * a);
				Color32 val2 = Color32.Lerp((Color32)((val.a == 0) ? new Color32(col.r, col.g, col.b, (byte)0) : val), col, a);
				val2.a = a2;
				px[i] = val2;
			}
		}

		private static Sprite Make(Color32[] px, int n)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: 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_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Expected O, but got Unknown
			Texture2D val = new Texture2D(n, n, (TextureFormat)4, false)
			{
				filterMode = (FilterMode)1,
				wrapMode = (TextureWrapMode)1,
				hideFlags = (HideFlags)32
			};
			val.SetPixels32(new Il2CppStructArray<Color32>(px));
			val.Apply();
			Sprite obj = Sprite.Create(val, new Rect(0f, 0f, (float)n, (float)n), new Vector2(0.5f, 0.5f));
			((Object)obj).hideFlags = (HideFlags)32;
			return obj;
		}
	}
	internal static class Drift
	{
		private static int _driftingId;

		private static float _blend;

		private static bool _tickFailed;

		private static bool _loggedFirstDrift;

		public static void Reset()
		{
			_driftingId = 0;
			_blend = 0f;
		}

		public static bool IsDrifting(LandVehicle v)
		{
			if (_driftingId != 0 && (Object)(object)v != (Object)null)
			{
				return ((Object)v).GetInstanceID() == _driftingId;
			}
			return false;
		}

		public static void Tick(LandVehicle v)
		{
			try
			{
				SpeedBoost.Apply(v);
				Impacts.Record(v);
				CarControl.Tick(v);
				int instanceID = ((Object)v).GetInstanceID();
				bool localPlayerIsDriver = v.LocalPlayerIsDriver;
				bool flag = localPlayerIsDriver && DriftMod.DriftHeld && Mathf.Abs(v.Speed_Kmh) >= DriftMod.Cfg.MinDriftSpeed.Value;
				if (_driftingId != 0 && _driftingId != instanceID)
				{
					if (!flag)
					{
						return;
					}
					_blend = 0f;
				}
				if (!localPlayerIsDriver)
				{
					if (_driftingId == instanceID)
					{
						End(v);
					}
					return;
				}
				float value = DriftMod.Cfg.GripFadeTime.Value;
				float num = ((value <= 0.001f) ? 1f : (Time.fixedDeltaTime / value));
				_blend = Mathf.Clamp01(_blend + (flag ? num : (0f - num)));
				if (_blend <= 0f)
				{
					if (_driftingId == instanceID)
					{
						End(v);
					}
					return;
				}
				if (!_loggedFirstDrift)
				{
					_loggedFirstDrift = true;
					DriftMod.Log.Msg($"Drifting in {v.vehicleCode} ({v.wheels?.Count ?? 0} wheels). Only logged the first time.");
				}
				_driftingId = instanceID;
				List<Wheel> wheels = v.wheels;
				if (wheels != null)
				{
					for (int i = 0; i < wheels.Count; i++)
					{
						ApplyGrip(wheels[i]);
					}
				}
				if (flag)
				{
					if (DriftMod.Cfg.KeepPower.Value)
					{
						ReleaseHandbrake(v);
					}
					PushYaw(v);
				}
				Stabilize(v);
				_tickFailed = false;
			}
			catch (Exception ex)
			{
				if (!_tickFailed)
				{
					DriftMod.Log.Error("Drift tick failed (logged once until it works again): " + ex);
				}
				_tickFailed = true;
			}
		}

		public static void ApplyGrip(Wheel w)
		{
			//IL_0045: 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_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: 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)
			if ((Object)(object)w == (Object)null)
			{
				return;
			}
			WheelCollider wheelCollider = w.wheelCollider;
			if (!((Object)(object)wheelCollider == (Object)null))
			{
				float num = (w.IsSteerWheel ? DriftMod.Cfg.FrontGrip.Value : DriftMod.Cfg.RearGrip.Value);
				WheelFrictionCurve sidewaysFriction = wheelCollider.sidewaysFriction;
				((WheelFrictionCurve)(ref sidewaysFriction)).stiffness = w.defaultSidewaysStiffness * Mathf.Lerp(1f, num, _blend);
				wheelCollider.sidewaysFriction = sidewaysFriction;
				if (DriftMod.Cfg.KeepPower.Value)
				{
					WheelFrictionCurve forwardFriction = wheelCollider.forwardFriction;
					((WheelFrictionCurve)(ref forwardFriction)).stiffness = w.defaultForwardStiffness;
					wheelCollider.forwardFriction = forwardFriction;
				}
			}
		}

		private static void ReleaseHandbrake(LandVehicle v)
		{
			Il2CppReferenceArray<WheelCollider> handbrakeWheels = v.handbrakeWheels;
			if (handbrakeWheels == null)
			{
				return;
			}
			for (int i = 0; i < ((Il2CppArrayBase<WheelCollider>)(object)handbrakeWheels).Length; i++)
			{
				WheelCollider val = ((Il2CppArrayBase<WheelCollider>)(object)handbrakeWheels)[i];
				if ((Object)(object)val != (Object)null)
				{
					val.brakeTorque = 0f;
				}
			}
		}

		private static void PushYaw(LandVehicle v)
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: 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)
			float num = DriftMod.Cfg.YawAssist.Value * _blend;
			Rigidbody rb = v.Rb;
			if (num <= 0f || (Object)(object)rb == (Object)null || rb.isKinematic)
			{
				return;
			}
			Transform transform = ((Component)v).transform;
			if (!(Vector3.Dot(rb.velocity, transform.forward) < 0f))
			{
				float actualMaxSteeringAngle = v.ActualMaxSteeringAngle;
				if (!(actualMaxSteeringAngle <= 0.01f))
				{
					float num2 = Mathf.Clamp(v.CurrentSteerAngle / actualMaxSteeringAngle, -1f, 1f);
					float num3 = Mathf.Clamp01(Mathf.Abs(v.Speed_Kmh) / 40f);
					rb.AddTorque(transform.up * (num2 * num * num3), (ForceMode)5);
				}
			}
		}

		private static void Stabilize(LandVehicle v)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: 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_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: 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_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: 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_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: 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_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)
			Rigidbody rb = v.Rb;
			if ((Object)(object)rb == (Object)null || rb.isKinematic || !AnyWheelGrounded(v))
			{
				return;
			}
			Transform transform = ((Component)v).transform;
			Vector3 up = transform.up;
			Vector3 velocity = rb.velocity;
			Vector3 val = Vector3.ProjectOnPlane(velocity, up);
			if (((Vector3)(ref val)).sqrMagnitude < 9f)
			{
				return;
			}
			Vector3 val2 = Vector3.ProjectOnPlane(transform.forward, up);
			if (!(Vector3.Dot(val, val2) <= 0f))
			{
				float fixedDeltaTime = Time.fixedDeltaTime;
				float num = Vector3.SignedAngle(val2, val, up);
				float num2 = Mathf.Max(5f, DriftMod.Cfg.MaxSlipAngle.Value);
				float num3 = Mathf.MoveTowards(num, 0f, DriftMod.Cfg.DriftTraction.Value * _blend * fixedDeltaTime);
				num3 = Mathf.Clamp(num3, 0f - num2, num2);
				if (!Mathf.Approximately(num3, num))
				{
					rb.velocity = Quaternion.AngleAxis(num3 - num, up) * val + (velocity - val);
				}
				float num4 = Mathf.Clamp01(DriftMod.Cfg.YawDamping.Value * _blend * fixedDeltaTime);
				Vector3 angularVelocity = rb.angularVelocity;
				rb.angularVelocity = angularVelocity - up * (Vector3.Dot(angularVelocity, up) * num4);
			}
		}

		internal static bool AnyWheelGrounded(LandVehicle v)
		{
			List<Wheel> wheels = v.wheels;
			if (wheels == null)
			{
				return true;
			}
			for (int i = 0; i < wheels.Count; i++)
			{
				WheelCollider val = (((Object)(object)wheels[i] != (Object)null) ? wheels[i].wheelCollider : null);
				if ((Object)(object)val != (Object)null && val.isGrounded)
				{
					return true;
				}
			}
			return false;
		}

		private static void End(LandVehicle v)
		{
			_driftingId = 0;
			_blend = 0f;
			List<Wheel> wheels = v.wheels;
			if (wheels == null)
			{
				return;
			}
			for (int i = 0; i < wheels.Count; i++)
			{
				Wheel val = wheels[i];
				if ((Object)(object)val != (Object)null)
				{
					val.ApplyFriction();
				}
			}
		}
	}
	[HarmonyPatch(typeof(LandVehicle), "FixedUpdate")]
	internal static class LandVehicleFixedUpdatePatch
	{
		private static void Postfix(LandVehicle __instance)
		{
			Drift.Tick(__instance);
		}
	}
	[HarmonyPatch(typeof(Wheel), "ApplyFriction")]
	internal static class WheelApplyFrictionPatch
	{
		private static void Postfix(Wheel __instance)
		{
			if (Drift.IsDrifting(__instance.vehicle))
			{
				Drift.ApplyGrip(__instance);
			}
		}
	}
	internal class DriftConfig
	{
		private const int CurrentVersion = 7;

		public readonly MelonPreferences_Category Category;

		public readonly MelonPreferences_Entry<int> ConfigVersion;

		public readonly MelonPreferences_Entry<string> DriftKey;

		public readonly MelonPreferences_Entry<float> RearGrip;

		public readonly MelonPreferences_Entry<float> FrontGrip;

		public readonly MelonPreferences_Entry<float> GripFadeTime;

		public readonly MelonPreferences_Entry<bool> KeepPower;

		public readonly MelonPreferences_Entry<float> YawAssist;

		public readonly MelonPreferences_Entry<float> MinDriftSpeed;

		public readonly MelonPreferences_Entry<float> SpeedMultiplier;

		public readonly MelonPreferences_Entry<float> TorqueMultiplier;

		public readonly MelonPreferences_Entry<bool> KnockProps;

		public readonly MelonPreferences_Entry<float> KnockSpeedMultiplier;

		public readonly MelonPreferences_Entry<float> HydrantSeconds;

		public readonly MelonPreferences_Entry<bool> KnockPeople;

		public readonly MelonPreferences_Entry<float> PeopleMinSpeed;

		public readonly MelonPreferences_Entry<float> PeopleLaunch;

		public readonly MelonPreferences_Entry<float> DriftTraction;

		public readonly MelonPreferences_Entry<float> MaxSlipAngle;

		public readonly MelonPreferences_Entry<float> YawDamping;

		public readonly MelonPreferences_Entry<bool> AirControl;

		public readonly MelonPreferences_Entry<float> AirControlStrength;

		public readonly MelonPreferences_Entry<string> FlipKeyName;

		public readonly MelonPreferences_Entry<float> FlipHeight;

		public readonly MelonPreferences_Entry<string> NitroKeyName;

		public readonly MelonPreferences_Entry<float> NitroPower;

		public readonly MelonPreferences_Entry<float> NitroSeconds;

		public readonly MelonPreferences_Entry<float> NitroRechargeSeconds;

		public readonly MelonPreferences_Entry<float> NitroMaxSpeed;

		public readonly MelonPreferences_Entry<float> CarCrashLaunch;

		public readonly MelonPreferences_Entry<string> JumpKeyName;

		public readonly MelonPreferences_Entry<float> JumpStrength;

		public readonly MelonPreferences_Entry<bool> LogAir;

		public readonly MelonPreferences_Entry<bool> MapMarkers;

		public readonly MelonPreferences_Entry<bool> CompassMarkers;

		public readonly MelonPreferences_Entry<string> RotateLeftKeyName;

		public readonly MelonPreferences_Entry<string> RotateRightKeyName;

		public Key Key { get; private set; } = (Key)1;

		public Key FlipKey { get; private set; } = (Key)32;

		public Key NitroKey { get; private set; } = (Key)51;

		public Key JumpKey { get; private set; } = (Key)1;

		public Key RotateLeftKey { get; private set; } = (Key)31;

		public Key RotateRightKey { get; private set; } = (Key)19;

		public DriftConfig()
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: 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_0021: 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_0590: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_05db: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ee: Unknown result type (might be due to invalid IL or missing references)
			Category = MelonPreferences.CreateCategory("FroggosDrivingRevamped", "FroggosDrivingRevamped");
			ConfigVersion = Category.CreateEntry<int>("ConfigVersion", 0, (string)null, "Used to update old defaults. Don't change.", false, false, (ValueValidator)null, (string)null);
			DriftKey = Category.CreateEntry<string>("DriftKey", "Space", (string)null, "Hold this key while driving to drift (UnityEngine.InputSystem.Key name, e.g. Space, LeftShift).", false, false, (ValueValidator)null, (string)null);
			RearGrip = Category.CreateEntry<float>("RearGrip", 0.5f, (string)null, "Rear tire sideways grip while drifting, as a fraction of normal (lower = slidier).", false, false, (ValueValidator)null, (string)null);
			FrontGrip = Category.CreateEntry<float>("FrontGrip", 1f, (string)null, "Front tire sideways grip while drifting, as a fraction of normal. Keep high so you can still steer.", false, false, (ValueValidator)null, (string)null);
			GripFadeTime = Category.CreateEntry<float>("GripFadeTime", 0.35f, (string)null, "Seconds the grip takes to fade out when you press the key, and back in when you let go (0 = instant).", false, false, (ValueValidator)null, (string)null);
			KeepPower = Category.CreateEntry<bool>("KeepPower", true, (string)null, "Release the vanilla handbrake while drifting so the rear wheels keep driving instead of locking up.", false, false, (ValueValidator)null, (string)null);
			YawAssist = Category.CreateEntry<float>("YawAssist", 0.7f, (string)null, "Extra rotation pushed into the slide in the direction you steer (0 = none).", false, false, (ValueValidator)null, (string)null);
			MinDriftSpeed = Category.CreateEntry<float>("MinDriftSpeed", 20f, (string)null, "Below this speed (km/h) drifting does nothing.", false, false, (ValueValidator)null, (string)null);
			SpeedMultiplier = Category.CreateEntry<float>("SpeedMultiplier", 1.15f, (string)null, "Top speed multiplier for every car (1 = vanilla).", false, false, (ValueValidator)null, (string)null);
			TorqueMultiplier = Category.CreateEntry<float>("TorqueMultiplier", 1.15f, (string)null, "Engine power multiplier for every car (1 = vanilla).", false, false, (ValueValidator)null, (string)null);
			KnockProps = Category.CreateEntry<bool>("KnockProps", true, (string)null, "Cars knock over lamp posts, street/traffic lights, hydrants, mailboxes, benches and payphones, and send loose props flying.", false, false, (ValueValidator)null, (string)null);
			KnockSpeedMultiplier = Category.CreateEntry<float>("KnockSpeedMultiplier", 1f, (string)null, "Scales the speed needed to knock a prop over (0.5 = half the speed, 2 = twice).", false, false, (ValueValidator)null, (string)null);
			HydrantSeconds = Category.CreateEntry<float>("HydrantSeconds", 30f, (string)null, "How long a knocked-over fire hydrant sprays water.", false, false, (ValueValidator)null, (string)null);
			KnockPeople = Category.CreateEntry<bool>("KnockPeople", true, (string)null, "People hit by a car ragdoll and get thrown.", false, false, (ValueValidator)null, (string)null);
			PeopleMinSpeed = Category.CreateEntry<float>("PeopleMinSpeed", 10f, (string)null, "Speed (km/h) needed to knock a person over.", false, false, (ValueValidator)null, (string)null);
			PeopleLaunch = Category.CreateEntry<float>("PeopleLaunch", 0.8f, (string)null, "How much of the car's speed a person is thrown with.", false, false, (ValueValidator)null, (string)null);
			DriftTraction = Category.CreateEntry<float>("DriftTraction", 11f, (string)null, "How fast (degrees per second) a slide straightens itself out toward where the car points. Higher = more planted, lower = more ice.", false, false, (ValueValidator)null, (string)null);
			MaxSlipAngle = Category.CreateEntry<float>("MaxSlipAngle", 65f, (string)null, "Largest angle (degrees) the car can slide sideways while drifting, so it can't spin out.", false, false, (ValueValidator)null, (string)null);
			YawDamping = Category.CreateEntry<float>("YawDamping", 0.3f, (string)null, "Calms the car's spin while drifting (0 = none).", false, false, (ValueValidator)null, (string)null);
			AirControl = Category.CreateEntry<bool>("AirControl", true, (string)null, "GTA-style air control: while all wheels are off the ground, W/S tip the nose down/up and A/D roll left/right.", false, false, (ValueValidator)null, (string)null);
			AirControlStrength = Category.CreateEntry<float>("AirControlStrength", 8f, (string)null, "How fast air control spins the car up (rad/s per second).", false, false, (ValueValidator)null, (string)null);
			FlipKeyName = Category.CreateEntry<string>("FlipKey", "R", (string)null, "Press while driving to lift the car, set it upright and drop it back down after a second (unstuck / unflip).", false, false, (ValueValidator)null, (string)null);
			FlipHeight = Category.CreateEntry<float>("FlipHeight", 1.5f, (string)null, "How high (m) the flip lifts the car.", false, false, (ValueValidator)null, (string)null);
			NitroKeyName = Category.CreateEntry<string>("NitroKey", "LeftShift", (string)null, "Hold while driving for a nitro boost.", false, false, (ValueValidator)null, (string)null);
			NitroPower = Category.CreateEntry<float>("NitroPower", 12f, (string)null, "Nitro push (m/s²). 0 turns nitro off.", false, false, (ValueValidator)null, (string)null);
			NitroSeconds = Category.CreateEntry<float>("NitroSeconds", 4f, (string)null, "Seconds of nitro in a full tank.", false, false, (ValueValidator)null, (string)null);
			NitroRechargeSeconds = Category.CreateEntry<float>("NitroRechargeSeconds", 10f, (string)null, "Seconds to refill an empty nitro tank.", false, false, (ValueValidator)null, (string)null);
			NitroMaxSpeed = Category.CreateEntry<float>("NitroMaxSpeed", 220f, (string)null, "Nitro stops pushing above this speed (km/h).", false, false, (ValueValidator)null, (string)null);
			CarCrashLaunch = Category.CreateEntry<float>("CarCrashLaunch", 1f, (string)null, "How hard other cars get shoved when you ram them (0 = vanilla).", false, false, (ValueValidator)null, (string)null);
			JumpKeyName = Category.CreateEntry<string>("JumpKey", "Space", (string)null, "Double-tap this key while driving (with a wheel on the ground) to make the car jump. Space by default, so a single press/hold still drifts.", false, false, (ValueValidator)null, (string)null);
			JumpStrength = Category.CreateEntry<float>("JumpStrength", 7f, (string)null, "Jump launch speed (m/s). 7 is about 2.5 m high; 0 turns jumping off.", false, false, (ValueValidator)null, (string)null);
			MapMarkers = Category.CreateEntry<bool>("MapMarkers", true, (string)null, "Show your owned cars and bikes on the phone map, labelled with their names.", false, false, (ValueValidator)null, (string)null);
			CompassMarkers = Category.CreateEntry<bool>("CompassMarkers", true, (string)null, "Show your owned cars and bikes on the compass.", false, false, (ValueValidator)null, (string)null);
			RotateLeftKeyName = Category.CreateEntry<string>("RecallRotateLeftKey", "Q", (string)null, "While placing a recalled vehicle: hold to rotate the hologram left.", false, false, (ValueValidator)null, (string)null);
			RotateRightKeyName = Category.CreateEntry<string>("RecallRotateRightKey", "E", (string)null, "While placing a recalled vehicle: hold to rotate the hologram right.", false, false, (ValueValidator)null, (string)null);
			LogAir = Category.CreateEntry<bool>("LogAir", true, (string)null, "Log every jump (take-off, in-air state, landing) to the MelonLoader log.", false, false, (ValueValidator)null, (string)null);
			try
			{
				CopyFromOldName();
			}
			catch (Exception ex)
			{
				DriftMod.Log.Warning("Couldn't copy settings from the old [FroggosDrifting] section, using defaults: " + ex.Message);
			}
			MigrateDefaults();
			Key = ParseKey(DriftKey, (Key)1);
			FlipKey = ParseKey(FlipKeyName, (Key)32);
			NitroKey = ParseKey(NitroKeyName, (Key)51);
			JumpKey = ParseKey(JumpKeyName, (Key)1);
			RotateLeftKey = ParseKey(RotateLeftKeyName, (Key)31);
			RotateRightKey = ParseKey(RotateRightKeyName, (Key)19);
		}

		private static Key ParseKey(MelonPreferences_Entry<string> entry, Key fallback)
		{
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: 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)
			if (Enum.TryParse<Key>(entry.Value?.Trim(), ignoreCase: true, out Key result) && (int)result != 0)
			{
				return result;
			}
			DriftMod.Log.Warning($"{((MelonPreferences_Entry)entry).Identifier} '{entry.Value}' is not a valid key name, using {fallback}.");
			return fallback;
		}

		private void MigrateDefaults()
		{
			if (ConfigVersion.Value >= 7)
			{
				return;
			}
			if (ConfigVersion.Value < 2)
			{
				Upgrade(RearGrip, 0.35f);
				Upgrade(FrontGrip, 0.9f);
				Upgrade(YawAssist, 1.2f);
				Upgrade(MinDriftSpeed, 10f);
			}
			if (ConfigVersion.Value < 3)
			{
				Upgrade(PeopleMinSpeed, 12f);
			}
			if (ConfigVersion.Value < 4)
			{
				Upgrade(RearGrip, 0.55f);
				Upgrade(YawAssist, 0.4f);
			}
			if (ConfigVersion.Value < 5)
			{
				Upgrade(RearGrip, 0.7f);
				Upgrade(YawAssist, 0.35f);
				Upgrade(DriftTraction, 55f);
				Upgrade(MaxSlipAngle, 45f);
				Upgrade(YawDamping, 1.2f);
				Upgrade(AirControlStrength, 5f);
			}
			if (ConfigVersion.Value < 6)
			{
				Upgrade(RearGrip, 0.62f);
				Upgrade(YawAssist, 0.38f);
				Upgrade(DriftTraction, 30f);
				Upgrade(MaxSlipAngle, 55f);
				Upgrade(YawDamping, 0.6f);
			}
			if (ConfigVersion.Value < 7)
			{
				Upgrade(RearGrip, 0.55f);
				Upgrade(YawAssist, 0.6f);
				Upgrade(DriftTraction, 15f);
				if (string.Equals(JumpKeyName.Value?.Trim(), "J", StringComparison.OrdinalIgnoreCase))
				{
					JumpKeyName.Value = "Space";
				}
			}
			ConfigVersion.Value = 7;
			Category.SaveToFile(false);
		}

		private void CopyFromOldName()
		{
			if (ConfigVersion.Value != 0)
			{
				return;
			}
			MelonPreferences_Category old = MelonPreferences.CreateCategory("FroggosDrifting", "FroggosDrifting (old name, no longer used)");
			if (OldEntry(old, "ConfigVersion", 0).Value == 0)
			{
				return;
			}
			int num = 0;
			foreach (MelonPreferences_Entry entry in Category.Entries)
			{
				if (!(entry is MelonPreferences_Entry<float> val))
				{
					if (!(entry is MelonPreferences_Entry<int> val2))
					{
						if (!(entry is MelonPreferences_Entry<bool> val3))
						{
							if (entry is MelonPreferences_Entry<string> val4)
							{
								val4.Value = OldEntry(old, ((MelonPreferences_Entry)val4).Identifier, val4.DefaultValue).Value;
								num++;
							}
						}
						else
						{
							val3.Value = OldEntry(old, ((MelonPreferences_Entry)val3).Identifier, val3.DefaultValue).Value;
							num++;
						}
					}
					else
					{
						val2.Value = OldEntry(old, ((MelonPreferences_Entry)val2).Identifier, val2.DefaultValue).Value;
						num++;
					}
				}
				else
				{
					val.Value = OldEntry(old, ((MelonPreferences_Entry)val).Identifier, val.DefaultValue).Value;
					num++;
				}
			}
			Category.SaveToFile(false);
			DriftMod.Log.Msg($"Copied {num} setting(s) from the old [FroggosDrifting] section; that section isn't used anymore.");
		}

		private static MelonPreferences_Entry<T> OldEntry<T>(MelonPreferences_Category old, string id, T fallback)
		{
			return old.GetEntry<T>(id) ?? old.CreateEntry<T>(id, fallback, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		}

		private static void Upgrade(MelonPreferences_Entry<float> entry, float oldDefault)
		{
			if (Math.Abs(entry.Value - oldDefault) < 0.0001f)
			{
				entry.Value = entry.DefaultValue;
			}
		}
	}
	public class DriftMod : MelonMod
	{
		internal static Instance Log;

		internal static DriftConfig Cfg;

		internal static bool DriftHeld;

		public override void OnInitializeMelon()
		{
			//IL_003b: 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_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			Log = ((MelonBase)this).LoggerInstance;
			Cfg = new DriftConfig();
			Log.Msg($"FroggosDrivingRevamped loaded. Hold [{Cfg.Key}] while driving to drift. Cars are x{Cfg.SpeedMultiplier.Value:0.##} top speed, x{Cfg.TorqueMultiplier.Value:0.##} power. Knock over props: {(Cfg.KnockProps.Value ? "on" : "off")}, people: {(Cfg.KnockPeople.Value ? "on" : "off")}. Flip: [{Cfg.FlipKey}], jump: double-tap [{Cfg.JumpKey}], nitro: [{Cfg.NitroKey}], air control: {(Cfg.AirControl.Value ? "WASD" : "off")}.");
		}

		public override void OnLateInitializeMelon()
		{
			GtaBridge.Resolve();
		}

		public override void OnUpdate()
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				Keyboard current = Keyboard.current;
				DriftHeld = current != null && ((ButtonControl)current[Cfg.Key]).isPressed;
				CarControl.ReadInput();
			}
			catch
			{
				DriftHeld = false;
			}
			VehicleTracker.Update();
			VehiclePlacer.Update();
			try
			{
				VehicleTracker.UiTick?.Invoke();
			}
			catch (Exception ex)
			{
				Log.Warning("Vehicles app tick failed: " + ex.Message);
			}
		}

		public override void OnFixedUpdate()
		{
			Hydrant.FixedTick();
			People.FixedTick();
		}

		public override void OnLateUpdate()
		{
			Knockables.Draw();
			Hydrant.Draw();
			VehiclePlacer.Draw();
		}

		public override void OnSceneWasUnloaded(int buildIndex, string sceneName)
		{
			DriftHeld = false;
			Drift.Reset();
			SpeedBoost.Reset();
			Impacts.Reset();
			Knockables.Reset();
			Hydrant.Reset();
			People.Reset();
			CarControl.Reset();
			VehicleTracker.Reset();
			VehiclePlacer.Reset();
		}
	}
	internal static class GtaBridge
	{
		private static bool _resolved;

		private static FieldInfo _stolen;

		public static bool Installed { get; private set; }

		public static void Resolve()
		{
			if (_resolved)
			{
				return;
			}
			_resolved = true;
			try
			{
				Type type = null;
				Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
				foreach (Assembly assembly in assemblies)
				{
					if (!(assembly.GetName().Name != "FroggosGTA"))
					{
						type = assembly.GetType("FroggosGTA.Carjack", throwOnError: false);
						if (type != null)
						{
							break;
						}
					}
				}
				if (!(type == null))
				{
					_stolen = type.GetField("_stolen", BindingFlags.Static | BindingFlags.NonPublic);
					Installed = _stolen != null;
					DriftMod.Log.Msg(Installed ? "FroggosGTA found: stolen police cars get markers, can be recalled, and FroggosGTA handles their rams." : "FroggosGTA found, but its stolen-car list isn't where expected; stolen police cars are treated like any other car.");
				}
			}
			catch (Exception ex)
			{
				DriftMod.Log.Warning("Looking for FroggosGTA failed, acting as if it isn't installed: " + ex.Message);
				Installed = false;
			}
		}

		public static void AddStolen(List<LandVehicle> into)
		{
			if (!Installed)
			{
				return;
			}
			try
			{
				if (!(_stolen.GetValue(null) is IEnumerable enumerable))
				{
					return;
				}
				foreach (object item in enumerable)
				{
					LandVehicle v = (LandVehicle)((item is LandVehicle) ? item : null);
					if (v != null && (Object)(object)v != (Object)null && ((Component)v).gameObject.activeInHierarchy && !into.Exists((LandVehicle x) => ((Il2CppObjectBase)x).Pointer == ((Il2CppObjectBase)v).Pointer))
					{
						into.Add(v);
					}
				}
			}
			catch
			{
			}
		}

		public static bool IsStolen(LandVehicle v)
		{
			if (!Installed || (Object)(object)v == (Object)null)
			{
				return false;
			}
			try
			{
				if (!(_stolen.GetValue(null) is IEnumerable enumerable))
				{
					return false;
				}
				foreach (object item in enumerable)
				{
					LandVehicle val = (LandVehicle)((item is LandVehicle) ? item : null);
					if (val != null && (Object)(object)val != (Object)null && ((Il2CppObjectBase)val).Pointer == ((Il2CppObjectBase)v).Pointer)
					{
						return true;
					}
				}
			}
			catch
			{
			}
			return false;
		}
	}
	internal static class Hydrant
	{
		private struct Drop
		{
			public Vector3 Pos;

			public Vector3 Vel;

			public float Age;

			public float Life;

			public float Size;
		}

		private sealed class Jet
		{
			public Vector3 Base;

			public float EndTime;

			public float Carry;

			public readonly List<Drop> Drops = new List<Drop>();
		}

		private const float JetSpeed = 14f;

		private const float JetHeight = 7f;

		private const float JetRadius = 1f;

		private const float Lift = 22f;

		private const float MaxRise = 7f;

		private const float Rate = 120f;

		private const float Gravity = 9.81f;

		private static readonly List<Jet> Jets = new List<Jet>();

		private static Material _material;

		private static Mesh _quad;

		private static bool _materialMissing;

		private static bool _failed;

		private static readonly string[] ExtraMaps = new string[9] { "_BumpMap", "_NormalMap", "_EmissionMap", "_MetallicGlossMap", "_SpecGlossMap", "_OcclusionMap", "_DetailAlbedoMap", "_DetailNormalMap", "_DistortionMap" };

		private static readonly string[] ExtraKeywords = new string[9] { "_NORMALMAP", "_FLIPBOOKBLENDING_ON", "_EMISSION", "_DISTORTION_ON", "_SPECGLOSSMAP", "_SPECULAR_COLOR", "_METALLICSPECGLOSSMAP", "_DETAIL_MULX2", "_DETAIL_SCALED" };

		public static void Reset()
		{
			Jets.Clear();
			_material = null;
			_materialMissing = false;
		}

		public static void Spray(Vector3 basePos, float seconds)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			if (!(seconds <= 0f))
			{
				Jets.Add(new Jet
				{
					Base = basePos,
					EndTime = Time.time + seconds
				});
			}
		}

		public static void FixedTick()
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			if (Jets.Count == 0)
			{
				return;
			}
			try
			{
				float fixedDeltaTime = Time.fixedDeltaTime;
				for (int num = Jets.Count - 1; num >= 0; num--)
				{
					Jet jet = Jets[num];
					bool flag = Time.time < jet.EndTime;
					Step(jet, fixedDeltaTime, flag);
					if (flag)
					{
						PushUp(jet.Base);
					}
					else if (jet.Drops.Count == 0)
					{
						Jets.RemoveAt(num);
					}
				}
				_failed = false;
			}
			catch (Exception ex)
			{
				if (!_failed)
				{
					DriftMod.Log.Error("Hydrant tick failed (logged once until it works again): " + ex);
				}
				_failed = true;
			}
		}

		private static void Step(Jet j, float dt, bool emit)
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0085: 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_00a9: 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_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: 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)
			for (int num = j.Drops.Count - 1; num >= 0; num--)
			{
				Drop value = j.Drops[num];
				value.Age += dt;
				if (value.Age >= value.Life || value.Pos.y < j.Base.y - 0.2f)
				{
					j.Drops.RemoveAt(num);
				}
				else
				{
					value.Vel.y -= 9.81f * dt;
					ref Vector3 vel = ref value.Vel;
					vel *= 1f - 0.15f * dt;
					ref Vector3 pos = ref value.Pos;
					pos += value.Vel * dt;
					j.Drops[num] = value;
				}
			}
			if (emit)
			{
				j.Carry += 120f * dt;
				int num2 = (int)j.Carry;
				j.Carry -= num2;
				Vector3 pos2 = j.Base + Vector3.up * 0.6f;
				for (int i = 0; i < num2; i++)
				{
					Vector2 val = Random.insideUnitCircle * 0.1f;
					Vector3 val2 = new Vector3(val.x, 1f, val.y);
					Vector3 normalized = ((Vector3)(ref val2)).normalized;
					j.Drops.Add(new Drop
					{
						Pos = pos2,
						Vel = normalized * (14f * Random.Range(0.8f, 1f)),
						Life = Random.Range(1.6f, 2.2f),
						Size = Random.Range(0.35f, 0.7f)
					});
				}
			}
		}

		public static void Draw()
		{
			//IL_003d: 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_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_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			if (Jets.Count == 0)
			{
				return;
			}
			try
			{
				Camera main = Camera.main;
				Material val = WaterMaterial();
				if ((Object)(object)main == (Object)null || (Object)(object)val == (Object)null)
				{
					return;
				}
				Mesh val2 = Quad();
				Quaternion rotation = ((Component)main).transform.rotation;
				for (int i = 0; i < Jets.Count; i++)
				{
					List<Drop> drops = Jets[i].Drops;
					for (int j = 0; j < drops.Count; j++)
					{
						Drop drop = drops[j];
						float num = drop.Age / drop.Life;
						float num2 = drop.Size * Mathf.Lerp(0.6f, 2f, num);
						Matrix4x4 val3 = Matrix4x4.TRS(drop.Pos, rotation, new Vector3(num2, num2, num2));
						Graphics.DrawMesh(val2, val3, val, 0, (Camera)null, 0, (MaterialPropertyBlock)null, (ShadowCastingMode)0, false);
					}
				}
			}
			catch (Exception ex)
			{
				if (!_failed)
				{
					DriftMod.Log.Error("Drawing hydrant water failed (logged once until it works again): " + ex);
				}
				_failed = true;
			}
		}

		private static void PushUp(Vector3 basePos)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0092: 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_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			HashSet<int> hashSet = new HashSet<int>();
			for (int i = 0; i < 3; i++)
			{
				Il2CppReferenceArray<Collider> val = Physics.OverlapSphere(basePos + Vector3.up * (1f + (float)i * 6f / 2f), 1f + (float)i * 0.3f, -1, (QueryTriggerInteraction)1);
				for (int j = 0; j < ((Il2CppArrayBase<Collider>)(object)val).Length; j++)
				{
					Rigidbody val2 = (((Object)(object)((Il2CppArrayBase<Collider>)(object)val)[j] != (Object)null) ? ((Il2CppArrayBase<Collider>)(object)val)[j].attachedRigidbody : null);
					if (!((Object)(object)val2 == (Object)null) && !val2.isKinematic && hashSet.Add(((Object)val2).GetInstanceID()))
					{
						float num = Mathf.Clamp01((val2.worldCenterOfMass.y - basePos.y) / 7f);
						if (val2.velocity.y < 7f)
						{
							val2.AddForce(Vector3.up * (22f * (1.2f - num)), (ForceMode)5);
						}
					}
				}
			}
		}

		private static Mesh Quad()
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			//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_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: 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_00e6: 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_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_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: 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_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: 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_014b: 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)
			if ((Object)(object)_quad != (Object)null)
			{
				return _quad;
			}
			Color val = default(Color);
			((Color)(ref val))..ctor(0.8f, 0.9f, 1f, 0.8f);
			_quad = new Mesh();
			_quad.vertices = Il2CppStructArray<Vector3>.op_Implicit((Vector3[])(object)new Vector3[4]
			{
				new Vector3(-0.5f, -0.5f, 0f),
				new Vector3(0.5f, -0.5f, 0f),
				new Vector3(0.5f, 0.5f, 0f),
				new Vector3(-0.5f, 0.5f, 0f)
			});
			_quad.uv = Il2CppStructArray<Vector2>.op_Implicit((Vector2[])(object)new Vector2[4]
			{
				new Vector2(0f, 0f),
				new Vector2(1f, 0f),
				new Vector2(1f, 1f),
				new Vector2(0f, 1f)
			});
			_quad.colors = Il2CppStructArray<Color>.op_Implicit((Color[])(object)new Color[4] { val, val, val, val });
			_quad.triangles = Il2CppStructArray<int>.op_Implicit(new int[12]
			{
				0, 2, 1, 0, 3, 2, 0, 1, 2, 0,
				2, 3
			});
			_quad.RecalculateBounds();
			return _quad;
		}

		private static Texture2D DropTexture()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(64, 64, (TextureFormat)4, false)
			{
				name = "FroggosDrivingRevamped Water Drop"
			};
			((Texture)val).wrapMode = (TextureWrapMode)1;
			((Texture)val).filterMode = (FilterMode)1;
			Color32[] array = (Color32[])(object)new Color32[4096];
			float num = 31.5f;
			for (int i = 0; i < 64; i++)
			{
				for (int j = 0; j < 64; j++)
				{
					float num2 = ((float)j - num) / num;
					float num3 = ((float)i - num) / num;
					float num4 = Mathf.Sqrt(num2 * num2 + num3 * num3);
					float num5 = Mathf.Clamp01(1f - num4);
					num5 = num5 * num5 * (3f - 2f * num5);
					array[i * 64 + j] = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, (byte)(num5 * 255f));
				}
			}
			val.SetPixels32(Il2CppStructArray<Color32>.op_Implicit(array));
			val.Apply(false, false);
			return val;
		}

		private static Material WaterMaterial()
		{
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Expected O, but got Unknown
			//IL_0264: Unknown result type (might be due to invalid IL or missing references)
			//IL_0216: Unknown result type (might be due to invalid IL or missing references)
			//IL_0286: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_material != (Object)null || _materialMissing)
			{
				return _material;
			}
			Material val = null;
			Il2CppArrayBase<LandVehicle> val2 = Object.FindObjectsOfType<LandVehicle>();
			for (int i = 0; i < val2.Length; i++)
			{
				if (!((Object)(object)val == (Object)null))
				{
					break;
				}
				List<Wheel> wheels = val2[i].wheels;
				if (wheels == null)
				{
					continue;
				}
				for (int j = 0; j < wheels.Count; j++)
				{
					if (!((Object)(object)val == (Object)null))
					{
						break;
					}
					ParticleSystem val3 = (((Object)(object)wheels[j] != (Object)null) ? wheels[j].DriftParticles : null);
					ParticleSystemRenderer val4 = (((Object)(object)val3 != (Object)null) ? ((Component)val3).GetComponent<ParticleSystemRenderer>() : null);
					if ((Object)(object)val4 != (Object)null && (Object)(object)((Renderer)val4).sharedMaterial != (Object)null)
					{
						val = ((Renderer)val4).sharedMaterial;
					}
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				_materialMissing = true;
				DriftMod.Log.Warning("No tire smoke material found, hydrant water won't be drawn (the jet still lifts things).");
				return null;
			}
			_material = new Material(val)
			{
				name = "FroggosDrivingRevamped Hydrant Water"
			};
			List<string> list = new List<string>();
			string[] extraMaps = ExtraMaps;
			foreach (string text in extraMaps)
			{
				if (_material.HasProperty(text))
				{
					if ((Object)(object)_material.GetTexture(text) != (Object)null)
					{
						list.Add(text);
					}
					_material.SetTexture(text, (Texture)null);
				}
			}
			extraMaps = ExtraKeywords;
			foreach (string text2 in extraMaps)
			{
				_material.DisableKeyword(text2);
			}
			Texture2D val5 = DropTexture();
			extraMaps = new string[2] { "_BaseMap", "_MainTex" };
			foreach (string text3 in extraMaps)
			{
				if (_material.HasProperty(text3))
				{
					_material.SetTexture(text3, (Texture)(object)val5);
					if (_material.HasProperty(text3 + "_ST"))
					{
						_material.SetVector(text3 + "_ST", new Vector4(1f, 1f, 0f, 0f));
					}
				}
			}
			Color val6 = default(Color);
			((Color)(ref val6))..ctor(0.75f, 0.88f, 1f, 0.6f);
			if (_material.HasProperty("_BaseColor"))
			{
				_material.SetColor("_BaseColor", val6);
			}
			if (_material.HasProperty("_Color"))
			{
				_material.SetColor("_Color", val6);
			}
			string text4 = string.Join(" ", Il2CppArrayBase<string>.op_Implicit((Il2CppArrayBase<string>)(object)_material.shaderKeywords));
			DriftMod.Log.Msg($"Hydrant water uses a copy of '{((Object)val).name}' ({(((Object)(object)val.shader != (Object)null) ? ((Object)val.shader).name : "no shader")}); removed maps: {((list.Count > 0) ? string.Join(", ", list) : "none")}; keywords left: {((text4.Length > 0) ? text4 : "none")}.");
			return _material;
		}
	}
	internal static class Impacts
	{
		private struct Motion
		{
			public Vector3 Velocity;

			public Vector3 AngularVelocity;
		}

		private static readonly Dictionary<int, Motion> Before = new Dictionary<int, Motion>();

		private static bool _failed;

		public static void Reset()
		{
			Before.Clear();
		}

		public static void Record(LandVehicle v)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			Rigidbody rb = v.Rb;
			if (!((Object)(object)rb == (Object)null) && !rb.isKinematic)
			{
				Before[((Object)v).GetInstanceID()] = new Motion
				{
					Velocity = rb.velocity,
					AngularVelocity = rb.angularVelocity
				};
			}
		}

		public static void OnHit(LandVehicle v, Collision collision)
		{
			//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_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				Rigidbody rb = v.Rb;
				Collider collider = collision.collider;
				if ((Object)(object)rb == (Object)null || rb.isKinematic || (Object)(object)collider == (Object)null || !Before.TryGetValue(((Object)v).GetInstanceID(), out var value))
				{
					return;
				}
				Vector3 velocity = value.Velocity;
				float num = ((Vector3)(ref velocity)).magnitude * 3.6f;
				if (!(num < 5f))
				{
					Vector3 point = NearestOnBounds(collider.bounds, rb.worldCenterOfMass);
					bool flag = GtaBridge.IsStolen(v);
					if ((!flag && DriftMod.Cfg.KnockPeople.Value && TryPerson(collider, velocity, point, out var keep)) || (!flag && v.LocalPlayerIsDriver && TryCar(v, rb, collider, velocity, point, out keep)) || (DriftMod.Cfg.KnockProps.Value && Knockables.TryKnock(collider, velocity, point, num, out keep)) || (DriftMod.Cfg.KnockProps.Value && TryLooseProp(collider, rb, velocity, out keep)))
					{
						rb.velocity = velocity * keep;
						rb.angularVelocity = value.AngularVelocity;
						_failed = false;
					}
				}
			}
			catch (Exception ex)
			{
				if (!_failed)
				{
					DriftMod.Log.Error("Handling a car impact failed (logged once until it works again): " + ex);
				}
				_failed = true;
			}
		}

		private static Vector3 NearestOnBounds(Bounds b, Vector3 p)
		{
			//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_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: 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)
			Vector3 min = ((Bounds)(ref b)).min;
			Vector3 max = ((Bounds)(ref b)).max;
			return new Vector3(Mathf.Clamp(p.x, min.x, max.x), Mathf.Clamp(p.y, min.y, max.y), Mathf.Clamp(p.z, min.z, max.z));
		}

		private static bool TryPerson(Collider other, Vector3 carVel, Vector3 point, out float keep)
		{
			//IL_003a: 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)
			keep = 1f;
			NPC componentInParent = ((Component)other).GetComponentInParent<NPC>();
			if ((Object)(object)componentInParent == (Object)null)
			{
				return false;
			}
			if (((Vector3)(ref carVel)).magnitude * 3.6f < DriftMod.Cfg.PeopleMinSpeed.Value)
			{
				return false;
			}
			if (!People.Knock(componentInParent, carVel, point))
			{
				return false;
			}
			keep = 0.95f;
			return true;
		}

		private static bool TryCar(LandVehicle v, Rigidbody carRb, Collider other, Vector3 carVel, Vector3 point, out float keep)
		{
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: 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_00e4: Unknown result type (might be due to invalid IL or missing references)
			keep = 1f;
			float value = DriftMod.Cfg.CarCrashLaunch.Value;
			if (value <= 0f)
			{
				return false;
			}
			LandVehicle componentInParent = ((Component)other).GetComponentInParent<LandVehicle>();
			if ((Object)(object)componentInParent == (Object)null || (Object)(object)componentInParent == (Object)(object)v)
			{
				return false;
			}
			Rigidbody rb = componentInParent.Rb;
			if ((Object)(object)rb == (Object)null || rb.isKinematic)
			{
				return false;
			}
			float num = ((Vector3)(ref carVel)).magnitude * 3.6f;
			if (num < 15f)
			{
				return false;
			}
			Vector3 val = carVel - rb.velocity;
			float num2 = Mathf.Clamp(carRb.mass / Mathf.Max(1f, rb.mass), 0.5f, 2f);
			Vector3 val2 = val * (0.6f * num2 * value) + Vector3.up * Mathf.Min(4f, num * 0.04f * value);
			rb.AddForceAtPosition(val2 * rb.mass, point, (ForceMode)1);
			keep = Mathf.Clamp(1f - 0.35f / num2, 0.6f, 0.9f);
			return true;
		}

		private static bool TryLooseProp(Collider other, Rigidbody carRb, Vector3 carVel, out float keep)
		{
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: 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_00ce: 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_00b7: Unknown result type (might be due to invalid IL or missing references)
			keep = 1f;
			Rigidbody attachedRigidbody = other.attachedRigidbody;
			if ((Object)(object)attachedRigidbody == (Object)null || (Object)(object)attachedRigidbody == (Object)(object)carRb || attachedRigidbody.isKinematic || attachedRigidbody.mass > 200f)
			{
				return false;
			}
			if ((Object)(object)((Component)other).GetComponentInParent<LandVehicle>() != (Object)null)
			{
				return false;
			}
			if (((Vector3)(ref carVel)).magnitude * 3.6f < 10f * DriftMod.Cfg.KnockSpeedMultiplier.Value)
			{
				return false;
			}
			Vector3 velocity = carVel * 1.15f + Vector3.up * Mathf.Min(4f, ((Vector3)(ref carVel)).magnitude * 0.2f);
			Vector3 velocity2 = attachedRigidbody.velocity;
			if (((Vector3)(ref velocity2)).sqrMagnitude < ((Vector3)(ref velocity)).sqrMagnitude)
			{
				attachedRigidbody.velocity = velocity;
			}
			attachedRigidbody.angularVelocity += Random.insideUnitSphere * 6f;
			keep = 1f - Mathf.Clamp(attachedRigidbody.mass / 2000f, 0.01f, 0.1f);
			return true;
		}
	}
	[HarmonyPatch(typeof(LandVehicle), "OnCollisionEnter")]
	internal static class LandVehicleCollisionPatch
	{
		private static void Postfix(LandVehicle __instance, Collision collision)
		{
			Impacts.OnHit(__instance, collision);
		}
	}
	internal static class Knockables
	{
		private sealed class Kind
		{
			public string Name;

			public float Mass;

			public float MinKmh;

			public float CarKeep;

			public float Topple;

			public bool Hydrant;

			public bool OwnBody;
		}

		private sealed class Piece
		{
			public Transform T;

			public Mesh Mesh;

			public int FirstSubMesh;

			public Material[] Materials;

			public Matrix4x4 WorldToLocalAtKnock;

			public int Layer;

			public ShadowCastingMode Shadows;
		}

		private sealed class Knocked
		{
			public Transform Root;

			public readonly List<Piece> Pieces = new List<Piece>();
		}

		private static readonly Kind[] Kinds = new Kind[37]
		{
			new Kind
			{
				Name = "StreetLight",
				Mass = 160f,
				MinKmh = 15f,
				CarKeep = 0.85f,
				Topple = 2.2f
			},
			new Kind
			{
				Name = "Lamp post",
				Mass = 120f,
				MinKmh = 12f,
				CarKeep = 0.88f,
				Topple = 2.4f
			},
			new Kind
			{
				Name = "TrafficLightTower",
				Mass = 300f,
				MinKmh = 15f,
				CarKeep = 0.78f,
				Topple = 1.6f
			},
			new Kind
			{
				Name = "TrafficLightTower_DoubleArm",
				Mass = 380f,
				MinKmh = 15f,
				CarKeep = 0.75f,
				Topple = 1.4f
			},
			new Kind
			{
				Name = "Fire hydrant",
				Mass = 70f,
				MinKmh = 12f,
				CarKeep = 0.9f,
				Topple = 4f,
				Hydrant = true
			},
			new Kind
			{
				Name = "Mailbox",
				Mass = 25f,
				MinKmh = 10f,
				CarKeep = 0.97f,
				Topple = 5f
			},
			new Kind
			{
				Name = "OutdoorBench",
				Mass = 60f,
				MinKmh = 10f,
				CarKeep = 0.93f,
				Topple = 3f
			},
			new Kind
			{
				Name = "PayPhone",
				Mass = 90f,
				MinKmh = 12f,
				CarKeep = 0.9f,
				Topple = 3f
			},
			new Kind
			{
				Name = "Rubbish bin",
				Mass = 30f,
				MinKmh = 10f,
				CarKeep = 0.96f,
				Topple = 4f
			},
			new Kind
			{
				Name = "WoodPlanter",
				Mass = 80f,
				MinKmh = 12f,
				CarKeep = 0.9f,
				Topple = 3f
			},
			new Kind
			{
				Name = "VMS Board",
				Mass = 250f,
				MinKmh = 15f,
				CarKeep = 0.8f,
				Topple = 1.8f
			},
			new Kind
			{
				Name = "WoodFence",
				Mass = 40f,
				MinKmh = 10f,
				CarKeep = 0.95f,
				Topple = 3f
			},
			new Kind
			{
				Name = "Fence1",
				Mass = 30f,
				MinKmh = 10f,
				CarKeep = 0.96f,
				Topple = 3f
			},
			new Kind
			{
				Name = "Fence2",
				Mass = 30f,
				MinKmh = 10f,
				CarKeep = 0.96f,
				Topple = 3f
			},
			new Kind
			{
				Name = "ChainLinkFence_2m",
				Mass = 50f,
				MinKmh = 10f,
				CarKeep = 0.93f,
				Topple = 2.5f
			},
			new Kind
			{
				Name = "OutdoorFence",
				Mass = 45f,
				MinKmh = 10f,
				CarKeep = 0.94f,
				Topple = 3f
			},
			new Kind
			{
				Name = "ChainLinkFence_4m",
				Mass = 80f,
				MinKmh = 12f,
				CarKeep = 0.9f,
				Topple = 2f
			},
			new Kind
			{
				Name = "Road safety barrier",
				Mass = 40f,
				MinKmh = 10f,
				CarKeep = 0.95f,
				Topple = 3f
			},
			new Kind
			{
				Name = "Outdoor chair",
				Mass = 10f,
				MinKmh = 10f,
				CarKeep = 0.99f,
				Topple = 6f
			},
			new Kind
			{
				Name = "Round Outdoor Table",
				Mass = 25f,
				MinKmh = 10f,
				CarKeep = 0.97f,
				Topple = 4f
			},
			new Kind
			{
				Name = "Shrub",
				Mass = 20f,
				MinKmh = 10f,
				CarKeep = 0.97f,
				Topple = 3f
			},
			new Kind
			{
				Name = "Shrub with base",
				Mass = 35f,
				MinKmh = 10f,
				CarKeep = 0.95f,
				Topple = 3f
			},
			new Kind
			{
				Name = "Dumpster",
				Mass = 300f,
				MinKmh = 15f,
				CarKeep = 0.78f,
				Topple = 1f
			},
			new Kind
			{
				Name = "Bollard_Black",
				Mass = 60f,
				MinKmh = 12f,
				CarKeep = 0.9f,
				Topple = 3f
			},
			new Kind
			{
				Name = "Bollard_Yellow",
				Mass = 60f,
				MinKmh = 12f,
				CarKeep = 0.9f,
				Topple = 3f
			},
			new Kind
			{
				Name = "Bus Stop",
				Mass = 350f,
				MinKmh = 15f,
				CarKeep = 0.75f,
				Topple = 1.2f
			},
			new Kind
			{
				Name = "Mooring Bollard",
				Mass = 150f,
				MinKmh = 15f,
				CarKeep = 0.85f,
				Topple = 2f
			},
			new Kind
			{
				Name = "Trash Can Prop",
				OwnBody = true,
				MinKmh = 10f,
				CarKeep = 0.97f,
				Topple = 5f
			},
			new Kind
			{
				Name = "Wood Crate Prop",
				OwnBody = true,
				MinKmh = 10f,
				CarKeep = 0.96f,
				Topple = 4f
			},
			new Kind
			{
				Name = "Traffic cone Prop",
				OwnBody = true,
				MinKmh = 10f,
				CarKeep = 0.99f,
				Topple = 6f
			},
			new Kind
			{
				Name = "Post box Prop",
				OwnBody = true,
				MinKmh = 10f,
				CarKeep = 0.95f,
				Topple = 4f
			},
			new Kind
			{
				Name = "Gas Bottle Prop",
				OwnBody = true,
				MinKmh = 10f,
				CarKeep = 0.98f,
				Topple = 5f
			},
			new Kind
			{
				Name = "Liquid Drum Prop",
				OwnBody = true,
				MinKmh = 10f,
				CarKeep = 0.95f,
				Topple = 4f
			},
			new Kind
			{
				Name = "Pallet Prop",
				OwnBody = true,
				MinKmh = 10f,
				CarKeep = 0.97f,
				Topple = 4f
			},
			new Kind
			{
				Name = "Wheelchair Prop",
				OwnBody = true,
				MinKmh = 10f,
				CarKeep = 0.98f,
				Topple = 5f
			},
			new Kind
			{
				Name = "Vending Machine",
				OwnBody = true,
				MinKmh = 15f,
				CarKeep = 0.85f,
				Topple = 2f
			},
			new Kind
			{
				Name = "ATM",
				OwnBody = true,
				MinKmh = 15f,
				CarKeep = 0.85f,
				Topple = 2f
			}
		};

		private static readonly Regex CopySuffix = new Regex("(\\s*\\(\\d+\\)|\\.\\d+|\\d+)$", RegexOptions.Compiled);

		private static readonly Dictionary<int, Transform> RootOf = new Dictionary<int, Transform>();

		private static readonly Dictionary<int, Kind> KindOf = new Dictionary<int, Kind>();

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

		private static readonly Dictionary<int, bool> FallCache = new Dictionary<int, bool>();

		private static readonly List<Knocked> Drawn = new List<Knocked>();

		private static bool _drawFailed;

		public static void Reset()
		{
			RootOf.Clear();
			KindOf.Clear();
			KnockedRoots.Clear();
			FallCache.Clear();
			Drawn.Clear();
		}

		public static bool TryKnock(Collider col, Vector3 carVel, Vector3 point, float kmh, out float carKeep)
		{
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: 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_0084: Unknown result type (might be due to invalid IL or missing references)
			carKeep = 1f;
			Kind kind;
			Transform val = Classify(col, out kind);
			if ((Object)(object)val == (Object)null || KnockedRoots.Contains(((Object)val).GetInstanceID()))
			{
				return false;
			}
			if (kmh < kind.MinKmh * DriftMod.Cfg.KnockSpeedMultiplier.Value)
			{
				return false;
			}
			if (!kind.OwnBody && !CanFall(val))
			{
				return false;
			}
			KnockedRoots.Add(((Object)val).GetInstanceID());
			Vector3 position = val.position;
			Knock(val, kind, carVel, point);
			if (kind.Hydrant)
			{
				Hydrant.Spray(position, DriftMod.Cfg.HydrantSeconds.Value);
			}
			DriftMod.Log.Msg($"Knocked over {((Object)val).name} at {kmh:0} km/h.");
			carKeep = kind.CarKeep;
			return true;
		}

		private static Transform Classify(Collider col, out Kind kind)
		{
			int instanceID = ((Object)col).GetInstanceID();
			if (RootOf.TryGetValue(instanceID, out var value))
			{
				kind = (((Object)(object)value != (Object)null) ? KindOf[((Object)value).GetInstanceID()] : null);
				return value;
			}
			kind = null;
			Transform val = null;
			Rigidbody attachedRigidbody = col.attachedRigidbody;
			if ((Object)(object)attachedRigidbody != (Object)null && !col.isTrigger)
			{
				Kind kind2 = Match(((Object)attachedRigidbody).name);
				if (kind2 != null && kind2.OwnBody)
				{
					kind = kind2;
					val = ((Component)attachedRigidbody).transform;
				}
			}
			else if ((Object)(object)attachedRigidbody == (Object)null && !col.isTrigger)
			{
				Transform val2 = ((Component)col).transform;
				int num = 0;
				while ((Object)(object)val2 != (Object)null && num < 6)
				{
					kind = Match(((Object)val2).name);
					if (kind != null && !kind.OwnBody)
					{
						val = val2;
						break;
					}
					kind = null;
					num++;
					val2 = val2.parent;
				}
			}
			RootOf[instanceID] = val;
			if ((Object)(object)val != (Object)null)
			{
				KindOf[((Object)val).GetInstanceID()] = kind;
			}
			return val;
		}

		private static Kind Match(string name)
		{
			if (string.IsNullOrEmpty(name))
			{
				return null;
			}
			string text = CopySuffix.Replace(name, "");
			for (int i = 0; i < Kinds.Length; i++)
			{
				if (Kinds[i].Name == name || Kinds[i].Name == text)
				{
					return Kinds[i];
				}
			}
			return null;
		}

		private static void Knock(Transform root, Kind kind, Vector3 carVel, Vector3 point)
		{
			//IL_00e9: U