Decompiled source of FroggosGTA v1.0.0

Mods/FroggosGTA.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using FroggosGTA;
using HarmonyLib;
using Il2CppFishNet.Connection;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppScheduleOne;
using Il2CppScheduleOne.DevUtilities;
using Il2CppScheduleOne.Equipping;
using Il2CppScheduleOne.GameTime;
using Il2CppScheduleOne.ItemFramework;
using Il2CppScheduleOne.Law;
using Il2CppScheduleOne.Lighting;
using Il2CppScheduleOne.Map;
using Il2CppScheduleOne.NPCs;
using Il2CppScheduleOne.NPCs.Behaviour;
using Il2CppScheduleOne.PlayerScripts;
using Il2CppScheduleOne.Police;
using Il2CppScheduleOne.UI;
using Il2CppScheduleOne.Vehicles;
using Il2CppScheduleOne.Vision;
using Il2CppSystem.Collections.Generic;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(GtaMod), "FroggosGTA", "1.0.0", "froggonater", null)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("FroggosGTA")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("FroggosGTA")]
[assembly: AssemblyTitle("FroggosGTA")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace FroggosGTA
{
	internal static class Carjack
	{
		private const float AbandonedProtectSeconds = 300f;

		private const float DeathScanInterval = 0.5f;

		private const float DeathScanRange = 120f;

		private static readonly HashSet<IntPtr> _direct = new HashSet<IntPtr>();

		private static readonly Dictionary<IntPtr, float> _abandonedUntil = new Dictionary<IntPtr, float>();

		private static readonly HashSet<IntPtr> _handled = new HashSet<IntPtr>();

		private static readonly List<LandVehicle> _stolen = new List<LandVehicle>();

		internal static bool Busy;

		private static LandVehicle _directRide;

		private static float _directRideSince;

		private static float _nextDeathScan;

		private static bool _resetPending;

		private static bool _cleanedOnLoad;

		private static int _lastDay = -1;

		private static GtaConfig Cfg => GtaMod.Cfg;

		private static VehicleManager Manager
		{
			get
			{
				if (!NetworkSingleton<VehicleManager>.InstanceExists)
				{
					return null;
				}
				return NetworkSingleton<VehicleManager>.Instance;
			}
		}

		internal static void Reset()
		{
			_direct.Clear();
			_abandonedUntil.Clear();
			_handled.Clear();
			_stolen.Clear();
			_directRide = null;
			_resetPending = false;
			_cleanedOnLoad = false;
			_lastDay = -1;
		}

		internal static void Tick()
		{
			//IL_00fe: 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_011d: Invalid comparison between Unknown and I4
			Player local = Player.Local;
			if ((Object)(object)local == (Object)null)
			{
				return;
			}
			VehicleManager manager = Manager;
			if ((Object)(object)manager == (Object)null)
			{
				return;
			}
			if (!_cleanedOnLoad)
			{
				_cleanedOnLoad = true;
				RemoveOwnedPoliceCars(manager, "loaded save");
			}
			if (NetworkSingleton<TimeManager>.InstanceExists)
			{
				int elapsedDays = NetworkSingleton<TimeManager>.Instance.ElapsedDays;
				if (_lastDay >= 0 && elapsedDays != _lastDay)
				{
					OnNewDay();
				}
				_lastDay = elapsedDays;
			}
			if ((Object)(object)_directRide != (Object)null && !local.IsInVehicle && Time.time - _directRideSince > 1.5f)
			{
				try
				{
					_directRide.IsPlayerOwned = false;
				}
				catch
				{
				}
				_directRide = null;
			}
			if (_resetPending && !local.IsInVehicle)
			{
				ReturnStolenCars("new day");
			}
			if (Cfg.ReplaceOnDriverDeath.Value && Time.time >= _nextDeathScan)
			{
				_nextDeathScan = Time.time + 0.5f;
				ScanForDeadDrivers(manager, local);
			}
			Keyboard current = Keyboard.current;
			if (current != null && ((ButtonControl)current[Cfg.StealKey]).wasPressedThisFrame && !local.IsInVehicle && (int)Cursor.lockState == 1)
			{
				TrySteal(local, manager);
			}
		}

		internal static bool IsProtected(LandVehicle v)
		{
			if ((Object)(object)v == (Object)null)
			{
				return false;
			}
			IntPtr pointer = ((Il2CppObjectBase)v).Pointer;
			if (_direct.Contains(pointer))
			{
				return true;
			}
			if (_abandonedUntil.TryGetValue(pointer, out var value))
			{
				return Time.time < value;
			}
			return false;
		}

		internal static bool AllowNpcEnter(LandVehicle v)
		{
			return !IsProtected(v);
		}

		internal static void OnNewDay()
		{
			Player local = Player.Local;
			if ((Object)(object)local != (Object)null && local.IsInVehicle && (Object)(object)_directRide != (Object)null)
			{
				_resetPending = true;
				GtaMod.Log.Msg("New day: your police car goes back to the station once you get out.");
			}
			else
			{
				ReturnStolenCars("new day");
			}
		}

		internal static void OnSleep()
		{
			ReturnStolenCars("sleep");
		}

		private static void ReturnStolenCars(string why)
		{
			_resetPending = false;
			int num = 0;
			foreach (LandVehicle item in _stolen)
			{
				if ((Object)(object)item != (Object)null && SendHome(item))
				{
					num++;
				}
			}
			_stolen.Clear();
			_handled.Clear();
			VehicleManager manager = Manager;
			if ((Object)(object)manager != (Object)null)
			{
				RemoveOwnedPoliceCars(manager, why);
			}
			if (num > 0)
			{
				GtaMod.Log.Msg($"{num} stolen police car(s) went back to the station ({why}).");
			}
		}

		private static bool SendHome(LandVehicle v)
		{
			//IL_00aa: 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_011f: Unknown result type (might be due to invalid IL or missing references)
			IntPtr pointer = ((Il2CppObjectBase)v).Pointer;
			_direct.Remove(pointer);
			_abandonedUntil.Remove(pointer);
			if ((Object)(object)_directRide != (Object)null && ((Il2CppObjectBase)_directRide).Pointer == pointer)
			{
				_directRide = null;
			}
			try
			{
				v.IsPlayerOwned = false;
			}
			catch
			{
			}
			if ((Object)(object)v.Agent != (Object)null)
			{
				((Behaviour)v.Agent).enabled = true;
			}
			if ((Object)(object)v.Rb != (Object)null)
			{
				v.Rb.velocity = Vector3.zero;
				v.Rb.angularVelocity = Vector3.zero;
			}
			PoliceLight componentInChildren = ((Component)v).GetComponentInChildren<PoliceLight>(true);
			if ((Object)(object)componentInChildren != (Object)null && componentInChildren.IsOn)
			{
				componentInChildren.SetIsOn(false);
			}
			if (!((Component)v).gameObject.activeSelf)
			{
				return false;
			}
			PoliceStation val = OwningStation(v);
			PoliceStation station = val ?? PoliceStation.GetClosestPoliceStation(((Component)v).transform.position);
			if ((Object)(object)station == (Object)null)
			{
				return false;
			}
			if ((Object)(object)val != (Object)null)
			{
				try
				{
					station.ReturnVehicle(v);
				}
				catch (Exception ex)
				{
					GtaMod.Verbose("ReturnVehicle: " + ex.Message);
				}
			}
			GtaMod.Later(0.2f, "park police car", delegate
			{
				if ((Object)(object)v != (Object)null && ((Component)v).gameObject.activeSelf && !v.isParked)
				{
					ParkInLot(v, station);
				}
			});
			return true;
		}

		private static void ParkInLot(LandVehicle v, PoliceStation station)
		{
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Expected O, but got Unknown
			//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_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_005f: Unknown result type (might be due to invalid IL or missing references)
			ParkingLot policeVehicleParkingLot = station.PoliceVehicleParkingLot;
			if (!((Object)(object)policeVehicleParkingLot == (Object)null))
			{
				int randomFreeSpotIndex = policeVehicleParkingLot.GetRandomFreeSpotIndex();
				if (randomFreeSpotIndex < 0)
				{
					GtaMod.Verbose("Station lot is full, putting the police car at its entrance.");
					Transform val = (((Object)(object)policeVehicleParkingLot.EntryPoint != (Object)null) ? policeVehicleParkingLot.EntryPoint : ((Component)station).transform);
					v.SetTransform(val.position + Vector3.up * 0.3f, val.rotation);
				}
				else
				{
					ParkingSpot val2 = policeVehicleParkingLot.ParkingSpots[randomFreeSpotIndex];
					v.Park((NetworkConnection)null, new ParkData(policeVehicleParkingLot.GUID, randomFreeSpotIndex, val2.Alignment), true);
				}
			}
		}

		private static PoliceStation OwningStation(LandVehicle v)
		{
			List<PoliceStation> policeStations = PoliceStation.PoliceStations;
			if (policeStations == null)
			{
				return null;
			}
			for (int i = 0; i < policeStations.Count; i++)
			{
				PoliceStation val = policeStations[i];
				if ((Object)(object)val == (Object)null || val.PoliceVehicles == null)
				{
					continue;
				}
				foreach (LandVehicle item in (Il2CppArrayBase<LandVehicle>)(object)val.PoliceVehicles)
				{
					if ((Object)(object)item != (Object)null && ((Il2CppObjectBase)item).Pointer == ((Il2CppObjectBase)v).Pointer)
					{
						return val;
					}
				}
			}
			return null;
		}

		private static void RemoveOwnedPoliceCars(VehicleManager vm, string why)
		{
			List<LandVehicle> playerOwnedVehicles = vm.PlayerOwnedVehicles;
			if (playerOwnedVehicles == null)
			{
				return;
			}
			List<LandVehicle> list = new List<LandVehicle>();
			for (int i = 0; i < playerOwnedVehicles.Count; i++)
			{
				LandVehicle val = playerOwnedVehicles[i];
				if ((Object)(object)val != (Object)null && !_direct.Contains(((Il2CppObjectBase)val).Pointer) && IsPolice(val))
				{
					list.Add(val);
				}
			}
			foreach (LandVehicle item in list)
			{
				try
				{
					item.DestroyVehicle();
				}
				catch (Exception ex)
				{
					GtaMod.Verbose("DestroyVehicle: " + ex.Message);
				}
			}
			if (list.Count > 0)
			{
				GtaMod.Log.Msg($"Removed {list.Count} police car(s) you owned ({why}). Police cars can't be kept.");
			}
		}

		private static void TrySteal(Player p, VehicleManager vm)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			LandVehicle v = FindNearestPoliceCar(vm, ((Component)p).transform.position, Cfg.StealRange.Value);
			if ((Object)(object)v == (Object)null)
			{
				return;
			}
			if (_direct.Contains(((Il2CppObjectBase)v).Pointer))
			{
				EnterDirect(v);
				return;
			}
			if (v.IsPlayerOwned)
			{
				v.EnterVehicle();
				return;
			}
			if (Mathf.Abs(v.Speed_Kmh) > Cfg.MaxCarjackSpeedKmh.Value)
			{
				GtaMod.Log.Msg("That police car is moving too fast to carjack. Point a gun at it to make it stop.");
				return;
			}
			List<NPC> list = Occupants(v);
			StopAI(v);
			if (!Minigame.Active && (list.Count <= 0 || !Cfg.CarjackMinigame.Value || !Minigame.Start(v, list[0], p, delegate
			{
				DoCarjack(v, p);
			})))
			{
				DoCarjack(v, p);
			}
		}

		private static void DoCarjack(LandVehicle v, Player p)
		{
			if ((Object)(object)v == (Object)null || (Object)(object)p == (Object)null)
			{
				return;
			}
			List<NPC> list = Occupants(v);
			StopAI(v);
			foreach (NPC item in list)
			{
				DragOut(item, v, p);
			}
			if (Cfg.AddTheftCrime.Value)
			{
				Reactions.AddTheft(p);
			}
			Reactions.Seen(p, "FroggosGTA_CarTheft", Cfg.NoticeSeconds.Value);
			Reactions.Wanted(p);
			GtaMod.Log.Msg((list.Count > 0) ? $"Carjacked a police car ({list.Count} thrown out)." : "Stealing a parked police car.");
			_handled.Add(((Il2CppObjectBase)v).Pointer);
			GtaMod.Later((list.Count > 0) ? 0.6f : 0.05f, "steal police car", delegate
			{
				Seize(v, enter: true);
			});
		}

		private static LandVehicle FindNearestPoliceCar(VehicleManager vm, Vector3 pos, float range)
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			LandVehicle result = null;
			float num = range;
			List<LandVehicle> allVehicles = vm.AllVehicles;
			for (int i = 0; i < allVehicles.Count; i++)
			{
				LandVehicle val = allVehicles[i];
				if (!((Object)(object)val == (Object)null) && ((Component)val).gameObject.activeInHierarchy)
				{
					float num2 = DistanceToCar(val, pos);
					if (num2 < num && IsPolice(val))
					{
						num = num2;
						result = val;
					}
				}
			}
			return result;
		}

		private static float DistanceToCar(LandVehicle v, Vector3 pos)
		{
			//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)
			//IL_0041: 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_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_0057: 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_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: 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_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: 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_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: 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_00bb: 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)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			BoxCollider boundingBox = v.boundingBox;
			if ((Object)(object)boundingBox == (Object)null)
			{
				return Mathf.Max(0f, Vector3.Distance(pos, ((Component)v).transform.position) - 2f);
			}
			Transform transform = ((Component)boundingBox).transform;
			Vector3 val = transform.InverseTransformPoint(pos) - boundingBox.center;
			Vector3 val2 = boundingBox.size * 0.5f;
			Vector3 val3 = default(Vector3);
			((Vector3)(ref val3))..ctor(Mathf.Clamp(val.x, 0f - val2.x, val2.x), Mathf.Clamp(val.y, 0f - val2.y, val2.y), Mathf.Clamp(val.z, 0f - val2.z, val2.z));
			return Vector3.Distance(pos, transform.TransformPoint(val3 + boundingBox.center));
		}

		private static void DragOut(NPC npc, LandVehicle v, Player p)
		{
			Exit(npc);
			Reactions.Say(npc, "Hey! That's a police vehicle!");
			float force = Cfg.DragOutForce.Value;
			if (force > 0f)
			{
				GtaMod.Later(0.1f, "ragdoll", delegate
				{
					//IL_001a: 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_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_0067: 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_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_0080: Unknown result type (might be due to invalid IL or missing references)
					//IL_0083: Unknown result type (might be due to invalid IL or missing references)
					//IL_0088: Unknown result type (might be due to invalid IL or missing references)
					//IL_009f: Unknown result type (might be due to invalid IL or missing references)
					//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
					//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
					//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
					//IL_005a: Unknown result type (might be due to invalid IL or missing references)
					//IL_005f: Unknown result type (might be due to invalid IL or missing references)
					//IL_0064: Unknown result type (might be due to invalid IL or missing references)
					if (!((Object)(object)npc == (Object)null))
					{
						Vector3 val = ((Component)npc).transform.position - ((Component)v).transform.position;
						val.y = 0f;
						if (((Vector3)(ref val)).sqrMagnitude < 0.01f)
						{
							val = -((Component)v).transform.right;
						}
						Vector3 val2 = ((Vector3)(ref val)).normalized + Vector3.up * 0.3f;
						val = ((Vector3)(ref val2)).normalized;
						npc.Movement.ActivateRagdoll_Server(((Component)npc).transform.position + Vector3.up, val, force);
					}
				});
			}
			GtaMod.Later(2.2f, "carjack reaction", delegate
			{
				Reactions.Pursue(npc, p);
			});
		}

		internal static bool CanHoldUp(LandVehicle v)
		{
			if ((Object)(object)v != (Object)null && !v.IsPlayerOwned && !_handled.Contains(((Il2CppObjectBase)v).Pointer) && IsPolice(v))
			{
				return Occupants(v).Count > 0;
			}
			return false;
		}

		internal static void HoldUp(LandVehicle v, Player p)
		{
			if (!CanHoldUp(v))
			{
				return;
			}
			_handled.Add(((Il2CppObjectBase)v).Pointer);
			List<NPC> list = Occupants(v);
			StopAI(v);
			foreach (NPC cop in list)
			{
				Exit(cop);
				Reactions.Say(cop, "Drop the weapon!");
				GtaMod.Later(0.5f, "gunpoint reaction", delegate
				{
					Reactions.Pursue(cop, p);
				});
			}
			Reactions.Seen(p, "FroggosGTA_CarTheft", Cfg.NoticeSeconds.Value);
			Reactions.Wanted(p);
			GtaMod.Log.Msg($"Held up a police car: {list.Count} got out.");
			GtaMod.Later(0.8f, "keep held-up police car", delegate
			{
				Seize(v, enter: false);
			});
		}

		private static void ScanForDeadDrivers(VehicleManager vm, Player p)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			Vector3 position = ((Component)p).transform.position;
			List<LandVehicle> allVehicles = vm.AllVehicles;
			for (int i = 0; i < allVehicles.Count; i++)
			{
				LandVehicle v = allVehicles[i];
				if ((Object)(object)v == (Object)null || v.IsPlayerOwned || _handled.Contains(((Il2CppObjectBase)v).Pointer))
				{
					continue;
				}
				Vector3 val = ((Component)v).transform.position - position;
				if (((Vector3)(ref val)).sqrMagnitude > 14400f)
				{
					continue;
				}
				List<NPC> list = Occupants(v);
				if (list.Count == 0 || !IsPolice(v))
				{
					continue;
				}
				bool flag = false;
				foreach (NPC item in list)
				{
					if (!item.IsConscious)
					{
						flag = true;
						break;
					}
				}
				if (!flag)
				{
					continue;
				}
				_handled.Add(((Il2CppObjectBase)v).Pointer);
				StopAI(v);
				foreach (NPC npc in list)
				{
					Exit(npc);
					if (npc.IsConscious)
					{
						GtaMod.Later(0.5f, "partner reaction", delegate
						{
							Reactions.Pursue(npc, p);
						});
					}
				}
				GtaMod.Verbose("Officer driving a police car is down, keeping the car.");
				GtaMod.Later(1f, "keep police car of downed officer", delegate
				{
					Seize(v, enter: false);
				});
			}
		}

		internal static void OnNpcExited(NPC npc, LandVehicle v)
		{
			if (!Busy && !((Object)(object)v == (Object)null) && !((Object)(object)npc == (Object)null) && Cfg.ReplaceOnDriverDeath.Value && !npc.IsConscious && !v.IsPlayerOwned && !_handled.Contains(((Il2CppObjectBase)v).Pointer) && Occupants(v).Count <= 0 && IsPolice(v))
			{
				_handled.Add(((Il2CppObjectBase)v).Pointer);
				GtaMod.Later(1f, "keep police car of downed officer", delegate
				{
					Seize(v, enter: false);
				});
			}
		}

		private static void Seize(LandVehicle v, bool enter)
		{
			if (!((Object)(object)v == (Object)null))
			{
				IntPtr key = ((Il2CppObjectBase)v).Pointer;
				StopAI(v);
				_abandonedUntil.Remove(key);
				if (!_stolen.Exists((LandVehicle x) => (Object)(object)x != (Object)null && ((Il2CppObjectBase)x).Pointer == key))
				{
					_stolen.Add(v);
				}
				if (enter)
				{
					EnterDirect(v);
				}
				else
				{
					_abandonedUntil[key] = Time.time + 300f;
				}
			}
		}

		private static void EnterDirect(LandVehicle v)
		{
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			_direct.Add(((Il2CppObjectBase)v).Pointer);
			_abandonedUntil.Remove(((Il2CppObjectBase)v).Pointer);
			StopAI(v);
			if ((Object)(object)v.Agent != (Object)null)
			{
				((Behaviour)v.Agent).enabled = false;
			}
			try
			{
				v.IsPlayerOwned = true;
			}
			catch
			{
			}
			_directRide = v;
			_directRideSince = Time.time;
			v.EnterVehicle();
			GtaMod.Log.Msg($"In the police car. [{Cfg.SirenKey}] lights + siren, Shift+[{Cfg.SirenKey}] mute siren.");
		}

		private static void Exit(NPC npc)
		{
			Busy = true;
			try
			{
				npc.ExitVehicle();
			}
			finally
			{
				Busy = false;
			}
		}

		private static void StopAI(LandVehicle v)
		{
			try
			{
				if ((Object)(object)v.Agent != (Object)null)
				{
					v.Agent.StopNavigating();
				}
			}
			catch (Exception ex)
			{
				GtaMod.Verbose("StopNavigating: " + ex.Message);
			}
		}

		internal static List<NPC> Occupants(LandVehicle v)
		{
			List<NPC> list = new List<NPC>();
			Il2CppReferenceArray<NPC> occupantNPCs = v.OccupantNPCs;
			if (occupantNPCs == null)
			{
				return list;
			}
			for (int i = 0; i < ((Il2CppArrayBase<NPC>)(object)occupantNPCs).Length; i++)
			{
				if ((Object)(object)((Il2CppArrayBase<NPC>)(object)occupantNPCs)[i] != (Object)null)
				{
					list.Add(((Il2CppArrayBase<NPC>)(object)occupantNPCs)[i]);
				}
			}
			return list;
		}

		internal static bool IsPolice(LandVehicle v)
		{
			if ((Object)(object)((Component)v).GetComponentInChildren<PoliceLight>(true) != (Object)null)
			{
				return true;
			}
			foreach (NPC item in Occupants(v))
			{
				if ((Object)(object)((Il2CppObjectBase)item).TryCast<PoliceOfficer>() != (Object)null)
				{
					return true;
				}
			}
			return false;
		}
	}
	internal class GtaConfig
	{
		public readonly MelonPreferences_Category Category;

		public readonly MelonPreferences_Entry<string> StealKeyName;

		public readonly MelonPreferences_Entry<string> SirenKeyName;

		public readonly MelonPreferences_Entry<float> StealRange;

		public readonly MelonPreferences_Entry<float> MaxCarjackSpeedKmh;

		public readonly MelonPreferences_Entry<bool> ReplaceOnDriverDeath;

		public readonly MelonPreferences_Entry<bool> GunpointEject;

		public readonly MelonPreferences_Entry<float> GunpointRange;

		public readonly MelonPreferences_Entry<float> GunpointHoldSeconds;

		public readonly MelonPreferences_Entry<float> DragOutForce;

		public readonly MelonPreferences_Entry<bool> AddTheftCrime;

		public readonly MelonPreferences_Entry<bool> CarjackMinigame;

		public readonly MelonPreferences_Entry<int> CarjackHits;

		public readonly MelonPreferences_Entry<float> MinigameZoneWidth;

		public readonly MelonPreferences_Entry<float> MinigameSlowdown;

		public readonly MelonPreferences_Entry<bool> MinigameNoSpeedUp;

		public readonly MelonPreferences_Entry<bool> MinigameWhenWanted;

		public readonly MelonPreferences_Entry<bool> PoliceNotice;

		public readonly MelonPreferences_Entry<float> NoticeSeconds;

		public readonly MelonPreferences_Entry<bool> WantedOnSteal;

		public readonly MelonPreferences_Entry<string> PursuitLevelName;

		public readonly MelonPreferences_Entry<int> DispatchOfficers;

		public readonly MelonPreferences_Entry<float> SpeedMultiplier;

		public readonly MelonPreferences_Entry<float> AccelerationMultiplier;

		public readonly MelonPreferences_Entry<float> MassMultiplier;

		public readonly MelonPreferences_Entry<float> PlowThrough;

		public readonly MelonPreferences_Entry<float> ShoveStrength;

		public readonly MelonPreferences_Entry<float> PersonLaunch;

		public readonly MelonPreferences_Entry<bool> VerboseLog;

		public Key StealKey { get; private set; } = (Key)20;

		public Key SirenKey { get; private set; } = (Key)21;

		public EPursuitLevel PursuitLevel { get; private set; } = (EPursuitLevel)4;

		public GtaConfig()
		{
			//IL_0003: 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_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0475: Unknown result type (might be due to invalid IL or missing references)
			//IL_0488: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b7: Unknown result type (might be due to invalid IL or missing references)
			Category = MelonPreferences.CreateCategory("FroggosGTA", "FroggosGTA");
			StealKeyName = Category.CreateEntry<string>("StealKey", "F", (string)null, "Key to carjack / steal the nearest police car (UnityEngine.InputSystem.Key name).", false, false, (ValueValidator)null, (string)null);
			SirenKeyName = Category.CreateEntry<string>("SirenKey", "G", (string)null, "Key to toggle the police lights + siren while driving a police car. Shift + this key mutes/unmutes only the siren sound.", false, false, (ValueValidator)null, (string)null);
			StealRange = Category.CreateEntry<float>("StealRange", 4.5f, (string)null, "How close (meters) you must be to a police car to steal it.", false, false, (ValueValidator)null, (string)null);
			MaxCarjackSpeedKmh = Category.CreateEntry<float>("MaxCarjackSpeedKmh", 30f, (string)null, "Police cars driving faster than this can't be carjacked (point a gun at them to make them stop).", false, false, (ValueValidator)null, (string)null);
			ReplaceOnDriverDeath = Category.CreateEntry<bool>("ReplaceOnDriverDeath", true, (string)null, "Keep a police car from vanishing when its officer is killed or knocked out inside it.", false, false, (ValueValidator)null, (string)null);
			GunpointEject = Category.CreateEntry<bool>("GunpointEject", true, (string)null, "Aiming a gun at a police car makes the cops inside get out.", false, false, (ValueValidator)null, (string)null);
			GunpointRange = Category.CreateEntry<float>("GunpointRange", 30f, (string)null, "Max distance (meters) for gunpoint to work.", false, false, (ValueValidator)null, (string)null);
			GunpointHoldSeconds = Category.CreateEntry<float>("GunpointHoldSeconds", 0.4f, (string)null, "How long you must keep aiming at the car before they get out.", false, false, (ValueValidator)null, (string)null);
			DragOutForce = Category.CreateEntry<float>("DragOutForce", 6f, (string)null, "How hard the cop is thrown out when carjacked (0 = no ragdoll).", false, false, (ValueValidator)null, (string)null);
			AddTheftCrime = Category.CreateEntry<bool>("AddTheftCrime", true, (string)null, "Stealing a police car adds a Theft charge to your record (counts if you get arrested).", false, false, (ValueValidator)null, (string)null);
			CarjackMinigame = Category.CreateEntry<bool>("CarjackMinigame", true, (string)null, "Carjacking a police car with a cop inside plays the pickpocket minigame first. Miss and the cop catches you.", false, false, (ValueValidator)null, (string)null);
			CarjackHits = Category.CreateEntry<int>("CarjackHits", 3, (string)null, "How many green zones you have to hit to win the carjack.", false, false, (ValueValidator)null, (string)null);
			MinigameZoneWidth = Category.CreateEntry<float>("MinigameZoneWidth", 2.2f, (string)null, "Green zone width for the carjack minigame, times the widest zone normal pickpocketing has. Bigger = easier.", false, false, (ValueValidator)null, (string)null);
			MinigameSlowdown = Category.CreateEntry<float>("MinigameSlowdown", 1.6f, (string)null, "How much slower the slider moves than in normal pickpocketing. Bigger = easier.", false, false, (ValueValidator)null, (string)null);
			MinigameNoSpeedUp = Category.CreateEntry<bool>("MinigameNoSpeedUp", true, (string)null, "Keep the slider at the same speed after each hit (normal pickpocketing speeds it up).", false, false, (ValueValidator)null, (string)null);
			MinigameWhenWanted = Category.CreateEntry<bool>("MinigameWhenWanted", false, (string)null, "Also play the minigame while you're wanted. Off = when the cops are already after you, F just yanks the cop out.", false, false, (ValueValidator)null, (string)null);
			if (Math.Abs(MinigameZoneWidth.Value - 1.3f) < 0.001f)
			{
				MinigameZoneWidth.Value = 2.2f;
			}
			if (Math.Abs(MinigameSlowdown.Value - 1.2f) < 0.001f)
			{
				MinigameSlowdown.Value = 1.6f;
			}
			PoliceNotice = Category.CreateEntry<bool>("PoliceNotice", true, (string)null, "Stealing a police car (and the carjack minigame) counts as a crime in progress, like pickpocketing: any cop who sees you reacts.", false, false, (ValueValidator)null, (string)null);
			NoticeSeconds = Category.CreateEntry<float>("NoticeSeconds", 8f, (string)null, "How long after the theft cops who see you still count it as a crime in progress.", false, false, (ValueValidator)null, (string)null);
			WantedOnSteal = Category.CreateEntry<bool>("WantedOnSteal", true, (string)null, "Stealing a police car (carjack, parked, or gunpoint) instantly makes you wanted and starts a police pursuit.", false, false, (ValueValidator)null, (string)null);
			PursuitLevelName = Category.CreateEntry<string>("PursuitLevel", "Lethal", (string)null, "Wanted level you get for stealing a police car: Investigating, Arresting, NonLethal, or Lethal (= dead or alive).", false, false, (ValueValidator)null, (string)null);
			DispatchOfficers = Category.CreateEntry<int>("DispatchOfficers", 4, (string)null, "How many officers the nearest station sends after you when you steal a police car (0 = none, only the cops already there).", false, false, (ValueValidator)null, (string)null);
			SpeedMultiplier = Category.CreateEntry<float>("SpeedMultiplier", 1.6f, (string)null, "Top speed of a police car while you drive it, times the normal top speed.", false, false, (ValueValidator)null, (string)null);
			AccelerationMultiplier = Category.CreateEntry<float>("AccelerationMultiplier", 1.8f, (string)null, "Engine power of a police car while you drive it (on top of the extra power that makes up for the extra weight).", false, false, (ValueValidator)null, (string)null);
			MassMultiplier = Category.CreateEntry<float>("MassMultiplier", 4f, (string)null, "How much heavier a police car is while you drive it. Engine, brakes and suspension are scaled to match, so it handles the same but shoves other cars.", false, false, (ValueValidator)null, (string)null);
			PlowThrough = Category.CreateEntry<float>("PlowThrough", 0.85f, (string)null, "How much of your speed you keep when you hit a car or a person (0 = normal crash, 1 = no slowdown at all). Walls and poles still stop you.", false, false, (ValueValidator)null, (string)null);
			ShoveStrength = Category.CreateEntry<float>("ShoveStrength", 0.6f, (string)null, "How hard cars you hit get knocked away (fraction of your speed they're pushed at).", false, false, (ValueValidator)null, (string)null);
			PersonLaunch = Category.CreateEntry<float>("PersonLaunch", 1f, (string)null, "How far people you hit get thrown (multiplied by your speed).", false, false, (ValueValidator)null, (string)null);
			VerboseLog = Category.CreateEntry<bool>("VerboseLog", false, (string)null, "Log extra detail for troubleshooting.", false, false, (ValueValidator)null, (string)null);
			StealKey = ParseKey(StealKeyName, (Key)20);
			SirenKey = ParseKey(SirenKeyName, (Key)21);
			if (Enum.TryParse<EPursuitLevel>(PursuitLevelName.Value?.Trim(), ignoreCase: true, out EPursuitLevel result) && (int)result != 0)
			{
				PursuitLevel = result;
			}
			else
			{
				GtaMod.Log.Warning("PursuitLevel '" + PursuitLevelName.Value + "' is not valid, using Lethal.");
			}
		}

		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;
			}
			GtaMod.Log.Warning($"{((MelonPreferences_Entry)entry).Identifier} '{entry.Value}' is not a valid key name, using {fallback}.");
			return fallback;
		}
	}
	public class GtaMod : MelonMod
	{
		internal static Instance Log;

		internal static GtaConfig Cfg;

		private static bool _tickFailed;

		private static readonly List<(float at, string what, Action act)> _later = new List<(float, string, Action)>();

		public override void OnInitializeMelon()
		{
			//IL_0037: 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)
			Log = ((MelonBase)this).LoggerInstance;
			Cfg = new GtaConfig();
			Log.Msg($"FroggosGTA loaded. [{Cfg.StealKey}] steal a police car, aim a gun at one to make the cops get out, [{Cfg.SirenKey}] siren.");
		}

		public override void OnUpdate()
		{
			try
			{
				RunLater();
				Minigame.Tick();
				Carjack.Tick();
				Gunpoint.Tick();
				Siren.Tick();
				PoliceBoost.Tick();
				_tickFailed = false;
			}
			catch (Exception ex)
			{
				if (!_tickFailed)
				{
					Log.Error("Update failed (logged once until it works again): " + ex);
				}
				_tickFailed = true;
			}
		}

		public override void OnSceneWasUnloaded(int buildIndex, string sceneName)
		{
			_later.Clear();
			Carjack.Reset();
			Gunpoint.Reset();
			PoliceBoost.Reset();
			Minigame.Reset();
		}

		internal static void Later(float delay, string what, Action act)
		{
			_later.Add((Time.time + delay, what, act));
		}

		private static void RunLater()
		{
			for (int num = _later.Count - 1; num >= 0; num--)
			{
				(float, string, Action) tuple = _later[num];
				if (!(Time.time < tuple.Item1))
				{
					_later.RemoveAt(num);
					try
					{
						tuple.Item3();
					}
					catch (Exception ex)
					{
						Log.Warning(tuple.Item2 + " failed: " + ex.Message);
					}
				}
			}
		}

		internal static void Verbose(string msg)
		{
			if (Cfg.VerboseLog.Value)
			{
				Log.Msg(msg);
			}
		}
	}
	internal static class Gunpoint
	{
		private const float AimThreshold = 0.5f;

		private const float RayRadius = 0.35f;

		internal static Equippable_RangedWeapon Weapon;

		private static LandVehicle _aimed;

		private static float _aimStart;

		private static readonly List<RaycastHit> _hits = new List<RaycastHit>();

		internal static void Reset()
		{
			Weapon = null;
			_aimed = null;
		}

		internal static void Tick()
		{
			if (!GtaMod.Cfg.GunpointEject.Value)
			{
				return;
			}
			Player local = Player.Local;
			if ((Object)(object)local == (Object)null || local.IsInVehicle || (Object)(object)Weapon == (Object)null || Weapon.Aim < 0.5f)
			{
				_aimed = null;
				return;
			}
			LandVehicle val = AimedVehicle();
			if ((Object)(object)val == (Object)null || !Carjack.CanHoldUp(val))
			{
				_aimed = null;
			}
			else if ((Object)(object)_aimed == (Object)null || ((Il2CppObjectBase)_aimed).Pointer != ((Il2CppObjectBase)val).Pointer)
			{
				_aimed = val;
				_aimStart = Time.time;
			}
			else if (Time.time - _aimStart >= GtaMod.Cfg.GunpointHoldSeconds.Value)
			{
				_aimed = null;
				Carjack.HoldUp(val, local);
			}
		}

		private static LandVehicle AimedVehicle()
		{
			//IL_0017: 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_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_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			Camera main = Camera.main;
			if ((Object)(object)main == (Object)null)
			{
				return null;
			}
			Il2CppStructArray<RaycastHit> obj = Physics.SphereCastAll(((Component)main).transform.position, 0.35f, ((Component)main).transform.forward, GtaMod.Cfg.GunpointRange.Value, -1, (QueryTriggerInteraction)1);
			_hits.Clear();
			foreach (RaycastHit item in (Il2CppArrayBase<RaycastHit>)(object)obj)
			{
				_hits.Add(item);
			}
			_hits.Sort((RaycastHit a, RaycastHit b) => ((RaycastHit)(ref a)).distance.CompareTo(((RaycastHit)(ref b)).distance));
			foreach (RaycastHit hit in _hits)
			{
				RaycastHit current2 = hit;
				Collider collider = ((RaycastHit)(ref current2)).collider;
				if (!((Object)(object)collider == (Object)null) && !((Object)(object)((Component)collider).GetComponentInParent<Player>() != (Object)null))
				{
					return ((Component)collider).GetComponentInParent<LandVehicle>();
				}
			}
			return null;
		}
	}
	internal static class Minigame
	{
		private class Session
		{
			public LandVehicle Vehicle;

			public NPC Cop;

			public Player Player;

			public Action OnSuccess;

			public int Required;

			public int Hits;

			public bool Started;

			public bool Done;

			public readonly List<(ItemSlot slot, ItemInstance item)> Stash = new List<(ItemSlot, ItemInstance)>();

			public float MinWidth;

			public float MaxWidth;

			public float SlideTime;

			public float Tolerance;

			public float BaseSpeed;

			public float OpenedAt;
		}

		private static readonly string[] FillerIds = new string[5] { "banana", "cuke", "donut", "energydrink", "mouthwash" };

		private static Session _s;

		internal static bool Active => _s != null;

		private static PickpocketScreen Screen
		{
			get
			{
				if (!Singleton<PickpocketScreen>.InstanceExists)
				{
					return null;
				}
				return Singleton<PickpocketScreen>.Instance;
			}
		}

		internal static void Reset()
		{
			_s = null;
		}

		internal static bool Start(LandVehicle v, NPC cop, Player p, Action onSuccess)
		{
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			PickpocketScreen screen = Screen;
			if (_s != null || (Object)(object)screen == (Object)null || screen.IsOpen || (Object)(object)cop.Inventory == (Object)null)
			{
				return false;
			}
			if (!GtaMod.Cfg.MinigameWhenWanted.Value && (Object)(object)p.CrimeData != (Object)null && (int)p.CrimeData.CurrentPursuitLevel != 0)
			{
				return false;
			}
			Session session = new Session
			{
				Vehicle = v,
				Cop = cop,
				Player = p,
				OnSuccess = onSuccess
			};
			try
			{
				FillPockets(session);
				if (session.Required == 0)
				{
					RestorePockets(session);
					return false;
				}
				session.MinWidth = screen.GreenAreaMinWidth;
				session.MaxWidth = screen.GreenAreaMaxWidth;
				session.SlideTime = screen.SlideTime;
				session.Tolerance = screen.Tolerance;
				float num = Math.Max(0.1f, GtaMod.Cfg.MinigameZoneWidth.Value);
				float greenAreaMaxWidth = (screen.GreenAreaMinWidth = session.MaxWidth * num);
				screen.GreenAreaMaxWidth = greenAreaMaxWidth;
				screen.Tolerance = session.Tolerance * num;
				screen.SlideTime = session.SlideTime * Math.Max(0.1f, GtaMod.Cfg.MinigameSlowdown.Value);
				_s = session;
				screen.Open(cop);
				if (!screen.IsOpen)
				{
					GtaMod.Verbose("Pickpocket screen didn't open, carjacking without the minigame.");
					Cleanup(screen, session);
					_s = null;
					return false;
				}
				session.Started = true;
				session.OpenedAt = Time.time;
				session.BaseSpeed = screen.slideTimeMultiplier;
				Reactions.Seen(p, "FroggosGTA_Carjacking", 0f);
				GtaMod.Log.Msg($"Carjack: hit all {session.Required} green zones to drag the cop out. Miss one and they catch you.");
				return true;
			}
			catch (Exception ex)
			{
				GtaMod.Log.Warning("Couldn't open the carjack minigame, carjacking without it: " + ex.Message);
				Cleanup(screen, session);
				_s = null;
				return false;
			}
		}

		internal static void Tick()
		{
			Session s = _s;
			if (s != null && s.Started && !(Time.time - s.OpenedAt < 0.5f))
			{
				PickpocketScreen screen = Screen;
				if (!((Object)(object)screen != (Object)null) || !screen.IsOpen)
				{
					GtaMod.Verbose("Carjack minigame screen is gone, ending it.");
					Finish(s);
				}
			}
		}

		internal static void AfterArrowStopped()
		{
			Session s = _s;
			if (s != null && s.Started && !s.Done && GtaMod.Cfg.MinigameNoSpeedUp.Value)
			{
				PickpocketScreen screen = Screen;
				if ((Object)(object)screen != (Object)null && s.BaseSpeed > 0f)
				{
					screen.slideTimeMultiplier = s.BaseSpeed;
				}
			}
		}

		internal static void OnSlotUnlocked()
		{
			Session s = _s;
			if (s == null || !s.Started || s.Done)
			{
				return;
			}
			s.Hits++;
			GtaMod.Verbose($"Carjack minigame hit {s.Hits}/{s.Required}");
			if (s.Hits < s.Required)
			{
				return;
			}
			s.Done = true;
			GtaMod.Later(0.25f, "carjack minigame win", delegate
			{
				PickpocketScreen screen = Screen;
				if ((Object)(object)screen != (Object)null && screen.IsOpen)
				{
					screen.Close();
				}
				else
				{
					Finish(s);
				}
				s.OnSuccess?.Invoke();
			});
		}

		internal static void OnFail()
		{
			Session s = _s;
			if (s != null && s.Started && !s.Done)
			{
				s.Done = true;
				GtaMod.Log.Msg("Carjack failed: the cop caught you!");
				Reactions.Say(s.Cop, "Hey! Get away from my car!");
				Reactions.Wanted(s.Player);
				Reactions.Seen(s.Player, "FroggosGTA_CarTheft", GtaMod.Cfg.NoticeSeconds.Value);
				GtaMod.Later(1f, "cop catches carjacker", delegate
				{
					Reactions.Pursue(s.Cop, s.Player);
				});
			}
		}

		internal static void OnClose()
		{
			Session s = _s;
			if (s != null && s.Started)
			{
				if (!s.Done)
				{
					GtaMod.Log.Msg("Carjack called off.");
				}
				Finish(s);
			}
		}

		private static void FillPockets(Session s)
		{
			List<ItemSlot> itemSlots = s.Cop.Inventory.ItemSlots;
			int count = itemSlots.Count;
			int want = Math.Min(Math.Max(1, GtaMod.Cfg.CarjackHits.Value), count);
			for (int i = 0; i < count; i++)
			{
				ItemSlot val = itemSlots[i];
				s.Stash.Add((val, val.ItemInstance));
				if (val.ItemInstance != null)
				{
					val.ClearStoredInstance(false);
				}
			}
			foreach (int item in SpreadIndices(count, want))
			{
				ItemInstance val2 = MakeFiller(s.Cop.Inventory);
				if (val2 != null)
				{
					itemSlots[item].SetStoredItem(val2, false);
					s.Required++;
				}
			}
		}

		private static IEnumerable<int> SpreadIndices(int n, int want)
		{
			if (want >= n)
			{
				for (int i = 0; i < n; i++)
				{
					yield return i;
				}
			}
			else if (want == 1)
			{
				yield return n / 2;
			}
			else
			{
				for (int i = 0; i < want; i++)
				{
					yield return (int)Math.Round((double)(i * (n - 1)) / (double)(want - 1));
				}
			}
		}

		private static ItemInstance MakeFiller(NPCInventory inv)
		{
			try
			{
				StorableItemDefinition randomInventoryItem = inv.GetRandomInventoryItem(new List<string>());
				ItemInstance val = ((randomInventoryItem != null) ? ((ItemDefinition)randomInventoryItem).GetDefaultInstance(1) : null);
				if (val != null)
				{
					return val;
				}
			}
			catch (Exception ex)
			{
				GtaMod.Verbose("random filler: " + ex.Message);
			}
			string[] fillerIds = FillerIds;
			for (int i = 0; i < fillerIds.Length; i++)
			{
				ItemDefinition item = Registry.GetItem(fillerIds[i]);
				if ((Object)(object)item != (Object)null)
				{
					return item.GetDefaultInstance(1);
				}
			}
			return null;
		}

		private static void RestorePockets(Session s)
		{
			foreach (var (val, val2) in s.Stash)
			{
				if (val == null)
				{
					continue;
				}
				try
				{
					if (val.ItemInstance != null)
					{
						val.ClearStoredInstance(false);
					}
					if (val2 != null)
					{
						val.SetStoredItem(val2, false);
					}
				}
				catch (Exception ex)
				{
					GtaMod.Verbose("restore pocket: " + ex.Message);
				}
			}
			s.Stash.Clear();
		}

		private static void Finish(Session s)
		{
			if (_s == s)
			{
				_s = null;
			}
			Cleanup(Screen, s);
		}

		private static void Cleanup(PickpocketScreen screen, Session s)
		{
			Reactions.Unseen(s.Player, "FroggosGTA_Carjacking");
			RestorePockets(s);
			if ((Object)(object)screen != (Object)null && s.MaxWidth > 0f)
			{
				screen.GreenAreaMinWidth = s.MinWidth;
				screen.GreenAreaMaxWidth = s.MaxWidth;
				screen.SlideTime = s.SlideTime;
				screen.Tolerance = s.Tolerance;
				s.MaxWidth = 0f;
			}
		}
	}
	[HarmonyPatch(typeof(NPC), "EnterVehicle")]
	internal static class NpcEnterVehiclePatch
	{
		private static bool Prefix(LandVehicle veh)
		{
			return Carjack.AllowNpcEnter(veh);
		}
	}
	[HarmonyPatch(typeof(NPC), "ExitVehicle")]
	internal static class NpcExitVehiclePatch
	{
		private static void Prefix(NPC __instance, out LandVehicle __state)
		{
			__state = __instance.CurrentVehicle;
		}

		private static void Postfix(NPC __instance, LandVehicle __state)
		{
			Carjack.OnNpcExited(__instance, __state);
		}
	}
	[HarmonyPatch(typeof(PoliceStation), "ReturnVehicle")]
	internal static class PoliceReturnVehiclePatch
	{
		private static bool Prefix(LandVehicle vehicle)
		{
			return !Carjack.IsProtected(vehicle);
		}
	}
	[HarmonyPatch(typeof(LandVehicle), "SetVisible")]
	internal static class SetVisiblePatch
	{
		private static bool Prefix(LandVehicle __instance, bool vis)
		{
			if (!vis)
			{
				return !Carjack.IsProtected(__instance);
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(LandVehicle), "DestroyVehicle")]
	internal static class DestroyVehiclePatch
	{
		private static bool Prefix(LandVehicle __instance)
		{
			return !Carjack.IsProtected(__instance);
		}
	}
	[HarmonyPatch(typeof(LandVehicle), "FixedUpdate")]
	internal static class FixedUpdatePatch
	{
		private static void Postfix(LandVehicle __instance)
		{
			PoliceBoost.OnFixedUpdate(__instance);
		}
	}
	[HarmonyPatch(typeof(LandVehicle), "OnCollisionEnter")]
	internal static class CollisionPatch
	{
		private static void Postfix(LandVehicle __instance, Collision collision)
		{
			PoliceBoost.OnCollision(__instance, collision);
		}
	}
	[HarmonyPatch(typeof(Player), "SleepStart")]
	internal static class SleepStartPatch
	{
		private static void Postfix(Player __instance)
		{
			if ((Object)(object)__instance != (Object)null && (Object)(object)Player.Local != (Object)null && ((Il2CppObjectBase)__instance).Pointer == ((Il2CppObjectBase)Player.Local).Pointer)
			{
				Carjack.OnSleep();
			}
		}
	}
	[HarmonyPatch(typeof(PickpocketScreen), "SetSlotLocked")]
	internal static class PickpocketSlotPatch
	{
		private static void Postfix(bool locked)
		{
			if (!locked)
			{
				Minigame.OnSlotUnlocked();
			}
		}
	}
	[HarmonyPatch(typeof(PickpocketScreen), "StopArrow")]
	internal static class PickpocketStopArrowPatch
	{
		private static void Postfix()
		{
			Minigame.AfterArrowStopped();
		}
	}
	[HarmonyPatch(typeof(PickpocketScreen), "Fail")]
	internal static class PickpocketFailPatch
	{
		private static void Postfix()
		{
			Minigame.OnFail();
		}
	}
	[HarmonyPatch(typeof(PickpocketScreen), "Close")]
	internal static class PickpocketClosePatch
	{
		private static void Postfix()
		{
			Minigame.OnClose();
		}
	}
	[HarmonyPatch(typeof(Equippable_RangedWeapon), "Equip")]
	internal static class RangedWeaponEquipPatch
	{
		private static void Postfix(Equippable_RangedWeapon __instance)
		{
			Gunpoint.Weapon = __instance;
		}
	}
	internal static class PoliceBoost
	{
		private class Original
		{
			public LandVehicle V;

			public float Mass;

			public float TopSpeed;

			public float HandBrake;

			public float Downforce;

			public Keyframe[] Torque;

			public Keyframe[] Brake;

			public readonly List<(WheelCollider wheel, JointSpring spring)> Springs = new List<(WheelCollider, JointSpring)>();
		}

		private const float MinPlowSpeed = 3f;

		private const float NpcHitCooldown = 1f;

		private static Original _boosted;

		private static Vector3 _lastVelocity;

		private static readonly Dictionary<IntPtr, float> _npcHitAt = new Dictionary<IntPtr, float>();

		private static GtaConfig Cfg => GtaMod.Cfg;

		internal static void Reset()
		{
			_boosted = null;
			_npcHitAt.Clear();
		}

		internal static void Tick()
		{
			Player local = Player.Local;
			if (!((Object)(object)local == (Object)null))
			{
				LandVehicle val = null;
				if (local.IsInVehicle && (Object)(object)local.CurrentVehicle != (Object)null)
				{
					val = ((Component)local.CurrentVehicle).GetComponent<LandVehicle>();
				}
				if (_boosted != null && ((Object)(object)_boosted.V == (Object)null || (Object)(object)val == (Object)null || ((Il2CppObjectBase)val).Pointer != ((Il2CppObjectBase)_boosted.V).Pointer))
				{
					Restore();
				}
				if ((Object)(object)val != (Object)null && _boosted == null && (Object)(object)val.Rb != (Object)null && Carjack.IsPolice(val))
				{
					Apply(val);
				}
			}
		}

		private static bool IsBoosted(LandVehicle v)
		{
			if (_boosted != null && (Object)(object)v != (Object)null && (Object)(object)_boosted.V != (Object)null)
			{
				return ((Il2CppObjectBase)v).Pointer == ((Il2CppObjectBase)_boosted.V).Pointer;
			}
			return false;
		}

		private static void Apply(LandVehicle v)
		{
			//IL_0130: 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_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			float num = Mathf.Max(1f, Cfg.MassMultiplier.Value);
			float num2 = Mathf.Max(0.1f, Cfg.SpeedMultiplier.Value);
			float num3 = Mathf.Max(0.1f, Cfg.AccelerationMultiplier.Value);
			Original original = new Original
			{
				V = v,
				Mass = v.Rb.mass,
				TopSpeed = v.TopSpeed,
				HandBrake = v.handBrakeForce,
				Downforce = v.downforce,
				Torque = CopyKeys(v.motorTorque),
				Brake = CopyKeys(v.brakeForce)
			};
			v.Rb.mass = original.Mass * num;
			v.TopSpeed = original.TopSpeed * num2;
			v.handBrakeForce = original.HandBrake * num;
			v.downforce = original.Downforce * num;
			ScaleKeys(v.motorTorque, original.Torque, num * num3);
			ScaleKeys(v.brakeForce, original.Brake, num);
			foreach (WheelCollider componentsInChild in ((Component)v).GetComponentsInChildren<WheelCollider>(true))
			{
				JointSpring suspensionSpring = componentsInChild.suspensionSpring;
				original.Springs.Add((componentsInChild, suspensionSpring));
				suspensionSpring.spring *= num;
				suspensionSpring.damper *= num;
				componentsInChild.suspensionSpring = suspensionSpring;
			}
			_boosted = original;
			_lastVelocity = v.Rb.velocity;
			GtaMod.Verbose($"Police boost on: mass {original.Mass:0} -> {v.Rb.mass:0} kg, top speed {original.TopSpeed:0} -> {v.TopSpeed:0}.");
		}

		private static void Restore()
		{
			//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_00cf: Unknown result type (might be due to invalid IL or missing references)
			Original boosted = _boosted;
			_boosted = null;
			if ((Object)(object)boosted.V == (Object)null)
			{
				return;
			}
			if ((Object)(object)boosted.V.Rb != (Object)null)
			{
				boosted.V.Rb.mass = boosted.Mass;
			}
			boosted.V.TopSpeed = boosted.TopSpeed;
			boosted.V.handBrakeForce = boosted.HandBrake;
			boosted.V.downforce = boosted.Downforce;
			SetKeys(boosted.V.motorTorque, boosted.Torque);
			SetKeys(boosted.V.brakeForce, boosted.Brake);
			foreach (var (val, suspensionSpring) in boosted.Springs)
			{
				if ((Object)(object)val != (Object)null)
				{
					val.suspensionSpring = suspensionSpring;
				}
			}
			GtaMod.Verbose("Police boost off.");
		}

		internal static void OnFixedUpdate(LandVehicle v)
		{
			//IL_001c: 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)
			if (IsBoosted(v) && (Object)(object)v.Rb != (Object)null)
			{
				_lastVelocity = v.Rb.velocity;
			}
		}

		internal static void OnCollision(LandVehicle v, Collision c)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: 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_0059: 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_0087: 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_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			if (!IsBoosted(v) || c == null || (Object)(object)c.collider == (Object)null || (Object)(object)v.Rb == (Object)null)
			{
				return;
			}
			Vector3 lastVelocity = _lastVelocity;
			if (((Vector3)(ref lastVelocity)).magnitude < 3f)
			{
				return;
			}
			Vector3 normalized = ((Vector3)(ref lastVelocity)).normalized;
			Vector3 val;
			if (c.contactCount <= 0)
			{
				val = ((Component)c.collider).transform.position;
			}
			else
			{
				ContactPoint contact = c.GetContact(0);
				val = ((ContactPoint)(ref contact)).point;
			}
			Vector3 val2 = val;
			NPC componentInParent = ((Component)c.collider).GetComponentInParent<NPC>();
			if ((Object)(object)componentInParent != (Object)null)
			{
				HitPerson(componentInParent, val2, normalized, ((Vector3)(ref lastVelocity)).magnitude);
			}
			else
			{
				LandVehicle componentInParent2 = ((Component)c.collider).GetComponentInParent<LandVehicle>();
				Rigidbody val3 = (((Object)(object)componentInParent2 != (Object)null) ? componentInParent2.Rb : c.rigidbody);
				if ((Object)(object)val3 == (Object)null)
				{
					return;
				}
				if (val3.isKinematic && (Object)(object)componentInParent2 != (Object)null)
				{
					val3.isKinematic = false;
				}
				if (val3.isKinematic)
				{
					return;
				}
				val3.AddForceAtPosition(normalized * ((Vector3)(ref lastVelocity)).magnitude * Cfg.ShoveStrength.Value * val3.mass, val2, (ForceMode)1);
			}
			v.Rb.velocity = Vector3.Lerp(v.Rb.velocity, lastVelocity, Mathf.Clamp01(Cfg.PlowThrough.Value));
		}

		private static void HitPerson(NPC npc, Vector3 point, Vector3 dir, float speed)
		{
			//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_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_004a: 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_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			IntPtr pointer = ((Il2CppObjectBase)npc).Pointer;
			if (_npcHitAt.TryGetValue(pointer, out var value) && Time.time - value < 1f)
			{
				return;
			}
			_npcHitAt[pointer] = Time.time;
			try
			{
				Vector3 val = dir + Vector3.up * 0.35f;
				Vector3 normalized = ((Vector3)(ref val)).normalized;
				npc.Movement.ActivateRagdoll_Server(point, normalized, speed * Cfg.PersonLaunch.Value);
			}
			catch (Exception ex)
			{
				GtaMod.Verbose("ragdoll on hit: " + ex.Message);
			}
		}

		private static Keyframe[] CopyKeys(AnimationCurve curve)
		{
			//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)
			if (curve == null)
			{
				return null;
			}
			Il2CppStructArray<Keyframe> keys = curve.keys;
			Keyframe[] array = (Keyframe[])(object)new Keyframe[((Il2CppArrayBase<Keyframe>)(object)keys).Length];
			for (int i = 0; i < ((Il2CppArrayBase<Keyframe>)(object)keys).Length; i++)
			{
				array[i] = ((Il2CppArrayBase<Keyframe>)(object)keys)[i];
			}
			return array;
		}

		private static void ScaleKeys(AnimationCurve curve, Keyframe[] original, float factor)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: 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)
			if (curve != null && original != null)
			{
				Keyframe[] array = (Keyframe[])(object)new Keyframe[original.Length];
				for (int i = 0; i < original.Length; i++)
				{
					Keyframe val = original[i];
					((Keyframe)(ref val)).value = ((Keyframe)(ref val)).value * factor;
					((Keyframe)(ref val)).inTangent = ((Keyframe)(ref val)).inTangent * factor;
					((Keyframe)(ref val)).outTangent = ((Keyframe)(ref val)).outTangent * factor;
					array[i] = val;
				}
				SetKeys(curve, array);
			}
		}

		private static void SetKeys(AnimationCurve curve, Keyframe[] keys)
		{
			if (curve != null && keys != null)
			{
				curve.keys = Il2CppStructArray<Keyframe>.op_Implicit(keys);
			}
		}
	}
	internal static class Reactions
	{
		internal const string TheftLabel = "FroggosGTA_CarTheft";

		internal const string MinigameLabel = "FroggosGTA_Carjacking";

		internal static void Pursue(NPC npc, Player p)
		{
			if ((Object)(object)npc == (Object)null || (Object)(object)p == (Object)null || !npc.IsConscious)
			{
				return;
			}
			PoliceOfficer cop = ((Il2CppObjectBase)npc).TryCast<PoliceOfficer>();
			if ((Object)(object)cop == (Object)null)
			{
				return;
			}
			Try("stop cop driving", delegate
			{
				VehiclePatrolBehaviour vehiclePatrolBehaviour = cop.VehiclePatrolBehaviour;
				if (vehiclePatrolBehaviour != null)
				{
					((Behaviour)vehiclePatrolBehaviour).Disable();
				}
				VehiclePursuitBehaviour vehiclePursuitBehaviour = cop.VehiclePursuitBehaviour;
				if (vehiclePursuitBehaviour != null)
				{
					((Behaviour)vehiclePursuitBehaviour).Disable();
				}
			});
			Try("cop pursuit", delegate
			{
				cop.BeginFootPursuit_Networked(p.PlayerCode, true);
			});
			Say(npc, "Stop right there!");
		}

		internal static void AddTheft(Player p)
		{
			Try("add theft", delegate
			{
				//IL_000b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0016: Expected O, but got Unknown
				p.CrimeData.AddCrime((Crime)new Theft(), 1);
			});
		}

		internal static void Wanted(Player p)
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: 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)
			GtaConfig cfg = GtaMod.Cfg;
			if ((Object)(object)p == (Object)null || !cfg.WantedOnSteal.Value)
			{
				return;
			}
			PlayerCrimeData crime = p.CrimeData;
			if (crime.CurrentPursuitLevel < cfg.PursuitLevel)
			{
				Try("set pursuit level", delegate
				{
					//IL_000c: Unknown result type (might be due to invalid IL or missing references)
					crime.SetPursuitLevel(cfg.PursuitLevel);
				});
				GtaMod.Log.Msg($"Wanted: {cfg.PursuitLevel}.");
			}
			Try("record position", delegate
			{
				crime.RecordLastKnownPosition(true);
			});
			int officers = cfg.DispatchOfficers.Value;
			if (officers <= 0)
			{
				return;
			}
			Try("dispatch", delegate
			{
				//IL_000b: Unknown result type (might be due to invalid IL or missing references)
				PoliceStation closestPoliceStation = PoliceStation.GetClosestPoliceStation(((Component)p).transform.position);
				if (closestPoliceStation != null)
				{
					closestPoliceStation.Dispatch(officers, p, (EDispatchType)0, true);
				}
			});
		}

		internal static void Seen(Player p, string label, float seconds)
		{
			if (!((Object)(object)p == (Object)null) && GtaMod.Cfg.PoliceNotice.Value)
			{
				Try("crime visibility", delegate
				{
					p.Visibility.ApplyState(label, (EVisualState)7, seconds);
				});
			}
		}

		internal static void Unseen(Player p, string label)
		{
			if (!((Object)(object)p == (Object)null))
			{
				Try("crime visibility off", delegate
				{
					p.Visibility.RemoveState(label, 0f);
				});
			}
		}

		internal static void Say(NPC npc, string line)
		{
			Try("dialogue", delegate
			{
				npc.ShowWorldSpaceDialogue(line, 3f);
			});
		}

		private static void Try(string what, Action act)
		{
			try
			{
				act();
			}
			catch (Exception ex)
			{
				GtaMod.Verbose(what + " failed: " + ex.Message);
			}
		}
	}
	internal static class Siren
	{
		private static bool _muted;

		internal static void Tick()
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			Keyboard current = Keyboard.current;
			if (current == null || !((ButtonControl)current[GtaMod.Cfg.SirenKey]).wasPressedThisFrame)
			{
				return;
			}
			Player local = Player.Local;
			if ((Object)(object)local == (Object)null || !local.IsInVehicle || (Object)(object)local.CurrentVehicle == (Object)null)
			{
				return;
			}
			PoliceLight componentInChildren = ((Component)local.CurrentVehicle).GetComponentInChildren<PoliceLight>(true);
			if ((Object)(object)componentInChildren == (Object)null)
			{
				return;
			}
			if (((ButtonControl)current.leftShiftKey).isPressed || ((ButtonControl)current.rightShiftKey).isPressed)
			{
				_muted = !_muted;
				if ((Object)(object)componentInChildren.Siren != (Object)null)
				{
					if (_muted)
					{
						componentInChildren.Siren.Stop();
					}
					else if (componentInChildren.IsOn)
					{
						componentInChildren.Siren.Play();
					}
				}
				GtaMod.Log.Msg(_muted ? "Siren muted." : "Siren unmuted.");
			}
			else
			{
				componentInChildren.SetIsOn(!componentInChildren.IsOn);
				if (componentInChildren.IsOn && _muted && (Object)(object)componentInChildren.Siren != (Object)null)
				{
					componentInChildren.Siren.Stop();
				}
				GtaMod.Verbose("Police lights " + (componentInChildren.IsOn ? "on" : "off"));
			}
		}
	}
}