Decompiled source of Cartel Enforcer MONO v1.6.0

CartelEnforcer.dll

Decompiled a month 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.Utils;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using ScheduleOne;
using ScheduleOne.AvatarFramework;
using ScheduleOne.AvatarFramework.Equipping;
using ScheduleOne.Cartel;
using ScheduleOne.Combat;
using ScheduleOne.DevUtilities;
using ScheduleOne.Dialogue;
using ScheduleOne.Doors;
using ScheduleOne.Economy;
using ScheduleOne.GameTime;
using ScheduleOne.Interaction;
using ScheduleOne.ItemFramework;
using ScheduleOne.Law;
using ScheduleOne.Levelling;
using ScheduleOne.Map;
using ScheduleOne.Messaging;
using ScheduleOne.Money;
using ScheduleOne.NPCs;
using ScheduleOne.NPCs.Behaviour;
using ScheduleOne.NPCs.CharacterClasses;
using ScheduleOne.NPCs.Other;
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.Messages;
using ScheduleOne.Vehicles;
using ScheduleOne.Vehicles.AI;
using ScheduleOne.VoiceOver;
using TMPro;
using UnityEngine;
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", "1.6.0", "XOWithSauce", null)]
[assembly: MelonColor]
[assembly: MelonOptionalDependencies(new string[] { "FishNet.Runtime" })]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("XOWithSauce")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCopyright("Copyright XOWithSauce 2025 Source MIT")]
[assembly: AssemblyDescription("Schedule I Cartel Enforcer Mod")]
[assembly: AssemblyFileVersion("1.6.0.0")]
[assembly: AssemblyInformationalVersion("1.6.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]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static UnityAction <0>__OnDealerDied;
		}

		[CompilerGenerated]
		private sealed class <DespawnDefenderGoonsSoon>d__16 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public List<CartelGoon> goons;

			private int <maxHoursWaited>5__2;

			private int <goonsDead>5__3;

			private int <i>5__4;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <DespawnDefenderGoonsSoon>d__16(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<maxHoursWaited>5__2 = 2;
					<goonsDead>5__3 = 0;
					<i>5__4 = 0;
					goto IL_00fd;
				case 1:
					<>1__state = -1;
					foreach (CartelGoon goon in goons)
					{
						if ((((NPC)goon).Health.IsDead || ((NPC)goon).Health.IsKnockedOut) && goon.IsGoonSpawned)
						{
							<goonsDead>5__3++;
							((NPC)goon).Health.Revive();
							goon.Despawn();
							((Behaviour)((NPC)goon).Behaviour.CombatBehaviour).Disable_Networked((NetworkConnection)null);
						}
					}
					if (<goonsDead>5__3 != goons.Count)
					{
						<i>5__4++;
						goto IL_00fd;
					}
					goto IL_010e;
				case 2:
					{
						<>1__state = -1;
						return false;
					}
					IL_010e:
					foreach (CartelGoon goon2 in goons)
					{
						if (goon2.IsGoonSpawned)
						{
							goon2.Despawn();
							((Behaviour)((NPC)goon2).Behaviour.CombatBehaviour).Disable_Networked((NetworkConnection)null);
						}
					}
					<>2__current = null;
					<>1__state = 2;
					return true;
					IL_00fd:
					if (<i>5__4 < <maxHoursWaited>5__2)
					{
						<>2__current = CartelEnforcer.Wait60;
						<>1__state = 1;
						return true;
					}
					goto IL_010e;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		[CompilerGenerated]
		private sealed class <EvaluateDealerState>d__13 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			private bool <isHostile>5__2;

			private bool <safetyThresholdMet>5__3;

			private CartelDealer[] <>7__wrap3;

			private int <>7__wrap4;

			private CartelDealer <d>5__6;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <EvaluateDealerState>d__13(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>7__wrap3 = null;
				<d>5__6 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_006c: Unknown result type (might be due to invalid IL or missing references)
				//IL_012b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0131: Invalid comparison between Unknown and I4
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = CartelEnforcer.Wait5;
					<>1__state = 1;
					return true;
				case 1:
				{
					<>1__state = -1;
					allCartelDealers = Object.FindObjectsOfType<CartelDealer>(true);
					Dealer[] array = Object.FindObjectsOfType<Dealer>(true);
					foreach (Dealer val in array)
					{
						if ((int)val.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));
					goto IL_051d;
				}
				case 2:
					<>1__state = -1;
					if (!CartelEnforcer.registered)
					{
						return false;
					}
					if (NetworkSingleton<TimeManager>.Instance.CurrentTime >= 1620 || NetworkSingleton<TimeManager>.Instance.CurrentTime <= 359)
					{
						<isHostile>5__2 = true;
						if ((int)NetworkSingleton<Cartel>.Instance.Status != 2)
						{
							<isHostile>5__2 = false;
						}
						if (currentDealerActivity != previousDealerActivity)
						{
							int num = 0;
							int num2 = 0;
							int num3 = 0;
							if (currentDealerActivity > 0f)
							{
								int minSumFrom24HourTime = TimeManager.GetMinSumFrom24HourTime(currentStayInsideStart);
								int minSumFrom24HourTime2 = TimeManager.GetMinSumFrom24HourTime(359);
								int num4 = Mathf.RoundToInt(Mathf.Lerp((float)minSumFrom24HourTime, (float)minSumFrom24HourTime2, currentDealerActivity));
								num = TimeManager.Get24HourTimeFromMinSum(num4);
								if (num == 400)
								{
									num = 359;
								}
								int minSumFrom24HourTime3 = TimeManager.GetMinSumFrom24HourTime(currentStayInsideEnd);
								int minSumFrom24HourTime4 = TimeManager.GetMinSumFrom24HourTime(1620);
								int num5 = Mathf.RoundToInt(Mathf.Lerp((float)minSumFrom24HourTime3, (float)minSumFrom24HourTime4, currentDealerActivity));
								num2 = TimeManager.Get24HourTimeFromMinSum(num5);
								num3 = num5 - num4;
							}
							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));
								num = TimeManager.Get24HourTimeFromMinSum(num7);
								int minSumFrom24HourTime7 = TimeManager.GetMinSumFrom24HourTime(currentStayInsideEnd);
								int minSumFrom24HourTime8 = TimeManager.GetMinSumFrom24HourTime(2359);
								int num8 = Mathf.RoundToInt(Mathf.Lerp((float)minSumFrom24HourTime7, (float)minSumFrom24HourTime8, num6));
								num2 = TimeManager.Get24HourTimeFromMinSum(num8);
								num3 = num8 - num7;
							}
							else
							{
								num = defaultStayInsideStart;
								num2 = defaultStayInsideEnd;
								num3 = defaultStayInsideDur;
							}
							currentStayInsideStart = num;
							currentStayInsideEnd = num2;
							currentStayInsideDur = num3;
							<>7__wrap3 = allCartelDealers;
							<>7__wrap4 = 0;
							goto IL_02f7;
						}
						goto IL_030e;
					}
					goto IL_051d;
				case 3:
					<>1__state = -1;
					if (!CartelEnforcer.registered)
					{
						return false;
					}
					ApplyNewEventState(<d>5__6, currentStayInsideStart, currentStayInsideEnd, currentStayInsideDur);
					<d>5__6 = null;
					<>7__wrap4++;
					goto IL_02f7;
				case 4:
					<>1__state = -1;
					if (!CartelEnforcer.registered)
					{
						return false;
					}
					ApplyNewEventState(<d>5__6, 0, 2359, 1440);
					<d>5__6.SetIsAcceptingDeals(false);
					<d>5__6 = null;
					<>7__wrap4++;
					goto IL_03cb;
				case 5:
					<>1__state = -1;
					if (!CartelEnforcer.registered)
					{
						return false;
					}
					if (!((NPC)<d>5__6).isInBuilding && !((NPC)<d>5__6).Movement.HasDestination && !((NPC)<d>5__6).Health.IsDead && !((NPC)<d>5__6).Health.IsKnockedOut)
					{
						WalkToInterestPoint(<d>5__6);
					}
					<d>5__6 = null;
					<>7__wrap4++;
					goto IL_04a9;
				case 6:
					<>1__state = -1;
					if (!CartelEnforcer.registered)
					{
						return false;
					}
					goto IL_051d;
				case 7:
					{
						<>1__state = -1;
						return false;
					}
					IL_030e:
					previousDealerActivity = currentDealerActivity;
					<safetyThresholdMet>5__3 = false;
					if (dealerConfig.SafetyEnabled && currentDealerActivity <= dealerConfig.SafetyThreshold)
					{
						<safetyThresholdMet>5__3 = true;
						<>7__wrap3 = allCartelDealers;
						<>7__wrap4 = 0;
						goto IL_03cb;
					}
					goto IL_03e2;
					IL_03cb:
					if (<>7__wrap4 < <>7__wrap3.Length)
					{
						<d>5__6 = <>7__wrap3[<>7__wrap4];
						<>2__current = CartelEnforcer.Wait05;
						<>1__state = 4;
						return true;
					}
					<>7__wrap3 = null;
					goto IL_03e2;
					IL_051d:
					if (CartelEnforcer.registered)
					{
						<>2__current = CartelEnforcer.Wait60;
						<>1__state = 2;
						return true;
					}
					<>2__current = null;
					<>1__state = 7;
					return true;
					IL_02f7:
					if (<>7__wrap4 < <>7__wrap3.Length)
					{
						<d>5__6 = <>7__wrap3[<>7__wrap4];
						<>2__current = CartelEnforcer.Wait05;
						<>1__state = 3;
						return true;
					}
					<>7__wrap3 = null;
					goto IL_030e;
					IL_04a9:
					if (<>7__wrap4 < <>7__wrap3.Length)
					{
						<d>5__6 = <>7__wrap3[<>7__wrap4];
						<>2__current = CartelEnforcer.Wait2;
						<>1__state = 5;
						return true;
					}
					<>7__wrap3 = null;
					<>2__current = CartelEnforcer.Wait60;
					<>1__state = 6;
					return true;
					IL_03e2:
					if (!<safetyThresholdMet>5__3)
					{
						if (!<isHostile>5__2)
						{
							<>7__wrap3 = allCartelDealers;
							<>7__wrap4 = 0;
							goto IL_04a9;
						}
						if (NetworkSingleton<TimeManager>.Instance.CurrentTime >= currentStayInsideEnd || NetworkSingleton<TimeManager>.Instance.CurrentTime <= currentStayInsideStart)
						{
							CartelEnforcer.coros.Add(MelonCoroutines.Start(StartActiveSignal()));
						}
					}
					goto IL_051d;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		[CompilerGenerated]
		private sealed class <OnCartelCustomerDeal>d__21 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public bool started;

			public CartelCustomerDeal dealEvent;

			private List<Customer> <regionLockedCustomers>5__2;

			private int <i>5__3;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <OnCartelCustomerDeal>d__21(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<regionLockedCustomers>5__2 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
				//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
				//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
				//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
				//IL_0207: Unknown result type (might be due to invalid IL or missing references)
				//IL_020c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0215: Unknown result type (might be due to invalid IL or missing references)
				//IL_0217: Unknown result type (might be due to invalid IL or missing references)
				//IL_02da: Unknown result type (might be due to invalid IL or missing references)
				//IL_02f6: 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_02fe: Unknown result type (might be due to invalid IL or missing references)
				//IL_0261: Unknown result type (might be due to invalid IL or missing references)
				//IL_0263: Unknown result type (might be due to invalid IL or missing references)
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = CartelEnforcer.Wait2;
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					if (started)
					{
						<regionLockedCustomers>5__2 = new List<Customer>();
						<i>5__3 = 0;
						goto IL_005e;
					}
					goto IL_0349;
				case 2:
				{
					<>1__state = -1;
					if (<i>5__3 < Customer.LockedCustomers.Count)
					{
						if (Customer.LockedCustomers[<i>5__3].NPC.Region == ((CartelActivity)dealEvent).Region && !<regionLockedCustomers>5__2.Contains(Customer.LockedCustomers[<i>5__3]))
						{
							<regionLockedCustomers>5__2.Add(Customer.LockedCustomers[<i>5__3]);
						}
						<i>5__3++;
						if (<i>5__3 < Customer.LockedCustomers.Count && CartelEnforcer.registered)
						{
							goto IL_005e;
						}
					}
					if (<regionLockedCustomers>5__2.Count == 0)
					{
						((CartelActivity)dealEvent).Deactivate();
						return false;
					}
					Customer val = <regionLockedCustomers>5__2[Random.Range(0, <regionLockedCustomers>5__2.Count)];
					bool flag = true;
					if ((Object)(object)val.CurrentContract != (Object)null)
					{
						flag = false;
					}
					if (!val.NPC.IsConscious)
					{
						flag = false;
					}
					int orderTime = val.customerData.OrderTime;
					int num = TimeManager.AddMinutesTo24HourTime(orderTime, 240);
					if (!NetworkSingleton<TimeManager>.Instance.IsCurrentTimeWithinRange(orderTime, num))
					{
						flag = false;
					}
					if (!flag)
					{
						((CartelActivity)dealEvent).Deactivate();
						return false;
					}
					EQuality correspondingQuality = StandardsMethod.GetCorrespondingQuality(val.customerData.Standards);
					new List<ProductDefinition>();
					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)
					{
						ItemInstance defaultInstance = Registry.GetItem("cocaine").GetDefaultInstance(4);
						QualityItemInstance val3 = (QualityItemInstance)(object)((defaultInstance is QualityItemInstance) ? defaultInstance : null);
						if (val3 != null)
						{
							val3.Quality = correspondingQuality;
						}
						if (((NPC)dealEvent.dealer).Inventory.CanItemFit(defaultInstance))
						{
							((NPC)dealEvent.dealer).Inventory.InsertItem(defaultInstance, true);
						}
					}
					ContractInfo val4 = val.TryGenerateContract((Dealer)(object)dealEvent.dealer);
					if (val4 != null)
					{
						int offeredDeals = val.OfferedDeals;
						val.OfferedDeals = offeredDeals + 1;
						val.TimeSinceLastDealOffered = 0;
						val.OfferedContractInfo = val4;
						val.OfferedContractTime = NetworkSingleton<TimeManager>.Instance.GetDateTime();
						val.HasChanged = true;
						EDealWindow dealWindow = ((Dealer)dealEvent.dealer).GetDealWindow();
						Contract val5 = val.ContractAccepted(dealWindow, false, (Dealer)(object)dealEvent.dealer);
						((Quest)val5).CompletionXP = 0;
						val5.completedContractsIncremented = false;
						((Dealer)dealEvent.dealer).AddContract(val5);
					}
					else
					{
						((CartelActivity)dealEvent).Deactivate();
					}
					<regionLockedCustomers>5__2 = null;
					goto IL_0349;
				}
				case 3:
					{
						<>1__state = -1;
						return false;
					}
					IL_005e:
					<>2__current = CartelEnforcer.Wait025;
					<>1__state = 2;
					return true;
					IL_0349:
					<>2__current = null;
					<>1__state = 3;
					return true;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		[CompilerGenerated]
		private sealed class <StartActiveSignal>d__17 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			private List<Contract> <validContracts>5__2;

			private List<Customer> <cList>5__3;

			private List<Customer> <validCustomers>5__4;

			private List<Dealer>.Enumerator <>7__wrap4;

			private Dealer <playerDealer>5__6;

			private int <i>5__7;

			private CartelDealer[] <>7__wrap7;

			private CartelDealer <d>5__9;

			private bool <actionTaken>5__10;

			private Customer <c>5__11;

			private ContractInfo <contractInfo>5__12;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <StartActiveSignal>d__17(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				int num = <>1__state;
				if (num == -3 || num == 1)
				{
					try
					{
					}
					finally
					{
						<>m__Finally1();
					}
				}
				<validContracts>5__2 = null;
				<cList>5__3 = null;
				<validCustomers>5__4 = null;
				<>7__wrap4 = default(List<Dealer>.Enumerator);
				<playerDealer>5__6 = null;
				<>7__wrap7 = null;
				<d>5__9 = null;
				<c>5__11 = null;
				<contractInfo>5__12 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_05e2: Unknown result type (might be due to invalid IL or missing references)
				//IL_05e7: Unknown result type (might be due to invalid IL or missing references)
				//IL_05ef: Unknown result type (might be due to invalid IL or missing references)
				//IL_0495: Unknown result type (might be due to invalid IL or missing references)
				//IL_049f: Expected O, but got Unknown
				bool result;
				try
				{
					Contract val;
					switch (<>1__state)
					{
					default:
						result = false;
						break;
					case 0:
						<>1__state = -1;
						<validContracts>5__2 = new List<Contract>();
						val = null;
						<>7__wrap4 = allDealers.GetEnumerator();
						<>1__state = -3;
						goto IL_011b;
					case 1:
						<>1__state = -3;
						if (!CartelEnforcer.registered)
						{
							result = false;
							<>m__Finally1();
							break;
						}
						if (<playerDealer>5__6.ActiveContracts.Count != 0)
						{
							val = <playerDealer>5__6.ActiveContracts[Random.Range(0, <playerDealer>5__6.ActiveContracts.Count)];
							if (!InterceptEvent.contractGuids.Contains(((Quest)val).GUID.ToString()) && !<validContracts>5__2.Contains(val))
							{
								<validContracts>5__2.Add(val);
							}
							<playerDealer>5__6 = null;
						}
						goto IL_011b;
					case 2:
						<>1__state = -1;
						if (!CartelEnforcer.registered)
						{
							result = false;
							break;
						}
						<cList>5__3.Add(Customer.UnlockedCustomers[<i>5__7]);
						<i>5__7++;
						goto IL_01bb;
					case 3:
					{
						<>1__state = -1;
						if (!CartelEnforcer.registered)
						{
							result = false;
							break;
						}
						Customer val2 = <cList>5__3[Random.Range(0, <cList>5__3.Count)];
						if ((Object)(object)val2.CurrentContract == (Object)null && (Object)(object)val2.AssignedDealer == (Object)null && val2.offeredContractInfo != null)
						{
							<validCustomers>5__4.Add(val2);
						}
						<cList>5__3.Remove(val2);
						if (<cList>5__3.Count > 0)
						{
							goto IL_01d8;
						}
						<>7__wrap7 = allCartelDealers;
						<i>5__7 = 0;
						goto IL_0706;
					}
					case 4:
						<>1__state = -1;
						if (!CartelEnforcer.registered)
						{
							result = false;
							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>5__9)) && !((NPC)<d>5__9).Health.IsDead && !((NPC)<d>5__9).Health.IsKnockedOut)
							{
								if (((Dealer)<d>5__9).ActiveContracts.Count == 0)
								{
									<actionTaken>5__10 = false;
									if (<validContracts>5__2.Count > 0 && Random.Range(0.01f, 1f) < dealerConfig.StealDealerContractChance)
									{
										val = <validContracts>5__2[Random.Range(0, <validContracts>5__2.Count)];
										if ((Object)(object)val != (Object)null)
										{
											<actionTaken>5__10 = true;
											((Quest)val).CompletionXP = 0;
											val.completedContractsIncremented = false;
											((Dealer)<d>5__9).AddContract(val);
											((Component)((NPC)<d>5__9).Behaviour.ScheduleManager.ActionList[0]).gameObject.SetActive(true);
										}
										<validContracts>5__2.Remove(val);
									}
									else if (<validCustomers>5__4.Count > 0 && Random.Range(0.01f, 1f) < dealerConfig.StealPlayerPendingChance)
									{
										<c>5__11 = <validCustomers>5__4[Random.Range(0, <validCustomers>5__4.Count)];
										if ((Object)(object)<c>5__11.CurrentContract == (Object)null && (Object)(object)<c>5__11.AssignedDealer == (Object)null && <c>5__11.offeredContractInfo != null)
										{
											<contractInfo>5__12 = new ContractInfo();
											<contractInfo>5__12.DeliveryLocation = <c>5__11.offeredContractInfo.DeliveryLocation;
											<contractInfo>5__12.DeliveryLocationGUID = <c>5__11.offeredContractInfo.DeliveryLocationGUID;
											<contractInfo>5__12.Payment = <c>5__11.offeredContractInfo.Payment;
											<contractInfo>5__12.Expires = <c>5__11.offeredContractInfo.Expires;
											<contractInfo>5__12.DeliveryWindow = <c>5__11.offeredContractInfo.DeliveryWindow;
											<contractInfo>5__12.PickupScheduleIndex = <c>5__11.offeredContractInfo.PickupScheduleIndex;
											<contractInfo>5__12.ExpiresAfter = <c>5__11.offeredContractInfo.ExpiresAfter;
											<contractInfo>5__12.IsCounterOffer = <c>5__11.offeredContractInfo.IsCounterOffer;
											<contractInfo>5__12.Products = <c>5__11.offeredContractInfo.Products;
											<c>5__11.ExpireOffer();
											<>2__current = CartelEnforcer.Wait01;
											<>1__state = 5;
											result = true;
											break;
										}
										goto IL_0655;
									}
									goto IL_066e;
								}
								if (!((Component)((NPC)<d>5__9).Behaviour.ScheduleManager.ActionList[0]).gameObject.activeSelf)
								{
									((Component)((NPC)<d>5__9).Behaviour.ScheduleManager.ActionList[0]).gameObject.SetActive(true);
								}
							}
							goto IL_06f8;
						}
						goto IL_0719;
					case 5:
					{
						<>1__state = -1;
						if (!CartelEnforcer.registered)
						{
							result = false;
							break;
						}
						<c>5__11.offeredContractInfo = <contractInfo>5__12;
						EDealWindow dealWindow = ((Dealer)<d>5__9).GetDealWindow();
						val = <c>5__11.ContractAccepted(dealWindow, false, (Dealer)(object)<d>5__9);
						if ((Object)(object)val != (Object)null)
						{
							((Quest)val).CompletionXP = 0;
							val.completedContractsIncremented = false;
							((Dealer)<d>5__9).AddContract(val);
							((Component)((NPC)<d>5__9).Behaviour.ScheduleManager.ActionList[0]).gameObject.SetActive(true);
							<actionTaken>5__10 = true;
						}
						<contractInfo>5__12 = null;
						goto IL_0655;
					}
					case 6:
						{
							<>1__state = -1;
							result = false;
							break;
						}
						IL_01bb:
						if (<i>5__7 < Customer.UnlockedCustomers.Count)
						{
							<>2__current = CartelEnforcer.Wait01;
							<>1__state = 2;
							result = true;
							break;
						}
						<validCustomers>5__4 = new List<Customer>();
						goto IL_01d8;
						IL_0706:
						if (<i>5__7 < <>7__wrap7.Length)
						{
							<d>5__9 = <>7__wrap7[<i>5__7];
							<>2__current = CartelEnforcer.Wait2;
							<>1__state = 4;
							result = true;
							break;
						}
						goto IL_0719;
						IL_01d8:
						<>2__current = CartelEnforcer.Wait01;
						<>1__state = 3;
						result = true;
						break;
						IL_06f8:
						<i>5__7++;
						goto IL_0706;
						IL_0719:
						<>7__wrap7 = null;
						<cList>5__3.Clear();
						<validCustomers>5__4.Clear();
						<validContracts>5__2.Clear();
						<>2__current = null;
						<>1__state = 6;
						result = true;
						break;
						IL_011b:
						if (<>7__wrap4.MoveNext())
						{
							<playerDealer>5__6 = <>7__wrap4.Current;
							<>2__current = CartelEnforcer.Wait01;
							<>1__state = 1;
							result = true;
							break;
						}
						<>m__Finally1();
						<>7__wrap4 = default(List<Dealer>.Enumerator);
						val = null;
						<cList>5__3 = new List<Customer>();
						<i>5__7 = 0;
						goto IL_01bb;
						IL_0655:
						<validCustomers>5__4.Remove(<c>5__11);
						<c>5__11 = null;
						goto IL_066e;
						IL_066e:
						if (!<actionTaken>5__10 && !((NPC)<d>5__9).isInBuilding && !((NPC)<d>5__9).Movement.HasDestination)
						{
							WalkToInterestPoint(<d>5__9);
						}
						<d>5__9 = null;
						goto IL_06f8;
					}
				}
				catch
				{
					//try-fault
					((IDisposable)this).Dispose();
					throw;
				}
				return result;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			private void <>m__Finally1()
			{
				<>1__state = -1;
				((IDisposable)<>7__wrap4).Dispose();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

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

		private 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;

		[IteratorStateMachine(typeof(<EvaluateDealerState>d__13))]
		public static IEnumerator EvaluateDealerState()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <EvaluateDealerState>d__13(0);
		}

		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_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02af: Expected O, but got Unknown
			//IL_027c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0281: Unknown result type (might be due to invalid IL or missing references)
			//IL_0287: Expected O, but got Unknown
			string text = "";
			text = dealerConfig.CartelDealerWeapon.ToLower() switch
			{
				"m1911" => "Avatar/Equippables/M1911", 
				"knife" => "Avatar/Equippables/Knife", 
				"shotgun" => "Avatar/Equippables/PumpShotgun", 
				_ => "Avatar/Equippables/M1911", 
			};
			Object obj = Resources.Load(text);
			AvatarEquippable component = Object.Instantiate<GameObject>((GameObject)(object)((obj is GameObject) ? obj : null), new Vector3(0f, -5f, 0f), Quaternion.identity, (Transform)null).GetComponent<AvatarEquippable>();
			CartelDealer[] array = allCartelDealers;
			foreach (CartelDealer dealer in array)
			{
				((NPC)dealer).Movement.MoveSpeedMultiplier = dealerConfig.CartelDealerMoveSpeedMultiplier;
				((NPC)dealer).Health.MaxHealth = dealerConfig.CartelDealerHP;
				((NPC)dealer).Health.Health = dealerConfig.CartelDealerHP;
				AvatarWeapon val = (AvatarWeapon)(object)((component is AvatarWeapon) ? component : null);
				if (val != null)
				{
					((NPC)dealer).Behaviour.CombatBehaviour.DefaultWeapon = val;
				}
				((NPC)dealer).Behaviour.CombatBehaviour.SetWeapon(text);
				((NPC)dealer).OverrideAggression(1f);
				NPCEvent_StayInBuilding val2 = null;
				NPCSignal_HandleDeal val3 = null;
				if (((NPC)dealer).Behaviour.ScheduleManager.ActionList != null)
				{
					foreach (NPCAction action in ((NPC)dealer).Behaviour.ScheduleManager.ActionList)
					{
						NPCEvent_StayInBuilding val4 = (NPCEvent_StayInBuilding)(object)((action is NPCEvent_StayInBuilding) ? action : null);
						if (val4 != null)
						{
							val2 = val4;
							continue;
						}
						NPCSignal_HandleDeal val5 = (NPCSignal_HandleDeal)(object)((action is NPCSignal_HandleDeal) ? action : null);
						if (val5 != null)
						{
							val3 = val5;
						}
					}
					if ((Object)(object)val2 != (Object)null)
					{
						((NPCAction)val2).StartTime = defaultStayInsideStart;
						((NPCEvent)val2).EndTime = defaultStayInsideEnd;
						((NPCEvent)val2).Duration = defaultStayInsideDur;
						((NPCAction)val2).onEnded = (Action)Delegate.Combine(((NPCAction)val2).onEnded, new Action(onStayInsideEnd));
					}
					if ((Object)(object)val3 != (Object)null)
					{
						((NPCSignal)val3).MaxDuration = 60;
						((NPCAction)val3).onEnded = (Action)Delegate.Combine(((NPCAction)val3).onEnded, new Action(onDealSignalEnd));
					}
				}
				UnityEvent onDieOrKnockedOut = ((NPC)dealer).Health.onDieOrKnockedOut;
				object obj2 = <>O.<0>__OnDealerDied;
				if (obj2 == null)
				{
					UnityAction val6 = OnDealerDied;
					<>O.<0>__OnDealerDied = val6;
					obj2 = (object)val6;
				}
				onDieOrKnockedOut.AddListener((UnityAction)obj2);
				((NPC)dealer).Health.onDieOrKnockedOut.AddListener(new UnityAction(TrySpawnGoonsOnDeath));
				void TrySpawnGoonsOnDeath()
				{
					//IL_0030: Unknown result type (might be due to invalid IL or missing references)
					//IL_003e: Unknown result type (might be due to invalid IL or missing references)
					//IL_0043: Unknown result type (might be due to invalid IL or missing references)
					//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
					//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
					//IL_0058: Unknown result type (might be due to invalid IL or missing references)
					//IL_005d: Unknown result type (might be due to invalid IL or missing references)
					//IL_008c: Unknown result type (might be due to invalid IL or missing references)
					//IL_0091: Unknown result type (might be due to invalid IL or missing references)
					//IL_0093: Unknown result type (might be due to invalid IL or missing references)
					//IL_0098: Unknown result type (might be due to invalid IL or missing references)
					//IL_009d: Unknown result type (might be due to invalid IL or missing references)
					//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
					//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
					if (!(Random.Range(0f, 1f) > 0.5f) && NetworkSingleton<Cartel>.Instance.GoonPool.UnspawnedGoonCount >= 2)
					{
						float num = default(float);
						Player closestPlayer = Player.GetClosestPlayer(((NPC)dealer).CenterPoint, ref num, (List<Player>)null);
						Vector3 val7 = 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);
							val7 = ((Component)dealer).transform.position + onUnitSphere * num4;
							num3++;
						}
						while (closestPlayer.IsPointVisibleToPlayer(val7, 30f, 5f));
						if (!(val7 == Vector3.zero))
						{
							List<CartelGoon> list = NetworkSingleton<Cartel>.Instance.GoonPool.SpawnMultipleGoons(val7, 2, true);
							foreach (CartelGoon item in list)
							{
								((NPC)item).Movement.WarpToNavMesh();
								if (Random.Range(0f, 1f) > 0.7f && CartelEnforcer.RangedWeapons != null && CartelEnforcer.RangedWeapons.Length != 0)
								{
									((NPC)item).Behaviour.CombatBehaviour.DefaultWeapon = CartelEnforcer.RangedWeapons[Random.Range(0, CartelEnforcer.RangedWeapons.Length)];
								}
								else if (CartelEnforcer.MeleeWeapons != null && CartelEnforcer.MeleeWeapons.Length != 0)
								{
									((NPC)item).Behaviour.CombatBehaviour.DefaultWeapon = CartelEnforcer.MeleeWeapons[Random.Range(0, CartelEnforcer.MeleeWeapons.Length)];
								}
								item.AttackEntity(((Component)closestPlayer).GetComponent<ICombatTargetable>(), true);
							}
							CartelEnforcer.coros.Add(MelonCoroutines.Start(DespawnDefenderGoonsSoon(list)));
						}
					}
				}
				void onDealSignalEnd()
				{
					if (!InterceptEvent.interceptingDeal || !((Object)(object)InterceptEvent.interceptor != (Object)null) || !((Object)(object)dealer == (Object)(object)InterceptEvent.interceptor))
					{
						if (NetworkSingleton<TimeManager>.Instance.CurrentTime <= 359 || NetworkSingleton<TimeManager>.Instance.CurrentTime >= 1600)
						{
							if (((Dealer)dealer).ActiveContracts.Count == 0)
							{
								if (!dealer.IsAcceptingDeals)
								{
									dealer.SetIsAcceptingDeals(true);
								}
								WalkToInterestPoint(dealer);
							}
						}
						else if (NetworkSingleton<TimeManager>.Instance.CurrentTime > 359 && NetworkSingleton<TimeManager>.Instance.CurrentTime < 1600)
						{
							if (((Dealer)dealer).ActiveContracts.Count > 0)
							{
								if ((Object)(object)InterceptEvent.interceptor != (Object)null && (Object)(object)dealer == (Object)(object)InterceptEvent.interceptor)
								{
									return;
								}
								((Quest)((Dealer)dealer).ActiveContracts[0]).Fail(true);
							}
							if (dealer.IsAcceptingDeals)
							{
								dealer.SetIsAcceptingDeals(false);
							}
						}
					}
				}
				void onStayInsideEnd()
				{
					if (!InterceptEvent.interceptingDeal || !((Object)(object)InterceptEvent.interceptor != (Object)null) || !((Object)(object)dealer == (Object)(object)InterceptEvent.interceptor))
					{
						if (NetworkSingleton<TimeManager>.Instance.CurrentTime <= 359 || NetworkSingleton<TimeManager>.Instance.CurrentTime >= 1600)
						{
							if (!dealer.IsAcceptingDeals)
							{
								dealer.SetIsAcceptingDeals(true);
							}
							WalkToInterestPoint(dealer);
						}
						else if (NetworkSingleton<TimeManager>.Instance.CurrentTime > 359 && NetworkSingleton<TimeManager>.Instance.CurrentTime < 1600)
						{
							if (((Dealer)dealer).ActiveContracts.Count > 0)
							{
								if ((Object)(object)InterceptEvent.interceptor != (Object)null && (Object)(object)dealer == (Object)(object)InterceptEvent.interceptor)
								{
									return;
								}
								((Quest)((Dealer)dealer).ActiveContracts[0]).Fail(true);
							}
							if (dealer.IsAcceptingDeals)
							{
								dealer.SetIsAcceptingDeals(false);
							}
						}
					}
				}
			}
		}

		[IteratorStateMachine(typeof(<DespawnDefenderGoonsSoon>d__16))]
		public static IEnumerator DespawnDefenderGoonsSoon(List<CartelGoon> goons)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <DespawnDefenderGoonsSoon>d__16(0)
			{
				goons = goons
			};
		}

		[IteratorStateMachine(typeof(<StartActiveSignal>d__17))]
		public static IEnumerator StartActiveSignal()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <StartActiveSignal>d__17(0);
		}

		public static void WalkToInterestPoint(CartelDealer d)
		{
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			if (CartelEnforcer.currentConfig.enhancedDealers && dealerConfig.FreeTimeWalking && (!InterceptEvent.interceptingDeal || !((Object)(object)InterceptEvent.interceptor != (Object)null) || !((Object)(object)InterceptEvent.interceptor == (Object)(object)d)) && ((Dealer)d).ActiveContracts.Count <= 0 && !((NPC)d).Health.IsDead && !((NPC)d).Health.IsKnockedOut && (NetworkSingleton<TimeManager>.Instance.CurrentTime >= currentStayInsideEnd || NetworkSingleton<TimeManager>.Instance.CurrentTime <= currentStayInsideStart))
			{
				DeliveryLocation randomUnscheduledDeliveryLocation = Singleton<Map>.instance.Regions[((NPC)d).Region].GetRandomUnscheduledDeliveryLocation();
				((NPC)d).Movement.SetDestination(randomUnscheduledDeliveryLocation.CustomerStandPoint.position);
				if (!d.IsAcceptingDeals)
				{
					d.SetIsAcceptingDeals(true);
				}
			}
		}

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

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

		[IteratorStateMachine(typeof(<OnCartelCustomerDeal>d__21))]
		public static IEnumerator OnCartelCustomerDeal(CartelCustomerDeal dealEvent, bool started)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <OnCartelCustomerDeal>d__21(0)
			{
				dealEvent = dealEvent,
				started = started
			};
		}
	}
	[Serializable]
	public class CartelDealerConfig
	{
		public float CartelDealerMoveSpeedMultiplier = 1.65f;

		public float CartelDealerHP = 200f;

		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;
	}
	[HarmonyPatch(typeof(Customer), "ProcessHandover")]
	public static class Customer_ProcessHandover_Patch
	{
		[HarmonyPrefix]
		public static bool Prefix(Customer __instance, EHandoverOutcome outcome, Contract contract, List<ItemInstance> items, bool handoverByPlayer, bool giveBonuses = true)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Invalid comparison between Unknown and I4
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)contract.Dealer != (Object)null && (int)contract.Dealer.DealerType == 1)
			{
				float num = 0f;
				__instance.TimeSinceLastDealCompleted = 0;
				__instance.NPC.SendAnimationTrigger("GrabItem");
				NetworkObject val = null;
				if ((Object)(object)contract.Dealer != (Object)null)
				{
					val = ((NetworkBehaviour)contract.Dealer).NetworkObject;
				}
				float num2 = 0f;
				__instance.ProcessHandoverServerSide(outcome, items, handoverByPlayer, num2, contract.ProductList, num, val);
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(Dealer), "CustomerContractEnded")]
	public static class Dealer_CustomerContractEnded_Patch
	{
		[HarmonyPrefix]
		public static bool Prefix(Dealer __instance, Contract contract)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Invalid comparison between Unknown and I4
			if ((int)__instance.DealerType == 1)
			{
				if (!__instance.ActiveContracts.Contains(contract))
				{
					return false;
				}
				__instance.ActiveContracts.Remove(contract);
				contract.SetDealer((Dealer)null);
				((MonoBehaviour)__instance).Invoke("SortContracts", 0.05f);
				if (CartelEnforcer.currentConfig.enhancedDealers)
				{
					DealerActivity.WalkToInterestPoint((CartelDealer)(object)((__instance is CartelDealer) ? __instance : null));
				}
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(CartelRegionActivities), "ActivityEnded")]
	public static class CartelRegionActivities_Patch
	{
		public static bool Prefix(CartelRegionActivities __instance)
		{
			if ((Object)(object)__instance.CurrentActivity == (Object)null)
			{
				return false;
			}
			return true;
		}
	}
	public class CartelRegActivityHours
	{
		public int region;

		public int cartelActivityClass;

		public int hoursUntilEnable;
	}
	public class HrPassParameterMap
	{
		public string itemDesc { get; set; }

		public Func<int> Getter { get; set; }

		public Action<int> Setter { get; set; }

		public Action HourPassAction { get; set; }

		public int modTicksPassed { get; set; }

		public int currentModHours { get; set; }

		public Func<bool> CanPassHour { get; set; }
	}
	public static class FrequencyOverrides
	{
		[CompilerGenerated]
		private sealed class <>c__DisplayClass3_0
		{
			public CartelActivities instanceActivities;

			public CartelDealManager instanceDealMgr;

			internal int <PopulateParameterMap>b__0()
			{
				return instanceActivities.HoursUntilNextGlobalActivity;
			}

			internal void <PopulateParameterMap>b__1(int value)
			{
				instanceActivities.HoursUntilNextGlobalActivity = value;
			}

			internal void <PopulateParameterMap>b__2()
			{
				instanceActivities.HourPass();
			}

			internal int <PopulateParameterMap>b__9()
			{
				return instanceDealMgr.HoursUntilNextDealRequest;
			}

			internal void <PopulateParameterMap>b__10(int value)
			{
				instanceDealMgr.HoursUntilNextDealRequest = value;
			}

			internal void <PopulateParameterMap>b__11()
			{
				instanceDealMgr.HourPass();
			}
		}

		[CompilerGenerated]
		private sealed class <>c__DisplayClass3_1
		{
			public CartelRegionActivities act;

			internal int <PopulateParameterMap>b__4()
			{
				return act.HoursUntilNextActivity;
			}

			internal void <PopulateParameterMap>b__5(int value)
			{
				act.HoursUntilNextActivity = value;
			}

			internal void <PopulateParameterMap>b__6()
			{
				act.HourPass();
			}
		}

		[CompilerGenerated]
		private sealed class <>c__DisplayClass3_2
		{
			public CartelCustomerDeal cartelCustomerDeal;
		}

		[CompilerGenerated]
		private sealed class <HelperSet>d__6 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public HrPassParameterMap hpmap;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <HelperSet>d__6(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					if (!hpmap.CanPassHour())
					{
						return false;
					}
					if (!InstanceFinder.IsServer)
					{
						return false;
					}
					if (CartelEnforcer.currentConfig.activityFrequency > 0f)
					{
						hpmap.HourPassAction();
					}
					else
					{
						if (hpmap.Getter() < 2)
						{
							return false;
						}
						float num = Mathf.Lerp(1f, 10f, 0f - CartelEnforcer.currentConfig.activityFrequency);
						if (hpmap.Getter() < hpmap.currentModHours)
						{
							hpmap.Setter(hpmap.currentModHours);
						}
						else
						{
							hpmap.modTicksPassed = 0;
							hpmap.currentModHours = hpmap.Getter();
						}
						hpmap.modTicksPassed++;
						if ((float)hpmap.modTicksPassed >= num)
						{
							hpmap.HourPassAction();
							hpmap.modTicksPassed = 0;
							hpmap.currentModHours -= 1;
						}
					}
					<>2__current = null;
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					return false;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		[CompilerGenerated]
		private sealed class <PopulateParameterMap>d__3 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			private <>c__DisplayClass3_0 <>8__1;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <PopulateParameterMap>d__3(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>8__1 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_02f2: Unknown result type (might be due to invalid IL or missing references)
				//IL_02fc: Expected I4, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>8__1 = new <>c__DisplayClass3_0();
					<>2__current = CartelEnforcer.Wait2;
					<>1__state = 1;
					return true;
				case 1:
				{
					<>1__state = -1;
					if (!CartelEnforcer.registered)
					{
						return false;
					}
					int num = 0;
					<>8__1.instanceActivities = NetworkSingleton<Cartel>.Instance.Activities;
					actFreqMapping.Add(new HrPassParameterMap
					{
						itemDesc = "Global Activities",
						Getter = () => <>8__1.instanceActivities.HoursUntilNextGlobalActivity,
						Setter = delegate(int value)
						{
							<>8__1.instanceActivities.HoursUntilNextGlobalActivity = value;
						},
						HourPassAction = delegate
						{
							<>8__1.instanceActivities.HourPass();
						},
						modTicksPassed = 0,
						currentModHours = <>8__1.instanceActivities.HoursUntilNextGlobalActivity,
						CanPassHour = () => (int)NetworkSingleton<Cartel>.Instance.Status == 2
					});
					num++;
					CartelRegActivityHours item = new CartelRegActivityHours
					{
						region = -1,
						hoursUntilEnable = GetActivityHours(CartelEnforcer.currentConfig.ambushFrequency),
						cartelActivityClass = -1
					};
					regActivityHours.Add(item);
					foreach (CartelActivity globalActivity in <>8__1.instanceActivities.GlobalActivities)
					{
						Ambush val = (Ambush)(object)((globalActivity is Ambush) ? globalActivity : null);
						if (val != null)
						{
							if ((CartelEnforcer.MeleeWeapons == null || CartelEnforcer.MeleeWeapons.Length == 0) && val.MeleeWeapons != null && val.MeleeWeapons.Length != 0)
							{
								CartelEnforcer.MeleeWeapons = val.MeleeWeapons;
							}
							if ((CartelEnforcer.RangedWeapons == null || CartelEnforcer.RangedWeapons.Length == 0) && val.RangedWeapons != null && val.RangedWeapons.Length != 0)
							{
								CartelEnforcer.RangedWeapons = val.RangedWeapons;
							}
						}
					}
					CartelRegionActivities[] regionalActivities = NetworkSingleton<Cartel>.Instance.Activities.RegionalActivities;
					for (int i = 0; i < regionalActivities.Length; i++)
					{
						<>c__DisplayClass3_1 CS$<>8__locals1 = new <>c__DisplayClass3_1
						{
							act = regionalActivities[i]
						};
						actFreqMapping.Add(new HrPassParameterMap
						{
							itemDesc = "Cartel Regional Activities (" + ((object)(EMapRegion)(ref CS$<>8__locals1.act.Region)).ToString() + ")",
							Getter = () => CS$<>8__locals1.act.HoursUntilNextActivity,
							Setter = delegate(int value)
							{
								CS$<>8__locals1.act.HoursUntilNextActivity = value;
							},
							HourPassAction = delegate
							{
								CS$<>8__locals1.act.HourPass();
							},
							modTicksPassed = 0,
							currentModHours = CS$<>8__locals1.act.HoursUntilNextActivity,
							CanPassHour = () => (int)NetworkSingleton<Cartel>.Instance.Status == 2
						});
						num++;
						foreach (CartelActivity activity in CS$<>8__locals1.act.Activities)
						{
							CartelRegActivityHours cartelRegActivityHours = new CartelRegActivityHours
							{
								region = (int)CS$<>8__locals1.act.Region
							};
							int num2 = 0;
							<>c__DisplayClass3_2 CS$<>8__locals0;
							if (activity is StealDeadDrop)
							{
								cartelRegActivityHours.cartelActivityClass = 0;
								num2 = GetActivityHours(CartelEnforcer.currentConfig.deadDropStealFrequency);
							}
							else
							{
								CS$<>8__locals0 = new <>c__DisplayClass3_2
								{
									cartelCustomerDeal = (CartelCustomerDeal)(object)((activity is CartelCustomerDeal) ? activity : null)
								};
								if (CS$<>8__locals0.cartelCustomerDeal != null)
								{
									cartelRegActivityHours.cartelActivityClass = 1;
									num2 = GetActivityHours(CartelEnforcer.currentConfig.cartelCustomerDealFrequency);
									if (CartelEnforcer.currentConfig.enhancedDealers)
									{
										((CartelActivity)CS$<>8__locals0.cartelCustomerDeal).onActivated = (Action)Delegate.Combine(((CartelActivity)CS$<>8__locals0.cartelCustomerDeal).onActivated, new Action(OnCustomerDealActive));
									}
								}
								else
								{
									cartelRegActivityHours.cartelActivityClass = 2;
									num2 = GetActivityHours(CartelEnforcer.currentConfig.cartelRobberyFrequency);
								}
							}
							cartelRegActivityHours.hoursUntilEnable = num2;
							regActivityHours.Add(cartelRegActivityHours);
							void OnCustomerDealActive()
							{
								CartelEnforcer.coros.Add(MelonCoroutines.Start(DealerActivity.OnCartelCustomerDeal(CS$<>8__locals0.cartelCustomerDeal, started: true)));
							}
						}
					}
					<>8__1.instanceDealMgr = NetworkSingleton<Cartel>.Instance.DealManager;
					actFreqMapping.Add(new HrPassParameterMap
					{
						itemDesc = "Cartel Deal Manager (Truced only)",
						Getter = () => <>8__1.instanceDealMgr.HoursUntilNextDealRequest,
						Setter = delegate(int value)
						{
							<>8__1.instanceDealMgr.HoursUntilNextDealRequest = value;
						},
						HourPassAction = delegate
						{
							<>8__1.instanceDealMgr.HourPass();
						},
						modTicksPassed = 0,
						currentModHours = <>8__1.instanceDealMgr.HoursUntilNextDealRequest,
						CanPassHour = () => (int)NetworkSingleton<Cartel>.Instance.Status == 1
					});
					num++;
					actFreqMapping.Add(new HrPassParameterMap
					{
						itemDesc = "Drive-By Events",
						Getter = () => DriveByEvent.hoursUntilDriveBy,
						Setter = delegate(int value)
						{
							DriveByEvent.hoursUntilDriveBy = value;
						},
						HourPassAction = delegate
						{
							DriveByEvent.hoursUntilDriveBy = Mathf.Clamp(DriveByEvent.hoursUntilDriveBy - 1, 0, 48);
						},
						modTicksPassed = 0,
						currentModHours = DriveByEvent.hoursUntilDriveBy,
						CanPassHour = () => (int)NetworkSingleton<Cartel>.Instance.Status == 2
					});
					<>2__current = null;
					<>1__state = 2;
					return true;
				}
				case 2:
					<>1__state = -1;
					return false;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		[CompilerGenerated]
		private sealed class <TickOverrideHourPass>d__5 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			private WaitForSeconds <WaitCalculated>5__2;

			private List<HrPassParameterMap>.Enumerator <>7__wrap2;

			private HrPassParameterMap <item>5__4;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <TickOverrideHourPass>d__5(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				int num = <>1__state;
				if (num == -3 || num == 2)
				{
					try
					{
					}
					finally
					{
						<>m__Finally1();
					}
				}
				<WaitCalculated>5__2 = null;
				<>7__wrap2 = default(List<HrPassParameterMap>.Enumerator);
				<item>5__4 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
				//IL_00be: Expected O, but got Unknown
				bool result;
				try
				{
					switch (<>1__state)
					{
					default:
						result = false;
						break;
					case 0:
						<>1__state = -1;
						<>2__current = CartelEnforcer.Wait5;
						<>1__state = 1;
						result = true;
						break;
					case 1:
					{
						<>1__state = -1;
						if (!CartelEnforcer.registered)
						{
							result = false;
							break;
						}
						if (CartelEnforcer.currentConfig.activityFrequency == 0f)
						{
							result = false;
							break;
						}
						float num = 60f;
						float num2 = 60f;
						if (CartelEnforcer.currentConfig.activityFrequency > 0f)
						{
							num2 = Mathf.Lerp(num, num / 10f, CartelEnforcer.currentConfig.activityFrequency);
						}
						<WaitCalculated>5__2 = new WaitForSeconds(num2 / (float)actFreqMapping.Count);
						goto IL_0179;
					}
					case 2:
						<>1__state = -3;
						if (!CartelEnforcer.registered)
						{
							result = false;
							<>m__Finally1();
							break;
						}
						MelonCoroutines.Start(HelperSet(<item>5__4));
						<item>5__4 = null;
						goto IL_0150;
					case 3:
						{
							<>1__state = -1;
							result = false;
							break;
						}
						IL_0179:
						while (true)
						{
							if (CartelEnforcer.registered)
							{
								if (!CartelEnforcer.registered)
								{
									result = false;
									break;
								}
								if (actFreqMapping.Count == 0)
								{
									continue;
								}
								<>7__wrap2 = actFreqMapping.GetEnumerator();
								<>1__state = -3;
								goto IL_0150;
							}
							<>2__current = null;
							<>1__state = 3;
							result = true;
							break;
						}
						break;
						IL_0150:
						if (<>7__wrap2.MoveNext())
						{
							<item>5__4 = <>7__wrap2.Current;
							<>2__current = <WaitCalculated>5__2;
							<>1__state = 2;
							result = true;
							break;
						}
						<>m__Finally1();
						<>7__wrap2 = default(List<HrPassParameterMap>.Enumerator);
						goto IL_0179;
					}
				}
				catch
				{
					//try-fault
					((IDisposable)this).Dispose();
					throw;
				}
				return result;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			private void <>m__Finally1()
			{
				<>1__state = -1;
				((IDisposable)<>7__wrap2).Dispose();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		public static List<HrPassParameterMap> actFreqMapping = new List<HrPassParameterMap>();

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

		public static int GetActivityHours(float configValue)
		{
			int num = 0;
			if (configValue > 0f)
			{
				int num2 = 1;
				return Mathf.RoundToInt(Mathf.Lerp(48f, (float)num2, configValue));
			}
			if (configValue < 0f)
			{
				int num3 = 96;
				float num4 = 0f - configValue;
				return Mathf.RoundToInt(Mathf.Lerp(48f, (float)num3, num4));
			}
			return 48;
		}

		[IteratorStateMachine(typeof(<PopulateParameterMap>d__3))]
		public static IEnumerator PopulateParameterMap()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <PopulateParameterMap>d__3(0);
		}

		public static void OnHourPassReduceCartelRegActHours()
		{
			if (regActivityHours.Count <= 0)
			{
				return;
			}
			foreach (CartelRegActivityHours regActivityHour in regActivityHours)
			{
				if (regActivityHour.hoursUntilEnable > 0)
				{
					regActivityHour.hoursUntilEnable--;
				}
			}
		}

		[IteratorStateMachine(typeof(<TickOverrideHourPass>d__5))]
		public static IEnumerator TickOverrideHourPass()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <TickOverrideHourPass>d__5(0);
		}

		[IteratorStateMachine(typeof(<HelperSet>d__6))]
		public static IEnumerator HelperSet(HrPassParameterMap hpmap)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <HelperSet>d__6(0)
			{
				hpmap = hpmap
			};
		}
	}
	[HarmonyPatch(typeof(CartelActivities), "TryStartActivity")]
	public static class CartelActivities_TryStartActivityPatch
	{
		[HarmonyPrefix]
		public static bool Prefix(CartelActivities __instance)
		{
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: 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_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			__instance.HoursUntilNextGlobalActivity = CartelActivities.GetNewCooldown();
			if (!__instance.CanNewActivityBegin())
			{
				return false;
			}
			List<CartelActivity> activitiesReadyToStart = NetworkSingleton<Cartel>.Instance.Activities.GetActivitiesReadyToStart();
			List<EMapRegion> validRegionsForActivity = NetworkSingleton<Cartel>.Instance.Activities.GetValidRegionsForActivity();
			if (activitiesReadyToStart.Count == 0 || validRegionsForActivity.Count == 0)
			{
				return false;
			}
			validRegionsForActivity.Sort((EMapRegion a, EMapRegion b) => NetworkSingleton<Cartel>.Instance.Influence.GetInfluence(b).CompareTo(NetworkSingleton<Cartel>.Instance.Influence.GetInfluence(a)));
			EMapRegion val = (EMapRegion)0;
			bool flag = false;
			foreach (EMapRegion item in validRegionsForActivity)
			{
				float influence = NetworkSingleton<Cartel>.Instance.Influence.GetInfluence(item);
				float num = 0f;
				float num2 = 0f;
				if (CartelEnforcer.currentConfig.activityInfluenceMin == 0f)
				{
					num = 0.7f;
					num2 = influence * num;
					if (Random.Range(0f, 1f) < num2)
					{
						val = item;
						flag = true;
						break;
					}
					continue;
				}
				if (CartelEnforcer.currentConfig.activityInfluenceMin > 0f)
				{
					num2 = Mathf.Lerp(influence * 0.7f, 1f, CartelEnforcer.currentConfig.activityInfluenceMin);
					if (Random.Range(0f, 1f) > num2)
					{
						val = item;
						flag = true;
						break;
					}
					continue;
				}
				_ = CartelEnforcer.currentConfig.activityInfluenceMin;
				num = Mathf.Lerp(1f, 0f, CartelEnforcer.currentConfig.activityInfluenceMin);
				num2 = influence * num;
				if (Random.Range(0f, 1f) > num2)
				{
					val = item;
					flag = true;
					break;
				}
			}
			if (!flag)
			{
				return false;
			}
			if (FrequencyOverrides.regActivityHours[0].hoursUntilEnable > 0)
			{
				return false;
			}
			int count = activitiesReadyToStart.Count;
			do
			{
				count = activitiesReadyToStart.Count;
				if (count == 0)
				{
					break;
				}
				int index = Random.Range(0, count);
				if (activitiesReadyToStart[index].IsRegionValidForActivity(val))
				{
					NetworkSingleton<Cartel>.Instance.Activities.StartGlobalActivity((NetworkConnection)null, val, 0);
					FrequencyOverrides.regActivityHours[0].hoursUntilEnable = FrequencyOverrides.GetActivityHours(CartelEnforcer.currentConfig.ambushFrequency);
					break;
				}
				activitiesReadyToStart.Remove(activitiesReadyToStart[index]);
			}
			while (count != 0);
			return false;
		}
	}
	[HarmonyPatch(typeof(CartelRegionActivities), "TryStartActivity")]
	public static class CartelRegionActivities_TryStartActivityPatch
	{
		public static Dictionary<CartelActivity, List<int>> enabledActivities = new Dictionary<CartelActivity, List<int>>();

		[HarmonyPrefix]
		public static bool Prefix(CartelRegionActivities __instance)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Invalid comparison between I4 and Unknown
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			__instance.HoursUntilNextActivity = CartelRegionActivities.GetNewCooldown(__instance.Region);
			List<int> list = new List<int>();
			for (int i = 0; i < FrequencyOverrides.regActivityHours.Count; i++)
			{
				if (FrequencyOverrides.regActivityHours[i].region == (int)__instance.Region)
				{
					list.Add(i);
				}
			}
			foreach (CartelActivity activity in __instance.Activities)
			{
				int num = 0;
				num = ((!(activity is StealDeadDrop)) ? ((activity is CartelCustomerDeal) ? 1 : 2) : 0);
				for (int j = 0; j < list.Count; j++)
				{
					if (FrequencyOverrides.regActivityHours[list[j]].cartelActivityClass == num && FrequencyOverrides.regActivityHours[list[j]].hoursUntilEnable <= 0 && !enabledActivities.ContainsKey(activity))
					{
						List<int> value = new List<int>
						{
							list[j],
							num
						};
						enabledActivities.Add(activity, value);
					}
				}
			}
			if (enabledActivities.Count == 0)
			{
				enabledActivities.Clear();
				return false;
			}
			int count = enabledActivities.Count;
			do
			{
				count = enabledActivities.Count;
				if (count == 0)
				{
					break;
				}
				KeyValuePair<CartelActivity, List<int>> keyValuePair = enabledActivities.ElementAt(Random.Range(0, count));
				if (keyValuePair.Key.IsRegionValidForActivity(__instance.Region))
				{
					__instance.StartActivity((NetworkConnection)null, __instance.Activities.IndexOf(keyValuePair.Key));
					if (keyValuePair.Value[1] == 0)
					{
						FrequencyOverrides.regActivityHours[keyValuePair.Value[0]].hoursUntilEnable = FrequencyOverrides.GetActivityHours(CartelEnforcer.currentConfig.deadDropStealFrequency);
					}
					else if (keyValuePair.Value[1] == 1)
					{
						FrequencyOverrides.regActivityHours[keyValuePair.Value[0]].hoursUntilEnable = FrequencyOverrides.GetActivityHours(CartelEnforcer.currentConfig.cartelCustomerDealFrequency);
					}
					else if (keyValuePair.Value[1] == 2)
					{
						FrequencyOverrides.regActivityHours[keyValuePair.Value[0]].hoursUntilEnable = FrequencyOverrides.GetActivityHours(CartelEnforcer.currentConfig.cartelRobberyFrequency);
					}
					break;
				}
				enabledActivities.Remove(keyValuePair.Key);
			}
			while (count != 0);
			enabledActivities.Clear();
			return false;
		}
	}
	public static class InfluenceOverrides
	{
		[CompilerGenerated]
		private sealed class <ApplyInfluenceConfig>d__1 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <ApplyInfluenceConfig>d__1(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = CartelEnforcer.Wait2;
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					if (!CartelEnforcer.registered)
					{
						return false;
					}
					if (CartelEnforcer.currentConfig.activityInfluenceMin != 0f)
					{
						foreach (CartelActivity globalActivity in NetworkSingleton<Cartel>.Instance.Activities.GlobalActivities)
						{
							float num = 0f;
							num = ((!(CartelEnforcer.currentConfig.activityInfluenceMin > 0f) || !(globalActivity.InfluenceRequirement > 0f)) ? Mathf.Lerp(globalActivity.InfluenceRequirement, 0f, 0f - CartelEnforcer.currentConfig.activityInfluenceMin) : Mathf.Lerp(globalActivity.InfluenceRequirement, 1f, CartelEnforcer.currentConfig.activityInfluenceMin));
							globalActivity.InfluenceRequirement = num;
						}
						CartelRegionActivities[] array = Object.FindObjectsOfType<CartelRegionActivities>(true);
						for (int i = 0; i < array.Length; i++)
						{
							foreach (CartelActivity activity in array[i].Activities)
							{
								float num2 = 0f;
								num2 = ((!(CartelEnforcer.currentConfig.activityInfluenceMin > 0f) || !(activity.InfluenceRequirement > 0f)) ? Mathf.Lerp(activity.InfluenceRequirement, 0f, 0f - CartelEnforcer.currentConfig.activityInfluenceMin) : Mathf.Lerp(activity.InfluenceRequirement, 1f, CartelEnforcer.currentConfig.activityInfluenceMin));
								activity.InfluenceRequirement = num2;
							}
						}
					}
					<>2__current = null;
					<>1__state = 2;
					return true;
				case 2:
					<>1__state = -1;
					return false;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		[CompilerGenerated]
		private sealed class <OnDayChangeApplyPassiveGain>d__2 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			private MapRegionData[] <>7__wrap1;

			private int <>7__wrap2;

			private MapRegionData <region>5__4;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <OnDayChangeApplyPassiveGain>d__2(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>7__wrap1 = null;
				<region>5__4 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_006f: Unknown result type (might be due to invalid IL or missing references)
				//IL_008b: Unknown result type (might be due to invalid IL or missing references)
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>7__wrap1 = Singleton<Map>.Instance.Regions;
					<>7__wrap2 = 0;
					goto IL_00ba;
				case 1:
					<>1__state = -1;
					if (ShouldChangeInfluence(<region>5__4.Region))
					{
						NetworkSingleton<Cartel>.Instance.Influence.ChangeInfluence(<region>5__4.Region, -0.02f + CartelEnforcer.influenceConfig.passiveInfluenceGainPerDay);
					}
					<region>5__4 = null;
					<>7__wrap2++;
					goto IL_00ba;
				case 2:
					{
						<>1__state = -1;
						return false;
					}
					IL_00ba:
					if (<>7__wrap2 < <>7__wrap1.Length)
					{
						<region>5__4 = <>7__wrap1[<>7__wrap2];
						<>2__current = CartelEnforcer.Wait05;
						<>1__state = 1;
						return true;
					}
					<>7__wrap1 = null;
					<>2__current = null;
					<>1__state = 2;
					return true;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		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;
		}

		[IteratorStateMachine(typeof(<ApplyInfluenceConfig>d__1))]
		public static IEnumerator ApplyInfluenceConfig()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <ApplyInfluenceConfig>d__1(0);
		}

		[IteratorStateMachine(typeof(<OnDayChangeApplyPassiveGain>d__2))]
		public static IEnumerator OnDayChangeApplyPassiveGain()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <OnDayChangeApplyPassiveGain>d__2(0);
		}

		public static void OnDayPassChangePassive()
		{
			CartelEnforcer.coros.Add(MelonCoroutines.Start(OnDayChangeApplyPassiveGain()));
		}
	}
	[Serializable]
	public class InfluenceConfig
	{
		public float interceptFail = 0.05f;

		public float interceptSuccess = -0.05f;

		public float deadDropFail = 0.05f;

		public float deadDropSuccess = -0.025f;

		public float gatheringFail = 0.025f;

		public float gatheringSuccess = -0.08f;

		public float robberyPlayerEscape = 0.08f;

		public float robberyGoonEscapeSuccess = 0.08f;

		public float robberyGoonDead = -0.08f;

		public float robberyGoonEscapeDead = -0.05f;

		public float cartelDealerDied = -0.05f;

		public float ambushDefeated = -0.025f;

		public float passiveInfluenceGainPerDay = 0.05f;
	}
	[HarmonyPatch(typeof(CartelDealer), "DiedOrKnockedOut")]
	public static class CartelDealer_Died_Patch
	{
		public static bool Prefix(CartelDealer __instance)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			if (!InstanceFinder.IsServer)
			{
				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
	{
		[CompilerGenerated]
		private sealed class <OverMonitorAmbush>d__1 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public List<CartelGoon> currentlySpawned;

			public EMapRegion region;

			private float <preMaxElapsed>5__2;

			private float <preElapsed>5__3;

			private List<CartelGoon> <ambushSpawned>5__4;

			private float <maxAmbushElapsed>5__5;

			private float <elapsed>5__6;

			private List<CartelGoon> <deadGoons>5__7;

			private int <spawnedCount>5__8;

			private List<CartelGoon>.Enumerator <>7__wrap8;

			private CartelGoon <goon>5__10;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <OverMonitorAmbush>d__1(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				switch (<>1__state)
				{
				case -3:
				case 2:
					try
					{
					}
					finally
					{
						<>m__Finally1();
					}
					break;
				case -4:
				case 3:
					try
					{
					}
					finally
					{
						<>m__Finally2();
					}
					break;
				}
				<ambushSpawned>5__4 = null;
				<deadGoons>5__7 = null;
				<>7__wrap8 = default(List<CartelGoon>.Enumerator);
				<goon>5__10 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0361: Unknown result type (might be due to invalid IL or missing references)
				try
				{
					switch (<>1__state)
					{
					default:
						return false;
					case 0:
						<>1__state = -1;
						<preMaxElapsed>5__2 = 1f;
						<preElapsed>5__3 = 0f;
						<ambushSpawned>5__4 = new List<CartelGoon>();
						goto IL_0111;
					case 1:
						<>1__state = -1;
						<preElapsed>5__3 += 0.25f;
						if (NetworkSingleton<Cartel>.Instance.GoonPool.spawnedGoons.Count != currentlySpawned.Count)
						{
							foreach (CartelGoon spawnedGoon in NetworkSingleton<Cartel>.Instance.GoonPool.spawnedGoons)
							{
								if (!currentlySpawned.Contains(spawnedGoon) && !<ambushSpawned>5__4.Contains(spawnedGoon) && !CartelGathering.spawnedGatherGoons.Contains(spawnedGoon))
								{
									<ambushSpawned>5__4.Add(spawnedGoon);
								}
							}
						}
						goto IL_0111;
					case 2:
						<>1__state = -3;
						<elapsed>5__6 += 0.5f;
						if (!<deadGoons>5__7.Contains(<goon>5__10))
						{
							if (((NPC)<goon>5__10).Health.IsDead || ((NPC)<goon>5__10).Health.IsKnockedOut)
							{
								<deadGoons>5__7.Add(<goon>5__10);
							}
							<goon>5__10 = null;
						}
						goto IL_024b;
					case 3:
						{
							<>1__state = -4;
							<elapsed>5__6 += 0.5f;
							if (<ambushSpawned>5__4.Contains(<goon>5__10))
							{
								<ambushSpawned>5__4.Remove(<goon>5__10);
							}
							<goon>5__10 = null;
							goto IL_02f8;
						}
						IL_024b:
						if (<>7__wrap8.MoveNext())
						{
							<goon>5__10 = <>7__wrap8.Current;
							<>2__current = CartelEnforcer.Wait05;
							<>1__state = 2;
							return true;
						}
						<>m__Finally1();
						<>7__wrap8 = default(List<CartelGoon>.Enumerator);
						<>7__wrap8 = <deadGoons>5__7.GetEnumerator();
						<>1__state = -4;
						goto IL_02f8;
						IL_0111:
						if (CartelEnforcer.registered && <preElapsed>5__3 < <preMaxElapsed>5__2)
						{
							<>2__current = CartelEnforcer.Wait025;
							<>1__state = 1;
							return true;
						}
						if (<ambushSpawned>5__4.Count == 0)
						{
							return false;
						}
						<maxAmbushElapsed>5__5 = 360f;
						<elapsed>5__6 = 0f;
						<deadGoons>5__7 = new List<CartelGoon>();
						<spawnedCount>5__8 = <ambushSpawned>5__4.Count;
						goto IL_0317;
						IL_02f8:
						if (<>7__wrap8.MoveNext())
						{
							<goon>5__10 = <>7__wrap8.Current;
							<>2__current = CartelEnforcer.Wait05;
							<>1__state = 3;
							return true;
						}
						<>m__Finally2();
						<>7__wrap8 = default(List<CartelGoon>.Enumerator);
						goto IL_0317;
						IL_0317:
						if (!CartelEnforcer.registered || !(<elapsed>5__6 < <maxAmbushElapsed>5__5) || <ambushSpawned>5__4.Count == 0 || <deadGoons>5__7.Count == <spawnedCount>5__8)
						{
							break;
						}
						<>7__wrap8 = <ambushSpawned>5__4.GetEnumerator();
						<>1__state = -3;
						goto IL_024b;
					}
					if ((<ambushSpawned>5__4.Count == 0 || <deadGoons>5__7.Count == <spawnedCount>5__8) && InstanceFinder.IsServer)
					{
						NetworkSingleton<Cartel>.Instance.Influence.ChangeInfluence(region, 0.075f + CartelEnforcer.influenceConfig.ambushDefeated);
					}
					return false;
				}
				catch
				{
					//try-fault
					((IDisposable)this).Dispose();
					throw;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			private void <>m__Finally1()
			{
				<>1__state = -1;
				((IDisposable)<>7__wrap8).Dispose();
			}

			private void <>m__Finally2()
			{
				<>1__state = -1;
				((IDisposable)<>7__wrap8).Dispose();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		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;
		}

		[IteratorStateMachine(typeof(<OverMonitorAmbush>d__1))]
		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)
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <OverMonitorAmbush>d__1(0)
			{
				currentlySpawned = currentlySpawned,
				region = region
			};
		}
	}
	[Serializable]
	public class NewAmbushConfig
	{
		public int mapRegion;

		public Vector3 ambushPosition = Vector3.zero;

		public List<Vector3> spawnPoints = new List<Vector3>();

		public float detectionRadius = 10f;
	}
	[Serializable]
	public class ListNewAmbush
	{
		public List<NewAmbushConfig> addedAmbushes = new List<NewAmbushConfig>();
	}
	public static class AmbushOverrides
	{
		[CompilerGenerated]
		private sealed class <>c__DisplayClass3_0
		{
			public NewAmbushConfig config;

			internal bool <AddUserModdedAmbush>b__0(CartelRegionActivities act)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0011: Invalid comparison between Unknown and I4
				return (int)act.Region == config.mapRegion;
			}
		}

		[CompilerGenerated]
		private sealed class <AddUserModdedAmbush>d__3 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <AddUserModdedAmbush>d__3(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e0: Expected O, but got Unknown
				//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
				//IL_0119: Unknown result type (might be due to invalid IL or missing references)
				//IL_0120: Expected O, but got Unknown
				//IL_016a: Unknown result type (might be due to invalid IL or missing references)
				//IL_016f: Unknown result type (might be due to invalid IL or missing references)
				//IL_019c: Unknown result type (might be due to invalid IL or missing references)
				//IL_01a3: Expected O, but got Unknown
				//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = CartelEnforcer.Wait2;
					<>1__state = 1;
					return true;
				case 1:
				{
					<>1__state = -1;
					if (!CartelEnforcer.registered)
					{
						return false;
					}
					CartelRegionActivities[] regionalActivities = NetworkSingleton<Cartel>.Instance.Activities.RegionalActivities;
					int num = 1;
					if (ambushConfig.addedAmbushes != null && ambushConfig.addedAmbushes.Count > 0)
					{
						using List<NewAmbushConfig>.Enumerator enumerator = ambushConfig.addedAmbushes.GetEnumerator();
						while (enumerator.MoveNext())
						{
							<>c__DisplayClass3_0 CS$<>8__locals0 = new <>c__DisplayClass3_0
							{
								config = enumerator.Current
							};
							CartelRegionActivities val = ((IEnumerable<CartelRegionActivities>)regionalActivities).FirstOrDefault((Func<CartelRegionActivities, bool>)((CartelRegionActivities act) => (int)act.Region == CS$<>8__locals0.config.mapRegion));
							Transform val2 = ((Component)val).transform.Find("Ambush locations");
							GameObject val3 = new GameObject($"AmbushLocation ({val2.childCount})");
							CartelAmbushLocation val4 = val3.AddComponent<CartelAmbushLocation>();
							val3.transform.position = CS$<>8__locals0.config.ambushPosition;
							val4.DetectionRadius = CS$<>8__locals0.config.detectionRadius;
							GameObject val5 = new GameObject("SpawnPoints");
							val5.transform.parent = val3.transform;
							val4.AmbushPoints = (Transform[])(object)new Transform[CS$<>8__locals0.config.spawnPoints.Count];
							int num2 = 0;
							foreach (Vector3 spawnPoint in CS$<>8__locals0.config.spawnPoints)
							{
								GameObject val6 = new GameObject("SP" + ((num2 == 0) ? "" : (" (" + num2 + ")")));
								val6.transform.position = spawnPoint;
								val6.transform.parent = val5.transform;
								val4.AmbushPoints[num2] = val6.transform;
								((Behaviour)val4).enabled = true;
								num2++;
							}
							num++;
							CartelAmbushLocation[] ambushLocations = val.AmbushLocations;
							CartelAmbushLocation[] array = (CartelAmbushLocation[])(object)new CartelAmbushLocation[ambushLocations.Length + 1];
							Array.Copy(ambushLocations, array, ambushLocations.Length);
							array[^1] = val4;
							val.AmbushLocations = array;
							val3.transform.parent = val2;
						}
					}
					return false;
				}
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		[CompilerGenerated]
		private sealed class <ApplyGameDefaultAmbush>d__2 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <ApplyGameDefaultAmbush>d__2(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
				//IL_0104: Unknown result type (might be due to invalid IL or missing references)
				//IL_0137: Unknown result type (might be due to invalid IL or missing references)
				//IL_013f: Unknown result type (might be due to invalid IL or missing references)
				//IL_015d: Unknown result type (might be due to invalid IL or missing references)
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = CartelEnforcer.Wait5;
					<>1__state = 1;
					return true;
				case 1:
				{
					<>1__state = -1;
					if (!CartelEnforcer.registered)
					{
						return false;
					}
					ambushConfig = ConfigLoader.LoadAmbushConfig();
					gameDefaultAmbush = ConfigLoader.LoadDefaultAmbushConfig();
					CartelRegionActivities[] array = Object.FindObjectsOfType<CartelRegionActivities>(true);
					int num = 0;
					CartelRegionActivities[] array2 = array;
					for (int i = 0; i < array2.Length; i++)
					{
						CartelAmbushLocation[] ambushLocations = array2[i].AmbushLocations;
						foreach (CartelAmbushLocation val in ambushLocations)
						{
							List<Vector3> list = val.AmbushPoints.Select((Transform tr) => tr.position).ToList();
							NewAmbushConfig newAmbushConfig = gameDefaultAmbush.addedAmbushes.ElementAt(num);
							num++;
							if (newAmbushConfig.spawnPoints.Count != list.Count)
							{
								continue;
							}
							if (((Component)val).transform.position != newAmbushConfig.ambushPosition)
							{
								((Component)val).transform.position = newAmbushConfig.ambushPosition;
							}
							if (val.DetectionRadius != newAmbushConfig.detectionRadius)
							{
								val.DetectionRadius = newAmbushConfig.detectionRadius;
							}
							for (int k = 0; k < newAmbushConfig.spawnPoints.Count; k++)
							{
								if (newAmbushConfig.spawnPoints[k] != list[k])
								{
									val.AmbushPoints[k].position = newAmbushConfig.spawnPoints[k];
								}
							}
						}
					}
					<>2__current = null;
					<>1__state = 2;
					return true;
				}
				case 2:
					<>1__state = -1;
					return false;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		public static ListNewAmbush ambushConfig;

		public static ListNewAmbush gameDefaultAmbush;

		[IteratorStateMachine(typeof(<ApplyGameDefaultAmbush>d__2))]
		public static IEnumerator ApplyGameDefaultAmbush()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <ApplyGameDefaultAmbush>d__2(0);
		}

		[IteratorStateMachine(typeof(<AddUserModdedAmbush>d__3))]
		public static IEnumerator AddUserModdedAmbush()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <AddUserModdedAmbush>d__3(0);
		}
	}
	public static class BuildInfo
	{
		public const string Name = "Cartel Enforcer";

		public const string Description = "Cartel - Modded and configurable";

		public const string Author = "XOWithSauce";

		public const string Company = null;

		public const string Version = "1.6.0";

		public const string DownloadLink = null;
	}
	public class CartelEnforcer : MelonMod
	{
		[HarmonyPatch(typeof(SaveManager), "Save", new Type[] { typeof(string) })]
		public static class SaveManager_Save_String_Patch
		{
			public static bool Prefix(SaveManager __instance, string saveFolderPath)
			{
				if (!isSaving)
				{
					isSaving = true;
					lock (CartelInventory.cartelItemLock)
					{
						ConfigLoader.Save(CartelInventory.cartelStolenItems);
					}
				}
				isSaving = false;
				return true;
			}
		}

		[HarmonyPatch(typeof(SaveManager), "Save", new Type[] { })]
		public static class SaveManager_Save_Patch
		{
			public static bool Prefix(SaveManager __instance)
			{
				if (!isSaving)
				{
					isSaving = true;
					lock (CartelInventory.cartelItemLock)
					{
						ConfigLoader.Save(CartelInventory.cartelStolenItems);
					}
				}
				isSaving = false;
				return true;
			}
		}

		[HarmonyPatch(typeof(LoadManager), "ExitToMenu")]
		public static class LoadManager_ExitToMenu_Patch
		{
			public static bool Prefix(LoadManager __instance, SaveInfo autoLoadSave = null, Data mainMenuPopup = null, bool preventLeaveLobby = false)
			{
				if (!isSaving)
				{
					isSaving = true;
					lock (CartelInventory.cartelItemLock)
					{
						ConfigLoader.Save(CartelInventory.cartelStolenItems);
					}
				}
				isSaving = false;
				ExitPreTask();
				return true;
			}
		}

		[HarmonyPatch(typeof(DeathScreen), "LoadSaveClicked")]
		public static class DeathScreen_LoadSaveClicked_Patch
		{
			public static bool Prefix(DeathScreen __instance)
			{
				ExitPreTask();
				return true;
			}
		}

		[CompilerGenerated]
		private sealed class <AfterAmbushInitComplete>d__26 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <AfterAmbushInitComplete>d__26(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = MelonCoroutines.Start(FrequencyOverrides.PopulateParameterMap());
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					<>2__current = MelonCoroutines.Start(InfluenceOverrides.ApplyInfluenceConfig());
					<>1__state = 2;
					return true;
				case 2:
				{
					<>1__state = -1;
					coros.Add(MelonCoroutines.Start(FrequencyOverrides.TickOverrideHourPass()));
					TimeManager instance = NetworkSingleton<TimeManager>.Instance;
					instance.onHourPass = (Action)Delegate.Combine(instance.onHourPass, new Action(FrequencyOverrides.OnHourPassReduceCartelRegActHours));
					if (currentConfig.debugMode)
					{
						<>2__current = MelonCoroutines.Start(DebugModule.SpawnAmbushAreaVisual());
						<>1__state = 3;
						return true;
					}
					break;
				}
				case 3:
					<>1__state = -1;
					break;
				}
				return false;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		[CompilerGenerated]
		private sealed class <ExtendGoonPool>d__29 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			private GoonPool <goonPool>5__2;

			private NetworkManager <netManager>5__3;

			private NetworkObject <nob>5__4;

			private int <newCount>5__5;

			private CartelGoon[] <newGoons>5__6;

			private int <i>5__7;

			private NetworkObject <nobNew>5__8;

			private CartelGoon <newGoon>5__9;

			private CartelGoon[] <>7__wrap9;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <ExtendGoonPool>d__29(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<goonPool>5__2 = null;
				<netManager>5__3 = null;
				<nob>5__4 = null;
				<newGoons>5__6 = null;
				<nobNew>5__8 = null;
				<newGoon>5__9 = null;
				<>7__wrap9 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0189: Unknown result type (might be due to invalid IL or missing references)
				//IL_018f: Unknown result type (might be due to invalid IL or missing references)
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
				{
					<>1__state = -1;
					<goonPool>5__2 = NetworkSingleton<Cartel>.Instance.GoonPool;
					CartelGoon[] goons = <goonPool>5__2.goons;
					<netManager>5__3 = Object.FindObjectOfType<NetworkManager>(true);
					PrefabObjects spawnablePrefabs = <netManager>5__3.SpawnablePrefabs;
					<nob>5__4 = null;
					for (int i = 0; i < spawnablePrefabs.GetObjectCount(); i++)
					{
						NetworkObject @object = spawnablePrefabs.GetObject(true, i);
						object obj2;
						if (@object == null)
						{
							obj2 = null;
						}
						else
						{
							GameObject gameObject = ((Component)@object).gameObject;
							obj2 = ((gameObject != null) ? ((Object)gameObject).name : null);
						}
						if ((string?)obj2 == "CartelGoon")
						{
							<nob>5__4 = @object;
							break;
						}
					}
					int num = goons.Length;
					int num2 = 5;
					<newCount>5__5 = num + num2;
					<newGoons>5__6 = (CartelGoon[])(object)new CartelGoon[<newCount>5__5];
					Array.Copy(goons, <newGoons>5__6, num);
					if ((Object)(object)goons.FirstOrDefault() != (Object)null)
					{
						<i>5__7 = num;
						goto IL_0265;
					}
					goto IL_0287;
				}
				case 1:
					<>1__state = -1;
					if (!registered)
					{
						return false;
					}
					<netManager>5__3.ServerManager.Spawn(<nobNew>5__8, (NetworkConnection)null, default(Scene));
					<>2__current = Wait05;
					<>1__state = 2;
					return true;
				case 2:
					<>1__state = -1;
					if (!registered)
					{
						return false;
					}
					((Component)<newGoon>5__9).gameObject.SetActive(true);
					<>2__current = Wait2;
					<>1__state = 3;
					return true;
				case 3:
					<>1__state = -1;
					if (!registered)
					{
						return false;
					}
					((Behaviour)((NPC)<newGoon>5__9).Movement).enabled = true;
					((Component)<newGoon>5__9).gameObject.SetActive(true);
					<newGoon>5__9.Despawn_Client();
					<newGoons>5__6[<i>5__7] = <newGoon>5__9;
					<goonPool>5__2.unspawnedGoons.Add(<newGoon>5__9);
					<nobNew>5__8 = null;
					<newGoon>5__9 = null;
					<i>5__7++;
					goto IL_0265;
				case 4:
				{
					<>1__state = -1;
					if (!registered)
					{
						return false;
					}
					NPCAction obj = ((NPC)<newGoon>5__9).Behaviour.ScheduleManager.ActionList[0];
					NPCEvent_StayInBuilding val = (NPCEvent_StayInBuilding)(object)((obj is NPCEvent_StayInBuilding) ? obj : null);
					if (val != null)
					{
						((NPCAction)val).Resume();
					}
					<newGoon>5__9.IsGoonSpawned = true;
					<>2__current = Wait05;
					<>1__state = 5;
					return true;
				}
				case 5:
					{
						<>1__state = -1;
						if (!registered)
						{
							return false;
						}
						<newGoon>5__9.Despawn_Client();
						<newGoon>5__9 = null;
						<i>5__7++;
						break;
					}
					IL_0287:
					<>7__wrap9 = NetworkSingleton<Cartel>.Instance.GoonPool.goons;
					<i>5__7 = 0;
					break;
					IL_0265:
					if (<i>5__7 < <newCount>5__5)
					{
						<nobNew>5__8 = Object.Instantiate<NetworkObject>(<nob>5__4);
						<newGoon>5__9 = ((Component)<nobNew>5__8).GetComponent<CartelGoon>();
						((Component)<newGoon>5__9).transform.parent = NetworkSingleton<NPCManager>.Instance.NPCContainer;
						NPCManager.NPCRegistry.Add((NPC)(object)<newGoon>5__9);
						<>2__current = Wait05;
						<>1__state = 1;
						return true;
					}
					<goonPool>5__2.goons = <newGoons>5__6;
					goto IL_0287;
				}
				if (<i>5__7 < <>7__wrap9.Length)
				{
					<newGoon>5__9 = <>7__wrap9[<i>5__7];
					if (((NPC)<newGoon>5__9).Health.IsDead || ((NPC)<newGoon>5__9).Health.IsKnockedOut)
					{
						((NPC)<newGoon>5__9).Health.Revive();
					}
					<>2__current = Wait01;
					<>1__state = 4;
					return true;
				}
				<>7__wrap9 = null;
				return false;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		[CompilerGenerated]
		private sealed class <InitializeAmbush>d__25 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <InitializeAmbush>d__25(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = MelonCoroutines.Start(AmbushOverrides.ApplyGameDefaultAmbush());
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					<>2__current = MelonCoroutines.Start(AmbushOverrides.AddUserModdedAmbush());
					<>1__state = 2;
					return true;
				case 2:
					<>1__state = -1;
					<>2__current = MelonCoroutines.Start(AfterAmbushInitComplete());
					<>1__state = 3;
					return true;
				case 3:
					<>1__state = -1;
					return false;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		[CompilerGenerated]
		private sealed class <InitializeAndEvaluateDriveBy>d__24 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <InitializeAndEvaluateDriveBy>d__24(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = MelonCoroutines.Start(DriveByEvent.InitializeDriveByData());
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					coros.Add(MelonCoroutines.Start(DriveByEvent.EvaluateDriveBy()));
					if (currentConfig.debugMode)
					{
						<>2__current = MelonCoroutines.Start(DebugModule.SpawnDriveByAreaVisual());
						<>1__state = 2;
						return true;
					}
					break;
				case 2:
					<>1__state = -1;
					break;
				}
				return false;
			}

			bool IEnumerator.MoveNext()
			{