Decompiled source of Cartel Enforcer MONO v2.0.0

Mods/CartelEnforcer.dll

Decompiled 3 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using CartelEnforcer;
using FishNet;
using FishNet.Connection;
using FishNet.Managing;
using FishNet.Managing.Object;
using FishNet.Object;
using HarmonyLib;
using MelonLoader;
using MelonLoader.Preferences;
using MelonLoader.Utils;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using ScheduleOne;
using ScheduleOne.Audio;
using ScheduleOne.AvatarFramework;
using ScheduleOne.AvatarFramework.Equipping;
using ScheduleOne.Cartel;
using ScheduleOne.Combat;
using ScheduleOne.Core.Items.Framework;
using ScheduleOne.DevUtilities;
using ScheduleOne.Dialogue;
using ScheduleOne.Doors;
using ScheduleOne.Dragging;
using ScheduleOne.Economy;
using ScheduleOne.EntityFramework;
using ScheduleOne.GameTime;
using ScheduleOne.Graffiti;
using ScheduleOne.Interaction;
using ScheduleOne.ItemFramework;
using ScheduleOne.Law;
using ScheduleOne.Levelling;
using ScheduleOne.Lighting;
using ScheduleOne.Map;
using ScheduleOne.Messaging;
using ScheduleOne.Misc;
using ScheduleOne.Money;
using ScheduleOne.NPCs;
using ScheduleOne.NPCs.Behaviour;
using ScheduleOne.NPCs.CharacterClasses;
using ScheduleOne.NPCs.Framework;
using ScheduleOne.NPCs.Other;
using ScheduleOne.NPCs.Relation;
using ScheduleOne.NPCs.Schedules;
using ScheduleOne.ObjectScripts;
using ScheduleOne.Packaging;
using ScheduleOne.Persistence;
using ScheduleOne.PlayerScripts;
using ScheduleOne.Police;
using ScheduleOne.Product;
using ScheduleOne.Product.Packaging;
using ScheduleOne.Property;
using ScheduleOne.Quests;
using ScheduleOne.Storage;
using ScheduleOne.UI;
using ScheduleOne.UI.Handover;
using ScheduleOne.UI.MainMenu;
using ScheduleOne.UI.Phone.ContactsApp;
using ScheduleOne.Vehicles;
using ScheduleOne.Vehicles.AI;
using ScheduleOne.VoiceOver;
using TMPro;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Events;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(global::CartelEnforcer.CartelEnforcer), "Cartel Enforcer", "2.0.0", "XOWithSauce", null)]
[assembly: MelonColor]
[assembly: MelonOptionalDependencies(new string[] { "FishNet.Runtime" })]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: MelonPlatformDomain(/*Could not decode attribute arguments.*/)]
[assembly: VerifyLoaderVersion("0.7.2", true)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("ScheduleOne.Core")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("XOWithSauce")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCopyright("Copyright XOWithSauce 2026 Source MIT")]
[assembly: AssemblyDescription("Schedule I Cartel Enforcer Mod")]
[assembly: AssemblyFileVersion("2.0.0.0")]
[assembly: AssemblyInformationalVersion("2.0.0")]
[assembly: AssemblyProduct("Cartel Enforcer")]
[assembly: AssemblyTitle("CartelEnforcer")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/XOWithSauce/schedule-cartelenforcer")]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[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 CartelEnforcer
{
	public static class DealerActivity
	{
		[HarmonyPatch(typeof(Dealer), "DealerUnconscious")]
		public static class Dealer_DealerUnconscious_Patch
		{
			[HarmonyPrefix]
			public static bool Prefix(Dealer __instance)
			{
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				//IL_000c: Invalid comparison between Unknown and I4
				if ((int)__instance.DealerData.DealerType == 1)
				{
					List<Contract> list = new List<Contract>(__instance.ActiveContracts);
					List<Contract> list2 = new List<Contract>();
					List<Contract> list3 = new List<Contract>();
					foreach (Contract item in list)
					{
						lock (playerDealerStolenLock)
						{
							if (playerDealerStolen.ContainsKey(((Quest)item).GUID.ToString()))
							{
								list3.Add(item);
							}
							else
							{
								list2.Add(item);
							}
						}
					}
					if (list2.Count > 0)
					{
						foreach (Contract item2 in list2)
						{
							((Quest)item2).Fail(true);
						}
					}
					if (list3.Count > 0)
					{
						foreach (Contract item3 in list3)
						{
							Dealer dealer = null;
							int completionXP = 0;
							if (playerDealerStolen.TryGetValue(((Quest)item3).GUID.ToString(), out var value))
							{
								dealer = value.Item1;
								completionXP = value.Item2;
							}
							Customer component = ((Component)item3.Customer).GetComponent<Customer>();
							if ((Object)(object)component != (Object)null && (Object)(object)component.CurrentContract != (Object)null)
							{
								if ((Object)(object)component.CurrentContract.Dealer != (Object)null && (Object)(object)component.CurrentContract.Dealer == (Object)(object)__instance)
								{
									component.CurrentContract.Dealer = dealer;
								}
								((Quest)component.CurrentContract).CompletionXP = completionXP;
							}
							lock (playerDealerStolenLock)
							{
								playerDealerStolen.Remove(((Quest)item3).GUID.ToString());
							}
							__instance.ActiveContracts.Remove(item3);
							__instance.currentContract = null;
						}
					}
					return false;
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(Customer), "ProcessHandover")]
		public static class Customer_ProcessHandover_Patch
		{
			private static readonly string name = "ProcessHandover";

			[HarmonyPrefix]
			public static bool Prefix(Customer __instance, EHandoverOutcome outcome, Contract contract, List<ItemInstance> items, bool handoverByPlayer, bool giveBonuses = true)
			{
				//IL_0022: 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)
				if (handoverByPlayer)
				{
					return true;
				}
				if ((Object)(object)contract.Dealer == (Object)null)
				{
					CheckIntercept(__instance, contract, outcome, handoverByPlayer);
					return true;
				}
				CheckPlayerDealerStolen(__instance, contract, outcome);
				return true;
			}

			public static void CheckPlayerDealerStolen(Customer __instance, Contract contract, EHandoverOutcome outcome)
			{
				//IL_005c: 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_0078: Unknown result type (might be due to invalid IL or missing references)
				//IL_007e: Unknown result type (might be due to invalid IL or missing references)
				if (!playerDealerStolen.ContainsKey(((Quest)contract).GUID.ToString()))
				{
					return;
				}
				playerDealerStolen.TryGetValue(((Quest)contract).GUID.ToString(), out var value);
				if (value == null)
				{
					return;
				}
				Dealer item = value.Item1;
				int item2 = value.Item2;
				float num = Vector3.Distance(__instance.NPC.CenterPoint, ((NPC)contract.Dealer).CenterPoint);
				float num2 = Vector3.Distance(__instance.NPC.CenterPoint, ((NPC)item).CenterPoint);
				if (num2 < num && num2 < 2f)
				{
					if (contract.Dealer.ActiveContracts.Count != 0 && (Object)(object)contract.Dealer.ActiveContracts[0] == (Object)(object)contract)
					{
						((Quest)contract.Dealer.ActiveContracts[0]).Fail(true);
					}
					contract.Dealer = item;
					((Quest)contract).CompletionXP = item2;
					contract.completedContractsIncremented = true;
				}
				else if (num < num2 && num < 2f)
				{
					if (item.ActiveContracts.Count != 0 && (Object)(object)item.ActiveContracts[0] == (Object)(object)contract)
					{
						((Quest)item.ActiveContracts[0]).Fail(true);
					}
					if (CartelEnforcer.currentConfig.stealBackCustomers && __instance.NPC.RelationData.RelationDelta > 1f)
					{
						float relationDelta = Mathf.Clamp(Mathf.Max(__instance.NPC.RelationData.RelationDelta * 0.85f, 0.2f), 0f, 5f);
						__instance.NPC.RelationData.RelationDelta = relationDelta;
					}
				}
				lock (playerDealerStolenLock)
				{
					playerDealerStolen.Remove(((Quest)contract).GUID.ToString());
				}
				consumedGUIDs.Add(((Quest)contract).GUID.ToString());
			}

			public static void CheckIntercept(Customer __instance, Contract contract, EHandoverOutcome outcome, bool handoverByPlayer)
			{
				if (!CartelEnforcer.currentConfig.interceptDeals)
				{
					return;
				}
				string key = ((Quest)contract).GUID.ToString();
				if (InterceptEvent.contractGuids.ContainsKey(key))
				{
					if (handoverByPlayer)
					{
						InterceptEvent.contractGuids[key].CompletedByPlayer = true;
					}
					else
					{
						InterceptEvent.contractGuids[key].CompletedByCartel = true;
					}
				}
			}
		}

		[HarmonyPatch(typeof(CartelDealer), "RandomizeInventory")]
		public static class CartelDealer_RandomizeInventory_Patch
		{
			[HarmonyPrefix]
			public static bool Prefix(CartelDealer __instance)
			{
				//IL_0011: Unknown result type (might be due to invalid IL or missing references)
				//IL_0017: Invalid comparison between Unknown and I4
				if (CartelEnforcer.currentConfig.alliedExtensions && (int)NetworkSingleton<Cartel>.Instance.Status == 1 && ((Dealer)__instance).IsRecruited)
				{
					return false;
				}
				bool flag = false;
				foreach (ItemSlot itemSlot in ((NPC)__instance).Inventory.ItemSlots)
				{
					if (itemSlot.ItemInstance != null)
					{
						flag = true;
					}
				}
				if (flag)
				{
					return false;
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(Dealer), "CheckNotifyPlayerOfDeal")]
		public static class Dealer_CheckNotifyPlayerOfDeal_Patch
		{
			[HarmonyPrefix]
			public static bool Prefix(Dealer __instance, Dealer cartelDealer, Contract contract)
			{
				//IL_0011: Unknown result type (might be due to invalid IL or missing references)
				//IL_0017: Invalid comparison between Unknown and I4
				if (CartelEnforcer.currentConfig.alliedExtensions && (int)NetworkSingleton<Cartel>.Instance.Status == 1 && cartelDealer.IsRecruited)
				{
					return false;
				}
				return true;
			}
		}

		[CompilerGenerated]
		private static class <>O
		{
			public static UnityAction <0>__OnDealerDied;
		}

		private static List<Dealer> allDealers = new List<Dealer>();

		public static CartelDealer[] allCartelDealers;

		public static CartelDealerConfig dealerConfig;

		public static float currentDealerActivity = 0f;

		public static float previousDealerActivity = 0f;

		private static float maxActivity = 1f;

		private static float minActivity = -1f;

		private static int defaultStayInsideStart = 200;

		private static int defaultStayInsideEnd = 2000;

		private static int defaultStayInsideDur = 1080;

		public static int currentStayInsideStart = 0;

		public static int currentStayInsideEnd = 0;

		public static int currentStayInsideDur = 0;

		public static Dictionary<string, Tuple<Dealer, int>> playerDealerStolen = new Dictionary<string, Tuple<Dealer, int>>();

		public static readonly object playerDealerStolenLock = new object();

		public static List<string> consumedGUIDs = new List<string>();

		public static IEnumerator EvaluateDealerState()
		{
			yield return CartelEnforcer.Wait5;
			if (allCartelDealers == null)
			{
				allCartelDealers = Object.FindObjectsOfType<CartelDealer>(true);
			}
			Dealer[] array = Object.FindObjectsOfType<Dealer>(true);
			foreach (Dealer val in array)
			{
				if ((int)val.DealerData.DealerType == 0)
				{
					allDealers.Add(val);
				}
			}
			currentStayInsideStart = defaultStayInsideStart;
			currentStayInsideEnd = defaultStayInsideEnd;
			currentStayInsideDur = defaultStayInsideDur;
			SetupDealers();
			TimeManager instance = NetworkSingleton<TimeManager>.Instance;
			instance.onDayPass = (Action)Delegate.Combine(instance.onDayPass, new Action(OnDayPassChange));
			while (CartelEnforcer.registered)
			{
				yield return CartelEnforcer.Wait60;
				if (!CartelEnforcer.registered)
				{
					yield break;
				}
				if (!CartelEnforcer.currentConfig.enhancedDealers || (NetworkSingleton<TimeManager>.Instance.CurrentTime < 1620 && NetworkSingleton<TimeManager>.Instance.CurrentTime > 359))
				{
					continue;
				}
				bool isHostile = true;
				if ((int)NetworkSingleton<Cartel>.Instance.Status != 2)
				{
					isHostile = false;
				}
				if (currentDealerActivity != previousDealerActivity)
				{
					int num2;
					int num4;
					int num5;
					if (currentDealerActivity > 0f)
					{
						int minSumFrom24HourTime = TimeManager.GetMinSumFrom24HourTime(currentStayInsideStart);
						int minSumFrom24HourTime2 = TimeManager.GetMinSumFrom24HourTime(359);
						int num = Mathf.RoundToInt(Mathf.Lerp((float)minSumFrom24HourTime, (float)minSumFrom24HourTime2, currentDealerActivity));
						num2 = TimeManager.Get24HourTimeFromMinSum(num);
						if (num2 == 400)
						{
							num2 = 359;
						}
						int minSumFrom24HourTime3 = TimeManager.GetMinSumFrom24HourTime(currentStayInsideEnd);
						int minSumFrom24HourTime4 = TimeManager.GetMinSumFrom24HourTime(1620);
						int num3 = Mathf.RoundToInt(Mathf.Lerp((float)minSumFrom24HourTime3, (float)minSumFrom24HourTime4, currentDealerActivity));
						num4 = TimeManager.Get24HourTimeFromMinSum(num3);
						num5 = num3 - num;
					}
					else if (currentDealerActivity < 0f)
					{
						float num6 = 0f - currentDealerActivity;
						int minSumFrom24HourTime5 = TimeManager.GetMinSumFrom24HourTime(currentStayInsideStart);
						int minSumFrom24HourTime6 = TimeManager.GetMinSumFrom24HourTime(2);
						int num7 = Mathf.RoundToInt(Mathf.Lerp((float)minSumFrom24HourTime5, (float)minSumFrom24HourTime6, num6));
						num2 = TimeManager.Get24HourTimeFromMinSum(num7);
						int minSumFrom24HourTime7 = TimeManager.GetMinSumFrom24HourTime(currentStayInsideEnd);
						int minSumFrom24HourTime8 = TimeManager.GetMinSumFrom24HourTime(2359);
						int num8 = Mathf.RoundToInt(Mathf.Lerp((float)minSumFrom24HourTime7, (float)minSumFrom24HourTime8, num6));
						num4 = TimeManager.Get24HourTimeFromMinSum(num8);
						num5 = num8 - num7;
					}
					else
					{
						num2 = defaultStayInsideStart;
						num4 = defaultStayInsideEnd;
						num5 = defaultStayInsideDur;
					}
					currentStayInsideStart = num2;
					currentStayInsideEnd = num4;
					currentStayInsideDur = num5;
					CartelDealer[] array2 = allCartelDealers;
					foreach (CartelDealer d in array2)
					{
						yield return CartelEnforcer.Wait05;
						if (!CartelEnforcer.registered)
						{
							yield break;
						}
						ApplyNewEventState(d, currentStayInsideStart, currentStayInsideEnd, currentStayInsideDur);
					}
				}
				previousDealerActivity = currentDealerActivity;
				bool safetyThresholdMet = false;
				if (dealerConfig.SafetyEnabled && currentDealerActivity <= dealerConfig.SafetyThreshold)
				{
					safetyThresholdMet = true;
					CartelDealer[] array2 = allCartelDealers;
					foreach (CartelDealer d in array2)
					{
						yield return CartelEnforcer.Wait05;
						if (!CartelEnforcer.registered)
						{
							yield break;
						}
						ApplyNewEventState(d, 600, 559, 1439);
						d.SetIsAcceptingDeals(false);
					}
				}
				if (safetyThresholdMet)
				{
					continue;
				}
				if (!isHostile)
				{
					CartelDealer[] array2 = allCartelDealers;
					foreach (CartelDealer d in array2)
					{
						yield return CartelEnforcer.Wait2;
						if (!CartelEnforcer.registered)
						{
							yield break;
						}
						if (!((NPC)d).isInBuilding && !((NPC)d).Movement.HasDestination && !((NPC)d).Health.IsDead && !((NPC)d).Health.IsKnockedOut)
						{
							WalkToInterestPoint(d);
						}
					}
					yield return CartelEnforcer.Wait60;
					if (!CartelEnforcer.registered)
					{
						yield break;
					}
				}
				else if (NetworkSingleton<TimeManager>.Instance.CurrentTime >= currentStayInsideEnd || NetworkSingleton<TimeManager>.Instance.CurrentTime <= currentStayInsideStart)
				{
					CartelEnforcer.coros.Add(MelonCoroutines.Start(StartActiveSignal()));
				}
			}
			yield return null;
		}

		public static void ApplyNewEventState(CartelDealer dealer, int inStart, int inEnd, int inDur)
		{
			if ((Object)(object)InterceptEvent.interceptor != (Object)null && (Object)(object)InterceptEvent.interceptor == (Object)(object)dealer)
			{
				return;
			}
			NPCEvent_StayInBuilding val = null;
			if (((NPC)dealer).Behaviour.ScheduleManager.ActionList != null)
			{
				foreach (NPCAction action in ((NPC)dealer).Behaviour.ScheduleManager.ActionList)
				{
					NPCEvent_StayInBuilding val2 = (NPCEvent_StayInBuilding)(object)((action is NPCEvent_StayInBuilding) ? action : null);
					if (val2 != null)
					{
						val = val2;
					}
				}
			}
			if ((Object)(object)val != (Object)null)
			{
				((NPCAction)val).StartTime = inStart;
				((NPCEvent)val).EndTime = inEnd;
				((NPCEvent)val).Duration = inDur;
			}
		}

		public static void SetupDealers()
		{
			//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_0565: Unknown result type (might be due to invalid IL or missing references)
			//IL_056f: Expected O, but got Unknown
			//IL_053c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0541: Unknown result type (might be due to invalid IL or missing references)
			//IL_0547: Expected O, but got Unknown
			string text = "";
			Object obj = Resources.Load(dealerConfig.CartelDealerWeapon.ToLower() switch
			{
				"m1911" => "Avatar/Equippables/M1911", 
				"goldenm1911" => "Avatar/Equippables/M1911_Gold", 
				"revolver" => "Avatar/Equippables/Revolver", 
				"knife" => "Avatar/Equippables/Knife", 
				"brokenbottle" => "Avatar/Equippables/BrokenBottle", 
				"shotgun" => "Avatar/Equippables/PumpShotgun", 
				_ => "Avatar/Equippables/M1911", 
			});
			Object obj2 = ((obj is GameObject) ? obj : null);
			_ = obj2 == (Object)null;
			AvatarEquippable component = Object.Instantiate<GameObject>((GameObject)(object)obj2, new Vector3(0f, -5f, 0f), Quaternion.identity, (Transform)null).GetComponent<AvatarEquippable>();
			if (!((Component)component).gameObject.activeSelf)
			{
				((Component)component).gameObject.SetActive(true);
			}
			AvatarRangedWeapon val = (AvatarRangedWeapon)(object)((component is AvatarRangedWeapon) ? component : null);
			AvatarMeleeWeapon val2 = (AvatarMeleeWeapon)(object)((component is AvatarMeleeWeapon) ? component : null);
			if ((Object)(object)val != (Object)null && dealerConfig.CartelDealerLethality > 0f)
			{
				val.Damage = Mathf.Lerp(val.Damage, val.Damage * 2f, dealerConfig.CartelDealerLethality);
				val.AimTime_Max = Mathf.Lerp(val.AimTime_Max, val.AimTime_Max * 0.5f, dealerConfig.CartelDealerLethality);
				val.AimTime_Min = Mathf.Lerp(val.AimTime_Min, val.AimTime_Min * 0.5f, dealerConfig.CartelDealerLethality);
				val.HitChance_MaxRange = Mathf.Lerp(val.HitChance_MaxRange, val.HitChance_MaxRange * 2f, dealerConfig.CartelDealerLethality);
				val.HitChance_MinRange = Mathf.Lerp(val.HitChance_MinRange, val.HitChance_MinRange * 2f, dealerConfig.CartelDealerLethality);
				((AvatarWeapon)val).MaxUseRange = Mathf.Lerp(((AvatarWeapon)val).MaxUseRange, ((AvatarWeapon)val).MaxUseRange * 2f, dealerConfig.CartelDealerLethality);
				((AvatarWeapon)val).MinUseRange = Mathf.Lerp(((AvatarWeapon)val).MinUseRange, ((AvatarWeapon)val).MinUseRange * 0.5f, dealerConfig.CartelDealerLethality);
				val.MaxFireRate = Mathf.Lerp(val.MaxFireRate, val.MaxFireRate * 0.5f, dealerConfig.CartelDealerLethality);
				val.ReloadTime = Mathf.Lerp(val.ReloadTime, val.ReloadTime * 0.5f, dealerConfig.CartelDealerLethality);
			}
			else if ((Object)(object)val2 != (Object)null && dealerConfig.CartelDealerLethality > 0f)
			{
				val2.Damage = Mathf.Lerp(val2.Damage, val2.Damage * 2f, dealerConfig.CartelDealerLethality);
				((AvatarWeapon)val2).CooldownDuration = Mathf.Lerp(((AvatarWeapon)val2).CooldownDuration, ((AvatarWeapon)val2).CooldownDuration * 0.5f, dealerConfig.CartelDealerLethality);
				val2.AttackRange = Mathf.Lerp(val2.AttackRange, val2.AttackRange * 2f, dealerConfig.CartelDealerLethality);
				val2.AttackRadius = Mathf.Lerp(val2.AttackRadius, val2.AttackRadius * 2f, dealerConfig.CartelDealerLethality);
				((AvatarWeapon)val2).MaxUseRange = Mathf.Lerp(((AvatarWeapon)val2).MaxUseRange, ((AvatarWeapon)val2).MaxUseRange * 2f, dealerConfig.CartelDealerLethality);
			}
			CartelDealer[] array = allCartelDealers;
			foreach (CartelDealer dealer in array)
			{
				((NPC)dealer).NPCData.Movement.WalkSpeed = dealerConfig.CartelDealerWalkSpeed;
				((NPC)dealer).NPCData.Health.MaxHealth = dealerConfig.CartelDealerHP;
				((NPC)dealer).Health.Health = dealerConfig.CartelDealerHP;
				AvatarWeapon val3 = null;
				if (component is AvatarWeapon)
				{
					val3 = (AvatarWeapon)(object)((component is AvatarWeapon) ? component : null);
				}
				if ((Object)(object)val3 != (Object)null)
				{
					((NPC)dealer).Behaviour.CombatBehaviour.SetDefaultWeapon(val3);
					if ((Object)(object)((NPC)dealer).Avatar != (Object)null)
					{
						component.Equip(((NPC)dealer).Avatar);
					}
				}
				((NPC)dealer).NPCData.Behaviour.DefaultAggression = 1f;
				NPCEvent_StayInBuilding val4 = null;
				if (((NPC)dealer).Behaviour.ScheduleManager.ActionList != null)
				{
					foreach (NPCAction action in ((NPC)dealer).Behaviour.ScheduleManager.ActionList)
					{
						NPCEvent_StayInBuilding val5 = (NPCEvent_StayInBuilding)(object)((action is NPCEvent_StayInBuilding) ? action : null);
						if (val5 != null)
						{
							val4 = val5;
						}
					}
					if ((Object)(object)val4 != (Object)null)
					{
						((NPCAction)val4).StartTime = defaultStayInsideStart;
						((NPCEvent)val4).EndTime = defaultStayInsideEnd;
						((NPCEvent)val4).Duration = defaultStayInsideDur;
						((NPCAction)val4).onEnded = (Action)Delegate.Combine(((NPCAction)val4).onEnded, new Action(onStayInsideEnd));
					}
				}
				UnityEvent onDieOrKnockedOut = ((NPC)dealer).Health.onDieOrKnockedOut;
				object obj3 = <>O.<0>__OnDealerDied;
				if (obj3 == null)
				{
					UnityAction val6 = OnDealerDied;
					<>O.<0>__OnDealerDied = val6;
					obj3 = (object)val6;
				}
				onDieOrKnockedOut.AddListener((UnityAction)obj3);
				((NPC)dealer).Health.onDieOrKnockedOut.AddListener(new UnityAction(TrySpawnGoonsOnDeath));
				void TrySpawnGoonsOnDeath()
				{
					//IL_003c: Unknown result type (might be due to invalid IL or missing references)
					//IL_004a: Unknown result type (might be due to invalid IL or missing references)
					//IL_004f: Unknown result type (might be due to invalid IL or missing references)
					//IL_00c3: 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_0064: Unknown result type (might be due to invalid IL or missing references)
					//IL_0069: Unknown result type (might be due to invalid IL or missing references)
					//IL_0098: Unknown result type (might be due to invalid IL or missing references)
					//IL_009d: 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_00b1: Unknown result type (might be due to invalid IL or missing references)
					//IL_00db: Unknown result type (might be due to invalid IL or missing references)
					if ((!(Random.Range(0f, 1f) > 0.5f) || CartelEnforcer.currentConfig.debugMode) && NetworkSingleton<Cartel>.Instance.GoonPool.UnspawnedGoonCount >= 2)
					{
						float num = default(float);
						Player closestPlayer = PlayerManager.GetClosestPlayer(((NPC)dealer).CenterPoint, ref num, (List<Player>)null);
						Vector3 val8 = Vector3.zero;
						int num2 = 4;
						int num3 = 0;
						do
						{
							if (!CartelEnforcer.registered)
							{
								return;
							}
							if (num3 == num2)
							{
								break;
							}
							Vector3 onUnitSphere = Random.onUnitSphere;
							onUnitSphere.y = 0f;
							((Vector3)(ref onUnitSphere)).Normalize();
							float num4 = Random.Range(16f, 24f);
							val8 = ((Component)dealer).transform.position + onUnitSphere * num4;
							num3++;
						}
						while (closestPlayer.IsPointVisibleToPlayer(val8, 30f, 5f));
						if (!(val8 == Vector3.zero))
						{
							List<CartelGoon> list2 = NetworkSingleton<Cartel>.Instance.GoonPool.SpawnMultipleGoons(val8, 2, true);
							foreach (CartelGoon item in list2)
							{
								((NPC)item).Movement.WarpToNavMesh();
								if (Random.Range(0f, 1f) > 0.7f && AmbushOverrides.RangedWeapons != null && AmbushOverrides.RangedWeapons.Length != 0)
								{
									((NPC)item).Behaviour.CombatBehaviour.SetDefaultWeapon(AmbushOverrides.RangedWeapons[Random.Range(0, AmbushOverrides.RangedWeapons.Length)]);
								}
								else if (AmbushOverrides.MeleeWeapons != null && AmbushOverrides.MeleeWeapons.Length != 0)
								{
									((NPC)item).Behaviour.CombatBehaviour.SetDefaultWeapon(AmbushOverrides.MeleeWeapons[Random.Range(0, AmbushOverrides.MeleeWeapons.Length)]);
								}
								item.AttackEntity(((Component)closestPlayer).GetComponent<ICombatTargetable>(), true);
							}
							CartelEnforcer.coros.Add(MelonCoroutines.Start(DespawnDefenderGoonsSoon(list2)));
						}
					}
				}
				void onStayInsideEnd()
				{
					if ((!InterceptEvent.interceptingDeal || !((Object)(object)InterceptEvent.interceptor != (Object)null) || !((Object)(object)dealer == (Object)(object)InterceptEvent.interceptor)) && ((Dealer)dealer).ActiveContracts.Count == 0)
					{
						if (!dealer.IsAcceptingDeals)
						{
							dealer.SetIsAcceptingDeals(true);
						}
						CartelEnforcer.coros.Add(MelonCoroutines.Start(WalkToInterestPoint(dealer, CartelEnforcer.Wait5)));
					}
				}
			}
			List<CartelDealer> list = new List<CartelDealer>();
			array = allCartelDealers;
			foreach (CartelDealer val7 in array)
			{
				if ((Object)(object)((NPC)val7).Avatar.CurrentSettings == (Object)null)
				{
					list.Add(val7);
				}
			}
			if (list.Count > 0)
			{
				foreach (CartelDealer item2 in list)
				{
					item2.RandomizeAppearance();
				}
			}
			list.Clear();
			list = null;
			array = allCartelDealers;
			for (int i = 0; i < array.Length; i++)
			{
				((NPC)array[i]).NPCData.Inventory.ClearInventoryOnNewDay = false;
			}
		}

		public static IEnumerator DespawnDefenderGoonsSoon(List<CartelGoon> goons)
		{
			int maxHoursWaited = 2;
			int goonsDead = 0;
			for (int i = 0; i < maxHoursWaited; i++)
			{
				yield return CartelEnforcer.Wait60;
				foreach (CartelGoon goon in goons)
				{
					if ((((NPC)goon).Health.IsDead || ((NPC)goon).Health.IsKnockedOut) && goon.IsGoonSpawned)
					{
						goonsDead++;
						goon.Despawn();
					}
				}
				if (goonsDead == goons.Count)
				{
					break;
				}
			}
			foreach (CartelGoon goon2 in goons)
			{
				if (goon2.IsGoonSpawned)
				{
					goon2.Despawn();
				}
			}
			yield return null;
		}

		public static IEnumerator StartActiveSignal()
		{
			Dictionary<EMapRegion, Contract> validContracts = new Dictionary<EMapRegion, Contract>();
			foreach (Dealer playerDealer in allDealers)
			{
				yield return CartelEnforcer.Wait01;
				if (!CartelEnforcer.registered)
				{
					yield break;
				}
				if (playerDealer.ActiveContracts.Count == 0)
				{
					continue;
				}
				Contract contract = playerDealer.ActiveContracts[Random.Range(0, playerDealer.ActiveContracts.Count)];
				string text = ((Quest)contract).GUID.ToString();
				if (!Enumerable.Contains(InterceptEvent.contractGuids.Keys, text) && !validContracts.ContainsValue(contract) && !consumedGUIDs.Contains(text) && !playerDealerStolen.ContainsKey(text) && ((Quest)contract).GetMinsUntilExpiry() > 60)
				{
					EMapRegion regionFromPosition = Singleton<Map>.Instance.GetRegionFromPosition(contract.DeliveryLocation.CustomerStandPoint.position);
					if (!validContracts.ContainsKey(regionFromPosition))
					{
						validContracts.Add(regionFromPosition, contract);
					}
				}
			}
			List<Customer> cList = new List<Customer>();
			for (int i = 0; i < Customer.UnlockedCustomers.Count; i++)
			{
				cList.Add(Customer.UnlockedCustomers[i]);
			}
			List<Customer> validCustomers = new List<Customer>();
			while (true)
			{
				yield return CartelEnforcer.Wait01;
				if (!CartelEnforcer.registered)
				{
					break;
				}
				Customer val = cList[Random.Range(0, cList.Count)];
				if ((Object)(object)val.CurrentContract == (Object)null && (Object)(object)val.AssignedDealer == (Object)null && val.offeredContractInfo != null)
				{
					validCustomers.Add(val);
				}
				cList.Remove(val);
				if (cList.Count > 0)
				{
					continue;
				}
				CartelDealer[] array = allCartelDealers;
				int num = 0;
				while (true)
				{
					if (num < array.Length)
					{
						CartelDealer d = array[num];
						Contract contract = null;
						yield return CartelEnforcer.Wait2;
						if (!CartelEnforcer.registered)
						{
							break;
						}
						if (NetworkSingleton<TimeManager>.Instance.CurrentTime >= currentStayInsideEnd || NetworkSingleton<TimeManager>.Instance.CurrentTime <= currentStayInsideStart)
						{
							if ((!((Object)(object)InterceptEvent.interceptor != (Object)null) || !((Object)(object)InterceptEvent.interceptor == (Object)(object)d)) && !((NPC)d).Health.IsDead && !((NPC)d).Health.IsKnockedOut && ((Dealer)d).ActiveContracts != null)
							{
								if (((Dealer)d).ActiveContracts.Count == 0)
								{
									bool actionTaken = false;
									if (validContracts.Count > 0 && validContracts.ContainsKey(((NPC)d).Region) && Random.Range(0.01f, 1f) < dealerConfig.StealDealerContractChance && dealerConfig.StealDealerContractChance != 0f)
									{
										contract = validContracts[((NPC)d).Region];
										if ((Object)(object)contract != (Object)null && (int)((Quest)contract).State == 1 && !playerDealerStolen.ContainsKey(((Quest)contract).GUID.ToString()) && !consumedGUIDs.Contains(((Quest)contract).GUID.ToString()))
										{
											int completionXP = ((Quest)contract).CompletionXP;
											((Quest)contract).CompletionXP = 0;
											contract.completedContractsIncremented = false;
											Dealer dealer = contract.Dealer;
											lock (playerDealerStolenLock)
											{
												playerDealerStolen.Add(((Quest)contract).GUID.ToString(), new Tuple<Dealer, int>(dealer, completionXP));
											}
											((Dealer)d).AddContract(contract);
											if (!((Behaviour)((Dealer)d)._attendDealBehaviour).Active)
											{
												((Dealer)d).CheckAttendStart();
											}
											actionTaken = true;
										}
									}
									else if (validCustomers.Count > 0 && Random.Range(0.01f, 1f) < dealerConfig.StealPlayerPendingChance && dealerConfig.StealPlayerPendingChance != 0f)
									{
										Customer c = validCustomers[Random.Range(0, validCustomers.Count)];
										if ((Object)(object)c.CurrentContract == (Object)null && (Object)(object)c.AssignedDealer == (Object)null && c.offeredContractInfo != null)
										{
											ContractInfo contractInfo = new ContractInfo();
											contractInfo.DeliveryLocation = c.offeredContractInfo.DeliveryLocation;
											contractInfo.DeliveryLocationGUID = c.offeredContractInfo.DeliveryLocationGUID;
											contractInfo.Payment = c.offeredContractInfo.Payment;
											contractInfo.Expires = c.offeredContractInfo.Expires;
											contractInfo.DeliveryWindow = c.offeredContractInfo.DeliveryWindow;
											contractInfo.PickupScheduleIndex = c.offeredContractInfo.PickupScheduleIndex;
											contractInfo.ExpiresAfter = c.offeredContractInfo.ExpiresAfter;
											contractInfo.IsCounterOffer = c.offeredContractInfo.IsCounterOffer;
											contractInfo.Products = c.offeredContractInfo.Products;
											c.ExpireOffer();
											yield return CartelEnforcer.Wait01;
											if (!CartelEnforcer.registered)
											{
												break;
											}
											c.offeredContractInfo = contractInfo;
											EDealWindow dealWindow = ((Dealer)d).GetDealWindow();
											contract = c.ContractAccepted(dealWindow, false, (Dealer)(object)d);
											if ((Object)(object)contract != (Object)null)
											{
												((Quest)contract).CompletionXP = 0;
												contract.completedContractsIncremented = false;
												((Dealer)d).AddContract(contract);
												if (!((Behaviour)((Dealer)d)._attendDealBehaviour).Active)
												{
													((Dealer)d).CheckAttendStart();
												}
												actionTaken = true;
											}
										}
										validCustomers.Remove(c);
									}
									if (!actionTaken)
									{
										if (!((NPC)d).isInBuilding && !((NPC)d).Movement.HasDestination)
										{
											WalkToInterestPoint(d);
										}
									}
									else if ((Object)(object)contract != (Object)null && (Object)(object)d != (Object)null)
									{
										CartelInventory.FulfillContractItems(contract, d);
									}
								}
								else if (!((Behaviour)((Dealer)d)._attendDealBehaviour).Active)
								{
									((Dealer)d).CheckAttendStart();
								}
							}
							num++;
							continue;
						}
					}
					cList.Clear();
					validCustomers.Clear();
					validContracts.Clear();
					break;
				}
				break;
			}
		}

		public static bool IsWalkingEnabled(CartelDealer d)
		{
			if (!CartelEnforcer.currentConfig.enhancedDealers)
			{
				return false;
			}
			if (!dealerConfig.FreeTimeWalking)
			{
				return false;
			}
			if (InterceptEvent.interceptingDeal && (Object)(object)InterceptEvent.interceptor != (Object)null && (Object)(object)InterceptEvent.interceptor == (Object)(object)d)
			{
				return false;
			}
			if (((Dealer)d).ActiveContracts.Count > 0)
			{
				return false;
			}
			if (((NPC)d).Health.IsDead || ((NPC)d).Health.IsKnockedOut)
			{
				return false;
			}
			if (NetworkSingleton<TimeManager>.Instance.CurrentTime < currentStayInsideEnd && NetworkSingleton<TimeManager>.Instance.CurrentTime > currentStayInsideStart)
			{
				return false;
			}
			if ((Object)(object)((NPC)d).Behaviour.GetBehaviour("Smoke Break") != (Object)null && ((NPC)d).Behaviour.GetBehaviour("Smoke Break").Active)
			{
				return false;
			}
			if ((Object)(object)((NPC)d).Behaviour.activeBehaviour != (Object)null && (Object)(object)((NPC)d).Behaviour.activeBehaviour == (Object)(object)((NPC)d).Behaviour.GenericDialogueBehaviour && (Object)(object)((NPC)d).Behaviour.GenericDialogueBehaviour.targetPlayer != (Object)null)
			{
				return false;
			}
			return true;
		}

		public static void WalkToInterestPoint(CartelDealer d)
		{
			//IL_009d: 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_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: 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_00f5: 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_005e: 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)
			if (!IsWalkingEnabled(d))
			{
				return;
			}
			if (Random.Range(0f, 1f) > 0.5f)
			{
				DeliveryLocation randomUnscheduledDeliveryLocation = Singleton<Map>.instance.Regions[((NPC)d).Region].GetRandomUnscheduledDeliveryLocation();
				((NPC)d).Movement.SetDestination(randomUnscheduledDeliveryLocation.CustomerStandPoint.position);
			}
			else
			{
				List<DeadDrop> list = DeadDrop.DeadDrops.FindAll((DeadDrop drop) => drop.Region == ((NPC)d).Region);
				DeadDrop val = list[Random.Range(0, list.Count)];
				_ = ((Component)val).transform.position;
				Vector3 val2 = ((Component)val).transform.position + ((Component)val).transform.forward * 1.6f + Vector3.down * 1.4f;
				Vector3 val3 = default(Vector3);
				((NPC)d).Movement.GetClosestReachablePoint(val2, ref val3);
				if (val3 != Vector3.zero)
				{
					((NPC)d).Movement.SetDestination(val3);
				}
			}
			if (!d.IsAcceptingDeals)
			{
				d.SetIsAcceptingDeals(true);
			}
		}

		public static IEnumerator WalkToInterestPoint(CartelDealer d, WaitForSeconds delay)
		{
			yield return delay;
			WalkToInterestPoint(d);
		}

		public static void OnDealerDied()
		{
			currentDealerActivity = Mathf.Clamp(currentDealerActivity - dealerConfig.DealerActivityDecreasePerKill, minActivity, maxActivity);
		}

		public static void OnDayPassChange()
		{
			currentDealerActivity = Mathf.Clamp(currentDealerActivity + dealerConfig.DealerActivityIncreasePerDay, minActivity, maxActivity);
		}

		public static IEnumerator OnCartelCustomerDeal(CartelCustomerDeal dealEvent, bool started)
		{
			yield return CartelEnforcer.Wait2;
			if (started)
			{
				List<Customer> list = Customer.LockedCustomers.FindAll((Customer customer) => customer.NPC.Region == ((CartelActivity)dealEvent).Region);
				if (list.Count == 0)
				{
					((CartelActivity)dealEvent).Deactivate();
					yield break;
				}
				int num = Random.Range(0, list.Count);
				Customer val = null;
				for (int num2 = 0; num2 < list.Count; num2++)
				{
					val = list[num];
					bool flag = true;
					if ((Object)(object)val.CurrentContract != (Object)null)
					{
						flag = false;
					}
					if (!val.NPC.IsConscious)
					{
						flag = false;
					}
					int orderTime = val.customerData.OrderTime;
					int num3 = TimeManager.AddMinutesTo24HourTime(orderTime, 240);
					if (!NetworkSingleton<TimeManager>.Instance.IsCurrentTimeWithinRange(orderTime, num3))
					{
						flag = false;
					}
					if (!flag)
					{
						if (num2 == list.Count - 1)
						{
							((CartelActivity)dealEvent).Deactivate();
							yield break;
						}
						num = (num + 1) % list.Count;
					}
				}
				if ((Object)(object)val == (Object)null)
				{
					((CartelActivity)dealEvent).Deactivate();
					yield break;
				}
				EQuality correspondingQuality = StandardsMethod.GetCorrespondingQuality(val.customerData.Standards);
				List<ProductTypeAffinity> source = new List<ProductTypeAffinity>(val.CustomerData.DefaultAffinityData.ProductAffinities);
				source = source.OrderByDescending((ProductTypeAffinity x) => x.Affinity).ToList();
				bool flag2 = false;
				foreach (ItemSlot allSlot in ((Dealer)dealEvent.dealer).GetAllSlots())
				{
					if (allSlot.ItemInstance == null)
					{
						continue;
					}
					ItemInstance itemInstance = allSlot.ItemInstance;
					ProductItemInstance val2 = (ProductItemInstance)(object)((itemInstance is ProductItemInstance) ? itemInstance : null);
					if (val2 != null)
					{
						if (((QualityItemInstance)val2).Quality < correspondingQuality)
						{
							flag2 = true;
							((QualityItemInstance)val2).Quality = correspondingQuality;
						}
						else
						{
							flag2 = true;
						}
						break;
					}
				}
				if (!flag2)
				{
					List<ProductDefinition> list2 = dealEvent.dealer.RandomProducts.ToList();
					ProductDefinition val3 = null;
					float num4 = 0f;
					foreach (ProductDefinition tempDef in list2)
					{
						ProductTypeAffinity val4 = source.First((ProductTypeAffinity x) => x.DrugType == tempDef.DrugType);
						if (val4 != null && val4.Affinity > num4)
						{
							val3 = tempDef;
							num4 = val4.Affinity;
						}
					}
					if ((Object)(object)val3 == (Object)null)
					{
						val3 = dealEvent.dealer.RandomProducts[0];
					}
					ItemInstance defaultInstance = ((ItemDefinition)val3).GetDefaultInstance(10);
					QualityItemInstance val5 = (QualityItemInstance)(object)((defaultInstance is QualityItemInstance) ? defaultInstance : null);
					if (val5 != null)
					{
						val5.Quality = correspondingQuality;
					}
					if (((NPC)dealEvent.dealer).Inventory.CanItemFit(defaultInstance))
					{
						((NPC)dealEvent.dealer).Inventory.InsertItem(defaultInstance, true);
					}
				}
				ContractInfo val6 = val.TryGenerateContract((Dealer)(object)dealEvent.dealer);
				if (val6 != null)
				{
					int offeredDeals = val.OfferedDeals;
					val.OfferedDeals = offeredDeals + 1;
					val.TimeSinceLastDealOffered = 0;
					val.OfferedContractInfo = val6;
					val.OfferedContractTime = NetworkSingleton<TimeManager>.Instance.GetDateTime();
					val.HasChanged = true;
					EDealWindow dealWindow = ((Dealer)dealEvent.dealer).GetDealWindow();
					Contract val7 = val.ContractAccepted(dealWindow, false, (Dealer)(object)dealEvent.dealer);
					((Quest)val7).CompletionXP = 0;
					val7.completedContractsIncremented = false;
					((Dealer)dealEvent.dealer).AddContract(val7);
				}
				else
				{
					((CartelActivity)dealEvent).Deactivate();
				}
			}
			yield return null;
		}
	}
	[Serializable]
	public class CartelDealerConfig
	{
		public float CartelDealerWalkSpeed = 2.8f;

		public float CartelDealerHP = 200f;

		public float CartelDealerLethality = 0.5f;

		public string CartelDealerWeapon = "M1911";

		public float StealDealerContractChance = 0.06f;

		public float StealPlayerPendingChance = 0.08f;

		public float DealerActivityDecreasePerKill = 0.1f;

		public float DealerActivityIncreasePerDay = 0.25f;

		public float SafetyThreshold = -0.85f;

		public bool SafetyEnabled = true;

		public bool FreeTimeWalking = true;
	}
	public static class StealBackCustomer
	{
		[Serializable]
		public class StolenNPCSerialized
		{
			public string npcID;

			public int sampleChancesProcessed;
		}

		[Serializable]
		public class SerializedStolenNPCs
		{
			public List<StolenNPCSerialized> stolenCustomers;
		}

		public class StolenNPC
		{
			public NPC npc;

			public int sampleChancesProcessed = -1;
		}

		public static List<StolenNPC> stolenNPCs = new List<StolenNPC>();

		public static List<string> playerMessageTemplates = new List<string> { "I won't be hustling with you anymore. Got better quality from another person...", "Sorry, but I've got to change my local. These prices ain't it.", "Just letting you know that I won't be hitting you up anymore...", "These last deals have been a bit pricey. I'll get my stuff elsewhere.", "You've been cutting me short. I'm done buying from you.", "Thought we were cool, but you've been ripping me off. Peace.", "That last one was too light and quality was trash... I'll find someone else." };

		public static void OnDayPassTrySteal()
		{
			if (CartelEnforcer.currentConfig.stealBackCustomers)
			{
				CartelEnforcer.coros.Add(MelonCoroutines.Start(WaitSleepEndTrySteal()));
			}
		}

		public static IEnumerator WaitSleepEndTrySteal()
		{
			yield return CartelEnforcer.Wait30;
			yield return (object)new WaitUntil((Func<bool>)(() => !CartelEnforcer.isSaving && !Singleton<SaveManager>.Instance.IsSaving));
			if (!CartelEnforcer.registered || !CartelEnforcer.currentConfig.stealBackCustomers || !InstanceFinder.NetworkManager.IsServer || (int)NetworkSingleton<Cartel>.Instance.Status != 2)
			{
				yield break;
			}
			float num = 0f;
			foreach (RegionInfluenceData item in NetworkSingleton<Cartel>.Instance.Influence.regionInfluence)
			{
				num += item.Influence;
			}
			float num2 = num / (float)NetworkSingleton<Cartel>.Instance.Influence.regionInfluence.Count;
			if (num2 > 0f && num2 <= 0.66f)
			{
				if ((int)NetworkSingleton<TimeManager>.Instance.CurrentDay != 1 && (int)NetworkSingleton<TimeManager>.Instance.CurrentDay != 4 && (int)NetworkSingleton<TimeManager>.Instance.CurrentDay != 6)
				{
					yield break;
				}
			}
			else if (num2 > 0.66f && num2 < 0.8f)
			{
				if ((int)NetworkSingleton<TimeManager>.Instance.CurrentDay != 1 && (int)NetworkSingleton<TimeManager>.Instance.CurrentDay != 4)
				{
					yield break;
				}
			}
			else if ((int)NetworkSingleton<TimeManager>.Instance.CurrentDay != 4)
			{
				yield break;
			}
			CartelEnforcer.coros.Add(MelonCoroutines.Start(StealCustomerWithDelay(num2)));
		}

		public static IEnumerator StealCustomerWithDelay(float cartelInfluence)
		{
			List<Customer> unlocked = new List<Customer>(Customer.UnlockedCustomers);
			if (unlocked.Count <= 18)
			{
				yield break;
			}
			int subtrahend = Random.Range(3, 6);
			int i = Mathf.Clamp(unlocked.Count - subtrahend, 0, unlocked.Count - 1);
			int maxCustomersChecked = 5;
			int maxSuccesfulStolen = 2;
			int currentCustomersChecked = 0;
			int currentStolen = 0;
			EMapRegion region1StolenFrom = (EMapRegion)0;
			while (CartelEnforcer.registered && i >= 0 && currentStolen < maxSuccesfulStolen && currentCustomersChecked < maxCustomersChecked)
			{
				Customer val = unlocked[i];
				if (CanStealCustomer(val.NPC, cartelInfluence) && region1StolenFrom != val.NPC.Region)
				{
					StealCustomer(val.NPC);
					currentStolen++;
					region1StolenFrom = val.NPC.Region;
				}
				i = Mathf.Clamp(i - subtrahend, 0, unlocked.Count - 1);
				subtrahend = Random.Range(3, 6);
				currentCustomersChecked++;
				yield return CartelEnforcer.Wait05;
			}
			yield return null;
		}

		public static bool CanStealCustomer(NPC npc, float cartelInfluence)
		{
			//IL_0001: 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_0030: Invalid comparison between Unknown and I4
			if ((int)npc.Region == 0)
			{
				return false;
			}
			if (!npc.RelationData.Unlocked)
			{
				return false;
			}
			float num = Random.Range(0f, 1f);
			if ((int)npc.Region == 1 && num > 0.5f)
			{
				return false;
			}
			float num2 = Mathf.Lerp(4.5f, 1.5f, cartelInfluence);
			if (npc.RelationData.RelationDelta > num2 && num > 0.1f)
			{
				return false;
			}
			Customer component = ((Component)npc).GetComponent<Customer>();
			if (Customer.LockedCustomers.Contains(component))
			{
				return false;
			}
			if ((Object)(object)component.CurrentContract != (Object)null)
			{
				return false;
			}
			if (component.CurrentAddiction > 0.8f && num > 0.2f)
			{
				return false;
			}
			if (npc.RelationData.Connections.Count < 2)
			{
				return false;
			}
			for (int i = 0; i < npc.RelationData.Connections.Count; i++)
			{
				if (!npc.RelationData.Connections[i].RelationData.Unlocked)
				{
					return false;
				}
			}
			List<StolenNPC> list = new List<StolenNPC>(stolenNPCs);
			for (int j = 0; j < list.Count; j++)
			{
				if ((Object)(object)list[j].npc == (Object)(object)npc)
				{
					return false;
				}
			}
			return true;
		}

		public static void StealCustomer(NPC npc)
		{
			npc.RelationData.Unlocked = false;
			Customer component = ((Component)npc).GetComponent<Customer>();
			if (!Customer.LockedCustomers.Contains(component))
			{
				Customer.LockedCustomers.Add(component);
			}
			if (Customer.UnlockedCustomers.Contains(component))
			{
				Customer.UnlockedCustomers.Remove(component);
			}
			component.minsSinceUnlocked = 0;
			component.customerData.GuaranteeFirstSampleSuccess = false;
			component.UpdatePotentialCustomerPoI();
			StolenNPC stolenNPC = new StolenNPC();
			stolenNPC.npc = npc;
			stolenNPC.sampleChancesProcessed = 1;
			stolenNPCs.Add(stolenNPC);
			if ((Object)(object)component.AssignedDealer != (Object)null)
			{
				component.AssignedDealer.RemoveCustomer(component);
			}
			Singleton<NewCustomerPopup>.Instance.PlayPopup(component);
			((TMP_Text)Singleton<NewCustomerPopup>.Instance.Title).text = "Customer has been stolen by Cartel!";
			CartelEnforcer.coros.Add(MelonCoroutines.Start(LateSendMessage(npc)));
		}

		public static IEnumerator LateSendMessage(NPC npc)
		{
			if (Random.Range(0f, 1f) > 0.5f)
			{
				yield return CartelEnforcer.Wait30;
			}
			else
			{
				yield return CartelEnforcer.Wait10;
			}
			if (CartelEnforcer.registered)
			{
				npc.MSGConversation.SendMessage(new Message(playerMessageTemplates[Random.Range(0, playerMessageTemplates.Count)], (ESenderType)1, true, -1), true, true);
			}
		}
	}
	[HarmonyPatch(typeof(Customer), "SampleConsumed")]
	public static class Customer_SampleConsumed_Patch
	{
		[HarmonyPrefix]
		public static bool Prefix(Customer __instance)
		{
			if (!CartelEnforcer.currentConfig.stealBackCustomers)
			{
				return true;
			}
			if (StealBackCustomer.stolenNPCs.Count == 0)
			{
				return true;
			}
			List<StealBackCustomer.StolenNPC> list = new List<StealBackCustomer.StolenNPC>(StealBackCustomer.stolenNPCs);
			StealBackCustomer.StolenNPC stolenNPC = null;
			for (int i = 0; i < list.Count; i++)
			{
				if ((Object)(object)list[i].npc == (Object)(object)__instance.NPC)
				{
					stolenNPC = list[i];
					break;
				}
			}
			if (stolenNPC == null)
			{
				return true;
			}
			stolenNPC.sampleChancesProcessed++;
			return true;
		}
	}
	[HarmonyPatch(typeof(Customer), "GetSampleSuccess")]
	public static class Customer_GetSampleSuccess_Patch
	{
		[HarmonyPostfix]
		public static void Postfix(Customer __instance, ref float __result)
		{
			if (!CartelEnforcer.currentConfig.stealBackCustomers || StealBackCustomer.stolenNPCs.Count == 0)
			{
				return;
			}
			List<StealBackCustomer.StolenNPC> list = new List<StealBackCustomer.StolenNPC>(StealBackCustomer.stolenNPCs);
			StealBackCustomer.StolenNPC stolenNPC = null;
			for (int i = 0; i < list.Count; i++)
			{
				if ((Object)(object)list[i].npc == (Object)(object)__instance.NPC)
				{
					stolenNPC = list[i];
					break;
				}
			}
			if (stolenNPC != null && stolenNPC.sampleChancesProcessed != -1)
			{
				float num = (float)stolenNPC.sampleChancesProcessed / 9f;
				if (num >= 1f)
				{
					__result = 0.95f;
				}
				else
				{
					__result = Mathf.Lerp(0.05f, 0.75f, Mathf.Clamp01(num * (1f + __instance.CurrentAddiction)));
				}
			}
		}
	}
	[HarmonyPatch(typeof(Customer), "SampleWasSufficient")]
	public static class Customer_SampleWasSufficient_Patch
	{
		[HarmonyPrefix]
		public static bool Prefix(Customer __instance)
		{
			if (!CartelEnforcer.currentConfig.stealBackCustomers)
			{
				return true;
			}
			if (StealBackCustomer.stolenNPCs.Count == 0)
			{
				return true;
			}
			StealBackCustomer.StolenNPC stolenNPC = StealBackCustomer.stolenNPCs.First((StealBackCustomer.StolenNPC x) => (Object)(object)x.npc == (Object)(object)__instance.NPC);
			if (stolenNPC != null)
			{
				StealBackCustomer.stolenNPCs.Remove(stolenNPC);
			}
			return true;
		}
	}
	public class CartelRegActivityHours
	{
		public int cartelActivityClass;

		public int hoursUntilEnable;
	}
	[Serializable]
	public class EventFrequencyConfig
	{
		public List<EventFrequency> events;

		public void InitializeDefault()
		{
			events = new List<EventFrequency>();
			events.Add(new EventFrequency
			{
				Identifier = "Ambush",
				CooldownHours = 0,
				InfluenceRequirement = -1f,
				RandomTimeRangePercentage = 0f
			});
			events.Add(new EventFrequency
			{
				Identifier = "RegionActivity",
				CooldownHours = 0,
				InfluenceRequirement = -1f,
				RandomTimeRangePercentage = 0f
			});
			events.Add(new EventFrequency
			{
				Identifier = "StealDeadDrop",
				CooldownHours = 0,
				InfluenceRequirement = -1f,
				RandomTimeRangePercentage = 0f
			});
			events.Add(new EventFrequency
			{
				Identifier = "CartelCustomerDeal",
				CooldownHours = 0,
				InfluenceRequirement = -1f,
				RandomTimeRangePercentage = 0f
			});
			events.Add(new EventFrequency
			{
				Identifier = "RobDealer",
				CooldownHours = 0,
				InfluenceRequirement = -1f,
				RandomTimeRangePercentage = 0f
			});
			events.Add(new EventFrequency
			{
				Identifier = "SprayGraffiti",
				CooldownHours = 0,
				InfluenceRequirement = -1f,
				RandomTimeRangePercentage = 0f
			});
			events.Add(new EventFrequency
			{
				Identifier = "CartelPlayerDeal",
				CooldownHours = 0,
				InfluenceRequirement = -1f,
				RandomTimeRangePercentage = 0f
			});
			events.Add(new EventFrequency
			{
				Identifier = "DriveBy",
				CooldownHours = 0,
				InfluenceRequirement = -1f,
				RandomTimeRangePercentage = 0f
			});
			events.Add(new EventFrequency
			{
				Identifier = "InterceptDeals",
				CooldownHours = 0,
				InfluenceRequirement = -1f,
				RandomTimeRangePercentage = 0f
			});
			events.Add(new EventFrequency
			{
				Identifier = "Gathering",
				CooldownHours = 0,
				InfluenceRequirement = -1f,
				RandomTimeRangePercentage = 0f
			});
			events.Add(new EventFrequency
			{
				Identifier = "Sabotage",
				CooldownHours = 0,
				InfluenceRequirement = -1f,
				RandomTimeRangePercentage = 0f
			});
		}
	}
	[Serializable]
	public class EventFrequency
	{
		public string Identifier = "";

		public int CooldownHours;

		public float InfluenceRequirement;

		public float RandomTimeRangePercentage = 0.15f;
	}
	[Serializable]
	public class CurrentEventCooldowns
	{
		public int StealDeadDropCooldown;

		public int CartelCustomerDealCooldown;

		public int RobDealerCooldown;

		public int SprayGraffitiCooldown;

		public int DriveByCooldown;

		public int GatheringCooldown;

		public int InterceptDealsCooldown;

		public Dictionary<string, int> SabotageCooldowns;

		public void InitializeDefault()
		{
			StealDeadDropCooldown = FrequencyOverrides.GetActivityHours("StealDeadDrop");
			CartelCustomerDealCooldown = FrequencyOverrides.GetActivityHours("CartelCustomerDeal");
			RobDealerCooldown = FrequencyOverrides.GetActivityHours("RobDealer");
			SprayGraffitiCooldown = FrequencyOverrides.GetActivityHours("SprayGraffiti");
			int activityHours = FrequencyOverrides.GetActivityHours("DriveBy");
			DriveByCooldown = ((activityHours != 0) ? activityHours : Random.Range(24, 68));
			int activityHours2 = FrequencyOverrides.GetActivityHours("Gathering");
			GatheringCooldown = ((activityHours2 != 0) ? activityHours2 : Random.Range(6, 15));
			int activityHours3 = FrequencyOverrides.GetActivityHours("InterceptDeals");
			InterceptDealsCooldown = ((activityHours3 != 0) ? activityHours3 : Random.Range(2, 8));
			int activityHours4 = FrequencyOverrides.GetActivityHours("Sabotage");
			activityHours4 = ((activityHours4 != 0) ? activityHours4 : Random.Range(16, 64));
			SabotageCooldowns = new Dictionary<string, int>
			{
				{ "Laundromat", activityHours4 },
				{ "Post Office", activityHours4 },
				{ "Taco Ticklers", activityHours4 }
			};
		}
	}
	public static class FrequencyOverrides
	{
		public static EventFrequencyConfig frequencyConfig;

		public static List<CartelRegActivityHours> regActivityHours = new List<CartelRegActivityHours>();

		public static readonly List<string> SupportedEventIdentifiers = new List<string>
		{
			"Ambush", "RegionActivity", "StealDeadDrop", "CartelCustomerDeal", "RobDealer", "SprayGraffiti", "CartelPlayerDeal", "DriveBy", "InterceptDeals", "Gathering",
			"Sabotage"
		};

		public static void InitFrequencyOverrides()
		{
			regActivityHours.Add(new CartelRegActivityHours
			{
				cartelActivityClass = 0,
				hoursUntilEnable = CartelEnforcer.eventCooldowns.StealDeadDropCooldown
			});
			regActivityHours.Add(new CartelRegActivityHours
			{
				cartelActivityClass = 1,
				hoursUntilEnable = CartelEnforcer.eventCooldowns.CartelCustomerDealCooldown
			});
			regActivityHours.Add(new CartelRegActivityHours
			{
				cartelActivityClass = 2,
				hoursUntilEnable = CartelEnforcer.eventCooldowns.RobDealerCooldown
			});
			regActivityHours.Add(new CartelRegActivityHours
			{
				cartelActivityClass = 3,
				hoursUntilEnable = CartelEnforcer.eventCooldowns.SprayGraffitiCooldown
			});
			DriveByEvent.hoursUntilDriveBy = CartelEnforcer.eventCooldowns.DriveByCooldown;
			CartelGathering.hoursUntilNextGathering = CartelEnforcer.eventCooldowns.GatheringCooldown;
			InterceptEvent.hoursUntilInterceptEvent = CartelEnforcer.eventCooldowns.InterceptDealsCooldown;
			if (CartelEnforcer.eventCooldowns.SabotageCooldowns != null && CartelEnforcer.eventCooldowns.SabotageCooldowns.Count > 0)
			{
				try
				{
					SabotageEvent.locations.ForEach(delegate(SabotageEvent.SabotageEventLocation x)
					{
						x.hoursUntilEnabled = CartelEnforcer.eventCooldowns.SabotageCooldowns.First((KeyValuePair<string, int> y) => y.Key == ((Property)x.business).propertyName).Value;
					});
				}
				catch (Exception)
				{
				}
			}
			foreach (CartelActivity globalActivity in NetworkSingleton<Cartel>.Instance.Activities.GlobalActivities)
			{
				float influenceRequirement = GetByID("Ambush").InfluenceRequirement;
				if (influenceRequirement >= 0f)
				{
					globalActivity.InfluenceRequirement = influenceRequirement;
				}
			}
			CartelRegionActivities[] regionalActivities = NetworkSingleton<Cartel>.Instance.Activities.RegionalActivities;
			for (int num = 0; num < regionalActivities.Length; num++)
			{
				foreach (CartelActivity activity in regionalActivities[num].Activities)
				{
					float influenceRequirement2 = GetByID(((object)activity).GetType().Name).InfluenceRequirement;
					if (influenceRequirement2 >= 0f)
					{
						activity.InfluenceRequirement = influenceRequirement2;
					}
				}
			}
		}

		public static int GetActivityHours(string identifier)
		{
			EventFrequency byID = GetByID(identifier);
			_ = byID.RandomTimeRangePercentage;
			int num = Mathf.RoundToInt((float)byID.CooldownHours * (1f + byID.RandomTimeRangePercentage));
			int num2 = Mathf.Clamp(Mathf.RoundToInt((float)byID.CooldownHours * (1f - byID.RandomTimeRangePercentage)), 1, num - 1);
			if (byID.CooldownHours != 0)
			{
				return Random.Range(num2, num);
			}
			return byID.CooldownHours;
		}

		public static EventFrequency GetByID(string identifier)
		{
			return frequencyConfig.events.First((EventFrequency x) => SupportedEventIdentifiers.Contains(x.Identifier) && x.Identifier == identifier);
		}

		public static void OnHourPassReduceCartelRegActHours()
		{
			if (regActivityHours == null || regActivityHours.Count == 0 || Singleton<SaveManager>.Instance.IsSaving || CartelEnforcer.isSaving)
			{
				return;
			}
			foreach (CartelRegActivityHours regActivityHour in regActivityHours)
			{
				if (regActivityHour.hoursUntilEnable > 0)
				{
					regActivityHour.hoursUntilEnable--;
				}
			}
		}
	}
	[HarmonyPatch(typeof(CartelDealManager), "CompleteDeal")]
	public static class CartelDealManager_CompleteDeal_Patch
	{
		[HarmonyPostfix]
		public static void Postfix(CartelDealManager __instance)
		{
			int activityHours = FrequencyOverrides.GetActivityHours("CartelPlayerDeal");
			__instance.HoursUntilNextDealRequest = ((activityHours != 0) ? activityHours : __instance.HoursUntilNextDealRequest);
		}
	}
	[HarmonyPatch(typeof(CartelActivities), "TryStartActivity")]
	public static class CartelActivities_TryStartActivityPatch
	{
		private static readonly string name = "TryStartGlobalActivity";

		[HarmonyPrefix]
		public static bool Prefix(CartelActivities __instance)
		{
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: 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_0096: 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_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: 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_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			int activityHours = FrequencyOverrides.GetActivityHours("Ambush");
			if (activityHours == 0)
			{
				__instance.HoursUntilNextGlobalActivity = CartelActivities.GetNewCooldown();
			}
			else
			{
				__instance.HoursUntilNextGlobalActivity = activityHours;
			}
			if (!__instance.CanNewActivityBegin())
			{
				return false;
			}
			List<CartelActivity> list = new List<CartelActivity>(__instance.GetActivitiesReadyToStart());
			List<EMapRegion> list2 = new List<EMapRegion>(__instance.GetValidRegionsForActivity());
			if (list.Count == 0 || list2.Count == 0)
			{
				return false;
			}
			list2.Sort((EMapRegion a, EMapRegion b) => NetworkSingleton<Cartel>.Instance.Influence.GetInfluence(b).CompareTo(NetworkSingleton<Cartel>.Instance.Influence.GetInfluence(a)));
			bool flag = false;
			EMapRegion currentRegion = Player.Local.CurrentRegion;
			if (list2.Contains(currentRegion))
			{
				flag = true;
				list2.Remove(currentRegion);
				list2.Insert(0, currentRegion);
			}
			EMapRegion val = (EMapRegion)0;
			bool flag2 = false;
			if (!CartelEnforcer.currentConfig.debugMode)
			{
				foreach (EMapRegion item in list2)
				{
					float influence = NetworkSingleton<Cartel>.Instance.Influence.GetInfluence(item);
					float num = 0f;
					float num2 = 0f;
					num = AmbushOverrides.ambushSettings.AmbushTriggerProbability;
					num2 = influence * num;
					if (Random.Range(0f, 1f) < num2)
					{
						val = item;
						flag2 = true;
						break;
					}
				}
				if (!flag2)
				{
					return false;
				}
			}
			else
			{
				flag2 = true;
				val = Player.Local.CurrentRegion;
			}
			int count = list.Count;
			bool flag3 = false;
			do
			{
				count = list.Count;
				if (count == 0)
				{
					break;
				}
				int num3 = 0;
				if (flag)
				{
					num3 = (flag3 ? Random.Range(0, count) : 0);
					flag3 = true;
				}
				else
				{
					num3 = Random.Range(0, count);
				}
				if (list[num3].IsRegionValidForActivity(val))
				{
					NetworkSingleton<Cartel>.Instance.Activities.StartGlobalActivity((NetworkConnection)null, val, 0);
					if (activityHours == 0)
					{
						__instance.HoursUntilNextGlobalActivity = CartelActivities.GetNewCooldown();
					}
					else
					{
						__instance.HoursUntilNextGlobalActivity = activityHours;
					}
					break;
				}
				list.Remove(list[num3]);
			}
			while (count != 0);
			return false;
		}
	}
	[HarmonyPatch(typeof(CartelRegionActivities), "TryStartActivity")]
	public static class CartelRegionActivities_TryStartActivityPatch
	{
		private static readonly string name = "TryStartRegionActivity";

		[HarmonyPrefix]
		public static bool Prefix(CartelRegionActivities __instance)
		{
			//IL_0016: 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)
			Dictionary<CartelActivity, Tuple<int, string>> dictionary = new Dictionary<CartelActivity, Tuple<int, string>>();
			int activityHours = FrequencyOverrides.GetActivityHours("RegionActivity");
			if (activityHours == 0)
			{
				__instance.HoursUntilNextActivity = CartelRegionActivities.GetNewCooldown(__instance.Region);
			}
			else
			{
				__instance.HoursUntilNextActivity = activityHours;
			}
			foreach (CartelActivity activity in __instance.Activities)
			{
				int actInt = 0;
				string text = "";
				if (activity is StealDeadDrop)
				{
					actInt = 0;
					text = "StealDeadDrop";
				}
				else if (activity is CartelCustomerDeal)
				{
					actInt = 1;
					text = "CartelCustomerDeal";
				}
				else if (activity is RobDealer)
				{
					actInt = 2;
					text = "RobDealer";
				}
				else
				{
					actInt = 3;
					text = "SprayGraffiti";
				}
				CartelRegActivityHours cartelRegActivityHours = FrequencyOverrides.regActivityHours.First((CartelRegActivityHours x) => x.cartelActivityClass == actInt);
				if (cartelRegActivityHours != null && cartelRegActivityHours.hoursUntilEnable <= 0)
				{
					dictionary.Add(activity, new Tuple<int, string>(actInt, text));
				}
			}
			if (dictionary.Count == 0)
			{
				dictionary.Clear();
				return false;
			}
			int count = dictionary.Count;
			do
			{
				count = dictionary.Count;
				if (count == 0)
				{
					break;
				}
				KeyValuePair<CartelActivity, Tuple<int, string>> keyValuePair = dictionary.ElementAt(Random.Range(0, count));
				if (keyValuePair.Key.IsRegionValidForActivity(__instance.Region))
				{
					__instance.StartActivity((NetworkConnection)null, __instance.Activities.IndexOf(keyValuePair.Key));
					FrequencyOverrides.regActivityHours[keyValuePair.Value.Item1].hoursUntilEnable = FrequencyOverrides.GetActivityHours(keyValuePair.Value.Item2);
					break;
				}
				dictionary.Remove(keyValuePair.Key);
			}
			while (count != 0);
			dictionary.Clear();
			dictionary = null;
			return false;
		}
	}
	public static class InfluenceOverrides
	{
		public static bool ShouldChangeInfluence(EMapRegion region)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Invalid comparison between Unknown and I4
			//IL_002c: 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)
			bool result = false;
			if ((int)NetworkSingleton<Cartel>.Instance.Status != 2)
			{
				result = false;
			}
			if (InstanceFinder.IsServer && Singleton<Map>.Instance.GetUnlockedRegions().Contains(region))
			{
				result = true;
			}
			if ((int)region == 0)
			{
				result = false;
			}
			return result;
		}

		public static IEnumerator OnDayChangeApplyPassiveGain()
		{
			MapRegionData[] regions = Singleton<Map>.Instance.Regions;
			foreach (MapRegionData region in regions)
			{
				yield return CartelEnforcer.Wait05;
				if (ShouldChangeInfluence(region.Region))
				{
					NetworkSingleton<Cartel>.Instance.Influence.ChangeInfluence(region.Region, CartelEnforcer.influenceConfig.passiveInfluenceGainPerDay);
				}
			}
			yield return null;
		}

		public static void OnDayPassChangePassive()
		{
			if (CartelEnforcer.influenceConfig.passiveInfluenceGainPerDay != 0f)
			{
				CartelEnforcer.coros.Add(MelonCoroutines.Start(OnDayChangeApplyPassiveGain()));
			}
		}
	}
	[Serializable]
	public class InfluenceConfig
	{
		public float interceptFail = 0.025f;

		public float interceptSuccess = -0.05f;

		public float deadDropFail = 0.025f;

		public float deadDropSuccess = -0.05f;

		public float gatheringFail = 0.025f;

		public float gatheringSuccess = -0.08f;

		public float robberyPlayerEscape = 0.025f;

		public float robberyGoonEscapeSuccess = 0.025f;

		public float robberyGoonDead = -0.08f;

		public float robberyGoonEscapeDead = -0.05f;

		public float sabotageBombDefused = -0.15f;

		public float sabotageGoonKilled = -0.05f;

		public float sabotageBombExploded = 0.2f;

		public float cartelDealerPersuaded = -0.1f;

		public float trucedGreetingChallenge = -0.15f;

		public float passiveInfluenceGainPerDay = 0.025f;

		public float cartelDealerDied = -0.1f;

		public float ambushDefeated = -0.1f;

		public float graffitiInfluenceReduction = -0.05f;

		public float customerUnlockInfluenceChange = -0.075f;
	}
	[HarmonyPatch(typeof(CartelDealer), "DiedOrKnockedOut")]
	public static class CartelDealer_Died_Patch
	{
		public static bool Prefix(CartelDealer __instance)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Invalid comparison between Unknown and I4
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			if (!InstanceFinder.IsServer)
			{
				return false;
			}
			if ((int)NetworkSingleton<Cartel>.Instance.Status != 2)
			{
				return false;
			}
			NetworkSingleton<Cartel>.Instance.Influence.ChangeInfluence(((NPC)__instance).Region, CartelEnforcer.influenceConfig.cartelDealerDied);
			return false;
		}
	}
	[HarmonyPatch(typeof(Ambush), "SpawnAmbush")]
	public static class Ambush_SpawnAmbush_Patch
	{
		public static bool Prefix(Ambush __instance, Player target, Vector3[] potentialSpawnPoints)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			List<CartelGoon> currentlySpawned = NetworkSingleton<Cartel>.Instance.GoonPool.spawnedGoons.ToList();
			CartelEnforcer.coros.Add(MelonCoroutines.Start(OverMonitorAmbush(potentialSpawnPoints, currentlySpawned, ((CartelActivity)__instance).Region)));
			return true;
		}

		public static IEnumerator OverMonitorAmbush(Vector3[] potentialSpawnPoints, List<CartelGoon> currentlySpawned, EMapRegion region)
		{
			//IL_000e: 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)
			List<CartelGoon> ambushSpawned = new List<CartelGoon>();
			yield return CartelEnforcer.Wait01;
			if (!CartelEnforcer.registered)
			{
				yield break;
			}
			if (NetworkSingleton<Cartel>.Instance.GoonPool.spawnedGoons.Count != currentlySpawned.Count)
			{
				foreach (CartelGoon spawnedGoon in NetworkSingleton<Cartel>.Instance.GoonPool.spawnedGoons)
				{
					if (spawnedGoon.IsGoonSpawned && !((NPC)spawnedGoon).Health.IsDead && !((NPC)spawnedGoon).Health.IsKnockedOut)
					{
						bool flag = false;
						if (((Behaviour)((NPC)spawnedGoon).Behaviour.CombatBehaviour).Active && ((NPC)spawnedGoon).Behaviour.CombatBehaviour.Target != null)
						{
							flag = true;
						}
						bool flag2 = false;
						if ((Object)(object)SabotageEvent.sabotager != (Object)null && (Object)(object)spawnedGoon == (Object)(object)SabotageEvent.sabotager)
						{
							flag2 = true;
						}
						if (!currentlySpawned.Contains(spawnedGoon) && !ambushSpawned.Contains(spawnedGoon) && !CartelGathering.spawnedGatherGoons.Contains(spawnedGoon) && !flag2 && flag)
						{
							ambushSpawned.Add(spawnedGoon);
						}
					}
				}
			}
			if (ambushSpawned.Count == 0)
			{
				yield break;
			}
			foreach (CartelGoon item in ambushSpawned)
			{
				_ = item;
			}
			float maxAmbushElapsed = 360f;
			float elapsed = 0f;
			List<CartelGoon> deadGoons = new List<CartelGoon>();
			int spawnedCount = ambushSpawned.Count;
			while (CartelEnforcer.registered && elapsed < maxAmbushElapsed && ambushSpawned.Count != 0 && deadGoons.Count != spawnedCount)
			{
				foreach (CartelGoon goon in ambushSpawned)
				{
					yield return CartelEnforcer.Wait05;
					elapsed += 0.5f;
					if (!deadGoons.Contains(goon) && (((NPC)goon).Health.IsDead || ((NPC)goon).Health.IsKnockedOut))
					{
						deadGoons.Add(goon);
					}
				}
				foreach (CartelGoon goon in deadGoons)
				{
					yield return CartelEnforcer.Wait05;
					elapsed += 0.5f;
					if (ambushSpawned.Contains(goon))
					{
						ambushSpawned.Remove(goon);
					}
				}
			}
			yield return CartelEnforcer.Wait01;
			if ((ambushSpawned.Count == 0 || deadGoons.Count == spawnedCount) && InstanceFinder.IsServer)
			{
				float num = 0.1f + CartelEnforcer.influenceConfig.ambushDefeated;
				if (num != 0f)
				{
					NetworkSingleton<Cartel>.Instance.Influence.ChangeInfluence(region, num);
				}
			}
			ambushSpawned.Clear();
			deadGoons.Clear();
		}
	}
	[HarmonyPatch(typeof(WorldSpraySurface), "Reward")]
	public static class WorldSpraySurface_Reward_Patch
	{
		public static bool Prefix(WorldSpraySurface __instance)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Invalid comparison between Unknown and I4
			//IL_0046: 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: Invalid comparison between Unknown and I4
			NetworkSingleton<LevelManager>.Instance.AddXP(50);
			if (!InstanceFinder.IsServer)
			{
				return false;
			}
			if ((int)NetworkSingleton<Cartel>.Instance.Status == 2 || (CartelEnforcer.currentConfig.alliedExtensions && (int)NetworkSingleton<Cartel>.Instance.Status == 1))
			{
				NetworkSingleton<Cartel>.Instance.Influence.ChangeInfluence(__instance.Region, CartelEnforcer.influenceConfig.graffitiInfluenceReduction);
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(Customer), "OnCustomerUnlocked")]
	public static class Customer_OnCustomerUnlocked_Patch
	{
		public static bool Prefix(Customer __instance, EUnlockType unlockType, bool notify)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Invalid comparison between Unknown and I4
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Invalid comparison between Unknown and I4
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			if (!notify || !NetworkSingleton<Cartel>.InstanceExists)
			{
				return true;
			}
			bool flag = (int)NetworkSingleton<Cartel>.Instance.Status == 2;
			bool flag2 = (int)NetworkSingleton<Cartel>.Instance.Status == 1;
			if (flag || flag2)
			{
				if (flag2 && !CartelEnforcer.currentConfig.alliedExtensions)
				{
					return true;
				}
				if (flag)
				{
					if (CartelEnforcer.currentConfig.stealBackCustomers)
					{
						List<StealBackCustomer.StolenNPC> list = new List<StealBackCustomer.StolenNPC>(StealBackCustomer.stolenNPCs);
						StealBackCustomer.StolenNPC stolenNPC = null;
						for (int i = 0; i < list.Count; i++)
						{
							if ((Object)(object)list[i].npc == (Object)(object)__instance.NPC)
							{
								stolenNPC = list[i];
								break;
							}
						}
						if (stolenNPC != null)
						{
							float num = 0.075f + CartelEnforcer.influenceConfig.customerUnlockInfluenceChange * 0.5f;
							if (num != 0f && (int)__instance.NPC.Region != 0)
							{
								NetworkSingleton<Cartel>.Instance.Influence.ChangeInfluence(__instance.NPC.Region, num);
							}
						}
					}
					else
					{
						float num2 = 0.075f + CartelEnforcer.influenceConfig.customerUnlockInfluenceChange;
						if (num2 != 0f && (int)__instance.NPC.Region != 0)
						{
							NetworkSingleton<Cartel>.Instance.Influence.ChangeInfluence(__instance.NPC.Region, num2);
						}
					}
				}
				else if (flag2 && (int)__instance.NPC.Region != 0)
				{
					NetworkSingleton<Cartel>.Instance.Influence.ChangeInfluence(__instance.NPC.Region, CartelEnforcer.influenceConfig.customerUnlockInfluenceChange);
				}
				return true;
			}
			return true;
		}
	}
	public static class AlliedExtension
	{
		public static ConfigLoader.CartelAlliedConfig alliedConfig;

		public static ConfigLoader.CartelAlliedQuests alliedQuests;

		public static DialogueContainer persuadeContainer;

		public static DialogueNodeData entryNode;

		public static Dictionary<EMapRegion, CartelDealer> dealersByRegion;

		public static void MakeMapPoI(Dealer dealer)
		{
			//IL_002b: 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_006c: Unknown result type (might be due to invalid IL or missing references)
			GameObject obj = Object.Instantiate<GameObject>(((Component)NetworkSingleton<NPCManager>.Instance.NPCPoIPrefab).gameObject);
			obj.transform.parent = ((Component)dealer).transform;
			obj.transform.localPosition = Vector3.zero;
			obj.transform.rotation = Quaternion.identity;
			NPCPoI component = obj.GetComponent<NPCPoI>();
			component.NPC = (NPC)(object)dealer;
			((POI)component).MainText = $"Cartel Dealer ({((NPC)dealer).Region})";
			((POI)component).InitializeUI();
			dealer.DealerPoI = component;
		}

		public static IEnumerator DelayedStateChange(ECartelStatus oldStatus, ECartelStatus newStatus)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: 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)
			yield return CartelEnforcer.Wait5;
			if ((int)oldStatus == 0 && (int)newStatus == 1)
			{
				NPC val = null;
				foreach (Dealer allPlayerDealer in Dealer.AllPlayerDealers)
				{
					if (((NPC)allPlayerDealer).ID == "molly_presley")
					{
						val = (NPC)(object)allPlayerDealer;
					}
				}
				_ = (Object)(object)val == (Object)null;
				CartelDealer[] allCartelDealers = DealerActivity.allCartelDealers;
				foreach (CartelDealer val2 in allCartelDealers)
				{
					AssignDealerConfig(val2);
					if (dealersByRegion.Count > 0)
					{
						if ((int)((NPC)val2).Region == 1)
						{
							((NPC)val2).RelationData.Connections.Add(val);
						}
						else
						{
							EMapRegion key = (EMapRegion)(((NPC)val2).Region - 1);
							((NPC)val2).RelationData.Connections.Add((NPC)(object)dealersByRegion[key]);
						}
					}
					CartelPersuade.AddPersuadeDialogue(val2);
				}
				if (!alliedQuests.alliedIntroCompleted && (Object)(object)EndGameQuest.activeTruceIntro == (Object)null)
				{
					yield return (object)new WaitUntil((Func<bool>)CanStart);
					yield return CartelEnforcer.Wait05;
					CartelEnforcer.coros.Add(MelonCoroutines.Start(EndGameQuest.SetupTruceIntroQuest()));
				}
			}
			else if ((int)oldStatus == 1 && (int)newStatus == 2)
			{
				CartelDealer[] allCartelDealers = DealerActivity.allCartelDealers;
				foreach (CartelDealer val3 in allCartelDealers)
				{
					if (((Dealer)val3).IsRecruited)
					{
						((Dealer)val3).IsRecruited = false;
						((NPC)val3).NPCData.Inventory.ClearInventoryOnNewDay = true;
						if (((Dealer)val3).AssignedCustomers.Count == 0)
						{
							continue;
						}
						for (int num = ((Dealer)val3).AssignedCustomers.Count - 1; num >= 0; num--)
						{
							if ((Object)(object)((Dealer)val3).AssignedCustomers[num] != (Object)null)
							{
								((Dealer)val3).RemoveCustomer(((Dealer)val3).AssignedCustomers[num]);
							}
						}
					}
					if (((Dealer)val3).HasBeenRecommended)
					{
						((Dealer)val3).HasBeenRecommended = false;
					}
					if (((NPC)val3).RelationData.Unlocked)
					{
						((NPC)val3).RelationData.Unlocked = false;
					}
				}
			}
			yield return null;
			static bool CanStart()
			{
				if (!Singleton<DialogueCanvas>.Instance.IsOpen && !Singleton<HandoverScreen>.Instance.IsOpen)
				{
					return PlayerSingleton<PlayerCamera>.Instance.ActiveUIElementCount <= 0;
				}
				return false;
			}
		}

		public static void OnAlliedStateChange(ECartelStatus oldStatus, ECartelStatus newStatus)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			if (CartelEnforcer.currentConfig.alliedExtensions)
			{
				CartelEnforcer.coros.Add(MelonCoroutines.Start(DelayedStateChange(oldStatus, newStatus)));
			}
		}

		public static IEnumerator SetupAlliedExtension()
		{
			yield return CartelEnforcer.Wait10;
			alliedConfig = ConfigLoader.LoadAlliedConfig();
			alliedQuests = ConfigLoader.LoadAlliedQuests();
			persuadeContainer = CartelPersuade.InitPersuadeContainer();
			SuppliesModule.InitSuppliesModule();
			NetworkSingleton<TimeManager>.Instance.onMinutePass.Add((Action)CartelPersuade.ReduceCooldown);
			TimeManager instance = NetworkSingleton<TimeManager>.Instance;
			instance.onHourPass = (Action)Delegate.Combine(instance.onHourPass, new Action(SuppliesModule.OnHourPassEvaluateSupply));
			TimeManager instance2 = NetworkSingleton<TimeManager>.Instance;
			instance2.onHourPass = (Action)Delegate.Combine(instance2.onHourPass, new Action(OnHourPassTrySpawnEncounter));
			TimeManager instance3 = NetworkSingleton<TimeManager>.Instance;
			instance3.onSleepEnd = (Action)Delegate.Combine(instance3.onSleepEnd, new Action(OnSleepEndIncreaseEncounterChance));
			if ((int)NetworkSingleton<Cartel>.Instance.Status == 0 || (int)NetworkSingleton<Cartel>.Instance.Status == 1)
			{
				Cartel instance4 = NetworkSingleton<Cartel>.Instance;
				instance4.OnStatusChange = (Action<ECartelStatus, ECartelStatus>)Delegate.Combine(instance4.OnStatusChange, new Action<ECartelStatus, ECartelStatus>(OnAlliedStateChange));
			}
			if (DealerActivity.allCartelDealers == null)
			{
				DealerActivity.allCartelDealers = Object.FindObjectsOfType<CartelDealer>(true);
			}
			if (DealerActivity.allCartelDealers == null || DealerActivity.allCartelDealers.Length == 0)
			{
				yield break;
			}
			NPC item = null;
			foreach (Dealer allPlayerDealer in Dealer.AllPlayerDealers)
			{
				if (((NPC)allPlayerDealer).ID == "molly_presley")
				{
					item = (NPC)(object)allPlayerDealer;
				}
			}
			dealersByRegion = new Dictionary<EMapRegion, CartelDealer>();
			CartelDealer[] allCartelDealers = DealerActivity.allCartelDealers;
			foreach (CartelDealer val in allCartelDealers)
			{
				EMapRegion region = ((NPC)val).Region;
				switch (region - 1)
				{
				case 0:
					dealersByRegion.Add((EMapRegion)1, val);
					break;
				case 1:
					dealersByRegion.Add((EMapRegion)2, val);
					break;
				case 2:
					dealersByRegion.Add((EMapRegion)3, val);
					break;
				case 3:
					dealersByRegion.Add((EMapRegion)4, val);
					break;
				case 4:
					dealersByRegion.Add((EMapRegion)5, val);
					break;
				}
			}
			if ((int)NetworkSingleton<Cartel>.Instance.Status == 1 && CartelEnforcer.currentConfig.alliedExtensions)
			{
				bool flag = false;
				allCartelDealers = DealerActivity.allCartelDealers;
				foreach (CartelDealer val2 in allCartelDealers)
				{
					AssignDealerConfig(val2);
					((NPC)val2).NPCData.Appearance.Mugshot = InterceptEvent.benziesLogo;
					((NPC)val2).NPCData.BasicInfo.FirstName = $"{((NPC)val2).FirstName} ({((NPC)val2).Region})";
					if ((int)((NPC)val2).Region == 1 && ((Dealer)val2).IsRecruited)
					{
						flag = true;
					}
					if (((Dealer)val2).IsRecruited)
					{
						((NPC)val2).NPCData.Inventory.ClearInventoryOnNewDay = false;
					}
					else if (!((Dealer)val2).IsRecruited && !((Dealer)val2).HasBeenRecommended)
					{
						CartelPersuade.AddPersuadeDialogue(val2);
					}
				}
				foreach (KeyValuePair<EMapRegion, CartelDealer> item2 in dealersByRegion)
				{
					if ((int)item2.Key == 1)
					{
						((NPC)dealersByRegion[item2.Key]).RelationData.Connections.Add(item);
					}
					else
					{
						EMapRegion key = (EMapRegion)(item2.Key - 1);
						((NPC)dealersByRegion[item2.Key]).RelationData.Connections.Add((NPC)(object)dealersByRegion[key]);
					}
					if (!((Dealer)item2.Value).IsRecruited && ((Dealer)item2.Value).HasBeenRecommended)
					{
						((Dealer)item2.Value).SetUpDialogue();
					}
					if (((Dealer)item2.Value).IsRecruited)
					{
						MakeMapPoI((Dealer)(object)item2.Value);
					}
				}
				if (!alliedQuests.alliedIntroCompleted && (Object)(object)EndGameQuest.activeTruceIntro == (Object)null && !flag)
				{
					CartelEnforcer.coros.Add(MelonCoroutines.Start(EndGameQuest.SetupTruceIntroQuest()));
				}
			}
			yield return null;
		}

		public static bool IsTrucedDialogueEnabled()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Invalid comparison between Unknown and I4
			if ((int)NetworkSingleton<Cartel>.Instance.Status != 1)
			{
				return CartelEnforcer.currentConfig.debugMode;
			}
			return true;
		}

		public static void OnHourPassTrySpawnEncounter()
		{
			if (!EndGameQuest.trueBrothersCompleted && !((Object)(object)EndGameQuest.activeTrueBrothersQuest != (Object)null) && !EndGameQuest.encounterActive && NetworkSingleton<TimeManager>.Instance.CurrentTime >= 1100 && NetworkSingleton<TimeManager>.Instance.CurrentTime <= 2300 && !((Object)(object)Player.Local.CurrentProperty != (Object)null) && EndGameQuest.TrueBrothersQuestPreRequirementsMet())
			{
				float num = Random.Range(0f, 1f);
				float num2 = Mathf.Lerp(0.98f, 0.7f, Mathf.Clamp01((float)alliedQuests.daysPassedSinceEncounter / 7f));
				if (!(num < num2))
				{
					CartelEnforcer.coros.Add(MelonCoroutines.Start(EndGameQuest.SummonConversateGoon()));
				}
			}
		}

		public static void OnSleepEndIncreaseEncounterChance()
		{
			if (EndGameQuest.TrueBrothersQuestPreRequirementsMet())
			{
				alliedQuests.daysPassedSinceEncounter++;
			}
		}

		public static void AssignDealerConfig(CartelDealer d)
		{
			//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_0007: 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_0023: Expected I4, but got Unknown
			EMapRegion region = ((NPC)d).Region;
			switch (region - 1)
			{
			case 0:
				((Dealer)d).DealerData.SalesCutPercentage = alliedConfig.WestvilleCartelDealerCut;
				((Dealer)d).DealerData.SigningFee = alliedConfig.WestvilleCartelSigningFee;
				break;
			case 1:
				((Dealer)d).DealerData.SalesCutPercentage = alliedConfig.DowntownCartelDealerCut;
				((Dealer)d).DealerData.SigningFee = alliedConfig.DowntownCartelSigningFee;
				break;
			case 2:
				((Dealer)d).DealerData.SalesCutPercentage = alliedConfig.DocksCartelDealerCut;
				((Dealer)d).DealerData.SigningFee = alliedConfig.DocksCartelSigningFee;
				break;
			case 3:
				((Dealer)d).DealerData.SalesCutPercentage = alliedConfig.SuburbiaCartelDealerCut;
				((Dealer)d).DealerData.SigningFee = alliedConfig.SuburbiaCartelSigningFee;
				break;
			case 4:
				((Dealer)d).DealerData.SalesCutPercentage = alliedConfig.UptownCartelDealerCut;
				((Dealer)d).DealerData.SigningFee = alliedConfig.UptownCartelSigningFee;
				break;
			default:
				((Dealer)d).DealerData.SalesCutPercentage = 99f;
				((Dealer)d).DealerData.SigningFee = 9999f;
				break;
			}
		}
	}
	[HarmonyPatch(typeof(CartelDealManager), "ExpireDeal")]
	public static class CartelDealManager_ExpireDeal_Patch
	{
		[HarmonyPrefix]
		public static bool Prefix(CartelDealManager __instance)
		{
			if (!CartelEnforcer.currentConfig.alliedExtensions)
			{
				return true;
			}
			((Quest)__instance.DealQuest).Expire(true);
			__instance.SendExpiryMessage();
			__instance.ActiveDeal = null;
			return false;
		}
	}
	[HarmonyPatch(typeof(CartelInfluenceChangePopup), "Show")]
	public static class CartelInfluenceChangePopup_Show_Patch
	{
		public static bool showEnqueued;

		[HarmonyPrefix]
		public static bool Prefix(CartelInfluenceChangePopup __instance, EMapRegion region, float oldInfluence, float newInfluence)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Invalid comparison between Unknown and I4
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			if (!CartelEnforcer.currentConfig.alliedExtensions)
			{
				return true;
			}
			if ((int)NetworkSingleton<Cartel>.Instance.Status != 1)
			{
				return true;
			}
			if (Singleton<LoadManager>.Instance.IsLoading)
			{
				return false;
			}
			if (newInfluence >= oldInfluence)
			{
				return false;
			}
			if (!showEnqueued)
			{
				showEnqueued = true;
				CartelEnforcer.coros.Add(MelonCoroutines.Start(InfluenceChangeAnimation(__instance, region, oldInfluence, newInfluence)));
			}
			return false;
		}

		public static bool CanShowInfluenceChange()
		{
			if (!Singleton<DialogueCanvas>.Instance.IsOpen && !Singleton<DealCompletionPopup>.Instance.IsPlaying)
			{
				return !Singleton<NewCustomerPopup>.Instance.IsPlaying;
			}
			return false;
		}

		public static IEnumerator InfluenceChangeAnimation(CartelInfluenceChangePopup __instance, EMapRegion region, float oldInfluence, float newInfluence)
		{
			//IL_000e: 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)
			yield return (object)new WaitUntil((Func<bool>)CanShowInfluenceChange);
			yield return (object)new WaitForSeconds(0.5f);
			__instance.SetDisplayedInfluence(oldInfluence);
			((TMP_Text)__instance.TitleLabel).text = $"Benzies' Influence in {region}";
			__instance.Anim.Play();
			yield return (object)new WaitForSeconds(0.8f);
			float elapsed = 0f;
			while (elapsed <= 1.5f)
			{
				elapsed += Time.deltaTime;
				float displayedInfluence = Mathf.Lerp(oldInfluence, newInfluence, elapsed / 1.5f);
				__instance.SetDisplayedInfluence(displayedInfluence);
				yield return (object)new WaitForEndOfFrame();
			}
			__instance.SetDisplayedInfluence(newInfluence);
			showEnqueued = false;
			yield return null;
		}
	}
	[HarmonyPatch(typeof(ContactsApp), "SetSelectedRegion")]
	public static class ContactsApp_SetSelectedRegion_Patch
	{
		[HarmonyPostfix]
		public unsafe static void Postfix(ContactsApp __instance, EMapRegion region, bool selectNPC)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Invalid comparison between Unknown and I4
			//IL_001b: 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_0051: 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_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Invalid comparison between Unknown and I4
			//IL_011f: 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)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0367: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_021d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0232: Unknown result type (might be due to invalid IL or missing references)
			//IL_0247: Unknown result type (might be due to invalid IL or missing references)
			//IL_025c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0270: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0305: Unknown result type (might be due to invalid IL or missing references)
			//IL_030b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0315: Unknown result type (might be due to invalid IL or missing references)
			//IL_031b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0339: Unknown result type (might be due to invalid IL or missing references)
			if (!CartelEnforcer.currentConfig.alliedExtensions || (int)NetworkSingleton<Cartel>.Instance.Status != 1 || (int)region == 0)
			{
				return;
			}
			float influence = NetworkSingleton<Cartel>.Instance.Influence.GetInfluence(region);
			((Component)__instance.LowerContainer).gameObject.SetActive(true);
			__instance.HorizontalScrollbarRectTransform.anchoredPosition = new Vector2(0f, 77f);
			((Component)__instance.UnlockRegionSliderNotch).gameObject.SetActive(true);
			__instance.InfluenceSlider.value = influence;
			__instance.InfluenceCountLabel.text = Mathf.RoundToInt(influence * 1000f) + " / 1000";
			__instance.InfluenceText.text = "Cartel influence in " + ((object)(*(EMapRegion*)(&region))/*cast due to .constrained prefix*/).ToString();
			if (Singleton<Map>.Instance.GetRegionData(region).IsUnlocked)
			{
				return;
			}
			if ((int)region >= 3 && ((Component)__instance.RegionLocked_Unavailable).gameObject.activeSelf)
			{
				((Component)__instance.RegionLocked_Unavailable).gameObject.SetActive(false);
			}
			((Component)__instance.RegionLockedContainer).gameObject.SetActive(true);
			((Component)__instance.RegionLocked_CartelInfluence).gameObject.SetActive(true);
			EMapRegion value = (EMapRegion)(region - 1);
			__instance.RegionLocked_CartelInfluence_Text.text = $"Reduce cartel influence in {value}\n\n\nto unlock this region.";
			Transform val = ((Component)__instance.RegionLocked_CartelInfluence_Text).transform.Find("CARTEL_ENFORCER_TEXT");
			if ((Object)(object)val == (Object)null)
			{
				GameObject val2 = new GameObject("CARTEL_ENFORCER_TEXT");
				val2.transform.parent = ((Component)__instance.RegionLocked_CartelInfluence_Text).transform;
				Text val3 = val2.AddComponent<Text>();
				val3.text = $"Or recruit the {value} Cartel Dealer";
				RectTransform component = val2.GetComponent<RectTransform>();
				component.anchoredPosition = Vector2.zero;
				component.anchoredPosition3D = Vector3.zero;
				component.anchorMax = new Vector2(0.5f, 0.5f);
				component.anchorMin = new Vector2(0.5f, 0.5f);
				component.offsetMax = new Vector2(150.5f, 214.25f);
				component.offsetMin = new Vector2(-150.5f, -214.25f);
				component.pivot = new Vector2(0.5f, 0.5f);
				component.sizeDelta = new Vector2(301f, 428.5f);
				val3.alignment = (TextAnchor)4;
				val3.fontSize = 28;
				val3.resizeTextMinSize = 0;
				((Graphic)val3).color = new Color(1f, 0.23f, 0.23f, 0.7f);
				Transform val4 = ((Component)__instance.RegionLocked_CartelInfluence_Text).transform.Find("Rank");
				if ((Object)(object)val4 != (Object)null)
				{
					Text component2 = ((Component)val4).GetComponent<Text>();
					if ((Object)(object)component2 != (Object)null)
					{
						val3.font = component2.font;
					}
				}
				val2.transform.localEulerAngles = Vector3.zero;
				val2.transform.localRotation = Quaternion.identity;
				val2.transform.localScale = Vector3.one;
				val2.transform.localPosition = new Vector3(0f, -105f, 0f);
			}
			else
			{
				((Component)val).gameObject.GetComponent<Text>().text = $"Or recruit the {value} Cartel Dealer";
			}
		}
	}
	[HarmonyPatch(typeof(Quest_DefeatCartel), "OnSleepEnd")]
	public static class Quest_DefeatCartel_OnSleepEnd_Patch
	{
		[HarmonyPrefix]
		public static bool Prefix(Quest_DefeatCartel __instance)
		{
			//IL_000f: 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: Invalid comparison between Unknown and I4
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Invalid comparison between Unknown and I4
			if (!CartelEnforcer.currentConfig.alliedExtensions)
			{
				return true;
			}
			if ((int)((Quest)__instance).State == 0 && Singleton<Map>.Instance.GetRegionData((EMapRegion)5).IsUnlocked && ((int)NetworkSingleton<Cartel>.Instance.Status == 1 || (int)NetworkSingleton<Cartel>.Instance.Status == 2))
			{
				((Quest)__instance).Begin(true);
			}
			return true;
		}
	}
	public static class AlliedCartelDialogue
	{
		public static readonly List<string> dealerEntryNodeTexts = new List<string> { "You've got a lot of nerve showing up like this.", "What's your problem?", "What do you want?!", "Start talking or start walking young punk." };

		public static readonly List<string> alliedDialogueKeys = new List<string> { "CLOTHING_SIMILARITY", "CARTEL_INFLUENCE", "THREATEN_CARTEL", "SPREAD_RUMOURS", "EXIT" };

		public static readonly Dictionary<string, List<string>> alliedDialogue = new Dictionary<string, List<string>>
		{
			{
				alliedDialogueKeys[0],
				new List<string> { "Check out my new drip.", "Same style, same goals, yeah?", "You're rocking the same vest?" }
			},
			{
				alliedDialogueKeys[1],
				new List<string> { "The Benzies are small time!", "Are the Benzies having it rough lately?", "The Benzies are a bunch of young punks." }
			},
			{
				alliedDialogueKeys[2],
				new List<string> { "Check the piece. You want a taste of lead?", "I'm packing some serious heat.", "You're about to get yo' ass whooped." }
			},
			{
				alliedDialogueKeys[3],
				new List<string> { "You know that Thomas has been talking to the cops right?", "I heard that Thomas is going to cut you out.", "Better watch out, that Thomas is a snake." }
			},
			{
				alliedDialogueKeys[4],
				new List<string> { "Nevermind.", "I got to go." }
			}
		};

		public static Dictionary<string, float> persuasionChances = new Dictionary<string, float>
		{
			{
				alliedDialogueKeys[0],
				0f
			},
			{
				alliedDialogueKeys[1],
				0f
			},
			{
				alliedDialogueKeys[2],
				0f
			},
			{
				alliedDialogueKeys[3],
				0f
			}
		};

		public static readonly Dictionary<string, float> persuasionBaseChances = new Dictionary<string, float>
		{
			{
				alliedDialogueKeys[0],
				CartelPersuade.CLOTHING_SIMILARITY_BASE_CHANCE
			},
			{
				alliedDialogueKeys[1],
				CartelPersuade.CARTEL_INFLUENCE_BASE_CHANCE
			},
			{
				alliedDialogueKeys[2],
				CartelPersuade.THREATEN_CARTEL_BASE_CHANCE
			},
			{
				alliedDialogueKeys[3],
				CartelPersuade.SPREAD_RUMOURS_BASE_CHANCE
			}
		};
	}
	public static class CartelPersuade
	{
		public static readonly float CLOTHING_SIMILARITY_BASE_CHANCE = 0.01f;

		public static readonly float CLOTHING_SIMILARITY_MAX_CHANCE = 0.85f;

		public static readonly float CARTEL_INFLUENCE_BASE_CHANCE = 0.02f;

		public static readonly float CARTEL_INFLUENCE_MAX_CHANCE = 0.35f;

		public static readonly float THREATEN_CARTEL_BASE_CHANCE = 0.01f;

		public static readonly float THREATEN_CARTEL_MAX_CHANCE = 0.6f;

		public static readonly float SPREAD_RUMOURS_BASE_CHANCE = 0.03f;

		public static readonly float SPREAD_RUMOURS_MAX_CHANCE = 0.45f;

		public static int persuadeCooldown = 60;

		public static readonly float colorSimilarityThreshold = 0.2f;

		public static void ReduceCooldown()
		{
			if (CartelEnforcer.currentConfig.alliedExtensions && persuadeCooldown > 0)
			{
				persuadeCooldown--;
			}
		}

		public static DialogueContainer InitPersuadeContainer()
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Expected O, but got Unknown
			//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_00a4: 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_00bf: Expected O, but got Unknown
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Expected O, but got Unknown
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Expected O, but got Unknown
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Expected O, but got Unknown
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Expected O, but got Unknown
			DialogueContainer val = ScriptableObject.CreateInstance<DialogueContainer>();
			((Object)val).name = "CARTEL_ENFORCER_PERSUADE